akhauriyash/Code-Regression huggingface dataset:
N,K = map(int,input().split())
L = list(map(int,input().split()))
ANS = []
for i in range(len(L)-K+1) :
    p = L[i]
    q = L[i+K-1]
    if p*q == 0 :
        r = abs(p-q)
    elif p*q < 0 :
        r = 2*min(abs(p),q) + max(abs(p),q)
    else :
        if p > 0 :
            r = q
        else :
            r = abs(p)
    ANS.append(r)
ans = min(ANS)
print(ans)


Measured memory_bytes: 14568
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false),cin.tie(0);
#define F first
#define S second
using namespace std;
typedef long long ll;
ll a,b,c;
const ll maxn=200005;
const ll mod=1e9+7;
typedef pair<ll,ll> pii;
ll num[100005];
ll n,k,x,y;
string s;
int main()
{
    //IOS
    while(cin>>n>>k)
    {
        if(k<=0&&k+n-1>=0)
        {
            cout<<(2*k+n-1)*n/2<<"\n";
        }
        else
        {
            if(k>0) cout<<(2*k+n-1)*n/2-k<<"\n";
            else cout<<(2*k+n-1)*n/2-(k+n-1)<<"\n";
        }
    }


}


Measured memory_bytes: 256
import sys


def main():
    dp = [[0] * W for _ in range(H)]

    for y in range(H):
        for x in range(W):
            if x == 0 and y == 0:
                if s[0][0] == "#":
                    dp[0][0] = 1
            elif x == 0:
                if s[y][x] == "#" and s[y - 1][x] == ".":
                    dp[y][x] = dp[y - 1][x] + 1
                else:
                    dp[y][x] = dp[y - 1][x]
            elif y == 0:
                if s[y][x] == "#" and s[y][x - 1] == ".":
                    dp[y][x] = dp[y][x - 1] + 1
                else:
                    dp[y][x] = dp[y][x - 1]
            else:
                if s[y][x] == "#" and s[y][x - 1] == "." and s[y - 1][x] == ".":
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x]) + 1
                elif s[y][x] == "#" and s[y][x - 1] == ".":
                    dp[y][x] = min(dp[y][x - 1] + 1, dp[y - 1][x])
                elif s[y][x] == "#" and s[y - 1][x] == ".":
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x] + 1)
                else:
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x])

    print(dp[-1][-1])


if __name__ == "__main__":
    H, W = map(int, sys.stdin.readline().split())
    s = [list(sys.stdin.readline().rstrip()) for _ in range(H)]
    main()

Measured memory_bytes: 3316
# # coding=utf-8
# # Author: lee215

get = lambda: int(raw_input().strip())
gets = lambda: [int(i) for i in raw_input().strip().split()]
getss = lambda n: [gets() for _ in xrange(n)]

import bisect


N, Q = gets()
S = raw_input()
query = getss(Q)


AC = []
for i in xrange(N):
    if S[i:i + 2] == "AC":
        AC.append(i)


# print AC
for i, j in query:
    i, j = i - 1, j - 1
    x = bisect.bisect_left(AC, i)
    y = bisect.bisect(AC, j - 1)
    print y - x
    # print i, j, y, x, y - x


Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl
#define all(v) v.begin(), v.end()
#define rsort(v) sort(v.rbegin(), v.rend())


int main() {
  ll X,Y;
  cin >> X >> Y;
  if (X==Y || abs(X-Y) == 1) {
    print("Brown");
  } else {
    print("Alice");
  }
  return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
using Graph = vector<vector<int>>;

ll GCD(ll a,ll b){
    if(b == 0) return a;
    return GCD(b,a%b);
}

ll LCM(ll a, ll b){
    ll g = GCD(a,b);
    return a / g * b;
}

int main(){
    int N;
    cin >> N;
    ll a,b;
    cin >> a;
    rep(i,N-1){
        cin >> b;
        a = LCM(a,b);
    }
    cout << a << endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i], a[i]--;
  
  vb visited(n);
  ll pos=0, cnt=0;
  while(!visited[pos]){
    visited[pos]=true;
    if(pos==1){
      cout<<cnt<<endl;
      return 0;
    }
    cnt++;
    pos=a[pos];
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 1024
N=int(input())
A_1=list(map(int, input().split()))
A_2=list(map(int, input().split()))
total_1=[0]*(N+1)
total_2=[0]*(N+1)
num_candy=[0]*N
for i in range(N):
	total_1[i+1]=A_1[i]+total_1[i]
	total_2[i+1]=A_2[i]+total_2[i]

for j in range(N):
	num_candy[j]=total_1[j+1]+(total_2[N]-total_2[j])

print(max(num_candy))


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

int main(void){
	int N, x;
	cin >> N >> x;
	vector<int> v(N);
	for(int i=0;i<N;i++){
		cin >> v[i];
	}
	sort(v.begin(), v.end());

	for(int i=0;i<N;i++){
		if (i == N-1){
			if(x != v[i]){
				cout << i << endl;
				break;
			}else if(x >= v[i]){
				cout << i+1 << endl;
				break;
			}
		}else{
			if(x >= v[i]){
				x -= v[i];
			}else {
				cout << i << endl;
				break;
			}
		}


	}

	return 0;
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7

n = int(input())
s = input()
t = list(map(lambda x: 1 if x == 'B' else 0, s))
t = tuple((tt - df) % 2 for tt, df in zip(t, reversed(range(n * 2))))
# print(t)

ans = 1
zeros = 0
ones = 0
for tt in t:
    if tt == 0:
        zeros += 1
    else:
        if zeros == 0:
            print(0)
            exit()
        ans *= zeros
        ans %= mod
        zeros -= 1
        ones += 1

if zeros > 0:
    print(0)
    exit()

for i in range(1, n + 1):
    ans *= i
    ans %= mod

print(ans)


Measured memory_bytes: 6964
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static float nextFloat() throws IOException {
        return Float.parseFloat(next());
    }
}

public class Main {
    //static final int MOD=1000000007;
    public static void main(String[] args) throws IOException {
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        Reader.init(System.in);
        int test = 1;
        for (int ii = 0; ii < test; ii++) {
            int a, b, h, m;
            a = Reader.nextInt();
            b = Reader.nextInt();
            h = Reader.nextInt();
            m = Reader.nextInt();
            double hour_angle = (double) (0.5 * (h * 60 + m));
            double minute_angle = (double) (6 * m);

            // Find the difference between two angles
            double angle = Math.abs(hour_angle - minute_angle);

            // smaller angle of two possible angles
            angle = Math.min(360.0 - angle, angle);

            //System.out.println("angle "+angle);
            double radians = (double) Math.toRadians(angle);
            double ans = (double) (Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(radians));
            ans = (double) Math.abs(Math.sqrt(ans));
            System.out.format("%.15f", ans);
        }
        out.flush();
        out.close();
    }
}



Measured memory_bytes: 34664
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")
    };
}

//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [i32; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }

// https://practice.contest.atcoder.jp/tasks/practice_1
//fn main() {
//    input!{
//        a: usize, b: usize, c: usize,
//        foo: chars,
//    }
//    let s: String = foo.into_iter().collect();
//    println!("{} {}", a+b+c, s);
//}

fn main() {
    input!{
        n: chars
    }
    let mut ans = String::from("");
    for i in n {
        if i == '1' { ans.push_str("9") } else if i == '9' { ans.push_str("1")};
    }
    println!("{}", ans);

}

Measured memory_bytes: 4352
//AtCoder ABC122 A - Double Helix
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    char b; cin>>b;
    char ans;
    switch(b){
        case 'A': ans='T';break;
        case 'T': ans='A';break;
        case 'G':ans='C';break;
        case 'C':ans='G';break;
    }
    cout<<ans<<endl;
    return 0;
}

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 <functional>
#include <numeric>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int X;
	cin >> X;
	if (X < 600) cout << 8 << endl;
	else if (X < 800) cout << 7 << endl;
	else if (X < 1000) cout << 6 << endl;
	else if (X < 1200) cout << 5 << endl;
	else if (X < 1400) cout << 4 << endl;
	else if (X < 1600) cout << 3 << endl;
	else if (X < 1800) cout << 2 << endl;
	else cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    string S;
    cin >> S;

    rep(i, S.length()) cout << 'x';
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 1e6 + 5;
int smf[MAX], cnt[MAX];
void sieve()
{
	for(int i = 2; i < MAX; i++) {
		if(!smf[i]) {
			smf[i] = i;
			for(int j = 2 * i; j < MAX; j += i) {
				if(!smf[j]) 
				smf[j] = i;
			}
		}
	}
}
int main()
{
	boost;
	sieve();
	int n, i;
	cin >> n;
	
	int arr[n];
	fo(i, 0, n)
	cin >> arr[i];
	
	int g = 0;
	for(int x : arr)
	g = __gcd(g, x);
	
	for(int x : arr) {
		while(x > 1) {
			int y = smf[x];
			cnt[y]++;
			while(x % y == 0) x /= y;
		}
	}
	
	bool ok = 1;
	for(i = 2; i < MAX; i++)
	ok &= (cnt[i] < 2);
	
	if(ok) cout << "pairwise coprime";
	else if(g == 1) cout << "setwise coprime";
	else cout << "not coprime";
}


Measured memory_bytes: 15228
#include <bits/stdc++.h>
using namespace std;
int main(){
int W,a,b,z=0;
    scanf("%d%d%d",&W,&a,&b);
    if(W>=1&&W<=pow(10,5)&&a>=1&&b<=pow(10,5)){
     if(a<b){
         if(b>a+W){
             z=b-(W+a);
             printf("%d",z);
         }else
             printf("0");

     }else if (a>b){
         z=a-(b+W);
         printf("%d",z);
     }else
     printf("0");
}
    return 0;
}


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

int main(){
    int N,M;
    string s,t;
    long long r=0;
    map<string, int> mp;

    cin >> N;
    for(int i=0;i<N;++i){
        cin >> s;
        mp[s];
        mp[s]+=1;
    }

    cin >> M;
    for (int i=0;i<M;++i){
        cin >> t;
        mp[t];
        mp[t]-=1;
    }
    vector<pair<string, int>> v(mp.begin(),mp.end());
    sort(v.rbegin(),v.rend(), [](auto& x, auto& y){return x.second < y.second;});
    cout << max(v[0].second,0) << endl;}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

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

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

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



// ***************************************


int main(){

    int N;
    cin >> N;

    int cnt = 0;
    int ans = 0;
    REP(i, N ){
        int x, y;
        cin >> x >> y;
        if (x == y){
            cnt++;
        } else{
            cnt = 0;
        }
        chmax(ans, cnt);
    }

    if (ans >= 3) cout << YES <<endl;
    else cout << NO << endl;


    return 0;
}


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

int main() {
    string S;
    cin >> S;
    int ans = 100000;
    rep(i, S.size() - 2) {
        int j = stoi(S.substr(i, 3));
        ans = min(ans, abs(j - 753));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
N = int(input())
S = math.factorial(N)
T = [i for i in range(2, N+1)]
s = 1
while len(T)>0:
  c = 1
  while S%T[0]==0:
    S //= T[0]
    c += 1
  s *= c
  s %= 10**9+7
  T = [t for t in T if t%T[0]]
print(s)

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

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

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N; cin >> N;
    vector<i64> P(N);
    REP(i, N) cin >> P[i];

    i64 s = 0;
    i64 maxp = 0;
    REP(i, N) {
        s += P[i];
        chmax(maxp, P[i]);
    }
    s -= maxp / 2;
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
p = [[i]+LIST() for i in range(m)]
q = [0]*(n+1)

p.sort(key=itemgetter(2))
for x in p:
    q[x[1]] += 1
    x.append(q[x[1]])

p.sort(key=itemgetter(0))
for x in p:
    print(str(x[1]).zfill(6)+str(x[3]).zfill(6))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

const int mod = 1e9+7;

ll P(ll l, ll r){
	ll ret = 1;
	for(ll i = 0; i < r; i++){
		ret *= (l-i);
		ret %= mod;
	}
	return ret;
}

ll dfs(vector<vector<int>> &tree, int now, int bf, int k){
	ll ret = 1;
	if(bf == -1){
		ret = k * P(k-1, tree.at(now).size());
		ret %= mod;
	}else{
		ret = P(k-2, tree.at(now).size()-1);
	}
	for(int i : tree.at(now)){
		if(bf == i) continue;
		ret *= dfs(tree, i, now, k);
		ret %= mod;
	}
	return ret;
}

int main(){
	int n, k;
	cin >> n >> k;
	vector<vector<int>> tree(n, vector<int>());
	rep(i, n-1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		tree.at(a).push_back(b);
		tree.at(b).push_back(a);
	}
	ll ans = dfs(tree, 0, -1, k);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int main(){
    IOS
    //io_set();
    string a;
    stack<char>s;
    cin>>a;
    ll i,n=a.size();
    for(i=0;i<n;i++){
        if(a[i]=='B'){
            if(!s.empty()){
                s.pop();
            }
        }
        else{
            s.push(a[i]);
        }
    }
    vector<char>v;
    while(!s.empty()){
        v.pb(s.top());
        s.pop();
    }
    if(v.size() == 0){
        cout<<" ";
    }
    else{
        for(i=(int)v.size()-1;i>=0;i--){
            cout<<v[i];
        }
    }
    return 0;
}

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

using namespace std;

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

    int b = n % 500;
    if (a >= b)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    ll h;
    cin >> h;
    ll cnt = 0;
    ll p = 1;
    while (h)
    {
        h /= 2;
        cnt++;
    }
    for (int i = 0; i < cnt; i++)
    {
        p *= 2;
    }
    p -= 1;
    cout << p << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vll vector<ll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
ll mod1 = 1e9 + 7;
ll mod2 = 998244353;

ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=(z*x);x =(x*x) ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll max(ll a,ll b,ll c){
	return max(max(a,b),c);
}
//to check overlap of intervals
bool overlap(pll p1,pll p2){
	if(p1.ss <= p2.ff)return false;
	if(p1.ff >= p2.ss)return false;
	return true;
	
}
void solve(ll tn){
	}






int main(){
	ll n,k;
	cin>>n>>k;
	cout<<min(n%k , k-(n%k))<<endl;






}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int uchiha=1e3+5;
int main(){
    map<int,int> mp;
    vector<int> v;
int n,k,c1=0,w;
cin>>n>>k;
for(int i=0;i<n;i++){
        cin>>w;
    mp[w]++;
}
for(auto e : mp){
    v.push_back(e.second);
}
sort(v.begin(),v.end(),greater<int>());
while(v.size()>k){
    c1+=v.back();
    v.pop_back();
}
cout<<c1;
}

Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, C, ans;
int s, t, c;

int main()
{
    cin >> N >> C;
    vector<int> imos(100003);
    vector<pair<int, pair<int, int>>> ch;
    for (int i = 0; i < N; i++)
    {
        cin >> s >> t >> c;
        c--;
        ch.push_back({c, {s, t}});
    }
    sort(ch.begin(), ch.end());
    c = ch[0].first;
    s = ch[0].second.first;
    t = ch[0].second.second;
    bool flag = false;
    for (int i = 1; i < N; i++)
    {
        if (ch[i].first == c && t == ch[i].second.first)
        {
            if (i == N - 1)
                flag = true;
            t = ch[i].second.second;
        }
        else
        {
            imos[s - 1]++, imos[t]--;
            c = ch[i].first, s = ch[i].second.first, t = ch[i].second.second;
        }
    }
    if (true)
    {
        imos[s - 1]++, imos[t]--;
    }

    for (int i = 0; i < 100002; i++)
    {
        imos[i + 1] += imos[i];
        ans = max(ans, imos[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 2296
N, K = map(int,input().split())
H = list(map(int,input().split()))
L = [[] for k in range(N)]
for _ in range(K):
    A, B = map(int,input().split())
    L[A-1].append(B-1)
    L[B-1].append(A-1)
ans = 0
for k in range(N):
    f = 1
    for e in L[k]:
        if H[k] <= H[e]:
            f = 0
            break
    ans += f
print(ans)


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

const ll MOD = 1e9+7;
signed main(){
    int N, M;
    cin>>N>>M;
    
    if( M<N || N==1 ){
        cout<<(M+1)%MOD<<endl;
        return 0;
    }
    
    int n = ( M/(N-1) )%MOD;
    int a = ( M+1-N+1 )%MOD;
    int d = 1+MOD-(N%MOD);
    
    
    cout<<( M+1+2*((n*a)%MOD + ( ( n*(n-1)/2 )%MOD *(1+MOD-N%MOD)  )%MOD) )%MOD<<endl;
    
}

Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long 
struct node{
	ll l,r;
	node(ll a,ll b){
		l=a;r=b;
	}
	friend bool operator<(const node &a,const node &b){
		return a.r>b.r;
	}
};
priority_queue<node> q;
ll n,t1,t2;
int main(){
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&t1,&t2);
		q.push(node(t1,t2));
	}
	ll sum=0;
	for(int i=0;i<n;i++){
		node e=q.top();
		q.pop();
		sum+=e.l;
		if(sum>e.r){
			printf("No");
			return 0;
		}
		//cout <<e.l<<" "<<e.r<<endl;
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
int main(){
    int n,i,j,k,l,ans = -inf;scanf("%d",&n);
    int rp[n+1][n+1];
    for(i=0;i<=n;i++) rp[0][i] = rp[i][0] = 0;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++) scanf("%d",&rp[i][j]);
    }
    for(i=1;i<=n;i++){
        for(j=2;j<=n;j++) rp[i][j] += rp[i][j-1];
    }
    for(i=1;i<=n;i++){
        for(j=2;j<=n;j++) rp[j][i] += rp[j-1][i];
    }
    for(i=1;i<=n;i++){
        for(j=i;j<=n;j++){
            for(k=1;k<=n;k++){
                for(l=k;l<=n;l++) ans = max(ans,rp[j][l]-rp[j][k-1]-rp[i-1][l]+rp[i-1][k-1]);
            }
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 3256
function Main(input) {
    input = input.split("\n");
  	n = Number(input[0].split(" "));
    a = input[1].split(" ").map(Number);
    b = input[2].split(" ").map(Number);
    c = input[3].split(" ").map(Number);
  	var count = 0;
  	for(var i=0; i<n; i++){
      count += b[a[i]-1];
      if(a[i] === a[i-1]+1){
      	count += c[a[i]-2];
      }
    }
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
N,C=map(int, input().split())
inarr=[[int(i) for i in input().split()] for _ in range(N)]
maxes1=[(0, 0)]*N
maxes2=[(0, 0)]*N
cums=[0]*(N+1)
cum = 0
cummax1 = (0, 0)
cummax2 = (0, 0)
for i, [a, v] in enumerate(inarr):
    cum += v
    if (cum - a) > cummax1[0]:
        cummax1 = (cum - a, a)
    if (cum - 2*a) > cummax2[0]:
        cummax2 = (cum - 2*a, a)
    maxes1[i]=cummax1
    maxes2[i]=cummax2
    cums[i+1]=cum

# print("{}".format(maxes1))
resmax = 0
for i, [b, v] in enumerate(inarr):
    oasum1, x = (0, 0) if i == 0 else maxes1[i-1]
    oasum2, x = (0, 0) if i == 0 else maxes2[i-1]
    obsum = cums[N] - cums[i]
    resmax = max(resmax, obsum + oasum1 - 2*(C-b), obsum + oasum2 - (C-b))
    # print(resmax)

# print(maxes1[N-1])
print(max(resmax, maxes1[N-1][0], 0))


Measured memory_bytes: 46476
// CPP program to find harmonic mean of numbers.
#include <bits/stdc++.h>
using namespace std;

int main()
{
    float sum=0,x;
    int n,i;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x;
        sum=sum+(1/x);
    }
    printf("%.14lf",1/sum);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import os
from sys import stdin, stdout


def solve(tc):
    x = int(stdin.readline().strip())
    if 400 <= x <600:
        print(8)
    elif 600<=x<800:
        print(7)
    elif 800<=x<1000:
        print(6)
    elif 1000<=x<1200:
        print(5)
    elif 1200<=x<1400:
        print(4)
    elif 1400<=x<1600:
        print(3)
    elif 1600<=x<1800:
        print(2)
    elif 1800<=x<2000:
        print(1)
    return

tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1


Measured memory_bytes: 61804
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n; cin >> n;
    vector<int> ar(n);
    rep(i,n) cin >> ar[i];
    ll ans = 0;
    rep(i,n-1){
        repp(j,n,i+1){
            ans += ar[i] * ar[j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int n = Integer.valueOf(stdIn.nextLine());
		String[] u = new String[n];
		for(int i=0;i<n;i++){
			u[i] = stdIn.nextLine();
		}
		int m = Integer.valueOf(stdIn.nextLine());
		boolean open = false;
		for(int i=0;i<m;i++){
			String input = stdIn.nextLine();
			boolean match = false;
			for(int j=0;j<n;j++){
				if(input.equals(u[j])){
					if(open){
						System.out.println("Closed by "+input);
						open = false;
					}
					else{
						System.out.println("Opened by "+input);
						open = true;
					}
					match = true;
					break;
				}
			}
			if(!match){
				System.out.println("Unknown "+input);
			}
		}
	}
}

Measured memory_bytes: 24768
N = int(input())
def prime(x):
  for i in range(2,N):
    if N%i == 0: #素数ではないか計算
      return False #素数ではない場合の戻り値
  return True #すべて計算した結果該当しない（素数）の戻り値

while True: #Nが素数であり続ける場合（Nが素数）
  if prime(N):
    print(N)
    break#Nが素数である場合終了
  N +=1

Measured memory_bytes: 3316
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range, std.functional;

void main() {
    auto N = readln.chomp.to!int;
    BigInt[] times;
    foreach (i; 0..N) {
        times ~= readln.chomp.to!BigInt;
    }
    writeln(times.reduce!lcm);
}

BigInt _gcd(BigInt a, BigInt b) {
    if (b == 0) return a;
    return memoize!_gcd(b, a % b);
}

alias gcd = memoize!_gcd;

BigInt _lcm(BigInt a, BigInt b) {
    return a * b / gcd(a, b);
}

alias lcm = memoize!_lcm;


Measured memory_bytes: 380
import java.io.*;

public class Main{
    public static void main(String[]args) throws NumberFormatException, IOException {
     
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[]str= br.readLine().split(" ");
        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        int c = Integer.parseInt(str[2]);
        int i,mod=0,count=0;
        for(i=a;i<b+1;i++){
            mod=c%i;
            if(mod==0)count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 17092
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int sum = 1;
		int ans = 0;
		for (int i=0;i<100;i++) {
			if (sum>=B) {
				break;
			}
			ans++;
			sum+=A-1;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21204
/*
	0588:Simple Calculator
*/
#include	<iostream>

using namespace std;

int main(void) {
	int result, num;
	char mark;
	
	cin >> num;
	result = num;
	while(1) {
		cin >> mark;
		if(mark == '=') { break; }
		cin >> num;
		switch(mark) {
		case '+': result += num; break;
		case '-': result -= num; break;
		case '*': result *= num; break;
		case '/': result /= num; break;
		}
	}
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define fr first
#define sc scanf
#define pf printf
#define se second
#define sq(x) x * x
#define ll long long
#define pb push_back
#define mk make_pair
#define ld long double
#define pr pair<int,int>
#define sz(s) int(s.size())
#define piip pair< pair<ll,ll>,ll >
#define fin(s) freopen( s, "r", stdin )
#define fout(s) freopen( s, "w", stdout )
#define TIME ios_base::sync_with_stdio(0)
using namespace std;

const ll INF = 1e9;
const ll N = 2e2+7;
const ll mod = 1e9 + 7;
const long double eps = 1E-7;
ll a, b, n , cnt ,mx,ans,c;
ll used[ N ];
ld x , y;
string s;
char z;
int main()
{
        TIME;
        cin >> a >> b >> c;
        cout<<min(b/a,c);
}


/* MADE BY
//________________________________________________________
//________________________________________________________ //
                                                           //
// ██╗   ██╗     ██████╗     ███████╗    ██╗    ███╗   ██╗ //
// ╚██╗ ██╔╝    ██╔═══██╗    ██╔════╝    ██║    ████╗  ██║ //
//  ╚████╔╝     ██║   ██║    ███████╗    ██║    ██╔██╗ ██║ //
//   ╚██╔╝      ██║   ██║    ╚════██║    ██║    ██║╚██╗██║ //
//    ██║       ╚██████╔╝    ███████║    ██║    ██║ ╚████║ //
//    ╚═╝        ╚═════╝     ╚══════╝    ╚═╝    ╚═╝  ╚═══╝ //
//________________________________________________________ //
//________________________________________________________ */


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Grid = vector<string>;
int	main()
{
		
	int H, W;
	cin >> H >> W;
	Grid grid(H);
	for (int i = 0; i < H; ++i)
		cin >> grid.at(i);
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (grid.at(i).at(j) == '#') {
				cout << '#';
				continue;
			}
			int	count = 0;
			for (int k = -1; k < 2; ++k) {
				for (int l = -1; l < 2; ++l) {
					if (k == 0 && l == 0) continue;
					int	n_i = i + k;
					int	n_j = j + l;
					if (n_i < 0 || H <= n_i) continue;
					if (n_j < 0 || W <= n_j) continue;
					if (grid.at(n_i).at(n_j) == '#')
						++count;
				}
			}
			cout << count;
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
while True:
    H , W = map(int,input().split())
    
    if H == 0 and W == 0:
        break

    else:
        for i in range(H):
            for j in range(W):

                if i == 0 or i == H-1 or j == 0 or j == W-1 :
                    print("#",end="")
                else:
                    print(".",end="")
            
            print()

        print()


Measured memory_bytes: 7004
#include<cstdio>
int n, T;
int c[105], t[105];
int main() {
	scanf("%d%d", &n, &T);
	int i;
	int min = 1005;
	for (i = 0; i < n; i++) {
		int c, t;
		scanf("%d%d", &c, &t);
		if (t <= T && min > c) min = c;
	}
	if (min == 1005) printf("TLE");
	else printf("%d", min);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 1000000007LL;
const int Maxn = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;



int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	str s;
	cin >> s;
	ll cnt = 1;
	ll ans = 0;
	ll nw = 0;
	ll ls = Inf;
	for(auto x : s){
		if(x == '>'){
			//ls = nw;
			nw = (nw == 0 ? -1 : 0);
			cnt ++;
		} else {
			nw ++;
			cnt = 0;
			ls = nw;
		}
		ans += nw;
		if(nw == -1){
			nw ++;
			ans += cnt;
			if(cnt > ls) ans ++;
		}
		//cerr << ans << ' ' << nw << '\n';
	}
	cout << ans;
	return 0;
}



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

int N;ull* A;ull* B;ull base=10000000000007LL;

vector<pair<int,int>> rollinghash() {
  ull start_a=0LL;ull b_hash=0LL;ull bb=1LL;vector<pair<int,int>> Re(0);
  for (int i=N;i>0;i--) {
    start_a+=(A[i%N]^A[i-1])*bb;
    b_hash+=(B[i%N]^B[i-1])*bb;
    bb*=base;
  }
  if (start_a==b_hash) {
    Re.push_back(make_pair(0,(A[0]^B[0])));
  }
  ull x=start_a;
  for (int i=0;i<N-1;i++) {
    x=x*base-bb*(A[i]^A[i+1])+(A[i]^A[i+1]);
    if (x==b_hash) {
      Re.push_back(make_pair(i+1,(A[i+1]^B[0])));
    }
  }
  return Re;
}

int main() {
  cin >> N;A=new ull[N];B=new ull[N];
  for (int i=0;i<N;i++) {
    cin >> A[i];
  }
  for (int i=0;i<N;i++) {
    cin >> B[i];
  }
  vector<pair<int,int>> R=rollinghash();
  for (pair<int,int> pii:R) {
    cout << pii.first << " " << pii.second << endl;
  }
}

Measured memory_bytes: 8304
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;
    cin>>a>>b;
    if(b.size() <= a.size())
    {
        cout<<"No"<<endl;
        exit(0);
    }
    for(int i=0;i<a.size();i++)
    {
        if(a[i] != b[i])
        {
            cout<<"No"<<endl;
            exit(0);
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

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

    vector<int> A(m);
    for (int i = 0; i < m; ++i) cin >> A[i];

    ll sum{};
    for (int value : A) {
        sum += value;
    }

    cout << (n - sum >= 0 ? n - sum : -1);
    return 0;
}


Measured memory_bytes: 3612
n = int(input())
A = list(map(int,input().split()))
acm1 = 0
acm2 = 0
ans1 = 0
ans2 = 0
for i, a in enumerate(A):
  acm1 += a
  acm2 += a
  if(i%2==1):
    if(acm1>=0):
      ans1 += acm1 + 1
      acm1 = -1
    if(acm2<=0):
      ans2 += -acm2 + 1
      acm2 = 1
  else:
    if(acm1<=0):
      ans1 += -acm1 + 1
      acm1 = 1
    if(acm2>=0):
      ans2 += acm2 + 1
      acm2 = -1
print(min(ans1, ans2))

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

int main() {
    int N;
    while (cin >> N) {
        vector<int> v(N);
        for (auto& i : v) cin >> i;
        sort(v.begin(), v.end());
        vector<int> add;
        int ans = 0;
        for (auto i : v) {
            ans += i;
            add.push_back(ans);
        }

        int sum = 0;
        for (auto i : add) sum += i;
        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int n; cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];

  int ans=0;
  while(1){
    bool f=0;
    rep(i,n){
      if(a[i]%2!=0){
        f=1;
      }else{
        a[i]/=2;
      }
    }
    if(f)
    break;
    ans++;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<list>
#include<algorithm>
using namespace std;
int main()
{
	int a[8096];
	list<int> con;
	list<int>::iterator itei,itej;
	int n,i,value;
	while(scanf("%d",&n),n)
	{
		con.clear();
		fill(a,a+sizeof(a)/sizeof(a[0]),0);

		for(i=1; i<=(n-1)/2; ++i)
			con.push_back(i*i%n);
		con.sort();
		con.unique();

		for(itei=con.begin(); itei!=con.end(); ++itei)
			for(itej=con.begin(); itej!=con.end(); ++itej)
			{
				if(itei!=itej)
				{
					value = *itei - *itej;
					if(value<0) value+=n;
					if(value> (n-1)/2) value = n-value;
					++a[value];
				}
			}
		for(i=1; i<=(n-1)/2; ++i)
			printf("%d\n",a[i]);
	}

	return 0;
}

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

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

    const ll INF = (ll) 2e10 + 1;
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s;
    vector<ll> t;

    for (int i = 0; i < a; ++i) {
        s.push_back(0);
        cin >> s[i];
    }
    for (int i = 0; i < b; ++i) {
        t.push_back(0);
        cin >> t[i];
    }

    for (int i = 0; i < q; ++i) {
        ll x;
        cin >> x;
        ll s_r = INF;
        ll s_l = -INF;
        ll t_r = INF;
        ll t_l = -INF;
        auto s_r_itr = lower_bound(s.begin(), s.end(), x);
        if (s_r_itr != s.end()) {
            s_r = *s_r_itr;
        }
        if (s_r_itr != s.begin()) {
            s_l = *(s_r_itr - 1);
        }

        auto t_r_itr = lower_bound(t.begin(), t.end(), x);
        if (t_r_itr != t.end()) {
            t_r = *t_r_itr;
        }
        if (t_r_itr != t.begin()) {
            t_l = *(t_r_itr - 1);
        }

        ll sRtR = max(s_r, t_r) - x;
        ll sLtL = x - min(s_l, t_l);
        ll sRtL = s_r - t_l + min(s_r - x, x - t_l);
        ll sLtR = t_r - s_l + min(t_r - x, x - s_l);

        ll min_length = min(sRtR, min(sLtL, min(sRtL, sLtR)));

        cout << min_length << '\n';
    }

    return 0;
}


Measured memory_bytes: 3060
S=list(input())
T=list(input())

ans=''
for i in range(len(S)-len(T)+1):
  for j in range(i,i+len(T)):
    if S[j]!=T[j-i] and S[j]!='?':
      break
  else:
    ans=S[:i]+T+S[i+len(T):]
if ans=='':
  print('UNRESTORABLE')
else:
  for i in range(len(ans)):
    if ans[i]=='?':
      ans[i]='a'
  print(*ans,sep='')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
  int N;
  cin >> N;
  int A[N], B[N];

  for(int i=0; i<N; i++){
    cin >> A[i];
    if(A[i] % 2 == 0) // even                                                                                   
      B[i] = true;
    else // odd                                                                                                 
      B[i] = false;
  }

  int odd = 1;
  for(int i=0; i<N; i++){
    if(B[i] == true)
      odd *= 2;
    else
      odd *= 1;
  }

  cout << pow(3, N) - odd << endl;

  return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.random;
  
void main() {
  auto x = readln.chomp.split.map!(to!int);
  if (x[0] < x[1] && x[1] < x[2]) writeln("Yes");
  else writeln("No");
}

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

#define ll long long
#define ull unsigned long long
#define N 300005
#define mod 998244353
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define vi vector<int> 
#define vll vector<ll>
#define all(c) c.begin(),c.end()
#define tr(it,c) for( typeof(c.begin()) it = c.begin() ; it!=c.end() ; it++)

ll modulo(ll num){ return ((num%mod)+mod)%mod;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),mod-2,MOD); }

ll x,y,xx,yy ;

ll invf[N],f[N];
void pre()
{
    invf[0]=invf[1]=inv(1);
    for(ll i=2;i<N;i++)    invf[i]=(invf[i-1] * inv(i))%mod;
    f[0] = f[1]=1;
    for(ll i=2;i<N;i++)  f[i]=(f[i-1]*i)%mod;
}

ll ncr(ll n,ll r)
{
	if(r>n) return 0;
    return (f[n]*invf[r]%mod*invf[n-r]%mod)%mod;
}
int main()
{
    boost;
    pre();
    ll n,a,b,k,i,ans,j ; 
    
    cin>>n>>a>>b>>k;
    
    if(k%__gcd(a,b)) return cout<<"0",0 ;
    
    ans = 0 ;    
    for(i = 0 ; i<=n ; i++)
    {
        if(i*a > k) break ; 
        if( (k - (i*a)) % b ) continue ; 
        
        j = (k - (i*a))/b ; 
        ans += ncr(n,i) * ncr(n,j) % mod  ; 
        ans%=mod;
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 4992