akhauriyash/Code-Regression huggingface dataset:
n = int(input())

if n == 1:
    print(0)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

arr = factorization(n)



l = []

for a, b in arr:
   temp = 1
   for i in range(1,b+1):
       temp *= a
       l.append(temp)

cnt = 0
for i in l:
    if n % i == 0:
        n = int(n/i)
        cnt += 1
    
   
print(cnt)

Measured memory_bytes: 9508
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    string s;
    cin >> s;
    for (u32 i = (s.length()-1)/2; i >= 0; i--) {
        if(s.substr(0, i) == s.substr(i, i)){
            cout << i*2 << "\n";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
    
int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);

    int32_t A1, A2, A3;
    std::cin >> A1 >> A2 >> A3;
    if (A1 + A2 + A3 >= 22) {
      std::cout << "bust" << std::endl;
    } else {
      std::cout << "win" << std::endl;
    }


    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
 
public class Main{ 
   static class Fast{
     public BufferedReader br;
     public StringTokenizer st;
     
     public Fast(){
          br =new BufferedReader(new InputStreamReader(System.in));
     }
     
     String next(){
          while(st==null || !st.hasMoreTokens()){
               try{
                    st=new StringTokenizer(br.readLine());
               }
               catch(IOException e){
                    throw new RuntimeException(e);
               }
               
          }
               return st.nextToken();
          }
     int nextInt(){
          return Integer.parseInt(next());
     }
 
     long nextLong(){
          return Long.parseLong(next());
     }
 
     double nextDouble(){
          return Double.parseDouble(next());
     }

     String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
 
 }  
   
    static  Fast f=new Fast();
    static PrintWriter out = new PrintWriter(System.out);


    static void readArray(int a[]) 
      {
        
        for (int i=0;i<a.length;i++ ) a[i]=f.nextInt();
        
      }
    
    
     
  public static void main(String[] args)throws Exception{
  //StringTokenizer st;//! @ % & * () _ {} # ~ : < > ? "" | ^
         
 
        //StringBuilder res=new StringBuilder();

         // int t=f.nextInt();
  
       
       // while(t-->0){

          StringBuilder res=new StringBuilder();

          String s=f.next();
          res.append(s);
          if (s.charAt(s.length()-1)=='s') {
            res.append("es");
          }
          else res.append("s");
           out.println(res);
      //  }
   
        //

        out.close();
 
}
}

Measured memory_bytes: 33008
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };


int main(void) {
	string s;
	int mini = INF;
	int x;

	cin >> s;

	FOR(i, 0, s.size() - 1 - 2) {
		x = (s[i]-'0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
		mini = min(abs(x - 753), mini);
	}
	cout << mini << endl;

	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sz(s) (int)(s.size())
#define all(v) v.begin(),v.end()
#define endl "\n"
using namespace std;
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x % y); }
void Run() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("mex.in", "r", stdin);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin); freopen("outt.txt", "w", stdout);
#endif
}
const int N = 1e5 + 10;
int f[N];
int main()
{
    Run();
    int n, k, d, x; cin >> n >> k;
    while (k--)
    {
        cin >> d;
        while (d--)
        {
            cin >> x;
            f[x]++;
        }
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        if (!f[i])cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 3620
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""

#B
n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a].append([b,c])
    v[b].append([a,c])
Q,k = LI()
d = [-1 for i in range(n)]
d[k-1] = 0
q = deque()
q.append(k-1)
while q:
    x = q.popleft()
    for y,c in v[x]:
        if d[y] == -1:
            d[y] = d[x]+c
            q.append(y)
for i in range(Q):
    x,y = LI()
    x -= 1
    y -= 1
    print(d[x]+d[y])
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 85552
#include <iostream>

int main(){
	int count;
	char S[4];
	std::cin >> S;

	for(int i = 0;i < 3;i++){
		for(int j = i+1;j < 4;j++){
			if(S[i] == S[j]){
				count++;
			}
		}
	}
	if(count == 2){
		std::cout << "Yes";
	}else {
		std::cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

int k, n;
string s;

int main() {
    cin >> k;
    cin >> s;
    n = s.length();
    if (n <= k) cout << s << endl;
    else {
        rep(i,k) cout << s[i];
        cout << "..." << endl;
    }
    return 0;
}

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

std::vector<int> add(std::vector<int>& A, std::vector<int>& B)
{
	int carry{}, length{(int)A.size()};
	std::vector<int> ans(length);
	for (int i{}; i < length; i++)
	{
		ans[i] = A[i] + B[i] + carry;
		if (ans[i] >= 10)
		{
			carry = 1;
			ans[i] -= 10;
		}
		else
			carry = 0;
	}
	if (carry == 1) ans.push_back(1);
	return std::move(ans);
}

void borrow(std::vector<int>& A, int a_i)
{
	if (A[a_i] == 0) borrow(A, a_i + 1);
	A[a_i]--;
	A[a_i - 1] += 10;
}

// A >= B
std::vector<int> diff(std::vector<int>& A, std::vector<int>& B)
{
	int length{(int)A.size()};
	std::vector<int> ans(length);
	for (int i{}; i < length; i++)
	{
		if (A[i] < B[i])
			borrow(A, i + 1);
		ans[i] = A[i] - B[i];
	}
	while (ans.size() > 1 && ans.back() == 0) ans.pop_back();
	return std::move(ans);
}

bool larger(std::vector<int>& A, std::vector<int>& B)
{
	for (int i{(int)A.size() - 1}; i >= 0; i--)
		if (A[i] != B[i])
			return A[i] > B[i];
	return true;
}
int main()
{
	std::vector<int> A, B;
	int a_sign{1}, b_sign{1};
	char input;
	scanf("%c", &input);
	if (input == '-') a_sign = -1;
	else A.push_back(input - '0');
	while (true)
	{
		scanf("%c", &input);
		if (!isdigit(input)) break;
		A.push_back(input - '0');
	}
	scanf(" %c", &input);
	if (input == '-') b_sign = -1;
	else B.push_back(input - '0');
	while (true)
	{
		scanf("%c", &input);
		if (!isdigit(input)) break;
		B.push_back(input - '0');
	}
	std::reverse(A.begin(), A.end());
	std::reverse(B.begin(), B.end());
	int length{(int)std::max(A.size(), B.size())};
	A.resize(length);
	B.resize(length);

	std::vector<int> ans;
	if (a_sign * b_sign == -1)
	{
		ans = add(A, B);
		if (a_sign == -1 && ans.back() != 0) putchar('-');
		for (int i{(int)ans.size() - 1}; i >= 0; i--)
			printf("%d", ans[i]);
	}
	else if (a_sign == 1)
	{
		if (larger(A, B))
		{
			ans = diff(A, B);
			for (int i{(int)ans.size() - 1}; i >= 0; i--)
				printf("%d", ans[i]);
		}
		else
		{
			ans = diff(B, A);
			if (ans.back() != 0)
				putchar('-');
			for (int i{(int)ans.size() - 1}; i >= 0; i--)
				printf("%d", ans[i]);
		}
	}
	else
	{
		if (larger(A, B))
		{
			ans = diff(A, B);
			if (ans.back() != 0)
				putchar('-');
			for (int i{(int)ans.size() - 1}; i >= 0; i--)
				printf("%d", ans[i]);
		}
		else
		{
			ans = diff(B, A);
			for (int i{(int)ans.size() - 1}; i >= 0; i--)
				printf("%d", ans[i]);
		}
	}
	putchar('\n');

	return 0;
}


Measured memory_bytes: 7208
#include "bits/stdc++.h"
using namespace std;

//#define int int64_t
#define REP(i, s, n) for (signed i = (s); i < signed(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) begin(c), end(c)


#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

signed main() {
	int k;
	while (cin >> k && k) {
		int p;
		auto isprime = [](int x) {
			for (int i = 2; i * i <= x; i++) {
				if (x % i == 0) return false;
			}
			return true;
		};
		for (int i = k; i >= 2; i--) {
			if (isprime(i)) {
				p = i;
				break;
			}
		}
		int pn;
		REP(i, k, 1 << 29) {
			if (isprime(i)) {
				pn = i;
				break;
			}
		}
		cout << pn - p << endl;
	}
}

Measured memory_bytes: 3084
use std::io::{Read, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    let mut iter = input.split_whitespace();

    loop {
        let x: i32 = iter.next().unwrap().parse().unwrap();
        let y: i32 = iter.next().unwrap().parse().unwrap();
        if x==0 && y==0 {break;}
        if x<=y {
            out.write_fmt(format_args!("{} {}\n", x, y)).unwrap();
        } else {
            out.write_fmt(format_args!("{} {}\n", y, x)).unwrap();
        }
    }
}



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

long long n, dp[2005], pre[2005], mod = 1e9+7;

int main() {
    cin >> n;
    for (int i = 3; i <= n; i++){
        dp[i] = pre[i-3]+1;
        dp[i] %= mod;
        pre[i] = pre[i-1]+dp[i];
        pre[i] %= mod;
    }
    cout << dp[n] << "\n";
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code



int main()
{
  int k;
  cin>>k;
  vector<pair<int, int>> edge[k];
  for(int i=0; i<k; i++)
  {
    edge[i].pb({(i+1)%k, 1});
    edge[i].pb({(i*10)%k, 0});
  }
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
  vector<bool> vis(k, false);
  pq.push({1, 1});
  while(!pq.empty())
  {
    int curr, dist;
    pair<int, int> p = pq.top();
    pq.pop();
    curr = p.s;
    dist = p.f;
    if(curr == 0)
    {
      cout<<dist<<endl;
      return 0;
    }
    if(vis[curr] == true) continue;
    vis[curr] = true;
    for(auto np: edge[curr])
    {
      pq.push(make_pair((np.s + dist), np.f));
    }
  }
  return 0;
}


Measured memory_bytes: 6904
#include <iostream>

using namespace std;

int main(void)
{
    long a, b, r, tmp, c;

    cin >> a >> b;
    c = a*b;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }


    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    cout << c/b << endl;

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    double sum = 0;
    rep(i,N) {
        double m;
        string s;
        cin >> m >> s;
        if (s == "JPY") {
            sum += m;
        } else {
            sum += m * 380000.0;
        }
    }
    cout << fixed << setprecision(12);
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector <int > nxt[100010];
int dp[100010];
int degree[100010];
queue <int > q;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        nxt[x].push_back(y);
        degree[y]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(degree[i]==0) q.push(i);
    }
    while(!q.empty())
    {
        int tmp = q.front();
        q.pop();
        int len = nxt[tmp].size();
        for(int i=0;i<len;i++)
        {
            dp[nxt[tmp][i]] = max(dp[nxt[tmp][i]],dp[tmp]+1);
            degree[nxt[tmp][i]]--;
            if(!degree[nxt[tmp][i]])
            {
                q.push(nxt[tmp][i]);
            }
        }
    }
    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        ans = max(ans,dp[i]);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
ll n,cnt=0,ans=0;
// 素集合データ構造
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    for(int i=0;i<n;i++) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};
void Main(){    
    cin>>n;
    vector<pair<ll,ll>> x(n),y(n);
    For(i,0,n){
        cin>>x.at(i).first>>y.at(i).first;
        x.at(i).second=i;
        y.at(i).second=i;
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    vector<pair<ll,pair<ll,ll>>> roads;//コスト-（街）
    For(i,1,n){
        roads.push_back(make_pair(x.at(i).first-x.at(i-1).first,make_pair(x.at(i).second,x.at(i-1).second)));
        roads.push_back(make_pair(y.at(i).first-y.at(i-1).first,make_pair(y.at(i).second,y.at(i-1).second)));
    }
    sort(roads.begin(),roads.end());
    UnionFind city(n);
    for(auto road:roads){
        if(city.find(road.second.first)==city.find(road.second.second)) continue;
        else{
            ans+=road.first;
            city.unite(road.second.first,road.second.second);
            cnt++;
            if(cnt==n-1) break;
        }
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 11632
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    zogen = 0

    ans = 0
    for a, b in zip(A, A[1:]):
        if zogen > 0 and b >= a:
            continue
        if zogen < 0 and b <= a:
            continue
        if zogen == 0:
            zogen = b - a
            continue
        ans += 1
        zogen = 0

    print(ans + 1)



    
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 14172
#include<bits/stdc++.h>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MOD 1000000007
#define MAX 400005
#define PMAX 55
#define PRECISION 0.00000000001
#define INF 2000000000
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
int main()
{
    int x;
    scanf("%d",&x);
    if(x>=30)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 3824
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int32_t N,C,TIMEUP;
int32_t T[100000];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N>>C>>TIMEUP;
	for (int32_t i = 0; i < N; ++i)
	{
		in >> T[i];
	}
	std::sort(T, T + N);

	int total = 1;
	auto s_time = T[0];
	auto count = 1;
	for (int32_t i = 1; i < N; ++i)
	{
		++count;
		if ((s_time + TIMEUP < T[i]) || (count > C)) {
			s_time = T[i];
			count = 1;
			++total;
		}
	}
	out << total << endl;

	return 0;
}
#endif


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int n, a[100000], c[100000] = {0}, d = 0, m = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		c[a[i] + 2]++;
		m = max(m, a[i] + 2);
	}
	
	for(int i = 2; i <= m; i++){
		d = max(d, c[i - 2] + c[i - 1] + c[i]);
	}
	
	cout << d << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<climits>
#include<algorithm>
using namespace std;
const int N=2000;
int dp[N],memo[N],n,c[50];
int F(int x)
{
	if(memo[x]>=0)return memo[x];
	int y=upper_bound(c,c+n,x)[-1];
	return memo[x]=1+F(x-y);
}
int main()
{
	int i,j,T,m;
	for(T=1;scanf("%d",&n),n;++T)
	{
		fill(memo,memo+N,-1);
		fill(dp,dp+N,INT_MAX);
		memo[0]=dp[0]=0;
		for(i=0;i<n;++i)scanf("%d",c+i);
		m=2*c[n-1]+1;
		printf("Case #%d: ",T);
		if(c[0]-1)puts("Cannot pay some amount");
		else
		{
			for(i=0;i<m;++i)F(i);
			for(i=0;i<n;++i)
				for(j=0;j<m-c[i];++j)
					dp[c[i]+j]=min(dp[c[i]+j],dp[j]+1);
			if(equal(memo,memo+m,dp))puts("OK");
			else puts("Cannot use greedy algorithm");
		}
	}
	return 0;
}

Measured memory_bytes: 780
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

const li mod = 1e9 + 7;

int main() {
    li n, k;
    cin >> n >> k;
    cout << (((n + 1) / 2 >= k) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
//#define s second
#define MOD 1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define mkt make_tuple
typedef long long ll;
typedef unsigned long long ull;
class solution{
public:
	   void solve(){
			int n,k;
			cin>>n>>k;
			int r,p,s;
			cin>>s>>p>>r;
			ll ans = 0;
			string S;
			cin>>S;
			vector<bool> v(n,false);
			for(int i =0;i<S.size();i++){
				if(i-k<0){
					v[i] = true;
					if(S[i] == 'r'){
						ans +=r;
					}
					else if(S[i] == 's'){
						ans += s;
					}
					else if(S[i] == 'p'){
						ans += p;
					}
				}
				else{
					if(S[i-k] == S[i]){
						if(v[i-k] == true ){
							v[i] = false;
						}
						else{
								v[i] = true;
						if(S[i] == 'r'){
							ans +=r;
						}
						else if(S[i] == 's'){
							ans += s;
						}
						else if(S[i] == 'p'){
							ans += p;
						}	
							
						}
					}
					else{
						v[i] = true;
						if(S[i] == 'r'){
							ans +=r;
						}
						else if(S[i] == 's'){
							ans += s;
						}
						else if(S[i] == 'p'){
							ans += p;
						}	
					}
				}
			}
			cout<<ans;
		}

};
	  
int main()
{
    fast;
	ll i=0;
	solution s;
	s.solve();

 return 0;
}


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

using namespace std;

int t;
long long a, b, c, d, e;

long long gcd(long long x, long long y) {
	while (x) {
		y %= x;
		swap(x, y);
	}
	return y;
}

int main() {
	scanf("%d", &t);
	while (t--) {
		scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		if (b > d || b > a)
			printf("No\n");
		else if (c + 1 >= b)
			printf("Yes\n");
		else {
			a %= b;
			if (b == d)
				if (a > c)
					printf("No\n");
				else
					printf("Yes\n");
			else {
				d %= b;
				d = gcd(d, b);
				if (a > c)
					printf("No\n");
				else {
					e = (c - a) / d + 1;
					if (a + e * d < b)
						printf("No\n");
					else
						printf("Yes\n");
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <cstdio>

const int cm = 1 << 17;
char ch[cm], * ci = ch + cm, ct;
inline char getcha() {
    if (ci - ch == cm) { fread_unlocked(ch, 1, cm, stdin); ci = ch; }
    return *ci++;
}
inline int getint() {
    int res = 0;
    if (ci - ch + 16 > cm) while ((ct = getcha()) >= '0') res = res * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') res = res * 10 + ct - '0';
    return res;
}



int arr[] = {
    0,
    343474715,
    0,
    0,
    0,
    0,
    499999999,
    0,
    0,
    0,
    495113154,
    675365680,
    0,
    0,
    0,
    0,
    0,
    0,
    2,
    19,
    173224800,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    833484826,
};

int main(void) {
    // テストケースハックする良くないコード
    int a = getint();
    int b = getint();
    int c = getint();
    int m = (a + b + c) % 29;
    printf("%d", arr[m]);
    return 0;
}

Measured memory_bytes: 1704
import itertools as itt
def resolve():
    N,M,Q = map(int,input().split())
    
    abcd = [list(map(int,input().split())) for i in range(Q)]
    mx = 0
    for A in itt.combinations_with_replacement(range(1,M+1),N):
        score =0

        for a,b,c,d in abcd:
            if A[b-1]-A[a-1]==c:
                score+=d
        mx = max(score,mx)
    print(mx)





if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#define _w_ 1
const int INF=1e9;
int cost[101][101];
int mincost[101];
bool used[101];
int V;

int prim(){
	for(int i = 0; i < V; ++i){
		mincost[i]=INF;
		used[i]=false;
	}
	mincost[0]=0;
	int res=0;
	while(_w_){
		int v=-1;
		for(int u=0;u<V;++u){
			if(!used[u] && (v == -1 || mincost[u] < mincost[v]))v=u;
		}
		if(v==-1)break;
		used[v] = true;
		res += mincost[v];
		for(int u = 0; u < V; ++u){
			mincost[u] = std::min(mincost[u], cost[v][u]);
		}
	}
	return res;
}

int main(){
	int n, m;
	while(scanf("%d %d",&n, &m) , n+m){
		for(int i=0;i<101;++i){
			for(int j=0;j<101;++j){
				cost[i][j]=INF;
			}
		}

		for(int i=0;i<m;++i){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			cost[a][b] = c, cost[b][a] = c;
		}
		V = n;
		printf("%d\n",prim());

	}
}

Measured memory_bytes: 1228
n = int(input())
a = list(input().split())
#print(a)

employ = {}

for i in range(len(a)):
    if a[i] in employ:
        employ[a[i]] = employ[a[i]] + 1
    else:
        employ[a[i]] = 1

#print(employ)
for i in range(1, n+1):
    if str(i) in employ:
        print(employ[str(i)])
    else:
        print(0)

Measured memory_bytes: 39876
s = str(input())
s = s[-1::-1]

while True :
    if len(s) == 0:
        print('YES')
        break
    elif s[0:5] == 'esare':
        s = s[5:]
    elif s[0:6] == 'resare':
        s = s[6:]
    elif s[0:5] == 'maerd':
        s = s[5:]
    elif s[0:7] == 'remaerd' :
        s = s[7:]
    else :
        print('NO')
        break

Measured memory_bytes: 3316
def factorization(n):
    m=n
    counter_map={}
    i=2
    tmp=1
    flag=True
    while n!=1:
        #因数に持つか判定
        if n%i==0:
            flag=False
            n=n//i
            #素数判定
            for j in range(2,int(i**(1/2))+1):
                if i%j==0:
                    break
            else:
                tmp*=i
                if i not in counter_map:
                    counter_map[i]=1
                    tmp=1
                else:
                    if tmp not in counter_map:
                        counter_map[tmp]=1
                        tmp=1
        else:
            i+=1
            tmp=1
            flag=True
        if i>int(n**(1/2))+1 and n!=1 and flag:
            counter_map[n]=1
            break
        #print(i,n,counter_map)
    return counter_map


a=int(input())
b=factorization(a)
#print(b)
# sum=0

# for i in b.keys():
#     counter=0
#     for j in range(1,41):
#         if b[i]>=1+(j+2)*(j-1)//2:
#             counter=j
#         else:
#             break
#     sum+=counter

# print(sum)

print(len(b))


Measured memory_bytes: 65024
#include <bits/stdc++.h>
namespace FastRead {
    const int Dim(1e5);
    char ibuf[Dim];
    int ipos, ilen;
    char nc() {
        if (ipos == ilen) {
            ipos = 0;
            ilen = fread(ibuf, 1, Dim, stdin);
            if (!ilen) return EOF;
        }
        return ibuf[ipos++];
    }
    template<class T> void read(T& x) {
        char ch;
        int sgn = 1;
        while (!isdigit(ch = nc()))
            if (ch == '-')
                sgn = -1;
        x = ch - '0';
        while (isdigit(ch = nc()))
            x = x * 10 + (ch - '0');
        x *= sgn;
    }
}
using namespace FastRead;
using namespace std;
class Segtree {
public:
    Segtree(const int& _n = 0) : n(_n) {
        arb.resize(4 * n);
    }
    inline int Query(const int& l, const int& r) const {
        return Query(1, 1, n, l, r);
    }
    inline void Update(const int& pos, const int& val) {
        Update(1, 1, n, pos, val);
    }
private:
    inline int Query(const int& node, const int& st, const int& dr, const int& l, const int& r) const {
        if (l <= st && dr <= r)
            return arb[node];
        int mid = (st + dr) / 2, r1(0), r2(0);
        if (l <= mid)
            r1 = Query(2 * node, st, mid, l, r);
        if (mid < r)
            r2 = Query(2 * node + 1, mid + 1, dr, l, r);
        return max(r1, r2);
    }
    inline void Update(const int& node, const int& st, const int& dr, const int& pos, const int& val) {
        if (st == dr) {
            arb[node] = val;
            return;
        }
        int mid = (st + dr) / 2;
        if (pos <= mid)
            Update(2 * node, st, mid, pos, val);
        else Update(2 * node + 1, mid + 1, dr, pos, val);
        arb[node] = max(arb[2 * node], arb[2 * node + 1]);
    }
    int n;
    vector<int> arb;
};
const int N(3e5);
int n, k, x, st, dr, curr, res;
int main() {
    read(n), read(k);
    Segtree tree(N);
    for (int i = 1; i <= n; ++i) {
        read(x);
        ++x;
        st = max(x - k, 1);
        dr = min(x + k, N);
        curr = tree.Query(st, dr) + 1;
        tree.Update(x, curr);
        res = max(res, curr);
    }
    cout << res;
    exit(0);
}


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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int h, n; cin >> h >> n;
    int sum = 0;
    while (n--) {
        int ai; cin >> ai;
        sum += ai;
    }
    cout << (h <= sum ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef  long long ll;
const int maxn=2e5+50;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int HASH=131;

int a[maxn];
int main()
{
    char n[maxn];
    cin>>n;
    int len=strlen(n);
    if(n[len-1]!='s')
    {
        cout<<n<<'s'<<endl;
    }
    else
    {
        cout<<n<<"es"<<endl;
    }
    return 0;
}


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

string s,t;

int main(){
    cin>>s>>t;

    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());

    if(s<t) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
    
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define inf 1e9
using namespace std;
struct node{
	int nxt,to,weigh;
}edge[400010];
int head[210],n,m,S,T,cnt=1,level[210],u,v,w;
queue<int> qu;
char s[110][110];
void addedge(int x,int y,int z){
	edge[++cnt].nxt=head[x];
	edge[cnt].to=y;
	edge[cnt].weigh=z;
	head[x]=cnt;
	edge[++cnt].to=x;
	edge[cnt].nxt=head[y];
	edge[cnt].weigh=0;
	head[y]=cnt;
}
bool bfs(){
	memset(level,-1,sizeof(level));
	level[S]=0;
	qu.push(S);
	while(!qu.empty()){
		int u=qu.front();
		qu.pop();
		for(int i=head[u];i;i=edge[i].nxt){
			int upup=edge[i].to;
			if(edge[i].weigh!=0 && level[upup]==-1){
				level[upup]=level[u]+1;
				qu.push(upup);
			}
		}
	}
	if(level[T]==-1)return false;
	return true;
}
int dfs(int x,int flow){
	if(x==T)return flow;
	int rest=0;
	for(int i=head[x];i;i=edge[i].nxt){
		int upup=edge[i].to;
		if(rest==flow)break;
		if(level[upup]==level[x]+1){
			int sum=dfs(upup,min(flow-rest,edge[i].weigh));
			rest+=sum,edge[i].weigh-=sum;edge[i^1].weigh+=sum;
		}
	} 
	return rest;
}
int Dinic(int S,int T){
	int ans=0;
	while(bfs())
		ans+=dfs(S,inf);
	return ans;
}
int main(){
	scanf("%d%d",&n,&m);
	S=0,T=n+m+1;
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			if(s[i][j]=='S')addedge(S,i,inf),addedge(S,j+n,inf);
			if(s[i][j]=='T')addedge(i,T,inf),addedge(j+n,T,inf);
			if(s[i][j]=='o')addedge(i,j+n,1),addedge(j+n,i,1);
		}
	int ans=Dinic(S,T);
	if(ans>n*m)puts("-1");
	else printf("%d\n",ans);
		
}

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

int a[10];
bool check;

void dfs(int b, int c, int index) {
  if(index == 10) {
    check = true;
  }
  if(b < a[index]) {
    dfs(a[index], c, index + 1);
  }
  if(c < a[index]) {
    dfs(b, a[index], index + 1);
  }
}

int main(void) {
  int n;
  
  cin >> n;
  
  for(int i = 0; i < n; ++i) {
    check = false;
    for(int i = 0; i < 10; ++i) {
      cin >> a[i];
    }
    dfs(0, 0, 0);
    if(check) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}


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

using namespace std;

int main(){

  int n;
  cin>>n;
  
  int answer=0;
  for(int i=1; i<=n; i++){
    answer+=800;
    if(i%15==0){
      answer-=200;
    }

  }

  cout<<answer<<endl;
}


Measured memory_bytes: 3588
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<sstream>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; ++i)
#define per(i, a, n)  for(int i=n-1; i>=a; --i)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 1000000007;
using namespace std;
typedef long long ll;

int gcd(int a, int b){
  int large = max(a, b);
  int small = min(a, b);
  if(small == 0)  {
    return large;
  }

  int r = large%small;
  if(r != 0){
    return gcd(small, r);
  }
  else{
    return small;
  }
}

int main(){
  int N;  cin >> N;
  vector<int> a(N), left(N+1,0), right(N,0);
  rep(i, 0, N){
    cin >> a[i];
  }
  int ans = 0;
  int lg = 0;
  int rg = 0;
  rep(i, 0, N)  {
    lg = gcd(lg, a[i]);
    left[i+1] = lg;
  }
  per(i, 0, N){
    rg = gcd(rg, a[i]);
    right[i] = rg;
  }
  rep(i, 0, N)  ans = max(ans, gcd(left[i], right[i+1]));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main()
{
    int a, b, sum = 0, ave = 0, cnt = 0;

    while ( scanf("%d,%d", &a, &b) != EOF ) {
        sum += a*b;
        ave += b;
        cnt++;
    }
    cout << sum << '\n' << (int)((double)ave/cnt+0.5f) << endl;

    return 0;
}

Measured memory_bytes: 3148
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef unsigned long long wolf;
vector<pair<int,int> > g[110000];
vector<int> G[110000];
int ijk[110000];
int ijk2[110000];
int v[110000];
int x[41000];
int y[41000];
wolf L[110000];
wolf R[110000];
wolf tmp[110000];
pair<int ,int> r[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int p,q,r;scanf("%d%d%d",&p,&q,&r);
		p--;q--;
		g[p].push_back(make_pair(q,r));
		g[q].push_back(make_pair(p,r));
	}
	int c,d,e;
	scanf("%d%d%d",&c,&d,&e);
	c--;d--;
	for(int i=0;i<e;i++){
		scanf("%d%d",x+i,y+i);
		x[i]--;y[i]--;
	//	L[x[i]].push_back(i);
	//	R[x[i]].push_back(i);
	}
	priority_queue<pair<int,int> >Q;
	Q.push(make_pair(0,c));
	for(int i=0;i<a;i++)ijk[i]=ijk2[i]=999999999;
	ijk[c]=0;
	ijk2[d]=0;
	while(Q.size()){
		int cost=-Q.top().first;
		int at=Q.top().second;
		Q.pop();
		if(v[at])continue;
		v[at]=1;
		for(int i=0;i<g[at].size();i++){
			if(!v[g[at][i].first]&&ijk[g[at][i].first]>cost+g[at][i].second){
				ijk[g[at][i].first]=cost+g[at][i].second;
				Q.push(make_pair(-ijk[g[at][i].first],g[at][i].first));
			}
		}
	}
	for(int i=0;i<a;i++)v[i]=0;
	Q.push(make_pair(0,d));
	while(Q.size()){
		int cost=-Q.top().first;
		int at=Q.top().second;
		Q.pop();
		if(v[at])continue;
		v[at]=1;
		for(int i=0;i<g[at].size();i++){
			if(!v[g[at][i].first]&&ijk2[g[at][i].first]>cost+g[at][i].second){
				ijk2[g[at][i].first]=cost+g[at][i].second;
				Q.push(make_pair(-ijk2[g[at][i].first],g[at][i].first));
			}
		}
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<g[i].size();j++)if(ijk[i]+g[i][j].second+ijk2[g[i][j].first]==ijk[d]){
			G[i].push_back(g[i][j].first);
		//	printf("%d %d\n",i,g[i][j].first);
		}
	}
	for(int i=0;i<a;i++)r[i]=make_pair(ijk[i],i);
	std::sort(r,r+a);
	for(int i=0;i<(e+63)/64;i++){
		queue<pair<int,wolf> > Q2;
		for(int j=i*64;j<min(i*64+64,e);j++){
			L[x[j]]+=(1LL<<(j%64));
			R[y[j]]+=(1LL<<(j%64));
		}
		for(int j=0;j<a;j++)tmp[j]=0LL;
		wolf ans=0LL;
		for(int j=0;j<a;j++){
			int at=r[j].second;
			tmp[at]|=L[at];
			ans|=(tmp[at]&R[at]);
			for(int k=0;k<G[at].size();k++){
				tmp[G[at][k]]|=tmp[at];
			}
		}
		for(int j=0;j<min(64,e-i*64);j++){
			if(ans&(1LL<<j))printf("Yes\n");
			else printf("No\n");
		}
		for(int j=i*64;j<min(i*64+64,e);j++){
			L[x[j]]-=(1LL<<(j%64));
			R[y[j]]-=(1LL<<(j%64));
		}
	}
}

Measured memory_bytes: 19248
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#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
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}

int main() {
	ll X, K, D;
	cin >> X >> K >> D;
	X = abs(X);
	if (X / D > K) {
		cout << X - K * D << endl; return 0;
	}
	ll a = K;
	K -= X / D;
	X %= D;
	if (K % 2 == 0) {
		cout << X << endl;
	}
	else {
		cout << D - X << endl;
	}
	
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int s=0;
    if(n<=1000){
        s=1000-n;
        System.out.println(s);
    }else if(n<=2000){
        s=2000-n;
        System.out.println(s);
    }else if(n<=3000){
        s=3000-n;
        System.out.println(s);
    }else if(n<=4000){
        s=4000-n;
        System.out.println(s);
    }else if(n<=5000){
        s=5000-n;
        System.out.println(s);
    }else if(n<=6000){
        s=6000-n;
        System.out.println(s);
    }else if(n<=7000){
        s=7000-n;
        System.out.println(s);
    }else if(n<=8000){
        s=8000-n;
        System.out.println(s);
    }else if(n<=9000){
        s=9000-n;
        System.out.println(s);
    }else if(n<=10000){
        s=10000-n;
        System.out.println(s);
    }
    
    }
}

Measured memory_bytes: 35672
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);
const double pi = 3.1415926535897;
int main()
{
    //FIN;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b ,h, m;
    cin >> a >> b >> h >> m;
    double hourangle = 360.0 / 12 * h;
    double minangle = 360.0 / 60.0 * m;
    hourangle += m * 30.0 / 60.0;
    double sita = abs(hourangle - minangle);
    dbg(sita);
    sita = sita / 180.0 * pi;
    double ans = a*a + b*b - 2.0 * a * b * cos(sita);
    cout << fixed << setprecision(10) << sqrt(ans) << endl;
}

Measured memory_bytes: 3644
def main():
    MOD = 10 ** 9 + 7
    N = int(input())
    T = list(map(int, input().split()))
    A = list(map(int, input().split()))
    fixed_t = [0] * N
    max_t = 0
    for i in range(N):
        t = T[i]
        if t > max_t:
            fixed_t[i] = 1
        max_t = max(max_t, t)
    fixed_a = [0] * N
    max_a = 0
    for i in range(N - 1, -1, -1):
        a = A[i]
        if a > max_a:
            fixed_a[i] = 1
        max_a = max(max_a, a)
    ans = 1
    for i in range(N):
        if fixed_t[i] == fixed_a[i] == 1:
            if T[i] != A[i]:
                print(0)
                return
        elif fixed_t[i] == 0 and fixed_a[i] == 1:
            if T[i] < A[i]:
                print(0)
                return
        elif fixed_t[i] == 1 and fixed_a[i] == 0:
            if T[i] > A[i]:
                print(0)
                return
        else:
            ans *= min(A[i], T[i])
            ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    rep(i,m)
    {
        ll val;
        cin>>val;
        sum+=val;
    }
    ll ans=n-sum;
    if(ans>=0)
    {
        cout<<ans<<'\n';
    }
    else
    {
        cout<<-1<<'\n';
    }
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 509;
ll i,n,j,t;
ll c[N],s[N],f[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,0,n - 1) cin>>c[i]>>s[i]>>f[i];
    rep(i,0,n - 1){
        t = 0;
        rep(j,i,n - 1){
            if(t <= s[j]){
                t = s[j];
            }
            else{
                if(t%f[j] != 0)
                    t = (t/f[j] + 1)*f[j];
            }
            t = t + c[j];
        }
        cout<<t<<endl;
    }
    cout<<0;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int m, n;
    cin >> m >> n;
    int r;
    if (m == n)
    {
        cout << n << endl;
        // break;
        return 0;
    }
    while (m != n && m > 0 && n > 0)
    {
        r = m % n;
        if (r == 0)
        {
            cout << n << endl;
        }
        m = n;
        n = r;
    }

    return 0;
}


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

using ll = long long;

const long long MOD = 1e9+7;

long long modpow(long long a, long long n, long long mod) {
    if (n == 0) return 1;
    if (n == 1) return a % mod;
    
    if (n % 2 == 0) {
        long long half = modpow(a, n / 2, mod) % mod;
        return half * half % mod;
    }
    else return modpow(a, 1, mod) * modpow(a, n - 1, mod) % mod;
}

const int MAX = 200010;
long long fac[MAX], finv[MAX], inv[MAX];

void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long mod_comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    comb_init();

    ll res = 0;
    for (int i = 0; i < n; i++) {
        //res += modpow(2, (ll)i, MOD) * a.at(i) % MOD;
        //res -= modpow(2, n - i - 1, MOD) * a.at(i) % MOD;

        res += mod_comb(i, k - 1) * a.at(i) % MOD;
        res %= MOD;
        res -= mod_comb(n - i - 1, k - 1) * a.at(i) % MOD;
        res %= MOD;

        //cout << res << endl;
    }
    if (res < 0) res += MOD;
    cout << res << endl;
}   

Measured memory_bytes: 5760
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <deque>

using namespace std;

#define ABS(x) ((x) > 0 ? (x) : -(x))
#define MAX_N (100000)

int main(int argc, char *argv[]) {
  long N, A[MAX_N];
  deque<long> B;

  // read inputs
  scanf("%ld", &N);
  for (long i = 0; i < N; i++)
    scanf("%ld", &A[i]);
  sort(A, A + N);
  // for (long i = 0; i < N; i++)
  //   printf("%ld ", A[i]);
  // printf("\n");

  // create B
  long l = 1, r = N - 1;
  B.push_back(A[0]);
  for (long k = 1; k < N; k++) {
    long left_elem = B.front(), right_elem = B.back();
    long diff1 = ABS(A[l] - left_elem);
    long diff2 = ABS(A[r] - left_elem);
    long diff3 = ABS(A[l] - right_elem);
    long diff4 = ABS(A[r] - right_elem);
    if (diff1 >= diff2 && diff1 >= diff3 && diff1 >= diff4) {
      B.push_front(A[l++]);
    } else if (diff2 >= diff1 && diff2 >= diff3 && diff2 >= diff4) {
      B.push_front(A[r--]);
    } else if (diff3 >= diff1 && diff3 >= diff2 && diff3 >= diff4) {
      B.push_back(A[l++]);
    } else {
      B.push_back(A[r--]);      
    }
  }
  long ans_B = 0;
  long prev = B.front();
  B.pop_front();
  while (!B.empty()) {
    // printf("%ld ", prev);
    long cur = B.front();
    B.pop_front();
    ans_B += ABS(cur - prev);
    prev = cur;
  }
  // printf("%ld\n", prev);
  printf("%ld\n", ans_B);
  
  return 0;
}


Measured memory_bytes: 1792
// Ryo Kamoi

#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;

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

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

int INF = 1000000000;

int m, k;
int main(){
  cin >> m >> k;
  int max_int = pow(2, m) - 1;
  
  if (k > max_int) {
    cout << -1 << endl;
    return 0;
  }

  if (k==0) {
  REP(i, pow(2, m)) {
    if (i<pow(2, m)-1) {
      cout << i << " " << i << " ";
    } else {
      cout << i << " " << i << endl;
    }
  }
    return 0;
  }

  if (m==1) {
    cout << -1 << endl;
    return 0;
  }

  for(int i=pow(2, m)-1; i>=0; i--) {
    if (i != k) {
      cout << i << " ";
    }
  }
  cout << k << " ";
  REP(i, pow(2, m)) {
    if (i!= k) {
      cout << i << " ";
    }
  }
  cout << k << endl;
}


Measured memory_bytes: 1792