akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n >= 30) System.out.println("Yes");
        else System.out.println("No");
        sc.close();
    }
}

Measured memory_bytes: 35612
from itertools import combinations

_ = input()
k, *B = map(int, input().split())
for v, combi in sorted([((sum([1 << cc for cc in c])), ' '.join(map(str, c))) for i in range(k + 1) for c in combinations(B, i)]):
    print(f'{v}: {combi}' if v else '0:')




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

int main(void) {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;

  int n = s.size();
  int answer = n;
  for (char c = 'a'; c <= 'z'; ++c) {
    int seq = 0;
    int max_seq = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] == c) {
        max_seq = max(max_seq, seq);
        seq = 0;
      } else {
        ++seq;
      }
    }
    max_seq = max(max_seq, seq);
    answer = min(answer, max_seq);
  }
  
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define N 10000011

using namespace std;
const int INF = (int)1e18;

int n, k, h[N], opt[N];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n >> k;
	for(int i=0; i<n; i++) cin >> h[i+1];
	opt[n] = 0;
	for(int i=n-1; i; i--) {
		opt[i] = INF;
		for(int j=0; j<k; j++) {
			if(i + j + 1 > n) break;
			opt[i] = min(opt[i], opt[i+j+1] + abs(h[i] - h[i+j+1]));
		}
	}
	cout << opt[1] << endl;
	return 0;
}

Measured memory_bytes: 3072
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "MyDisjointset.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
typedef pair<int, int> P; typedef long long int ll;
const int INF = 10000000;
int n, e;
int d[15][15], dp[1 << 15][15];
int main() {
	cin >> n >> e;
	fill(d[0], d[15], INF);
	fill(dp[0], dp[1 << 15], INF);
	for (int i = 0; i < e; i++) {
		int s, t, dis; cin >> s >> t >> dis;
		d[s][t] = dis;
	}
	dp[(1 << n) - 1][0] = 0;
	for (int i = (1 << n) - 2; i >= 0; i--)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++)
				if (!(i >> k & 1))
					dp[i][j] = min(dp[i][j], dp[i | 1 << k][k] + d[j][k]);
	if (dp[0][0] >= INF) cout << -1 << endl;
	else cout << dp[0][0] << endl;
	return 0;
}

Measured memory_bytes: 5012
# Nまでの素数を列挙
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError("n is int type.")
    if n < 2:
        raise ValueError("n is more than 2")
    prime = [2]
    limit = int(n ** 0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


# if __name__ == '__main__':
# data = get_sieve_of_eratosthenes(100)
# print(' '.join(map(str, data)))
# print("2～{0}までで以上が素数です\n".format(100))


N = int(input())
P = get_sieve_of_eratosthenes(55555)
cnt = 0
for p in P:
    if p % 5 == 1:
        print(p)
        cnt += 1
    if cnt == N:
        break


Measured memory_bytes: 10652
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	ans := 9999999999999
	for i := 0; i < len(s)-2; i++ {
		n, _ := strconv.Atoi(s[i : i+3])
		if abs(753-n) < ans {
			ans = abs(753 - n)
		}
	}
	fmt.Println(ans)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("YES\n"):printf("NO\n");
// }}} 2

// }}} 1

int main() {

    char S[100003], T[100004];
    int Q;

    Scs( S );
    Scs( T );

    int s[100003] = {};
    int t[100003] = {};

    for( ll i = 1; S[i-1]; i++ ){
        s[i] += S[i-1] == 'A' ? 1 : 2;
        s[i+1] += s[i];
    }
    for( ll i = 1; T[i-1]; i++ ){
        t[i] += T[i-1] == 'A' ? 1 : 2;
        t[i+1] += t[i];
    }

    int a,b,c,d;
    bool ans = 0;

    Scd(Q);
    while( Q-- ){
        Scd2(a,b);
        Scd2(c,d);

        ans = ( s[b] - s[a-1] )%3 == ( t[d] - t[c-1] )%3;
        YesNo( ans );

    }

    return 0;
}

/*
 * A
 * BB
 * BBBBB
 * BBBBBBBB
 * AAAA
 * AAAAAAA
 * AAAAAAAAAA
 * AAB
 *
 * 1 -> 2 2
 * 1 -> 1 0
 *
 * AB
 * AAA
 * AAAAAA
 * BBB
 * BBBBBB
 * []
 *
 * 1 A      BB
 * 2 AA     B
 * 0 AAA    BBB
 * 1 AAAA   BBBBB
 * 2 AAAAA  BBBB
 * 0 AAAAAA BBBBBB
 *
 * ///MOD 3///
 *
 */



Measured memory_bytes: 1536
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;

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

int main(){
    char str[28];
    bool al[26], isdif = true;
    scanf("%s", str);
    int n = strlen(str);
    fill_n(al, 26, false);

    REP(i,n){
        int index = str[i] - 'a';
        if(al[index]) isdif = false;
        else al[index] = true;
    }
    printf("%s", isdif ? "yes" : "no");
    return 0;
}

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

int main(){
    int n,m; cin>>n>>m;
    vector<string> a(n);
    vector<string> b(m);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<m;i++) cin>>b[i];

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i+m-1>=n||j+m-1>=n) continue;
            bool c=true;
            for(int k=0;k<m;k++){
                for(int l=0;l<m;l++){
                    if(a[i+k][j+l]!=b[k][l]) c=false;
                }
            }
            if(c){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
def f(x):
    if x>=0:
        return x
    else:
        return -x
a=int(input())
b,c=(map(int,input().split(" ")))
d=list(map(int,input().split(" ")))
e=float("inf")
g=0
for x in range(1,len(d)+1):
    if e>=f(c-(b-d[x-1]*0.006)):
        e=f(c-(b-d[x-1]*0.006))
        g=x
print(g)

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

#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	while(cin >> n >> m){
		vector<int>v[n+5];
		f(n){
			fr(j,0,m){
				int add;
				cin >> add;
				v[i].pb(add);
			}
		}	
		int ans = 0;
		f(n){
			fr(j,i+1,n){
				int sum = 0;
				fr(k,0,m){
					sum += ((v[i][k]-v[j][k])*(v[i][k]-v[j][k]));
				}
				if((int)sqrt(sum)*(int)sqrt(sum)==sum)ans++;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
//#define GBN_USE_C
#ifdef GBN_USE_C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#else
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#endif

#define rep(i,n) for(int i = 0; i < (n); ++i)
 
typedef long long ll;
typedef char str255[256];

#define BIG_PRIME 1'000'000'007
#define BP_remainder(x) ((x) % BIG_PRIME)

const int INF = 1 << 30;
const int INF_NEG = INF * -1;
const ll INF_LONG = 1LL << 62;
const ll INF_LONG_NEG = INF_LONG * -1;

int main()
{
    int K, N; cin >> K >> N;
    vector<int> A(N + 9); rep(i, N) cin >> A[i];
    int distMin = A[N - 1] - A[0];
    for (int i = 1; i < N; ++i){
        distMin = min(distMin, K - (A[i] - A[i - 1]));
    }
    cout << distMin << endl;


    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll   long long int  
#define pb push_back
const int M=1e9 + 7;
using namespace std;
int N=1000000+1;
int main() {
   
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    ll W;cin>>W;
    int* v=new int[n+1];
    int* w=new int[n+1];
    int totV=0;
    for(int i=1;i<=n;i++)
    {
    	cin>>w[i]>>v[i];
    	totV+=(v[i]);
	}
	ll** dp=new ll*[n+1];
	for(int i=0;i<=n;i++)
	{
		dp[i]=new ll[totV+1];
		for(int j=0;j<=totV;j++)
		{
			dp[i][j]=INT_MAX;
		}
	}
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=totV;j++)
		{
			if(i==0 )
			{
				//dp[i][j]=0;
				continue;
			}
			if(j>=v[i])
			{
				dp[i][j]=min(w[i]+dp[i-1][j-v[i]],dp[i-1][j]);
			}else{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	int ans;
	//for(int i=0;i<=n;i++)
	//{
		for(int j=0;j<=totV;j++)
		{
			if(dp[n][j]<=W)
			{    
			    
				ans=j;
			}
	
		}
	//}
	cout<<ans<<endl;
	return 0;
}










Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P = pair<ll,ll>;
const ll INF = ll(1e18)+5;
const string YES = "POSSIBLE";
const string NO = "IMPOSSIBLE";

int main() {
    ll N,M;
    cin >> N >> M;
    vector<vector<ll>> graph(N);
    for(int i=0;i<M;i++){
        ll a,b;
        cin >> a >> b;
        --a;--b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<ll> d(N,INF);
    queue<ll> q;
    q.push(0);
    d[0] = 0;
    while(!q.empty()){
        ll p = q.front();q.pop();
        // cerr <<"p=" << p << endl;
        for(ll child:graph[p]){
            // cerr <<"child=" << child << endl;
            if(d[child] == INF){
                d[child] = d[p] + 1;
                q.push(child);
            }
        }
    }
    // cerr <<"dN=" << d[N-1] << endl;
    if(d[N-1] <=2){
        cout << YES << endl;
    }else{
        cout << NO <<endl;
    }
    return 0;
}

Measured memory_bytes: 15208
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using lond = long double;

int main(){
	string s;

	cin >> s;
	//cout << s.compare("ABC");
	if (s.compare("ABC")==0){
		cout << "ARC" << endl;
	}
	else
		cout << "ABC";

	return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>

int main()
{
    long long int  w,h,ans,x,y;
    scanf("%lld %lld %lld %lld",&w,&h,&x,&y);
    printf("%f ",w*h/2.0);
    if(w%2==0 && w/2 == x && h%2==0 && h/2==y) printf("1");
    else printf("0");
}


Measured memory_bytes: 128
f = lambda: map(int,input().split())

a,b,c,x,y = f()
if x<=y:
    print(min(2*c,a+b)*x + min(2*c,b)*(y-x))
else:
    print(min(2*c,a+b)*y + min(2*c,a)*(x-y))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s, alphabet = "abcdefghijklmnopqrstuvwxyz"; cin >> s;
  set<char> appeared;
  int size = s.size();
  for(int i = 0; i < size; i++) {
    appeared.insert(s.at(i));
  }
  bool noneornot = 0;
  char firstfound;
  for(int i = 0; i < 26; i++) {
    if(!(appeared.count(alphabet.at(i)))) {
      noneornot = 1;
      firstfound = alphabet.at(i);
      break;
    }
  }
  if(noneornot) {
    cout << firstfound << endl;
  }
  else {
    cout << "None" << endl;
  }
}

Measured memory_bytes: 3660
n,h=map(int,input().split())
l=[tuple(map(int,input().split())) for _ in range(n)]
th=max(l,key=lambda x:x[0])[0]
l=sorted([i for i in l if i[1]>=th],key=lambda x:-x[1])
c,v=0,0
for i in l:
  if v<h:
    v+=i[1]
    c+=1
if v<h:
  a,b=divmod(h-v,th)
  if b:a+=1
  c+=a
print(c)

Measured memory_bytes: 22788
import java.util.Scanner;

public class Main {

    public static String process(int N, int K, String S) {
        return S.substring(0, K - 1) + S.substring(K - 1, K).toLowerCase() + S.substring(K);
    }

    // Util func

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        String S = sc.next();

        final String result = process(N, K, S);

        output(result);
    }

    private static void output(String result) {
        System.out.println(result);
    }
}


Measured memory_bytes: 23252
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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





string n;
ll d;
ll dp[10005][2][105];

ll rec(ll k, bool tight, ll sum){
    if(k == n.size()) return sum == 0;
    
    ll x = n[k] - '0';
    ll r = tight? x : 9;
    
    ll &res = dp[k][tight][sum];
    if(~res) return res;
    res = 0;
    
    for(ll i = 0; i <= r; i++){
        res += rec(k + 1, tight && i == r, (sum + i) % d);
        res %= MOD;
    }
    
    return res;
}

int main() {
    cin >> n >> d;
    memset(dp, -1, sizeof(dp));
    cout << (rec(0, true, 0) - 1 + MOD) % MOD << endl;
}


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

typedef long long ll;

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

const int N = 1e5 + 5;
ll dp[N][2], h[N];
int n;

ll solve(int n, int f) {
    if (n == 1) return 0;
  	if (n == 0) return 1e18;
    if (dp[n][f - 1] != -1) return dp[n][f - 1];
    dp[n][f - 1] = 1e18;
    return dp[n][f - 1] = min(abs(h[n] - h[n - f]) + solve(n - f, 1), abs(h[n] - h[n - f]) + solve(n - f, 2));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    memset(dp, -1, sizeof(dp));
    ll ans = min(solve(n, 1), solve(n, 2));
    cout << ans;
    
    return 0;
}


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

int main(void)
{
  std::vector<char> vc(4);
  for(auto& c : vc) std::cin >> c;

  int res{1};
  for(auto it = vc.begin(); it != vc.end(); ++it)
    if(std::next(it) != vc.end() && *it == *std::next(it)) res = false;

  auto ans = res ? "Good" : "Bad";
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
from itertools import groupby as gb
l=[(a,len(list(b))) for a,b in gb(list(input()))]
ret=[]
for q,w in zip(l[::2],l[1::2]):
    a,b=q[1],w[1]
    ret+=[0]*(a-1)+[b//2-(-a//2),a//2-(-b//2)]+[0]*(b-1)
print(*ret,sep=" ")


Measured memory_bytes: 13500
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
signed main()
{
    fast;
    int n;
    cin>>n;
    int ans = 0;
    int d[n+1];
    for(int i=1;i<=n;i++)
        cin>>d[i];
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            ans+=(d[i]*d[j]);
        }
    }
    cout<<ans;
}   

Measured memory_bytes: 256
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			String[] ss = sc.next().split(",");
			double[] X = new double[4];
			double[] Y = new double[4];
			for (int i = 0; i < 8; i += 2) {
				X[i / 2] = Double.parseDouble(ss[i]);
				Y[i / 2] = Double.parseDouble(ss[i + 1]);
			}
			System.out.println(solve(X, Y));
		}
	}

	String solve(double[] X, double[] Y) {
		boolean dirs[] = new boolean[4];
		for (int i = 0; i < 4; i++) {
			int j = (i + 1) % 4;
			int k = (i + 2) % 4;

			dirs[i] = cross(X[j] - X[i], Y[j] - Y[i], X[k] - X[i], Y[k] - Y[i]);
		}
		boolean yes = true;
		for (int i = 1; i < 4; i++)
			if (dirs[i - 1] != dirs[i])
				yes = false;
		return yes ? "YES" : "NO";
	}

	boolean cross(double x1, double y1, double x2, double y2) {
		return (x1 * y2 - x2 * y1) >= 0;
	}

}

Measured memory_bytes: 11000
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

t=int(input())
nabcd=[list(map(int,input().split())) for i in range(t)]

for i in range(t):
    n,a,b,c,d=nabcd[i]
    lst=[-n]
    coin=defaultdict(lambda: float('inf'))
    coin[n]=0
    dic={}
    while lst:
        now=-heapq.heappop(lst)
        # print(now)
        # print(lst)
        if now==1:
            coin[0]=min(coin[0],coin[now]+d)
            break

        if now in dic:
            continue
        else:
            dic[now]=1
    
        if now%2==0:
            heapq.heappush(lst,-now//2)
            coin[now//2]=min(coin[now//2],coin[now]+min(a,now//2*d))
        else:
            heapq.heappush(lst,-(now+1)//2)
            coin[(now+1)//2]=min(coin[(now+1)//2],coin[now]+min(a+d,(now-(now+1)//2)*d))
            if (now-1)//2>0:
                heapq.heappush(lst,-(now-1)//2)
                coin[(now-1)//2]=min(coin[(now-1)//2],coin[now]+min(a+d,(now-(now-1)//2)*d))

        for j in range(3):
            if (now+j)%3==0:
                if j==0:
                    heapq.heappush(lst,-(now+j)//3)
                    coin[(now+j)//3]=min(coin[(now+j)//3],coin[now]+min(b+j*d,(now-(now+j)//3)*d))
                    # print(coin[now]+min(b+j*d,(now-(now+j)//3)*d))
                else:
                    heapq.heappush(lst,-(now+j)//3)
                    coin[(now+j)//3]=min(coin[(now+j)//3],coin[now]+min(b+j*d,(now-(now+j)//3)*d))
                    if (now+j-3)//3>0:
                        heapq.heappush(lst,-(now+j-3)//3)
                        coin[(now+j-3)//3]=min(coin[(now+j-3)//3],coin[now]+min(b+(3-j)*d,(now-(now+j-3)//3)*d))
        
        for j in range(5):
            if (now+j)%5==0:
                if j==0:
                    heapq.heappush(lst,-(now+j)//5)
                    coin[(now+j)//5]=min(coin[(now+j)//5],coin[now]+min(c+j*d,(now-(now+j)//5)*d))
                else:
                    heapq.heappush(lst,-(now+j)//5)
                    coin[(now+j)//5]=min(coin[(now+j)//5],coin[now]+min(c+j*d,(now-(now+j)//5)*d))
                    if (now+j-5)//5>0:
                        heapq.heappush(lst,-(now+j-5)//5)
                        coin[(now+j-5)//5]=min(coin[(now+j-5)//5],coin[now]+min(c+(5-j)*d,(now-(now+j-5)//5)*d))
        # print(now,lst,coin)
    print(coin[0])

Measured memory_bytes: 107344
package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}
	gcd := func(a, b int) int {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}
	const mod int = 1e9 + 7
	pow := func(n int) int {
		res, x := 1, 2
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}

	type pair struct{ x, y int }
	var n, x, y int
	Fscan(in, &n)
	cnt := map[pair]int{}
	cnt2 := map[pair]int{}
	cntO := 0
	for i := 0; i < n; i++ {
		Fscan(in, &x, &y)
		if x == 0 && y == 0 {
			cntO++
			continue
		}
		if y < 0 {
			x = -x
			y = -y
		} else if y == 0 {
			x = abs(x)
		}
		g := gcd(abs(x), y)
		x /= g
		y /= g
		if x > 0 {
			cnt[pair{x, y}]++
		} else {
			cnt2[pair{y, -x}]++
		}
	}

	ans := 1
	for p, c := range cnt {
		ans = ans * (pow(c) + pow(cnt2[p]) - 1) % mod
		delete(cnt2, p)
	}
	for _, c := range cnt2 {
		ans = ans * (pow(c)) % mod
	}
	Fprintln(out, (ans+cntO-1+mod)%mod)
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 18364
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
int main() {
	int H, W, N, p = 0;
	cin >> H >> W >> N;
	vector<int> a(N);
	vector<vector<int>> c(H, vector<int>(W));
	rep(i, 0, N) {
		cin >> a[i];
		rep(i2, 0, a[i]) {
			c[p / W][p % W] = i + 1;
			p++;
		}
	}
	rep(i, 0, H) {
		if (i % 2)reverse(all(c[i]));
		rep(i2, 0, W)printf(i2 == W - 1 ? "%d\n" : "%d ", c[i][i2]);
	}
	return 0;
}


Measured memory_bytes: 384
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
//typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void printvi(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
void printvil(vector<int> v){rep(i,0,v.size()){cout<<v[i]<<endl;}}
void printvvi(vector<vector<int>> v){
    rep(i,0,v.size()){
        rep(j,0,v[i].size()){
            if(j)cout<<" ";
            cout<<v[i][j];
        }
        cout<<endl;
    }
}
void printvstr(vector<string> v){
    rep(i,0,v.size()){
        cout<<v[i]<<endl;
    }
}

signed main (){
    map<int,int> mp;
    mp[1]=6000;
    mp[2]=4000;
    mp[3]=3000;
    mp[4]=2000;
    rep(i,0,4){
        int t,x;
        cin>>t>>x;
        cout<<mp[t]*x<<endl;
    }

    
}
/*
*/



Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int main(void){
    int a=0;
    int b=0;
    int c=0;

    cin >> a >> b >> c;

    if(a==b)cout << c << endl;
    else if(b==c)cout << a << endl;
    else if(c==a)cout << b << endl;

    return 0;
}


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

int main()
{
   char S[100001]={'\0'};
   scanf("%s",S);
   int count=0;
   for (int i =0;i<strlen(S)-1;i++)
   {
    if (S[i]==S[i+1])
    {
        count++;
        if (S[i+1]=='0')S[i+1]='1';
        else S[i+1]='0';

    }

   }

   printf("%d",count);
    return 0;
}


Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  map<int, vector<int>> mp;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    mp[a].push_back(b);
  }
  priority_queue<int> pq;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    for (auto &el : mp[i]) {
      pq.push(el);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << "\n";
}



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

int n, l;
int a[100000];
int t[100000];	//t[i] = ?????????i??????????§?????????????

int main() {
	int i;
	
	cin >> n >> l;
	for (i = 0; i < n; i++) cin >> a[i];
	
	//Left -> Left + 1
	for (i = 1; i < n; i++) {
		if (a[i-1] > a[i]) {
			t[i] = t[i-1] + l - a[i-1];
		}
	}
	
	//Right -> Right - 1
	for (i = n - 2; i >= 0; i--) {
		if (a[i] < a[i+1]) {
			t[i] = max(t[i], t[i+1] + l - a[i+1]);
		}
	}
	
	int ans = 0;
	for (i = 0; i < n; i++) {
		ans = max(ans, t[i] + l - a[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int> dataa(N), datab(N);
  string S;
  cin >> S;
  int counta = 0, countb = 0;
  for(int i = 0; i < N; i++){
    if(S.at(i) == 'E')counta++;
    else countb++;
    dataa.at(i) = counta;
    datab.at(i) = countb;
  }
  int ans = 1000000000;
  for(int i = 0; i < N; i++){
    if(S.at(i) == 'E')ans = min(ans, dataa.at(N - 1) - dataa.at(i) + datab.at(i));
    else ans = min(ans, dataa.at(N - 1) - dataa.at(i) + datab.at(i) - 1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3204
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.StringTokenizer

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val A = sc.nextInt()
    val B = sc.nextInt()
    val M = sc.nextInt()

    val a = Array(A) { sc.nextInt() }
    val b = Array(B) { sc.nextInt() }
    var best = a.min()!! + b.min()!!

    repeat(M) {
        val x = sc.nextInt() - 1
        val y = sc.nextInt() - 1
        val c = sc.nextInt()
        val new = a[x] + b[y] - c
        if (best > new) best = new
    }

    println(best)

}


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 63144
#include <bits/stdc++.h>
#define INF (1LL << 60)
#define int long long
#define magic 100000
using namespace std;

int dp[101][100001]; // object, value
// dp[i][j] : using first i items, value j, least weight
int32_t main(){
	int n, w;
	cin >> n >> w;
	for(int i = 0; i <= 100; i++){
		for(int j = 1; j <= 100000; j++){
			dp[i][j] = INF;
		}
	}
	for(int i = 1; i <= n; i++){
		int v_i, w_i;
		cin >> w_i >> v_i; 
		for(int j = 1; j <= magic; j++){
			// exclude the i th item
			dp[i][j] = min(dp[i][j], dp[i - 1][j]);
			// include the i th item
			if(j >= v_i)
				dp[i][j] = min(dp[i][j], dp[i - 1][j - v_i] + w_i);
		}
	}
	int res = 0;
	for(int i = 1; i <= magic; i++){
		if(dp[n][i] <= w){
			res = i;
		}
	} 
	cout << res;
}

Measured memory_bytes: 79104
#include<stdio.h>
#include<math.h>
int main()
{
	long long int n,d,i,c=0,x,y;
	
	scanf("%lld %lld",&n,&d);
	while(n--)
	{
		scanf("%lld %lld",&x,&y);
		if(((x*x)+(y*y))<=d*d)
		{
			c++;
		}
		
		
	}printf("%lld\n",c);
}

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

#include <math.h>
#define PI 3.14159265358979323846264338327950L
const int mxN = 1e9 + 7;

char s[100005];
long long dp[100005][13];

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> b(n);
    set<int> s;
    for (int i = n - 1; i >= 0; i--) {
        int cnt = 0;
        for (int j = i; j < n; j+= i+1) {
            cnt += b[j];
        }
        if (cnt % 2 != a[i]) {
            b[i] = 1;
            s.insert(i + 1);
        }
    }
    bool ok = true;
    for (int i = n - 1; i >= 0; i--) {
        int cnt = 0;
        for (int j = i; j < n; j+= i+1) {
            cnt += b[j];
        }
        if (cnt % 2 != a[i]) ok = false;
    }
    if (ok) {
        cout << s.size() << "\n";
        for (auto x : s) cout << x << " ";
    }
    else {
        cout << -1;
    }
    return 0;
}

Measured memory_bytes: 10400
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int a,b,n,a1,b1;
	cin>>n>>a>>b;
	a1=a-n;
	b1=b-n;
	if (a1<0)
	{
		a1=a1*-1;
	}
	if (b1<0)
	{
		b1=b1*-1;
	}
	if (a1<b1)
	{
		cout<<"A"<<endl;
	}
	else
	{
		cout<<"B"<<endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    int a[7]={1,3,5,7,8,10,12};
    int b[4]={4,6,9,11};
    bool f=0;
    for(int i=0;i<7;i++)
    {
        if(a[i]==x)
            for(int j=0;j<7;j++)
        {
            if(a[j]==y)
                f=1;
        }
    }
    for(int i=0;i<4;i++)
    {
        if(b[i]==x)
            for(int j=0;j<4;j++)
        {
            if(b[j]==y)
                f=1;
        }
    }
    if(f==1)
    {
        cout<<"Yes"<<endl;
    }
    else if(x==2&&y==2)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009

void solve()
{
	ll n,m ;
	rl2(n,m);
	string str;
	cin>>str;
	ll p=SZ(str)-1;
	VL ans;
	while(p!=0)
	{
		bool ok=false;
		frr(i,m+1,1)
		{
			if(p-i<0)continue;
			if(str[p-i]=='1')continue;
			p-=i;
			ans.PB(i);
			ok=true;
			break;
		}
		if(!ok)
		{
			cout<<-1<<endl;
			return;
		}
	}
	reverse(ALL(ans));
	fr(i,0,SZ(ans))
	{
		cout<<ans[i]<<" ";
	}
	NL;
	return;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 1528
program main
	implicit none
    integer::n,i,j
    integer,allocatable::a(:),b(:),c(:,:)
    read(*,*) n
    allocate(a(n))
    allocate(b(n))
    read(*,*) a
    read(*,*) b
    allocate(c(2,n))
    c(1,1)=a(1)
    do j=2,n
        c(1,j)=c(1,j-1)+a(j)
    end do
    c(2,1)=a(1)+b(1)
    do i=2,n
    	c(2,i)=max(c(1,i),c(2,i-1))+b(i)
    end do
    write(*,*) c(2,n)
    deallocate(a)
    deallocate(b)
    deallocate(c)
    stop
end program main




Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long
ll read()
{
	ll tmp=0;char c=getchar(),f=1;
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){tmp=tmp*10+c-48;c=getchar();}
	return tmp*f;
}
using namespace std;
ll a[100010];
int n;
int main()
{
	int i;
	n=read();
	for(i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1); a[n+1]=0;
	int last=1,ans=0;
	for(i=1;i<=n+1;i++)
		if(a[i]!=a[last]){
			ans+=(i-last)%2;
			last=i;
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            final long N  = sc.nextLong();
            final long A  = sc.nextLong();
            final long B  = sc.nextLong();

            long kurikaesi = N / (A+B);
            long amari = N % (A+B);

            long tsuika = 0;
            if (amari > A) {
                tsuika = A;
            } else {
                tsuika = amari;
            }

            System.out.println(kurikaesi * A + tsuika);
        } finally {
            sc.close();
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
	int n,l;
	cin >> n >> l;
	vector <string> v(n);
	rep(i,n) cin >> v[i];
	sort(v.begin(), v.end());
	rep(i,n) cout << v[i];
	cout << endl;
}


Measured memory_bytes: 256
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    if (k == 1) cout << 0;
    else cout << n - k;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
n = int(input())
s = [input() for i in range(n)]
st = [0,0,0,0,0]
p = [0,0,0,0,0,0,1,1,1,2]
q = [1,1,1,2,2,3,2,2,3,3]
r = [2,3,4,3,4,4,3,4,4,4]
ans = 0

for i in range(n):
    if s[i][0] == 'M':
        st[0] += 1
    elif s[i][0] == 'A':
        st[1] += 1
    elif s[i][0] == 'R':
        st[2] += 1
    elif s[i][0] == 'C':
        st[3] += 1
    elif s[i][0] == 'H':
        st[4] += 1

for i in range(10):
    ans += st[p[i]]*st[q[i]]*st[r[i]]

print(ans)


Measured memory_bytes: 57688
text = input()
for i in range(int(input())):
    ls = list(input().split())
    command = (ls[0])
    a = int(ls[1])
    b = int(ls[2])+1
    if command == 'print':
        print(text[a:b])
    elif command == 'reverse':
        text = text[:a] + text[a:b][::-1] + text[b:]
    elif command == 'replace':
        text =  text[:a] + ls[3] + text[b:]

Measured memory_bytes: 7672
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
//#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=2050;
//ここまでテンプレ
int main(){
	int N,Z,W;
	cin>>N>>Z>>W;
	ll a[SIZE];
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	if(N==1){
		cout<<abs(W-a[0])<<endl;
		return 0;
	}
	cout<<max(abs(W-a[N-1]),abs(a[N-1]-a[N-2]))<<endl;
	return 0;
}

Measured memory_bytes: 888
#include <stdio.h>

int main (){
    int x, y;
    while(scanf ("%d %d",&x,&y) != EOF){
        if(x == 0 && y == 0) return 0;
        if(x > y) printf ("%d %d\n",y,x);
        else printf ("%d %d\n",x,y);
    }
    return 0;
}


Measured memory_bytes: 1984
#include <stdio.h>

int A,B;

int main() {
    scanf("%d %d", &A,&B);
    int i=A+B;
    int j=A-B;
    int k=A*B;
    
    if(i >= j ){
     if(i >= k){
         printf("%d", i);
         }else{
             printf("%d", k);
             
         }
        
    }
    else{
        if(j>=k){
            printf("%d", j);
            
        }else{
            printf("%d", k);
        }
    }
}

Measured memory_bytes: 128
#include <stdio.h>
 
int main(void) {
    int sum;
    int d;
    int i;
    while(!feof(stdin)) {
        scanf("%d",&d);
        if(feof(stdin))break;
        for(i=0,sum=0;i<600;i+=d)sum+=i*i*d;
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 600
N,A,B=map(int,input().split())
while True:
  if B!=A+1:
    A+=1
  else:
    if A==1:
      print("Borys")
      exit()
    else:
      A-=1
 
  if A!=B-1:
    B-=1
  else:
    if B==N:
      print("Alice")
      exit()
    else:
      B+=1

Measured memory_bytes: 38384
x = int(input())
if x <= 599:
    print("8")
elif x <= 799:
    print("7")
elif x <= 999:
    print("6")
elif x <= 1199:
    print("5")
elif x <= 1399:
    print("4")
elif x <= 1599:
    print("3")
elif x <= 1799:
    print("2")
else:
    print("1")

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N,K; cin >> N >> K;
	V<int> A(N); rep(i,N) cin >> A[i];
	int S = accumulate(all(A),0);
	V<int> gs;
	for(int i=1;i*i<=S;i++) if(S%i==0){
		gs.pb(i);
		if(i*i != S) gs.pb(S/i);
	}
	sort(all(gs),greater<int>());
	for(int g: gs){
		V<int> v;
		for(int a: A) v.pb(a%g);
		sort(all(v));
		int R = accumulate(all(v),0)/g;
		int L = N-R;
		ll need = 0;
		rep(i,L) need += v[i];
		for(int i=L;i<N;i++) need += g-v[i];
		if(need/2 <= K){
			cout << g << endl;
			return 0;
		}
	}
}


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

int main(){
  int n;

  while(cin >> n){
    if(n == 0) break;

    int A = 0;
    int B = 0;

    for(int i = 0; i < n; i++){
      int a, b;
      cin >> a >> b;

      if (a > b) {
        A += a + b;
      } else if(a < b) {
        B += a + b;
      } else {
        A += a;
        B += b;
      }
    }

    cout << A << " " << B << endl;
  }
}

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

typedef pair <int, int> ii;
typedef long long ll;

const int Maxn = 100005;

int n;
int s[Maxn];
map <ii, ll> L;
ll res;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &s[i]);
    for (int i = 1; i <= n; i++) {
        ll cur = 0;
        for (int j = i; j < n; j += i) {
            cur += s[j];
            L[ii(i, j)] = cur;
        }
    }
    for (int i = 1; i <= n; i++) {
        ll cur = 0;
        for (int j = n - 1 - i; j > 0; j -= i) {
            cur += s[j];
            int b = j - i;
            if (0 < b && b < j && (j % i || (n - 1 - j) / i < j / i))
                res = max(res, cur + L[ii(i, n - 1 - j)]);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 75648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.solveC();
	}

	private void solveA() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		int NA = N * A;

		if (NA > B) {
			System.out.println(B);
		} else {
			System.out.println(NA);
		}
	}

	private void solveB() {
		Scanner sc = new Scanner(System.in);

		String N = sc.nextLine();

		int iN = Integer.parseInt(N);

		String[] str = N.split("");

		int I = 0;
		for (int i = 0; i < str.length; i++) {
			int I2 = Integer.parseInt(str[i]);
			I += I2;
		}
		if (iN % I == 0) {
			System.out.println("Yes");
		} else if (iN % I != 0) {
			System.out.println("No");
		}

	}

	private void solveC() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		int NX = N * X;
		int NKY = (N - K) * Y;

		if (N <= K) {
			System.out.println(NX);
		} else {
			System.out.println(K * X + (N - K) * Y);
		}
	}

	private void solveD() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveE() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveF() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
struct UnionFind
{
    vector<ll> par;
    vector<ll> siz;
    UnionFind(ll n) : par(n), siz(n, 1)
    {
        rep(i, n) par[i] = i;
    }
    void init(ll n)
    {
        par.resize(n);
        siz.assign(n, 1LL);
        for (ll i = 0; i < n; ++i)
            par[i] = i;
    }
    ll root(ll x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(ll x, ll y)
    {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry)
            return;
        if (siz[rx] < siz[ry])
            swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }
    bool same(ll x, ll y)
    {
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
    ll size(ll x)
    {
        return siz[root(x)];
    }
};
int main()
{
    ll n, m;
    cin >> n >> m;
    UnionFind tree(n);
    rep(i, m)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        tree.unite(a, b);
    }
    ll ans = 0;
    rep(i, n)
    {
        ans = max(ans, tree.size(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 6424