akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>


using namespace std;

using ll = long long;

const ll MAX = 10000;


vector<vector<pair<ll, ll>>> graph;
bool finished[MAX] = {};
ll d[MAX];
ll n;


void dijkstra()
{
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
    pq.push(make_pair(0, 0));

    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();

        if (finished[p.second])
            continue;

        for (auto e : graph[p.second]) {
            if (!finished[e.second]) {
                pq.push(make_pair(p.first + e.first, e.second));
            }
        }
        finished[p.second] = true;
        d[p.second] = p.first;
    }
}


int main()
{
    cin >> n;
    graph.resize(n);
    for (ll i = 0; i < n; i++) {
        ll u, k;
        cin >> u >> k;
        for (ll j = 0; j < k; j++) {
            ll v, c;
            cin >> v >> c;
            graph[u].push_back(make_pair(c, v));
        }
    }

    dijkstra();

    for (ll i = 0; i < n; i++) {
        cout << i << " " << d[i] << endl;
    }
}



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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int n,m;
vector<vector<int>> v;
vector<int> dp;
bitset<100010> bs;

int rec(int pos){
  if(bs[pos])return dp[pos];  
  for(auto e:v[pos])ChangeMax(dp[pos], rec(e)+1);
  bs[pos] = 1;
  return dp[pos];
}

int main(){
  cin >> n >> m;
  v.resize(n);
  dp.resize(n,0);
  for(int i = 0; i < m; ++i){
    int x,y; cin >> x >> y;x--;y--;
    v[x].push_back(y);
  }
  int ans = 0;
  for(int i = 0; i < n; ++i){
    ChangeMax(ans, rec(i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8192
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const s = args[0][0]
	const N = s.length
	const arr = new Array()

	for (let i = 0; i < N; i++) {
		if (s[i] === '0' || s[i] === '1') {
			arr.push(s[i])
		} else {
			arr.pop()
		}
	}

	console.log(arr.join(''))
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

int main() {
	int a,b,c;cin>>a>>b>>c;
	int max=a;
	if(a<b)max=b;
	if(max<c)max=c;
	int ans=(max-a)/2;
	a=(max-a)%2;
	ans+=(max-b)/2;
	ans+=(max-c)/2;
	b=(max-b)%2;
	c=(max-c)%2;
	int rem=a+b+c;
	if(rem==2){
		cout<<ans+1<<endl;
	}else if(rem==1){
		cout<<ans+2<<endl;
	}else{
		cout<<ans<<endl;
	}

	return 0;
}


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

int main(){
	int N, i, j, k, l, ans;
	scanf("%d", &N);
	ans = N;
	vector<int> x(N), y(N);
	for(i = 0; i < N; i++){
		scanf("%d%d", &x[i], &y[i]);
	}
	for(i = 0; i < N; i++){
		for(j = 0; j < N; j++){
			int p = x[i] - x[j], q = y[i] - y[j];
			if(p == 0 && q == 0){
				continue;
			}
			int cnt = 0;
			for(k = 0; k < N; k++){
				for(l = 0; l < N; l++){
					if(x[k] - x[l] == p && y[k] - y[l] == q){
						cnt++;
					}
				}
			}
			ans = min(ans, N - cnt);
		}
	}
	printf("%d\n", ans);
	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++)

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

    int x = (int) (n / 1.08);

    if (((int) (x * 1.08)) != n && ((int) ((x + 1) * 1.08)) != n) {
        cout << ":(" << endl;
    } else {
        if ((int) (x * 1.08) == n) {
            cout << x << endl;
        } else {
            cout << ++x << endl;
        }
    }
}

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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> arr(n,0);
    vector<int> dp(n,INT_MAX);
    for(int i=0;i<n;i++)cin>>arr[i];
    dp[0]=0;    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=i+k;j++){
            if(j<n)dp[j] = min(dp[j],dp[i]+abs(arr[i]-arr[j]));
            else break;
        }
    } 
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1024
//#include<bits/stdc++.h>
#define ll long long
#include <stdio.h>
#include <algorithm>
#pragma GCC optimize(2)
using namespace std;
const int maxn=1e6+1000;
const int INF=1e9+7;
inline ll read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
ll n,m,x;
char str[100005];
int main()
{
    scanf("%lld%s",&n,str);
    if(n>=3200) printf("%s\n",str);
    else printf("red\n");
    return 0;
}


Measured memory_bytes: 128
from functools import reduce


def _gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def _lcm(a, b):
    return (a * b) // _gcd(a, b)


def lcm(*n):
    return reduce(_lcm, n)


def f(_a):
    num = lcm(*_a)
    result = 0
    for i in _a:
        result += (num - 1) % i
    return result


N = int(input())
A = list(map(int, input().split()))
print(f(A))


Measured memory_bytes: 3940
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
  
    int N,K;
    cin >> N >> K;

    vector<long long> x(N);
    for(int i = 0;i < N;i++) {
        cin >> x.at(i);
    }
    
    long long ans = 1000000000;
    for(int i = 0;i < N - K + 1;i++) {
        long long l = x.at(i);
        long long r = x.at(i + K - 1);
        long long dis1 = abs(l) + abs(r - l),dis2 = abs(r) + abs(l - r);
        long long mini = min(dis1,dis2);
        ans = min(ans,mini);
    }

    cout << ans << endl;

    
}



Measured memory_bytes: 1024
a=input()
if a[0]==a[1]==a[2]=="R":
  print(3)
else:
  if a[0]==a[1]=="R":
    print(2)
  else:
    if a[1]==a[2]=="R":
      print(2)
    else:
      if a[0]=="R" or a[1]=="R" or a[2]=="R":
        print(1)
      else:
        print(0)

Measured memory_bytes: 9024
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

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

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);

//番号ズレ注意！！
int main() {
    int N, M, C;
    cin >> N >> M >> C;
    int B[M];
    REP(i, M) {
        cin >> B[i];
    }
    int A[N][M];
    int ans = 0;
    REP(i, N) {
        int sum = C;
        REP(j, M) {
            cin >> A[i][j];
            sum += A[i][j] * B[j];
        }
        if (sum > 0)ans += 1;
    }
    print(ans);
}


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

int gcd(int p, int q) {
	if (p < q) swap(p, q);
	if (p % q == 0) return q;
	else return gcd(p / q, p % q);
}
int keta(long p, int q) {
	if (p / 10 == 0) return q + 1;
	else return keta(p / 10, q + 1);
}
long long kaijo(int p, int q) {
	if (p == 1) return q;
	else return kaijo(p - 1, p * q);
}
long long Combination(int p, int q, int r, long long tmp) {
	if (q == 0) return tmp;
	else {
		tmp = tmp * p / r;
		tmp %= 1000000007;
		return Combination(p - 1, q - 1, r + 1, tmp);
	}
}
long long ruijo(long long p, long long q) {
	long long ans = 1;
	if (q >= 1) {
		rep(i, q) {
			ans *= p;
			ans %= 1000000007;
		}
	}
	return ans;
}

int main() {
	long long N, U, zero, zeronine, number, ans;
	cin >> N;
	number = 1000000007;
	U = ruijo(10, N - 1);
	zero = ruijo(9, N);
	zeronine = ruijo(8, N - 1);
	ans = (U * 10 - (2 * zero) % number + zeronine * 8) % number;
	cout << ans << endl;
}

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

int main()
{
    ll  n , k , x , y , ans;

    cin>>n>>k>>x>>y;

    if(n > k){
        ans = (k*x) + (n-k)*y;
    }
    else{
        ans = n*x;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3604
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  ll sum = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  for(int i = 0; i < n; i++) {
    cin >> b[i];
    sum -= b[i];
  }
  if(sum < 0) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> d;
  int limit = 0;
  for(int i = 0; i < n; i++) {
    if(a[i] > b[i]) {
      d.push_back(a[i] - b[i]);
      limit++;
    }
  }
  sort(d.rbegin(), d.rend());
  int cnt = 0;
  int ans = 0;

  for(int i = 0; i < n; i++) {
    if(a[i] < b[i]) {
      ans++;
      while(a[i] < b[i]) {
        if(abs(a[i] - b[i]) >= d[cnt]) {
          a[i] += d[cnt];
          d[cnt] = 0;
          cnt++;
          if(cnt == limit) {
            break;
          }
        } else {
          d[cnt] -= (b[i] - a[i]);
          a[i] = b[i];
        }
      }
    }
  }
  if(ans > 0) {
    cnt++;
  }
  cout << cnt + ans << endl;
  return 0;
}

Measured memory_bytes: 4372
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
long y1,m1,d1,y2,m2,d2;
string s[10];
while(cin>>y1>>m1>>d1>>y2>>m2>>d2){
if(y1<0||m1<0|d1<0||y2<0||m2<0||d2<0)break;
if(m1<3){y1--;m1+=12;}
if(m2<3){y2--;m2+=12;}
d1=long(365.25*y1)+y1/400-y1/100+long(30.59*(m1-2))+d1;
d2=long(365.25*y2)+y2/400-y2/100+long(30.59*(m2-2))+d2;
cout<<d2-d1<<endl;
}
return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

#define x first
#define y second

int block=700;

bool cmp(pair<pair<int,int>,int> p, pair<pair<int,int>,int> q) {
    if (p.first.first / block != q.first.first / block)
        return p < q;
    return (p.first.first / block & 1) ? 
        (p.first.second < q.first.second) : (p.first.second > q.first.second);
}

int clrs[1000007];
int ans[500005];
int arr[500005];
int n,qq;
vector<pair<pair<int,int>,int>>v;

int32_t main() 
{
    IOS
    cin>>n>>qq;
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    for(int i=0;i<qq;i++)
    {
        int a,b;
        cin>>a>>b;
        v.push_back({{a,b},i});
    }
    sort(v.begin(),v.end(),cmp);
    int cur_l = 1;
    int cur_r = 0;
    int sum=0;
    for(auto q:v)
    {
        while (cur_l > q.x.x) 
        {
            cur_l--;
            clrs[arr[cur_l]]++;
            if(clrs[arr[cur_l]]==1)
                sum++;
        }
        while (cur_r < q.x.y) 
        {
            cur_r++;
            clrs[arr[cur_r]]++;
            if(clrs[arr[cur_r]]==1)
                sum++;
        }
        while (cur_l < q.x.x) 
        {
            clrs[arr[cur_l]]--;
            if(clrs[arr[cur_l]]==0)
                sum--;
            cur_l++;
        }
        while (cur_r > q.x.y) 
        {
            clrs[arr[cur_r]]--;
            if(clrs[arr[cur_r]]==0)
                sum--;
            cur_r--;
        }
        ans[q.y] = sum;
    }
    for(int i=0;i<qq;i++)
        cout<<max(0ll,ans[i])<<endl;
}   


Measured memory_bytes: 27348
#include <iostream>
using namespace std;
int main() {
	int W, H, X, Y;
	cin >> W >> H >> X >> Y;
	cout.precision(15);
	cout << 0.5 * W * H << ' ' << (X * 2 == W && Y * 2 == H ? 1 : 0) << endl;
	return 0;
}

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

typedef long long ll;
const int N = 1010;
const int moder = 1e9 + 7;

struct matrix{
	int a[2][2];
	
	matrix (){memset(a, 0, sizeof(a));}
	
	int *operator [] (int n){return a[n];}
	
	matrix operator * (const matrix &m)const{
		matrix ret;
		for (int k = 0; k < 2; ++ k){
			for (int i = 0; i < 2; ++ i){
				for (int j = 0; j < 2; ++ j){
					ret.a[i][j] = (ret.a[i][j] + 1ll * a[i][k] * m.a[k][j]) % moder;
				}
			}
		}
		return ret;
	}
};

int powermod(int a, ll exp){
	int ret = 1;
	for ( ; exp > 0; exp >>= 1){
		if (exp & 1){
			ret = 1ll * ret * a % moder;
		}
		a = 1ll * a * a % moder;
	}
	return ret;
}

matrix powermod(matrix a, ll exp){
	matrix ret;
	ret[0][0] = ret[1][1] = 1;
	for ( ; exp > 0; exp >>= 1){
		if (exp & 1){
			ret = ret * a;
		}
		a = a * a;
	}
	return ret;
}

char s[N][N];

int main(){
	int h, w;
	scanf("%d%d", &h, &w);
	ll k;
	scanf("%lld", &k);
	for (int i = 0; i < h; ++ i){
		scanf("%s", &s[i]);
	}
	int black = 0;
	for (int i = 0; i < h; ++ i){
		for (int j = 0; j < w; ++ j){
			black += s[i][j] == '#';
		}
	}
	int row = 0;
	for (int i = 0; i < h; ++ i){
		row += s[i][0] == '#' && s[i][w - 1] == '#';
	}
	int column = 0;
	for (int i = 0; i < w; ++ i){
		column += s[0][i] == '#' && s[h - 1][i] == '#';
	}
	if (row && column || !k){
		puts("1");
		return 0;
	}
	if (!row && !column){
		printf("%d\n", powermod(black, k - 1));
		return 0;
	}
	matrix trans;
	trans[0][0] = black;
	if (row){
		for (int i = 0; i < h; ++ i){
			for (int j = 0; j < w - 1; ++ j){
				trans[0][1] += s[i][j] == '#' && s[i][j + 1] == '#';
			}
		}
	}
	else{
		for (int j = 0; j < w; ++ j){
			for (int i = 0; i < h - 1; ++ i){
				trans[0][1] += s[i][j] == '#' && s[i + 1][j] == '#';
			}
		}
	}
	trans[0][1] = (moder - trans[0][1]) % moder;
	trans[1][1] = row | column;
	trans = powermod(trans, k - 1);
	int ans = trans[0][0] + trans[0][1];
	ans -= ans >= moder ? moder : 0;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> adjlist;
int t=0;
vector<int> d;
vector<int> f;
void input(int n){
	vector<int> f={0,0};
	adjlist.push_back(f);
  for(int i=0;i<n;i++){
    vector<int> list;
    int ln;
    cin>>ln;
    list.push_back(ln);
    cin>>ln;
    list.push_back(ln);
    for(int j=0;j<ln;j++){
      int an;
      cin>>an;
      list.push_back(an);
    }
    adjlist.push_back(list);
  }
}

void depth_search(int id){
	vector<int> list=adjlist[id];
	for(int j=0;j<list[1];j++){
		if(d[list[2+j]]<0){
			d[list[2+j]]=++t;
			depth_search(list[2+j]);
		}
	}
	f[id]=++t;
}
 
void print(int n){
  for(int i=1;i<n+1;i++){
    cout<<i<<' '<<d[i]<<' '<<f[i]<<endl;
  }
}
int main(){
  int n;
  cin>>n;
	d=vector<int> (n+1,-1);
	f=vector<int> (n+1,-1);
  input(n);
	for(int i=1;i<n+1;i++){
		if(f[i]<0){
			d[i]=++t;
			f[i]=t;
			depth_search(i);
		}
	}
  print(n);
  return 0;
}


Measured memory_bytes: 3172
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	m := eGetInt(scanner)
	if n == m {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func pow(a, n int) int {
	return int(math.Pow(float64(a), float64(n)))
}
func countBitOfOn(i, numbits int) int {
	count := 0
	var bit uint64
	for bit = 0; bit < uint64(numbits); bit++ {
		t := 1 << bit
		if i&t > 0 {
			count++
		}
	}
	return count
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int h,w,k; cin >>h >>w >>k;
  vector<vector<int>> map(h,vector<int>(w,0));
  rep(i,h){
    rep(j,w){
      char c; cin >>c;
      map[i][j]=(c=='#');
    }
  }
  
  int limh=1<<h,limw=1<<w,ans=0;
  rep(bsh,limh){
    rep(bsw,limw){
      int cnt=0;
      rep(i,h){
        if(bsh&(1<<i)) continue;
        rep(j,w){
          if(bsw&(1<<j)) continue;
          cnt+=map[i][j];
        }
      }
      if(k==cnt) ans++;
    }
  }
  
  print(ans);
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a > c && b < c) {cout << "Yes" << endl;}
  else if (a < c && b > c) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,n) for(int i = -1; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	if (a < b) return gcd(b, a);

	unsigned c;

	while ((c = a % b)) {
		a = b;
		b = c;
	}
	return b;
}

ll lcm(ll a, ll b) {
	ll c = gcd(a, b);
	return a / c * b;
}


int main() {

	int s, w;

	cin >> s >> w;

	bool ans= true;

	if (s <= w) ans = false;

	puts(ans ? "safe" : "unsafe");


	return 0;
}

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

int main() {
	int n, d;
	cin >> n >> d;
	vector a(n, vector(2, 0));
	rep(i, n) rep(j, 2) cin >> a[i][j];

	atcoder::two_sat t(n);
	rep(i, n) for (int j = i + 1; j < n; ++j) rep(k, 4) {
		if (abs(a[i][k >> 1] - a[j][k & 1]) < d) t.add_clause(i, k >> 1, j, k & 1);
	}
	if (t.satisfiable()) {
		puts("Yes");
		auto ans = t.answer();
		rep(i, n) cout << a[i][!ans[i]] << endl;
	} else {
		puts("No");
	}
}

Measured memory_bytes: 3800
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  for(int n,d;cin>>n>>d,n;){
    vector<int> c[100];
    int s[100]={};
    int nm=0;
    for(int i=0;i<n;i++){
      int m;
      cin>>m;
      c[i].resize(m);
      for(int j=0;j<m;j++){
	cin>>c[i][j];
	nm++;
	s[i]+=c[i][j];
      }
    }
    if(n==1){
      nm=0;
    }
    for(;nm;nm--){
      vector<int> v(begin(s),begin(s)+n);
      sort(v.rbegin(),v.rend());
      for(int i=0;i<n;i++){
	if(!c[i].empty()&&((s[i]==v[0])?v[1]:v[0])-(s[i]-c[i].back())<=d){
	  s[i]-=c[i].back();
	  c[i].pop_back();
	  goto next;
	}
      }
      break;
    next:
      ;
    }
    cout<<(nm?"No":"Yes")<<endl;
  }
}

Measured memory_bytes: 1244
//cwystc <--> 陈威宇是天才  --by cwy
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const double PI=acos(-1);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
#define per(i,a,b) for (int i=(a);i>=(b);i--)
#define Rep(i,a,b) for (int i=(a);i<(b);i++)
#define Per(i,a,b) for (int i=(a);i>(b);i--)
#define travel_set(it,a) for (set<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_map(it,a) for (map<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_vec(it,a) for (vector<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define p(x) cout << x << endl;
#define def cout << "find" << endl;
#define what_is(x) cout << #x << " is " << x << endl;
template <class T>T sqr(T x){return x*x;}
template <class T>T alex(T x){return (x>0)?x:-x;}
template <class T>void read(T&x){
	x=0;T f=1;char ch=getchar();
	while ((ch<48||ch>57)&&ch!=45)ch=getchar();
	if (ch==45)f=-1,ch=getchar();
	while (ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();
	x*=f;
}

//-------------------------------------------------head-------------------------------------------------

#define maxn 100005
int n;
vector<int>E[maxn];
int sign[maxn];bool vis[maxn];
bool gbit(int x,int bit){return (x>>bit)&1;}
void dfs(int x){
	vis[x]=true;int _sign=0;int s=0;
	Rep(i,0,E[x].size())if (!vis[E[x][i]]){
		dfs(E[x][i]);s|=(_sign&sign[E[x][i]]);_sign|=sign[E[x][i]];
	}
	Rep(i,(int)log2(s),20)if (gbit(_sign,i)==0){_sign=_sign>>i<<i|(1<<i);break;}
	sign[x]=_sign;
}
int main(){
	// freopen("D.in","r",stdin);
	// freopen("D.out","w",stdout);
	read(n);
	Rep(i,1,n){
		int x,y;read(x);read(y);
		E[x].pb(y);E[y].pb(x);
	}
	dfs(1);int res=0;
	rep(i,1,n)res=max(res,sign[i]);/*
	cerr << (int)log2(1<<0) << endl;
	cerr << (int)log2(1<<1) << endl;
	cerr << (int)log2(1<<2) << endl;
	cerr << (int)log2(1<<3) << endl;
	cerr << (int)log2(1<<4) << endl;
	cerr << (int)log2(1<<5) << endl;
	cerr << (int)log2(1<<6) << endl;
	cerr << (int)log2(1<<7) << endl;
	cerr << (int)log2(1<<8) << endl;
	cerr << (int)log2(1<<9) << endl;
	cerr << (int)log2(1<<10) << endl;
	cerr << (int)log2(1<<11) << endl;
	cerr << (int)log2(1<<12) << endl;
	cerr << (int)log2(1<<13) << endl;
	cerr << (int)log2(1<<14) << endl;
	cerr << (int)log2(1<<15) << endl;
	cerr << (int)log2(1<<16) << endl;
	cerr << (int)log2(1<<17) << endl;
	cerr << (int)log2(1<<18) << endl;
	cerr << (int)log2(1<<19) << endl;*/
	res=(int)log2(res);printf("%d\n",res);return 0;
}

Measured memory_bytes: 10752
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.next();
        String t = in.next();

        for (int i = 0; i < s.length(); i++) {
            System.out.print(s.charAt(i));
            System.out.print(t.charAt(i));
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main ()
{
    int a, b, c, x;
    cin >> a>> b >>c;
    if (a>b) {
        x=a;
        a=b;
        b=x;
    }
       if(b > c){
      x = b;
      b = c;
      c = x;

 

   }
   
   if(a > b){
      x = a;
      a = b;
      b = x;
      
   }
   
   cout << a << " " << b << " " << c << endl;
   
   return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define frfr  freopen("input.text","r",stdin); freopen("output.text","w",stdout)
#define ll long long int 
void solve(){
	int d,t,s;
	cin>>d>>t>>s;
  	double req=double(d)/s;
	if(req>t){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
}
int main(){
	IOS;
	//frfr;
	solve();
}

Measured memory_bytes: 3600
<?php

$data = array();
while ($line = fgets(STDIN)) {
    $value = rtrim($line);
    if ('0' === $value) break;
    if (10000 < (int)($value)) continue;
    $data[] = $value;
}

$i = 1;
foreach ($data as $value) {
    printf("Case %d: %d\n", $i, $value);
    $i++;
}

Measured memory_bytes: 16860
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100005;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
vector<vector<ll>> g(200005);
vector<ll> cnt(200005,0);
vector<bool> done(200005,0);
void dfs(ll v){
    done[v] = 1;
    for (ll u:g[v]){
        if (done[u]) continue;
        cnt[u] += cnt[v];
        dfs(u);
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,q,a,b,p,x;
    cin >> n >> q;
    rep(i,n-1){
        cin >> a >> b;
        --a;
        --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i,q){
        cin >> p >> x;
        cnt[p-1] += x;
    }
    dfs(0);
    array_output(cnt.begin(),cnt.begin()+n);
}




Measured memory_bytes: 27268
#include<stdio.h>
int main(void){
 long long int x,ans=0,a;
 scanf("%lld",&x);
 a=x/500;
 ans+=a*200;
 x%=500;
 a=x/5;
 ans+=a;
 printf("%lld\n",ans*5);
 return 0;
}


Measured memory_bytes: 128
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print("-1")
    exit()

if len(S) < 26:
    for i in range(26):
        if not chr(ord("a") + i) in S:
            print(S + chr(ord("a") + i))
            exit()
else:
    pop_list = []
    S = list(S)
    while True:
        pop_chr = S.pop()
        pop_list.append(pop_chr)
        pop_list.sort()
        for candidate in pop_list:
            if S[-1] < candidate:
                S.pop()
                S.append(candidate)
                print(*S, sep="")
                exit()


Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> a(N);
	map<int, int> mp;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		mp[a[i]]++;
	}

	bool flag = false;
	if (mp.size() == 1 && a[0] == 0) flag = true;
	if (N % 3 == 0) {
		if (mp.size() == 2 && mp[0] == N / 3) flag = true;
		if (mp.size() == 3) {
			int tmp = 0, num;
			for (const auto &e : mp) {
				tmp ^= e.first;
				num += e.second != N / 3;
			}
			if (tmp == 0 && num == 0)flag = true;
		}
	}

	if (flag) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

string s, t;

int main(){
    cin >> s >> t;
    
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    if(s < t) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                                #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,pa>
                                        #define ppa pair<int,int>
                                        #define ppap pair<pa,pa>
                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-10)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
                                  #define VI vector<int>
                                        using namespace std;
                                        
                                  class pas{
                                    	public:
                                    	int x,y;
                                    	pas(int x=0,int y=0):x(x),y(y) {}
                                    	pas operator + (pas p) {return pas(x+p.x,y+p.y);}
                                    	pas operator - (pas p) {return pas(x-p.x,y-p.y);}
                                    	pas operator * (int a) {return pas(x*a,y*a);}
                                    	pas operator / (int a) {return pas(x/a,y/a);}
                                    //	double absv() {return sqrt(norm());}
                                    	int norm() {return x*x+y*y;}
                                    	bool operator < (const pas &p) const{
                                    		return x != p.x ? x<p.x: y<p.y;
                                    	}
                                    	bool operator == (const pas &p) const{
                                    		return x==p.x && y==p.y;
                                    	}
                                    };
int n,V,W,K,N,L,R;
vector<int>ve;

//int dp[2][10001]={0};
int a[1010] ;
int s;
           signed main(){
           	int h,l;
      cin>>h>>l;
           	//if(h>=l)cout<<1<<endl;
           	if(h>-l)cout<<1<<endl;
           	else if(h==-l) cout<<0<<endl;
           	else cout<<-1<<endl;
           }
             

Measured memory_bytes: 3080
import itertools

n = int(input())
a = [i+1 for i in range(n)]

p = list(map(int, input().split()))
q = list(map(int, input().split()))

ans = []
for i, v in enumerate(itertools.permutations(a, n)):
    if list(v) == p or list(v) == q:
        ans.append(i)
    if len(ans) == 2:
        print(ans[1] - ans[0])
        exit()
print(0)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {
	long long N, M;
	cin >> N >> M;
	string S;
	cin >> S;

	vector<long long> ANS;

	for (long long i = S.size() - 1; i > 0; i--) {
		for (long long j = M; j >= 0; j--) {
			if (j == 0) {
				cout << -1;
				return 0;
			}
			if (i - j < 0) {
				continue;
			}
			if (S[i - j] == '0' ) {
				ANS.push_back(j);
				i = i - j + 1;
				break;
			}
		}
	}

	for (long long i = ANS.size() - 1; i >= 0; i--) {
		cout << ANS[i];
		if (i != 0) {
			cout << ' ';
		}
	}

	return 0;
}


Measured memory_bytes: 1528
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int a,b; 
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(a);in(b);cout<<a*b<<endl;
	return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>

int min(int x,int y){
  if(x<y) return x;
  else return y;
}

int main(){
  int a,b,c,d,e,f,i,j,lim,max[2]={},k;
  double maxi=0.0;
  scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
  
  for(i=0;i<=f/(a*100);i++){
    for(j=0;(a*i+b*j)*100<=f;j++){
      lim=min((a*i+b*j)*e,f-(a*i+b*j)*100);
      for(k=0;k*d<=lim;k++){
        if(maxi<=(double)(k*d+(lim-k*d)/c*c)/((k*d+(lim-k*d)/c*c)+(a*i+b*j)*100)){
          maxi=(double)(k*d+(lim-k*d)/c*c)/((k*d+(lim-k*d)/c*c)+(a*i+b*j)*100);
          max[0]=(k*d+(lim-k*d)/c*c)+(a*i+b*j)*100;
          max[1]=(k*d+(lim-k*d)/c*c);
        }
      }
    }
  }
  printf("%d %d\n",max[0],max[1]);
}

Measured memory_bytes: 128
# include <stdio.h>
# include <string.h>
# define MAX(a,b) (a)>(b)?(a):(b)
typedef long long LL;

int main ()
{
	int i, n, a, b;
	LL x=1, y=1, d;
	scanf("%d",&n);
	for (i=1; i<=n; ++i) {
		scanf("%d%d",&a,&b);
		d=MAX((x+a-1)/a,(y+b-1)/b);
		x=a*d; y=b*d;
	}
	printf("%lld\n",x+y);
	return 0;
}

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

long long l[100];
int main(){
  long long n; cin>>n;
  l[0]=2;
  l[1]=1;
  for(int i=2;i<=n;i++){
    l[i]=l[i-1]+l[i-2];
  }
  cout<<l[n]<<endl;
  return 0;
}

Measured memory_bytes: 256
def main():
	from collections import deque
	N,M,*L,S,T = map(int,open(0).read().split())
	G = [[] for _ in range(N)]
	step = [False]*(3*N)
	step[(S-1)*3] = True
	for u,v in zip(*[iter(L)]*2):
		G[u-1].append(v-1)
	q = deque([(S-1,0)])
	while q:
		cur,d = q.popleft()
		for nxt in G[cur]:
			if nxt==T-1 and (d+1)%3==0:
				print((d+1)//3)
				exit()
			if not step[nxt*3+(d+1)%3]:
				step[nxt*3+(d+1)%3] = True
				q.append((nxt,d+1))
	print(-1)
	
if __name__=="__main__":main()

Measured memory_bytes: 28484
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  while(cin >> n, n) {
    char ba[n][n];
    REP(i,n)
      REP(j,n)
      cin >> ba[j][i];
    int dp[n][n][4]; // ツ可。ツ、ツ縦ツ、ツ偲篠湘」ツ債カツ、ツ偲篠湘」ツ右
    memset(dp,0,sizeof(dp));
    
    REP(y,n) {
      REP(x,n) {
        if (ba[x][y] == '1') {
          dp[x][y][0] = ((x>0)?dp[x-1][y][0]:0) + 1;
          dp[x][y][1] = ((y>0)?dp[x][y-1][1]:0) + 1;
          dp[x][y][2] = ((x>0&&y>0)?dp[x-1][y-1][2]:0) + 1;
          dp[x][y][3] = ((x<n-1&&y>0)?dp[x+1][y-1][3]:0) + 1;
        }
      }
    }
    cout << *max_element(&dp[0][0][0],&dp[n-1][n-1][3]) << endl;
  }
}

Measured memory_bytes: 1944
#include <iostream>

using namespace std;

typedef struct Station {
	int distance;
	int opening;
	int cycle;
	int takeTime;
};

Station stations[512];

int main() {
	int n; cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int c, s, f;
		cin >> c >> s >> f;

		Station station = {c, s, f, 0};
		stations[i] = station;
	}

	Station station = {0, 0, 0, 0};
	stations[n - 1] = station;

	for (int i = 0; i < n - 1; ++i) {
		for (int j = i; j < n; ++j) {
			// 開通式
			if (stations[i].takeTime < stations[j].opening) stations[i].takeTime = stations[j].opening;

			// 乗車間隔考慮
			if (stations[j].cycle > 0) {
				stations[i].takeTime +=
				    (stations[j].cycle - (stations[i].takeTime - stations[j].opening) % stations[j].cycle) % stations[j].cycle;
			}

			// 移動時間
			stations[i].takeTime += stations[j].distance;
		}
	}

	for (int i = 0; i < n; ++i) {
		cout << stations[i].takeTime << endl;
	}

	return 0;
}

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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" \
						  << " = " << a[i] << endl;
#define fastio                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define PI 3.141592654
#define all(v) v.begin(), v.end()

using namespace std;

using ll = long long;
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
using pi = pair<int, int>;

ll powmod(ll base, ll exp, const ll MOD) { ll ans = 1; while (exp) { if (exp & 1)	ans = (ans * base) % MOD; base = (base * base) % MOD; exp >>= 1; }return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }

//ll f[500005];
//ll kCn(ll k, ll n) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }


const int mxN = 1e6;


void test_case() {
	
}

int main() {
	fastio;
	int l, r, d;
	cin >> l >> r >> d;
	int ans = 0;
	for (int i = l; i <= r; ++i)
		ans += (i % d == 0);
	cout << ans;
	return 0;
}


Measured memory_bytes: 3660
N = int(input())
A = list(map(int, input().split()))
D = {}
for i in A:
    if i in D:
        D[i] += 1
    else:
        D[i] = 1
cnt = 0
for k in D.keys():
    if D[k] % 2:
        D[k] = 1
    else:
        D[k] = 2
        cnt += 1
print(len(set(A)) - (cnt % 2))


Measured memory_bytes: 20828
n, m = map(int, input().split())
 
sac = set()
lwa = [0] * n
 
for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if p in sac:
        continue
    elif s == 'AC':
        sac.add(p)
    else:
        lwa[p] += 1

print(len(sac), sum(lwa[p] for p in sac))

Measured memory_bytes: 12696
'use strict';
let isMine = grid => {
  if (grid === undefined) return false;
  if (grid === '#') return true;
  return false;
};

let countMine = (map, i, j) => {
  if (map[i][j] === '#') return '#';

  let count = 0;
  for (let x = -1; x <= 1; x++) {
    for (let y = -1; y <= 1; y++) {
      if (i + x < 0 || j + y < 0) continue;
      if (i + x >= map.length || j + y >= map[i].length) continue;
      // console.log(`${i + x}, ${j + y}`);
      if (isMine(map[i + x][j + y])) count++;
    }
  }
  return count + '';
};
let execute = input => {
  let inputs = input.split('\n');
  inputs.shift();
  let map = inputs.map(line => line.split(''));
  let ans = '';
  for (let i = 0; i < map.length; i++) {
    for (let j = 0; j < map[i].length; j++) {
      ans += countMine(map, i, j);
    }
    if (i + 1 !== map.length) ans += '\n';
  }
  return ans;
};

function Main(input) {
  console.log(execute(input));
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    int n = s.size();
    vector<string> v;
    int t = min(5, n);

    for (int i = 1; i <= t; i++){ //i文字分のsubstring
        rep(j, n - i + 1){
            v.push_back(s.substr(j, i));
        }
    }

    sort(v.begin(), v.end());

    v.push_back(" ");

    int i = 0, cnt = 1;
    while (true){
        if (v[i] != v[i+1]){
            if (cnt == k){
                cout << v[i] << endl;
                break;
            }
            cnt ++;
            i ++;
        }
        else i++;
    }
}

Measured memory_bytes: 1660
N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort(reverse=True)
BC = [0] * M
for i in range(M):
    b,c = list(map(int,input().split()))
    BC[i] = (c,b)
BC.sort(reverse=True)
#print(A)
#print(BC)
s = 0
count = 0
ai = 0
for c,b in BC:
    while A[ai] >= c and ai < N:
        #print(s)
        s += A[ai]
        ai += 1
        count += 1
        if count == N:
            break
    #print(s)
    s += min(N-count,b)*c
    count += min(N-count,b)
    if count == N:
        break
s += sum(A[ai:ai+N-count])
print(s)

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

template<class INT>
std::vector<INT> factorize(INT n){
    std::vector<INT> res;
    for (INT i = 1; i * i <= n; i++){
        if (n % i == 0){
            res.push_back(i);
            if (i * i != n)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> A(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    auto F = factorize(accumulate(A.begin(), A.end(), 0));
    sort(F.begin(), F.end(), greater<int>());

    for (const auto &f: F){
        vector<int> B(n);
        for (int i = 0; i < n; i++)
            B[i] = A[i] % f;
        if (accumulate(B.begin(), B.end(), 0, [&](const auto &l, const auto &r){return l + min(r, f - r);}) > k + k)
            continue;
        const auto S = accumulate(B.begin(), B.end(), 0);
        const auto i = S / f;
        nth_element(B.begin(), B.begin() + (n - i), B.end());
        if (max(accumulate(B.begin(), B.begin() + (n - i), 0), S - accumulate(B.begin() + (n - i), B.end(), 0)) <= k){
            printf("%d\n", f);
            return 0;
        }
    }

    puts("0");
}

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

int main() {
	int n;
	while(cin >> n){
	int count = 0;
	for (int i = 0; i < 10;i++) {
		for (int j = 0; j < 10;j++) {
			for (int k = 0; k < 10;k++) {
				if (n - i - j - k >=0 && n - i - j - k <= 9) count++;
			}
		}
	}
	cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
import sys
import functools
sys.setrecursionlimit(10**6)

N = int(input())
MAXN = 10**5
six_ps = [6**i for i in range(1, 7)]
nine_ps = [9**i for i in range(1, 6)]


@functools.lru_cache(maxsize=None)
def rec(n):
    if n < 6:
        return n

    if n in six_ps or n in nine_ps:
        return 1

    six_tmps = [1 + rec(n - six_p) if six_p < n else MAXN for six_p in six_ps]
    six_tmp = min(six_tmps)

    nine_tmps = [
        1 + rec(n - nine_p) if nine_p < n else MAXN for nine_p in nine_ps
    ]
    nine_tmp = min(nine_tmps)

    return min(six_tmp, nine_tmp)


print(rec(N))


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

using static Input;
using static Util;
class Program
{
    static int N, M;
    static HashSet<int> A; 
    static void INPUT()
    {
        N = NextInt();
        M = NextInt();
        A = new HashSet<int>();
        for (int i = 0; i < M; i++)
        {
            A.Add( NextInt());
        }
        
    }

    static void OUT()
    {
        var dp = new long[N + 2];
        dp[0] = 1;
        for (int i = 0; i < N; i++)
        {
            if (!A.Add(i)) continue;
            dp[i + 1] += dp[i];
            dp[i + 2] += dp[i];
            dp[i + 1] %= MOD;
            dp[i + 2] %= MOD;
        }

        Console.WriteLine(dp[N]);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 22236
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""

input:
5 4
0 1
1 2
2 3
3 4

output:
1
2
3
"""

import sys

sys.setrecursionlimit(int(1e5))


def dfs_Tarjan(current, visited, disc, low, parent):
    global timer
    children = 0
    visited[current] = True
    disc[current] = low[current] = timer
    timer += 1

    for adj in adj_table[current]:
        if not visited[adj]:
            parent[adj] = current
            children += 1
            dfs_Tarjan(adj, visited, disc, low, parent)
            low[current] = min(low[current], low[adj])
            if parent[current] == -1 and children > 1:
                art_set.add(current)
            elif parent[current] != -1 and low[adj] >= disc[current]:
                art_set.add(current)

        elif adj != parent[current]:
            low[current] = min(low[current], disc[adj])

    return None


def dfs_init():
    parent = [-1] * v_num
    visited = [False] * v_num
    disc, low = ([float('inf')] * v_num for _ in range(2))

    for v in range(v_num):
        if not visited[v]:
            dfs_Tarjan(v, visited, disc, low, parent)

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    v_num, e_num = map(int, _input[0].split())
    edges = map(lambda x: x.split(), _input[1:])

    adj_table = tuple([] for _ in range(v_num))
    for edge in edges:
        source, target = map(int, edge)
        adj_table[source].append(target)
        adj_table[target].append(source)

    timer = 0
    art_set = set()
    # generate articulation points set
    dfs_init()
    if art_set:
        print(*sorted(art_set), sep='\n')

Measured memory_bytes: 23784
#include <bits/stdc++.h>
using namespace std ;
 
#define lli long long int
#define pb push_back
 
lli mmc(lli num1, lli num2) 
{
    lli mmc, aux, i;
 
    for (i = 1; i <= num2; i++) 
    {
        aux = num1 * i;
        if ((aux % num2) == 0) 
        {
            mmc = aux;
            i = num2 + 1;
        }
    }
    return mmc;
}
int main ()
{
    lli a , b ;
    cin >> a >> b ;
    cout << mmc(a , b) << endl;
    return 0 ;
}

Measured memory_bytes: 256