akhauriyash/Code-Regression huggingface dataset:
sx, sy, tx, ty = map(int, input().split())
for i in range(tx - sx):
    print("R", end = "")
for i in range(ty - sy):
    print("U", end = "")
for i in range(tx - sx):
    print("L", end = "")
for i in range(ty - sy):
    print("D", end = "")
print("D", end = "")
for i in range(tx - sx + 1):
    print("R", end = "")
for i in range(ty - sy + 1):
    print("U", end = "")
print("L", end = "")
print("U", end = "")
for i in range(tx - sx + 1):
    print("L", end = "")
for i in range(ty - sy + 1):
    print("D", end = "")
print("R")

Measured memory_bytes: 4468
from collections import deque
N, U, V = map(int, input().split())
U -= 1
V -= 1
tree = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)


def get_rank(v):
    rank = [-1] * N
    next_v = deque([v])
    rank[v] = 0
    while next_v:
        node = next_v.popleft()
        r = rank[node]
        for i in tree[node]:
            if rank[i] != -1:
                continue
            rank[i] = r + 1
            next_v.append(i)
    return rank


takahashi = get_rank(U)
aoki = get_rank(V)
ans = 0
for x, y in zip(takahashi, aoki):
    if x <= y:
        ans = max(ans, y-1)

print(ans)

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

int main(void){
    char n[3];
    scanf("%s",&n);
        if(n[0] == '1'){
        n[0] = '9';
        }else if(n[0] == '9'){
        n[0] = '1';
        }

        if(n[1] == '1'){
        n[1] = '9';
        }else if(n[1] == '9'){
        n[1] = '1';
        }

        if(n[2] == '1'){
        n[2] = '9';
        }else if(n[2] == '9'){
        n[2] = '1';
        }
    

    printf("%s",n);
    return 0;
    


}

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    ll k = 0;
    cin >> k;
    vector<pair<ll, ll>> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i).first >> a.at(i).second;
    }
    sort(a.begin(), a.end());
    ll cnt = 0;
    int now = 0;
    while (true) {
        cnt += a.at(now).second;
        if (cnt >= k) {
            cout << a.at(now).first << endl;
            break;
        }
        now++;
    }
    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	map<int, int> mp;
	rep(i,n){
		int a;
		cin >> a;
		++mp[a];
	}
	vector<int> v;
	for(auto p : mp){
		v.push_back(p.second);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	if(v.size() > k){
		rep(i,v.size()-k) ans += v[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13392
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int main()
{
  lint n, a;
  cin >> n;
  cin >> a;

  if(n%500 <= a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*
	Name: Strawberry Cakes
	Author: jack ∑sun
	Date: 25/11/19 21:57
	Description: Strawberry Cakes
*/
#include<bits/stdc++.h>
using namespace std;
int n,m,k,num,ans[305][305];
char c[305][305];
int cnt[305];
vector<int>v;
void solve(int a,int b)
{
	vector<int>t;
	for(int i=a;i<=b;i++)
		for(int j=1;j<=m;j++)
			if(c[i][j]=='#')
				t.push_back(j);
	sort(t.begin(),t.end());
	for(int i=0;i<t.size();i++)
	{
		int t1=1,t2=m;
		if(i>=1)
			t1=t[i-1]+1;
		if(i<(int)t.size()-1)
			t2=t[i];
		num++;
		for(int j=a;j<=b;j++)
			for(int k=t1;k<=t2;k++)
				ans[j][k]=num;
	}
}
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			cin>>c[i][j];
			if(c[i][j]=='#')
				cnt[i]++;
		}
	for(int i=1;i<=n;i++)
		if(cnt[i]>=1)
			v.push_back(i);
	for(int i=0;i<v.size();i++)
	{
		int v1=1,v2=n;
		if(i>=1)
			v1=v[i-1]+1;
		if(i<(int)v.size()-1)
			v2=v[i];
		solve(v1,v2);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			cout<<ans[i][j]<<' ';
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
const int N=3e5+5,MAX=3e7,MOD=1e9+7;
 
using namespace std;
string a;
int memo[N][2];
int solve(int indx,bool one){
	if(indx>=sz(a))return 0;

	int &ret = memo[indx][one];

	if(~ret)return ret;
	if(one){
		if(a[indx]!=a[indx-1])ret=max(ret,1+solve(indx+1,1));
		else {
			if(indx==sz(a)-1)return -1e9;
		}
		ret = max(ret,1+solve(indx+2,0));
		ret = max(ret,solve(indx+1,0));
	}
	else{
		ret = max(ret,1+solve(indx+1,1));
	}

	return ret;

}
int main()
{

    	
    	cin>>a;

    	memset(memo,-1,sizeof(memo));

    	cout<<solve(0,0)<<endl;
    	
}

Measured memory_bytes: 11908
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a,b = inpm()

if a<=b:
    print(str(a)*b)
else:
    print(str(b)*a)

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

using namespace std;

typedef pair<int, int> pii;

#define F first
#define S second

const int MAXN = 800 + 10;

int n, m, k;
string s[MAXN];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int lv[MAXN][MAXN];
pii q[MAXN*MAXN];

bool fit(int x, int y){return 0 <= x && x < n && 0 <= y && y < m && s[x][y] != '#';}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> k;
	for (int i = 0; i < n; i++)	cin >> s[i];
	pii a;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (s[i][j] == 'S')
				a = {i, j};

	memset(lv, 63, sizeof(lv));
	int h = 0, t = 0;
	q[t++] = a; lv[a.F][a.S] = 0;
	while (t-h){
		auto v = q[h++];
		if (lv[v.F][v.S] > k){
			h--;
			break;
		}
		for (int w = 0; w < 4; w++){
			pii u(v.F+dx[w], v.S+dy[w]);
			if (fit(u.F, u.S) && lv[v.F][v.S] + 1 < lv[u.F][u.S]){
				lv[u.F][u.S] = lv[v.F][v.S] + 1;
				q[t++] = u;
			}
		}
	}

	int ans = 1e9;
	for (int i = 0; i < h; i++){
		auto v = q[i];
		ans = min(ans, 1+(v.F+k-1)/k);
		ans = min(ans, 1+(v.S+k-1)/k);
		ans = min(ans, 1+(n-1-v.F+k-1)/k);
		ans = min(ans, 1+(m-1-v.S+k-1)/k);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
    ll x, y, co = 0;
    cin >> x >> y;
    ll tmp = x;
    while (tmp <= y) {
        co++;
        tmp *= 2;
    }
    cout << co << endl;
}

Measured memory_bytes: 3632
n, d = gets.split.map(&:to_i)
coordinates = n.times.map { gets.split.map(&:to_i) }

answer = coordinates.combination(2).count do |(y, z)|
  distance = Math.sqrt((0...d).reduce(0) { |s, i| s += (y[i] - z[i]) ** 2 })
  distance - distance.to_i == 0
end
puts answer

Measured memory_bytes: 1788
c = []
for i in range(3):
    c.append(list(map(int, input().split())))
if(c[0][0] + c[1][1] + c[2][2] == c[0][1] + c[1][2] + c[2][0] == c[0][2] + c[1][0] + c[2][1]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (1 << 20)

int a[MAXN], b[MAXN], c[MAXN];

int main() {
	int na, nb, m;
	cin >> na >> nb >> m;
	for (int i = 1; i <= na; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= nb; i++) {
		cin >> b[i];
	}
	int ret = MAXN;
	for (int i = 1; i <= m; i++) {
		int x, y, c;
		cin >> x >> y >> c;
		int cur = a[x] + b[y] - c;
		ret = min(ret, cur);
	}
	sort(a + 1, a + na + 1);
	sort(b + 1, b + nb + 1);
	ret = min(ret, a[1] + b[1]);
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 4368
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, k = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))


def dfs(i):
    if 0 <= visited[i]:
        return
    visited[i] = idx
    cycle.append(i)
    global csum
    csum += C[i]
    dfs(P[i])


visited = [-1]*n
idx = 0
cycles = []
for i in range(n):
    if 0 <= visited[i]:
        continue
    cycle = []
    csum = 0
    dfs(i)
    cycles.append((cycle, csum))
    idx += 1


INF = 10**18
ans = -INF
for i in range(n):
    cycle, csum = cycles[visited[i]]
    cmem = len(cycle)

    if 0 < csum:
        a, b = divmod(k, cmem)
        scoreA = csum*(a-1)
        b += cmem
        score = 0
        scoreB = 0
        for _ in range(b):
            i = P[i]
            score += C[i]
            if scoreB < score:
                scoreB = score
        X = scoreA+scoreB
    else:
        b = min(k, cmem)
        score = 0
        INF = 10**18
        X = -INF
        for _ in range(b):
            i = P[i]
            score += C[i]
            if X < score:
                X = score

    if ans < X:
        ans = X
print(ans)


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

int main(){
    int N,K;
    scanf("%d%d",&N,&K);
    int A[101][101];
    int d[101];
    bool bit[101] = {false};
    for(int i=1;i<=K;i++){
        scanf("%d",d+i);
        for(int j=1;j<=d[i];j++){
            scanf("%d",&A[i][j]);
            bit[A[i][j]] = true;
        }
    }
    int ans = 0;
    for(int i=1;i<=N;i++){
        if(!bit[i]) ans++;
    }
    printf("%d",ans);
}


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

int main() {
  int N,A,Ans=0;
  cin>>N;
  
  rep(i,N){cin >> A;
          if(i%2==0&&A%2==1){Ans++;}
          }
  cout<<Ans<<endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

using ll = long long;
template <ll MOD = 1000000007>
struct Mint{
	ll x;

	Mint() : x(0) {}
	Mint(ll t){
		x = t % MOD;
		if(x < 0) x += MOD;
	}
	
	Mint pow(ll n){
		Mint res(1), t(x);
		while(n > 0){
			if(n & 1) res *= t;
			t *= t;
			n >>= 1;
		}
		return res;
	}

	Mint inv() const {
		ll a = x, b = MOD, u = 1, v = 0, t;
		while(b > 0){
			t = a / b;
			a -= t * b;
			swap(a, b);
			u -= t * v;
			swap(u, v);
		}
		return Mint(u);
	}

	Mint & operator += (Mint a){
		x += a.x;
		if(x >= MOD) x -= MOD;
		return *this;
	}
	Mint & operator -= (Mint a){
		x += MOD - a.x;
		if(x >= MOD) x -= MOD;
		return *this;
	}
	Mint & operator *= (Mint a){
		x = 1LL * x * a.x % MOD;
		return *this;
	}
	Mint & operator /= (Mint a){
		return (*this) *= a.inv();
	}

	Mint operator + (Mint a) const { return Mint(x) += a; }
	Mint operator - (Mint a) const { return Mint(x) -= a; }
	Mint operator * (Mint a) const { return Mint(x) *= a; }
	Mint operator / (Mint a) const { return Mint(x) /= a; }

	Mint operator - () const{ return Mint(-x); }

	bool operator == (const Mint a){ return x == a.x; }
	bool operator != (const Mint a){ return x != a.x; }
	bool operator < (const Mint a){ return x < a.x; }

	friend ostream & operator << (ostream & os, const Mint &a){
		return os << a.x;
	}

	friend istream & operator >> (istream & is, Mint &a){
		ll t;
		is >> t;
		a = Mint<MOD>(t);
		return (is);
	}
};

template <typename T>
struct Comb{
	vector<T> fac, fin;

	Comb(int sz) : fac(sz + 1), fin(sz + 1){
		fac[0] = fin[sz] = T(1);
		for(int i = 1; i <= sz; i++){
			fac[i] = fac[i - 1] * T(i);
		}
		fin[sz] /= fac[sz];
		for(int i = sz - 1; i >= 0; i--){
			fin[i] = fin[i + 1] * T(i + 1);
		}
	}

	inline T fact(int k) const { return fac[k]; }
	inline T finv(int k) const { return fin[k]; }

	T P(int n, int k) const {
		if(k < 0 || n < k) return T(0);
		return fac[n] * fin[n - k];
	}

	T C(int n, int k) const {
		if(k < 0 || n < k) return T(0);
		return fac[n] * fin[n - k] * fin[k];
	}

	T H(int n, int k) const {
		if(n < 0 || k < 0) return T(0);
		return k == 0 ? T(1) : C(n + k - 1, k);
	}
};

signed main(){
	int n,k;
	cin >> n >> k;
	Comb<Mint<>> C(2000);
	for(int i = 1; i <= k; i++){
		cout << C.C(n - k + 1, i) * C.C(k - 1, i - 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 1; i < n; i++)
using ll = long long;

int main() {
  int a, b;
  cin >> a >> b;
  ll num = 1;
  ll i = min(a, b);
  while (1) {
    if (i % a == 0 && i % b == 0) {
      num = i;
      break;
    }
    i /= num;
    num++;
    i *= num;
  }
  cout << num;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split(' ')))
B = list(map(int,input().split(' ')))
C = list(map(int,input().split(' ')))

ans = 0
pre_a = -100 
for a in A:
	ans += B[a-1]
	if a == pre_a + 1:
		ans += C[pre_a-1]
	pre_a = a

print(ans)


Measured memory_bytes: 3060
n=int(input())
aa=map(int,input().split())
aa=list(aa)
memo=[]
count=0
for a in aa:
    if a<400:memo.append(1)
    elif a<800:memo.append(2)
    elif a<1200:memo.append(3)
    elif a<1600:memo.append(4)
    elif a<2000:memo.append(5)
    elif a<2400:memo.append(6)
    elif a<2800:memo.append(7)
    elif a<3200:memo.append(8)
    else:count+=1

memo=set(memo)
min=len(memo)
if min==0:min=1
max=len(memo)+count
#if max>8: max=8
print(min,max)

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

int main(){
	int A,B,C,ans=0;
	cin >> A >> B >> C;
	ans=B/A;
	if(ans>=C) cout << C << endl;
	else cout << ans << endl;
}

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

int n;
int M[101010][3]={};
ll dp[101010][3]={};
ll cnt=0;


int main(){
   int a,b;
   cin>>a>>b;
   if(a>9||b>9){
      cout<<-1<<endl;
      return 0;
   }
   cout<<a*b<<endl;
}



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

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

Measured memory_bytes: 256
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        long x = scan.nextLong();
        long b = 100;
        int out = 0;
        while(b < x){
            b += b / 100;
            out++;
        }
        System.out.println(out);
    }

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


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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------

int N;

signed main(){
	cin >> N;
	char s[20];
	int64 c[5] = { 0, 0, 0, 0, 0 };
	REP(i, 0, N) {
		scanf("%s\n", s, 10);

		switch(s[0]) {
			case ('M'):	c[0]++;	break;
			case ('A'):	c[1]++;	break;
			case ('R'):	c[2]++;	break;
			case ('C'):	c[3]++;	break;
			case ('H'):	c[4]++;	break;
		}
//		cout << c[0] << " " << c[1] << " " << c[2] << " " << c[3] << " " << c[4] << endl;

	}
	int64 ans = 0;
	REP(i, 0, 3) {
		if(c[i] == 0)	continue;
		REP(j, i+1, 4) {
			if(c[j] == 0)	continue;
			REP(k, j+1, 5) {
				if(c[k] == 0)	continue;
				ans += c[i] * c[j] * c[k];
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ITP1
{
    class Program
    {
        public static void Main()
        {
            int[] val = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            if (val[0] < val[1] && val[0] < val[2])
                if (val[1] < val[2])
                    Console.WriteLine("{0} {1} {2}",val[0], val[1], val[2]);
                else
                    Console.WriteLine("{0} {2} {1}", val[0], val[1], val[2]);
            else if (val[1] < val[0] && val[1] < val[2])
                if (val[0] < val[2])
                    Console.WriteLine("{1} {0} {2}", val[0], val[1], val[2]);
                else
                    Console.WriteLine("{1} {2} {0}", val[0], val[1], val[2]);
            else
                if (val[0] < val[1])
                    Console.WriteLine("{2} {0} {1}", val[0], val[1], val[2]);
                else
                    Console.WriteLine("{2} {1} {0}", val[0], val[1], val[2]);
        }
    }
}


Measured memory_bytes: 16388
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	int n = in();
	vector<int>a(n);
	REP(i, n)a[i] = in();
	int q = in();
	REP(i, q)
	{
		int b, e, k;
		cin >> b >> e >> k;
		cout << count(a.begin() + b, a.begin() + e, k) << endl;
	}
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

ll powmod(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}
ll modinv(ll n) {
    return powmod(n, P - 2);
}

vector<int> f0, f1;
void init(int n) {
    f0.resize(n + 1);
    f0[0] = 1;
    for (int i = 1; i <= n; i++) {
        f0[i] = (ll)f0[i - 1] * i % P;
    }
    f1.resize(n + 1);
    f1[n] = modinv(f0[n]);
    for (int i = n; i > 0; i--) {
        f1[i - 1] = (ll)f1[i] * i % P;
    }
}
ll fact(int k) {
    return f0[k];
}
ll comb(int n, int k) {
    if (n < k || k < 0) return 0;
    return (ll)f0[n] * f1[k] % P * f1[n - k] % P;
}
ll perm(int n, int k) {
    if (n < k || k < 0) return 0;
    return (ll)f0[n] * f1[n - k] % P;
}

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

    init(n + m);

    ll r = 0, s = 1;
    for (int i = 0; i <= n; i++) {
        ll t = perm(m - i, n - i);
        r += comb(n, i) * perm(m, i) % P * t % P * t % P * s;
        s *= -1;
    }

    r %= P;
    r += P;
    r %= P;
    cout << r << endl;

    //A_iは相異なる
    //B_iは相異なる
    //ただの順列かあ しかし1つめの条件が厄介で
    //1個だけ一致するとき1小さい問題に帰着できる？しかしN^2かかりそう

    return 0;
}

Measured memory_bytes: 11020
dd = ((1, 0), (0, -1), (-1, 0), (0, 1))
ENWS = "ENWS"
ds = [-1, 0, 1, 2]
ss = [2, 3, 0, 1]

while 1:
    W, H = map(int, input().split())
    if W == H == 0:
        break
    S = [input() for i in range(H)]

    ps = []; U = [[-1]*W for i in range(H)]
    for i in range(H):
        for j, c in enumerate(S[i]):
            if c in ENWS:
                ps.append([i, j, ENWS.index(c)])
                U[i][j] = 1
            elif c == '#':
                U[i][j] = W*H
    rest = len(ps)
    t = 0
    while rest > 0 and t <= 180:
        for p in ps:
            y, x, c = p
            if c == -1:
                continue
            for d in ds:
                dx, dy = dd[(c+d) % 4]
                nx = x + dx; ny = y + dy
                if U[ny][nx] == -1:
                    p[2] = (c+d) % 4
                    break
        ps.sort(key = lambda x: ss[x[2]])
        qs = []
        for p in ps:
            y, x, c = p
            if c == -1:
                continue
            dx, dy = dd[c]
            nx = x + dx; ny = y + dy
            if U[ny][nx] == -1:
                U[ny][nx] = 1
                if S[ny][nx] == 'X':
                    rest -= 1
                    p[2] = -1
                    qs.append((ny, nx))
                else:
                    p[0] = ny; p[1] = nx
                qs.append((y, x))
        for y, x in qs:
            U[y][x] = -1
        t += 1
    if t <= 180:
        print(t)
    else:
        print("NA")



Measured memory_bytes: 5656
# 最大公約数
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a

# 最小公倍数
def lcm(a, b):
    return a * b / gcd(a, b)

# 1行目の入力を空白で分割された文字列として扱う
A, B = map(int, input().split())

# 答えの準備
res = int(lcm(A, B))

# 答えの出力
print(res)


Measured memory_bytes: 2940
fn main() {
    let (s, w) = input();
    println!("{}", solve(s, w))
}

fn input() -> (u32, u32) {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.pop();
    let mut iter = buf.split_whitespace();
    let s: u32 = iter.next().unwrap().parse().unwrap();
    let w: u32 = iter.next().unwrap().parse().unwrap();
    (s, w)
}

fn solve(s: u32, w: u32) -> String {
    if s <= w { return String::from("unsafe"); }
    String::from("safe")
}


Measured memory_bytes: 2104
a, b, c, x, y = map(int, input().split())
min_price = 10 ** 9
for i in range(10 ** 5 + 1):
  price = i * 2 * c + max(0, x - i) * a + max(0, y - i) * b
  if price < min_price:
    min_price = price
print(min_price)

Measured memory_bytes: 3064
const [_, input] = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");

const MAX = 10 ** 18;
const inputs = input.split(" ").map((s) => parseInt(s, 10));

if (inputs.includes(0)) {
  console.log(0);
  process.exit(0);
}

let curr = 1n;
inputs.forEach((n) => {
  curr = curr * BigInt(n);
  if (curr > MAX) {
    console.log(-1);
    process.exit(0);
  }
});
console.log(curr.toString());


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

using namespace std;
#define ll long long

const int N = 1e5 + 5;
ll INF = 998244353;


int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    unordered_map<ll,ll>hmap;

    vector<ll> pat;
    pat.push_back(x);
    hmap[x] = 0;

    ll prev = x;
    ll count = x;
    ll next;

    bool flag = false;
    int start, end;
    for(int i=1; i<n;i++)
    {
        next = (prev * prev) %m;
        if(hmap.find(next) != hmap.end())
        {
            flag = true;
            start = hmap[next];
            end = i-1;
            break;
        }
        //cout<<next<<" ";
        hmap[next] = i;
        pat.push_back(next);
        count += next;
        prev = next;
    }
    //cout<<endl;
    
    if(!flag)
    {
        cout <<count<<endl;
    }
    else
    {
        ll cycleSum = 0;
        for(int i = start; i<=end;i++)
        {
            cycleSum += pat[i];
        }

        ll rev = ( n - (end + 1))/ ( end - start + 1);
        count += cycleSum*rev;

        ll m = ( n - (end + 1))% ( end - start + 1);
        for(int i = 0; i<m;i++)
        {
            count += pat[start + i];
        }

        cout<<count<<endl;
    }
}


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

int main(){
  int n;
  cin>>n;
  n%=10;
  if(n==3){
    cout<<"bon";
  }else if(n==0||n==1||n==6||n==8){
    cout<<"pon";
  }else{
    cout<<"hon";
  }
}

Measured memory_bytes: 3632
import java.util.*;
import static java.lang.Math.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;
        if(a>=13){
            ans = b;
        }else if(a>=6){
            ans = b/2;
        }else{
            
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c && c <= b)
		Yes();
	else
		No();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  } 
  int ans = 0;
  rep(i,N) {
    if(A[A[i]-1] == i+1) {
      ans++;
    }
  }
  cout << ans / 2 << endl;
  return 0;
}

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

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, m;
int q[N];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++ )
	{
		int x;
		scanf("%d", &x);
		
		int l = 1, r = m;
		while (l < r)
		{
			int mid = l + r >> 1;
			if (q[mid] < x) r = mid;
			else l = mid + 1;
		}
		
		if (!m || q[r] >= x) q[ ++ m] = x;
		else q[r] = x;
	}
	
	printf("%d\n", m);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
ll R[200010];

int main() {
	cin >> n;
	ll ans = -INF;
	ll num = INF;
	rep(i, n) {
		cin >> R[i];
		if (i >= 1)ans = max(R[i] - num, ans);
		num = min(num, R[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4652
#include <cstdio>
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <string>

using namespace std;
using ll = long long;

ll N, K;
struct Sushi {
    ll t, d;
};
vector<Sushi> sushis;

void input() {
    cin >> N >> K;
    sushis.resize(N);
    for (auto& s : sushis)
        cin >> s.t >> s.d;
}

void solve() {
    sort(sushis.begin(), sushis.end(), [](auto l, auto r) {
        return l.d < r.d;
    });
    ll der = 0;
    set<ll> types;
    priority_queue<ll, vector<ll>, greater<ll>> flows;
    for (ll i = N-1; i >= N-K; i--) {
        der += sushis[i].d;
        if (types.find(sushis[i].t) != types.end())
            flows.push(sushis[i].d);
        else
            types.insert(sushis[i].t);
    }
    ll ans = der + pow(types.size(), 2);
    for (ll i = N-K-1; i >= 0; i--) {
        if (flows.size() == 0) break;
        auto &sushi = sushis[i];
        if (types.find(sushi.t) != types.end()) continue;
        types.insert(sushi.t);
        der += sushi.d;
        der -= flows.top();
        flows.pop();
        ans = max(ans, der + ll(pow(types.size(), 2)));
    }
    cout << ans << endl;
}

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



Measured memory_bytes: 5244
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")

#include <cstdio>
#include <vector>
#include <bitset>

using namespace std;

using int64 = long long;

template<class T> inline void fastin(T &num) {
  T c;
  num = 0;
  c = getchar_unlocked();
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
}

int dp[40];

int main() {
  int n; int64 k; fastin(n); fastin(k);
  vector<int64> a(n);
  for (int i = 0; i < n; ++i) fastin(a[i]);

  for (int i = 0; i < n; ++i) {
    bitset<40> bit(a[i]);
    for (int j = 0; j < 40; ++j) {
      dp[j] += bit.test(j);
    }
  }

  int64 ans = 0;
  int64 tmp = 0;
  for (int i = 0; i < n; ++i) {
    tmp += (a[i] ^ k);
  }

  ans = tmp;

  for (int i = 39; i >= 0; --i) {
    bitset<40> kbit(k);
    if (kbit.test(i)) {
      kbit.reset(i);
      for (int j = i - 1; j >= 0; --j) {
        if (dp[j] > n - dp[j]) {
          kbit[j] = 0;
        } else {
          kbit[j] = 1;
        }
      }
      int64 best = kbit.to_ullong();
      int64 t = 0;
      for (int j = 0; j < n; ++j) {
        t += (best ^ a[j]);
      }
      ans = max(ans, t);
    }
  }

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 1024
N, M = gets.strip.split.map(&:to_i)

def fact(n)
  n.times.map { |i| i + 1 }.inject(:*)
end

def combi(n)
  if n > 2
    fact(n) / (fact(n - 2) * fact(2))
  elsif n.eql?(2)
    1
  else
    0
  end
end

puts combi(N) + combi(M)


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

int main (){
 long long int n,d;
  cin >> n >> d;

  long long int x[n],y[n];
  long long int xv,yv;
  long long int dv=d*d;
  long long int c=0;
  long long int ans;
  for(long long int i=0; i<n; i++){
     cin >> x[i] >> y[i];
       xv = x[i] * x[i];
       yv = y[i] * y[i];
       ans = xv + yv;
    if(dv>=ans){
      c++;
  }
  }
  cout << c << endl;
}



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

using namespace std;

typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin >> n;
    ll a[n];
    ll fre[n+1]={0};
    for(int i=0 ;i<n ;i++)
    {
        cin >> a[i];
        fre[a[i]]++;
    }
    ll ans=0;
    for(int i=1 ; i<=n ;i++)
    {
        if(fre[i]>0)
        {
            ans += (fre[i]*(fre[i]-1))/2;
        }
    }
    for(int i=0 ; i<n ; i++)
    {
        ll temp = fre[a[i]];
        ll ka = (temp*(temp-1))/2;
        temp--;
        ll kh = (temp*(temp-1))/2;

        cout << ans-ka+kh << "\n" ;
    }


    return 0;
}


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

typedef long long i64;
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);(i)++)
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);(i)--)
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

int main(){
    string s,t;
    cin>>s>>t;
    string ans = "No";

    FOR(i,0,t.size()){
        char m = t[0];
        FOR(j,0,t.size()-1){
            t[j] = t[j+1];
        }
        t[t.size()-1] = m;
        if(s == t){
            ans = "Yes";
        }
    }

    put(ans);
}

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

using namespace std;

int main(){
	
	int i, n, l, acum = 0;
	scanf("%d%d", &n, &l);
	if (l >= 0){
		//come menor indice
		for (i = 2; i <= n; ++i){
			acum += l + i - 1;
			//printf("%d\n", acum);
		}
	}else{
		int pos = ((-1 * l) + 1);
		if (pos <= n){
			//come pos
			for (i = 1; i <= n; ++i){
				if (i != pos){
					acum += l + i - 1;
				}
			}
		}else{
			//come maior possivel
			for (i = 1; i < n; ++i){
				acum += l + i - 1;
			}
		}
	}
	printf("%d\n", acum);
	return 0;
}
//l + i -1
//n e l positivos = comer maça com menor indice
//n pos e l neg = menor abs(l + i - 1)
//se l = -1, pos 2
//se l = -2, pos 3
//pos = l * (-1) + 1//se tiver, se não, o maior possível

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

l=0
r = 10**9
for g in gates:
    l = max(l, g[0])
    r = min(r, g[1])
print(r-l+1 if r>=l else 0)

Measured memory_bytes: 60120
# ABC162F - Select Half

import sys
input = sys.stdin.buffer.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    
    if n<4:
        print(max(a))
        sys.exit()

    if n%2:
        #dp[位置][個数]
        dp=[[0,0,0]for i in range(n-2)]
        dp[0]=a[:3]
        for i in range(2,n-1,2):
            dp[i][0]=dp[i-2][0]+a[i]
            dp[i][1]=max(dp[i-2][0],dp[i-2][1])+a[i+1]
            dp[i][2]=max(dp[i-2][0],dp[i-2][1],dp[i-2][2])+a[i+2]
        print(max(dp[-1]))

    else:
        #dp[位置][個数]
        dp=[[0,0]for i in range(n-1)]
        dp[0]=a[:2]
        for i in range(2,n-1,2):
            dp[i][0]=dp[i-2][0]+a[i]
            dp[i][1]=max(dp[i-2][0],dp[i-2][1])+a[i+1]
        print(max(dp[-1]))

main()

Measured memory_bytes: 53240
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    println!("{}", a * b);
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a+b+c >= 22)cout << "bust";
    else cout << "win";
}

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

int main(){
	int a[5];
	
	for(int i = 0; i < 5; i++){
		scanf("%d", &a[i]);
		if(a[i] < 40) a[i] = 40;
	}
	
	printf("%d\n", (a[0] + a[1] + a[2] + a[3] + a[4]) / 5);
	
	return 0;
}

Measured memory_bytes: 1028
#include<stdio.h>
int main(){
    int h1,m1,h2,m2,k;
    scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);
    int tm=0;
    if(m2<m1){
        tm=(h2-h1-1)*60+m2+60-m1;
    }else{
        tm=(h2-h1)*60+m2-m1;
    }
    printf("%d\n",tm-k);
    return 0;
}

Measured memory_bytes: 1732
N, C = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

LEN = 10 ** 5 + 7
d = [[0] * LEN for _ in range(C + 1)]
for s, t, c in X:
    d[c][s] += 1
    d[c][t + 1] -= 1

for i in range(C + 1):
    for j in range(LEN - 1):
        d[i][j + 1] += d[i][j]

x = [0] * LEN
for i in range(C + 1):
    for j in range(LEN):
        x[j] += int(d[i][j] > 0)
        
print(max(x))


Measured memory_bytes: 86232
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    a, b, c = LI()
    if a + b + c >21:
        print("bust")
    else:
        print("win")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    int a[n];
    double ave = 0,Min = 100000.0;
    int ans;
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
        ave += a[i];
    }
    ave /= n;
    for(int i = 0;i < n;i++)
    {
        if(fabs(ave - a[i]) < Min)
        {
            Min = fabs(ave - a[i]);
            ans = i;
        }
    }
    cout << ans << "\n";

    return 0;
}

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

using namespace std;

int main() {
  int w, h, n;
  scanf("%d %d %d", &w, &h, &n);
  int hx = w, hy = h, lx = 0, ly = 0;
  for (int i = 0; i < n; i++) {
    int x, y, a;
    scanf("%d %d %d", &x, &y, &a);
    switch (a) {
    case 1:
      lx = max(x, lx);
      break;
    case 2:
      hx = min(x, hx);
      break;                                                             
    case 3:
      ly = max(y, ly);
      break;
    case 4:     
      hy = min(y, hy);                                                      
    }
  }
  printf("%d\n", max(0, (hx - lx)) * max(0, (hy - ly)));
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<ll> a(n);
	ll s = 0;
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
		s += a[i];
	}

	ll res = inf;
	ll x;
	for (ll i = 0; i <= 100; i++)
	{
		x = 0;
		for (ll j = 0; j < n; j++)
		{
			x += (a[j] - i) * (a[j] - i);
		}

		res = min(res, x);
	}

	println(res);
}

Measured memory_bytes: 256
//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (100010)
int n,m,s,a[N];
signed main(){
	Rd(n),Rd(m);
	Frn1(i,1,n)s+=Rd(a[i]);
	sort(a+1,a+n+1,[](int a,int b){return a>b;});
	printf(a[m]>=ceil(s/(4.0*m))?"Yes":"No"),exit(0);
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


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

    string s;
    cin >> s;
    char pr = 'a';
    F0R(i,4){
      if(pr == s[i]) {
        cout << "Bad"<<endl;
        return 0;
      }
      pr = s[i];
    }

    cout << "Good"<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
def SelectionSort(A):
    swapCount=0
    # sort
    for i in range(len(A)):
        mini=i
        for j in range(i,len(A)):
            if A[j]<A[mini]:
                mini=j
        if mini!=i:
            tmp=A[i]
            A[i]=A[mini]
            A[mini]=tmp
            swapCount+=1
    return swapCount
    

# input
n=int(input())
nums=list(map(int, input().split()))
count=SelectionSort(nums)
maplist=map(str, nums)
print(' '.join(maplist))
print(count)


Measured memory_bytes: 5600
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)

mod3 :: Int -> Bool
mod3 = ((==) 0) . (flip mod 3)

toYesNo :: Bool -> String
toYesNo True = "Possible"
toYesNo _ = "Impossible"

solve :: Int -> Int -> Bool
solve a b
    | ma || mb || mc = True
    | otherwise = False
    where
        ma = mod3 a
        mb = mod3 b
        mc = mod3 (a + b)

main :: IO ()
main = do
    [a, b] <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine :: IO [Int]
    putStrLn $ toYesNo $ solve a b


Measured memory_bytes: 380
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll q;
	while ((q = in()) != -1) {
		double x = q / 2.0;
		while (abs(x * x * x - q) >= 0.00001 * q) {
			x -= (x * x * x - q) / (3 * x * x);
		}
		SETP(10);
		cout << x << endl;
	}
}


Measured memory_bytes: 3228
#include <iostream>
#include <stdio.h>
using namespace std;

#define MAX 100
#define INF 2097152
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];


int main(void){

	int i,j;
	int minv,d[MAX],color[MAX];
	int u,v;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			M[i][j] = INF;
		}
	}

	int k,l,m,p;
	for(i=0;i<n;i++){
		scanf("%d %d",&m,&k);
		for(j=0;j<k;j++){
			scanf("%d %d",&p,&l);
			M[m][p] = l;
		}
	}

	for(i=0;i<n;i++){
		d[i] = INF;
		color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;

	while(1){
		minv = INF;
		u = -1;
		for(i=0;i<n;i++){
			if(minv > d[i] && color[i] != BLACK){
				u = i;
				minv = d[i];
			}
		}
		if(u == -1) break;
		color[u] = BLACK;
		for(v=0;v<n;v++){
			if(d[v]>d[u] + M[u][v]){
				d[v] = d[u] + M[u][v];
				color[v] = GRAY;
			}
		}
	}

	for(i=0;i<n;i++){
		if(d[i] == INF){
			printf("%d -1\n",i);
		}else{
			printf("%d %d\n",i,d[i]);
		}
	}

return 0;

}










Measured memory_bytes: 3248
import sys
import math
input = sys.stdin.readline

mod = 10**9+7


def main():
    N = int(input())
    r1 = [1]
    for i in range(N-1):
        r1.append(r1[i] * (i+1) % mod)
    r2 = [1]
    for i in range(N-1):
        r2.append(r2[i] * (N-1-i) % mod)

    X = list(map(int, input().split()))
    D = [0 for i in range(N)]
    for i in range(N-1):
        D[i] = X[i+1] - X[i]

    ans = 0
    r = 0
    for i in range(N):
        r += r1[i] * r2[N-i-2]
        ans += D[i] * r
        ans %= mod
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 22552
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
int n;
string s;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>s;
    s=s.c_str();
    int le[n];//ここまでのEの数
    le[0]=0;
    int ri[n];//ここまでのWの数
    ri[n-1]=0;
    for(int i=1;i<n;i++){
        if(s[i-1]=='W')
        le[i]=le[i-1]+1;
        else 
        le[i]=le[i-1];
    }
    for(int i=n-2;i>-1;i--){
        if(s[i+1]=='E')
        ri[i]=ri[i+1]+1;
        else
        ri[i]=ri[i+1];
    }
    int ans=INF;
    for(int i=0;i<n;i++){
        ans=min(ans,ri[i]+le[i]);
    }
    cout << ans<< "\n";
}

Measured memory_bytes: 2964
#include <stdio.h>

void overlap_check(int ary[200],int parson_num){
   bool is_overlap;
   for(int i = 0; i < parson_num; i++){
   is_overlap = false;
     for(int j = i + 1; j < parson_num; j++){
      if(ary[i] == ary[j]){
        is_overlap = true; 
        ary[j] = 0; 
      }   
    }
    if(is_overlap) ary[i] = 0;
  }
}

int main(){
  int i1[200];
  int i2[200];
  int i3[200]; 
  int parson_num;
  scanf("%d",&parson_num);
  for(int i = 0; i < parson_num; i++)
    scanf("%d%d%d",&i1[i],&i2[i],&i3[i]);

  overlap_check(i1,parson_num);
  overlap_check(i2,parson_num);
  overlap_check(i3,parson_num);
  
  for(int i = 0; i < parson_num; i++)
    printf("%d\n",i1[i] + i2[i] + i3[i]);
 
}      

Measured memory_bytes: 2696