akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX-5
#define MAX 10000000
#define mod 1000000007
#define pb push_back
#define mk make_pair
using namespace std;
void solve(){
	ll n,i;
  	cin>>n;
  	for (i=1000;i<=10000;i+=1000)
        if (i<n)
            continue;
        else
            break;
    cout<<i-n<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

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

#define MAX (1 << 21)
const int N = 1000;

int main() {
    int n;
    int m[N + 1][N + 1];
    int p[N + 1];
    for (int i = 1; i <= N; i++)
        m[i][i] = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i] >> p[i + 1];
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= n - i + 1; j++) {
            int k = j + i - 1;
            m[j][k] = MAX;
            for (int l = j; l < k; l++) {
                m[j][k] = min(m[j][k], m[j][l] + m[l + 1][k] + p[j - 1] * p[l] * p[k]);
            }
        }
    }
    cout << m[1][n] << endl;
    return 0;
}




Measured memory_bytes: 7004
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, a[100000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    map<int,int> m;
    for(int i=0;i<n;i++){
        if(a[i]%4==0){
            m[4]++;
        }
        else if(a[i]%2==0){
            m[2]++;
        }
        else{
            m[1]++;
        }
    }
    if(m[4]+1>=m[1]&&m[2]==0){
yes;
        return 0;
    }
    if(m[4]>=m[1]){
        yes;
        return 0;
    }
    else{
        no;
        return 0;
    }
}

Measured memory_bytes: 640
N, M = map(int, input().split())
member = [list(map(int, input().split())) for i in range(N)]  # 複数行の数値の入力

allcnt = 0
cnt = 0
exist = False
for i in range(1, M + 1):
    cnt = 0
    for j in range(0, N):
        for k in range(1, member[j][0] + 1):
            if member[j][k] == i:
                exist = True
        if exist == True:
            cnt += 1
            exist = False
    if cnt == N:
        allcnt += 1

print(allcnt)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	
		int n = Integer.parseInt(sc.next());
		char[] c = new char[n];
		String cs = sc.next();
		for(int i = 0; i < n; i++) {
			c[i] = cs.charAt(i);
		}
		
		int rcnt = 0;
		int wcnt = 0;
		for(int i = 0; i < n; i++) {
			if(c[i] == 'R') {
				rcnt++;
			}
		}
		for(int i = 0; i < rcnt; i++) {
			//System.out.println(c[i]);
			if(c[i] == 'W') {
				wcnt++;
			}
		}
		//System.out.println(rcnt);
		System.out.println(wcnt);
		

	}
}



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

min8 = (A * 25 + 1) // 2 
max8 = ((A+1) * 25 - 1) // 2
min10 = B * 10
max10 = (B+1) * 10 - 1

if min10 > max8 or min8 > max10:
	print(-1)
else:
	print(max([min8, min10]))


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

int main() {
  int a, b, k; cin >> a >> b >> k;
  int c, d;
  c = max(a, b);
  d = min(a, b);
  vector<int> cd;
  for (int i = 1; i <= d; i++) {
    if (d % i == 0 && c % i == 0) {
      cd.push_back(i);
    }
  }
  int num = cd.size() - k;
  int ans = cd.at(num);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int S = 1e6+6e1;
constexpr ll MOD = 998244353;

ll pw(ll base, ll exp) {
	ll res = 1;
	while (exp) {
		if (exp & 1) (res *= base) %= MOD;
		exp >>= 1, (base *= base) %= MOD;
	}
	return res;
}

ll inv(ll x) { return pw(x, MOD - 2); }

ll A[200002], sum[S], cur[S];

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

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

	for (int i = 0; i < N; ++i) (sum[A[i]] += A[i]) %= MOD;
	for (int i = 1; i < S; ++i) {
		for (int j = 2 * i; j < S; j += i) (sum[i] += sum[j]) %= MOD;
	}

	ll ans = 0;
	for (int i = 1; i < S; ++i) {
		ll r = (inv(i) - cur[i] + MOD) % MOD;
		(ans += (sum[i] * sum[i]) % MOD * r) %= MOD;
		for (int j = 2 * i; j < S; j += i) (cur[j] += r) %= MOD;
	}

	for (int i = 0; i < N; ++i) (ans += MOD - A[i]) %= MOD;

	cout << inv(2) * ans % MOD;
}

Measured memory_bytes: 20820
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main(){

    int i,start,end;
    string str,cmd,rp;
    char temp;
    int number;

    cin >> str >> number;

    for(i == 0; i < number; i++){
        cin >> cmd;
        if(cmd == "print"){
            cin >> start >> end;
            cout << str.substr(start, end - start + 1) << endl;
        }else if(cmd == "reverse"){
            cin >> start >> end;
            for(; start < end;start++,end--){
                temp = str[start];
                str[start] = str[end];
                str[end] = temp;                
                }
        }else if(cmd == "replace"){
                cin >> start >> end >> rp;
                str.replace(start, end - start+1, rp);
        }
    }
    return 0;
}

Measured memory_bytes: 1220
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

vector<pair<int, int>> works;
queue<pair<int, int>> works_q;

int main(void) {
    int N, M;
    cin >> N >> M;

    priority_queue<pair<int, int>> q;

    works.resize(N);
    for (int i = 0; i < N; i++) {
        int A, B;
        cin >> A >> B;
        works[i] = {A, B};
    }
    sort(works.begin(), works.end());
    for (int i = 0; i < N; i++) {
        works_q.push(works[i]);
    }

    ll acc = 0;
    int day = 1;
    while (day <= M) {
        while (!works_q.empty()) {
            auto p = works_q.front();
            if (p.first <= day) {
                q.push({p.second, p.first});
                works_q.pop();
            } else {
                break;
            }
        }

        if (!q.empty()) {
            pair<int, int> w = q.top();
            q.pop();
            acc += ll(w.first);
        }

        day++;
    }

    cout << acc << endl;

    return 0;
}


Measured memory_bytes: 3068
PROGRAM-ID.                      ABC_108_A.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 K       PIC 9(3).
    01 D       PIC 9(3).
    01 X       PIC 9(6).

    01 ans     PIC X(6).

    01 ZS      PIC Z(6)9.
    01 DUMMY   PIC X(1).

PROCEDURE                        DIVISION.
    ACCEPT K.

    DIVIDE 2 INTO K GIVING D.

    COMPUTE X = D * (K - D).

    MOVE X TO ZS
    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
    ZS DELIMITED BY ALL SPACE
    INTO DUMMY ans.


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<ll, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<ldouble, ldouble> pdd;

int n;
int d[200020][2];
int deg[200020];
vector <int> E[200020];

void dfs(int x, int fa) {
	vector <int> v;
	for(int e : E[x]) if(e != fa) dfs(e, x), v.pb(e);
	if(szz(v) == 0) {
		d[x][0] = 1;
		d[x][1] = 1;
		return;
	}
	d[x][0] = 1;
	if(szz(v) > 1) d[x][0] = 0;
	for(int e : v) {
		if(d[e][0] == 0) d[x][0] = 0;
	}
	if(d[x][0] == 1) d[x][1] = 1;
	else {
		int ok = 1;
		for(int e : v) if(d[e][0] == 1) ok = 0;
		for(int e : v) d[x][1] += d[e][1];
		if(ok == 0) d[x][1]--;
	}
}

void solve() {
	scanf("%d", &n);
	rep(i, n-1) {
		int x, y; scanf("%d%d", &x, &y); ++x; ++y;
		E[x].pb(y); E[y].pb(x);
		deg[x]++, deg[y]++;
	}
	int r = 1;
	for(int i=2;i<=n;i++) if(deg[i] > deg[r]) r = i;
	if(deg[r] <= 2) {
		puts("1");
		return;
	}
	dfs(r, -1);
	printf("%d\n", d[r][1]);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}




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


int main() {
	int N;
	cin >> N;
	vector<int>A(N +1 );
	for (int n = 0;n<N;++n) {
		cin >> A[n + 1];
	}
	vector<int>B(N + 1);
	for (int n = N;n>=1;--n) {
		int sum = 0;
		for (int m = n + n;m <= N;m += n) {
			sum += B[m];
		}
		if (A[n] == sum%2) {
			B[n] = 0;
		}
		else{
			B[n] = 1;
		}
	}
	vector<int>Ans;
	for (int n = 0; n < N; ++n) {
		if (0 != B[n + 1]) {
			Ans.push_back(n + 1);
		}
	}
	cout << Ans.size()<<endl;
	for (int n = 0; n < Ans.size(); ++n) {
		if (0 !=n) {
			cout << " ";
		}
		cout << Ans[n];
	}
	return 0;
}

Measured memory_bytes: 5400
/*
START BY THE NAME OF ALMIGHTY ALLAH


THIS WONT BE ACCEPTED
STOP_GIVING_UP

*/
#include<bits/stdc++.h>
#define l(n)for(int i=0;i<n;i++)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r,r1=0,r2=0,k,a,b,c,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0,o=0,t1=0;
    vector<long long>v;
    vector<long long>u;
    vector<long long>s;
    std::vector<int>::iterator it;

    cin>>o>>t>>t1;
    cout<<t1<<" "<<o<<" "<<t<<endl;
}


Measured memory_bytes: 256
#include <cstdio>

int head[401],nxt[200001],b[200001],k,n,h,ind[401],outd[401],f[401];
bool vis[401];
void push(int s,int t){
//	printf("push %d %d\n",s,t);
	nxt[++k]=head[s];
	head[s]=k;
	b[k]=t;
	++ind[t];
	++outd[s];
}
int find(int x){return f[x]?f[x]=find(f[x]):x;}
bool check(){
	for(int i=1;i<=h;i++)if(ind[i]>outd[i])return 0;
	for(int i=h+1;i<=(h<<1);i++)if(ind[i]<outd[i])return 0;
	for(int i=1;i<=(h<<1);i++)
		for(int j=head[i];j;j=nxt[j]){
			int u=find(i),v=find(b[j]);
			if(u!=v)f[u]=v;
		}
	for(int i=1;i<=(h<<1);i++)if(ind[i]!=outd[i])vis[find(i)]=1;
	for(int i=1;i<=(h<<1);i++)if(ind[i]&&!vis[find(i)])return 0;
	return 1;
}
int main(){
	scanf("%d%d",&n,&h);
	for(int i=1,a,b,c,d;i<=n;i++)
		scanf("%d%d%d%d",&a,&b,&c,&d),
		push((!c)?a:(h+c),(!d)?h+b:d);
	if(check())puts("YES");
	else puts("NO");
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

 
int main() {
    ll n, ans = 0;
    string s, t, u;

    cin >> n >> s >> t;

    for (int i = 0; i < n; i++) {
        u += s[i];
        u += t[i];
    }

    cout << u << endl;

    
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>

#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007

using namespace std;


void solve()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while (true)
    {
        C -= B;
        if (C <= 0)
        {
            cout << "Yes\n";
            return;
        }
        A -= D;
        if (A <= 0)
        {
            cout << "No\n";
            return;
        }
    }
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    // cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3596
N = int(input())
ans = 0
for i in range(1,N+1):
    if i % 2 ==0:
        continue
    count = 0
    for j in range(1,i+1):
        if i % j == 0:
            count = count + 1
    if count == 8:
        ans = ans + 1
print(ans)

Measured memory_bytes: 3060
a,b= map(int,input().split())

if a==0 or b==0:
    print("Zero")
    exit()

if a<=0 and 0<=b:
    print("Zero")
    exit()

if b<0:
    a=abs(a)
    b=abs(b)
    res = a-b
    if res%2==0:
        print("Negative")
    else:
        print("Positive")
else:
    print("Positive")

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

using namespace std;

int main()
{
    int k=1,d=0,n,i,x;//k=1 for d=0 included

    cin>>n>>x;

    int l[n];

    for(i=0;i<n;i++)
    {
        cin>>l[i];
        d=d+l[i];
        if(d<=x)
            k++;
    }

    cout<<k<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

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

		int n = stdIn.nextInt();
		int m = stdIn.nextInt();

		Hill hill = new Hill();
		IntStream.range(0, n).forEach(i -> hill.addTenboudai(stdIn.nextInt()));
		IntStream.range(0, m).forEach(i -> hill.addPath(stdIn.nextInt(), stdIn.nextInt()));

		System.out.println(hill.getGoodTenb());


		stdIn.close();
	}
}

class Hill {
	private List<Tenboudai> tenbList = new ArrayList<Tenboudai>();


	public void addPath(int fromIndex, int toIndex) {
		tenbList.get(fromIndex-1).addPath(toIndex);
		tenbList.get(toIndex-1).addPath(fromIndex);
	}

	public void addTenboudai(int height) {
		tenbList.add(new Tenboudai(height));
	}

	public Tenboudai getTenboudai(int index) {
		return tenbList.get(index);
	}

	public int getGoodTenb() {

		int cnt = 0;

		for (Tenboudai tenboudai : tenbList) {

			if(tenboudai.isEmptyPath()) {
				cnt++;
				continue;
			}

			int currentHeight = tenboudai.getHeight();
//			tenboudai.getPaths().stream().map(p -> tenbList.get(p-1).getHeight());
			boolean isGood = tenboudai.getPaths().stream().allMatch(p -> tenbList.get(p-1).getHeight() < currentHeight);

			if(isGood) {
				cnt++;
			}

		}

		return cnt;
	}

}

class Tenboudai {
	private int height;
	private Set<Integer> paths = new HashSet<Integer>();

	public Tenboudai(int height) {
		this.height = height;
	}

	public int getHeight() {
		return height;
	}

	public Set<Integer> getPaths() {
		return paths;
	}

	public boolean isEmptyPath() {
		return paths.isEmpty();
	}

	public void addPath(int index) {
		paths.add(index);
	}
}

Measured memory_bytes: 87180
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n-1); i >= 0; i--)
#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 repitr(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;

int main(){
	string s;
	cin >> s;
	for(unsigned int i = 0; i < s.size(); i += 2){
		if(i+1 == s.size() || s[i] != 'h' || s[i+1] != 'i'){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

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

    if (b == 1) {
        cout << 0 << endl;
        exit(0);
    }
    int cnt = 1;
    int tap = a;
    while (tap < b) {
        tap = tap-1 + a;
        cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll X, Y;
	cin >> X >> Y;
	ll ans = 0;
	if (X == 1 && Y == 1)cout << 400000+300000*2 << "\n";
	else {
		if (X <= 3)ans += (4 - X) * 100000;
		if (Y <= 3)ans += (4 - Y) * 100000;
		cout << ans << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	long long A[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		bool flg = true;
		while (flg) {
			if (A[i] % 2 == 0) {
				A[i] /= 2;
				ans++;
			}
			else {
				flg = false;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
/* -------------------------------------------------

Author :- Vaibhav Pal
College :- Northern India Engineering College, New Delhi
Coding Handle :- underdog_eagle
Title :-

----------------------------------------------------*/
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 1000000000000000000         
#define nl '\n'
#define sp ' '
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define bg begin()
#define en end()
#define fo(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)

inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

int main()
{
	FAST_IO
   /* #ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
    #endif*/

	ll n, k;
	cin >> n >> k;
	map<ll, ll> m;
	map<ll, ll>::iterator it;
	fo(i, 1, n){
		ll x;
		cin >> x;
		it = m.find(x);
		if(it != m.en) it->second++;
		else m.insert(mp(x, 1));
	}
	
	vll v;
	for(it = m.bg; it != m.en; it++) v.pb(it->second);
	sort(v.bg, v.en);
	ll y = v.size();
	ll ans = 0;
	if(y > k)
		fo(i, 0, y - k - 1) ans += v[i];
	cout << ans;
	
	
	return 0;
}

Measured memory_bytes: 14964
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    int n = 0 , k = 0 ; 
    cin >> n >> k ; 
    vector<int> height(n+1), cost(n+1, INT_MAX) ;
    for(int i = 1 ; i <= n ; i++)
        cin >> height[i] ;
    cost[1] = 0 ;
    for(int i = 2 ; i <= n ; i++)
        for(int j = 1 ; j <= k ; j++)
            if(i-j > 0)
                cost[i] = min(cost[i-j] + abs(height[i]-height[i-j]) , cost[i]) ;
    cout << cost[n] ;
}


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

string S, T;
void input(){
    cin >> S >> T;
}

void solve(){
    T.pop_back();
    if(S == T){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

int main(){
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3524
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,K; cin >> N >> K;
    vi V;
    V.eb(0);
    vi A(N);
    rep(i,N) {
        cin >> A[i];
        A[i]--;
    }
    int pos=A[0];
    map<int,int> m;
    m[0]=1;
    int cnt=1;
    while(!m[pos]){
        cnt++;
        m[pos]=cnt;
        V.eb(pos);
        pos=A[pos];
    }
    m[pos]--;
    if(K-m[pos]>0) K=(K-m[pos])%(SZ(V)-m[pos])+m[pos];
    cout << V[K]+1 << endl;
}

Measured memory_bytes: 18532
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
char a[60][60];
char b[60][60];
int m,n;
bool match(int x,int y){
rep(i,n)rep(j,n){
if(a[x+i][y+j]!=b[i][j])return 0;
}
return 1;
}
int main(){
cin>>m>>n;
rep(i,m)rep(j,m)cin>>a[i][j];
rep(i,n)rep(j,n)cin>>b[i][j];
rep(i,m-n+1)rep(j,m-n+1)if(match(i,j)){
cout<<"Yes"<<endl;
return 0;
}
cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e6;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;
signed main(){
  ios::sync_with_stdio(false);cin.tie(0);

  int K;
  cin >> K;
  int N = 0;
  int T = 1;
  for(int i = 1; i <= xx; i++) {
    N = N + (7 * T);
    N = N % K;
    T = T * 10;
    T = T % K;
    dg1(N);
    if(N == 0){
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
} 

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
  cout<<n<<endl;
  vector<int>v;
  v.push_back(n);
  set<vector<int> >se;
  while(1){LL:;
    for(int i=v.size()-1;i>=0;i--){
      if(v[i]>1){
        if(!i||v[i]>=3){
          int h=v[i]-1,p=0;
          while(v.size()>i)v.erase(v.end()-1);
          for(int j=0;j<v.size();j++)p+=v[j];
          while(1){
            v.push_back(h);
            p+=h;
            while(p+h>n)h--;
            if(!h)break;
          }
          se.insert(v);
          goto L;
        }
        else{
          v[i]--;
          if(v.size()>i+1)v[i+1]++;
          else v.push_back(1);
          goto L;
        }
      }
    }
    break;
    L:;
    for(int i=0;i<v.size()-1;i++)
      if(v[i]<v[i+1])goto LL;
    for(int i=0;i<v.size();i++){
      if(i)cout<<' ';
      cout<<v[i];
    }
    cout<<endl;
  }}
}

Measured memory_bytes: 3296
#include<iostream>
#include<map>
using namespace std;
map<int, bool> m;
int main()
{
	int n,temp,num=0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		if (m[temp] == 1)
		{
			m[temp] = 0; num--;
		}
		else
		{
			m[temp] = 1; num++;
		}
	}
	cout << num;
	return 0;
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace kyopro
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nk = Console.ReadLine().Split();
            int[] nk2 = Array.ConvertAll(nk, int.Parse);
            int n = nk2[0];
            int k = nk2[1];
            string[] s = { };
            string s2 = Console.ReadLine();
            for(int i = 0;i < n; i++)
            {
                Array.Resize(ref s, s.Length + 1);
                s[i] = s2.Substring(i,1);
            }
            string han = s[k -1].ToLower();
            for(int i = 0;i < n; i++)
            {
                if(i == k -1)
                {
                    s[i] = han;
                }
                else
                {
                    s[i] = s2.Substring(i,1);
                }
            }
            string answer = string.Join("", s);
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>

using namespace std;

int main()
{
    long long x;
    cin>>x;
    while(x!=0)
    {
        if(x%10==7)
        {
            cout<<"Yes";
            return 0;
        }
        x=x/10;
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 3620
s = input()
alp = "abcdefghijklmnopqrstuvwxyz"
if (s[0]=='A')and (s[2:-1].count('C')==1):
    s = s.replace('A','').replace('C','')
    for c in s:
        if not(c in alp):
            print("WA")
            exit()
    print("AC")
else: print("WA")

Measured memory_bytes: 3060
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}


signed main()
{ 
	speed
	int n,d,a;
	cin>>n>>d>>a;
	vector<pair<int,int>> inp(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>inp[i].x>>inp[i].y;
	}
	sort(inp.begin(),inp.end());
	vector<int> curr(n,0);
	int pres=0,ans=0;
	for(int i=0;i<n;++i)
	{
		int rem=inp[i].y-pres*a;
		rem=max(rem,0ll);
		int num=rem/a+((rem%a)!=0);
		//cout<<num<<"\n";
		ans+=num;
		int tar=inp[i].x+d+d;
		pres+=num;
		int index=lower_bound(inp.begin(),inp.end(),make_pair(tar,10000000000ll))-inp.begin();
		curr[index-1]+=num;
		pres-=curr[i];
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
#include <bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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; }

int N,maxi=0,A,x;
bool y;

int main(){
    cin>>N;
    vector<pair<int,bool>> v[N];
    rep(i,N){
        cin>>A;
        rep(j,A){
            cin>>x>>y;
            x--;
            v[i].push_back({x,y});
        }
    }
    rep(i,(1<<N)){
        bitset<15> bs(i);
        bool ok=true;
        rep(j,N){
            for(pair<int,bool> p:v[j]){
                if(bs[j]==1){
                    if(bs[p.first]!=p.second)ok=false;
                }
            }
        }
        if(ok){
            int tmp=0;
            rep(i,15)if(bs[i]==1)tmp++;
            maxi=max(maxi,tmp);
        }
    }
    out(maxi);

    
    
}


Measured memory_bytes: 384
#include <stdio.h>
 
int n;
int memo[1000][11][21]={0};
 
int main(void){
  int i,j,k,t,co=0,max;
  for(i=1;i<=999;i++){
    for(j=1;j<=10;j++){
      if(i%3==0||j%2!=0)max=20;
      else max =19;
    for(k=1;k<=max;k++){
      memo[i][j][k]=co;
      co++;
    }
    }
  }
  scanf("%d",&n);
  for(t=0;t<n;t++){
    scanf("%d%d%d",&i,&j,&k);
    printf("%d\n",196470-memo[i][j][k]);
  }
   
     
  return 0;
}





Measured memory_bytes: 2620
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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 T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB") PRINT("No");
    else PRINT("Yes");
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
    int N, M;
    cin >> N >> M;
    vector<VI> memo;
    REP(i, N){
        VI tmp;
        memo.PB(tmp);
    }

    VI P, Y;
    REP(i, M){
        int p, y;
        cin >> p >> y;
        memo[p-1].PB(y);
        P.PB(p-1);
        Y.PB(y);
    }

    REP(i, N){
        sort(ALL(memo[i]));
    }

    REP(i, M){
        int idx = lower_bound(ALL(memo[P[i]]), Y[i]) - memo[P[i]].begin();
        printf("%06d%06d\n", P[i]+1, idx+1);
    }
}

Measured memory_bytes: 7792
N = int(input())
LRs = []
for _ in range(N):
    X, L = map(int, input().split())
    LRs.append((X-L, X+L))

LRs.sort(key=lambda x: x[1])
#print(LRs)

ans = 0
RNow = -float('inf')
for L, R in LRs:
    if RNow <= L:
        ans += 1
        RNow = R

print(ans)


Measured memory_bytes: 18264
#include<bits/stdc++.h>
using namespace std;
double xp1,yp1,xp2,yp2,x,y,xp,yp,l1,r1,l2,r2,sum;
int n;
int main(){
	scanf("%lf%lf%lf%lf",&xp1,&yp1,&xp2,&yp2);
	l1=xp2-xp1;
	r1=yp2-yp1;
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		scanf("%lf%lf",&x,&y);
		l2=x-xp1;
		r2=y-yp1;
		sum=l1*r2-l2*r1;
		if(sum>0)printf("COUNTER_CLOCKWISE\n");
		else if(sum<0)printf("CLOCKWISE\n");
		     else{
		     	sum=l1*l2+r1*r2;
		     	if(sum<0)printf("ONLINE_BACK\n");
		     	else{
					if(sqrt((l1*l1)+(r1*r1))<
					   sqrt((l2*l2)+(r2*r2)))printf("ONLINE_FRONT\n");
					else printf("ON_SEGMENT\n");
				}
			 }
	}
} 


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}
// end of Template
int n,k,ans;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        int h; cin>>h;
        if(h>=k)ans++;
    }
    cout<<ans<<newl;
}


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

int main() {
  string O, E;
  cin >> O;
  cin >> E;
  if(O.size() == E.size()) {
    for(int i = 0; i < O.size(); i++) {
      cout << O.at(i) << E.at(i);
    }
  }
  else {
    for(int i = 0; i < E.size(); i++) {
      cout << O.at(i) << E.at(i);
      if(i == E.size()-1) {
        cout << O.at(O.size()-1);
      }
    }
  }
}


Measured memory_bytes: 256
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int N;
    cin >> N;
    vector<string> W(N, "");
    for (int i = 0; i < N; i++)
        cin >> W[i];

    string ans = "Yes";
    vector<string> used(1, W[0]);
    for (int i = 1; i < N; i++) {
        int flag = 1;
        int len = W[i-1].length();

        for (int j = 0; j < used.size(); j++) {
            if (W[i] == used[j]) {
                ans = "No";
                flag = 0;
            }
        }
        if (W[i][0] - W[i-1][len-1]) {
            ans = "No";
            flag = 0;
        }

        if (flag) {
            used.push_back(W[i]);
        } else {
            break;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

//=============modinv============================
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//=================================================

int main() {
  ll mod = 1e9 + 7;
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, K;
  cin >> N >> K;
  vector<pll> A(N);//0 neg, 1 pos
  for (ll i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    if (a < 0) {
      A.at(i).second = 0;
    }
    else {
      A.at(i).second = 1;
    }
    A.at(i).first = abs(a);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  bool p1_use = false, n1_use = false;
  ll p1 = 0, n1 = 0, p2 = 0, n2 = 0;
  for (ll i = 0; i < K; ++i) {
    if (A.at(i).second == 0) {
      n1 = A.at(i).first;
      n1_use = true;
    }
    else {
      p1 = A.at(i).first;
      p1_use = true;
    }
  }
  for (ll i = N - 1; i >= K; --i) {
    if (A.at(i).second == 0) {
      n2 = A.at(i).first;
    }
    else {
      p2 = A.at(i).first;
    }
  }
  ll ans = 1;
  ll cnt = 0;
  for (ll i = 0; i < K; ++i) {
    ans = (ans * A.at(i).first) % mod;
    if (A.at(i).second == 0) {
      cnt += 1;
    }
  }
  if (cnt % 2 == 0) {
    cout << ans << "\n";
    return 0;
  }
  if ((p1 * n2 == 0) && (n1 * p2 == 0)) {
    ans = 1;
    for (ll i = N - 1; i >= N - K; --i) {
      ans = (ans * A.at(i).first) % mod;
    }
    ans = mod - ans;
    ans %= mod;
    cout << ans << "\n";
    return 0;
  }
  if (n1_use && p1_use) {
    if (n1 * n2 < p1 * p2) {
      ans = ((ans * modinv(n1, mod)) % mod) * p2 % mod;
    }
    else {
      ans = ((ans * modinv(p1, mod)) % mod) * n2 % mod;
    }
  }
  else if (p1_use && (!n1_use)) {
    ans = ((ans * modinv(p1, mod)) % mod) * n2 % mod;
  }
  else {
    ans = ((ans * modinv(n1, mod)) % mod) * p2 % mod;
  }
  cout << ans << "\n";
}


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

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

Bs_and_Cs_lst = []

for _ in range(M):
    B, C = map(int, input().split())

    Bs_and_Cs_lst.append((C, B))


As_lst.sort()
Bs_and_Cs_lst.sort(reverse=True)


p = 0
finish = False
for C, B in Bs_and_Cs_lst:
    for i in range(B):
        if p + i >= N:
            finish = True
            break

        if As_lst[p+i] < C:
            As_lst[p+i] = C
        else:
            finish = True
            break
    if finish:
        break
    p += B


max_count = 0
for i in range(N):
    max_count += As_lst[i]

print(max_count)


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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

const ll MOD = 1e9 + 7;

ll exp(ll a, ll b){
    if(b == 0) return 1;
    ll tmp = exp(a, b >> 1);
    tmp *= tmp; tmp %= MOD;
    if(b & 1) tmp *= a;
    tmp %= MOD;
    return tmp;
}

ll n;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    ll res = exp(10, n) - 2 * exp(9, n) + exp(8, n);
    cout << (res%MOD + MOD)%MOD; 
    return 0;
}

Measured memory_bytes: 3648
# B
import numpy as np
h, w = map(int, input().split())
fi = np.array([['.' for _ in range(w)] for _ in range(h)])
for i in range(h):
    si = input()
    for j, s in enumerate(si):
        fi[i, j] = s
xs = [-1, 0, 1]
ys = [-1, 0, 1]
for i in range(h):
    for j in range(w):
        if fi[i, j] == '#':
            continue
        else:
            cnt = 0
            for x in xs:
                for y in ys:
                    ni = i + x
                    nj = j + y
                    if (0 <= ni <= h-1) and (0 <= nj <= w-1):
                        if fi[ni, nj] == '#':
                            cnt += 1
            fi[i, j] = str(cnt)
for row in fi:
    print(''.join(row))

Measured memory_bytes: 18228
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a, b, x;
  cin >> a >> b >> x;
  ll ax, bx;
  if(a == 0) ax = 0;
  else ax = (a-1)/x + 1;
  if(b == 0) bx = 1;
  else bx = b/x + 1;

  cout << bx - ax << endl;


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 100010;

int a[N];

int main()
{	int n;
	scanf("%d", &n);
	int Max = 0;
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n, greater<int>());
	int p = 1;
	while (p <= n && p <= a[p])
		p++;
	p--;
	int x = 1;
	while (p+x <= n && a[p+x] == p)
		x++;
	x--;
	if (((a[p]-p) & 1) || (x & 1))
		puts("First");
	else
		puts("Second");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;

const ll MOD = 1000000007;

int main() {FIN
	
	ll n, m, i, k, c = 0, a, b;
	cin >> n >> k;
	m = (n * (n + 1)) / 2;
	for (i = k - 1; i <= n; i++) {
		a = (i * (i + 1)) / 2;
		b = m - (((n - (i + 1)) * (n - (i + 1) + 1)) / 2);
		c = (c + ((b - a) + 1) % MOD) % MOD;
	}
	cout << c << "\n";
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int A,B,M;
    cin>>A>>B>>M;
    vector<int>a(A);
    vector<int>b(B);
    vector<vector<int>>m(M,vector<int>(3));
    for(int i=0;i<A;i++){cin>>a.at(i);}
    for(int i=0;i<B;i++){cin>>b.at(i);}
    for(int i=0; i<M;i++){
      cin>>m.at(i).at(0)>>m.at(i).at(1)>>m.at(i).at(2);
    }
    int minA=*min_element(a.begin(),a.end());
    int minB=*min_element(b.begin(),b.end());
    int ans=minA+minB;

    for(int i=0; i<M;i++){
      int p=a.at(m.at(i).at(0)-1)+b.at(m.at(i).at(1)-1)-m.at(i).at(2);
      ans=min(ans,p);
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6528
n,m = map(int,input().split())
data = [list(map(int,input().split())) for _ in range(m)]

_min = 1
_max = n

for d in data:
    if _min < d[0]:
        _min = d[0]
    if _max > d[1]:
        _max = d[1]

if _max >= _min:
    print(_max-_min+1)
else:
    print(0)

Measured memory_bytes: 27344
#include<stdio.h>
#include<string.h>



long long gcd(long long a, long long b) {

 
	if (a%b == 0)return b;
	else return gcd(b, (a%b));

}
int main(){
	int n,i;
	long long a[100001], b[100001] = {0}, c[100001] = { 0 },max;

	scanf("%d", &n);
	for (i = 0; i < n; i++) 

		scanf("%lld", &a[i]);
	b[0] = a[0];
	for (i = 1; i <= n-1; i++) 
		
		
				b[i] = gcd(b[i-1], a[i]);
	for (i = n - 1; i >= 0; i--)c[i] = gcd(c[i+1], a[i]);
	if (b[n-2] > c[1])max = b[n-2];
	else max = c[1];
	for (i = 1; i < n-1; i++) {
		if (max <gcd( b[i-1],c[i+1]))max = gcd(b[i-1],c[i+1]);

	}
	printf("%lld", max);
	return 0;

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  long long n,a,cnt=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    if(a!=i+1){
      cnt++;
    }
  }
  if(cnt>2){
    cout << "NO\n";
  }else{
    cout << "YES\n";
  }
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<long long> L(87);
  L.at(0) = 2;
  L.at(1) = 1;
  
  for (int i = 2; i <= 86; i++){
    L.at(i) = L.at(i - 1) + L.at(i - 2);
  }
  
  cout << L.at(N) << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N ;
  cin >> N;
  int a, b, c, d ;
  a = N /1000 ;
  b = (N - a*1000) / 100 ;
  c = (N -a*1000 - b*100) / 10 ;
  d = N % 10;
  
  if ((b == c)&&(a==b || c == d)){
  cout << "Yes" << endl ;
  }
  else{
  cout << "No" << endl ;
  }
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        if (int(floor(i * 1.08)) == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
using System;

namespace abc148C
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            long A = long.Parse(str[0]);
            long B = long.Parse(str[1]);
            long G = A;
            long H = B;
            if (A < B)
            {
                G = B;
                H = A;
            }
            else
            {
                G = A;
                H = B;
            }
            long C = G;
            long D = G;
            long E = H;
            while(C != 0)
            {
                C = D % E;
                D = E;
                E = C;
            }
            long F = (G / D) * H;
            Console.WriteLine(F);
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
int main()
{
    unsigned long long int b=0,c=1,i,t,n[100010];
    scanf("%llu",&t);
    for(i=1;i<=t;i++)
    {
        scanf("%llu",&n[i]);
        if(n[i]==0)
        {
            printf("0\n");
            return 0;
        }
    }
    for(i=1;i<=t;i++)
    {
        
        if(n[i]<=1000000000000000000/c)
        c=c*n[i];
        else
        {
            printf("-1\n");
            return 0;
        }
    }
    //scanf("%llu %llu",&a,&b);
    printf("%llu\n",c);
    return 0;
}

Measured memory_bytes: 2512