akhauriyash/Code-Regression huggingface dataset:
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let v = read_vec::<u32>();
    let n = v[0];
    let k = v[1];

    let ans = (1..n+1).map(|i| {
        if i >= k {
            1.0f64
        } else {
            1.0f64 / 2.0f64.powi(((k as f64) / (i as f64)).log2().ceil() as i32)
        }
    }).fold(0.0, |acc, x| acc + x) / (n as f64);

    println!("{}", ans);
}


Measured memory_bytes: 4604
#include<stdio.h>
#include<string.h>
#define LEN 100000

typedef struct pea{
  char name[10];
  int t;
}P;

P Q[LEN];
int head,tail;

void  enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue(){
  P x=Q[head];
  head=(head+1)%LEN;
  return x;
}

int min(int a,int b){ return a<b?a:b;}

int main(){
  int time=0,c;
  int i,q;
  P u;
  int n;
  scanf("%d%d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  head=1;
  tail=n+1;

  while(head!=tail){
    u=dequeue();
    c=min(q,u.t);
    u.t-=c;
    time+=c;
    if(u.t>0)enqueue(u);
    else printf("%s %d\n",u.name,time);
  }
  return 0;
}
    



Measured memory_bytes: 4128
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include<bitset>


using namespace std;

#define ll long long
#define ld long double
#define MOD 1000000007
#define rep(i, n) for(int i = 0;i < n;i++)
#define PI 3.14159265358979323846
template <typename T>

T lcm(T x, T y)
{
    T xy = x*y;
    if(x<y)swap(x,y);
    T r;
    r = x%y;
    while(r!=0){
    x = y;
    y = r;
    r = x % y;
  }
  return xy/y;
};


int main()
{
    ll a,b;
    cin >> a >> b;
    ll ans;
    ans = lcm(a,b);
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
a,b,h,m=map(int,input().split())
k=360*(h*60+m)/720
n=360*m/60
rad=m-n
ans=(a**2+b**2-2*a*b*math.cos(2*math.pi*abs(k-n)/360))**0.5
print(str(ans)+"\n")

Measured memory_bytes: 9540
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const LL MOD=(LL)998244353;
const LL MAX_N=(LL)2e5+3;
LL fact[MAX_N],ifact[MAX_N],inv[MAX_N];


void _inv(){
    inv[0]=inv[1]=1LL;
    for(LL i = 2LL;i < MAX_N;i++){
        inv[i]= (inv[MOD%i] * (MOD - MOD/i)) % MOD;
    }
}
void calc(){
    _inv();
    fact[0]  =1LL;
    ifact[0] =1LL;
    for(LL i = 1LL;i < MAX_N;i++){
        fact[i] = (fact[i-1LL] * i) % MOD;
        ifact[i]= (inv[i] * ifact[i-1]) % MOD;
    }
}
LL C(LL n, LL r){
    if(n < 0 || r < 0 || r > n)return 0;
    if(r>n/2LL)r = n - r;
    //cout<<"!"<<fact[4]<<" "<<(fact[4]*ifact[4])%MOD<<endl;
    return (fact[n]*ifact[n-r]%MOD)*ifact[r]%MOD;
}
int main(){
    calc();
    LL N,M,K;
    cin>>N>>M>>K;
    LL ressum=0;
    LL tmp=1;
    for(LL i=0;i<N-1-K;i++)tmp=tmp*(M-1LL)%MOD;
    for(LL n=N-1-K;n<N;n++){
        LL res=M;
        LL k=N-1-n;
        res=res*tmp%MOD;
        tmp=(M-1LL)*tmp%MOD;
        LL H=C(n+k,k);
        //cout<<H<<endl;
        res=res*H%MOD;
        ressum+=res;
        ressum%=MOD;
    }
    cout<<ressum<<endl;
    return 0;
}

Measured memory_bytes: 8328
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	for (int i = min(A, B); i > 0; --i) {
		if (A % i == 0 && B % i == 0) {
			--K;
			if (K == 0) {
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Mod 1000000007
#define Val(x) (((long long)x) % Mod)
#define maxn 3005
using namespace std;
int C[maxn][maxn],fac[maxn],inv[maxn][maxn];
int Pow(int a,int n) {
	int ret = 1 , base = a;
	while(n > 0) {
		if(n&1)	ret = Val(ret * base);
		base = Val(base * base);
		n >>= 1;
	}
	return ret;
}
int dp1[maxn][maxn];	// dp1[n][b] : # of dividing n people into exactly n / b groups whose size is b
int dp2[maxn][maxn];	// dp2[i][j] : # of dividing i people into some group, all the size of groups is less than or equal to j
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	C[0][0] = 1;
	for(int i=1;i<maxn;i++) {
		C[i][0] = C[i][i] = 1;
		for(int j=1;j<i;j++)
			C[i][j] = Val(C[i-1][j-1] + C[i-1][j]);
	}	

	fac[0] = 1;
	for(int i=1;i<maxn;i++)
		fac[i] = Val(fac[i-1] * i);
	
	for(int i=1;i<maxn;i++) {
		inv[i][1] = Pow(fac[i],Mod-2);
		for(int j=2;j<maxn;j++)
			inv[i][j] = Val(inv[i][j-1] * inv[i][1]);
	}
	
	for(int i=1;i<maxn;i++)
		for(int j=1;j<=i;j++)
			if(i % j == 0)
				dp1[i][j] = Val(Val(fac[i] * inv[j][i/j]) * inv[i/j][1]);
	
	int n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	
	fill(dp2[0],dp2[0]+maxn,1);
	for(int i=1;i<=n;i++)
		for(int j=a;j<=b;j++) {
			for(int k=c;k<=d && j*k <= i;k++)
				dp2[i][j] = Val(Val(C[i][j*k] * dp1[j*k][j]) * dp2[i-j*k][j-1] + dp2[i][j]);
			dp2[i][j] = Val(dp2[i][j] + dp2[i][j-1]);
		}
		
	cout << dp2[n][b] << endl;
	return 0;
}


Measured memory_bytes: 118144
/*
      author : nishi5451
      created: 12.08.2020 16:25:12
*/

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


int main(){
    string sa,sb,sc;
    cin >> sa >> sb >> sc;
    int a = -1;
    int b = -1;
    int c = -1;
    a++;
    char no = sa[a];
    while(1){
        if(no=='a'){
            a++;
            if(a==sa.size()){
                cout << "A" << endl;
                return 0;
            }
            no = sa[a];
        }else if(no=='b'){
            b++;
            if(b==sb.size()){
                cout << "B" << endl;
                return 0;
            }
            no = sb[b];
        }else if(no=='c'){
            c++;
            if(c==sc.size()){
                cout << "C" << endl;
                return 0;
            }
            no = sc[c];
        }
    } 
    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int y = scanner.nextInt();
        if (y >= n * 1000 && y <= n * 10000) {
            int m10000Max = y / 10000;
            for (int t10000 = m10000Max; t10000 >= 0; t10000--) {
                int temp = y - t10000 * 10000;
                for (int t1000 = temp % 5000 / 1000; t1000 <= temp / 1000; t1000 += 5)
                    if (t10000 + t1000 + (y - (t10000 * 10000 + t1000 * 1000)) / 5000 == n) {
                        System.out.println(t10000 + " " + ((y - (t10000 * 10000 + t1000 * 1000)) / 5000) + " " + t1000);
                        return;
                    }
            }
        }
        System.out.println("-1 -1 -1");
    }
}

Measured memory_bytes: 23764
#include<iostream>
#define llint long long int
using namespace std;

int main() {
    llint n, k;
    cin >> n >> k;
    
    llint a = n / k;
    llint b = (n + k / 2) / k;

    llint ans;
    if (k % 2 == 0) ans = a * a * a + b * b * b;
    else ans = a * a * a;

    cout << ans << endl;
}

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

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

	int H,W,N;
	int i,j;
	int high,low;
	int sum=0;
	int answer;
	int counter=0;
	double ave;
	vector<int> given;

	cin >> H >> W >> N;

	if(H<W){
		high=W;
		low=H;
	}else{
		high=H;
		low=W;
	}

	while(sum<N){
		sum+=high;
		counter++;
	}

	answer=counter;
	cout << answer << endl;

	return 0;
}



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

#define int long long


struct DSU{
	vector<int> parent , val ;
	int N ;
	DSU(){
		N = 10 ;
	}
	DSU(int n){
		N = n ;
		parent.resize(n) ;
		val.resize(n) ;
		for(int i = 0 ; i < N ; i++) {
			parent[i] = i ;
			val[i] = 1 ;
		}
	}
	int gp(int v){ //get_parent
		if(v == parent[v])
			return v ;
		return parent[v] = gp(parent[v]) ;
	}
	bool merge(int a , int b){
		a = gp(a) , b = gp(b) ;
		if(a == b) return true ;
		if(val[a] < val[b]) // a must remain the greatest!!! :p 
			swap(a,b) ;
		parent[b] = parent[a] ;
		val[a] += val[b] ;
		return false ;
	}
} ;


int32_t main(){
	int n , m ;
	cin >> n >> m ;
	DSU dsu(n) ;
	for(int i = 0 ; i < m ; i++){
		int f , s ;
		cin >> f >> s ;
		f-- , s-- ;
		dsu.merge(f,s) ;
	}
	cout << *max_element(dsu.val.begin() , dsu.val.end()) ;
	return 0 ;
}




Measured memory_bytes: 6368
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
n = int(input())
a = list(map(int,input().split()))

if n%2 == 0:
    c = collections.Counter(a)
    item = []
    for key,value in c.items():
        item.append([key,value])
    item.sort()
    ans = 1
    for i in range(len(item)):
        if 2*i + 1 == item[i][0]:
            if item[i][1] == 2:
                ans *= 2
                ans %=MOD
            else:
                print(0)
                sys.exit()
        else:
            print(0)
            sys.exit()
    print(ans%MOD)
else:
    c = collections.Counter(a)
    ans = 1
    item = []
    for key,value in c.items():
        item.append([key,value])
    item.sort()
    for i in range(1,len(item)):
        if 2*i == item[i][0]:
            if item[i][1] == 2:
                ans *= 2
                ans %=MOD
            else:
                print(0)
                sys.exit()
        else:
            print(0)
            sys.exit()
    if item[0][0] == 0 and item[0][1] == 1:
        print(ans%MOD)
    else:
        print(0)

Measured memory_bytes: 16840
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int N, L, s, t, u, x[172809];
int main() {
	while (scanf("%d%d", &N, &L), N) {
		fill(x, x + 172800, 0);
		for (int i = 0; i < N; i++) {
			scanf("%d%d%d", &s, &t, &u);
			for (int j = s; j < t; j++) x[j] = u, x[j + 86400] = u;
		}
		double l = 0, r = 1.0e+7;
		for (int i = 0; i < 70; i++) {
			double m = (l + r) * 0.5;
			double s = L; bool flag = true, f2 = false;
			for (int j = 0; j < 172800; j++) {
				s += m - x[j];
				s = min(s, 1.0 * L);
				if (s < -1.0e-7) {
					flag = false;
					break;
				}
				if (j >= 86400 && s >= L - 1.0e-7) f2 = true;
			}
			if (flag && f2) r = m;
			else l = m;
		}
		printf("%.12lf\n", l);
	}
	return 0;
}

Measured memory_bytes: 3376
#include <stdio.h>

int main(void)
{
    int count=0,N,K,h[100001];
    int i;
    
    scanf("%d %d",&N,&K);
    
    for(i=0; i<N; i++){
        scanf("%d",&h[i]);
    }
    
    for(i=0; i<N; i++){
        if(h[i] >= K){
            count++;
        }
    }
 
    printf("%d\n",count);
        
    return 0;
}

Measured memory_bytes: 512
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	set<lint> wat, sug;
	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			if ((A * i + B * j) * 100 <= F) wat.emplace(A * i + B * j);
			if (C * i + D * j <= E / 100.0 * F) sug.emplace(C * i + D * j);
		}
	}

	double maxC = 0.0;
	pair<lint, lint> ans{ 100 * A, 0LL };
	for (const auto &w : wat) {
		for (const auto &s : sug) {
			if (s <= w * E && w * 100 + s <= F) {
				if (maxC < 1.0 * s / w) {
					maxC = 1.0 * s / w;
					ans = { 100 * w + s, s };
				}
			}
		}
	}

	cout << ans.first << " " << ans.second << "\n";

	return 0;
}


Measured memory_bytes: 384
N, K = [int(i) for i in input().split()]
sum = 0
float(sum)
for i in range(1, N + 1):
    b = i
    con = 0
    while K > b:
        b = b * 2
        con += 1
    else:
        sum += 1 / N * (0.5 ** con)

print(sum)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/


int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
        a[i]--;
    }
    vector<pair<int,int>> odd(100000);
    vector<pair<int,int>> even(100000);
    rep(i, 100000){
        odd[i].first = 0, odd[i].second = i;
        even[i].first = 0, even[i].second = i;
    }
    rep(i, n){
        if(i % 2 == 0) odd[a[i]].first++;
        else even[a[i]].first++;
    }
    sort(odd.begin(), odd.end(), greater<>());
    sort(even.begin(), even.end(), greater<>());
    
    int count_1 = 0, count_2 = 0, count_3 = 0;
    rep(i, n){
        if(odd[0].second == even[0].second) count_3 = 100000;
        if(i % 2 == 0){
            if(a[i] != odd[0].second) count_1++;
            if(a[i] != odd[1].second) count_2++;
            if(a[i] != odd[0].second) count_3++;
        }else if(i % 2 == 1){
            if(a[i] != even[1].second) count_1++;
            if(a[i] != even[0].second) count_2++;
            if(a[i] != even[0].second) count_3++;
        }
    }
    cout << min({count_1, count_2, count_3}) << endl;
}

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int ab = a - b;
	int bc = b - c;
	int ca = c - a;
	if(ab < 0) ab *= (-1);
	if(bc < 0) bc *= (-1);
	if(ca < 0) ca *= (-1);
	int abc = max(max(ab, bc), ca);
	int ans = ab + bc + ca - abc;
	cout << ans << endl;
}

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

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    mint choose(int n, int a){
        mint x = 1 ,y = 1;
        for(int i = 0; i < a; ++i){
            x *= n-i;
            y *= i+1;
        }
        return x / y;
    }
    friend istream& operator>>(istream& is, mint& m){
        is >> m.x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

mint fanc[200010];

mint choose2(int n, int a){
  return fanc[n]/(fanc[n-a]*fanc[a]);
}

int main(){
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  h--; w--;
  //階乗前計算
  fanc[0]=1;
  for(int i=1; i<200010; ++i){
    fanc[i]=fanc[i-1]*i;
  }
  mint ans=0;
  int cnt=0;
  for(int i=h-a; i>=0; --i){
    int dx=b+cnt;
    if(dx>w)break;
    ans+=choose2(i+dx,i)*choose2((h+w)-(i+dx),h-i);
    cnt++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5196
#include <iostream>

#define SIZE 50

int N, M;
std::string A[SIZE], B[SIZE];

bool judge(int I, int J) {
    for (int i=0; i<M; ++i) {
        for (int j=0; j<M; ++j) {
            if ((i+I >= N || j+J >= N) || B[i][j] != A[I+i][J+j]) return false;
        }
    }
    return true;
}

void solve() {
    bool flag = false;
    for (int i=0; i<N; ++i) {
        for (int j=0; j<N; ++j) {
            if (B[0][0] == A[i][j]) flag |= judge(i, j);
        }
    }
    std::cout << ( (flag) ? "Yes" : "No" ) << std::endl;
}

int main() {
    std::cin >> N >> M;
    for (int i=0; i<N; ++i) std::cin >> A[i];
    for (int i=0; i<M; ++i) std::cin >> B[i];
    solve();
    return 0;
}

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

int main(){
    int n,m;
    bool broken[100003] = {false};
    int mod = 1000000007;

    cin >> n >> m;
    if(n==1){
        cout << 1 << endl;
        return 0;
    }
    for(int i=0;i<m;i++){
        int a;
        cin >> a;
        broken[a] = true;
    }

    long long int pre_num=1;
    if(broken[1]) pre_num = 0;
    long long int pre_pre_num = 1;
    long long int tmp;
    for(int i=2;i<=n;i++){
        tmp = (pre_num + pre_pre_num) % mod;
        pre_pre_num = pre_num;
        pre_num = tmp;
        if(broken[i]) {pre_num=0;}
        // cout << tmp << endl;
    }
    cout << tmp%mod << endl;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  vector<char>st(s.size());
  for(int i=0;i<s.size();i++){
    st.at(i)=s.at(i);
  }
  int cnt=0;
  for(int i=0;i<s.size()-1;i++){
    if(st.at(i)==st.at(i+1)){
      if(st.at(i+1)=='0'){
        st.at(i+1)='1';
      }
      else{
        st.at(i+1)='0';
      }
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 512
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let arr = nextIntArray()
    const N= arr[0]
    const X = arr[1]
    const Y = arr[2]
    let len = new Array(N-1).fill(0)
    for(let i = 1; i<=N-1;i++){
        for(let j = i+1; j<=N; j++){
            let diff = j - i
            let tmp1 = Math.abs(X-i) + 1+ Math.abs(Y-j)
            let tmp2 = Math.abs(X-j) + 1 + Math.abs(Y-i)
            let l = Math.min(diff, tmp1, tmp2)
            len[l-1]++
        }
    }
    for(let el of len){
        myout(el)
    }
}
Main()


Measured memory_bytes: 34720
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

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;
}

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    map<int, int> a;
    for(int i = 0; i < n; i++){
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int ans = 0, mid = 0;
    mid = n/2;
    if(d[mid] != d[mid -1]){
        ans = d[mid] - d[mid-1];
    }
    // for(int i = 0; i < n; i++){
    //     cout << d[i] << " ";
    // }
    // cout << endl;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
typedef long ll;
using namespace std;
ll gcd(ll a,ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
int main(void){
    ll a, b; cin >> a >> b;
    ll g = gcd(a,b);int cnt = 0;
    for (ll i = 2; i*i <= g; i++) {
        if(g%i==0) cnt++;
        while (g%i == 0) {
            g /= i;
        }
        if(i>2) i++;
    }if(g>1) cnt++;
    cout << cnt+1 << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let in_s: Vec<char> = read::<String>().chars().collect();

    if in_s.len() >= 6 && in_s[2] == in_s[3] && in_s[4] == in_s[5] {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
// Problem : A - A?C
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//look at my code
//my code is amazing
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007 //998244353
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define nl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define cout1(a) cout<<a<<nl
#define cout2(a,b) cout<<a<<" "<<b<<nl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<nl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<nl
#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<nl
#define x first
#define y second
#define vc vector
#define pb push_back
#define ar array
#define all(a) (a).begin(), (a).end()
#define ms(v,n,x) fill(v,v+n,x);
#define init(c,a) memset(c,a,sizeof(c))
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod 
#define inf 9e18
#define cases ll T;cin>>T;while(T--)
#define BLOCK 500
//const double PI = 3.141592653589793238460;
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
// const int N=;

int32_t main()
{
    
	fast
	string s;
	cin>>s;
	if(s[1]=='B')
	cout<<"ARC";
	else
	cout<<"ABC";
	
	

	



    

	return 0;
    
}

Measured memory_bytes: 3652
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n 

    def find(self, x): 
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y): 
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x): 
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N,M =map(int,input().split())
uf =UnionFind(N)
for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    uf.union(a, b)

ans =0
a = uf.roots()
for i in range(len(a)):
    if uf.size(a[i])>ans:
        ans = uf.size(a[i])
print(ans)


Measured memory_bytes: 18456
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	rep(snip_i, n) cin >> p.at(snip_i);
	int ans = 0;
	rep2(i, 1, n-1){
		vector<int> temp;
		temp.push_back(p.at(i-1));
		temp.push_back(p.at(i));
		temp.push_back(p.at(i+1));
		sort(temp.begin(), temp.end());
		if(temp.at(1) == p.at(i)) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 24) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s; cin >> s;
	bool a = 1-s.length()%2;
	rep(i, s.length()) {
		if(i%2) a = a && (s[i] == 'i');
		else a = a && (s[i] == 'h');
	}
	if(a) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define PSB push_back
typedef long long LL;
//#define int long long

//booooooooooooost

#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int)


#define M 1000000007
LL  arr[200000][2];


LL inv_mod(LL a, LL m)
{
	LL b, x, u, q, abs_m, tmp;

	abs_m = (m < 0) ? -m : m;
	b = m; x = 1; u = 0;
	while (b > 0) {
		q = a / b;
		tmp = u; u = x - q * u; x = tmp;
		tmp = b; b = a - q * b; a = tmp;
	}

	return (x < 0) ? abs_m + x : x;
}

LL conb(LL x, LL y) {
	return (((arr[x][0] * arr[y][1]) % M) * arr[x - y][1]) % M;
}


signed main() {

	REP(i, 200001) {
		arr[i][0] = (i == 0 ? 1 : i * arr[i - 1][0]) % M;
		arr[i][1] = inv_mod(arr[i][0], M);
	}


	LL H, W, A, B;
	cin >> H >> W >> A >> B;


	LL ans = 0;
	for (LL i = 0; i < H - A; ++i) {
		ans += conb((i + 1) + B - 2, B - 1) * conb(H - i + W - B - 2, W - B - 1);
		ans %= M;
	}

	std::cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3456
from collections import Counter
n = int(input())
v = list(map(int, input().split()))

a = []
b = []
for i in range(n//2):
    a.append(v[2*i])
    b.append(v[2*i+1])

def change(list):
    counter = Counter(list)
    m_ap1 = '0'
    m_ap2 = '0'
    if len(counter.most_common()) > 1:
        m_ap1, m_ap2 = counter.most_common()[0][0], counter.most_common()[1][0]
    else:
        m_ap1 = counter.most_common()[0][0]
    l = len(list)
    cnt1 = 0
    cnt2 = 0
    for i in range(l):
        if list[i] != m_ap1:
            cnt1 += 1
        if list[i] != m_ap2:
            cnt2 += 1
    return cnt1, cnt2, m_ap1, m_ap2
ca1, ca2, ma1, ma2 = change(a)
cb1, cb2, mb1, mb2 = change(b)
# print(change(a))
# print(change(b))
if ca1+cb1:
    if ma1 != mb1:
        print(ca1+cb1)
    else:
        print(min(ca1+cb2,cb1+ca2))
else:
    if ma1 != mb1:
        print(ca1+cb1)
    else:
        print(n//2)


Measured memory_bytes: 17492
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define Inf 1000000000000000ll
#define ll long long
using namespace std;

int main() {
    int x,y;
    cin>>x>>y;
    
    ll ans1=Inf;
    ll ans2=Inf;
    ll ans3=Inf;
    ll ans4=Inf;
    
    
    if (x <= y) {
        ans1 = y-x;
    }
    
    if (-x <= y) {
        ans2 = y+x+1;
    }
    
    if (x <= -y) {
        ans3 = -y-x+1;
    }
    
    if (-x <= -y) {
        ans4 = -y+x+2;
    }
    
    
    cout << min(ans1, min(ans2,min(ans3,ans4))) << endl;
}

Measured memory_bytes: 764
/**
 * Created by ko_ji on 2017/09/10.
 */

import java.util.Scanner;
import java.util.Arrays;

class Main{
    public static void main(String args[]){
        int A[] = new int[2];

        Scanner sc = new Scanner(System.in);
        A[0] = sc.nextInt();
        A[1] = sc.nextInt();
        int c = A[0] + A[1];

        if (A[0] % 3 == 0 || A[1] % 3 == 0 || c % 3 == 0) {
            System.out.println("Possible");
        }else{
            System.out.println("Impossible");
        }


    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0,s=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		char t;
		cin>>t;
		if(t=='I')s++;
		else s--;
		ans=max(ans,s);
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
 
using namespace std;
 
long long int dp[3001][3001][2];
 
long long int solve(long long int a[], int i,int j,int t)
{
    if(i==j)
    {
        return 0;
    }
	else if(dp[i][j][t]!=-1)
	{
		return dp[i][j][t];
	}
    else if(t==1)
    {
        dp[i][j][t] = max(solve(a,i+1,j,0)+a[i], solve(a, i,j-1,0)+a[j-1]);
    }
    else
    {
        dp[i][j][t] = min(solve(a, i+1,j,1)-a[i],solve(a, i,j-1,1)-a[j-1]);
    }
    
    return dp[i][j][t];
}
 
int main()
{
    int n;
    cin>>n;
    long long int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
	
    memset(dp, -1, sizeof(dp[0][0][0]) * 3001 * 3001 * 2);
				
    cout<<solve(a,0,n,1);
 
    return 0;
    
 
}

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

int main()
{
    int n,m=0;
    cin>>n;
    char s[n];
    cin>>s;
    int x;
    
    for(int i=0 ; i<=n ;i++){
    	if(s[i]=='I'){
		
		 m++;
		  }
    	else if(s[i]=='D'){
		
		 m--;
	}
	x=max(x,m);
	}
	
    printf("%d",x);
	
}

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

int main(int argc, char const *argv[]) {
    long long a, b, k;
    cin >> a >> b >> k;

    a -= k;
    if (a < 0) {
        b += a;
        a = 0;
    }
    if (b < 0) b = 0;

    cout << a << ' ' << b << endl;
    return 0;
}


Measured memory_bytes: 3600
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

printList [a] = print a
printList (a:as) = putStr ( show a ) >> putChar ' ' >> printList as

main = do
	[ n, d ] <- readIntegers
	ps <- map mp <$> replicateM ( fromIntegral n ) readIntegers
	print $ length $ filter ( f d ) ps

f d ( x, y ) = x ^ 2 + y ^ 2 <= d ^ 2

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

typedef long long LL;

const int M = 2e5, N = 4e3, MOD = 1e9 + 7, I2 = (MOD + 1) >> 1;

int n, a[M + 5], b[M + 5], fac[N + N + 5], ifac[N + N + 5], pool[N + 5][N + 5], *g[N + 5], **f;

inline int add(const int &x) {
	return x >= MOD ? x - MOD : x;
}
inline void add(int &x, const int &y) {
	(x += y) >= MOD && (x -= MOD);
}
inline void sub(int &x, const int &y) {
	(x -= y) < 0 && (x += MOD);
}
inline int binom(int n, int m) {
	return (LL)fac[n] * ifac[m] % MOD * ifac[n - m] % MOD;
}
inline int pow(int x, int k) {
	int ans = 1;
	for (; k > 0; k >>= 1, x = (LL)x * x % MOD) {
		if (k & 1) {
			ans = (LL)ans * x % MOD;
		}
	}
	return ans;
}
inline int inv(int x) {
	return pow(x, MOD - 2);
}
void init(int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; i++) {
		fac[i] = (LL)fac[i - 1] * i % MOD;
	}
	ifac[n] = inv(fac[n]);
	for (int i = n; i >= 1; i--) {
		ifac[i - 1] = (LL)ifac[i] * i % MOD;
	}
}
int main() {
	init(N + N);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &a[i], &b[i]);
	}
	int maxA = *std::max_element(a + 1, a + n + 1);
	int maxB = *std::max_element(b + 1, b + n + 1);
	for (int i = 0; i <= N + 1; i++) {
		g[i] = &pool[i][2001];
	}
	f = &g[2001];
	for (int i = 1; i <= n; i++) {
		f[-a[i]][-b[i]]++;
	}
	for (int i = -maxA; i <= maxA; i++) {
		for (int j = -maxB; j <= maxB; j++) {
			add(f[i][j], add(f[i - 1][j] + f[i][j - 1]));
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		add(ans, f[a[i]][b[i]]);
		sub(ans, binom((a[i] + b[i]) << 1, a[i] << 1));
	}
	printf("%lld\n", (LL)ans * I2 % MOD);
	return 0;
}

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

int h, w;

int main(void){
	cin >> h >> w;
	vector<vector<char>> f(h+2, vector<char>(w+2, '#'));
	rep(i, h){
		rep(j, w){
			cin >> f[i+1][j+1];
		}
	}
	rep(i, h+2){
		rep(j, w+2){
			cout << f[i][j];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3612
<?php
 
    fscanf(STDIN, "%d %d", $N, $X);
 
    function uec($a, $b) {
        $m = max($a, $b);
        $n = min($a, $b);
 
        while ($n != 0) {
            $tmp = $n;
            $n = ($m % $n);
            $m = $tmp;
        }
 
        return $m;
    }
 
    echo ($N - uec($N, $X)) * 3 . "\n";

Measured memory_bytes: 3576
#include <stdio.h>
int main(void){
  char a;
  int wo;
  scanf("%d",&wo);



  if(wo < 112){
    printf("111\n");
  }else if(wo < 223){
    printf("222\n");
  }else if(wo < 334){
    printf("333\n");
  }else if(wo < 445){
    printf("444\n");
  }else if(wo < 556){
    printf("555\n");
  }else if(wo < 667){
    printf("666\n");
  }else if(wo < 778){
    printf("777\n");
  }else if(wo < 889){
    printf("888\n");
  }else if(wo < 1000){
      printf("999\n");
    }
}

Measured memory_bytes: 128
#intじゃ無理
K=str(input())
D=int(input())
N=len(K)
P=10**9+7


#DP[i][smaller][j]=上からi(1<=i<=len(K))桁目までで桁総和modDがj(0<=j<=D-1)の個数
DP=[[[0]*(D) for index1 in range(2)] for index2 in range(N+1)]
#i=0に関しては初期値として与える
DP[0][0][0]=1

#桁DP:O(ND)
for i in range(1,N+1):
    for j in range(D):
        for k in range(10):
            DP[i][1][(j+k)%D]=(DP[i][1][(j+k)%D]+DP[i-1][1][j])%P
        for l in range(int(K[i-1])):
            DP[i][1][(j+l)%D]=(DP[i][1][(j+l)%D]+DP[i-1][0][j])%P
        DP[i][0][(j+int(K[i-1]))%D]=(DP[i][0][(j+int(K[i-1]))%D]+DP[i-1][0][j])%P

#0を除く
print((DP[N][0][0]+DP[N][1][0]-1)%P)





Measured memory_bytes: 63196
use proconio::input;

fn main() {
    input! {
        n: usize,
        t: [i64; n],
        a: [i64; n],
    };
    let mut f = vec![0_i64; n];
    f[0] = t[0];
    let mut p = t[0];
    for (i, &t_i) in t.iter().enumerate().skip(1) {
        if p < t_i {
            f[i] = t_i;
        }
        p = t_i;
    }
    if f[n - 1] > 0 && f[n - 1] != a[n - 1] {
        println!("0");
        return;
    }
    f[n - 1] = a[n - 1];
    p = a[n - 1];
    for (i, &a_i) in a.iter().enumerate().rev().skip(1) {
        if f[i] > 0 && f[i] > a_i {
            println!("0");
            return;
        }
        if p < a_i {
            if f[i] > 0 && f[i] != a_i {
                println!("0");
                return;
            }
            f[i] = a_i;
        }
        p = a_i;
    }

    let mut ans = 1_i64;
    for (&f_i, (&t_i, &a_i)) in f.iter().zip(t.iter().zip(a.iter())) {
        if f_i == 0 {
            ans *= std::cmp::min(t_i, a_i);
            ans %= 1_000_000_007;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6320
s = input().rstrip()

s1 = s[0]
if s.count(s1) != 2:
    print('No')
    exit()

s2 = ''
for c in s:
    if s1 != c:
        s2 = c
        break

if s.count(s2) != 2:
    print('No')
    exit()

print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define N 10000

int check(vector<int> w, int n, int cost) {
	int sum = 0;
	int num = 1;
	for(int i = 0; i < n; i++) {
		if(w[i]+sum <= cost) {
			sum += w[i];
		}
		else {
			sum = w[i];
			num++;
		}
	}
	return num;
}


int main() {
	int n, k;
	cin >> n >> k;
	vector<int> w(n, 0);
	
	int sum = 0, max = 0;
	for(int i = 0; i < n; i++) {
		cin >> w[i]; 
		sum += w[i];	
		if(max < w[i]) {
			max = w[i];
		}

	}

	//sort(w.begin(), w.end());
	
	//int max = w[n-1];

	while(max != sum) {
		int mid = (max+sum)/2;
		if(check(w, n, mid) > k) {
			max = mid+1;
		}
		else {
			sum = mid;
		}
	}

	cout << max << endl;
	return 0;
}





Measured memory_bytes: 3576
#include<cstdio>  
#include<iostream>  
#include<algorithm>  
#include<cstdlib>  
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<cmath>
#include<map>
#define LL long long
#define pii pair<int,int>
#define mp make_pair
 
using namespace std;
 
inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
}
 
inline void read(int &x){
  char c=nc();int b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
 
inline void read(LL &x){
  char c=nc();LL b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

inline int read(char *s)
{
	char c=nc();int len=1;
	for(;!(c>='a' && c<='z');c=nc()) if (c==EOF) return 0;
	for(;(c>='a' && c<='z');s[len++]=c,c=nc());
	s[len++]='\0';
	return len;
}

inline void read(char &x){
  for (x=nc();!(x>='A' && x<='Z');x=nc());
}

int wt,ss[19];
inline void print(int x){
	if (x<0) x=-x,putchar('-'); 
	if (!x) putchar(48); else {
	for (wt=0;x;ss[++wt]=x%10,x/=10);
	for (;wt;putchar(ss[wt]+48),wt--);}
}
inline void print(LL x){
	if (x<0) x=-x,putchar('-');
	if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}
}

int n,a[200010];

bool check1(int x)
{
	for (int i=1;i<2*n;i+=2)
		if (a[i]<x) return false;
	return true;
}

bool check(int x)
{
	if (check1(x)) return true;
	int y=0,z;
	for (int i=1;i<n;i++)
		if (a[i]>=x && a[i+1]>=x) y=i+1;
	z=y;
	if (z!=0)
	{
		while (a[z+2]>=x)
		{
			z+=2,y++;
			if (z+2>=2*n) break;
		}
		if (y>=n) return true;
	}
	y=0;
	for (int i=2*n-1;i>n;i--)
		if (a[i]>=x && a[i-1]>=x) y=i-1;
	z=y;
	if (z!=0)
	{
		while (a[z-2]>=x)
		{
			z-=2,y--;
			if (z-2<1) break;
		}
		if (y<=n) return true;
	}
	return false;
}

int main()
{
	read(n);
	memset(a,0,sizeof(a));
	for (int i=1;i<2*n;i++)
		read(a[i]);
	int l=2,r=2*n-2,mid,res;
	while (l<=r)
	{
		mid=l+r>>1;
		if (check(mid)) l=mid+1,res=mid;else r=mid-1;
	}
	print(res),puts("");
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int A,B;
  cin >> A >> B;
  if(A > 9 || B > 9){
    cout << "-1" << endl;
  }
  	else cout << A*B <<endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/practice2/tasks/practice2_j

#include <atcoder/all>

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

ll op(ll a, ll b) { return max(a, b); }
ll e() { return -1; }
ll target;
bool f(ll v) { return v < target; }

void solve() {
  ll N, Q;
  cin >> N >> Q;

  VL as(N);
  rep(i, N) cin >> as[i];

  segtree<ll, op, e> seg(as);

  rep(i, Q) {
    ll t;
    cin >> t;

    if (t == 1) {
      ll x, v;
      cin >> x >> v;
      x--;
      seg.set(x, v);
    } else if (t == 2) {
      ll l, r;
      cin >> l >> r;
      l--;
      cout << seg.prod(l, r) << "\n";
    } else if (t == 3) {
      ll p;
      cin >> p >> target;
      p--;
      cout << seg.max_right<f>(p) + 1 << "\n";
    }
  }
}


Measured memory_bytes: 9024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;

int N, K;

int main() {
    cin >> N >> K;
    vector<ll> h(N);
    for (int i = 0; i < N; i++) cin >> h.at(i);
    
    sort(h.begin(), h.end());
    ll d = 1000000000;
    for (int i = 0; i <= N - K; i++) {
        if (h.at(i + K - 1) - h.at(i) < d) {
            d = h.at(i + K - 1) - h.at(i);
        }
    }
    cout << d << endl;
}


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

using namespace std;
#define ll long long
#define st first
#define nd second
#define pb push_back

const int maxn = (int)5e5;
const int R = 1024 * 512;

int c[maxn];
int tree[2 * R];
int lazy[2 * R];
int lastOccurr[maxn];
int occurrToLeft[maxn];
int ansToCout[maxn];
pair<int,int> queries[maxn];
pair<int,int> sorted[maxn];

void update(int id, int val){
	tree[id] += val;
	lazy[id] += val;
}
void push(int id){
	update(2 * id, lazy[id]);
	update(2 * id + 1, lazy[id]);
	lazy[id] = 0;
}
void add(int beg, int end, int id = 1, int l = 1, int r = R){
	if(l > end || r < beg) return;
	if(beg <= l && r <= end){
		update(id,1);
		return;
	}
	push(id);
	int left = 2 * id;
	int right = 2 * id + 1;
	int mid = (l + r) / 2;
	add(beg,end,left,l,mid);
	add(beg,end,right,mid + 1,r);
	tree[id] = max(tree[left],tree[right]);
}
int giveAns(int beg, int end, int id = 1, int l = 1, int r = R){
	if(l > end || r < beg) return 0;
	if(beg <= l && r <= end)
		return tree[id];
	push(id);
	int left = 2 * id;
	int right = 2 * id + 1;
	int mid = (l + r) / 2;
	return max(giveAns(beg,end,left,l,mid),giveAns(beg,end,right,mid + 1,r));
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,q;
	cin >> n >> q;
	for(int i = 1; i <= n; i++)
		cin >> c[i];
	vector<vector<int> > querry(n + 1);
	for(int i = 1; i <= q; i++){
		cin >> queries[i].first >> queries[i].second;
		querry[queries[i].second].push_back(i);
	}
	for(int i = 1; i <= n; i++)
		lastOccurr[i] = 0;
	for(int i = 1; i <= n; i++){
		occurrToLeft[i] = lastOccurr[c[i]] + 1;
		lastOccurr[c[i]] = i;
	}
	sort(sorted + 1, sorted + q + 1);
	for(int i = 1; i <= n; i++){
		add(occurrToLeft[i],i);
		for(int j = 0; j < (int) querry[i].size(); j++){
			int prevI = querry[i][j];
			ansToCout[prevI] = giveAns(queries[prevI].first,n);
		}
	}
	for(int i = 1; i <= q; i++)
		cout << ansToCout[i] << '\n';
	return 0;
}



Measured memory_bytes: 47928
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  ll n,a,b;
  cin>>n>>a>>b;
  ll temp=n%(a+b);
  ll ans=0;
  if(a==0)goto A;
  ans=n/(a+b)*a;
  
  if(temp>=a)ans+=a;
  else ans+=temp;
A:{cout<<ans;}  
}

Measured memory_bytes: 256