akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int parent[100005];
int d[100005];
int find(int x)
{
	if(x==parent[x]) return parent[x];
	int l=find(parent[x]);
	d[x]=d[parent[x]]+d[x];
	parent[x]=l;
	return l;
} 
int Unit(int x,int y,int z)
{
	int px=find(x);
	int py=find(y);
	if(px==py)
	return z==d[y]-d[x];
	parent[py]=px;
	d[py]=d[x]-d[y]+z;
	return 1;
} 
int main()
{
	int n,m;
	while(cin>>n>>m)
	{
		int i,ok=1;int x,y,z;
		for(i=1;i<=n;i++) parent[i]=i;
		for(i=1;i<=m;i++)
		{
			cin>>x>>y>>z;
			if(ok)
			{
				ok=Unit(x,y,z);
			}
		}
		if(!ok) cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define inf 2e9
#define f first
#define s second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speed;

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

ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}

int main (){
    int a,b,t;
    cin >> a >> b >> t;
    cout << t/a*b << "\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

using namespace std;

class inverse {
    public:
    inverse(int n, int mod);
    ~inverse();
    long long get_inv(int x);
    long long get_fact(int x);
    long long get_invfact(int x);
    long long get_comb(int x, int y);
    
    private:
    int mod;
    long long* inv;
    long long* fact;
    long long* invfact;
};

inverse::inverse(int n, int mod) : mod(mod) {
    inv = (long long *)malloc(sizeof(long long) * (n + 1));
    fact = (long long *)malloc(sizeof(long long) * (n + 1));
    invfact = (long long *)malloc(sizeof(long long) * (n + 1));
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    fact[0] = invfact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    for (int i = 1; i <= n; i++) invfact[i] = invfact[i - 1] * inv[i] % mod;
}

inverse::~inverse() {
    free(inv);
    free(fact);
    free(invfact);
}

long long inverse::get_inv(int x) {
    return inv[x];
}

long long inverse::get_fact(int x) {
    return fact[x];
}

long long inverse::get_invfact(int x) {
    return invfact[x];
}

long long inverse::get_comb(int x, int y) {
    return fact[x] * invfact[y] % mod * invfact[x - y] % mod;
}

const int mod = 1000000007;
int a[20];
long long dp[21][1001];

int main() {
    int n, k, i, j, l;
    
    scanf("%d %d", &n, &k);
    
    for (i = 0; i < k; i++) scanf("%d", &a[i]);
    
    inverse inv(n, mod);
    
    dp[0][0] = 1;
    
    for (i = 0; i < k; i++) {
        for (j = 0; j <= n; j++) {
            if (dp[i][j] == 0) continue;
            
            for (l = 0; l <= a[i] && j + l <= n; l++) {
                dp[i + 1][j + l] += dp[i][j] * inv.get_comb(n - l, a[i] - l) % mod * inv.get_invfact(l) % mod;
                if (dp[i + 1][j + l] >= mod) dp[i + 1][j + l] -= mod;
            }
        }
    }
    
    printf("%lld\n", dp[k][n] * inv.get_fact(n) % mod);
    
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int N;
int A[114514];

int main(void) {
	int i;
	int mimorinn = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
	}
	for (i = 1; i < N; i++) {
		if (A[i - 1] < A[i]) mimorinn++;
	}
	printf("%d\n", mimorinn);
	return 0;
}



Measured memory_bytes: 2236
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	int d,ans=0;
	while(cin>>d){
		for(int i=0;i<600;i+=d){
			ans+=(i*i)*d;
		}
		cout<<ans<<endl;
		ans=0;
	}
	return 0;
}

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

#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++)

int main(){
  int w,a,b,ans;
  cin>>w>>a>>b;
  ans=b-a-w;
  if(b<a){ans=a-b-w;}
  cout<<max(0,ans)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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 INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, z, w;
    cin>>n>>z>>w;
    vl as(n); cin>>as;
    if (n == 1) {
        cout<<abs(as[0] - w)<<endl;
        return 0;
    }
    cout<<max(abs(as[n - 1] - as[n - 2]), abs(as[n - 1] - w));
}

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

public class Main {

    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();

            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                list.add(Integer.parseInt(sc.next()));
            }
            System.out.println(calc(list));
        }
    }

    public static double calc(List<Integer> list) {
        BigDecimal child = BigDecimal.ONE;
        BigDecimal sum = BigDecimal.ZERO;
        for (int i = 0; i < list.size(); i++) {
            BigDecimal cache = BigDecimal.ONE;
            for (int j = 0; j < list.size(); j++) {
                if (i != j) {
                    cache = cache.multiply(BigDecimal.valueOf(list.get(j)));
                }
            }

            sum = sum.add(cache);
            child = child.multiply(BigDecimal.valueOf(list.get(i)));
        }

        return child.divide(sum, 10, RoundingMode.UP).doubleValue();
    }

}


Measured memory_bytes: 24404
A,B,N=list(map(int,input().split()))
listA=list(map(int,input().split()))
listB=list(map(int,input().split()))
ma=sorted(listA)
mb=sorted(listB)
M=min(ma)+min(mb)
for i in range(N):
  x,y,c=list(map(int,input().split()))
  ans=listA[x-1]+listB[y-1]-c
  if ans<M:
    M=ans
print(M)

Measured memory_bytes: 24832
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int N;
    io.read(N);
    vector<int> l(N);
    vector<int> r(N);
    for(int i = 0; i < N; i++){
        io.read(l[i], r[i]);
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        ans += r[i] - l[i] + 1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
while (n, x = gets.split(" ").map(&:to_i)) != [0, 0] do
  count = 0
  (1...n).each do |i|
    ((i+1)..n).each do |j|
      ((j+1)..n).each do |k|
        if i + j + k == x
          count += 1
        end
      end
    end
  end
  puts count
end

Measured memory_bytes: 8748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, C;
  cin >> N >> C;
  int D[C][C], c[N][N];
  for (int i = 0; i < C; i++) {
    for (int j = 0; j < C; j++) {
      cin >> D[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> c[i][j];
      c[i][j]--;
    }
  }
  int g[C][3]{};
  for(int i = 0; i < C; i++) {
    for(int j = 0; j < N; j++) {
      for(int k = 0; k < N; k++) {
        if(c[j][k] != i) {
          g[i][(j + k) % 3] += D[c[j][k]][i];
        }
      }
    }
  }
  int min_v = INT32_MAX;
  for (int i = 0; i < C; i++) {
    for (int j = 0; j < C; j++) {
      for (int k = 0; k < C; k++) {
        if (i == j || i == k || j == k) continue;
        min_v = min(min_v, g[i][0] + g[j][1] + g[k][2]);
      }
    }
  }
  cout << min_v << "\n";
  return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;
const int m=1000000000;

int main(){
	string s,t;
    int l;
    cin>>l;
    cin>>s>>t;
    FOR(i,0,l){
        cout<<s[i]<<t[i];
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
#define sort(v) sort(v.begin(), v.end())
#define sortr(v) sort(v.rbegin(), v.rend())
void chmin(int &a, int b) {if(a > b) a = b;}
void chmax(int &a, int b) {if(a < b) a = b;}

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};


int main(){
    string s;
    cin >> s;
    rep(i,0,s.length()){
        cout << "x";
    }
}

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

int main(){
    int N;
    cin >> N;
    int64_t ans = 0;
    for(int64_t i=1; i<=N; i++){
        int64_t num = N/i;
        ans += num*(num+1)/2*i;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    priority_queue<string,vector<string>,greater<string> >v;
    int N,L;
    cin>>N>>L;
    REP(i,N){
        string s;
        cin>>s;
        v.push(s);
    }
    while(!v.empty()){
          string s=v.top();v.pop();
          cout<<s;
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a,b,d,r=0;
	double f=0;
		scanf("%d %d",&a,&b);
		d=a/b;
		r=a%b;
		f=(double)a/b;
	printf("%d %d %lf\n",d,r,f);
return 0;
}


Measured memory_bytes: 2100
#include<stdio.h>
#include<stdlib.h>

int main(){
	int P,Q,R,max,sum;
	scanf("%d %d %d",&P,&Q,&R);
	sum = P+Q+R;
	if(P<Q){
		if(Q<R)max=R;
		else max = Q;
	}
	else{
		if(P<R)max=R;
		else max = P;
	}
	printf("%d\n",sum-max);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;	

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define nl cout<<"\n"
#define MOD(x) ((x%P)+P)%P
#define vec(v) loop(i,0,v.size()) cout<<v[i]<<" "; nl
const int N = 50;
const ll P = 1000000007;
const double eps = 1e-6;

ll can[N][N], ans[N][N];
ll n,k;

void cansq()
{
	ll temp[N][N] = {};
	for(int i=0; i<N; i++)
	{
		for(int j=0; j<N; j++)
		{
			for(int k=0; k<N; k++)
			{
				temp[i][j] += can[i][k]*can[k][j];
				temp[i][j] = MOD(temp[i][j]);
			}
		}
	}
	for(int i=0; i<N; i++)
		for(int j=0; j<N; j++)
			can[i][j] = temp[i][j];
}

void mulans()
{
	ll temp[N][N] = {};
	for(int i=0; i<N; i++)
	{
		for(int j=0; j<N; j++)
		{
			for(int k=0; k<N; k++)
			{
				temp[i][j] += ans[i][k]*can[k][j];
				temp[i][j] = MOD(temp[i][j]);
			}
		}
	}
	for(int i=0; i<N; i++)
		for(int j=0; j<N; j++)
			ans[i][j] = temp[i][j];
}

void matexp(ll k)
{
	while(k)
	{
		if(k%2)
			mulans();
		cansq();
		k /= 2;
		// for(int i=0; i<n; i++)
		// {
		// 	for(int j=0; j<n; j++)
		// 		cout<<can[i][j]<<" ";
		// 	nl;
		// }
		// nl;
	}
}

int main()
{
	fastio();

	cin>>n>>k;

	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			cin>>can[i][j];

	for(int i=0; i<n; i++)
		ans[i][i] = 1;

	matexp(k);
	
	ll res = 0;
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			res = MOD(res+ans[i][j]);

	cout<<res,nl;

	//cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}

Measured memory_bytes: 384
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	string s;
	scans(s);
	printyn(s.substr(0, s.length() / 2) == s.substr(s.length() / 2 + 1));
	
	Please AC;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pii pair<int, int>
using namespace std;

const int N = (int)1e5 + 5;
const int INF = (int)1e9 + 9;
int a[N];
map <int, int> cnt1, cnt2;
set <pii> st1, st2;

void go(int x) {
	cout << x << endl;
	exit(0);
}

main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		if (i % 2) {
			cnt1[a[i]]++;
		}
		else {
			cnt2[a[i]]++;
		}
	}
	
	for (auto c : cnt1) {
		st1.insert({c.sc, c.fr});
	}
	for (auto c : cnt2) {
		st2.insert({c.sc, c.fr});
	}
	
	st1.insert({0, 0});
	st2.insert({0, 0});
	
	set <pii> ::iterator it;
	it = (--st1.end());
	pii p1, p2, p11, p22;
	p1 = *it;
	it = (--st2.end());
	p2 = *it;
	
	if (p1.sc != p2.sc) {
		go(n - (p1.fr + p2.fr));
	}
	
	it = (--st1.end()), it--;
	p11 = *it;
	it = (--st2.end()), it--;
	p22 = *it;
	
	cout << n - max(p1.fr + p22.fr, p2.fr + p11.fr);
}


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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
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;}
//end



int main(){
   int n; cin>>n; n++;
   vector<int> a(n); rep(i,0,n)cin>>a[i];
   if(a[0]>=2){
      puts("-1"); return 0;
   }
   vector<ll> lim(n); lim[0]=1-a[0];
   rep(i,1,n){
      lim[i]=lim[i-1]*2-a[i];
      chmin(lim[i],INF);
      if(lim[i]<0){
         puts("-1");
         return 0;
      }
   }
   ll res=0,rem=0;
   for(int i=n-1;i>=0;i--){
      if(rem>lim[i]*2){
         puts("-1"); return 0;
      }
      chmin(rem,lim[i]);
      rem+=a[i];
      res+=rem;
   } cout<<res<<endl;
   return 0;
}

Measured memory_bytes: 4240
s = input()
sc = ''
c = 0

for i in range(len(s)):
  if 'C' == s[i]:
    sc = s[i+1:]
    for j in range(len(sc)):
      if 'F' == sc[j]:
        c += 1

if c > 0:
  print('Yes')
else:
  print('No')

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

int main(){
  string s;
  cin>>s;
  bool ok=true;
  rep(i,3){
    if(s[i]==s[i+1])ok=false;
  }
  if(ok)cout<<"Good"<<endl;
  else cout<<"Bad"<<endl;
}


Measured memory_bytes: 3620
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
    }

    if a>8 || b>8 {
        println!(":(");
    } else {
        println!("Yay!");
    }

}


Measured memory_bytes: 2116
import java.util.Scanner;

public class Main {
	static Scanner in = new Scanner(System.in);
	
	public static void main(String[] args){
		int n = in.nextInt();
		
		int sum = 0;
		for(int i = 0; i < n; i++){
			if(in.nextInt() % 2 == 1){
				sum++;
			}
		}
		if(sum % 2 == 1){
			System.out.println("NO");
		}else{
			System.out.println("YES");
		}

	}
}

Measured memory_bytes: 48452
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
    int n;
    scanf("%d",&n);
    vector<long double>p(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
        //cout<<p[i]<<" ";
    }
    //cout<<endl;
    vector<vector<long double>>dp(n+1,vector<long double>(n+1,0));
    dp[0][0]=1.0;
    for(int ri=1;ri<=n;ri++){
        for(int ci=0;ci<=n;ci++){
            if(ci>ri)
                break;
            if(ci==0)
                dp[ri][ci]=(1-p[ri-1])*dp[ri-1][ci];
            else
                dp[ri][ci]=(1-p[ri-1])*dp[ri-1][ci]+(p[ri-1])*dp[ri-1][ci-1];

            //cout<<dp[ri][ci]<<" ";
        }
    }
    long double ans=0.0;
    
    for(int i=n/2+1;i<=n;i++){
        ans+=dp[n][i];
        //cout<<dp[n][i]<<endl;
    }
    cout<<setprecision(10)<<ans;
}


Measured memory_bytes: 141056
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef long double LD;
typedef vector<LD> vld;
typedef vector<pair<LD, LD>> vpld;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
typedef pair<ll, PL> TL;
typedef vector<TL> vtl;
typedef vector<vtl> vvtl;
typedef long double ld;
typedef vector<ld> vld;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec /* copy */){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const tpl& lhs, const tpl& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}

bool bit(ll st, ll b){return ((st>>b)&1) == 1;}


int main(){
#ifdef __DEBUG_LOCAL__
    ifstream file("../../../../../in.txt");
    if(file.is_open()) cin.rdbuf(file.rdbuf());
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vl A(N); rep(i, N) cin >> A[i];
    ll now = 0;
    rep(i, N){
        if(A[i] == now+1) now++;
    }
    cout << ( now == 0 ? -1 : N - now) << endstr;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<vector<int>> G;
long  double dp[601],ans=700;
void f(int block)
{
    dp[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
        int deg=G[i].size();
        long double mn=0,sum=0;
        for(auto v:G[i])
        {
            mn=max(mn,dp[v]);
           sum+=dp[v];
        }
        if(i==block&&deg>=2)
        {
            sum-=mn;
            deg--;
        }
        dp[i]=1+sum/deg;

    }
    ans=min(ans,dp[0]);
}
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n>>m;
    G.resize(n);
    for(int i=0;i<m;i++)
    {
        int s,t;
        cin>>s>>t;
        --s,--t;
        G[s].push_back(t);
    }
    for(int i=0;i<n;i++)
        f(i);
    cout<<fixed<<setprecision(10)<<ans;
    return 0;
}


Measured memory_bytes: 1408
def gcd(a, b):
    if b == 0:
        return a
    a, b = b, a % b
    return gcd(a, b) 

k = int(input())

ans_1 = 0
# pattern1: 'aaa'
for a in range(1, k + 1):
    ans_1 += a

# pattern2: 'aab' or 'abb'
ans_2 = 0
for a in range(1, k):
    for b in range(a + 1, k + 1):
        ans_2 += gcd(a, b)
ans_2 *= 6

# pattern3: 'abc'
ans_3 = 0
for a in range(1, k - 1):
    for b in range(a + 1, k):
        for c in range(b + 1, k + 1):
            d = gcd(a, b)
            ans_3 += gcd(c, d)
ans_3 *= 6

ans = ans_1 + ans_2 + ans_3
print(ans)

Measured memory_bytes: 9224
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
ans = 0
for i in range(N):
    ans += bisect.bisect_left(A,B[i])*(N-bisect.bisect_right(C,B[i]))
print(ans)

Measured memory_bytes: 105444
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}


int main() {
    ll a;
    cin >> a;
    string b;
    cin >> b;
    ll b100 = (b[0]-'0')*100+(b[2]-'0')*10+(b[3]-'0');
    cout << a*b100/100 << endl;
}


Measured memory_bytes: 3636
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

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

int main() {

    int N;
    cin >> N;

    string S;
    cin >> S;

    int cnt = 0;
    S.erase(unique(S.begin(), S.end()), S.end());
    

    cout << S.size() << endl;

    return 0;
}





















































Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	998244353

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

int main()
{
	int n;
	cin >> n;
	n %= 10;

	if (n == 3)
		printf("bon");
	else if(n == 0 || n == 1 || n == 6 || n == 8)
		printf("pon");
	else
		printf("hon");

	return 0;
}

Measured memory_bytes: 3256
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::min;

fn main() {
    input! {
        N: usize,
        K: usize,
        x: [i64; N],
    }
    let mut ans = 1 << 60;
    for i in 0..(N - K + 1) {
        let left = x[i];
        let right = x[i + K - 1];
        if right <= 0 {
            ans = min(ans, left.abs());
        } else if left >= 0 {
            ans = min(ans, right);
        } else {
            if left.abs() > right.abs() {
                ans = min(ans, 2 * right.abs() + left.abs());
            } else {
                ans = min(ans, 2 * left.abs() + right.abs());
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;

int main(){
	int n;
	while(cin >> n) {
		if(n==-1) break;
		int ret = 3130;
		n -= 10;
		if(n<=0) {
			cout << ret << endl;
			continue;
		}
		ret -= 1250;
		n -= 10;
		if(n<=0) {
			ret -= 125*n;
			cout << ret << endl;
			continue;
		}
		ret -= 1400;
		n -= 10;
		if(n<=0) {
			ret -= 140*n;
			cout << ret << endl;
			continue;
		}
		ret -= 160*n;
		cout << ret << endl;
	}
}

Measured memory_bytes: 1160
def main():
    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp%i==0:
                cnt=0
                while temp%i==0:
                    cnt+=1
                    temp //= i
                arr.append([i, cnt])
    
        if temp!=1:
            arr.append([temp, 1])
    
        if arr==[]:
            arr.append([n, 1])
    
        return arr
    N = int(input())
    A = factorization(N)
    count = 0
    if A[0][0] != 1:
        for a in A:
            for i in range(a[1]):
                if a[1] - (i+1) >= 0:
                    a[1] = a[1] - (i+1)
                    count += 1
                else:
                    break
            
    print(count)
    
if __name__ == '__main__':
    main()

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

const int N = 4005;

int n, m, P, L;
bool a[N][N];
short l[N][N], r[N][N], u[N][N], d[N][N];
long long ans;

int T[N];
void upd(int x, int v) { for (; x <= n; x += x & -x) T[x] += v; }
int get(int x) { int res = 0; for (; x > 0; x -= x & -x) res += T[x]; return res; }

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m >> L >> P;
	for (int i = 1; i <= P; ++i) { int u, v; cin >> u >> v; a[u][v] = 1; }

	for (int i = 1; i <= n; ++i) {
		l[i][0] = 0; r[i][m + 1] = m + 1;
		for (int j = 1; j <= m; ++j) l[i][j] = (a[i][j] ? j : l[i][j-1]);
		for (int j = m; j >= 1; --j) r[i][j] = (a[i][j] ? j : r[i][j+1]);
	}
	for (int j = 1; j <= m; ++j) {
		u[0][j] = 0; d[n + 1][j] = n + 1;
		for (int i = 1; i <= n; ++i) u[i][j] = (a[i][j] ? i : u[i-1][j]);
		for (int i = n; i >= 1; --i) d[i][j] = (a[i][j] ? i : d[i+1][j]);
	}
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) {
		d[i][j] = min(d[i][j] - i, r[i][j] - j) - 1;
		u[i][j] = min(i - u[i][j], j - l[i][j]) - 1;
		//cerr << i << ' ' << j << ' ' << d[i][j] << ' ' << u[i][j] << endl;
	}

	for (int h = 1 - m; h <= n - 1; ++h) {
		//cerr << h << endl;
		vector<int> Z;
		vector < pair<int,int> > v;
		for (int i = n; i >= 1; --i) {
			int j = i - h; if (j < 1 || j > m) continue;
			v.push_back(make_pair(i - u[i][j], i));
		}
		sort(v.begin(), v.end());
		for (int i = 0; i <= n; ++i) T[i] = 0;

		int ptr = 0;
		for (int i = 1; i <= n; ++i) {
			int j = i - h; if (j < 1 || j > m) continue;
			//cerr << h << " -> " << i << ' ' << j << endl;
			while(ptr < (int)v.size() && v[ptr].first <= i) {
				int k = v[ptr].second; //cerr << k << ' ' << v[ptr].first << endl;
				upd(k, 1); ++ptr;
			}
			if (!a[i][j] && d[i][j] + i >= i + L - 1) 
				ans +=  (get(min(d[i][j] + i, n)) - 
					 	 get(min(n, i + L - 2)));
		}
	}

	cout << ans << endl;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a>=k){
        cout<<k<<endl;
        return 0;
    }
    else if(b>=k-a){
        cout<<a<<endl;
        return 0;
    }
    else{
        cout<<a+(ll)(k-a-b)*(-1)<<endl;
    }
return 0;
}

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

int main() {
    char ch;
    int count[26] = {};
    
    while(cin >> ch) {
        ch = tolower(ch);
        if (isalpha(ch)) {
            count[ch - 'a']++;
        }
    }
    for (int i = 0; i < 26; i++) {
        printf("%c : %d\n", i + 'a' ,count[i]);
    }
    return 0;
}



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

const int ALPHABET = 26;

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

  int n = s.size();

  vector<int> cnt(ALPHABET);
  for(char c : s) {
    int x = c - 'a';
    cnt[x]++;
  }
  int answer = 1 + n * (n - 1) / 2;

  for (int i = 0; i < ALPHABET; i++) {
    int x = cnt[i];
    answer -= x * (x - 1) / 2;
  }

  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    long double w, h, x, y, a, b;
    cin >> w >> h >> x >> y;

    cout << w * h / 2 << " ";
    if(x == w / 2 && y == h / 2)  cout << 1 << endl;
    else cout << 0 << endl;
  	return 0;
}


Measured memory_bytes: 256
N,K=list(map(int,input().split()))
h=[]
for k in range(K):
    d_i=int(input())
    a=list(map(int,input().split()))
    for i in range(d_i):
        h.append(a[i])
h2=set(h)
ans=N-len(h2)
print(ans)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
const int MOD = 1e9+7;
using namespace std;
typedef long long ll;

ll factor(ll n){
  ll res=1;
  while(n>1){
    res = (res * n) % MOD;
    n--;
  }
  return res;
}

int main()
{
  ll N, M;
  ll res=0;
  cin >> N >> M;

  ll a = max(N,M);
  ll b = min(N,M);
  if(a-b>1){
    cout << 0 << endl;
    return 0;
  }

  if(a-b==1){
    res = (factor(a) * factor(b)) % MOD;
  } else {
    res = (((factor(a) * factor(b)) % MOD) * 2) % MOD;
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *min_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int N; cin >> N;
   V<int> h(N+2);
   h[0] = -1;
   REP(i, N) cin >> h[i+1];
   h[N+1] = 0;

   stack<int> st;
   int ans = 0;
   REP(i, N+2) {
      while (!st.empty() && h[st.top()] >= h[i]) {
         int m = h[st.top()]; st.pop();
         chmax(ans, m * (i - st.top() - 1));
      }
      st.push(i);
   }
   cout << ans << endl;

   return 0;
}



Measured memory_bytes: 4588
// ref. https://drken1215.hatenablog.com/entry/2020/02/09/225300
#include <iostream>
#include <string>

template <typename T>
T nCk(int n, int k) {
  if (k > n) return 0;
  T ret = 1;
  for (auto i = 0; i < std::min(n - k, k); ++i) {
    ret *= n - i;
    ret /= i + 1;
  }
  return ret;
}

template <typename T>
T power(T x, int n) {
  T ans{1};
  while (n) {
    if (n % 2) ans *= x;
    x *= x;
    n >>= 1;
  }
  return ans;
}

using namespace std;
using ll = long long;

string S;
int N, K;


// i: 確定済みの桁数
// k: 残り使用可能な0以外の桁の数
// smaller: i桁目までを見たとき、Nよりも小さいかどうか
ll solve(int i, int k, bool smaller) {
  if (!k)
    return 1;  // 0以外の数が入る桁を使い果たしているので、以降の桁は全て0になるしか無い。
  if (i == N) {  // N桁目まですべて数が確定している
    // ここに来ているということは0以外の桁がまだ余っているので、条件を満たせない
    return 0;
  }

  if (smaller) { // i桁目までで、既にNより小さいことが確定している。
    // これ以降の桁は0...0から9...9の間の数のうち、
    // k個の桁が0でない数であれば良い。
    return nCk<ll>(N - i, k) * power<ll>(9, k);
  }

  // この桁が0の場合、選択肢はないので次の桁に移る。
  if(S[i] == '0') return solve(i+1,k,false);

  // ここまでたどり着いた場合、この桁に0以外の数が入りうるので、場合分けをする。
  // zero: 0を入れる場合、smallerはtrueになる。
  ll zero = solve(i+1,k,true);
  // icchi: 最大値を入れる場合、smallerはfalseのまま。kは一つ減る。
  ll icchi = solve(i+1,k-1,false);
  // others: その他の場合、kは一つ減り、smallerはtrueになる。
  ll others = solve(i+1,k-1,true) * (S[i] - '1');

  return zero + icchi + others;
}

int main() {
  cin >> S >> K;
  N = S.size();
  cout << solve(0, K, false) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define t(x) cerr<<#x<<":"<<x<<'\n';
#define t2(a,n) { cerr<<#a<<" = "; for(int i=0; i<n; ++i){ cerr << a[i] << ' '; } ; cerr <<'\n'; }
#define t3(a){ cerr<<#a<<" = "; for(auto i: a){ cerr<<i<<" "; } cerr<<'\n'; }

ll get(ll n)
{

    switch(n & 3)
    {
    case 0: return n;
    case 1: return 1;
    case 2: return n + 1;
    case 3: return 0;
    }
}


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

	ll a,b;
	cin>>a>>b;
	cout<<(get(b) ^ get(a-1)) << endl;

	#ifdef LOL
	    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin

def main():
    ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

    N, W = ds_in()

    dp = [[0] * (W+1) for i in range(N+1)]
# dp[index][weight]:=valueとしてdp[n]での最大を求める.
    for i in range(N):
    # pre = values.copy()
        w, v = ds_in()  # [weight, value]
        for j in range(W+1):
            if (j-w>=0):
                dp[i+1][j] = max(dp[i][j], dp[i][j-w]+v)
            else:
                dp[i+1][j] = dp[i][j]
    ans = 0
    for i in range(W+1):
        ans = max(ans, dp[N][i])
    print(ans)
    return 0
main()

Measured memory_bytes: 118768
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr <<"\e[91m"<<__func__<<": "<< #x << " = " << x <<"\e[39m"<< "\n"
typedef unsigned long long ll;
const int maxn = 1e7+2;
int a[maxn];

int main()
{
#ifndef ONLINE_JUDGE
    // freopen("../io/in.txt", "r", stdin);
    //freopen("../io/out.txt", "w", stdout);
#endif // ONLINE_JUDGE
    ll ans = 0LL;
    
    int n;
    cin >> n;

    for(int i=1; i<=n; i++) {
        for(int j=i; j<=n; j += i) a[j]++;
    }

    // for(int i=1; i<=n; i++) watch(a[i]);

    for(ll i=1; i<=n; i++) ans += (i*(ll)a[i]);

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 42612
#include <stdio.h>
#include <math.h>

int main(){
	int n; char s[101];
	scanf("%d", &n);
	scanf("%s", s);

	int cout, max = -1 ;
	int memo[26] = { 0 };

	//切る場所
	for (int i = 0; i < n; ++i) {
		cout = 0;
		//check
		for (int j = 0; j <= i; ++j) {
			for (int k = i + 1; k < n; ++k) {

				if (s[j] == s[k]) {
					memo[s[j]-97] = 1;
				}
			}
		}
		for (int j = 0; j < 26; ++j) {
			if (memo[j]) {
				cout++;
			}
			memo[j] = 0;
		}

		max = fmax(max, cout);
	}

	printf("%d", max);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	int K,S,x=0,y=0,z,ANS=0;
	cin>>K>>S;
	for(;;){
		z=S-x-y;
		if(z>=0&&z<=K)ANS++;
		if(x==K&&y==K)break;
		else if(y!=K){
			y++;
		}
		else if(y==K){
			x++;
			y=0;
		}
	}
	cout<<ANS<<endl;
}

Measured memory_bytes: 888
N, K = map(int, input().split())
A = list(map(int, input().split()))

l = 0
r = max(A)
for _ in range(100):
    mid = (r + l + 1) // 2
    count = 0
    for log in A:
        if log > mid:
            count += (log + mid - 1) // mid - 1
    if count <= K:
        r = mid
    else:
        l = mid

print(r)


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

#define pb push_back
#define mp make_pair
#define inside sl<=l&&r<=sr
#define outside r<sl||sr<l
#define INF 1000000009
using namespace std;
typedef long long ll;

double dp[301][301][301];
double n;

struct ind {
	int i, j, k;
};

inline bool operator<(const ind& a, const ind& b){
	int num1 = a.i + a.j*2 + a.k*3;
	int num2 = b.i + b.j*2 + b.k*3;
	return num1 < num2;
}

double get(int i, int j, int k){
	if (i == -1 || j == -1 || k == -1) return 0;
	if (dp[i][j][k] == INF) assert(0);
	if (i > 300 || j > 300 || k > 300) cout << "NASIL OLUR??? " << i << ", " << j << ", " << j << endl;
	return dp[i][j][k]+1;
}

int main(){
	//freopen("stl.gir", "r", stdin);
	
	cin >> n;
	int n1 = 0;
	int n2 = 0;
	int n3 = 0;
	double top = 0;
	for (int i = 0; i < n; i++){
		int a;
		cin >> a;
		top += a;
		if (a == 1) n1++;
		else if (a == 2) n2++;
		else if (a == 3) n3++;
		else assert(0);
	}
	int b1 = n1;
	int b2 = n2;
	int b3 = n3;
	n1 = b1+b2+b3;
	n2 = b2+b3;
	n3 = b3;
	
	//cout << n1 << " " << n2 << " " << n3 << endl;
	
	assert(n1 < 301);
	
	for (int i1 = n1; i1 >= 0; i1--)
	for (int i2 = n2; i2 >= 0; i2--)
	for (int i3 = n3; i3 >= 0; i3--)
		dp[i1][i2][i3] = INF;
	
	dp[0][0][0] = 0;
	
	
	for (int k = 0; k <= n3; k++)
	for (int j = 0; j <= n2; j++)
	for (int i = 0; i <= n1; i++){
		//cout << i << ", " << j << ", " << k << "\n";
		if (i + j*2 + k*3 > top) continue;
		if (i == 0 && j == 0 && k == 0) continue;
		if (i+j+k > n) continue;
		//dp[i][j][k] = (1 + (i/n)*get(i-1, j, k) + (j/n)*get(i+1, j-1, k) + (k/n)*get(i, j+1, k-1))/((i+j+k)/n);
		dp[i][j][k] = ((n-i-j-k)/n + (i/n)*get(i-1, j, k) + (j/n)*get(i+1, j-1, k) + (k/n)*get(i, j+1, k-1))/((i+j+k)/n);
		//cout << " -> " << dp[i][j][k] << endl;
	}
	
	
	cout << setprecision(15) << dp[b1][b2][b3] << endl;
}

Measured memory_bytes: 213248
#include<bits/stdc++.h>
#define N 100005
using namespace std;
typedef long long LL;
char s[N],t[N];
vector<int> p[30];
LL n,m;
int main()
{
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)p[s[i]-'a'].push_back(i);
	for(int i=1;i<=n;i++)p[s[i]-'a'].push_back(i+n);
	m=strlen(t+1);
	LL k=0,q=0;
	for(int i=1;i<=m;i++)
	{
		LL x=t[i]-'a',v=upper_bound(p[x].begin(),p[x].end(),q)-p[x].begin();
		if(v==p[x].size())
		{
			puts("-1");
			return 0;
		}
		q=p[x][v];
		while(q>n)k++,q-=n;
	}
	printf("%lld\n",k*n+q);
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main() {
    long long n, a, b;
    cin >> n >> a >> b;

    if (abs(a-b) % 2) {
        if (n-a < b)
            cout << (n-b+1)+(((n-a)-(n-b+1))/2) << endl;
        else
            cout << b+(((a-1)-b)/2) << endl;
    }
    else {
        cout << (b-a)/2 << endl;
    }
}


Measured memory_bytes: 888
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    char s[15];
    int i, num, smallest = 753;
    scanf("%s", s);

    for (i = 0; s[i + 2] != '\0'; i++)
    {
        num = abs((100 * (s[i] - '0') + 10 * (s[i + 1] - '0') + (s[i + 2] - '0')) - 753);
        if (smallest > num) smallest = num;
    }

    printf ("%d", smallest);

    return (0);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
typedef long long ll;
using namespace std;
int main(void){
    int n,x;
    cin>>n>>x;
    int min=10000;
    int sum=0;
    for(int i=0;i<n;i++){
        int m;
        cin>>m;
        sum+=m;
        if(m<min){
            min=m;
        }
    }
    int ans=0;
    ans=(x-sum)/min+n;
    cout<<ans<<endl;
}

Measured memory_bytes: 384