akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, m;
    cin>>n>>m;

    ll ans = 0;
    for (ll i = 1; i * i <= m; ++i) {
        if (m % i == 0) {
            if (m / i >= n) chmax(ans, i);
            if (i >= n) chmax(ans, m / i);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cstring>

using namespace std;

int main()
{
	int n;

	scanf("%d", &n);

	map<long long, long long> list;
	vector<long long> arr;

	for (int i = 0; i < n; i++)
	{
		long long input;

		scanf("%lld", &input);

		arr.push_back(input);

		map<long long, long long>::iterator ret;

		ret = list.find(input);

		if (ret == list.end())
		{
			list[input] = 1;
		}

		else
		{
			ret->second++;
		}
	}

	long long tot = 0;

	for (map<long long, long long>::iterator it = list.begin(); it != list.end(); it++)
	{
		tot += it->second*(it->second - 1) / 2;
	}

	for (int i = 0; i < n; i++)
	{
		map<long long, long long>::iterator ret;

		ret = list.find(arr[i]);

		long long sol;

		sol = tot;

		if (ret->second > 1)
		{
			sol -= ret->second - 1;
		}

		printf("%lld\n", sol);
	}

	return 0;
}

Measured memory_bytes: 11760
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
typedef long long ll;

ll n,m,h,w,a,b;
string s,t;
pair<ll,ll> p[100005];

int main() {
  cin >> n;
  rep(i,n){
    cin >> a >> b;
    p[i]={a+b,a-b};
  }
  sort(p,p+n);
  ll ans=0,x=-3e18;
  rep(i,n){
    if(p[i].second<x) continue;
    x=p[i].first; ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
N, A, B, C, D = map(int, input().split())
S = input()

if C < D:
    flag = 1
    for i in range(A-1, C-1):
        if S[i+1] == "#" and S[i] == "#":
            flag = 0
            break
    for i in range(B-1, D-1):
        if S[i+1] == "#" and S[i] == "#":
            flag = 0
            break

else:
    flag = 1
    for i in range(A-1, C-1):
        if S[i+1] == "#" and S[i] == "#":
            flag = 0
            break
    for i in range(B-1, D-1):
        if S[i+1] == "#" and S[i] == "#":
            flag = 0
            break

    if flag == 1:
        flag = 0
        for i in range(B-2, D-1):
            if S[i+2] == "." and S[i+1] == "." and S[i] == ".":
                flag = 1

if flag == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3572
import std.container;
import std.range;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.stdio;
import std.container;

void main() {
	int n;
	readf("%s\n", &n);

	auto a = new int[n];
	auto b = new int[n];
	foreach (i;0..n) {
		int x, y;
		readf("%s %s\n", &x, &y);
		a[i] = x + y;
		b[i] = x - y;
	}

	a.sort;
	b.sort;

	max(a[$ - 1] - a[0], b[$ - 1] - b[0]).writeln;
}


Measured memory_bytes: 4280
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod = 1000000007;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
	int W, a, b;
	cin >> W >> a >> b;
	cout << max( {b - a - W, a - W - b, 0} ) << endl;
}



Measured memory_bytes: 3608
#include<stdio.h>

int N, D;
char data[1010];
char aaa[1010];

void input(){
	scanf("%d\n", &N);
	gets(data);
	scanf("%d", &D);
}

void process(){
	int cnt = 0;
	for (int i = 0; i < N; ++i){
		aaa[i] = '1';
		cnt += aaa[i] != data[i];
	}

	if (cnt > D){
		for (int i = N - 1; i >= 0; --i){
			if (data[i] != aaa[i]) {
				aaa[i] = '0';
				--cnt;
				if (cnt == D) break;
			}
		}
	}
	else if (cnt < D){
		for (int i = N - 1; i >= 0; --i) {
			if (data[i] == aaa[i]) {
				aaa[i] = '0';
				++cnt;
				if (cnt == D) break;
			}
		}
	}
}

void output(){
	printf("%s\n", aaa);
}

int main() {
	input();
	process();
	output();
	return 0;
}

Measured memory_bytes: 1016
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int N;
    cin >> N;
    vector<map<char,int>> chars(N); 
    string alp{"abcdefghijklmnopqrstuvwxyz"};
    rep(i, N) for(auto& c : alp) chars[i][c] = 0;
    rep(i, N){
        string S; cin >> S;
        for(auto& c : S) chars[i][c]++;
    }

    string ans = "";
    for(auto& c : alp){
        int MIN = 1e9;
        rep(i, N) MIN = min(MIN, chars[i][c]);
        string tmp(MIN, c);
        ans += tmp;
    }
    cout << ans << endl;
}



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

typedef long long ll;

const int MN = 305, P = 998244353;

typedef std::bitset<MN> bst;

char buf[1 << 15], *S, *T;

inline char gc() {
	if (S == T) {
		T = (S = buf) + fread(buf, 1, 1 << 15, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}

bst val[MN], vec[MN];

int n, m, cnt;

inline int fpw(int x, int k) {
	int res = 1;
	for (; k; k >>= 1, x = (ll) x * x % P)
		if (k & 1) res = (ll) res * x % P;
	return res;
}

inline int read() {
	int x; bool f; char c;
	for (f = 0; (c = getchar()) < '0' || c > '9'; f = c == '-');
	for (x = c ^ '0'; (c = getchar()) >= '0' && c <= '9'; x = (x << 1) + (x << 3) + (c ^ '0'));
	return f ? -x : x;
}

int main() {
	n = read(), m = read();
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			val[i][j] = read();

	for (int i = 0; i < n; ++i)
		for (int j = m; j--; )
			if (val[i][j]) {
				if (vec[j].count()) val[i] ^= vec[j];
				else {
					++cnt;
					vec[j] = val[i];
				/*	for (int k = j; k--; )
						if (vec[j][k]) vec[j] ^= vec[k];
					for (int k = j; ++k < m; )
						if (vec[k][j]) vec[k] ^= vec[j];*/
					break;
				}
			}

	printf("%lld\n", (ll)fpw(2, m - 1) * (fpw(2, n) - fpw(2, n - cnt) + P) % P);
	return 0;
}

Measured memory_bytes: 256
using System;
class Program{
  static void Main(string[] args){
    string[] tmp = Console.ReadLine().Split(' ');
    int a=int.Parse(tmp[0]), b=int.Parse(tmp[1]), c=int.Parse(tmp[2]);
    Console.WriteLine(a*c<=b?c:Math.Floor((double)b/a));
  }
}

Measured memory_bytes: 11092
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a =scan.nextInt();
		int b =scan.nextInt();
		int c =scan.nextInt();
		if(a < b) {
			if(b < c) {
				System.out.println("Yes");		
			}
			else {
				System.out.println("No");
			}
		}
		else {
			System.out.println("No");
		}
	}	
}



Measured memory_bytes: 26288
a, b, c, x, y = gets.split.map(&:to_i)

ltc = (a + b) < 2 * c
f = x > y ? y : x
diff = x > y ? x - y : y - x

sum = 0
if ltc
  sum += f * (a + b)
else
  sum += f * 2 * c
end

pt1 = diff * 2 * c
pt2 = x > y ? diff * a : diff * b

if pt1 < pt2
  sum += pt1
else
  sum += pt2
end

puts sum

Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class A
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int H = GetInt();
		int A = GetInt();
		WriteLine((H + A - 1) / A);
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rrep(i,n) for (int i = 1; i <= (n); i++)
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

int main() {
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  ll ans = 1e18;
  rep(i,100001) {
    ll total = 2 * c * i + max(x-i,0) * a + max(y-i,0) * b;
    if (total < ans) ans = total;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

int main()
{
	int n=read(),k=read();
	if(2*k-1<=n)puts("YES");
	else puts("NO");
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int min = 1000;
		int max = 0;
		for(int i=0;i<N;i++){
			int temp = sc.nextInt();
			if(min>temp)
				min = temp;
			if(max<temp)
				max = temp;
		}
		System.out.println(max-min);

	}

}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

struct Data {
  ll x,y,z;
};
  

void compute(int n,int m,vector<Data> &vec) {
  ll ans = -LLONG_MAX;
  rep(i,(1<<3)) {
    priority_queue<ll> Q;
    rep(j,n) {
      ll v = 0;
      if( (i>>0) & 1 ) {
	v += vec[j].x;
      } else {
	v -= vec[j].x;
      }
      if( (i>>1) & 1 ) {
	v += vec[j].y;
      } else {
	v -= vec[j].y;
      }
      if( (i>>2) & 1 ) {
	v += vec[j].z;
      } else {
	v -= vec[j].z;
      }
      Q.push(v);
    }
    ll score = 0;
    rep(_,m) {
      score += Q.top(); Q.pop();
    }
    ans = max(ans,score);
  }
  cout << ans << endl;
}

int main() {
  int n,m;
  cin >> n >> m;
  vector<Data> vec(n);
  rep(i,n) {
    cin >> vec[i].x >> vec[i].y >> vec[i].z;
  }
  compute(n,m,vec);
  return 0;
}


Measured memory_bytes: 256
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

void solve() {
    int n, cost[6], d;
    cin >> n >> cost[2] >> cost[3] >> cost[5] >> d;
    
    map<int, int> ans;
    Prior<int> que; que.push(n);
    
    int lst = -1;
    while (!que.empty()) {
        int nxt = que.top(); que.pop();
        if (nxt == lst) continue;
        lst = nxt;
        // cout << "on " << nxt << " : " << ans[nxt] << "\n";
        
        for (auto x : {2, 3, 5}) {
            ans[ nxt     /x] = min((ans[ nxt     /x] ? ans[ nxt     /x] : INF),
                                   ans[nxt] + (nxt > 2E9 ? INF : (nxt -  nxt     /x) * d));
            ans[(nxt+x-1)/x] = min((ans[(nxt+x-1)/x] ? ans[(nxt+x-1)/x] : INF),
                                   ans[nxt] + (nxt > 2E9 ? INF : (nxt - (nxt+x-1)/x) * d));
            ans[ nxt     /x] = min(ans[ nxt     /x], ans[nxt] + cost[x] + (  nxt%x)   * d);
            ans[(nxt+x-1)/x] = min(ans[(nxt+x-1)/x], ans[nxt] + cost[x] + (x-nxt%x)%x * d);
            // cout << "  push " <<  nxt     /x << " : " << ans[ nxt     /x] << "\n";
            // cout << "  push " << (nxt+x-1)/x << " : " << ans[(nxt+x-1)/x] << "\n";
            que.push(nxt/x), que.push((nxt+x-1)/x);
        }
        
        if (nxt == 0) break;
    }
    
    // for (int i = 0; i <= 11; ++i) cout << ans[i] << " \n"[i == 11];
    
    cout << ans[0] << "\n";
}

int32_t main() {
    fastIO();
    
    int t;
    cin >> t;
    while (t--) solve();
    
    return 0;
}

Measured memory_bytes: 4440
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[11][7];
int used[11];
int p[6][6];
int solve(int a){
	if(a==10){
		for(int i=0;i<5;i++)for(int j=0;j<5;j++)
			if(!p[i][j])return 0;
		return 1;
	}
	int ret=0;
	for(int i=0;i<10;i++){
		if(used[i])continue;
		used[i]=1;
		bool ok=true;
		if(a%2){
			for(int j=0;j<5;j++){
				p[a/2][j]+=str[i][j]-'0';
				if(p[a/2][j]==2)ok=false;
			}
		}else{
			for(int j=0;j<5;j++){
				p[j][a/2]+=str[i][j]-'0';
				if(p[j][a/2]==2)ok=false;
			}
		}
		if(ok)ret+=solve(a+1);
		used[i]=0;
		if(a%2){
			for(int j=0;j<5;j++){
				p[a/2][j]-=str[i][j]-'0';
			}
		}else{
			for(int j=0;j<5;j++){
				p[j][a/2]-=str[i][j]-'0';
			}
		}
	}
	for(int i=0;i<10;i++){
		if(used[i])continue;
		if(str[i][0]==str[i][4]&&str[i][1]==str[i][3])continue;
		used[i]=1;
		bool ok=true;
		if(a%2){
			for(int j=0;j<5;j++){
				p[a/2][j]+=str[i][4-j]-'0';
				if(p[a/2][j]==2)ok=false;
			}
		}else{
			for(int j=0;j<5;j++){
				p[j][a/2]+=str[i][4-j]-'0';
				if(p[j][a/2]==2)ok=false;
			}
		}
		if(ok)ret+=solve(a+1);
		used[i]=0;
		if(a%2){
			for(int j=0;j<5;j++){
				p[a/2][j]-=str[i][4-j]-'0';
			}
		}else{
			for(int j=0;j<5;j++){
				p[j][a/2]-=str[i][4-j]-'0';
			}
		}
	}
	return ret;
}
int main(){
	while(1){
		for(int i=0;i<5;i++)for(int j=0;j<5;j++)p[i][j]=0;
		scanf("%s",str[0]);
		for(int i=0;i<10;i++)used[i]=0;
		if(str[0][0]=='E')break;
		for(int i=1;i<10;i++)scanf("%s",str[i]);
		int ret=solve(0);
		printf("%d\n",ret/8);
	}
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, K;
    cin >> N >> K;

    if (K == 1) {
        cout << 0 << endl;
    } else {
        cout << N - K << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
bool A[200001];
inline char tc(){
  static char fl[100],*A=fl,*B=fl;
  return A==B&&(B=(A=fl)+fread(fl,1,100,stdin),A==B)?EOF:*A++;  
}
inline int read(){
  int a=0;static char c;
  while((c=tc())<48||c>57);
  while(c>=48&&c<=57)a=a*10+c-48,c=tc();
  return a;
}
int main(){
  int n,m,a,b;n=read();m=read();
  while(m--){a=read();b=read();
    if(a==1){
      if(A[b])return puts("POSSIBLE"),0;
      A[b]=1;
    }
    if(b==n){
      if(A[a])return puts("POSSIBLE"),0;
      A[a]=1;
    }
  }
  puts("IMPOSSIBLE");
}

Measured memory_bytes: 384
a, b, c, x, y = gets.split.map(&:to_i)

result = []
result << a*x + b*y
result << 2*c*[x,y].max

if x > y
  result << 2*c*y + (x-y) * a
else
  result << 2*c*x + (y-x) * b
end

p result.min


Measured memory_bytes: 14224
<?php
            fscanf(STDIN, "%d", $d);
            switch ($d) {
            case 22:
                echo "Christmas Eve Eve Eve"."\n";
                break;
            case 23:
                echo "Christmas Eve Eve"."\n";
                break;
            case 24:
                echo "Christmas Eve"."\n";
                break;
            case 25:
                echo "Christmas"."\n";
                break;
        }
            ?>

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

#define INF 1e9
#define LLINF 1e12
using namespace std;

#define REPR(i, n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

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

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

typedef long long ll;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int maxi = 2 * 1e5;
    ll minCost = LLINF;
    REP(boughtABpizza, maxi + 1) {
        ll cost = boughtABpizza * C;
        int kumiawasePizza = boughtABpizza / 2;

        cost += max(0, (X - kumiawasePizza) * A);
        cost += max(0, (Y - kumiawasePizza) * B);
        chmin(minCost,cost);
    }
    cout << minCost << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std; 
long long  n,k,A[200000],F[200000],f=-1,l=1e12+1,m,ans;
bool flag;
int main(void){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    for(int i=0;i<n;i++){
        cin>>F[i];
    }
    sort(A,A+n);
    sort(F,F+n);
    reverse(F,F+n);
    while(l!=f+1){
        ans=0;
        flag=false;
        m=(l+f)/2;
        for(int i=0;i<n;i++){
            ans+=max(0LL,A[i]-(m/F[i]));
            if(ans>k){
                f=m;
                flag=true;
                break;
            }
        }
        if(!flag){
            l=m;
        }
    }
    cout<<l<<endl;
}

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

int main(){

	int n, prime[10001], p[10001];

	fill(prime, prime+10001, 1);
	fill(p, p+10001, 0);
	
	prime[0] = 0;
	prime[1] = 0;
	for(int i=2; i<10001; i++){
		if(prime[i] == 1){
			if(prime[i-2] == 1) p[i] = 1;
			for(int j=2; i*j<10001; j++){
				prime[i*j] = 0;
			}
		}
	}
	
	while(cin >> n){
		if(n == 0) break;
		for(int i=n; i>0; i--){
			if(p[i] == 1) {
				cout << i-2 << " " << i << endl;
				break;
			}
		}
	}
	
	return 0;

}

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

int main(){
    int n; cin >> n;
    vector<int> x(n), y;
    for (auto i = 0; i < n; i++) cin >> x[i];
    y = x; sort(y.begin(), y.end());
    int a = y[n / 2 - 1], b = y[n / 2];

    for (auto i = 0; i < n; i++) {
        if(x[i] >= b) cout << a << endl;
        else cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 4756
#include <iostream>
#include <math.h>
using namespace std;

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

    double save = 1;

    for(double i=2.0;  i< n/2; i+=1){
        for(double j= 2.0; pow(i,j) <= n; j+=1){
            //cout << pow(i,j) <<","<< i <<","<< j << endl;
            if(save < pow(i,j)){
                save = pow(i,j);
            }
        }
    }
    cout <<save <<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
int ruijo10(int x){
    if(x==0) return 1;
    int ans=1;
    rp(i,x) ans *= 10;
    return ans;
}
int allnum(int x){
    if(x==0) return 1;
    else return ruijo10(x)+allnum(x-1);
}
int dp[200005];
int main(){
    int n;
    cin >> n;
    
    dp[0]=0;
    for(int i=1; i<=n; i++){
        deque<int> n(6,-1);
        int dig=0;
        int k=i;
        while(k){
            n.push_front(k%10);
            k /= 10;
            dig++;
        }
    
    
    if(dig==1) {dp[i]=dp[i-1]+1; continue;}
    if(dig==2) {
        if(n.at(0)<n.at(1)) dp[i]=dp[i-1];
        else if(i%11==0) dp[i]=dp[i-1]+1;
        else dp[i]=dp[i-1]+2;
        continue;
    }
    if(n.at(dig-1)==0) {dp[i]=dp[i-1]; continue;}

    int mid;
    mid=(i%ruijo10(dig-1))/10 +1;
    if(n.at(0)<n.at(dig-1)){
        dp[i]=dp[i-1]+2*(allnum(dig-3));
    }
    if(n.at(0)==n.at(dig-1)){
        dp[i]=dp[i-1]+2*(allnum(dig-3)+mid)+1;
    }
    if(n.at(0)>n.at(dig-1)){
        dp[i]=dp[i-1]+2*(allnum(dig-2));
    }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

bool YYMM, MMYY;

int main() {
	char d[5];
	YYMM = MMYY = false;
	scanf("%s", d);
	int A = (d[0] - '0') * 10 + (d[1] - '0');
	int B = (d[2] - '0') * 10 + (d[3] - '0');

	if ( A >= 1 && A <= 12 ) MMYY = true;
	if ( B >= 1 && B <= 12 ) YYMM = true;

	if ( YYMM && MMYY ) {
		printf("AMBIGUOUS\n");
	} else if ( !YYMM && !MMYY ) {
		printf("NA\n");
	} else if ( YYMM ) {
		printf("YYMM\n");
	} else {
		printf("MMYY\n");
	}

}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
bool visited[100001];
int ans=0;
vector <int> path[100001];
void dfs(int n){
    visited[n]=true;
    for(int i=0;i<path[n].size();i++){
        if(!visited[path[n][i]]){
            dfs(path[n][i]);
        }
    }
    return ;
}
int main(){
    int n,m,a,b,c;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>a>>b>>c;
        path[b].push_back(a);
        path[a].push_back(b);
    }
    for(int i=1;i<=n;i++){
        if(!visited[i]){
            ans++;
            dfs(i);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8960
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
    string s;
    cin >> s;
    long long c = 0, ans = 0;
    for(int i = s.size() - 1; i >= 0; i--){
        if(s[i] == 'W') c++;
        else ans += c;
    }
    cout << ans << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
long long a,b,c,d;
long long count(long long sub){
  long long min,max;
  if(a%sub==0)min=a/sub;
  else min=a/sub+1;
  max=b/sub;
  return max-min+1;
}
int main(){
  cin>>a>>b>>c>>d;
  long long countC=count(c);
  long long countD=count(d);
  if(c>d){//c<d
    long long temp=c;
    c=d;
    d=temp;
  }
  //cout<<c<<d<<endl;
  long long r=d%c;
  long long tempd=d;
  long long tempc=c;
  while(r!=0){
    tempd=tempc;
    tempc=r;
    r=tempd%tempc;
    //cout<<r<<endl;
  }
  //cout<<tempc<<endl;
  long long countCD=count(c*d/tempc);
  //cout<<countC<<" "<<countD<<" "<<countCD<<endl;
  cout<<b-a+1-countC-countD+countCD<<endl;

}


Measured memory_bytes: 256
#include<complex>
#include<stdio.h>
#define F(a,b,c) acos((b*b+c*c-a*a)/2/b/c)
int main(){int n;double d,e,f,g,h,i;for(scanf("%d",&n);n--;){scanf("%lf%lf%lf%lf%lf%lf",&d,&g,&e,&h,&f,&i);std::complex<double> a(d,g),b(e,h),c(f,i);float A=abs(b-c),B=abs(c-a),C=abs(a-b),L=F(A,B,C),s=sin(2*L),t=sin(2*F(B,C,A)),u=sin(2*F(C,A,B)),v=s+t+u;printf("%.3f %.3f %.3f\n",(d*s+e*t+f*u)/v,(g*s+h*t+i*u)/v,A/sin(L)/2);}}

Measured memory_bytes: 0
import os
import sys

import numpy as np
from scipy.optimize import fmin

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
X = list(map(int, sys.stdin.buffer.readline().split()))

X = np.array(X, dtype=int)


def calc(p):
    return ((X - p) ** 2).sum()


ans = INF
for i in range(200):
    ans = min(ans, calc(i))
# print(ans)

y, = fmin(calc, x0=0, disp=False)
print(int(calc(round(y))))


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

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

    if(abs(A-B) % 2 != 0 || abs(A-B) == 1)cout << "Borys";
    else cout << "Alice";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
C = [list(map(int,input().split())) for i in range(3)]
result = 'No'

if C[1][0]-C[0][0]==C[1][1]-C[0][1] and C[1][2]-C[0][2]==C[1][1]-C[0][1]:
  if C[2][0]-C[0][0]==C[2][1]-C[0][1] and C[2][2]-C[0][2]==C[2][1]-C[0][1]:
    result = 'Yes'
    
print(result)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt()-1;
        int Y = sc.nextInt()-1;
        int[][] min = new int[N][N];
        int[] ans = new int[N];
        for(int a=0;a<N;a++){
            for(int b=a+1;b<N;b++){
                if(a>=Y || b <=X){
                    min[a][b] = b-a;
                }else{
                    int other = Math.abs(a-X) + Math.abs(b-Y) + 1;
                    min[a][b] = Math.min(other, b-a);
                }
                ans[min[a][b]-1]++;
            }
        }
        for(int i =0;i<N-1;i++) {
            System.out.println(ans[i]);
        }
    }

}


Measured memory_bytes: 54612
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int n[200005];
int main()
{
    int a,b,c,d,e,f,i,j,k,chk=0;
    cin>>a;
    for(i=0; i<a; i++)
        cin>>n[i];
    sort(n,n+a);
    for(i=1; i<a; i++)
    {
        if(n[i]==n[i-1]) chk=1;
        if(chk==1)
        {
            cout<<"NO"<<endl;
            break;
        }
    }
if(chk==0) cout<<"YES"<<endl;
return 0;
}


Measured memory_bytes: 1024
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        int n;
        string s;
        cin >> n >> s;

        int cnt = 0, i = 0, j = n - 1;
        while (i < j) {
            if (s[i] == 'W' && s[j] == 'R') {
                swap(s[i], s[j]);
                i++;
                j--;
                cnt++;
            }
            else if (s[i] == 'R')
                i++;
            else if (s[j] == 'W')
                j--;
        }

        cout << cnt << '\n';
    }
    
    return 0;
}



Measured memory_bytes: 3752
/*input
2
1
2 0
1
1 0
*/
/**
    Author: Kristopher Paul
    Date Created: 08-12-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int n;
    cin >> n;
    int x[n],y[n];
    map<int,vector<pii> > vec;
    FOR(i,0,n){
        int t;
        cin >> t;
        FOR(j,0,t){
            int x,y;
            cin >> x >> y;
            vec[i+1].pb(mp(x,y));
        }
    }
    int ans = 0;
    FOR(mask,0,1<<n){
        bool cl[n] = {};
        int tot = 0;
        FOR(i,0,n){
            if(mask & (1<<i)){
                cl[i] = true;
                tot++;
            }
        }
        bool c = true;
        FOR(i,0,n){
            if(mask & (1<<i)){
                FOR(j,0,vec[i+1].size()){
                    if((vec[i+1][j].second == 1 && !cl[vec[i+1][j].first-1]) || (vec[i+1][j].second == 0 && cl[vec[i+1][j].first-1])){
                        c = false;
                        break;
                    }
                }
            }
        }
        if(c == false){
            continue;
        }
        remax(ans,tot);
    }
    cout << ans << endl;
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 256
n = gets.to_i
 
def prime?(number)
  return true if number == 2
  return false if number % 2 == 0
  i = 3
  max = Math.sqrt(number)
  while i <= max
    return false if number % i == 0
    i += 2
  end
  return true
end
 
a = []
n.times do
  a << gets.to_i
end
 
count = 0
a.each do |number|
  count += 1 if prime?(number)
end
 
puts count

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

int main() {
	//cout<<"GfG!";
	char a[100][100];
	int h, w;
	cin>>h>>w;
	for (int i = 0; i < h; i++)
	        cin>>a[i];
	for (int i = -1; i <= h; i++)
	{
	    if (i == -1 || i == h)
	    {
	        for (int j = 0; j < (w+2); j++)
	            cout<<"#";
	        cout<<endl;
	    }
	    else
	    {
	        cout<<"#";
	        for (int k = 0; k < w; k++)
	            cout<<a[i][k];
	        cout<<"#\n";
	    }
	}
	return 0;
}

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

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

    int i=0;
    int j=n-1;
    int ans = 0;
    while (true) {
        while (i < n && s[i] == 'R') {
            i++;
        }
        while (j >= 0 && s[j] == 'W') {
            j--;
        }
        swap(s[i], s[j]);
        if (i >= n-1 || j <= 0  || i >= j) {
            break;
        }
        ans++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3900
import math
a, b ,angleC = [float(x) for x in input().split(" ")]

c = math.sqrt((a **2) + (b **2) - 2*a*b*(math.cos(math.radians(int(angleC))) ))

S = 1/2 * a * b * (math.sin(math.radians(int(angleC))))
L = a + b + c
h = 2 * S / a


print(S)
print(L)
print(h)

Measured memory_bytes: 7720
#include <stdio.h>

int main(void)
{
    int min, middle, max;
    int sum;
    int n, x;
    int cnt;

    while (1){
        scanf("%d %d", &n, &x);
        if (n == 0 && x == 0){
            break;
        }else{
            cnt = 0;
            for (min = 1; min <= (x / 3); min++){
                for (middle = min + 1; middle < (x - min) / 2.0; middle++){
                    /*max = x - min - middle > middle => middle < (x - min) / 2*/
                    for (max = middle + 1; max <= n; max++){
                        sum = min + middle + max;
                        if (sum == x){
                            cnt++;
                        }
                    }
                }
            }
            printf("%d\n", cnt);
        }
    }

    return 0;
}

Measured memory_bytes: 600
def resolve():
    N = int(input())
    A = [list(map(int, input().split())) for i in range(2)]

    calc = ans = 0
    for i in range(N):
        calc = sum(A[0][:i+1]) + sum(A[1][i:])
        if ans < calc:
            ans = calc
    print(ans)

resolve()

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
 
 
int main(){
	int n;
	cin>>n;
	string s;
	int a=0,b=0,c=0,d=0;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='('){
			a++;
			
		}
		else{
			b++;
			if(a<b)c++,b--;
		}
	}
	if(a>b)d=a-b;
	for(int i=0;i<c;i++)cout<<"(";
	cout<<s;
	for(int i=0;i<d;i++)cout<<")";
	return 0;
}

Measured memory_bytes: 256
N = int(input())
lis = [0] * 1001001
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            n = x**2 + y**2 + z**2 + x*y + y*z + z*x
            lis[n] += 1
for i in range(1, N+1):
    print(lis[i])

Measured memory_bytes: 82228
while 1:
    a, operator, b = input().split()
    if operator == "+":
        print(int(a) + int(b))
    elif operator == "-":
        print(int(a) - int(b))
    elif operator == "*":
        print(int(a) * int(b))
    elif operator == "/":
        print(int(a) // int(b))
    elif operator == "?":
        break
    else:
        print("'" + operator + "'" + " is not a operator.")

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

int main(){
  int N; cin >>N;
  string S; cin >> S;
  int ans = 0;
  char prev;
  for(int i=0; i<S.size(); i++){
    if(i==0||S[i]!=prev){
      ans+=1;
      prev=S[i];
      continue;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 512
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::max;


#[fastout]
fn main() {
    input! {
    s: Chars
    }
    let n = s.len();
    let mut ans = 0;
    for i in 0..n / 2 {
        if s[i] != s[n - i - 1] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2100
S = input()
Q = int(input())
arr1 = []
arr2 = []
count = 1
for _ in range(Q):
    q = input()
    if q == "1":
        count *= -1
    else:
        _, f, c = map(str, q.split())
        if f == "1":
            arr1.append(c) if count == 1 else arr2.append(c)
        else:
            arr2.append(c) if count == 1 else arr1.append(c)

if count == 1:
    ans = "".join(arr1[::-1]) + S + "".join(arr2)
else:
    ans = "".join(arr2[::-1]) + S[::-1] + "".join(arr1)
print(ans)


Measured memory_bytes: 72472
import java.util.*;

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

		String S = sc.next();

		S = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "");

		println(S.equals("") ? "YES" : "NO");
	}

	public static String remove(String str, String str2) {
		int index = str.indexOf(str2);
		str.substring(0, index);
		str = new String(str.substring(0, index) + str.substring(index+str2.length()));
		return str;
	}
	public static void print(Object o) {
		System.out.print(o);
	}

	public static void println(Object o) {
		System.out.println(o);
	}
}

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

int n;
int p[5000];
int cnt[5001];

int main() {
	int i, j;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> p[i];
	
	int ans = 1145141919;
	for (i = 0; i <= p[0]; i++) {
		for (j = 0; j < n; j++) cnt[j] = 0;
		cnt[0] += i;
		
		for (j = 0; j < n; j++) {
			int kaisu = max(0, p[j] - cnt[j]);
			cnt[j] += kaisu;
			cnt[j + 1] += kaisu;
		}
		
		int sumCnt = 0;
		for (j = 0; j < n; j++) sumCnt += cnt[j];
		ans = min(ans, sumCnt);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3096
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, X: int, Y: int):
    ans = 1e20
    for i in range(max(X, Y) + 1):
        a = max(X-i, 0)
        b = max(Y-i, 0)
        c = 2*i
        ans = min(ans, A*a + B*b + C*c)
    return ans

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    print(solve(A, B, C, X, Y))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
#define N 1000000
 
void insertionSort(int [],int,int);
void shellSort(int[],int);
 
int cnt=0;
 
int main(){
  int n,i,j,A[N];
  
  scanf("%d",&n);
  
  for(i=0; i<n; i++)
    scanf("%d",&A[i]);
   
  shellSort(A,n);
  printf("%d\n",cnt);
 
  for(i=0; i<n; i++)
    printf("%d\n",A[i]);

  return 0;
}
 
void insertionSort(int A[],int n,int g){
  int i,j,v;
  
  for(i=g; i<n; i++){
    v = A[i];
    j = i - g;
    
    while(j>=0 && A[j]>v){
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    
    A[j+g] = v;
  }
}
 
void shellSort(int A[],int n){
  int i,m=0;
  int G[n];
  G[0]=0;
  
  for(i=0; i<n; i++){
    G[i+1] = 3 * G[i] + 1;
    m++;
    if(G[i+1] > N) break;
  }
  
  while(G[m] > n) m--;
  
  printf("%d\n",m);
 
  for(i=m; i>1; i--)
    printf("%d ",G[i]);
  
  printf("%d\n",G[1]);
  
  for(i=m; i>=0; i--)
    insertionSort(A,n,G[i]); 
}



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

using namespace std;

int a, b, ans = 0;

bool pal(int x)
{
	int g[6], cnt = 0;
	while (x)
	{
		g[++cnt] = x % 10;
		x /= 10;
	}
	for (int i = 1; i <= 2; i++) 
		if (g[i] != g[5 - i + 1]) return false;
	return true;
}

int main()
{
	scanf("%d%d", &a, &b);
	for (int i = a; i <= b; i++)
		if (pal(i)) ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N, K; cin >> N >> K;
    int ans = K * pow(K-1, N-1);
    cout << ans << endl;
}

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

const int mod = 998244353;

int N;
string X, G;
vector<string> A;

string gcd(string a, string b) {
    if(a.size() < b.size()) return gcd(b, a);
    if(b.size() == 0) return a;

    string ret;
    bool t = false;
    for(int i = 0; i < b.size(); i++) {
        char c = a[i] == b[i]? '0' : '1';
        if(c == '1') t = true;
        if(t) ret.push_back(c);
    }
    for(int i = b.size(); i < a.size(); i++) {
        if(a[i] == '1') t = true;
        if(t) ret.push_back(a[i]);
    }
    return gcd(ret, b);
}

bool cmp(string a, string b) {
    if(a.size() != b.size()) return a.size() < b.size();
    for(int i = 0; i < a.size(); i++) {
        if(a[i] != b[i]) return a[i] < b[i];
    }
    return false;
}

int str_to_int(string s) {
    if(s.size() == 0) return 0;
    int ret = 0;
    for(int i = 0; i < s.size(); i++) {
        ret = ret * 2 % mod;
        if(s[i] == '1') ret = (ret + 1) % mod;
    }
    return ret;
}

string C;

int dfs(int idx) {
    if(idx == X.size() - G.size() + 1) return cmp(C, X) || C == X;
    if(C[idx] != X[idx]) {
        for(int i = idx; i < idx + G.size(); i++) {
            C[i] = C[i] == G[i - idx]? '0' : '1';
        }
    }
    return dfs(idx + 1);
}

int ans;

int main() {
    cin >> N >> X;

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

    G = "";
    for(int i = 0; i < N; i++) {
        G = gcd(A[i], G);
    }

    if(cmp(X, G)) {
        cout << 1;
        return 0;
    }

    ans = str_to_int(X.substr(0, X.size() - G.size() + 1));

    for(int i = 0; i < X.size(); i++) C.push_back('0');
    ans += dfs(0);
    ans %= mod;

    cout << ans;
}


Measured memory_bytes: 38912
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            System.out.println((N % 10 == 7 || ((N / 10) % 10) == 7 || ((N / 100) % 10) == 7) ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 26952
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair

void colorEdges(int ptr, vector<vector<pair<int, int> > >& gra, 
                vector<int>& edgeColors, bool isVisited[]) 
{ 
    queue<int> q; 
    int c = 0; 
  
    set<int> colored; 
  
    if (isVisited[ptr]) 
        return; 
  
    isVisited[ptr] = 1; 
  
    for (int i = 0; i < gra[ptr].size(); i++) { 
        if (edgeColors[gra[ptr][i].second] != -1) 
            colored.insert(edgeColors[gra[ptr][i].second]); 
    } 
  
    for (int i = 0; i < gra[ptr].size(); i++) { 
        if (!isVisited[gra[ptr][i].first]) 
            q.push(gra[ptr][i].first); 
  
        if (edgeColors[gra[ptr][i].second] == -1) { 
            while (colored.find(c) != colored.end()) 
  
                c++; 
  
            edgeColors[gra[ptr][i].second] = c; 
  
            colored.insert(c); 
            c++; 
        } 
    } 
  
    // while queue's not empty 
    while (!q.empty()) { 
        int temp = q.front(); 
        q.pop(); 
  
        colorEdges(temp, gra, edgeColors, isVisited); 
    } 
  
    return; 
} 
int main(){
	int n,u,v;
	vector<vector<pair<int, int> > > gra; 
  
    vector<int> edgeColors; 
  
    bool isVisited[100000] = { 0 }; 
  
	scanf("%d",&n);
	 gra.resize(n+1); 

	for(int i=0;i<n-1;i++){
		scanf("%d%d",&u,&v);
		u--,v--;
		gra[u].push_back(mp(v,i));
		gra[v].push_back(mp(u,i));

	}
	edgeColors.resize(n-1, -1); 

  	colorEdges(0, gra, edgeColors, isVisited); 

  	int s=0;
	for(int i=0;i<n-1;i++){
		s =max(edgeColors[i],s);
	} 
	printf("%d\n",s+1 );
	for(int i=0;i<n-1;i++){
		printf("%d\n",edgeColors[i]+1 );
	}
	return 0;
}


Measured memory_bytes: 60416
#include<bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a + b + 1) / 2 << endl;
}

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
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;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,M;
    cin>>N>>M;
    vector<pair<int,int>> vec;
    int a,b;
    REP(i,N){
        cin>>a>>b;
        vec.pb(mp(a,-b));
    }
    sort(all(vec));
    priority_queue<int> maxpq;
    int j=0;
    int ans;ans=0;
    REP1(i,M){
        if(j<vec.size()){
            while(vec[j].first==i){
                maxpq.push(-1*vec[j].second);
                j++;
            }
        }
        if(maxpq.empty()){
            continue;
        }else{
            ans+=maxpq.top();
            maxpq.pop();
        }
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A,B,t1,t2,t3,big;
    cin>>A>>B;
    t1=A+B;
    t2=A-B;
    t3=A*B;
    big=t1;
    if(big<t2){
        big=t2;
    }
    if(big<t3){
    big=t3;
    }
    cout<<big<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin>>n;
  vector<int> a(n+2);
  a[0]=0;
  a[n+1]=0;
  for(int i=0;i<n;i++){
    cin>>a[i+1];
  }
  int sum=0;
  for(int i=1;i<n+2;i++){
    sum+=abs(a[i]-a[i-1]);
  }
  for(int i=1;i<=n;i++){
    int x=sum;
    x-=(abs(a[i]-a[i-1])+abs(a[i+1]-a[i]));
    x+=abs(a[i+1]-a[i-1]);
    cout<<x<<endl;
  }
}

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

using namespace std;

int main(void) {
    long n, a, b;
    cin >> n >> a >> b;
    long ans = 0;
    ans += n / (b + a) * a;
    ans += min(n % (b + a), a);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#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 - a * 1000 - b * 100) % 10;

    int count = 0;
    if (a == 2){
        count++;
    }
    if (b == 2){
        count++;
    }
    if (c == 2){
        count++;
    } 
    if (d == 2){
        count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        long A=sc.nextLong();
        long B=sc.nextLong();
        long C=sc.nextLong();
        long count=0;
        long a,b,c;
        while(((A%2)==0) && ((B%2)==0) && ((C%2)==0)){
            if((A==B) && (B==C)){
                count=-1;
                break;
            }
            a=A;
            b=B;
            c=C;
            A=(b+c)/2;
            B=(a+c)/2;
            C=(a+b)/2;
            count+=1;
        }
        System.out.println(count);
    }
}



Measured memory_bytes: 23764