akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    ll n;
    cin>>n;
    ll a=sqrt(n);
    while(true){
        if(n%a==0){
            a=n/a;
            n/=a;
            break;
        }else{
            a--;
        }
    }
    cout<<a+n-2<<endl;
}

Measured memory_bytes: 256
N = int(input())
S = input()

# R/G/Bそれぞれの個数
r = S.count('R')
g = S.count('G')
b = S.count('B')

# R,G,Bとなる選び方の総数。順番はRGBとは限らない
ans = r * g * b

# j-i != k-j は扱いにくい
# j-i == k-j　の数を求めて引く（余事象）
# この時、k == 2*j - i、すなわちi,jが決まればkは一意に定まる

# i = 0,1,2,...,N-3
# j = i+1,i+2,...,N-2
# k = 2*j-1

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = 2 * j - i
        # kが範囲内、かつ、条件1を満たしている場合
        if k <= N - 1 and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1

print(ans)


Measured memory_bytes: 9140
N, K = map(int, input().split())
mod = 10 ** 9 + 7

def modinv(x):
    return pow(x, mod - 2, mod)

modinv_table = [-1 for _ in range(N + 1)]

for i in range(1, N + 1):
    modinv_table[i] = modinv(i)

def cmb(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans
    
for i in range(1, K + 1): 
    ans = 0
    tmp = cmb(K - 1, i - 1)
    if N - K < i - 1:
        print(ans)
        continue
    else:
        tmp_N = N - K - (i - 1)
        if tmp_N > 0:
            ans += cmb(tmp_N + i, i) * tmp
        else:
            ans += tmp
    print(ans % mod)  

Measured memory_bytes: 3444
#include<stdio.h>

int main()
{
    int h,w;
    while(1){
    scanf("%d %d",&h,&w);
    if(h==0 && w==0)
        break;
    for(int i=0;i<h;i++){
        for(int l=0;l<w;l++){
            if(i==0){
              printf("#");
            }else if(i==h-1){
               printf("#"); 
            }else if(l==0 || l==w-1){
               printf("#");
            }else{
                printf(".");
            }
        }
        printf("\n");
    }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2624
#include <bits/stdc++.h>
using namespace std;
#include <unordered_map>
#define inputarr(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define prllarr(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" ";
#define pb push_back
#define ll long long
#define mod 1000000007
#define foi ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define in(n) scanf("%lld",&n);
#define in2(x,y) scanf("%lld %lld",&(x),&(y));
#define in3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z));
#define out(n) printf("%lld\n",n);
#define out2(x,y) printf("%lld %lld\n",x,y);
#define test(t)  ll t; in(t);while(t--)
#define set(arr,n,s) for(ll i=0;i<n;i++){arr[i]=s;}


/*error-----
convert every int to long long eg-1LL
create array with proper analysis of problem constrain
check mod also
*/
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1){res=(res*x)%p;} y=y>>1;x=(x*x)%p;}return res;}
ll modInverse(ll a,ll p){return power(a,p-2,p);}//used with feemat little

ll gcd(ll x,ll y){if(x==0 || y==0){return max(y,x);}return gcd(y%x,x);}
ll gcdExtended(ll a,ll b,ll &x,ll &y){if(a==0){x=0;y=1;return b;}ll x1,y1;ll gcd = gcdExtended(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return gcd;}//o(log(b))
ll arr[1003][1003];
ll dp[1003][1003];
int main()
{
	ll h,w;
	cin>>h>>w;
	for(ll i=0;i<h;i++)
	{
		for(ll j=0;j<w;j++)
		{
			char s;
			cin>>s;
			if(s=='.')
			{
				arr[i][j]=1;
			}
			else
			{
				arr[i][j]=0;
			}
		}
	}
	dp[0][0]=1;
	for(ll i=0;i<h;i++)
	{
		for(ll j=0;j<w;j++)
		{
			if(i==h-1 && j==w-1)
			{
				break;
			}
			if(arr[i][j+1]!=0)
			{
				dp[i][j+1]+=dp[i][j];
				dp[i][j+1]%=mod;;
			}
			if(arr[i+1][j]!=0)
			{
				dp[i+1][j]+=dp[i][j];
				dp[i+1][j]%=mod;;
			}

		}
	}
	out(dp[h-1][w-1]);





}

	



	

Measured memory_bytes: 15872
'use strict'


function Main(input) {
  input = input.trim().split('\n')
  const array = input[0].split(' ').map(s => parseInt(s))

  const N = array[0]
  const K = array[1]
  const H = input[1].split(' ').map(s => parseInt(s))


  let a = H.sort((a, b) => b - a)
  a = a.slice(K)

  if(a.length < 1) {
    console.log(0)
    return
  }
  
  const res = a.reduce((p, c) => p + c)
  console.log(res)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for(int i = 0; i < M; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  
  if(N >= M) cout << 0 << endl;
  else{
    vector<int> B(M - 1);
    for(int i = 0; i < M - 1; i++) B.at(i) = A.at(i + 1) - A.at(i);
    sort(B.begin(), B.end());
    int x = M - 1 - (N - 1);//足さないといけない数
    int ans = 0;
    for(int i = 0; i < x; i++) ans += B.at(i);
    cout << ans << endl;
  }
}

Measured memory_bytes: 3912
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		double ab = (double)a / b;
		
		System.out.println(String.format("%d %d %.6f", a/b, a%b, ab));
		sc.close();
	}
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long n, std::vector<long long> X, std::vector<long long> L){
    VPii robo(n);
    REP(i,0,n){
        robo[i].second=X[i]-L[i];
        robo[i].first=X[i]+L[i];
    }
    sort(ALL(robo));

    int now=-INF,ans=0;
    REP(i,0,n){
        if(now<=robo[i].second){
            ans++;
            now=robo[i].first;
        }
    }
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> X(N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(X), std::move(L));
    return 0;
}


Measured memory_bytes: 3328
#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 sz(x) (int)(x).size()
#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 newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
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;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

int N;
vp d;
  
int main() {
  cin >> N;
  d = vp(N);
  rep(i,N) {
    int x,y;
    cin >> x >> y;
    d[i] = P(x,y);
  }
  vi tar;
  rep(i,N) {
    tar.push_back(i);
  }
  double ans = 0;
  int cnt = 0;
  do {
    double cost = 0;
    rep(i,N-1) {
      int xd = d[tar[i]].first - d[tar[i+1]].first;
      int yd = d[tar[i]].second - d[tar[i+1]].second;
      cost += sqrt(xd*xd+yd*yd);
    }
    ans += cost;
    cnt++;
  } while(next_permutation(rng(tar)));
  cout << setprecision(16) << ans / (double)cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import Data.List (sort)
import Control.Monad
import Control.Applicative
main = do
     n <- readLn
     replicateM n solve
solve = do
      a:b:c:_ <- sort . map read . words <$> getLine
      putStrLn $ if c*c == a * a + b * b
                 then "YES"
                 else "NO"

Measured memory_bytes: 4180
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);
const bool DEBUG = 0;

int N;
string str[2];

int main()
{
	int i, j;

	si(N);
	cin >> str[0] >> str[1];
	int ans = 2 * N;
	fl(i,0,N)
	{
		string s = str[0].substr(i);
		string t = str[1].substr(0,(int)s.SZ());
		// cout << s << " " << t << "\n";
		if(s == t)
		{
			int left = N - s.SZ();
			ans = left * 2 + s.SZ();
			break;
		}
	}

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


	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
from bisect import*
a,b,q=map(int,input().split())
a1=[int(input())for i in range(a)]
b1=[int(input())for i in range(b)]
q=[int(input())for i in range(q)]
 
a1=[-20**10]+a1+[20**10]
b1=[-20**10]+b1+[20**10]
 
for i in q:
    x=bisect_left(a1,i)
    y=bisect_left(b1,i)
    low =i-min(a1[x-1],b1[y-1])
    high=max(a1[x],b1[y])-i
    turn1=min(a1[x]-i,i-b1[y-1])+abs(a1[x]-b1[y-1])
    turn2=min(b1[y]-i,i-a1[x-1])+abs(b1[y]-a1[x-1])
    print(min(low,high,turn1,turn2))

Measured memory_bytes: 16768
<?php
$n = trim(fgets(STDIN));
$ans = 0;
if($n % 11 != 0){
$r = $n % 11;
$n -= $r;
if($r > 6){
++$ans;
}
++$ans;
}

if($n > 0){
$ans += $n / 11 * 2;
}
echo $ans;
?>

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

using namespace std;


int h[100010],dp[100010],n;

int call(int i)
{
	if(i == n-1)return 0;
	if(dp[i] != -1)return dp[i];

	int ret = 1 << 30;

	if(i+1 <= n-1)ret = min(ret,call(i+1) + abs(h[i] - h[i+1]));
	if(i+2 <= n-1)ret = min(ret,call(i+2) + abs(h[i] - h[i+2]));

	return dp[i] = ret;
}

int main()
{
	cin >> n;

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

		cin >>  h[i];
	}
	for(int i = 0;i <= 100000;i++)dp[i]=-1;

	cout << call(0) << endl;

	return 0;
}

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

int main(void) {
	string N;
	cin >> N;
	printf((N[0] == N[1] && N[0] == N[2]) || (N[1] == N[2] && N[1] == N[3]) ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));//p^num
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << n << ": ";
    auto res = prime_factorize(n);
    REP(i, res.size()){
        REP(j, res[i].second){
            cout << res[i].first;
            if(i != (int)res.size() - 1 || j != (int)res[i].second - 1) cout << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 3188
n = int(input())
lis = [list(map(int,input().split())) for i in range(n)]
for i in range(n):lis[i].append(lis[i][1]+lis[i][0])

takahashi = 0
aoki = 0

lis.sort(key = lambda x:x[2],reverse=True)

for i in range(n):
    if i % 2 == 0:
        takahashi += lis[i][0]
    else:
        aoki += lis[i][1]
print(takahashi-aoki)

Measured memory_bytes: 32224
n=int(input())
R=[list(map(int,input().split())) for i in range(n)]
B=sorted([list(map(int,input().split())) for i in range(n)])
a=0
for i in range(n):
  y=-1
  c=-1
  for j in range(n-a):
    if R[j][0]<B[i][0] and R[j][1]<B[i][1]:
      if R[j][1]>y:
        y=R[j][1]
        c=j
  if c==-1:
    continue
  else:
    R.pop(c)
    a=a+1
print(a)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{
	int ct=0,temp,i,j,check=0;
	int nct=0;
	int a[101] = {0};
	int N[101] = {0};
	
	while(scanf("%d",&temp)!=EOF)
	{
		if(ct==0)
		{
			a[0] = temp;
			N[0]=1;
			nct++;
		}
		else
		{
			for(i=0;i<ct;i++)
			{
				if(a[i]==temp)
				{
					N[i]++;
					check = 1;
					break;
				}
			}
			if(check==0)
			{
				a[nct] = temp;
				N[nct]++;
				nct++;
			}
		}
		ct++;
		check = 0;
	}
	for(i=0;i<nct;i++)
	{
		for(j=i+1;j<nct;j++)
		{
			if(a[i]>a[j])
			{
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
				//
				temp = N[i];
				N[i] = N[j];
				N[j] = temp;
			}
		}
	}
	temp = 0;
	for(i=0;i<nct;i++)
	{
		if(temp<N[i])
		temp = N[i];
	}
	for(i=0;i<nct;i++)
	{
		if(N[i]==temp)
		printf("%d\n",a[i]);
	}
	return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"
#define int ll

int D;
const int N=26;
vector<vector<int>>s;
vector<int>c;

ll score(vector<int>&t){
  ll score=0;
  ll ans=0;
  vector<int>last(N,-1);
  for(int i=0;i<D;i++){
    ans+=s[i][t[i]];
    last[t[i]]=i;
    for(int j=0;j<N;j++){
      if(last[j]==-1)ans-=c[j]*(i+1);
      else ans-=c[j]*(i-last[j]);
    }
    score+=max(ans+1000000,0ll);
  }
  return score;
}

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

  auto start = std::chrono::system_clock::now();  
  cin>>D;
  c.resize(N);
  for(int i=0;i<N;i++)cin>>c[i];
  s.resize(D,vector<int>(N));
  for(int i=0;i<D;i++)for(int j=0;j<N;j++)cin>>s[i][j];

  vector<int>t(D,0);
  ll S=score(t);
  while(true){
    for(int x=0;x<100;x++){
      vector<int>s(D);
      for(int j=0;j<D;j++)s[j]=t[j];
      random_device rnd;
      mt19937 mt(rnd());
      uniform_int_distribution<>randD(0,D-1);
      uniform_int_distribution<>randN(0,N-1);
      int d=randD(mt);
      int n=randN(mt);
      s[d]=n;
      ll SS=score(s);
      if(S<SS){
        S=SS;
        t[d]=n;
      }
    }
    auto end = std::chrono::system_clock::now();
    auto dur = end-start;
    auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
    if(1980<msec)break;
  }

  for(auto it:t)cout<<it+1<<endl;
  return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,K; cin>>N>>K;
    vector<ld> A(N);
    rep(i,N) cin>>A[i];
    rep(i,N) A[i]=(A[i]+1)/2;
    vector<ld> B=A;
    rep(i,N-1) A[i+1]+=A[i];
    ld sum=0;
    ld ans=0;
    reps(i,K-1,N){
        if(i>=K){
            sum+=B[i-K];
        }
        maxi(ans,A[i]-sum);
    }
    cout<< ans <<"\n";
    

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 6528
INF = 10 ** 9 + 7
H, W = map(int, input().split())
a = [input() for _ in range(H)]
dp = [[0 for _ in range(W)] for _ in range(H)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        if i + 1 < H and a[i + 1][j] == '.':
            dp[i + 1][j] = dp[i][j] + dp[i + 1][j]
            dp[i + 1][j] %= INF
        if j + 1 < W and a[i][j + 1] == '.':
            dp[i][j + 1] = dp[i][j + 1] + dp[i][j]
            dp[i][j + 1] %= INF

print(dp[H - 1][W - 1])

Measured memory_bytes: 83776
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-09 16:13:48
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    sort(all(s));

    if (s == "abc") cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
/*
 * じょえチャンネル
 * 高評価・チャンネル登録よろしくお願いします！
 * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
 */

#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N, K;
    cin >> N >> K;
    unsigned long ans{0}, c{1};
    while(c <= N){
        ++ans;
        c *= K;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import copy
def BubbleSort(d,N):
    for i in range(0,N):
        for j in range(i+1,N)[::-1]:#
            if d[j][1] < d[j-1][1]:
                t=d[j]
                d[j]=d[j-1]
                d[j-1]=t 
    return d

def selectionSort(d,N):
    c1 = 0
    for i in range(0,N):
        minj = i    #カーソル
        for j in range(i,N):
            if d[j][1] < d[minj][1]:
                minj = j
        if(i!=minj):
            t = d[i]
            d[i] = d[minj]
            d[minj] = t
            c1+=1     
    return d           

if __name__=="__main__":
    n = int(input())
    l = [i for i in input().split()]
    l2=copy.deepcopy(l)
    print(' '.join(BubbleSort(l,n)))#pythonの場合は一回関数入れるとlは更新されてしまうのでlをコピーかなんかでもう一個作っとく必要がある
    print('Stable')#バブルソートは同じ数の順番入れ替わらないんすよね
    print(' '.join(selectionSort(l2,n)))
    if l != l2:
        print('Not stable')
    else:
        print('Stable')


Measured memory_bytes: 6348
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define lli long long int
#define double long double
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define siz(x) x.size()
#define prs(x,y) x.find(y)!=x.end()
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define forn(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
inline int level(int n){int ans=0;while(n%2==0){n/=2;ans++;}return ans;}
int main()
{
	fast_io //REMOVE FOR interactive problems
	lli n,x,t;
	cin>>n>>x>>t;
	cout<<((n+(x-1LL))/x)*t;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
  long w=0,ans=0;
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
      if(s[i]=='W'){
          w++;
          ans += 1+i-w;
      } 
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    ll a;cin>>a; ll p=1;
    rep(i,a){p=(p*(i+1)%MOD);}cout<<p<<endl;
}

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

int main() {
  
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A*B*C == 175) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  
return 0;
}

Measured memory_bytes: 3600
k, s = map(int, input().split())

ans = 0
for x in range(k+1)[::-1]:
    y = min(s-x, k)
    z = s-x-y
    if z > k:
        break
    if x >= 0 and y >= 0 and z >= 0:
        ans += y - z + 1

print(ans)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, ac = 0, wa = 0, tle = 0, re = 0;
	string s;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		if (s == "AC") {
			ac++;
		} else if (s == "WA") {
			wa++;
		} else if (s == "TLE") {
			tle++;
		} else if (s == "RE") {
			re++;
		}
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){
  if(b==0)  return a;
  return gcd(b, a%b);
}
int main(){
    ll a, b;
    cin >> a >> b;
    cout << (a/gcd(a,b))*b << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);ios::sync_with_stdio(false);
  int n, q;

  cin >> n >> q;

  vector<vector<int>> to(n);
  vector<ll> ans(n);

  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a;--b;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  rep(i, q) {
    int p, x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }

  auto dfs = [&](auto dfs, int v, int p) -> void {
    for(int u : to[v]) if(u != p) {
      ans[u] += ans[v];
      dfs(dfs, u, v);
    }
  };

  dfs(dfs, 0, -1);

  rep(i, n) {
    cout << ans[i] << (i == n - 1 ? '\n' : ' ');
  }

  return 0;
}


Measured memory_bytes: 21888
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>  // min, max
#include <fstream>  // ifstream
#include <iomanip>  // setprecision
using namespace std;
typedef long long ll;

int main(void)
{
#ifdef FILE_DEBUG
    ifstream inputFile("data/input.txt");
    cin.rdbuf(inputFile.rdbuf());
#endif
    // これより下にコードを書く

    int N;
    cin >> N;
    vector<int> data(N);
    for (int i = 0; (i < N); ++i) {
        cin >> data[i];
    }

    int minDiff = numeric_limits<int>::max();
    for (int t = 0; (t < (N-1)); ++t) {
        int sum1 = 0;
        for (int i = 0; (i <= t); ++i) {
            sum1 += data[i];
        }
        int sum2 = 0;
        for (int i = t+1; (i < N); ++i) {
            sum2 += data[i];
        }
        minDiff = min(minDiff, abs(sum2 - sum1));
    }

    cout << minDiff << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import os

MOD = 10007

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

    N = int(sys.stdin.buffer.readline().rstrip())
    L1, L2 = 2, 1
    for n in range(N):
        L1, L2 = L2, L1+L2

    print(L1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
/**
 *    Author  : Ador
 *    Created : 24.07.2020
**/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cctype>
typedef long long int ll ;
typedef unsigned long long int ull ;
using namespace std ;
int main(void)
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
        //freopen("input.txt", "r", stdin) ;
        //freopen("output.txt", "w", stdout) ;
    int t ; cin >> t ;
    int i , x , cnt = 0 ;
    for(i = 1 ; i <= t ; ++i)
    {
        cin >> x ;
        if(i % 2 and x % 2) ++cnt ;
    }
    cout << cnt << "\n" ;
    return 0 ;
}

Measured memory_bytes: 3620
from itertools import permutations
from scipy.sparse.csgraph import floyd_warshall
n,m=map(int,input().split())
table=[[0]*n for i in range(n)]
Edge=[None]*m
for i in range(m):
    a,b,c=map(int,input().split())
    table[a-1][b-1]=c
    table[b-1][a-1]=c
    Edge[i]=[a,b,c]
d=floyd_warshall(csgraph=table, directed=False, return_predecessors=False)
ans=0
for i in range(m):
  a,b,c=Edge[i]
  if d[a-1][b-1]<c:
    ans+=1
print(ans)

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

using namespace std;
typedef long long ll;
typedef pair<int,int>pa;
map<pa,int>mp;
const int N=2e5+100;
int n,m;
int a[2000],b[2000],c[2000];
int path[202][202];
void floyd()
{
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                path[i][j]=min(path[i][j],path[i][k]+path[k][j]);
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m;
   for(int i=1;i<=n;i++)
     for(int j=1;j<=n;j++){
       if(i==j) path[i][j]=0;
       else path[i][j]=1e9;
     }
    for(int i=1;i<=m;i++){
        cin>>a[i]>>b[i]>>c[i];
        path[a[i]][b[i]]=path[b[i]][a[i]]=c[i];
    }
    floyd();
    int ans=0;
    for(int i=1;i<=m;i++){
        int f=1;
        for(int j=1;j<=n;j++){
            if(path[j][a[i]]+c[i]==path[j][b[i]]){
                f=0;
            }
        }
        if(f) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3640
N,K = map(int, input().split())

def intlist(x):
    y = []
    for i in range(len(x)):
        y.append(int(x[i]))
    return y

p = intlist(input().split())

p.sort()

total = 0
for i in range(K):
    total = total + p[i]
    
print(total)

Measured memory_bytes: 9212
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solution(String[] args) throws Exception{

		int N = nextInt();
		String S = nextString();
		String ans = "Yes";

		pw.println(N%2==0&&S.equals(S.substring(0,N/2)+S.substring(0,N/2))?"Yes":"No");

	}


	public static void dfs(int n,int cnt,ArrayList<Integer>[] tree,int parent,int[] set){
		if(n!=parent&&tree[n].size()==1){
			set[n]=cnt;
			return;
		}
		for(int x:tree[n]){
			if(x==parent){
				continue;
			}
			dfs(x,cnt+1,tree,n,set);
		}
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



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


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

  char col[N];
  for(int i = 0; i < N; i++){
    cin >> col[i];
    if(col[i] == 'Y'){
      cout << "Four" << endl;
      return 0;
    }
  }
 
  cout << "Three" << endl;

  return 0;
}

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

int main () 
{
    int H, W;
    std::cin >> H >> W;
    
    char s[H][W];
    for (int i = 0; i < H; i++) 
    {
        for (int j = 0; j < W; j++) 
        {
            std::cin >> s[i][j];
        }
    }
    
    for (int i = 0; i < H; i++) 
    {
        for (int j = 0; j < W; j++) 
        {
            if (s[i][j] == '#' and s[i-1][j] != '#' and s[i+1][j] != '#' and s[i][j-1] != '#' and s[i][j+1] != '#')
            {
                std::cout << "No" << std::endl;
                return 0;
            }
        }
    }
    
    std::cout << "Yes" << std::endl;
    
    return 0;
}

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

int main( void )
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if ( ( e - a ) <= k )
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }

    return 0;
}


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

int main(){
  int n,i,j;
  cin >> n;
  vector<ll> a(n),b(n),c(n);
  ll s=0,t;
  for(i=0;i<n;i++){
    cin >> a.at(i);
  }
  for(i=0;i<n;i++){
    cin >> b.at(i);
    c.at(i)=a.at(i)-b.at(i);
    s += c.at(i);
  }
  
  if(s<0){
    cout << -1 << endl;
    return 0;
  }
  
  sort(c.begin(),c.end());
  if(c.at(0)>=0){
    cout << 0 << endl;
    return 0;
  }
  
  s=0;
  i=0;
  while(c.at(i)<0){
    s -= c.at(i);
    i++;
  }
  j=n;
  t=0;
  while(t<s){
    j--;
    t += c.at(j);
  }
  
  cout << i+n-j << endl;
}

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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
typedef long long ll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e;
    int tmp = iinf;
    if(a%10!=0){
        amin(tmp, a%10);
        a+=10-a%10;
        
    }
    if(b%10!=0){
        amin(tmp, b%10);
        b+=10-b%10;
        
    }
    if(c%10!=0){
        amin(tmp, c%10);
        c+=10-c%10;
        
    }
    if(d%10!=0){
        amin(tmp, d%10);
        d+=10-d%10;
        
    }
    if(e%10!=0){
        amin(tmp, e%10);
        e+=10-e%10;
        
    }
    if(tmp==iinf){
        tmp=10;
    }
    cc(a+b+c+d+e-10+tmp);
}

Measured memory_bytes: 256
//
//  main.cpp
//  atCoder
//
//  Created by Lynn Zhou on 10/19/15.
//
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int a,b;
    while (1) {
        cin>>a>>b;
        if(a==0 && b==0)
            break;
        int sum=0;
        for(int i=1;i<=a;i++){
            for(int j=i+1;j<=a;j++){
                for(int k=j+1;k<=a;k++){
                    if((i+j+k)==b)
                        sum++;
                }
            }
        }
        cout<<sum<<endl;
    }
    
    return 0;
    
}

Measured memory_bytes: 1160
n = input()
m = input()
lst = []
if m in n:
    print(0)
else:
    for i in range(len(n) - len(m) + 1):
        count = 0
        for j in range(i, len(m) + i):
            if n[j] != m[j-i]:
                count += 1
        lst.append(count)
    print(min(lst))

Measured memory_bytes: 73136
N,M = map(int,input().split())
st = [list(map(int,input().split())) for _ in range(N)]
ch = [list(map(int,input().split())) for _ in range(M)]
for i in range(N):
    d = float("inf")
    for j in range(M):
        dj = abs(st[i][0]-ch[j][0])+abs(st[i][1]-ch[j][1])
        if d > dj:
            c = j+1
            d = dj
    print(c)

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

#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef vector<int> vi;

void solve(void) {

	int n;
	cin >> n;

	vi A(n), B(n), C(n);

	for(int i = 0; i < n; i++) {
		cin >> A[i] >> B[i] >> C[i];
	}

	vector<vi> dp(n+1, vi(3));

	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < 3; j++) {
			if(j == 0) {
				dp[i][j] = max(dp[i-1][1], dp[i-1][2]) + A[i-1];
			} else if (j == 1) {
				dp[i][j] = max(dp[i-1][0], dp[i-1][2]) + B[i-1];
			} else {
				dp[i][j] = max(dp[i-1][0], dp[i-1][1]) + C[i-1];
			}
		}
	}


	int ans = max(dp[n][0], max(dp[n][1], dp[n][2]));
	cout << ans << '\n';
}

int main(void) {

	solve();
	return 0;
}


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

int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    vector<int>d(n+1);
    for(int i=0;i<n;i++){
        cin>>a[i];
        d[a[i]]++;
    }
    sort(d.begin(),d.end(),greater<int>());
    int tmp=0;
    for(int i=0;i<k;i++){
        tmp+=d[i];
    }
    cout<<n-tmp<<endl;
    
    return 0;
}

Measured memory_bytes: 4776
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    A, B = [], []
    for _ in range(N):
        a, b = ZZ()
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    midA = A[N//2] if N%2 == 1 else (A[N//2-1] + A[N//2])
    midB = B[N//2] if N%2 == 1 else (B[N//2-1] + B[N//2])
    print(midB-midA+1)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 99636
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;
int main(){
  int H,W;cin>>H>>W;
  vector<string>S(H);for(int i=0;i<H;i++)cin>>S[i];
  vector<vector<int>>D(H,vector<int>(W,INT_MAX)),filled(H,vector<int>(W,0));
  
  queue<p>q;q.push(p(0,0));filled[0][0]=true;D[0][0]=0;
  while(q.size()){
    int y=q.front().first,x=q.front().second;q.pop();
    if(y-1>=0 && S[y-1][x]=='.'&& filled[y-1][x]==0){
      D[y-1][x]=D[y][x]+1;filled[y-1][x]=1;q.push(p(y-1,x));}
    if(y+1<H && S[y+1][x]=='.'&&  filled[y+1][x]==0){
      D[y+1][x]=D[y][x]+1;filled[y+1][x]=1;q.push(p(y+1,x));}
    if(x-1>=0 && S[y][x-1]=='.'&&  filled[y][x-1]==0){
      D[y][x-1]=D[y][x]+1;filled[y][x-1]=1;q.push(p(y,x-1));}
    if(x+1<W && S[y][x+1]=='.'&&  filled[y][x+1]==0){
      D[y][x+1]=D[y][x]+1;filled[y][x+1]=1;q.push(p(y,x+1));}
  }
  if(D[H-1][W-1]==INT_MAX){cout<<-1;return 0;}
  int white=0;
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)white+=(S[i][j]=='.');
  cout<<white-D[H-1][W-1]-1;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
const int mod = 1000000007;

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

    int broken[n+1];
    rep(i, n+1) {
        broken[i] = 0;
    }
    rep(i, m) {
        int a;
        cin >> a;
        broken[a] = 1;
    }

    int dp[n+2];
    rep(i, n+2) {
        dp[i] = 0;
    }

    dp[n] = 1;
    for(int i = n-1; i >= 0; i--) {
        if(broken[i]) {
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i+1] + dp[i+2])%mod;
    }
    
    cout << dp[0] << endl;
    return 0;
}

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

int n, m, pre[1001];
bool vis[1001];
vector<int> adj[1001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
	}
	for(int i = 1; i <= n; i++){
		memset(vis, 0, sizeof(vis));
		memset(pre, 0, sizeof(pre));
		stack<pair<int, int>> que;
		que.push({i, 0});
		while(!que.empty()){
			pair<int, int> vtx = que.top();
			que.pop();
			vis[vtx.first] = true;
			pre[vtx.first] = vtx.second;
			for(auto j : adj[vtx.first])
				if(j == i){
					set<int> chn = {i};
					int cur = vtx.first;
					while(cur != i){
						chn.insert(cur);
						cur = pre[cur];
					}
					bool val = true;
					for(auto k : chn){
						int cnt = 0;
						for(auto l : adj[k])
							if(chn.find(l) != chn.end()) cnt++;
						if(cnt > 1) val = false;
					}
					if(val){
						cout << chn.size() << "\n";
						for(auto k : chn) cout << k << "\n";
						return 0;
					}
				}else if(!vis[j]) que.push({j, vtx.first});
		}
	}
	cout << "-1\n";
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> 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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const ll MOD=1000000007;
const ll LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    ll a, b, c, d;cin >> a >> b >> c >> d;
    cout << max({a * c, b * d, a * d, b * c}) << endl;
    return 0;
}


Measured memory_bytes: 3632
n, k = map(int, input().split())
A = list(map(int, input().split()))

dict = {}

for a in A:
	try:
		dict[a] += 1
	except KeyError:
		dict[a] = 1

sorted_dict = sorted(dict.items(), key=lambda x: -x[1])

ans = 0
for i in range(k,len(sorted_dict)):
	ans += sorted_dict[i][1]
print(ans)

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

int main(){
    long long a, b, c, d, n;
    cin >> a >> b >> c >> d >> n;
    a *= 4;
    b *= 2;
    long long ans = 0;
    if (n % 2 == 0) {
        a *= 2;
        b *= 2;
        c *= 2;
        n /= 2;
        long long mn = min({a, b, c, d});
        ans += mn * n;
    } else {
        a *= 2;
        b *= 2;
        c *= 2;
        n /= 2;
        long long mn = min({a, b, c, d});
        ans += mn * n;
        ans += min({a/2, b/2, c/2});
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
s = list(input())
n = len(s)
k = int(input())
t = [ord(s[i]) - 97 for i in range(n)]
for i in range(n):
    if k == 0:
        break
    x = 26 - t[i]
    if 0 < x % 26 <= k:
        k -= x
        s[i] = "a"
t[-1] = ord(s[-1]) - 97
if k > 0:
    s[-1] = chr((k + t[-1]) % 26 + 97)
print("".join(s))

Measured memory_bytes: 10528
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int f(int n) {
		if(n % 2 == 0) return n / 2;
		else return 3 * n + 1;
	}
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int s = sc.nextInt();
		int[] a = new int[1000010];
		int[] check = new int[1000010];
		Arrays.fill(check, 0);
		a[1] = s; check[s]++;
		for(int i = 2; i < a.length; i++) {
			a[i] = f(a[i - 1]);
			check[a[i]]++;
			if(check[a[i]] > 1) {
				System.out.println(i);
				break;
			}
		}
	}
}


Measured memory_bytes: 30164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0; int a = 0; int b = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'W') a++;
    if(s[i] == 'R') b++;
  }
  for(int i = 0; i < b; i++){
    if(s[i] == 'W') ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3744
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    
    static int H, W, sx, sy, ex, ey;
    static boolean wall[][] = new boolean[1005][1005];
    static boolean vis[][] = new boolean[1005][1005];

    static LinkedList<Integer> queueX = new LinkedList<>(),
                            queueY = new LinkedList<>(),
                            cost = new LinkedList<>();
    static int queueSize = 0;

    public static boolean crawl(int x, int y, Integer warpUsed) {
        if (vis[x][y]) return false;
        if (wall[x][y]) return false;
        vis[x][y] = true;

        if (x == ex && y == ey) return true;

        // -- try walking first
        if (crawl(x+1, y, warpUsed)) return true;
        if (crawl(x-1, y, warpUsed)) return true;
        if (crawl(x, y+1, warpUsed)) return true;
        if (crawl(x, y-1, warpUsed)) return true;

        // -- performing Warp spell
        for (int dx = -2; dx <= 2; dx++)
            for (int dy = -2; dy <= 2; dy++)
                if (!wall[x+dx][y+dy] && !vis[x+dx][y+dy]) {
                    queueX.add(x+dx);
                    queueY.add(y+dy);
                    cost.add(warpUsed + 1);
                    queueSize++;
                }
        return false;
    }

    public static void solve() {
        queueX.add(sx); queueY.add(sy);
        cost.add(0);
        queueSize = 1;
        // --
        while (queueSize > 0) {
            Integer x = queueX.pop(), y = queueY.pop(), c = cost.pop();
            queueSize--;
            //System.out.println("Crawling.. x = " + x + " y = " + y + " c = " + c);
            //
            if (crawl(x, y, c)) {
                System.out.println(c);
                return;
            }
        }
        System.out.println(-1);
    }

    public static void main(String[] args) {
        H = sc.nextInt(); W = sc.nextInt();
        sx = sc.nextInt(); sy = sc.nextInt();
        ex = sc.nextInt(); ey = sc.nextInt();
        sx += 1; sy += 1;
        ex += 1; ey += 1;

        for (int i = 0; i < 1005; i++)
            Arrays.fill(wall[i], true);

        // start at (2, 2)
        for (int i = 0; i < H; i++) {
            String s = sc.next();
            for (int j = 0; j < W; j++) {
                wall[i+2][j+2] = (s.charAt(j) == '.' ? false : true);
            }
        }
        solve();
    }
}

Measured memory_bytes: 85484
def main():
    A = [int(i) for i in input().split()]
    K = int(input())

    cnt = 0
    while cnt < K and A[0] >= A[1]:
        A[1] *= 2
        cnt += 1

    while cnt < K and A[1] >= A[2]:
        A[2] *= 2
        cnt += 1

    if A[0] < A[1] and A[1] < A[2]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61736
import Data.Char

win :: String->Char->Bool
win g c = 
    ((g!!0)==c && (g!!1)==c && (g!!2)==c) || 
    ((g!!3)==c && (g!!4)==c && (g!!5)==c) || 
    ((g!!6)==c && (g!!7)==c && (g!!8)==c) || 
    ((g!!0)==c && (g!!3)==c && (g!!6)==c) || 
    ((g!!1)==c && (g!!4)==c && (g!!7)==c) || 
    ((g!!2)==c && (g!!5)==c && (g!!8)==c) || 
    ((g!!0)==c && (g!!4)==c && (g!!8)==c) || 
    ((g!!2)==c && (g!!4)==c && (g!!6)==c)

solve :: String->IO ()
solve grid = do
    if      win grid 'o' then putStrLn "o"
    else if win grid 'x' then putStrLn "x"
    else                      putStrLn "d"

main = do
    ss <- getContents
    mapM_ solve $ lines ss

Measured memory_bytes: 3528
#include <stdio.h>

int main()
{
	int N, h[100];
	scanf("%d", &N);

	for(int n=0; n<N; n++){
		scanf("%d", h+n);
	}

	int res = 0, count = 1;
	for(int i=0; count != 0; i++){
		count = 0;
		if(h[0]>i){
			count++;
		}
		for(int n=1; n<N; n++){
			if(h[n]>i && h[n-1]<=i){
				count++;
			}
		}
		res += count;
	}
	printf("%d\n", res);

	return 0;
}


Measured memory_bytes: 128