akhauriyash/Code-Regression huggingface dataset:
/*#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define ll long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;*/

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

#define LL long long
#define ll long long

const LL MOD=1e9+7;
const int maxn=1e5+10;

//const int INF=0x7ffffff;
//const int magic=348;
//const int zero=200;

int n;
//LL p,p1;
LL id1,id2;
LL a[100048];
int v[100048];
int cnt[100048];

LL fac[100048],finv[100048],inv[100048];

void make()
{
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<100010;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]* i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C(int x,int y)
{
	if(x<y) return 0;
	return fac[x]*(finv[y]*finv[x-y]%MOD)%MOD;
}

int main ()
{
	//LL i;
	//cin>>n;
	/*memset(cnt,0,sizeof(cnt));
	for (i=1;i<=n+1;i++)
	{
		cin>>a[i];
		cnt[a[i]]++;
	}
	p=p1=0;
	for (i=1;i<=n+1;i++)
		if (cnt[a[i]]==2)
			if (p1==0) p1=i; else p=i;*/
	/*	memset(a, 0, sizeof(a));
    memset(v, 0, sizeof(v));
    for(ll i = 1; i <= n + 1; ++i){
        cin >> a[i];
        v[a[i]]++;
    }
    for(ll i = 1; i <= n + 1; ++i){
        if(v[a[i]] == 2 && !id1){
            id1 = i;
        }
        else if(v[a[i]] == 2) {
            id2 = i;
        }
    }
	LL ans;
	make();
	LL L=max(id1-1,0LL),R=max(n+1-id2,0LL);
	for (ll i=0;i<=n;i++)
	{
		ans=C(n+1,(i+1)*1LL);
		ans-=C(L+R,i*1LL);
		if (ans<0) ans+=MOD;
		cout<<ans<<endl;
	}
	return 0;*/
	ll n;
    make();
    ll id1 = 0, id2 = 0;
    cin >> n;
    memset(a, 0, sizeof(a));
    memset(v, 0, sizeof(v));
    for(ll i = 1; i <= n + 1; ++i){
        cin >> a[i];
        v[a[i]]++;
    }
    for(ll i = 1; i <= n + 1; ++i){
        if(v[a[i]] == 2 && !id1){
            id1 = i;
        }
        else if(v[a[i]] == 2) {
            id2 = i;
        }
    }
    ll L = max(id1 - 1LL, 0LL), /*M = id2 - id1 - 1LL*/ R = max(n + 1LL - id2, 0LL);
    ll res = 0;
    for(ll i = 1; i <= n + 1; ++i){
        res = C(n + 1, i * 1LL);
        res -= C(L + R, (i - 1) * 1LL);
        if(res < 0)res += MOD;
        cout << res << '\n';
    }
    return 0;
}

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

int main()
{
  int H, W;
  cin >> H >> W;
  
  string S;
  char s;
  
  for(int i = 0; i < H + 2; i++)
  {
    if(i == 0 || i == H + 1)
    {
      for(int j = 0; j < W + 2; j++)
      {
        S += "#";
      }
      cout << S << endl;
    }
    else
    {
      S += "#";
      for(int j = 0; j < W; j++)
      {
        cin >> s;
        S += s;
      }
      S += "#";
      cout << S << endl;
    }
    S = "";    
  }
}

Measured memory_bytes: 3640
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ViewPatterns          #-}
module Main where
import Data.Function
import Data.List as List
import Data.Char as Char
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as B8

main :: IO ()
main = do
  n:k:_ <- readInts
  let d = (n - 1) * (n - 2) `div` 2 - k;
  if d < 0
    then print (-1)
    else do
    print $ (n - 1) + d
    mapM_ (\(l,r) -> putStrLn $ show l ++ " " ++ show r)
      $ [(1,r)| r <- [2..n]]
    mapM_ (\(l,r) -> putStrLn $ show l ++ " " ++ show r)
      $ take d $ [(l,r) | l <- [2 .. n], r <- [l+1 .. n]]

readInts :: IO [Int]
readInts = List.unfoldr (B8.readInt . B8.dropWhile isSpace) <$> BS.getLine


Measured memory_bytes: 1020
#include<iostream>
using namespace std;
int c1,c2,c3,c4,c5,c6,sum,flag;
int in(){
cin>>c1>>c2>>c3>>c4>>c5>>c6;
}
int com(){
sum+=c1+c2*5+c3*10+c4*50+c5*100+c6*500;
if(sum>=1000)
flag=1;
else
flag=0;
}
int out(){
cout<<flag<<endl;
}
int main(){
in();
com();
out();
}

Measured memory_bytes: 1160
n = int(input())
slist = [input() for _ in range(n)]
sset = set(slist)
m = int(input())
tlist = [input() for _ in range(m)]

ans = 0
for s in sset:
	if slist.count(s)>tlist.count(s):
		ans =max(ans,slist.count(s)-tlist.count(s))
print(ans)

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

const int N = 105;
const int INF = 1e18;
int dp[N][N];

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

    rep(i,N) rep(j,N) {
        if(i == j) dp[i][j] = 0;
        else dp[i][j] = INF;
    }
    for(int i = 0; i < m; i++){
        int a,b,c;
        cin >> a >> b >> c;
        dp[a][b] = c;
    }
    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            for (int j = 0; j < n; j++) {
                if(dp[i][k] != INF && dp[k][j] != INF) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
    bool flag = true;
    for(int i = 0 ; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j && dp[i][j] < 0) flag = false;
        }
    }

    if(!flag) cout << "NEGATIVE CYCLE" << endl;
    else {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(dp[i][j] == INF) cout << "INF";
                else cout << dp[i][j];

                if(j == n - 1) cout << endl;
                else cout << " ";
            }
        }
    }

}


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

int main(){
  
  long long n,m;
  cin>>n>>m;
  if(n==1&&m==1) cout<<1<<endl;
  else if(n==1||m==1) cout<<n*m-2<<endl;
  else if(n==2||m==2) cout<<0<<endl;
  else cout<<(n-2)*(m-2)<<endl;
}

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

void swap(int &a, int &b){
	int dum = a;
	a = b;
	b = dum;
	return;
}

void swap(char &a, char &b){
	char dum = a;
	a = b;
	b = dum;
	return;
}

int main(){
	int n, minj;
	cin >> n;
	vector<int> a(n), b(n);
	vector<char> s(n), t(n);
	for (int i = 0; i != n; i++){
		cin >> s[i] >> a[i];
		t[i] = s[i];
		b[i] = a[i];
	}

	int unsorted, flag, isstable;

	unsorted = 0;
	flag = 1;
	while (flag){
		flag = 0;
		for (int j = n - 1; j != unsorted; j--){
			if (a[j - 1] > a[j]){
				swap(a[j - 1], a[j]);
				swap(s[j - 1], s[j]);
				flag = 1;
			}
		}
		unsorted++;
	}

	for (int i = 0; i != n; i++) cout << (i == 0 ? "" : " ") << s[i] << a[i];

	cout << endl << "Stable" << endl;

	for (int i = 0; i != n; i++){
		minj = i;
		for (int j = i; j != n; j++){
			if (b[j] < b[minj]){
				minj = j;
			}
		}
		if (minj != i){
			swap(b[i], b[minj]);
			swap(t[i], t[minj]);
		}
	}
	
	for (int i = 0; i != n; i++) cout << (i == 0 ? "" : " ") << t[i] << b[i];

	isstable = 0;
	for (int i = 0; i != n; i++) if (s[i] != t[i]) isstable = 1;

	cout << endl << (isstable == 0 ? "Stable" : "Not stable") << endl;

}


Measured memory_bytes: 3116
#include<cstdio>//aoj515 School Road
#include<algorithm>
#include<functional>
using namespace std;
void func(int,int);
int cnt,a,b,n,kouzi[17][17];
int main(void)
{
	int i,j,x,y;
	while(1){
		scanf("%d %d",&a,&b);
		if(a==0 && b==0) break;
		scanf("%d",&n);
		for(i=1;i<=b;i++){
			for(j=1;j<=a;j++){
				kouzi[i][j]=0;
			}
		}
		for(i=0;i<n;i++){
			scanf("%d %d",&x,&y);
			kouzi[y][x]=1;
		}
		cnt=0;
		func(1,1);
		printf("%d\n",cnt);
	}
}
void func(int yy,int xx)
{
	if(yy==b && xx==a){
		cnt++;
	}
	else{
		if(xx+1<=a && kouzi[yy][xx+1]==0){
			func(yy,xx+1);
		}
		if(yy+1<=b && kouzi[yy+1][xx]==0){
			func(yy+1,xx);
		}
	}
}


Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main() {
	int a, b, c, y, i, j;
	cin >> a >> b >> c;
	y = 0;
	j = 0;
	i = a;
	if (a>b) {
		return -1;
	}
	while (i <= b) {
		y = c % i;
		if (y == 0) {
			j++;
		}
		i++;
	}
	cout << j << endl;
	return 0;
}

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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 998244353;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);


    ll n, s;
    cin >> n >> s;
    vector<int> dp(s+1);
    dp[0] = 1;
    for(ll i=1; i<=n; i++) {
        ll a;
        cin >> a;
        vector<int> pre = dp;
        for(ll j=0; j<=s; j++) {
            (dp[j] = pre[j] * 2) %= MOD;
            if(j-a>=0)
                (dp[j] += pre[j-a]) %= MOD;
        }
    }
    cout << dp[s] << endl;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  vl a(N);
  ll tot = 0;
  rep(i, N){
    cin >> a[i];
    tot += a[i];
  }

  ll cum = 0;
  ll ans = (ll)pow(10, 16);

  rep(i, N - 1){
    cum += a[i];
    ans = min(ans, abs(cum - (tot - cum)));
  }

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


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
		public static void main(String[] args)throws IOException {
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String[] str=br.readLine().split(" ");
			
			double x1=Double.parseDouble(str[0]);
			double y1=Double.parseDouble(str[1]);
			double x2=Double.parseDouble(str[2]);
			double y2=Double.parseDouble(str[3]);
			double dist=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
			System.out.printf("%.8f",dist);
		}

}

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

string s, ans;

int main()
{
    cin >> s;
    for(int i = 0; i < s.size(); i++)
        if((s[i] == 'K' || s[i] == 'B' || s[i] == 'R') && (i == 0 || s[i - 1] != 'A'))
            ans.push_back('A'), ans.push_back(s[i]);
        else
            ans.push_back(s[i]);
    if(s[s.size() - 1] != 'A')
        ans.push_back('A');
    printf(ans == "AKIHABARA" ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Data.List

main :: IO ()
main = solve <$> f >>= print
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> Int
solve [a, n, m] = length . filter g . takeWhile ((<= m) . snd) $ map f [1..]
  where
    f y = (y, (y + a) ^ n)
    g (y, x) = (== y) . sum $ unfoldr h x
    h a = if a == 0 then Nothing else let (q, r) = divMod a 10 in Just (r, q)



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

int main() {
  char s;
  cin >> s;
  if(s == 'A') {
    cout << "T";
  }else if(s == 'T') {
    cout << "A";
  }else if(s == 'G') {
    cout << "C";
  }else{
    cout << "G";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 998244353LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,s;
  cin>>n>>s;
  vll a(n);
  rep(i,n) cin>>a[i];
  vvll dp(n+1,vll(s+1,0));
  dp[0][0]++;
  rep(i,n)rep(j,s+1){
    dp[i+1][j]+=2*dp[i][j];
    dp[i+1][j]%=MOD;
      if(s>=j+a[i]){
      dp[i+1][j+a[i]]+=dp[i][j];
      dp[i+1][j+a[i]]%=MOD;
    }
  }
  COUT(dp[n][s]);
}

Measured memory_bytes: 73660
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=1e5+9,mod=1e9+7;
	inline int add(int x,int y){return x+y>=mod?x-mod+y:x+y;}
	inline int sub(int x,int y){return x>=y?x-y:x+mod-y;}
	int f[N],n,nxt[N][3],sum[N],ans;char s[N];
	int main(){
		scanf("%s",s+1),n=strlen(s+1);
		int peg=0;
		for(int i=1;i<n;i++) if(s[i]==s[i+1]){peg=1;break;}
		if(!peg) puts("1"),exit(0);
		for(int i=1;i<=n;i++) sum[i]=(sum[i-1]+(s[i]=='a'?1:2))%3;
		for(int j=0;j<3;j++) nxt[n][j]=n+1;
		for(int i=n-1;i>=0;i--){
			for(int j=0;j<3;j++) nxt[i][j]=nxt[i+1][j];
			nxt[i][sum[i+1]]=i+1;
		}
		f[0]=1;
		for(int i=0;i<n;i++){
			for(int j=1;j<3;j++) f[nxt[i][(sum[i]+j)%3]]=add(f[i],f[nxt[i][(sum[i]+j)%3]]);
			if(i && sum[n]==sum[i]) ans=add(ans,f[i]); 
		}
	//	for(int i=1;i<=n;i++) cout<<f[i]<<" ";cout<<endl;
		printf("%d\n",add(ans,f[n]));
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

const ll mod = 998244353;

const ll INF = 1e15;

int main() {
	ll n,k;
	cin >> n >> k;
	vector<ll> vs(n + k + 1, 0);
	rep(i, n) cin >> vs[i];
	vector<ll> dp(n + k + 1, INF);
	dp[0] = 0;
	rep(i, n) {
		rep(j, k + 1) {
			dp[i + j] = min(dp[i + j], dp[i] + abs(vs[i + j] - vs[i]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1792
fun main(arg: Array<String>) {
    val (K, N) = listOfInt()
    val A = listOfInt().toMutableList()
    A.add(A[0] + K)
    val C = IntArray(N)
    for (n in 0 until N) C[n] = A[n + 1] - A[n]
//System.err.println(C.joinToString())
    var ans = C.sum() - C.max()!!
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun listOfLong(delta: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + delta }
fun listOfDouble(delta: Double = 0.0) = listOfString().map { java.lang.Double.parseDouble(it) + delta }
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfDouble() = listOfString().map(String::toDouble)


Measured memory_bytes: 83044
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;

int main(){
  int N; cin >> N;
  vector<vector<int>> kuku (9, vector<int>(9, 0));
  bool flag = false;
  for(int i = 1; i<=9; i++){
    for(int j = 1; j<=9; j++){
      kuku.at(i-1).at(j-1) = i * j;
      if(N == kuku.at(i-1).at(j-1)) flag = true;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
cnt = 0
ans = 0
for a,b in ab:
  cnt += b
  ans += a * b
  if cnt >= m:
    if cnt > m: ans -= a * (cnt-m)
    break
print(ans)

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

using   namespace       std;

int     main() {
        int N;
        cin >> N;
        vector<int> d(N);
        for (int i=0; i<N; i++) cin >> d.at(i);
        sort(d.begin(), d.end());
        int n=N/2;
        int s=d.at(n)-d.at(n-1);
        cout << s << endl;
        return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=998244353 ;



vector<ll> inv,fact,invfact;
void mod_build(int n=101010){
    fact.resize(n+1);
    inv.resize(n+1);
    invfact.resize(n+1);
    fact[0]=inv[0]=invfact[0]=1;
    inv[1]=1;
    rep(i,n){
        fact[i+1]=fact[i]*(i+1)%mod;
        if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
}
ll perm(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
    k%=mod-1;
    if(k<0)k+=mod-1;
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

ll dp[3030][3030],dpx[3030][3030],dpy[3030][3030], p[3030][3030], ip[3030][3030];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    mod_build();
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    dp[a][b]=1;
    dpx[a][b]=dp[a][b]*powmod(a+1,mod-1-b)%mod*b%mod;
    dpy[a][b]=dp[a][b]*powmod(b+1,mod-1-a)%mod*a%mod;
    REP(i,1,3030)rep(j,3030){
        if(j==0)p[i][j]=ip[i][j]=1;
        else {
            p[i][j]=p[i][j-1]*i%mod;
            ip[i][j]=ip[i][j-1]*inv[i]%mod;
        }
    }

    for(int i=a;i<=c;i++)for(int j=b;j<=d;j++){
        if(i==a&&j==b)continue;
        if(i==a){
            dp[i][j]=dp[i][j-1]*i%mod;
        } else if(j==b){
            dp[i][j]=dp[i-1][j]*j%mod;
        } else {
            dp[i][j]+=dpx[i-1][j-1]*p[i][j-1]%mod;
            dp[i][j]+=dpy[i-1][j-1]*p[j][i-1]%mod;
            dp[i][j]+=dp[i-1][j-1]*(i-1)*(j-1)%mod;
            dp[i][j]%=mod;
        }
        dpx[i][j]=(dpx[i][j-1]+dp[i][j]*ip[i+1][j]%mod*j)%mod;
        dpy[i][j]=(dpy[i-1][j]+dp[i][j]*ip[j+1][i]%mod*i)%mod;
    }
    cout<<dp[c][d]<<endl;
    return 0;
}

Measured memory_bytes: 361856
#B問題
N = int(input())
XY = [list(map(int,input().split())) for i in range(N)]
edges = []
for i in range(N):
    x1,y1 = XY[i][0],XY[i][1]
    for j in range(N-i-1):
        J = i+j+1
        x2,y2 = XY[J][0],XY[J][1]
        dx = x2-x1
        dy = y2-y1
        if dx <= 0:
            if dx == 0:
                if dy < 0:
                    dy = -dy
            else:
                dx = -dx
                dy = -dy
        edges.append([dx,dy])

listcount = []
count = []
if N == 1:
    listcount.append([0,0])
    count.append(1)

for edge in edges:
    if edge == [0,0]:
        if [0,0] not in listcount:
            listcount.append([0,0])
            count.append(1)
    elif edge in listcount:
        count[listcount.index(edge)]+=1
    else:
        listcount.append(edge)
        count.append(1)
        
most = max(count)
if N == 1:
    print(1)
else:
    print(N-most)


Measured memory_bytes: 3188
def ynf(dt,dx,dy):
#    print(dt,dx,dy)
    if (dx+dy)>dt:
        return 0
    if (dx+dy)%2 != dt%2:
        return 0
    return 1

icase=0
if icase==0:
    n=int(input())
    txy=[]
    for i in range(n):
        txy.append(list(map(int,input().split())))
elif icase==1:
    n=2
    txy=[]
    txy.append([3, 1, 2])
    txy.append([6, 1, 1])
elif icase==2:
    n=1
    txy=[]
    txy.append([2, 100, 100])
elif icase==3:
    n=2
    txy=[]
    txy.append([5, 1, 1])
    txy.append([100, 1, 1])

dt=txy[0][0]
dx=txy[0][1]
dy=txy[0][2]

yn=1
for i in range(n):
    if ynf(dt,dx,dy)==0:
        yn=0
        break
    elif i==n-1:
        break
    else:
        dt=txy[i+1][0]-txy[i][0]
        dx=txy[i+1][1]-txy[i][1]
        dy=txy[i+1][2]-txy[i][2]
        
if yn==0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 27324
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int gcd(int a, int b)
{

    if(b == 0) {
            return a;
    }
    else {
        return gcd(b, a % b);
    }
}
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
        cin>>a[i];
    int x=a[0];
    for(int i=1;i<n;++i)
    {
        x=gcd(x,a[i]);
    }
    cout<<x;

}



Measured memory_bytes: 640
n, m = gets.strip.split.map(&:to_i)
list = [0] * m

n.times do
    ans = gets.strip.split.map(&:to_i)
    ans.shift
    ans.each do |a|
        list[a - 1] += 1
    end
end

cnt = list.select { |item| item == n }.size

puts cnt


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

int main(){
    string s;
    cin >> s;
    int n = s.length();
    int ans = n;
    for(int i = 0; i < n-1; i++){
        if(s[i] != s[i+1])  ans = min(ans, max(i+1, n-(i+1)));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
//Sourav Mondal

#include <bits/stdc++.h>
using namespace std;
#define llt long long int

int main() {
	char x;
	cin>>x;
	if((int)x<(int)'a'+26&&(int)x>(int)'A'+26)
	cout<<"a"<<endl;
	else
	cout<<"A"<<endl;
    return 0;
}


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

void func149b() {
  long long a, b, k;
  cin >> a >> b >> k;
  if (k <= a) {
    cout << a - k << " " << b << "\n";
  } else if (k <= a + b) {
    cout << "0 " << b - (k - a) << "\n";
  } else {
    cout << "0 0\n";
  }
}


int main() {
  func149b();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a;
  int b=0;
  char s[3];
  scanf("%s",&s);
  
  for(a=0;a<=3;a=a+1){
    if(s[a]=='1'){
      b=b+1;
    }
    
    else{
      b=b;
    }
  }
  printf("%d\n",b);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(string, s);

  int i, j;
  for (i = 0; i < sz(s); ++i)
    if (s[i] == 'A') break;

  for (j = 0; j < sz(s); ++j)
    if (s[sz(s) - 1 - j] == 'Z') break;

  j = sz(s) - 1 - j;

  // printf("%d ~ %d\n", i, j);
  cout << j - i + 1 << endl;

  return 0;
}

Measured memory_bytes: 640
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  N = readint()[1]

  n = 0
  a = []
  while N>0
    append!(a,[(N-1)%26 + 1])
    N = (N-1)÷26
    n+=1
  end
  
  for i in n:-1:1
    print('a'+a[i]-1)
  end
  println()
end

main()

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

vector<int64_t> fact, fact_inv;

void create_mod_tables(int num){
    fact.assign(num+1, 1);
    fact_inv.assign(num+1, 1);
    for(int i=1; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
    fact_inv[num] = inv_mod(fact[num]);
    for(int i=num; i>0; i--) fact_inv[i-1] = fact_inv[i] * i % MOD;
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int main(){
    int N, M;
    cin >> N >> M;
    create_mod_tables(1e6);

    int64_t ans = 0;
    for(int i=0; i<=N; i++){
        int64_t res = comb_mod(N, i) * perm_mod(M, i) % MOD;
        mul(res, power_mod(perm_mod(M-i, N-i), 2));
        add(ans, i%2 ? MOD-res : res);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 18764
def main():
  n, p = map(int, input().split()) 
  s = input() 

  ans = 0

  if p == 2:
    for i, si in enumerate(s):
      if int(si) % 2 == 0:
        ans += (i+1)
    print(ans)
    exit()

  if p == 5:
    for i, si in enumerate(s):
      if int(si) % 5 == 0:
        ans += (i+1)
    print(ans)
    exit()

  rem_list = [0] * p
  cof = 1
  prev_rem = 0
  
  for i in range(n):
    rem = (int(s[n-1-i]) * cof + prev_rem) %  p
    ans += rem_list[rem]
    if rem == 0:
      ans += 1      
    rem_list[rem] += 1

    prev_rem = rem
    cof *= 10
    cof %= p

  print(ans)

if __name__ == "__main__":
  main()

Measured memory_bytes: 3500
#include<stdio.h>

int main(void){

  int N, K;
  char S[51];

  scanf("%d %d",&N,&K);
  scanf("%s",&S);

  if(S[K - 1] == 'A'){
    S[K - 1] = 'a';
  }else if(S[K - 1] == 'B'){
    S[K - 1] = 'b';
  }else if(S[K - 1] == 'C'){
    S[K - 1] = 'c';
  }


  printf("%s" , S);


  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
using namespace std;

int INF = 1e9 + 7;

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

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

	if (abs(c - a) <= d || (abs(a - b) <= d) && (abs(b - c) <= d)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String X = sc.next();
        int Y = sc.nextInt();
        int T = 0;
        String STR = "";

        char[] c = X.toCharArray();

        for(char c1 : c) {
            T++;
            if(T == 1){
                STR = STR + c1;
            }
            if(T == Y){
                T = 0;
            }
        }

        System.out.println(STR);
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#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 n, m;
    cin >> n;
    //現在持っている問題の難易度
    map<int, int> mp_d;
    rep(i,n) {
        int D;
        cin >> D;
        mp_d[D]++;
    }
    cin >> m;
    //必要な問題の難易度
    vector<int> T(m);
    map<int, int> mp_t;
    rep(i,m) {
        cin >> T[i];
        mp_t[T[i]]++;
    }

    for (int i = 0; i < m; i++)
    {
        if (mp_t[T[i]] > mp_d[T[i]]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 22716
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}

int main(){
  fastIO();
  ll x;
  cin>>x;
  for(int i=-1000;i<=1000;i++){
    for(int j=-1000;j<=1000;j++){
      ll ans = pow(i,5)-pow(j,5);
      if(ans==x){
        cout<<i<<" "<<j<<endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

template <typename T>
class SegTree {
private:
    int n;
    vector<T> data;
    T id;
    function<T(T, T)> update;
    function<T(T, T)> merge;

    T _query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return id;
        if(a <= l && r <= b) return data[k];
        
        T vl = _query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = _query(a, b, 2 * k + 2, (l + r) / 2, r);
        return merge(vl, vr);
    }

public:
    SegTree(int _n, T _id, function<T(T, T)> _update, function<T(T, T)> _merge)
    : id(_id), update(_update), merge(_merge) {
        n = 1;
        while(n < _n) n <<= 1;
        data = vector<T>(2 * n - 1, id);
    }

    void change(int k, T x) {
        k += n - 1;
        data[k] = update(data[k], x);
        while(k > 0) {
            k = (k - 1) / 2;
            data[k] = merge(data[2 * k + 1], data[2 * k + 2]);
        }
    }

    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    T operator[](int k) {
        return data[k + n - 1];
    }
};

const int MOD = 998244353;
static const int n_max = 200000;
vector<int> powtwo;

void powtwoinit(int N) {
    powtwo.resize(N + 1);
    powtwo[0] = 1;
    for(int i=1; i<=N; ++i) {
        powtwo[i] = powtwo[i - 1] * 2 % MOD;
    }
}

int main() {
    int N;
    cin >> N;
    vector<P> x(N), y(N);
    for(int i=0; i<N; ++i) {
        int a, b;
        cin >> a >> b;
        x[i] = P(a, i);
        y[i] = P(b, i);
    }
    sort(begin(x), end(x));
    sort(begin(y),end(y));
    vector<P> point(N);
    for(int i=0; i<N; ++i) {
        point[x[i].second].first = i;
        point[y[i].second].second = i;
    }
    sort(begin(point), end(point));

    SegTree<int> done(N, 0, plus<int>(), plus<int>());
    SegTree<int> undone(N, 0, plus<int>(), plus<int>());
    for(int i=0; i<N; ++i) undone.change(i, 1);

    int res = 0;
    powtwoinit(N);
    for(P p : point) {
        int y = p.second;
        done.change(y, 1);
        undone.change(y, -1);

        vector<int> num(4);
        num[0] = undone.query(y + 1, N);
        num[1] = done.query(y + 1, N);
        num[2] = done.query(0, y);
        num[3] = undone.query(0, y + 1);

        long long tmp = powtwo[N] - 1;
        for(int i=0; i<4; ++i) {
            tmp = (tmp - powtwo[num[i] + num[(i + 1) % 4]] + MOD) % MOD;
            tmp = (tmp + powtwo[num[i]]) % MOD;
        }
        res = (res + tmp) % MOD;
    }
    cout << res << endl;
}

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
  ll n;
  cin >> n;

  COUT(n*n*n);
}

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

/*

3 2
*/


Measured memory_bytes: 256
#include "bits/stdc++.h"
using ll = long long;
using namespace std;


void solve() {
   int n, x, ans = 0;
   cin >> n;
   for(int i = 1; i <= n; i++) {
      cin >> x;
      ans += (i % 2 == 1) && (x % 2 == 1);
   }
   cout << ans << endl;
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e15;
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }

  ll ans = INF;
  REP(j, 2) {
    ll sum = 0, cnt = 0;

    if (j == 0) {
      REP(i, n) {
        sum += a[i];
        if (i % 2 == 0) {
          if (sum > 0) continue;
          cnt += 1 - sum;
          sum = 1;
        } else {
          if (sum < 0) continue;
          cnt += 1 + sum;
          sum = -1;
        }
      }
      ans = min(ans, cnt);
    } else {
      REP(i, n) {
        sum += a[i];
        if (i % 2 == 0) {
          if (sum < 0) continue;
          cnt += 1 + sum;
          sum = -1;
        } else {
          if (sum > 0) continue;
          cnt += 1 - sum;
          sum = 1;
        }
      }
      ans = min(ans, cnt);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int n,m;
  n=max(a,b)-min(a,b);
  m=max(b,c)-min(b,c);
  bool ok=false;
  if((max(a,c)-min(a,c))<=d){
    ok=true;
  }
  else if(n<=d && m<=d){
    ok=true;
  }
  if(ok){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


signed main() {
    int N;
    int W[110];
    cin >> N;
    int S = 0;
    rep(i, N) {
        cin >> W[i];
        S += W[i];
    }
    int S1 = 0;
    int S2 = S;
    int ans = INF;
    for (int T = 0; T < N; ++T) {
        S1 += W[T];
        S2 -= W[T];
        ans = min(ans, abs(S1 - S2));
    }
    cout << ans << endl;
    return 0;
}


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

class Dijkstra {
public:
    struct edge { long long v, dist; };

    struct state {
        long long v, cost;
        bool operator>(const state s) const { return cost > s.cost; }
    };

    const long long INF = (1LL << 60);
    long long N;
    vector< vector<edge> > E;

    Dijkstra(long long n): N(n), E(n) {}

    //有効グラフの時はこっち。u→vに距離dで結ぶ
    void add_directed_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
    }

    //無向グラフの時はこっち。uとvを双方向に距離dで結ぶ
    void add_undirected_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
        E[v].push_back((edge) { u, d });
    }

    //Sを始点として、他の頂点への最短経路を探す
    vector<long long> shortest_path(long long S) {
        vector<long long> dp(E.size(), INF);
        priority_queue<state, vector<state>, greater<state> > q;
        q.push((state) { S, 0 });
        while(!q.empty()) {
            long long v = q.top().v, cost = q.top().cost;
            q.pop();
            if(dp[v] <= cost) continue;
            dp[v] = cost;
            for(int i=0;i < E[v].size() ; i++) {
            long long nv = E[v][i].v, ncost = cost + E[v][i].dist;
            if(dp[nv] > ncost) q.push((state) { nv, ncost });
            }
        }
        return dp;
    }
};


signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    ll n,m,s,t;
    cin>>n>>m>>s>>t;
    Dijkstra dij(n+1);
    for(int i=0;i<m;i++){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        dij.add_undirected_edge(a,b,d);
        dij.add_undirected_edge(b,c,d);
        dij.add_undirected_edge(c,a,d);
    }
    ll ans = dij.shortest_path(s)[t];
    cout << ans << endl;
    
}


Measured memory_bytes: 27508
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code)]
fn remove_whitespace(s: &str) -> String {
    s.chars().filter(|c| !c.is_whitespace()).collect()
}

#[allow(unused_imports)]
use std::io::{stdout, Write};
fn main() {
    let n: usize = read();
    let mut v: Vec<(f64, f64)> = Vec::new();
    for _i in 0..n {
        v.push(read_two::<f64>());
    }
    let mut sum = 0.0;
    for i in 0..n {
        for j in i..n {
            sum += ((v[i].0 - v[j].0).powf(2.0) + (v[i].1 - v[j].1).powf(2.0)).sqrt();
        }
    }
    println!("{}", sum * 2.0 / n as f64);
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct dis{
    int d, p;
};
bool s(dis const& c,dis const&b){
    return c.p>b.p;
}
int n,m,a;
vector<dis>vec;
int main(){
    while(cin>>n>>m,n){
        vec.clear();
        a=0;
        for(int i=0;i<n;i++){
            dis d;
            cin>>d.d>>d.p;
            vec.push_back(d);
        }
        sort(vec.begin(),vec.end(),s);
        for(int i=0;i<n;i++){
            if(m<vec[i].d){
                a+=(vec[i].d-m)*vec[i].p;
            }
            m=max(0,m-vec[i].d);
        }
        cout<<a<<endl;
    }
    return 0;
}

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


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

    double d,t,s;
    cin >> d >> t >> s;
    
    if ((d / s) <= t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3736
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		long h = cin.nextLong();
		long w = cin.nextLong();
		long ans = Math.min(func1(h, w), func2(h, w));
		ans = Math.min(ans, func2(w, h));
		System.out.println(ans);
	}

	public static long func1(long h, long w){
		if(h % 3 == 0 || w % 3 == 0){
			return 0;
		}
		return Math.min(h, w);
	}

	public static long func2(long h, long w){
		long min_dif = h * w ;
		if(w % 2 == 0) {
			for (long i = 1; i < h; ++i ) {
				min_dif = Math.min(Math.abs(w * i - w / 2 * (h - i)), min_dif );	
			}
		} else {
			for (long i = 1; i < h; ++i ) {
				long max_dif = Math.max(Math.abs( (w+1) / 2 * (h - i) - w / 2 * (h - i)) , Math.max(Math.abs(w * i - w / 2 * (h - i)), Math.abs(w * i - (w+1) / 2 * (h - i))));
				min_dif = Math.min(max_dif, min_dif);
			}
		}
		return min_dif;
	}
}

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


void solve(long long N, std::string S){
    char now=S[0];
    int a=0;
    rep(i,N){
        if(i>0 and S[i]!=now){
            a++;
            now=S[i];
        }
    }
    cout<<a+1<<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(){
    std::cout<<std::fixed<<std::setprecision(10);//誤差小数10桁まで
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, a[100001];
int main() {
  cin >> n; read_n(a, n, 1);
  lli ans = 0, p = 0;
  for (lli i=1; i<=n; ++i) {
    ans += a[i] / 2;
    if (a[i] % 2 == 1) {
      if (p == 1) { ++ans; p = 0; }
      else p = 1;
    } else if (a[i] == 0) {
      p = 0;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1024
class Solution:

    def solve(self, N: int, K: int) -> int:

        if K == 0:
            return N**2

        answer = 0
        for b in range(K+1, N+1):

            answer += (N//b) * (b-K) + max(N % b-K+1, 0)

        return answer


if __name__ == '__main__':

    # standard input
    N, K = map(int, input().split())
    # solve
    solution = Solution()
    print(solution.solve(N, K))


Measured memory_bytes: 2940
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_5-B: Merge Sort

#include <climits>
#include <cstdio>
#include <cstring>

static void print_ints(const int as[], const unsigned int n, const char* sep = " ") {
  const char* out_sep = "";
  for (auto i = 0u; i < n; ++i) {
    std::printf("%s%d", out_sep, as[i]);
    out_sep = sep;
  }
  std::printf("\n");
}

static void print_int(const unsigned int n) {
  std::printf("%d\n", n);
}

static unsigned int comparison_count = 0u;

static void merge(int* /*const*/ begin, int* const middle, int* /*const*/ end) {
  while (*begin < *middle) {
    ++begin;
    ++comparison_count;
  }
  while (*(middle-1) < *(end-1)) {
    --end;
    ++comparison_count;
  }
  auto size = middle - begin;
  int tmp[size+1]; // size+1(sentinel)
  std::memcpy(tmp, begin, sizeof(tmp[0])*size);
  tmp[size] = INT_MAX; // > 10**9
  auto ss0 = begin, ss1 = tmp, ss2 = middle;
  const auto end1 = ss1+size, end2 = end;
  while (ss2 < end2) {
    if (*ss1 <= *ss2) {
      *ss0++ = *ss1++;
    } else {
      *ss0++ = *ss2++;
    }
    ++comparison_count;
  }
  while (ss1 < end1) {
    *ss0++ = *ss1++;
    ++comparison_count;
  }
}

void merge_sort(int* const begin, int* const end) {
  auto size = end - begin;
  if (size > 1) {
    auto middle = begin + size/2;
    merge_sort(begin, middle);
    merge_sort(middle, end);
    merge(begin, middle, end);
  }
}

int main(void) {
  unsigned int n;
  std::scanf("%d", &n);
  int ss[n];
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%d", &ss[i]);
  }

  merge_sort(ss, ss+n);

  print_ints(ss, n);
  print_int(comparison_count);

  return 0;
}

// eof

Measured memory_bytes: 5588
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	S := getStdin()
	fmt.Printf("%s\n", S[:3])
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdbool.h>

int gradeStudents(int pm, int pe, int pj);

int main(void)
{
    int number;
    int pm, pe, pj;
    while (true) {
        scanf("%d", &number);
        if (number == 0) {
            break;
        }
        for (int i = 0; i < number; ++i) {
            scanf("%d %d %d", &pm, &pe, &pj);
            printf("%c\n", gradeStudents(pm, pe, pj));
        }
    }
    return 0;
}

int gradeStudents(int pm, int pe, int pj)
{
    char result;
    if (pm == 100 || pe == 100 || pj == 100) {
        result = 'A';
    } else if ((pm + pe) / 2 >=90) {
        result = 'A';
    } else if ((pm + pe + pj) / 3 >= 80) {
        result = 'A';
    } else if ((pm + pe + pj) / 3 >= 70) {
        result = 'B';
    } else if ((pm + pe + pj) / 3 >= 50 && (pm >= 80 || pe >= 80)) {
        result = 'B';
    } else {
        result = 'C';
    }
    return result;
}

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

int main() {
    int n;
    vector<int> a;
    cin >> n;
    for (int ai, i = 0; i < n; i++) {
        cin >> ai;
        a.push_back(ai);
    }
    for (int i = n-1; 0 < i; i--) {
        cout << a[i] << " ";
    }
    if (0 < n) {
        cout << a[0];
    }
    cout << endl;
    return 0;
}



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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  int OK = 1000000000, NG = 0;
  while (OK - NG > 1) {
    int mid = (OK + NG) / 2;
    long long int X = 0;
    for (int i = 0; i < N; i++) {
      X += (A.at(i) + mid - 1) / mid;
    }
    if (X <= K + N) OK = mid;
    else NG = mid;
  }
  cout << OK << endl;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<ll(n); i++)
#define REPR(i, n) for(ll i=n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<ll(n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
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; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  int k = n/2 + (n&1);
  printf("%.9f\n", double(k)/double(n));

  return 0;
}


Measured memory_bytes: 3740