akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<unistd.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ST first
#define ND second
#define ll long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;
 
// replace ll with pair if multiset needed
typedef tree<int, null_type, greater<int >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set secik;
 
const ll INF = 1e9 + 9;
const ll MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;
 
// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)
 
//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<int> gen(0,n-1);

const int SIZE = 1e6 + 6;

ll dp[SIZE][2];
vector<int> adj[SIZE];

void dfs(int v, int prev){
	for(auto it : adj[v]){
		if(it == prev) continue;
		dfs(it,v);
	}
	long long ilo1 = 1, ilo2 = 1;
	for(auto it : adj[v]){
		if(it == prev) continue;
		ilo1 = (ilo1 * (dp[it][0] + dp[it][1])) % MOD;
		ilo2 = (ilo2 * dp[it][0]) % MOD;
	}
	dp[v][0] = ilo1;
	dp[v][1] = ilo2;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	int n; cin >> n;
	for(int i = 1; i < n; i++){
		int a,b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	dfs(1,-1);

	cout << (dp[1][0] + dp[1][1]) % MOD;




}

Measured memory_bytes: 36992
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
using db = double;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)
  __gcd(a,b)は最大公約数を取ってくれる、aとb
  の大きい方をNとしたとき、計算量は log(N);
 */
const int mod = 1e9 + 7;

//ここから書き始める
int main(){
	int n ;// nは整数
	cin >> n; // 毎回入力するのをテンプレートに
	int m ; 
	cin >> m;
	vector<string> a(n);
	rep(i,n) cin >> a[i];
	vector<string> b(m);
	rep(i,m) cin >> b[i];

	//cにaの切り取る部分を入れて、それがbと一致するかを見る
	vector<string> c(m);

	for(int i = 0 ; i <= n - m ;i++){//横
		for(int j = 0; j <= n - m ; j++){//縦
			for(int k = 0 ;k < m ; k++){
			//	cout << "make c[k], k: "<< k<<endl;
				c[k] = a[i+k].substr(j,m);
			}
			if(c==b){
				cout << "Yes"<<endl;
				return 0;
			}
		}
	}
	cout << "No" << endl; 
	//	for(auto x: a){
	//		cout<< x<<endl;
	//	}
	//	for(auto x: b){
	//		cout<< x<<endl;
	//	}
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp;

#[fastout]
fn main() {
  input! {
    s: Chars,
    mut t: Chars,
  }
  t.pop();

  println!("{}", if s == t { "Yes" } else { "No" });
}


Measured memory_bytes: 2192
N,M=map(int,input().split())
Lmax=1
Rmin=N
for i in range(M):
    L,R=map(int,input().split())
    Lmax=max(Lmax,L)
    Rmin=min(Rmin,R)
    
print(max(Rmin-Lmax+1,0))

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

int main() {

int a,b,c,d;

cin >>a>>b>>c>>d;
string ans="Yes";
rep(i,1e9)
{
  if(i%2==0)
  {c-=b;}
  else
  {a-=d;}
  if(c<=0)
  {ans="Yes"; break;}
  if(a<=0)
  {ans="No"; break;}
  
}

cout << ans<<endl;




}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/


Measured memory_bytes: 3596
#include<stdio.h>
int main(){
    int a,b,r,tmp;
    scanf("%d%d",&a,&b);
    if(a<b){
        tmp=a;
        a=b;
        b=tmp;
    }
    
    r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    printf("%d\n",b);
    
    return 0;
    
}


Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
//最初に設定する.
ll MOD=998244353;
const int  MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];  void modcinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long modc(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; }
int main( ){
    modcinit();
    ll N,M;
    ll K;
    cin>>N>>M>>K;
    ll ans=0;
    ll mod=MOD;
    rep(i,0,K+1){
       ll add=((M*modc(N-1,i)%mod+mod)%mod*modpow(M-1,N-1-i,mod)%mod+mod)%mod;
       ans=((add+ans)%mod+mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}




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

#define int long long
#define mod 1000000007

using namespace std;

main()
{
    string s;
    int k;

    cin >> s;
    cin >> k;

    int i = -1;

    for(i=0;i<s.size();i++)
    {
        if(s[i] != '1')
            break;
    }

    if(i == -1)
        cout << s[0] << endl;
    else if(k <= i)
        cout << 1 << endl;
    else
        cout << s[i] << endl;
}

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

const int N=1005,M=40005,oo=1e9;
struct edge{
	int di,nextt,ed;
}e[M];
int son[N],nedge,cur[N],deep[N],n,m;
inline void aedge(int a,int b,int c){
	e[++nedge].nextt=son[a];
	son[a]=nedge;
	e[nedge].ed=b;
	e[nedge].di=c;
}
inline void insert(int a,int b,int c){
	aedge(a,b,c); aedge(b,a,0); //cout<<a<<" "<<b<<endl;
}
inline bool bfs(int s,int t){
	for(int i=1;i<N;i++)deep[i]=oo;
    for(int i=1;i<N;i++)cur[i]=son[i];
    deep[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty()){
        int now=q.front();q.pop();
        for(int tmp=son[now];tmp;tmp=e[tmp].nextt)
            if(deep[e[tmp].ed]>=oo&&e[tmp].di){deep[e[tmp].ed]=deep[now]+1,q.push(e[tmp].ed);}
    }
    return deep[t]<oo;
}
int dfs(int now,int t,int limit){
    if(!limit||now==t) return limit;
    int flow=0,f;
    for(int tmp=cur[now];tmp;tmp=e[tmp].nextt){
        cur[now]=tmp;
        if(deep[e[tmp].ed]==deep[now]+1&&(f=dfs(e[tmp].ed,t,min(limit,e[tmp].di)))){
            flow+=f; limit-=f; e[tmp].di-=f; e[((tmp-1)^1)+1].di+=f; if(!limit)break;
        }
    }
    return flow;
}
inline int dinic(int s,int t){
    int ans=0;
    while(bfs(s,t))ans+=dfs(s,t,oo);
    return ans;
}
inline int read(){
	int x=0;char ch=getchar();bool positive=1;
	for(;!isdigit(ch);ch=getchar())	if(ch == '-')	positive=0;
	for(;isdigit(ch);ch=getchar())	x=x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a;putchar('-');
	}
	write(a);puts("");
}
const int P=10000005;
int tot,q[P/10];
bool heshu[P],a[P];
int b[205];
int main(){
    n=read();
	for(int i=2;i*i<P;i++)if(!heshu[i]){
		for(int j=i+i;j<P;j+=i)heshu[j]=1;
	}
	tot=0;
	for(int i=1;i<=n;i++){
		int t=read(); a[t]^=1; a[t+1]^=1;
	}
	heshu[1]=1;
	int jb=0;
	for(int i=1;i<P;i++)if(a[i])b[++jb]=i;
	for(int i=1;i<=jb;i++)if(b[i]&1){
		for(int j=1;j<=jb;j++)if(b[j]%2==0){
			if(!heshu[abs(b[i]-b[j])]){insert(i,j,1);}
		}
	}
	int s=jb+1,t=jb+2;
	for(int i=1;i<=jb;i++)if(b[i]&1){insert(s,i,1); tot++; }else insert(i,t,1);
	int jj=dinic(s,t); 
	cout<<jj+(jb-jj*2)+((tot-jj)&1)<<endl;
}


Measured memory_bytes: 18816
#include<bits/stdc++.h>
      using namespace std;
      #define ll long long
      #define pb push_back
      #define pll  pair <long long,long long>
      #define mp make_pair
      #define ss second
      #define ff first
      #define maa 1000000007
      #define endl '\n'
      #define ld long double
      #define all(x) x.begin(),x.end()
      ll  power(ll  i,ll  j)
      {
        if(j==0)
        return 1 ;
        ll t=power(i,j/2)%maa ;
        if(j%2==0)
        return (t%maa*t%maa)%maa ;
        else
        return ((t%maa*t%maa)%maa*(i%maa)%maa)%maa ;
      }
      bool is(ll  i)
      {
        if(i==1)
            return 0 ;
        ll  f=0 ;
        for(ll  j=2;j<=sqrt(i);j++)
        {
            if(i%j==0)
            {
                f=1 ;
                break ;
            }
        }
        return !f ;
      }
      ll dp[3001][3001] ;
      string r,s ;
      ll fun(ll i,ll j)
      {
          if(i==-1||j==-1)
          return 0 ;
          else if(dp[i][j]!=-1)
          return dp[i][j] ;
          else
          {
              ll ans=0 ;
              ans=max(fun(i-1,j),fun(i,j-1)) ;
              if(r[i]==s[j])
              ans=max(ans,1+fun(i-1,j-1)) ;
              return dp[i][j]=ans ;
          }
          
      }
      string Ans ;
      void fun1(ll i,ll j,ll u,string sans)
      {
          
          
          if(u==0)
         {
             Ans=sans ;
             return ;
         }
         if(i==-1||j==-1)
          return ;
          
         // cout<<i<<" "<<j<<" "<<u<<endl ;
          
          if(u==fun(i-1,j))
          {
             
              fun1(i-1,j,u,sans) ;
          }
          else if(u==fun(i,j-1))
          {
              
              fun1(i,j-1,u,sans) ;
          }
          else if(r[i]==s[j]&&(u-1)==fun(i-1,j-1))
          {
              sans+=s[j] ;
              fun1(i-1,j-1,u-1,sans) ;
          }
      }
      int main()
      {

        /// 50-4
        /// freopen("input.txt","r",stdin);
        /// freopen("output.txt","w",stdout);
        cin>>r>>s ;
        for(ll i=0;i<3001;i++)
        for(ll j=0;j<3001;j++)
        dp[i][j]=-1 ;
        
        ll ans=fun(r.length()-1,s.length()-1) ;
        
        
       fun1(r.length()-1,s.length()-1,ans,"") ;
        
        reverse(all(Ans)) ;
        cout<<Ans ;
      
        
        
      }








Measured memory_bytes: 78464
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import           Data.List             (minimumBy)
import           Data.Maybe            (fromJust)
import           Data.Ord              (comparing)

main :: IO ()
main = do
  n <- readLn :: IO Int
  [t, a] <- getInts
  hs <- getInts
  print $ solve n t a hs

solve :: Int -> Int -> Int -> [Int] -> Int
solve n t a hs = fst . minimumBy (comparing snd) $ zip [1 .. n] [abs (a' - (t' - fromIntegral h * 0.006)) | h <- hs]
  where a' = fromIntegral a
        t' = fromIntegral t

readInts :: BC.ByteString -> [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words

getInts :: IO [Int]
getInts = readInts <$> BC.getLine


Measured memory_bytes: 1020
import sys
import numpy as np

#n=int(sys.stdin.readline())
n,k=map(int,sys.stdin.readline().split())
#a=np.array([sys.stdin.readline().split() for i in range(n)],np.int64)

i=-1
while True:
    i+=1
    if n<k**i:
        print(i)
        break
        


Measured memory_bytes: 21552
n = int(input())
t,a = map(int,input().split())
h = [int(i) for i in input().split()]
ans = []
count=[]
for i in range(len(h)):
    aim = t-(h[i]*0.006)
    ans.append(aim)
for j in range(n):
    ou = abs(ans[j]-a)
    count.append(ou)
print(count.index(min(count))+1)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll N, X; cin >> N >> X;
	ll m[100];
	ll minV = 1 << 21;
	ll cnt = 0;
	rep(i, 0, N) {
		cin >> m[i];
		X -= m[i];
		cnt++;
		minV = min(minV, m[i]);
	}
	cout << X / minV + cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;

int N;
string S;
long long m, c, t;

void add(int i) {
    if (S[i] == 'M') ++m;
    else if (S[i] == 'C') ++c, t += m;
}

void erase(int i) {
    if (S[i] == 'M') --m, t -= c;
    else if (S[i] == 'C') --c;
}

long long solve(int K) {
    long long res = 0;
    m = 0; t = 0;
    int r = 0;
    for (int l = 0; l < N;) {
        while(r < N && r - l <K) add(r++);
        if (S[l] == 'D') res += t;
        erase(l++);
    }
    return res;
}

int main(){
    while (cin >> N >> S) {
        int Q; cin >> Q;
        for (int i = 0; i < Q; ++i) {
            int k; cin >> k;
            cout << solve(k) << endl;
        }
    }
}


Measured memory_bytes: 1412
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
if s == 'ABC':
    print('ARC')
else:
    print('ABC')

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

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> A)
{
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    cout << (A.size() == N ? YES : NO) << 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)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<string> s(3);
  for (int i = 0; i < 3; i++) {cin >> s.at(i);}
  for (int i = 0; i < 3; i++) {
    char c = s.at(i).at(0);
    putchar(toupper(c));
  }
}

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

int main(void){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	
	int a[3],i;
	for(i=0;i<3;i++)cin>>a[i];
	sort(a,a+3);
	cout<<a[2]-a[0]<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    while (true) {
        int num = sc.nextInt();
        if (num == 0) {
            break;
        }
        int max = 0;
        int min = 1000;
        int scoreSum = 0;
        for (int j = 0; j < num; j++) {
            int score = sc.nextInt();
            scoreSum += score;
            if (score < min) {
                min = score;
            }
            if (score > max) {
                max = score;
            }
        }
        scoreSum -= max;
        scoreSum -= min;

        num -= 2;

        System.out.println(scoreSum / num);
    }
    }
}


Measured memory_bytes: 29196
#include<iostream>
#include<string>

int main(){
    std::string S;
    std::cin >> S;
    for(int i = 0; i < S.size(); i++){
        // for 0 origin
        if(i % 2 == 0) std::cout << S[i];
    }

    std::cout << std::endl;
    return 0;
}


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

A = [True for i in range(N + 2)]

dp = [0 for i in range(N + 3)]

for i in range(M):
    a = int(input())
    A[a] = False

dp[0] = 1
for i in range(N):
    if A[i] == False:
        continue
    dp[i + 1] += dp[i]
    dp[i + 1] %= 1000000007
    dp[i + 2] += dp[i]
    dp[i + 2] %= 1000000007

print(dp[N])


Measured memory_bytes: 7888
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
from itertools import product
def bisection(l,r,f,left=True,discrete=True):
    eps=1 if(discrete) else 10**-8
    if((not left)^f(r)): return r if(left) else r+1
    elif(left^f(l)): return l-1 if(left) else l
    while(r-l>eps):
        h=(l+r)//2 if(discrete) else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if(not discrete) else l if(left) else r

def resolve():
    k = int(input())

    def check(x):
        if 1 <= x <= 9:
            return x >= k
        x = str(x)
        dp = [[0] * 2 for _ in range(10)]
        s = int(x[0])
        for i in range(1, s):
            dp[i][1] = 1
        dp[s][0] = 1

        x = x[1:]
        for s in x:
            s = int(s)
            ndp = [[0] * 2 for _ in range(10)]
            for d, lt in product(range(10), range(2)):
                for nd in [d-1, d, d+1]:
                    if not (0 <= nd <= 9):
                        continue
                    if lt == 0 and s < nd:
                        continue
                    nlt = max(lt, s > nd)
                    ndp[nd][nlt] += dp[d][lt]
            for d in range(1, 10):
                ndp[d][1] += 1
            dp = ndp
        return sum(dp[d][lt] for d, lt in product(range(10), range(2))) >= k


    print(bisection(1, 10**18+1, check, left=False))
resolve()

Measured memory_bytes: 43620
A, B, C = map(int, input().split())

if A==7:
    if B==5:
        if C==5:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
elif A==5:
    if B==7:
        if C==5:
            print("YES")
        else:
            print("NO")
    elif B==5:
        if C==7:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
else:
    print("NO")

Measured memory_bytes: 3064
ABCD = [int(s) for s in list(input())]
operators = ["-", "+"]
for bit in range(1 << 3):
    ops = [(bit >> i) & 1 for i in range(3)]
    tmp = ABCD[0]
    for op, val in zip(ops, ABCD[1:]):
        if op:
            tmp += val
        else:
            tmp -= val
    if tmp == 7:
        print(ABCD[0], end="")
        for op, val in zip(ops, ABCD[1:]):
            print(operators[op], val, sep="", end="")
        print("=7")
        exit()


Measured memory_bytes: 38256
package main

import "fmt"

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

	var o int

	o = n / 100
	if n > o*100+o*10+o {
		o++
		fmt.Println(o*100 + o*10 + o)
	} else {
		fmt.Println(o*100 + o*10 + o)
	}
}

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

class Dmondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());

        //素因数分解の結果を保存
        var array = new int[100];
        array[0] = 1;
        for (int i = 1; i < 100; ++i) array[i] = 0;
        for (int i = 2; i <= N; ++i)
        {
            var num = i;
            for (int k = 2; k <= i; ++k)
            {
                if (num < k) break;
                while (num % k == 0)
                {
                    array[k - 1]++;
                    num /= k;
                }
            }
        }

        var list = new List<double>();
        // 74 2.24 4.14 2.4.4
        for (int i=0;i<array.Count();++i)
        {
            if (array[i] == 0) continue;
            if (74 <= array[i])
            {
                var n = Math.Pow(i + 1, 74);
                if (!list.Contains(n)) list.Add(n);
            }

            for (int j = 0; j < array.Count(); ++j)
            {
                if ((array[j] == 0)||(j==i)) continue;
                if (4 <= array[i] && 14 <= array[j])
                {
                    var n = (Math.Pow(i + 1, 4) + Math.Pow(j + 1, 14));
                    if (!list.Contains(n)) list.Add(n);
                }
                if (2 <= array[i] && 24 <= array[j])
                {
                    var n = (Math.Pow(i + 1, 2) + Math.Pow(j + 1, 24));
                    if (!list.Contains(n)) list.Add(n);
                }

                for (int k = 0; k < array.Count(); ++k)
                {
                    if ((array[k] == 0)||(k==i)||(k==j)) continue;

                    if ( 2 <= array[i] && 4 <= array[j] && 4 <= array[k] )
                    {
                        var n = (Math.Pow(i + 1, 2) + Math.Pow(j + 1, 4) + Math.Pow(k + 1, 4));
                        if (!list.Contains(n)) list.Add(n);
                    }
                }
            }
        }
        Console.WriteLine(list.Count());
        
    }
}

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

using namespace std;

int main()
{
  long long res = 0;
  int N;
  cin >> N;
  vector<long long> a(N);
  vector<long long> b(N);
  for (int i = 0; i < N; i++) cin >> a[N-i-1] >> b[N-i-1];
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    a[i] += sum;
    long long t = b[i] - a[i] % b[i];
    if (a[i] % b[i] != 0) {
      a[i] += t;
      sum += t;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 1792
a = list(map(int,input().split()))
N, D = a[0], a[1]
pts = []
for _ in range(N):
  a = list(map(int,input().split()))
  pts.append([a[0],a[1]])

rev = 0
for r in pts:
  if (r[0]**2 + r[1]**2)**0.5 <= D:
    rev += 1

print(rev)


Measured memory_bytes: 39412
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=3e5+10;
ll ans,n;
int main(){
    cin>>n;
    for(int i=sqrt(n)+1;i>=1;i--){
        if(n%i==0){ans=n/i+i;break;}
    }
    cout<<ans-2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
  int64_t A,B,C,K;
  cin >> A >> B >> C >> K;
  int64_t ans = A-B;
  if(abs(ans)>1000000000000000000){
    cout << "Unfair" << endl;
  }
  else if(K%2 == 0){
    cout << ans << endl;
  }
  else{
    cout << -1*ans << endl;
  }

}



Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	if(k==1){
		cout << 0 << endl;
	}
	else{
		cout << n-k << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>

using namespace std;

int main(){

  int sx;
  int sy;
  int tx;
  int ty;

  cin >> sx >> sy >> tx >> ty;

  
  //cout << sx << tx << sy << ty << endl;

  //原点へ
  
  tx = tx - sx;
  sx = sx - sx;

  ty = ty - sy;
  sy = sy - sy;

  //cout << sx << tx << sy << ty << endl;


  string ans;
  string s_g;
  string g_s;

  string dr = "DR";
  string ul = "UL";

  int i;
  for(i = 0; i < abs(tx); i++){

    if(tx > 0){
      s_g.push_back('R');
      g_s.push_back('L');
    }
    else{
      s_g.push_back('L');
      g_s.push_back('R');
    }
  }

  for(i = 0; i < abs(ty); i++){

    if(ty > 0){
      s_g.push_back('U');
      g_s.push_back('D');
    }
    else{
      s_g.push_back('D');
      g_s.push_back('U');
    }
  }

  ans = s_g + g_s + dr + s_g + ul + ul + g_s + dr;


  cout << ans << endl;


}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

// Union Find {{{
class UnionFind {
 public:
     int n;
     std::vector<int> par;
     std::vector<int> num;

     explicit UnionFind(int n) {  // [0 n)のunion find
         this->n = n;
         this->par.resize(n);
         this->num.resize(n, 1);
         for (int i = 0; i < n; i++) {
             this->par[i] = i;
         }
     }

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

     bool same(int i, int j) {
         return root(i) == root(j);
     }

     bool unite(int i, int j) {
         int t = root(i);
         int k = root(j);

         if (t == k)
           return false;

         par[t] = k;
         num[k] += num[t];
         return true;
     }

     int size(int i) {
         return num[root(i)];
     }
};
// }}}

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

ll H,W;
string s[500];

UnionFind uf(500*500);
bool visited[500][500];
set<PLL> nWhite[500*500];

ll vertexID(ll y, ll x) {
  return y * 500 + x;
}

void dfs(ll y, ll x, ll sy, ll sx) {
  if (visited[y][x])
    return;

  // cout << y << " " << x << endl;
  visited[y][x] = true;
  uf.unite(vertexID(y,x), vertexID(sy,sx));

  if (y-2 >= 0 && s[y-1][x] == '.' && s[y-2][x] == '#') dfs(y-2,x,sy,sx);
  if (y+2 < H  && s[y+1][x] == '.' && s[y+2][x] == '#') dfs(y+2,x,sy,sx);
  if (x-2 >= 0 && s[y][x-1] == '.' && s[y][x-2] == '#') dfs(y,x-2,sy,sx);
  if (x+2 < W  && s[y][x+1] == '.' && s[y][x+2] == '#') dfs(y,x+2,sy,sx);

  if (y-1 >= 0 && x-1 >= 0 && (s[y][x-1] == '.' || s[y-1][x] == '.') && s[y-1][x-1] == '#') dfs(y-1,x-1,sy,sx);
  if (y+1 < H  && x-1 >= 0 && (s[y][x-1] == '.' || s[y+1][x] == '.') && s[y+1][x-1] == '#') dfs(y+1,x-1,sy,sx);
  if (y-1 >= 0 && x+1 < W  && (s[y][x+1] == '.' || s[y-1][x] == '.') && s[y-1][x+1] == '#') dfs(y-1,x+1,sy,sx);
  if (y+1 < H  && x+1 < W  && (s[y][x+1] == '.' || s[y+1][x] == '.') && s[y+1][x+1] == '#') dfs(y+1,x+1,sy,sx);
}

signed main() {
  cin >> H >> W;
  rep(y,H)
    cin >> s[y];

  rep(y,H)
    rep(x,W)
      if (s[y][x] == '#')
       dfs(y, x, y, x);

  rep(y,H)
    rep(x,W)
      if (s[y][x] == '#') {
        ll id = uf.root(vertexID(y,x));
        rep(k,4) {
          ll ny = y + dy[k];
          ll nx = x + dx[k];
          if (0 <= ny && ny < H && 0 <= nx && nx < W && s[ny][nx] == '.')
            nWhite[id].insert({ny, nx});
        }
      }


  ll ans = 0;
  rep(y,H) {
    rep(x,W) {
      if (s[y][x] == '#') {
        ll id = uf.root(vertexID(y,x));
        ans += nWhite[id].size();
        // printf("%5d(%2d)", id, nWhite[id].size());
      } else {
        // printf("%5s", ".");
      }
    }
    // cout << endl;
  }

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



Measured memory_bytes: 35584
W,H,x,y,r = map(int,input().split())
t = 0
if 0<=(x-r):
    t += 1
if (x+r)<=W:
    t += 1
if 0<=(y-r):
    t += 1
if (y+r)<=H:
    t += 1
if t == 4:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5596
import collections

local = False
if local:
    file = open("B.txt", "r")

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

X = int(inp())

count500 = X // 500
X-=count500*500
count5 = X // 5

print(str(1000*count500+5*count5))

Measured memory_bytes: 38384
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	for (;;) {
		int N;

		cin >> N;
		if (cin.fail()) break;

		vector<ll> V(N + 10, INF);
		V[0] = 0;
		for (int i = 0; i <= N; i++) {
			if (V[i] == INF) continue;
			V[1 + i] = min(V[1 + i], V[i] + 1);
			for (int j = 6; j + i <= N; j *= 6) {
				V[j + i] = min(V[j + i], V[i] + 1);
			}
			for (int j = 9; j + i <= N; j *= 9) {
				V[j + i] = min(V[j + i], V[i] + 1);
			}
		}

		cout << V[N] << endl;
	}

	return 0;
}


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

#define INF (1 << 29)

int maps[6][2] = {
  {1, 2},
    {INF, 4},
      {1, INF},
	{5, 2},
	  {3, 5},
	    {2, 1},
};

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

  char temp[105];

  while(1){
    cin >> temp;
    if(strcmp(temp, "#") == 0) break;

    int now = 0;
    bool flag = true;
    for(int i = 0;i < strlen(temp) && flag;++i){
      if(maps[now][temp[i] - '0'] != INF){
	now = maps[now][temp[i] - '0'];
      }else{
	flag = false;
      }
    }
    
    if(now == 5 && flag){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }

  }

  return 0;
}





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

using namespace std;

int main(){
    int N;
    int K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<int> nums;
    int counter = 0;
    int now = 1;
    for(int i = 0; i < N; i++){
        if(S[i] == (char)(now + '0')) counter++;
        else{
            nums.push_back(counter);
            now = 1 - now;
            counter = 1;
        }
    } 
    if(counter != 0) nums.push_back(counter);
    if(nums.size()%2 == 0) nums.push_back(0);//最後が0カウンタならば架空の1の個数0を付け足す。1-0-1-0-1とかにしたい

    vector<int> sums(nums.size()+1);
    for (int i = 0; i < nums.size(); i++)
    {
        sums[i + 1] = sums[i]+nums[i];
    }


    int ans = 0;
    int left = 0;
    int right = 0;
    int Add = 2*K+1;
    int temp;
    for (int i = 0; i < nums.size(); i+=2)
    {
        left = i;
        right = min(i + Add, (int)nums.size());
        temp = sums[right] - sums[left];
        ans = max(ans,temp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1272
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
#define PB push_back
const int N=1e4+10;
int main(){
    int n,m,l,r,d[N],nxt;
    queue<int> q;
    vector<int> graph[N];
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)d[i]=0;
    while(m--){
        scanf("%d%d",&l,&r);
        graph[l].PB(r);
        d[r]++;
    }
    for(int i=0;i<n;i++)if(d[i]==0)q.push(i);
    while(!q.empty()){
        nxt=q.front();
        q.pop();
        printf("%d\n",nxt);
        for(int i=0;i<graph[nxt].size();i++){
            d[graph[nxt][i]]--;
            if(d[graph[nxt][i]]==0)q.push(graph[nxt][i]);
        }
    }
}


Measured memory_bytes: 3124
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

//ベルマンフォード法
//更新はN-1回で済む(N回以上かかったら負の閉路あり)
//O(NM)

int N, M, P;
int A[5000], B[5000];
LL C[5000];
LL cost[2500];
bool visited1[2500] ={}, visited2[2500] ={};
vector<int> edge1[2500], edge2[2500];

int main(){
	cin >> N >> M >> P;
	for(int i=0; i<M; i++){
		cin >> A[i] >> B[i] >> C[i];
		A[i]--; B[i]--;
		C[i] = P - C[i];
		edge1[A[i]].PB(B[i]);
		edge2[B[i]].PB(A[i]);
	}

	//bfs
	queue<int> que;
	que.push(0);
	visited1[0] = true;
	while(!que.empty()){
		for(int i=0; i<edge1[que.front()].size(); i++){
			if(!visited1[edge1[que.front()][i]]){
				que.push(edge1[que.front()][i]);
				visited1[edge1[que.front()][i]] = true;
			}
		}
		que.pop();
	}

	que.push(N-1);
	visited2[N-1] = true;
	while(!que.empty()){
		for(int i=0; i<edge2[que.front()].size(); i++){
			if(!visited2[edge2[que.front()][i]]){
				que.push(edge2[que.front()][i]);
				visited2[edge2[que.front()][i]] = true;
			}
		}
		que.pop();
	}

	for(int i=0; i<N; i++) cost[i] = LLONG_MAX/10000;
	cost[0] = 0;
	for(int i=0; i<N; i++){
		for(int j=0; j<M; j++){
			cost[B[j]] = min(cost[B[j]], cost[A[j]] + C[j]);
		}
	}
	for(int j=0; j<M; j++){
		if(visited1[B[j]] && visited2[B[j]] && cost[B[j]] > cost[A[j]] + C[j]){
			cout << -1 << endl;
			return 0;
		}
		cost[B[j]] = min(cost[B[j]], cost[A[j]] + C[j]);
	}
	cout << max(0LL, -cost[N-1]) << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNextDouble()) {
			double[] p = new double[8];
			for (int i = 0; i < 8; i++)
				p[i] = sc.nextDouble();
			System.out.println((p[4]>p[2] || p[6]<p[0] || p[5]>p[3] || p[7]<p[1])?"NO":"YES");
		}
	}
}

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

int main(){
  int N,X;
  cin >> N >> X;
  vector<int> L(N);
  for(int i=0; i<N; i++){
    cin >> L.at(i);
  }
  int D=0,i=1;
  while(D<=X&&i<=N){
    D+=L.at(i-1);
    i+=1;
  }
  if(D<=X){
    cout << N+1 << endl;
  }
  else{
    cout << i-1 << endl;
  }
}

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

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    
    int N; cin >> N;
    cout << (N + 1) / 2 << endl;
}


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

// 型名の省略
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> P;
typedef pair<lint, lint> Plint;
 
const int MOD = 1e9+7;
const int INF = 1<<18;
const lint INFLINT = 1LL<<60;
const double PI=acos(-1.0);
 
// cinとcoutの高速化
#define endl "\n"
struct cinacc{cinacc(){cin.tie(0);ios::sync_with_stdio(false);}}cinaccc;
struct coutacc{coutacc(){cout.setf(ios::fixed);cout.precision(12);}}coutaccc;
 
// 繰り返し
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define reps(i,n) for(lint i=0;i<=(lint)(n);i++)
#define rrep(i,n) for(lint i=(lint)(n)-1;i>0;i--)
#define rreps(i,n) for(lint i=(lint)(n)-1;i>=0;i--)

#define pb push_back

#define ALL(s) (s.begin(), s.end())
#define SZ(s) (s.size())

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

// Union-Find-Tree
class UnionFind {
	vector<int> par;
	UnionFind(int n):par(n){rep(i,n)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){return root(x)==root(y);}
};

// Final Weapon!
// #define int lint

int main() {
    string a, b;
    cin >> a >> b;
    for(int i = 1; pow(i, 2) <= stoi(a+b); i++) {
        if(pow(i, 2) == stoi(a+b)) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
S = input()
K = int(input())
t = 0
if S[0] != '1':
  print(S[0])
else:
  for i in range(len(S)):
    if S[i] != '1':
      t = i
      break
  if t+1 > K:
    print(1)
  else:
    print(S[t])

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
	string str;

	cin >> str;
	int ans = 0, before = -1;


	while (str.length() > 1 && ans != before ) {
		before = ans;
		for (int i = 0; i <= str.size() - 2; i++) {
			if (str[i] != str[i + 1]) {
				ans += 2;
				str.erase(str.begin() + i);
				str.erase(str.begin() + i);
				break;
			}
		}
		
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n, m;
  cin >> n >> m;
  int a, ans = 0;
  for(int i = 0; i < m; i++){
    cin >> a;
    ans += a;
  }
  if(n >= ans){
    cout << n - ans << endl;
  }else{
    cout << -1 << endl;
  }
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>

int main(void){

    int N,M,i,j,CityLoad[51],a[51],b[51];

    scanf("%d %d",&N,&M);
    for(i = 1;i <= M;i++){
        scanf("%d %d",&a[i],&b[i]);
    }
    for(i = 1;i <= N;i++){
        CityLoad[i] = 0;
    }

    for(i = 1;i <= M;i++){
        CityLoad[a[i]]++;
        CityLoad[b[i]]++;
    }

    for(i = 1;i <= N;i++) printf("%d\n",CityLoad[i]);
    return 0;
}

Measured memory_bytes: 128
from typing import List


def changes(amount: int, kind: int, coins: List[int]) -> int:

    T: List[int] = [50001] * (amount + 1)
    T[0] = 0

    for i in range(kind):
        for j in range(coins[i], amount + 1):
            T[j] = min(T[j], T[j - coins[i]] + 1)

    return T[amount]


def main() -> None:
    n, m = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]

    print(changes(n, m, c))


main()



Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
int n,a[100005],f[100004],e[100004];
int gcd(int x,int y){
	if(y==0)return x;
	return gcd(y,x%y);
}
priority_queue<int> que;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
    f[0]=a[0];
    for(int i=1;i<n;i++){
		f[i]=gcd(a[i],f[i-1]);
	}
	e[n-1]=a[n-1];
	for(int i=n-2;i>=0;i--){
		e[i]=gcd(a[i],e[i+1]);
	}
	que.push(e[1]);
	que.push(f[n-2]);
	for(int i=1;i<n-1;i++){
		que.push(gcd(f[i-1],e[i+1]));
	}
	cout<<que.top()<<endl;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

#define MAX_N 2000005
ll inv[MAX_N], fac[MAX_N], finv[MAX_N];
void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i=2; i<MAX_N; i++) {
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    fac[i] = fac[i-1] * (ll)i % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}
ll perm(ll n, ll r) {
  if(n < 0)       return 0;
  else if(n < r)  return 0;
  else            return (fac[n] * finv[n-r]) % mod;
}
ll comb(ll n, ll r) {
  ll ans = 1;
  ans = perm(n, r);
  ans = (ans * finv[r]) % mod;
  return ans;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  make();
  ll ans = 0;
  for(int k=0; k<=N; k++) {
    (ans += mod + (k%2 ? -1 : 1) * (comb(N, k) * perm(M, k) % mod * perm(M-k, N-k) % mod * perm(M-k, N-k) % mod)) %= mod;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 50456
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int temp = 0;
		int sum = 0;
		List<Integer> list = new ArrayList<Integer>();
		for(int i = 0;i < n ; i++){
			temp = sc.nextInt();
			list.add(temp);
		}
		for (int t = 0 ; t < list.size() ; t++){
			for (int s = t + 1  ; s < list.size() ;s++){
				sum += list.get(t) * list.get(s);
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
import math

def search(current, K, count, N):
  if count >= N:
    return current

  a = search(current * 2, K, count + 1, N)
  b = search(current + K, K, count + 1, N)
  return min(a, b)


def main():
  N = int(input())
  K = int(input())
  
  print(search(1, K, 0, N))


if __name__ == '__main__':
  main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
void pre(){}
void solve(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    bool flag = false;
    while(a>0 && d>0){
        c-=b;
        if(c<=0){
            flag=true;
            break;
        }
        a-=d;
        if(a<=0){
            flag=false;
            break;
        }
    }
    if(flag){
        cout<<"Yes"<<"\n";
    }else{
        cout<<"No"<<"\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T= Integer.parseInt(sc.next());
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		sc.close();

		if(A * T < B) {
			System.out.println(A * T);
		}else {
			System.out.println(B);
		}

	}
}

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

int main(){
    int n;
    while(true) {
        cin >> n;
        if(n==0) break;
        unordered_map<char,char> code;
        for(int i=0; i<n; ++i){
            char key,val;
            cin >> key >> val;
            code[key]=val;
        }
        int m;
        cin >> m;
        for(int i=0; i<m; ++i){
            char c;
            cin >> c;
            if(code.find(c)!=code.end()) {
                cout << code[c];
            } else {
                cout << c;
            }
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3016
from collections import Counter
import math

def main():
    r=2
    def comb2(n):
        if n < 2:
            return 0
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    
    N = int(input())
    A = list(map(int, input().split()))
    
    count = Counter(A)
    
    all_c = sum([comb2(count[i]) for i in count])
    
    for b in A:
        print(all_c - (count[b]-1))
    
if __name__ == "__main__":
    main()


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

		ll g(int64_t x){
          if(x==-1){
            return 0; 
          }else{
                ll y=0; 
                if(x%2==0) y+= (x/2)*2; 
                if(x%4==1||x%4==2) y+=1;
                return y; 
          }
        }

        int main() {
          ll A,B;
          cin>> A>>B;  
          
          bitset<42> s(g(A-1));
          bitset<42> t(g(B)); 
          bitset<42> u = s^t; 
          
          ll S=0;
          ll c=1;
          for(int i=0; i<41; i++){
            if(u.test(i)) S= S+ c ; 
            c*=2; 
          }
          
          cout<< S; 

        }

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

using namespace std;

#define F first
#define S second
typedef long long ll;
typedef pair<char, ll> P;

int main()
{
    ll len[3];    
    vector<P> X[3];
    for (int i = 0; i < 3; i++) {
        char c;
        ll l;
        while (cin >> c, c != '$') {
            cin >> l;
            X[i].push_back(P(c, l));
        }
        len[i] = X[i].size();
    }
    for (int i = 0; i <= len[0]-len[1]; i++) {
        bool same = 1;
        for (int j = i; j < i+len[1]; j++) {
            if (X[1][j-i].F != X[0][j].F ||
                (i < j && j < i+len[1]-1 && X[1][j-i].S != X[0][j].S)) {
                same = 0;
                break;
            }
        }
        if (X[0][i].S < X[1][0].S || X[0][i+len[1]-1].S < X[1][len[1]-1].S) {
            continue;
        }

        if (same) {
            vector<P> v, res;
            for (int j = 0; j < i; j++) {
                v.push_back(X[0][j]);
            }
            ll diff = X[0][i].S - X[1][0].S;
            if (len[1] != 1) {
                if (diff > 0) {
                    v.push_back(P(X[0][i].F, diff));      
                }
                for (int j = 0; j < len[2]; j++) {
                    v.push_back(X[2][j]);
                }
                diff = X[0][i+len[1]-1].S - X[1][len[1]-1].S;
                if (diff > 0) {
                    v.push_back(P(X[0][i+len[1]-1].F, diff));
                }
            } else {
                for (int j = 0; j < len[2]; j++) {
                    v.push_back(X[2][j]);
                }                
                if (diff > 0) {
                    v.push_back(P(X[0][i].F, diff));   
                }
            }
            for (int j = i+len[1]; j < len[0]; j++) {
                v.push_back(X[0][j]);
            }
            
            for (int j = 0; j < (int)v.size(); ) {
                ll k = j, sum = 0;
                while (k < (ll)v.size() &&
                       v[j].F == v[k].F) {
                    sum += v[k].S;
                    k++;
                }
                res.push_back(P(v[j].F, sum));
                j = k;
            }
            X[0] = res;
            break;
        }
    }
    for (int i = 0; i < X[0].size(); i++) {
        cout << X[0][i].F << " " << X[0][i].S << " ";
    }
    cout << "$" << endl;
    return 0;
}

Measured memory_bytes: 1332
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  ll n,sum=0;
  cin >> n;
  rep(i,1,n+1){
    if(i%3 && i%5){
      sum+= i;
    }
  }
  cout << sum;
}


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

int main()
{
  int a,b,c,sleep[10000]={0};

  cin>>a>>b>>c;
  if(a+b==60&&a<c){
    cout<<"-1"<<endl; return 0;
  }
  for(int i=0;i<9000;i+=(a+b))
    for(int j=i;j<=(i+a);j++)
      sleep[j]=1;
  for(int i=c;i<10000;i+=60)
    if(sleep[i]){
      cout<<i<<endl; return 0;
    }
  cout<<"-1"<<endl;
}


Measured memory_bytes: 1208