akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;

ll mod_pow(ll a,ll b,ll mod){
    a%=mod;
    if(b==0)return 1;
    if(b==1)return a;
    ll res=mod_pow(a,b/2,mod)%mod;
    res*=res; res%=mod;
    if(b%2)res*=a;
    return res%mod;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int cnt=0;
    for(char c:s){
        if(c=='1')cnt++;
    }
    int p=0,q=0;
    for(int i=0;i<n;i++){
        p=(p*2+(s[i]=='1'))%(cnt+1);
        if(cnt>1)q=(q*2+(s[i]=='1'))%(cnt-1);
    }
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            if(cnt==1){
                printf("0\n");
            }
            else{
                int qq=q;
                qq-=mod_pow(2,n-1-i,cnt-1);
                qq%=(cnt-1);
                if(qq<0)qq+=(cnt-1);
                int res=1;
                while(qq){
                    res++;
                    int u=__builtin_popcount(qq);
                    qq%=u;
                }
                printf("%d\n",res);
            }
        }
        else{
            int qq=p;
            qq+=mod_pow(2,n-1-i,cnt+1);
            qq%=(cnt+1);
            if(qq<0)qq+=(cnt+1);
            int res=1;
            while(qq){
                res++;
                int u=__builtin_popcount(qq);
                qq%=u;
            }
            printf("%d\n",res);
        }
    }
}


Measured memory_bytes: 3840
import math
a,b,h,m=map(int,input().split())
h%=12
ad=360*(m/60)
bd=360*(h/12)+30*(m/60)
dig=abs(ad-bd)
c=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(dig)))
print(c)

Measured memory_bytes: 9500
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 1e18+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
    int d, t, s;
    cin >> d >> t >> s;
    int dis = t * s;
    if(dis >= d)
    	cout << "Yes\n";
    else
    	cout << "No\n";

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct P{
  int h,w;
  P(int h,int w):h(h),w(w){}
};
bool operator <(const P& a,const P& b){
  int la = a.h*a.h+a.w*a.w;
  int lb = b.h*b.h+b.w*b.w;
  return (la<lb) || (la==lb && a.h < b.h);
}
bool operator == (const P& a,const P& b){
  return a.h==b.h && a.w==b.w;
}

int main(){
  vector<P> R;
  for(int i=1;i<=160;++i)
    for(int j=i+1;j<=160;++j)
      R.push_back(P(i,j));
  sort(R.begin(),R.end());
  int h,w;
  while(cin>>h>>w,h||w){
    P T = P(h,w);
    int l = 0;
    int r = R.size();
    for(int i=0;i<20;++i){
      int m = (l+r)/2;
      if(T < R[m]) r = m;
      else l = m;
    }
    if(T==R[l]) ++l;
    cout << R[l].h << " " << R[l].w << endl;
  }
  return 0;
}

Measured memory_bytes: 1328
# -*- coding:utf-8 -*-

class UnionFindVerDepth():
    def __init__(self, N):
        """ N個のノードのUnion-Find木を作成する """
        # 親の番号を格納する。自分が親だった場合は、自分の番号になり、それがそのグループの番号になる
        self._parent = [n for n in range(0, N)]
        # グループの深さ
        self._depth = [1] * N

    def find_root(self, x):
        """ xの木の根(xがどのグループか)を求める """
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x]) # 縮約
        return self._parent[x]

    def unite(self, x, y):
        """ xとyの属する集合を併合する """
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        # 小さい方を大きい方に併合させる（木の偏りが減るので）
        if self._depth[gx] < self._depth[gy]:
            self._parent[gx] = gy
        else:
            self._parent[gy] = gx
            if self._depth[gx] == self._depth[gy]: self._depth[gx] += 1

    def get_depth(self, x):
        """ xが属するグループの深さを返す """
        return self._depth(self.find_root(x))

    def is_same_group(self, x, y):
        """ xとyが同じ集合に属するか否か """
        return self.find_root(x) == self.find_root(y)


def solve():
    """戦略
    □ □ □ □ □ □ □ □ □ □ □ □ □ □ □
    |_| |_| |_|     |_| | |_|_|_|
                    |___|
     1   2   3  4 5   6      7   

    上みたいなものを考えたらわかるが、答えはグループの数(=7)。

    Union-Findを使えばよい。

    """
    N, M = list(map(int, input().split()))
    X, Y, Z = [], [], []
    uf = UnionFindVerDepth(N)
    for i in range(M):
        x, y, z = list(map(int, input().split()))
        x, y = x-1, y-1
        uf.unite(x, y)
    
    # 答えは、(グループの数) 
    ans = 0
    for i in range(N):
        if uf.find_root(i) == i:
            ans += 1
    
    print(ans)


if __name__ == "__main__":
    solve()


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,num2[200010],num5[200010],nump[200010],num[20][100][100];
string s;

int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>s;
		LL val=0,cnt=-1,pos;
		rep(j,s.size())
		{
			if(s[j]=='.')
			{
				pos=j;
				cnt=s.size()-j-1;
				break;
			}
			val=val*10+s[j]-'0'; 
		}
		LL cur=s.size()-1;
		if(cnt!=-1)
		while(s[cur]=='0')
		{
			cur--;
			cnt--;
		}
		//cout<<i<<' '<<cnt<<"stane\n";
		if(cnt!=-1) for(int j=pos+1;j<=cur;j++) val=val*10+s[j]-'0';
		else cnt=0;
		LL cnt2=0,cnt5=0;
		while(val%2==0)
		{
			val/=2;
			cnt2++;
		}
		while(val%5==0)
		{
			val/=5;
			cnt5++;
		}
		num2[i]=cnt2;
		num5[i]=cnt5;
		nump[i]=cnt;
		//cout<<i<<' '<<cnt<<"stane\n";
	}
	LL ans=0;
	rep(i,n)
	{
		rep(j,10)
		{
			rep(k,20) if(k+num5[i]>=j+nump[i]) ans+=num[j][k][max(0LL,j+nump[i]-num2[i])];
		}
		for(int j=num2[i];j>=0;j--) num[nump[i]][num5[i]][j]++;
		//num[nump[i]][num2[i]][num5[i]]++;
		//cout<<ans<<' '<<nump[i]<<' '<<num2[i]<<' '<<num5[i]<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8408
/*
ABC154C - Distinct or Not
*/

#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
	int n;
	int a[200000];
	int i;
	int isFound = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &(a[i]));
	}

	qsort(a, n, sizeof(int), compare_int);

	for (i = 0; i < n - 1; i++) {
		if (a[i] == a[i + 1]) {
			isFound = 1;
			break;
		}
	}

	if (isFound == 0) {
		printf("YES");
	} else {
		printf("NO");
	}

	return 0;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int n; cin>>n;
    vector<lint> a(n), b(n), c(n), p(n*2);
    rep(i, n){
        cin >> a[i];
        b[i]=a[i]+i; c[i]=-a[i]+i;
    }
    lint ans = 0;
    rep(j, n){
        if(j!=0 && 0<=c[j] && c[j]<p.size()){
            ans += p[c[j]];
        }
        if(0<=b[j] && b[j]<p.size()) p[b[j]]++;
    }
    out(ans);
}

Measured memory_bytes: 11180
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
  int N,ans=0,cnt=0;
  cin>>N;
  if(N<105) cout<<"0"<<endl;
  else if(N>=105){
  for(int i=105;i<=N;i+=2){
    for(int j=1;j<=N;j++){
      if(i%j==0) cnt++;
      if(j==N&&cnt==8) ans++;
    }
    cnt=0;
  }
    cout<<ans<<endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int now=0,n,cnt,num;
int a[N],b[N],fa[N];
int in[N],out[N];
int sz[N];
map<int,int> mp;
int get(int x){
	return fa[x]==x?x:fa[x]=get(fa[x]);
}
void add(int x,int y){
	in[y]++; out[x]++; cnt++;
	x=get(x); y=get(y);
	if (x!=y) sz[y]+=sz[x],fa[x]=y;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		now^=a[i];
		if (!mp[a[i]]) mp[a[i]]=++num;
	}
	for (int i=1;i<=n;i++){
		scanf("%d",&b[i]);
		if (!mp[b[i]]) mp[b[i]]=++num;
	}
	if (!mp[now]) mp[now]=++num;
	++in[mp[now]];
	for (int i=1;i<=num;i++) sz[i]=1,fa[i]=i;
	for (int i=1;i<=n;i++)
		if (a[i]!=b[i])
			add(mp[b[i]],mp[a[i]]);
	int dif=0;
	for (int i=1;i<=num;i++)
		if (out[i]>in[i]||in[i]+1<out[i])
			return puts("-1"),0;
		else if (out[i]!=in[i]) ++dif;
	if (dif>1) return puts("-2"),0;
	for (int i=1;i<=num;i++)
		if (get(i)==i){
			if (sz[i]==1) cnt+=(mp[now]==i);
			else ++cnt;
		}
	printf("%d\n",cnt-1);
}

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

const int maxn = 100009;
int a[maxn], b[maxn], n, ans, sum;

int main() {
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%d", &a[i]);
	for (int i=1; i<=n; i++) scanf("%d", &b[i]);
	for (int i=1; i<=n; i++) {
		sum = 0;
		for (int j=1; j<=i; j++)
			sum += a[j];
		for (int j=i; j<=n; j++)
			sum += b[j];
		ans = max(ans, sum);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	// your code goes here
	int i,n,k,temp,s;
	// i=1;
	s=0;
	cin>>k>>n;
	while(n--){
		cin>>temp;
		s=s+temp;
	}
	if (s>=k){
		cout<<"Yes"<<endl;	
	}
	else{
		cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
read -a list
array=(`for i in ${list[@]}; do echo $i; done | sort -n`)
if [ "${array[0]}" = "1" ] && [ "${array[1]}" = "4" ] && [ "${array[2]}" = "7" ] && [ "${array[3]}" = "9" ]; then
	echo YES
else
	echo NO
fi

Measured memory_bytes: 760
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

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

fn main() {
    let v = read_vec::<usize>();
    let (a,b) = (v[0],v[1]);
    let e = b - a;
    println!("{}",e*(e+1)/2 - b);
}


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

int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

const int mod = 1000000007;
struct mint {
  int x; // typedef long long ll;
  mint(int x=0):x((x%mod+mod)%mod){}
  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(int t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  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;
  }
};

int count(int a){
  int ans=0;
  while(1){
    if(a%2!=0){
      return ans;
    }
    a/=2;
    ans++;
  }
}

int ketaSouwa(int n){
  int a=0;
  while(1){
    if(n/10==0) return a+n;
    a+=n%10;
    n/=10;
  }
}

int main(){
    int n,m;
    cin>>n>>m;
    if(m==0){
      cout<<0<<" "<<0<<endl;
    }else{
    vector<int> p(m+1);
    vector<string> s(m+1);
    rep(i,m) cin>>p[i]>>s[i];
    map<int,bool> mp;
    map<int,int> mp2;
    for (int i = 1; i <= n; ++i) mp[i]=false;
    for (int i = 1; i <= n; ++i)mp2[i]=0;
    int ans1=0,ans2=0;
    rep(i,m){
      if(mp[p[i]]==false&&s[i]=="WA"){
        mp2[p[i]]++;
      }
      else if(mp[p[i]]==false&&s[i]=="AC"){
        mp[p[i]]=true;
        ans1++;
      }else if(mp[p[i]]==true){
        continue;
      }
    }
    for (int i = 1; i <= n; ++i){
      if(mp[i]==true) ans2+=mp2[i];
    }
    cout<<ans1<<" "<<ans2<<endl;
    }
    return 0;
}

Measured memory_bytes: 15488
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#include <climits>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n;

int main() {
    cin >> n;
    int res = floor(sqrt(n))*floor(sqrt(n));
    put(res);
    return 0;
}


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

int N;
int X;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  cin >> N >> X;

  vector<int> a;
  for (int i = 0; i < N; i++) {
    int temp; cin >> temp;
    a.push_back(temp);
    X -= temp;
  }

  int ans = N;
  sort(a.begin(), a.end());

  ans += X/a[0];

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
  cin >> N >> M;
  vector<int> vec(M);
  for(int i = 0; i < M; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  vector<int> div(M - 1);
  
  
 if(N >= M) {
   cout << 0 << endl;
   return 0;
 }
  else {
    for(int i = 0; i < M - 1; i ++) {
      div.at(i) = abs(vec.at(i + 1) - vec.at(i));
    }
    
    sort(div.begin(), div.end());
    
    int sum = 0;
    for(int i = 0; i < M - N; i++) {
      sum += div.at(i);
    }
    
    cout << sum << endl;
    return 0;
  }
}
  
      
      


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#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 FORD(i, a, b) for(int i = a; i >= b; --i)
#define El '\n'
typedef long long int ll;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k%2==0)
	cout<<a-b;
	else
	cout<<b-a;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N, X[101010];
itn L, Q;
int ne[101010][20];

void solve() {
    FOR(N) {
        ne[i][0] = lower_bound(X + i, X + N, X[i] + L + 1) - 1 - X;
    }
    FOR(19) {
        FOR(x, N) {
            ne[x][i + 1] = ne[ne[x][i]][i];
        }
    }
    while (Q--) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if (a > b)
            swap(a, b);

        int ans = 0;
        for (int i = 19; i >= 0; i--) {
            if (ne[a][i] < b) {
                a = ne[a][i];
                ans += 1ll << i;
            }
        }
        cout << ans + 1 << endl;
    }
}

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

    cin >> N;
    FOR(N)
    cin >> X[i];
    cin >> L >> Q;

    solve();
    return 0;
}


Measured memory_bytes: 17408
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

import collections

c = collections.Counter(a)

for i in range(n):
    print(c[i+1] if (i+1) in c else 0)

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

# define All(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using ull = unsigned long long;
using ld  = long double;


//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

    ll k, n;
    cin >> k >> n;

    vector <ll> a(n);
    for (auto& ai: a) {
        cin >> ai;
    }


    ll ans = INT_MAX;

    for (int i=0; i<n-1; i++) {
        ans = min(ans, k - (a[i+1]-a[i]));
    }

    ans = min(ans, (a[n-1]-a[0]));

    cout << ans << endl;

    return 0;
}


//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Measured memory_bytes: 1792
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ");
//#define double long double

using namespace std;

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }

const int MOD = 998244353;
const ll INF = 1e17;
const int INT_INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

int N;
string X;

vector<int>divs;
void init() {
	FOR(i, 1, N + 1) {
		if (N%i == 0 && (N / i) % 2 == 1) {
			divs.pb(i);
		}
	}
}
int dp[200020][2];
ll ans;
void calc() {
	vector<int>values;
	int M = divs.size();
	REP(i, M) {
		int k = divs[i];
		//cout << "k:" << k << endl;
		string S = X.substr(0, k);
		dp[0][0] = 1, dp[0][1] = 0;
		if (S[0] == '1')dp[0][1] = 1;
		FOR(j, 1, k) {
			if (S[j] == '1') {
				dp[j][0] = 1;
				dp[j][1] = dp[j - 1][0] + dp[j - 1][1] * 2 % MOD;
			}
			else {
				dp[j][0] = 1;
				dp[j][1] = dp[j - 1][1]*2%MOD;
			}
			dp[j][0] %= MOD; dp[j][1] %= MOD;
			//cout << "j:"; pe(j); pe(dp[j][0]); print(dp[j][1]);
		}
		int tmp = dp[k - 1][1];
		string str;
		string Srev;
		REP(j, S.size()) {
			if (S[j] == '1')Srev += '0';
			else Srev += '1';
		}
		for (int j = 0;; j++) {
			if (str.size() >= X.size())break;
			if (j & 1)str += Srev;
			else str += S;
		}
		//print(str);
		if (str <= X)tmp++;
		tmp %= MOD;
		//pe(divs[i]); print(tmp);
		REP(j, i) {
			if (divs[i] % divs[j] == 0) {
				tmp += MOD - values[j];
				tmp %= MOD;
			}
		}
		values.push_back(tmp);
		ans += tmp*(2*k%MOD); ans %= MOD;
	}
	print(ans);
}

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

	cin >> N >> X;
	init();
	calc();
}


Measured memory_bytes: 4280
# -*- coding: utf-8 -*-
import numpy as np

A_list = []
for i in range(3):
    A, B, C = map(int, input().split())
    A_list.append([A, B, C])
N = int(input())
for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A_list[j][k] == b:
                A_list[j][k] = 0

A_array = np.array(A_list)

ans = "No"
if 0 in np.sum(A_array, axis=0):
    ans = "Yes"

if 0 in np.sum(A_array, axis=1):
    ans = "Yes"

if A_array[0][0] + A_array[1][1] + A_array[2][2] == 0:
    ans = "Yes"

if A_array[0][2] + A_array[1][1] + A_array[2][0] == 0:
    ans = "Yes"

print(ans)

Measured memory_bytes: 12504
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

 int n;
 vector<int> ans;
 vector<int> c;
 using Graph = vector<vector<int>>;
 Graph G;
 void dfs(int v, int p,int &iter)
 {
     
     ans[v] = c[iter];
    // cerr <<"ans="<<ans[v]<<"cnt="<< iter << endl;
     for (auto nv : G[v])
     {
         if (nv == p)
             continue;
         dfs(nv, v,++iter);
     }
}
int main() {
   
    cin >> n;
    G.assign(n, vector<int>());

    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
        //cerr << G[a] << endl;
    }
   // cerr<<G[1]<<endl;
    c.resize(n);
    for (int i = 0; i < n; i++)
    {
        cin>>c[i];
    }
   
    sort(c.rbegin(), c.rend());
    ans.resize(n);
    int iter=0;
    dfs(0, -1,iter);
    ll sum=0;
    ll maxc=0;
    for(int i=0;i<n;i++){
        sum+=c[i];
        if(c[i]>=maxc){
            maxc=c[i];
        }
    }
    sum-=maxc;
    cout<<sum<<endl;
   for(auto v: ans) cout<<v<<" ";
    printf("\n");

    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<stdio.h>
using namespace std;

bool p[50050];

void erato(){
	fill(p, p+50050, true);
	p[0] = p[1] = false;

	for(int i=0; i *i < 50050; i++){
		if(!p[i]) continue;
		for(int j = i + i; j < 50050; j+= i){
			p[j] = false;
		}
	}
}

int input;
int big, small;

int main(){
	erato();
	while(scanf("%d", &input) != EOF){
		big = small = input;
		big++; small--;
		while(1){
			if(p[small] && p[big]) break;
			if(!p[small])small--;
			if(!p[big])big++;
		}
		cout << small << " " << big << endl;
	}
}

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

bool e[150010];

void erato(){
	fill(e, e+150010, true);
	e[0] = e[1] = false;

	for(int i=0; i < 150010; i++){
		if(!e[i]) continue;
		for(int j=i+i; j < 150010; j += i){
			e[j] = false;
		}
	}
}

int main(){
	erato();

	int n, p;
	int primeNumbers[100];
	int addPrimeNumbers[100010];
	while(cin >> n >> p, n != -1 && p != -1){
		while(1){
			if(e[++n]) break;
		}
		for(int i=0; i < p; n++){
			if(e[n]){
				primeNumbers[i] = n;
				i++;
			}
		}
		int countPrimeNumbers = 0;
		for(int i=0; i < p; i++){
			for(int j=i; j < p; j++){
				addPrimeNumbers[countPrimeNumbers] =  primeNumbers[i] + primeNumbers[j];
				countPrimeNumbers++;
			}
		}
		sort(addPrimeNumbers, addPrimeNumbers + countPrimeNumbers);

		cout << addPrimeNumbers[p-1] << endl;
	}
}

Measured memory_bytes: 1344
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#ifdef _DEBUG
#define dd(x) cout << #x << " : " << x << endl
#else
#define dd(x)
#endif
using namespace std;
using ll = int64_t;

int main(){
    int x, y; cin >> x >> y;

    rep(i, x+1) {
        int j = x - i;
        if(2*i + 4*j == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define pop(v) (v).back(); (v).pop_back()
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

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

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

    char a,b;
    cin>>a>>b;
    if(a<b)co("<");
    else if(a==b)co("=");
    else co(">");
}

Measured memory_bytes: 256
/*
 _ _ _   _    _   _    _   _ _ _   _    _   _ __ _   __       __
|  _ _| | |  | | | |  | | |  _  | | |  | | |  __  | |   \   /   |
| |_ _  | |__| | | |  | | | |_| | | |__| | | |__| | | |\ \_/ /| |
|_ _  | |  __  | | |  | | |  _ <  |  __  | |  __  | | | \   / | |
 _ _| | | |  | | | |__| | | |_| | | |  | | | |  | | | |  \_/  | |  _   _   _
|_ _ _| |_|  |_| |_ __ _| |_ _ _| |_|  |_| |_|  |_| |_|       |_| |_| |_| |_|

*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
const int  MOD=1000000007;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

void solve(){
    long n,m;
    cin>>n>>m;
    long Wa[n+2];
    vector<bool > Ac(n+2,false);
    memset(Wa,0,sizeof(Wa));
    for(int i=0;i<m;i++){
        long x;
        cin>>x;
        string s;
        cin>>s;
        if(s=="WA"){
            if(!Ac[x]){
                Wa[x]++;
            }
        } else {
            Ac[x]=true;
        }
    }
    long TotAC=0,TotWA=0;
    for(int i=0;i<n+2;i++){
        if(Ac[i]){
            TotAC++;
            TotWA+=Wa[i];
        }
    }
    cout<<TotAC<<" "<<TotWA<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t = 1;
    // cin>>t;
    for (long int tt = 1; tt <= t; tt++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4440
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	int ans = 0;
	rep(i, N) {
		int A = i + 1;
		string s = to_string(A);

		if (s[s.size() - 1] == '0')
			continue;
		if (s[s.size() - 1] == s[0])
			ans++;
		int B = (s[s.size() - 1] - '0') * 10 + s[0] - '0';
		//cout << B << endl;
		int c = 1;
		while (B <= N) {
			ans += c;
			c *= 10;
			B = (s[s.size() - 1] - '0') * 10 * c + c * 10 - 10 + s[0] - '0';
		}
		B = (s[s.size() - 1] - '0') * c * 10 + s[0] - '0';
		//if (A < 1000)
		//	cout << B << " ";
		M = N - B % 10;
		B -= B % 10;

		ans += max(0LL, (M - B + 10) / 10);
		//if (A < 1000)
		//	cout << A << " " << B << " " << ans << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {

  int H ,W,i,j;

  while(1) {
    scanf("%d %d",&H, &W);
    if(H == 0 && W == 0) {
      break; 
    }

    for (j=1; j<=H; j++) {
      for(i=1; i<=W; i++) {
	if(j == 1 || j == H) {
	  printf("#");
	} else if (j !=1 && j !=H && i==1 || i==W) {
	  printf("#");
	} else {
	  printf(".");
	}
      }

      printf("\n");
    }
    printf("\n");
  }
  return 0;
}



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

using namespace std;

int main()
{
   string s;
   cin>>s;
   
   if(s[2]==s[3] && s[4]==s[5])
   {
       cout<<"Yes"<<endl;
   }
   else
   {
       cout<<"No"<<endl;
   }
   
   return 0;
}

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string s = Console.ReadLine();
        int K = int.Parse(Console.ReadLine());
        // Console.WriteLine(UsingList(s, K));
        Console.WriteLine(UsingHashSetOrderBy(s, K));
        // Console.WriteLine(UsingSortedSet(s, K));
    }

    // List→IEnumerable→IOrderedEnumerable
    static string UsingList(string s, int K)
    {
        List<string> list = new List<string>();
        for (int len = 1; len <= Math.Min(s.Length, 5); len++)
        {
            for (int i = 0; i <= s.Length - len; i++)
            {
                list.Add(s.Substring(i, len));
            }
        }
        var list_d = list.Distinct();
        var ranking = list_d.OrderBy(i => i);
        return ranking.ElementAt(K - 1);
    }

    // HashSet→IOrderedEnumerable
    static string UsingHashSetOrderBy(string s, int K)
    {
        HashSet<string> hs = new HashSet<string>();
        for (int len = 1; len <= Math.Min(s.Length, 5); len++)
        {
            for (int i = 0; i <= s.Length - len; i++)
            {
                hs.Add(s.Substring(i, len));
            }
        }
        var ranking = hs.OrderBy(i => i);
        return ranking.ElementAt(K - 1);
    }

    // SortedSetのみ！
    static string UsingSortedSet(string s, int K)
    {
        SortedSet<string> ss = new SortedSet<string>();
        for (int len = 1; len <= Math.Min(s.Length, 5); len++)
        {
            for (int i = 0; i <= s.Length - len; i++)
            {
                ss.Add(s.Substring(i, len));
            }
        }
        return ss.ElementAt(K - 1);
    }
}


Measured memory_bytes: 13780
package main
 
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
 
func main() {
	N := scanInt()
	P := scanIntSlice(N)
	Q := scanIntSlice(N)
 
	ns := make([]int, N)
	for i := 0; i < N; i++ {
		ns[i] = i + 1
	}
 
	var a, b int
	index := 1
	next := true
	for {
		if equalSlice(ns, P) {
			a = index
		}
		if equalSlice(ns, Q) {
			b = index
		}
 
		ns, next = nextPermutation(ns)
		index++
 
		if !next {
			break
		}
	}
 
	fmt.Println(abs(a - b))
}
 
func nextPermutation(ns []int) ([]int, bool) {
	k := -1
	for i := len(ns) - 2; i >= 0; i-- {
		if ns[i] < ns[i+1] {
			k = i
			break
		}
	}
 
	if k == -1 {
		return ns, false
	}
 
	l := k + 1
 
	for i := len(ns) - 1; i >= l; i-- {
		if ns[k] < ns[i] {
			l = i
			break
		} else {
			l = -1
		}
	}
 
	if l == -1 {
		return ns, false
	}
 
	ns[k], ns[l] = ns[l], ns[k]
 
	ns = append(ns[:k+1], reverse(ns[k+1:])...)
	return ns, true
}
 
func reverse(ns []int) []int {
	rns := make([]int, len(ns))
	for i, v := range ns {
		rns[len(rns)-i-1] = v
	}
	return rns
}
 
func equalSlice(a, b []int) bool {
	if len(a) != len(b) {
		return false
	}
 
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
 
	return true
}
 
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}
 
// --------------- BASE DEFINITIONS ---------------

var sc = bufio.NewScanner(os.Stdin)
 
func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
 
func scanIntSlice(n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt()
	}
 
	return is
}


Measured memory_bytes: 2408
#include<stdio.h>
#include<iostream>

using namespace std;

int N;
int num[10];
bool flag = false;

void dfs(int a, int b, int cnt){
    if(cnt==10) flag = true;
    if(a < num[cnt]) dfs(num[cnt], b, cnt+1);
    if(b < num[cnt]) dfs(a, num[cnt], cnt+1);
}

int main(){
    scanf("%d\n", &N);
    for(int i=0; i<N; i++){
        flag = false;
        for(int j=0; j<10; j++) scanf("%d", num+j);
        dfs(0,0,0);
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <cmath>
using namespace std;
 
void insertionSort(int A[], int N) {
 
    for(int k=0;k<N;k++) {
        cout << A[k];
        if(k!=N-1) {
            cout << " ";
        }
    }
        cout << endl;
 
    for(int i=1;i<N;i++) {
        int v = A[i];
        int j = i - 1;
        while(j>=0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
 
        for(int k=0;k<N;k++) {
            cout << A[k];
            if(k!=N-1) {
                cout << " ";
            }
        }
        cout << endl;
    }
}
 
 
int main(void) {
 
    int n;
    cin >> n;
 
    int a[n];
    for(int i=0;i<n;i++) {
        cin >> a[i];
    }
 
    insertionSort(a, n);
}
 

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
    ll x; cin >> x;
    ll t = x / 500;
    ll d = x % 500;
    ll c = d / 5;
    cout << 1000 * t + 5 * c << endl;
    return 0; 
}

Measured memory_bytes: 256
// Learn more about F# at http://fsharp.org
open System
open System.Net.NetworkInformation

type ll=int64
let ll=int64

let flip f a b = f b a
let add x y= x+y


    
[<EntryPoint>]
let main argv =
    let [|a;b|]= stdin.ReadLine().Split(' ')|>Array.map int
    let _=printfn "%d" ( a*b-a-b+1)
    
    0 // return an integer exit code



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

int gcd(int a, int b)
{
    int c;

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

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int main(void){
    int n, countR = 0, countB = 0;
    char c;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> c;
        if(c == 'R') countR++;
        else countB++;
    }
    if(countR > countB) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, p: "List[int]"):
    ret = sum(p) - max(p) // 2
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>

using ll = long long;

using namespace std;

const int MAX = 1005;
char sl[MAX][MAX];

const int mod = 1e9 + 7;

int main() {
    int h, w;
    cin >> h >> w;
    
    vector<vector<ll> > dp(h, vector<ll>(w));
    
    for (int i=0; i<h; i++) {
        string s;
        cin >> s;
        for (int j=0; j<w; j++) {
            sl[i][j] = s[j];
        }
    }
    
    dp[0][0] = 1;
    for (int i=1; i<w; i++) {
        if (sl[0][i] == '.') {
            dp[0][i] = dp[0][i-1];
        } else {
            dp[0][i] = 0;
        }
    }
    
    for (int i=1; i<h; i++) {
        if (sl[i][0] == '.') {
            dp[i][0] = dp[i-1][0];
        } else {
            dp[i][0] = 0;
        }
    }
    
    dp[0][0] = 0;
    
    for (int row=1; row<h; row++) {
        for (int col=1; col<w; col++) {
            if (sl[row][col] == '.') {
                dp[row][col] = dp[row-1][col] + dp[row][col-1];
                if (dp[row][col] >= mod) {
                    dp[row][col] -= mod;
                }
//                cout << dp[row][col] << "\n";
            }
        }
    }
    
    cout << dp[h-1][w-1] << "\n";
//    for (int i=0; i<h; i++) {
//        for (auto j : dp[i]) {
//            cout << j << " ";
//        }
//    }
    
    
    return 0;
}




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

using namespace std;

int a[2019], b[2019];

int main()
{
    long long ans = 0LL;
    char g = getchar();
    while (g > '0' && g <= '9')
    {
        int x = g - '0';
        ++b[x];
        for (int i = 0; i < 2019; ++i)
            b[(i * 10 + x) % 2019] += a[i];

        ans += 1LL * b[0];
        for (int i = 0; i < 2019; ++i)
            a[i] = b[i], b[i] = 0;
        g = getchar();
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<climits>
#include<cmath>
#include<iomanip>

using namespace std;

long long ans(long long K, long long A, long long B, long long h){
    return 0;
}

int main(void){
    long long K, A, B;
    cin >> K >> A >> B;
    if((B - A) <= 2 || K + 1 <= A){
        cout << 1 + K << endl;
        // cout << "A" << endl;
        return 0;
    }
    long long h = A - 1;
    if((K - h) % 2 != 0) h++;
    cout << 1 + h + (B - A) * (K - h) / 2 << endl;
    // cout << "B" << endl;
    return 0;
}

Measured memory_bytes: 256
import math
def main():
  a=int(input())
  b=int(input())
  c=int(input())
  x=int(input())
  ans=0
  for i in range(0,a+1):
    for j in range(0,b+1):
      for k in range(0,c+1):
        if i*500+j*100+50*k==x:
          ans+=1
  print(ans)
  
main()


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

long count(long n, long x) {
    long count = 0;
    if(n==-1) return 0;
    return n/x + 1;
}
int main() {
    long a,b,x; cin >> a >> b >> x;
    cout << (count(b,x) - count(a-1,x)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define forin(x,y) for(ll i=x;i<y;i++)
#define vii vector<ll>
#define pii  pair<ll,ll>
#define pb push_back
#define mp make_pair
using namespace std;


ll max_val( ll n, ll w)
{
    
}    
int main()
{
    ios::sync_with_stdio(false);    cin.tie(0);     cout.tie(0);
    ll n,w;         cin>>n>>w;
    vector<vii> mat(n+1);
    for(auto &i :mat)   i.resize(w+1,0);
    vii val(n+1),wt(n+1);
    forin(0,n)
    {
        cin>>wt[i+1]>>val[i+1];
    }
    for(ll i=1;i<n+1;i++)
    {
        for(ll j=1;j<w+1;j++)
        {
            mat[i][j] = max(mat[i-1][j],mat[i][j-1]);
            if(wt[i]<=j)
            {
                mat[i][j] = max(mat[i-1][j],mat[i-1][j-wt[i]] + val[i]);
            }
        }
    }
   cout<<mat[n][w]<<endl;

}


Measured memory_bytes: 79488
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
signed main(){
  ll n,a[1000000],p,f,cun=0;
  cin>>n;
  for(ll i=1;i<=n;i++){
    cin>>a[i];
  }
  for(ll i=1;i<=n;i++){
	if(a[i]==1){
	  p = i;
      f = 0;
      break;
    }else{
      p = 1;
      f = 1;
    }
  }
  for(ll i=1;i<=n;i++){
    if(a[p]==2){
      if(f==1){
        cout<<cun+1<<"\n";
        return(0);
      }else{
      cout<<cun<<"\n";
      return(0);
      }
    }else{
      p = a[p];
      cun++;
    }
  }
  cout<<"-1\n";
  return(0);
}

Measured memory_bytes: 2944
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String w = scan.nextLine();
        String t = scan.next();
        int sum = 0;
        while(!t.equals("END_OF_TEXT")) {
            if (t.length() == w.length()) {
                for (int x = 0; x < t.length(); x++){
                    if (Character.toString(t.charAt(x)).equalsIgnoreCase(Character.toString(w.charAt(x)))) {
                        if (x == t.length() - 1) {
                            sum++;
                        }
                    }
                    else {
                        x = t.length();
                    }
                }
            }
            t = scan.next();
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 26280
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int main(){
    long n,i,j;
    while(cin >> n)
    {
        for(i=1;i<=n;i++)
        {
            cin >> a[i];
        }
        long sum=0;
        for(i=1;i<n;i++)
        {
            if(a[i]>a[i+1])
            {
                sum+=a[i]-a[i+1];
                a[i+1]=a[i];
            }

        }
        cout << sum << "\n";;
    }
    return 0;
}


Measured memory_bytes: 4316
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <cmath>

using namespace std;

int main() {
    size_t n, k;
    cin >> n >> k;
    vector<size_t> p(n, 0);
    for (size_t i = 0; i < n; ++i)
        cin >> p[i];
    size_t x[1001]{};
    for (size_t i = 1; i < 1001; ++i)
        x[i] = i + x[i - 1];
    double b = 0;
    for (size_t i = 0; i < k; ++i) {
        b += double(x[p[i]]) / p[i];
    }
    double c = b;
    for (size_t i = k; i < n; ++i) {
        b -= double(x[p[i - k]]) / p[i - k];
        b += double(x[p[i]]) / p[i];
        c = max(c, b);
    }
    printf("%.8f", c);
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265358979323846264338327950L
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1)
    {
        cerr << name << " = " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args)
    {
        const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
        __f(comma+1, args...);
    }
#else
#define debug(...)
#endif
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll n;
 	cin >> n;
 	vector <ll> vec(n);
 	for (ll i = 0; i < n; i++) cin >> vec[i];
 	ll ans = 0;
 	for (ll i = 0; i < n; i++) {
 		for (ll j = i + 1; j < n; j++) {
 			for (ll k = j + 1; k < n; k++) {
 				if (vec[i] != vec[j] && vec[j] != vec[k] && vec[i] != vec[k]) {
 					if (vec[i] + vec[j] > vec[k]) {
 						if (vec[j] + vec[k] > vec[i]) {
 							if (vec[i] + vec[k] > vec[j]) {
 								ans++;
 							}
 						}
 					}
 				}
 			}
 		}
 	}
 	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3660