akhauriyash/Code-Regression huggingface dataset:
import heapq
from itertools import accumulate
inf = float('inf')

def dijkstra(ad_lst, n, s):
    costs = [inf for i in range(n+1)]
    costs[s], Q = 0, []
    heapq.heappush(Q, [costs[s], s])

    while(Q != []):
        c, u = heapq.heappop(Q)
        for v, c in ad_lst[u].items():
            if costs[u] + c < costs[v]:
                heapq.heappush(Q, [costs[u] + c, v])
                costs[v] = costs[u] + c
    return costs

n,m,s,t, = map(int, input().split())

route_y = {i: {} for i in range(n+1)}
route_s = {i: {} for i in range(n+1)}
for i in range(m):
    u, v, a, b = map(int, input().split())
    route_y[u][v] = a
    route_y[v][u] = a
    route_s[u][v] = b
    route_s[v][u] = b

cost_y = dijkstra(route_y, n, s)
cost_s = dijkstra(route_s, n, t)
result = list(accumulate([y+s for y,s in zip(cost_y, cost_s)][::-1], min))
yen = 10**15
[print(yen-result[i]) for i in range(n-1, -1, -1)]


Measured memory_bytes: 111588
#include<iostream>
#define MOD (1000000007)
using namespace std;
#define int long long
typedef long long ll;
ll modinv(ll a, ll m){
  ll b=m,u=1,v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  u%=m;
  if(u<0) u+=m;
  return u;
}
signed main(){
  ll n,same_n,tmp[100002],num[100001],s=-1,e,sel0,sel1;
  cin >> n;
  for(int i=0;i<=n;i++){
    cin >> tmp[i];
    num[tmp[i]]++;
    if(num[tmp[i]]==2){
      same_n=tmp[i];
    }
  }
  for(int i=0;i<n;i++){
    if(tmp[i]==same_n){
      if(s==-1)s=i;
      else e=i;
    }
  }

  for(int i=0;i<=n;i++){
    if(i==0){
      cout << n<<endl;
      sel0=n+1;
      sel1=1;
      continue;
    }
    if(i==n){
      cout << "1\n";
      continue;
    }
    sel0 = (((sel0*(n+1-i))%MOD)*modinv(i+1,MOD))%MOD;
    if(s+n-e+1<i)sel1=0;
    else sel1=(((sel1*(s+n-e+1-i)%MOD))*modinv(i,MOD))%MOD;
    ll num =sel0-sel1;
    if(num<0) num+=MOD;
    num%=MOD;
    cout << num<<endl;
  }
}


Measured memory_bytes: 2816
#include <iostream>

using namespace std;

int main()
{
	char c;
	cin >> c;
	switch (c) {
	case 'A':
		cout << "T" << endl;
		break;
	case 'T':
		cout << "A" << endl;
		break;
	case 'C':
		cout << "G" << endl;
		break;
	case 'G':
		cout << "C" << endl;
		break;
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
S_and_P_and_res_num = [['', 0, 0] for _ in range(N)]
for i in range(N):
    s, p = input().split()
    S_and_P_and_res_num[i][0] = s
    S_and_P_and_res_num[i][1] = int(p)
    S_and_P_and_res_num[i][2] = i + 1
S_and_P_and_res_num.sort(key=lambda x: (x[0], -x[1]))
[print(S_and_P_and_res_num[i][2]) for i in range(N)]


Measured memory_bytes: 9112
#include <iostream>
#include <set>
using namespace std;
    int d[101];
    int G[101][101];
void krusta(int n){
    int color[101],l,m;
    for(int i=1;i<=n;i++){
        d[i]=1000000;
        color[i]=0;
    }
    d[1]=0;
    while(1){
        m=1000000;
        for(int i=1;i<=n;i++){
            if(color[i]!=1 && d[i]<m){
                m=d[i];
                l=i;
            }
        }
        color[l]=1;
        if(m==1000000){
            break;
        }
        for(int i=1;i<=n;i++){
            if(color[i]!=1 && G[l][i]!=-1 && G[l][i]<d[i]){
                d[i]=G[l][i];
            }
        }
    }
}
int main(){
    int n,m;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>m;
            G[i][j]=m;
        }
    }
    krusta(n);
    int sum=0;
    for(int i=1;i<=n;i++){
        sum=sum+d[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3128
using System;
using System.Reflection;
using System.Linq.Expressions;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder {
    public class Program {
        static int[] getKeys(char delimiter) {
            var Keys = Console.ReadLine().Split(' ');
            int[] Ns = new int[Keys.Length];
            for (int i = 0; i < Keys.Length; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }

        static void Main() {
            var Keys = getKeys(' ');
            if (Keys[0] == Keys[1]) {
                Console.WriteLine(Keys[2]);
            } else if (Keys[1] == Keys[2]) {
                Console.WriteLine(Keys[0]);
            } else {
                Console.WriteLine(Keys[1]);
            }
        }
    }
}


Measured memory_bytes: 13140
package main

import "fmt"

var a, p []int

func eat(n, x int) int {
	if n == 0 {
		if x <= 0 {
			return 0
		}
		return 1
	} else if x <= 1+a[n-1] {
		return eat(n-1, x-1)
	} else {
		return p[n-1] + 1 + eat(n-1, x-2-a[n-1])
	}
}

func main() {
	var n, x int
	fmt.Scan(&n, &x)

	a = make([]int, n+1)
	a[0] = 1
	for i := range a[:len(a)-1] {
		a[i+1] = a[i]*2 + 3
	}

	p = make([]int, n+1)
	p[0] = 1
	for i := range p[:len(p)-1] {
		p[i+1] = p[i]*2 + 1
	}

	fmt.Println(eat(n, x))
}


Measured memory_bytes: 512
package main

import (
	"fmt"
	"sort"
)

var N int

type point struct {
	x, y int
}

func (p point) isLessThan(q point) bool {
	if p.x < q.x && p.y < q.y {
		return true
	}
	return false
}

type points []point

type reds struct {
	points
}

func (p reds) Len() int {
	return len(p.points)
}

func (p reds) Swap(i, j int) {
	p.points[i], p.points[j] = p.points[j], p.points[i]
}

func (p reds) Less(i, j int) bool {
	return p.points[j].y < p.points[i].y
}

type blues struct {
	points
}

func (p blues) Len() int {
	return len(p.points)
}

func (p blues) Swap(i, j int) {
	p.points[i], p.points[j] = p.points[j], p.points[i]
}

func (p blues) Less(i, j int) bool {
	return p.points[i].x < p.points[j].x
}

func main() {
	fmt.Scan(&N)

	ps := make(points, N)
	for i := range ps {
		fmt.Scan(&ps[i].x, &ps[i].y)
	}
	reds := reds{ps}
	sort.Sort(reds)

	ps = make(points, N)
	for i := range ps {
		fmt.Scan(&ps[i].x, &ps[i].y)
	}
	blues := blues{ps}
	sort.Sort(blues)

	count := 0
	pairs := make([]bool, N)
	for _, r := range reds.points {
		for i, b := range blues.points {
			if !pairs[i] && r.isLessThan(b) {
				count++
				pairs[i] = true
				break
			}
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _001_FindingMissingCards
{
    /*
     */

    class Program
    {
        static void Main()
        {
            Boolean cont = true;

            while (cont)
            {
                string line = Console.ReadLine();
                if (Convert.ToString(line) == "0")
                {
                    cont = false;
                }
                else
                {
                    char[] ca = line.ToCharArray();
                    int num = 0;
                    for (int i = 0; i < ca.Length; i++)
                    {
                        num += Convert.ToInt32(Convert.ToString(ca[i]));
                    }
                    Console.WriteLine(num);
                }
            }
        }
    }
}

Measured memory_bytes: 9252
#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
ull h;
unsigned long long digui(ull x)
{
    if(x>1)
    return (2*digui(x/2)+1);
    if(x==1)
    return 1;
}
int main()
{
    cin>>h;
    cout<<digui(h);
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	static char[][] map;
	static int h;
	static int w;
	static int n;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		h = stdIn.nextInt();
		w = stdIn.nextInt();
		n = stdIn.nextInt();
		map = new char[h][w];
		for(int i = 0; i < h; i++) {
			String tmp = stdIn.next();
			for(int j = 0; j < w; j++) {
				map[i][j] = tmp.charAt(j);
			}
		}
		System.out.println((solv())?"YES":"NO");
	}
	static char[][] TMap;
	static boolean[][] isR;
	static boolean solv() {
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w-1; j++) {
				TMap = new char[h][w];
				for(int k = 0; k < h; k++) {
					TMap[k] = Arrays.copyOf(map[k], map[k].length);
				}
				swapT(j,i,j+1,i);
				
				while(true) {
					isR = new boolean[h][w];
					fall();
					eC();
					boolean a = er();
					if(!a) {
						if(check()) {
							return true;
						}
						else {
							break;
						}
					}
				}
			}
		}
		return false;
	}
	public static void swapT(int x, int y, int xx, int yy) {
		char tmp = TMap[y][x];
		TMap[y][x] = TMap[yy][xx];
		TMap[yy][xx] = tmp;
	}
	public static void swapR(int x, int y, int xx, int yy) {
		boolean tmp = isR[y][x];
		isR[y][x] = isR[yy][xx];
		isR[yy][xx] = tmp;
	}
	
	static boolean eC() {
		boolean ret = false;
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				//x方向
				char tmp = TMap[i][j];
				if(tmp == '.') continue;
				boolean X = true;
				for(int k = 0; k < n; k++) {
					if(j+k >= w || tmp != TMap[i][j+k]) {
						X = false;
						break;
					}
				}
				boolean Y = true;
				for(int k = 0; k < n; k++) {
					if(i + k >= h || tmp != TMap[i+k][j]) {
						Y = false;
						break;
					}
				}
				
				if(X) {
					for(int k = 0; k < n; k++) {
						isR[i][j+k] = true;
					}
					ret = true;
				}
				if(Y) {
					for(int k = 0; k < n; k++) {
						isR[i+k][j] = true;
					}
					ret = true;
				}
			}
		}
		return ret;
	}
	static void show() {
		for(int i = 0; i < w; i++) {
			System.out.print("=");
		}
		System.out.println();
		
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				System.out.print(TMap[i][j]);
			}
			System.out.println();
		}
		for(int i = 0; i < w; i++) {
			System.out.print("=");
		}
		System.out.println();
	}
	static boolean fall() {
		boolean ret = false;
		while(true) {
			boolean a = false;
			for(int i = h-2; i >= 0; i--) {
				for(int j = 0; j < w; j++) {

					if(TMap[i+1][j] == '.' && TMap[i][j] != '.') {
						a = true;
						swapT(j,i+1,j,i);
						swapR(j,i+1,j,i);
					}
				}
			}
			if(!a) {
				break;
			}
			ret = true;
		}
		return ret;
	}
	static boolean er() {
		boolean ret = false;
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				if(isR[i][j]) {
					ret = true;
					TMap[i][j] = '.';
				}
			}
		}
		return ret;
	}
	
	static boolean check() {
		for(int i = 0; i < w; i++) {
			if(TMap[h-1][i] != '.') return false;
		}
		return true;
	}
}

Measured memory_bytes: 30712
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

int main() {
	int x;
	cin >> x;
	int cnt_500 = x / 500;
	x -= 500 * cnt_500;
	int cnt_5 = x / 5;
	ll ans = (ll)1000 * cnt_500 + (ll)5 * cnt_5;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;


int main()
{
	int a;
	int b;
	int c;
	int d;
	cin >> a >> b >> c >> d;
	if (((c - a >= 0) && (c - a <= d)) || ((a - c >= 0) && (a - c <= d)))
		cout << "Yes";
	else if (
		(((b - a >= 0) && (b - a <= d)) || ((a - b >= 0) && (a - b <= d)))	//aとb
		&&
		(((c - b >= 0) && (c - b <= d)) || ((b - c >= 0) && (b - c <= d)))	//bとc
		) {
		cout << "Yes";
	}
	else
		cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> P(n,0);
    rep(i,n) cin >> P[i];

    int c=0;
    for(int i=1; i<=n-2; i++){
        vector<int> tmp(3,0);
        rep(j,3) tmp[j] = P[i-1+ j];
        sort(ALL(tmp));
        if(tmp[1] == P[i])c++;
    }
    cout << c << endl;
    return 0;
}

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

char s[500001], sr[500001];
int n, kmp[500001], kmpr[500001];

void bld(char s[], int kmp[]) {
	int k = 0;
	f(i, 1, n) {
		while (k&&s[i] != s[k])k = kmp[k - 1];
		if (s[k] == s[i])++k;
		kmp[i] = k;
	}
}

int main() {
	scanf("%s", s);
	n = strlen(s);
	bld(s, kmp);
	int z = n - kmp[n - 1];
	if (z == 1) { printf("%d\n1", n); return 0; }
	if (n % z || z == n) { printf("1\n1"); return 0; }
	printf("2\n");
	f(i, 0, n)sr[n - i - 1] = s[i];
	bld(sr, kmpr);
	int an = 0;
	f(i, 1, n) {
		int z = i - kmp[i - 1];
		int j = n - i, y = j - kmpr[j - 1];
		if ((z == i || i % z) && (y == j || j % y))++an;
	}
	printf("%d", an);
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define ll         long long int
#define co         cout
#define ci         cin
#define sf1(n)     scanf("%lld",&n)
#define sf2(n,m)   scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define pf1(n)     printf("%lld\n",n);
#define mem(a,b)   memset(a,b,sizeof(a))
#define en         cout<<endl;
#define pb         push_back
#define fi         first
#define se         second
#define coy        cout<< "YES"<<endl;
#define con        cout<< "NO"<<endl;
#define f(a,b)     for(ll i=a;i<b;i++)
#define all(x)     (x).begin(),(x).end()
#define allr(x)    (x).rbegin(),(x).rend()
#define pi         pair<ll,ll>
#define br         break;
#define i64        long long
#define PI 3.1415926535897932384626433832795

int main()
{
    ll t,n,g,k,m,mx=0,mn=1e9,c,res,c1,x,y,w,z,c2;
    ci>>n;
    co<<n+(n*n)+(n*n*n);
}



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

int keisan(int a, int b){
  int c, d;
  while(d != 0){
    c = b;
    d = a % b;
    if(d == 0){
      break;
      }
    a = c, b = d;
  }
  return b;
}

int main(void){
  int k;
  cin >> k;
  long cnt = 0;
  int a, b;
  
  rep(i, k+1){
  	rep(j, k+1){
  	  a = keisan(i, j);
      rep(l, k+1){
        b = keisan(a, l);
        cnt += b;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3620
a = int(input()) #10
b = int(input()) #2
c = int(input()) #1
x = int(input())/50

ans=0
for p in range(0,a+1):
    for q in range(0,b+1):
        if x-c<=10*p+2*q and 10*p+2*q<=x:
            ans = ans+1

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define lol long long

int main()
{
	int N;
	cin >> N;
	vector<int> L(2 * N);
	int ans = 0;
	for (int i = 0; i < 2 * N; i++) {
		cin >> L[i];
	}
	sort(L.begin(), L.end());
	for (int i = 0; i < N; i++) {
		ans += L[i * 2];
	}
	cout << ans << endl;
}

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, y;
    x = n * 800;
    y = (n / 15) * 200;
    cout << x - y << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String fst[] = in.readLine().split(" ");
        String[] At = in.readLine().split(" ");
        String[] Bt = in.readLine().split(" ");
        int maxA = Integer.parseInt(fst[2]);
        int minB = Integer.parseInt(fst[3]);
        for (int index = 0; index < At.length; index ++) {
            maxA = Math.max(maxA, Integer.parseInt(At[index]));
        }
        for (int index = 0; index < Bt.length; index ++) {
            minB = Math.min(minB, Integer.parseInt(Bt[index]));
        }
        if(maxA == minB || maxA > minB){
            System.out.println("War");
        }else{
            System.out.println("No War"); 
        }
    }
}

Measured memory_bytes: 21204
n = gets.chomp.split(' ').map(&:to_i)[0]
as = gets.chomp.split(' ').map(&:to_i)
ans = Array.new(n, 0)
as.each { |a| ans[a - 1] = ans[a - 1] + 1 }
ans.each { |a| puts(a) }

Measured memory_bytes: 35752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	ll n,m;cin>>n>>m;
	if(n>1&&m>1) cout<<(n-2)*(m-2)<<"\n";
	else if(n==1&&m==1) cout<<1<<"\n";
	else cout<<max(n,m)-2<<"\n";
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, k;

	cin >> n >> k;

	if (n % k) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main() {
	int N, M, C;
	std::cin >> N >> M >> C;
	std::vector<int> B(M);
	for (int j=0; j<M; j++) {
	  std::cin >> B[j];
	}

	int n_success = 0;
	int score, A;
  for (int i=0; i<N; i++) {
		score = C;
	  for (int j=0; j<M; j++) {
		  std::cin >> A;
			score += A * B[j];
		}
		if (score > 0) n_success++;
	}

	std::cout << n_success << std::endl;
}


Measured memory_bytes: 256
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
class permut{
  constructor(ary){
    var n=ary.length;
    this.array=ary;
    this.id=Array(n).fill().map((a,i)=>i);
    this.id2=Array(n).fill().map((a,i)=>i);
    this.moved=Array(n).fill(0);
    this.left=Array(n).fill(true);
    this.done=false;
  }
  static swap(self,i){
    var u=self.id2[i],v=self.id2[i-1],t=self.id[u];
    self.id2[i]=self.id2[i-1],self.id2[i-1]=u;
    self.id[u]=self.id[v],self.id[v]=t;
  }
  next(){
    if(this.done)return;
    var n=this.array.length,res=Array(n);
    for(var i=0;i<n;i++)res[i]=this.array[this.id2[i]];
    while(i--){
      if(this.moved[i]<i){
        this.moved[i]++;
        var m=this.left[i]?this.id[i]:this.id[i]+1;
        permut.swap(this,m);
        return res;
      }
      this.moved[i]=0,this.left[i]=!this.left[i];
    }
    this.done=true;
    return res;
  }
}

console.log(main());
function main(){
  var n = o.a();
  var p = +o.l().join("");
  var q = +o.l().join("");
  var pm = new permut(Array(n).fill().map((a,i)=>i+1));
  var ary = [];
  while(1){
    var t = pm.next();
    if(t === undefined)break;
    ary.push(+t.join(""));
  }
  ary.sort((a,b)=>a-b);
  var ans;
  for(var i = 0;;i++){
    if(p === ary[i]){
      ans = i;
      break;
    }
  }
  for(var i = 0;;i++){
    if(q === ary[i]){
      return Math.abs(i-ans);
    }
  }
}

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

dist = [-1] * (N+1)
dist[1] = 0
connection = [[] for _ in range(N+1)]
ans = [-1] * (N+1)

for quel in range(M):
    a, b = map(int, input().split())
    connection[a].append(b)
    connection[b].append(a)

que = []
que.append(1)

while que:
    v = que.pop(0)

    for i in connection[v]:
        if dist[i] != -1:continue

        dist[i] = dist[v] + 1
        que.append(i)
        ans[i] = v

#print(dist)
print('Yes')
for j in range(2, N+1):
    print(ans[j])

Measured memory_bytes: 34388
#include <bits/stdc++.h> 
#define ll long long
#define F first
#define S second
#define FF first.first
#define FS first.second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e16, MOD=998244353;
     
ll n, q=1, a[N], b[N], c[N], m, x, y, z, X, Y, Z, o, u, h, w, mx, mn, ans=INF, Ans, k;
string s, S;
vector <ll> v[N];
pair<ll, ll> p[N];

int main(){ios_base::sync_with_stdio(false), cin.tie(0);
                    
//    cin>>q;
                        
    while(q--){ans=INF;
        
        cin>>n>>m;
        
        for (int i=1; i<=m; i++)cin>>x,n-=x;
        cout<<max(n, (ll)-1);
	}
	return 0;
}

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

using namespace std;

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

    if(a+b == c || b+c == a || a+c == b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using namespace std;

int main(){
	int M;
	cin>>M;
	for(int m = 1; m <= M; m++){
		int money, year, N;
		cin>>money>>year>>N;
		int mx;
		for(int n = 0; n < N; n++){
			int now_money = money;
			int interest = 0;
			int type; double ratio; int cost;
			cin>>type>>ratio>>cost;
			//calc
			for(int i = 0; i < year; i++){
				interest += (int)(ratio * now_money);
				if(type){
					now_money += interest;
					interest = 0;
				}
				now_money -= cost;
			}
			now_money += interest;
			if(n == 0 || mx < now_money)mx = now_money;
		}
		cout<<mx<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>

#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
#define INF 100000000000000001
using namespace std;

int main(){
	ll n;
	ll a[5];
	ll doko[6];
	ll time=0;
	ll min = INF;
	cin >> n;
	rep(i,0,5){
		cin >> a[i];
	}  
	rep(i,0,5){
		if(min > a[i]){
			min = a[i];
		}
	}
	time = n / min;
	if(n % min != 0){
		time++;
	}
	time += 4;
	cout << time << endl;
}


Measured memory_bytes: 256
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        int[] a = IntStream.range(0, N).map(i -> Integer.parseInt(sc.next())).toArray();
        int ans = 0;
        int index = 1;
        
        for (int i = 0; i < N; i++) {
            if (a[i] == index) {
                index++;
            } else if (a[i] != index) {
                ans++;
            }
        }
        
        out.println(index == 1 ? "-1" : ans);
        
        out.flush();
    }
}

Measured memory_bytes: 61484
#include <iostream>
#include <algorithm>
#include <string>
using namespace::std;
int main() {
    int N,cnt,res=0; 
    cin >> N;
    string S; cin >> S;
    for (int i=0;i<1000;i++){
        string lucky = to_string(i);
        if (lucky.size()==1) lucky = "00"+lucky;
        if (lucky.size()==2) lucky = "0" +lucky;
        cnt = 0;
        for (int j=0;j<N;j++){
            if (lucky[cnt]==S[j]) cnt++;
        }
        if (cnt==3) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  ll n;
  cin>>n;
  vector<ll> A;
  rep(i,n){
    ll a;
    cin>>a;
    A.push_back(a);
  }
  ll hoge[3];
  rep(i,3){
    hoge[i] = 0;
  }
  ll ans = 1;
  rep(i,n){
    ll a = A[i];
    ll count = 0;
    rep(j,3){
      if(a == hoge[j]){
        if(count == 0){
          hoge[j] += 1;
        }
        count++;
      }
    }
    if(count == 0){
      cout<<0<<endl;
      return 0;
    }
    ans *= count;
    ans %= MOD;
  }
  cout<<ans<<endl;

  return 0;
}


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

int main() {
    int n, l; cin >>n >>l;
    vector<string> s;
    for (int i = 0; i < n; i++) {
        string tmp;
        cin >> tmp;
        s.push_back(tmp);
    }
    sort(s.begin(), s.end());
    for (auto s_: s) {cout << s_;}; cout << endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

int main() {
    int n, k, m,M ; long long ans =0;
    vector<int> v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> k;
        v.push_back(k-i-1);
    }
    sort(v.begin(), v.end());
    m = v[n / 2]; M = v[n / 2 + 1];
    for (int i = 0; i < n; i++) ans += abs(v[i] - m);
    if (n % 2 == 1) {
        for(int j=(M-m)/2; j<=(M-m)/2+1; j++){
            long long s = 0;
            for (int i = 0; i < n;i++) {
                s += abs(v[i] -j);
            }
            ans = min(ans, s);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define pb push_back
#define MAXN 21010
#define Scan(a) scanf("%I64d", &a)
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int n, m, d[110];
vector<II> a[110];
map<II, int> ma;
priority_queue<II, vector<II>, greater<II> > h;
set<int> res, b[110];

void dijkstra(int s)
{
    FOR(i,1,n) b[i].clear();
    FOR(i,1,n) d[i] = 1000000000;
    d[s] = 0;
    h.push(II(d[s], s));
    while (!h.empty()) {
        II g = h.top();
        h.pop();
        if (d[g.Y] != g.X) continue;
        int u = g.Y;
        for (vector<II>::iterator it = a[u].begin(); it!=a[u].end(); it++) {
            int v = it->X;
            int c = it->Y;
            if (d[v] > d[u] + c) {
                d[v] = d[u] + c;
                h.push(II(d[v], v));
                b[v] = b[u];
                b[v].insert(ma[II(u,v)]);
            }
            else if (d[v] == d[u] + c) {
                for (set<int>::iterator it = b[u].begin(); it!=b[u].end(); it++) b[v].insert(*it);
                b[v].insert(ma[II(u,v)]);
            }
        }
    }
    FOR(i,1,n)
        for (set<int>::iterator it = b[i].begin(); it!=b[i].end(); it++) res.insert(*it);
}

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> n >> m;
    FOR(i,1,m) {
        int u, v, c;
        cin >> u >> v >> c;
        a[u].pb(II(v, c));
        a[v].pb(II(u, c));
        ma[II(u,v)] = i;
        ma[II(v,u)] = i;
    }
    FOR(i,1,n)
        dijkstra(i);
    cout << m - res.size();
    return 0;
}


Measured memory_bytes: 512
N,X = map(int,input().split())
Z=list(map(int,input().split()))

D=[]

for i in range(N):
    D.append(abs(X-Z[i]))
    
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
res = D[0]

for j in range(1, N):
    res = gcd(res, D[j])

print(res)


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

using namespace std;

typedef long long L;

L get(L y, L x) {
  L res = 0;
  if (x > y) {
    x = -x;
    res++;
  }
  res += abs(y - x);
  return res;
}

int main()
{
  L x, y;
  scanf("%lld %lld", &x, &y);
  
  if (x == y) {
    printf("0\n");
    return(0);
  }
  
  printf("%lld\n", min(min(get(y, x), get(-y, x) + 1), min(get(y, -x) + 1, get(-y, -x) + 2)));
  return(0);
}

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

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

	int a, b; cin >> a >> b;
	string A = to_string(b);
	string B = to_string(a);
	string X, Y;
	rep(i, a) X += A;
	rep(i, b) Y += B;
	cout << min(X, Y) << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(1-sc.nextInt());
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


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

int w, h;
bool data[99][99]; //x, y
int memo[99][99]; //x, y

int solve(int x, int y){

  if(y < 0 || x == w)  return 0;
  if(data[x][y]) return 0;
  if(memo[x][y]) return memo[x][y];
  if(x == w-1 && !y) return 1;

  return memo[x][y] = solve(x+1, y) + solve(x, y-1);
}

int main(){

  int n;

  while(true){
    cin >> w >> h;
    if(!w && !h) break;

    memset(data, false, sizeof(data));
    memset(memo, 0, sizeof(memo));

    cin >> n;
    for(int i=0;i<n;i++){
      int a, b;
      cin >> a >> b;
      data[--a][h-b] = true;
    }

    cout << solve(0, h-1) << endl;
  }
}

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

int a , b , c; 

int main(){
	scanf("%d %d %d" , &a , &b , &c);
	if(a == b && a != c || a == c && a != b || b == c && b != a) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a,b;

  scanf("%d %d", &a, &b);

  if (a < b) {
    printf("a < b\n");
  }
  else if (a > b) {
    printf("a > b\n");
  }
  else {
    printf("a == b\n");
  }
  return (0);
}



Measured memory_bytes: 2064
N,M=map(int,input().split())
s,t=0,0
G=[[] for i in range(N)]
for i in range(M):
  s,t=map(int,input().split())
  G[s-1].append(t-1)
A=1000
for x in range(N):
  DP=[0]*N
  for i in range(N-2,-1,-1):
    s=0
    for j in range(len(G[i])):
      s=max(s,DP[G[i][j]])
      DP[i]+=DP[G[i][j]]
    if i==x and len(G[i])!=1:
      DP[i]-=s
      DP[i]/=(len(G[i])-1)
    else:
      DP[i]/=len(G[i])
    DP[i]+=1
  A=min(A,DP[0])
print(A)

Measured memory_bytes: 85292
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [a, b, c]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    return `${a + b + c <= 21 ? "win" : "bust"}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


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

int main() {
    int N;
    cin >> N;
    
    int A[N];
    int B[N];
    int C[N];

    for( int i = 0 ; i < N; i++) cin >> A[i]; //食べた順
    for( int i = 0 ; i < N; i++) cin >> B[i]; //満足度
    for( int i = 0 ; i < N-1; i++) cin >> C[i]; //追加満足度

    int satisfiedPoint = 0;
    for( int i = 0 ; i < N; i++){
        satisfiedPoint += B[i];
    }
    for( int i = 0 ; i < N-1; i++){
        if ( A[i]+ 1 == A[i+1] ){
            satisfiedPoint += C[A[i]-1];
        }
    }
    cout << satisfiedPoint << endl;
    return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do
    [_,a,b] <- (map read . words) <$> getLine
    xs <- (map read . words) <$> getLine
    print $ solve (a, b) xs

solve :: (Int, Int) -> [Int] -> Int
solve (a,b) xs = sum cs
    where
        ds = zipWith (-) (tail xs) (init xs)
        cs = [min (d*a) b | d <- ds]

Measured memory_bytes: 36220
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
LL N, A, B;
LL x[MAX];

int main(void) {
    scanf("%ld%lld%lld", &N, &A, &B);
    REP(i, N) scanf("%lld", x + i);
    LL ans = 0;
    REP(i, N - 1) {
        ans += min(B, A * (x[i + 1] - x[i]));
    }
    cout << ans << endl;
}


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

bool func() {
    int counter = 0;
    unsigned long long N, A, B, C, X;
    cin >> N >> A >> B >> C >> X;
    if(N==0 && A==0 && B==0 && C==0 && X==0) return true;
    for(int i=0; i<N; i++) {
        if(i>0) {
            X = (A*X + B) % C;
            counter++;
        }
        int n;
        cin >> n;

        while(X!=n && counter<10001) {
            X = (A*X + B) % C;
            counter++;
        }
    }
    if(counter<10001) {
        printf("%d\n", counter);
    } else {
        printf("%d\n", -1);
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    bool flag = false;
    while(!flag) {
        flag = func();
    }
    return 0;
}



Measured memory_bytes: 3032
import sys
input = sys.stdin.readline
def main():
    S = input().rstrip()
    T = input().rstrip()
    ans = 0
    for i in range(len(S)-len(T)+1):
        CNT = 0
        for j in range(len(T)):
            if S[i+j] == T[j]:
                CNT += 1
        ans = max(ans, CNT)
    print(len(T) - ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << A.at(K-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a; cin>>a;
	cout<<((a+1)*a)/2;
	
	return 0;
}

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

struct P
{
    int x,y,z;

    bool operator<(const P &a)const{
              return x>a.x;
    }

};

vector<int> v,v1;
//bitset<4001000> b;
int a,c,i,b,n,m,k,d;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int o[333331];
long long l[333331];
int j[1];
int e;
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long x,y,mod=1000000007,mod2=1000000009,mod3=2017;
long long z;
double pi=3.14159265;
P u[1];
stack<int> s;

//set<long long> s;
queue<int> q;

//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p,p1;
//list<int> l;

//string r,r1;
char r[1113];
//deque<int> de;

bool as(P a,P b)
{
    if(max(a.z,-a.z)!=max(b.z,-b.z))
        return max(a.z,-a.z)<max(b.z,-b.z);
    return a.z<b.z;
    //return a.y<b.y;
}


int main()
{
    scanf("%d %d",&a,&b);
    n=a/b;
    if(b%2==0&&a>=b/2)
        m=max((a-b/2)/b+1,0);
    printf("%lld",(long long)n*(n)*(n)+(long long)m*(m)*(m));
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define Graph vector<vector<int>>
using namespace std;

int n, m;
vector<int> a(50), b(50);
Graph edge(50, vector<int> (50));
vector<bool> visited(50);

void dfs(int v) {
	visited[v] = true;
	for (int next = 0; next < n; next++) {
		if (edge[v][next] == false)
			continue;
		if (visited[next] == true)
			continue;
		dfs(next);
	}
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		edge[a[i]][b[i]] = true;
		edge[b[i]][a[i]] = true;
	}

	int ans = 0;
	for (int i = 0; i < m; i++) {
		edge[a[i]][b[i]] = false;
		edge[b[i]][a[i]] = false;

		for (int j = 0; j < n; j++)
			visited[j] = false;

		dfs(0);

		bool  bridge = false;
		for (int j = 0; j < n; j++) {
			if (visited[j] == false) {
				bridge = true;
				break;
			}
		}
		if (bridge)
			ans += 1;

		edge[a[i]][b[i]] = true;
		edge[b[i]][a[i]] = true;
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int R = 0;
  int B = 0;
  for ( int i = 0 ; i<N ; i++ ) {
    if ( S[i] == 'R' ) { 
      R++;
    }
    else {
      B++;
    }
  }
  if ( R > B ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
k = int(input())
if k<=9:
    print(k)
    exit(0)

dp = [[1]*10]
counts = [0,9]
digit = 0

while counts[-1] < k:
    digit += 1
    d = [0]*10
    d[0] = dp[-1][0] + dp[-1][1]
    for i in range(1,9):
        d[i] = dp[-1][i-1] + dp[-1][i] + dp[-1][i+1]
    d[9] = dp[-1][8] + dp[-1][9]
    dp.append(d)
    count = counts[-1]
    for i in range(1,10):
        count += d[i]
        if count >= k:
            leading = i
            print(leading, end="")
            count -= d[i]
            k -= count
            break
    counts.append(count)

digit -= 1

while digit>=0:
    d = dp[digit]
    if leading == 0:
        r = range(0,2)
    elif leading == 9:
        r = range(8,10)
    else:
        r = range(leading-1,leading+2)
    count = 0
    for i in r:
        count += d[i]
        if count >= k:
            leading = i
            print(leading, end="")
            count -= d[i]
            k -= count
            digit -= 1
            break
print("")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include <stdlib.h>
using namespace std;
#define          neli                   printf("\n")
#define          gcd(a,b)               __gcd(a,b)

int main()
{

   string str;cin>>str;
   int n=str.size();int i,x,k;
   for(i=0;i<n;i++)
   {
       if(i%2)
       {
           if(str[i]==76||str[i]==85||str[i]==68)
                continue;

           else{

                cout<<"No"<<endl;
               return 0;
           }
       }
       else
       {
           if(str[i]==82||str[i]==85||str[i]==68)
                continue;
           else{
                cout<<"No"<<endl;
               return 0;
           }
       }
   }

   cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    private void solve(Scanner in) {
        int N = in.nextInt(), M = in.nextInt();
        int[] a = new int[N], b = new int[N], c = new int[M], d = new int[M];
        for (int i = 0; i < N; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
        }
        for (int i = 0; i < M; i++) {
            c[i] = in.nextInt();
            d[i] = in.nextInt();
        }
        for (int i = 0; i < N; i++) {
            int ans = 0;
            int min = Integer.MAX_VALUE;
            for (int j = 0; j < M; j++) {
                int dist = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
                if (min > dist) {
                    ans = j;
                    min = dist;
                }
            }
            System.out.println(ans + 1);
        }
    }
}

Measured memory_bytes: 21972
a, b, c, x, y = map(int, input().split())

res = a*x + b*y # 条件を満たす買い方のうちABピザの枚数(*2)を全探索する。ABピザを一切買わない場合を一旦答えにする（これを大きい値にして、for ループを0からにしてもよい）
for i in range(1, max(x, y)+1): # 全部ABピザでまかなう時は x,yの内多い方分買うことになる
    ab = i*2 # ABピザを買う枚数奇数枚買うことはないので2倍
    cand = ab*c + a*max(0, x-i) + b*max(0, y-i) # i枚分はABピザになるので-i 負の値にはならない（あまりになる）ので0とのmaxをとる

    res = min(res, cand) # 候補との最小値を保持

print(res)

Measured memory_bytes: 3060
/*
* @Author: Kabid
* @Date:   2020-04-26 18:01:07
* @Last Modified by:   Kabid
* @Last Modified time: 2020-05-17 18:17:51
*/
#include<bits/stdc++.h>

#define ll long long
#define  in(x) scanf("%d",&x);
#define out(x) printf("%d",x);
#define  ins(x)  scanf("%s",x);
#define outs(x) printf("%s",x);
#define lin puts("");
#define _ putchar(' ');
using namespace std;

int t;       //test cases
ll  n = 0, m,i; //variables
ll a[200002], b[200002], c, k;
string s;
int main() {
	cin >> n ;
	

	cin>>s;

k=s.size();
	if(k<=n){
		cout<<s<<endl;
	}
	else{
		for(i=0;i<n;i++)
			putchar(s[i]);
		puts("...");
	}






	return 0;
}




Measured memory_bytes: 3640
n,m = $stdin.gets.split.map(&:to_i)
arr = gets.chomp.split(' ').map(&:to_i)
tot = arr.inject(&:+);sel = tot.to_f / (4*m)
eranda = 0

arr.each do |k|
	if k >= sel
      eranda +=1 
    end
end

if eranda >= m
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
N = int(input())
a = list(map(int, input().split()))

cond = [0] * (N+1)
ans = [0]* (N+1)


def yakusu(x):
    yakusu = [1]
    for i in range(2, int(x**0.5)+1):
        if x%i == 0:
            yakusu.append(i)
            if i != x//i:
                yakusu.append(x//i)
    
    return yakusu

for i in range(N, 0, -1):
    tmp = cond[i]
    if tmp != a[i-1]:
        ans[i] = 1
        cond[i] = 1 - tmp
        if i > 1:
            for j in yakusu(i):
                cond[j] = 1 - cond[j]

res = 0
reslist = []
for i in range(1, N+1):
    if ans[i] == 1:
        res += 1
        reslist.append(i)

if res == 0:
    print(0)
else:
    print(res)
    print(' '.join(map(str, reslist)))

Measured memory_bytes: 85488