akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n;
	cin >> n;
	vector <string> arr(n);
	for (int z=0;z<n;z++){
		cin >> arr[z];
	}
	ll c = 0;
	for (int z=0;z<n;z++){
		for (int x=0;x<arr[z].size()-1;x++){
			if (arr[z][x] == 'A' && arr[z][x+1] == 'B')c++;
		}
	}
	ll ba = 0,ae = 0, bf=0;
	for (int z=0;z<n;z++){
		if (arr[z][0] == 'B' && arr[z][arr[z].size()-1] == 'A') ba++;
		else if (arr[z][0] == 'B') bf++;
		else if (arr[z][arr[z].size()-1] == 'A') ae++;
	}
	if (ba != 0){
		if (ae != 0) {ae--;ba++;}
		if (bf != 0) {bf--;ba++;}
		c += ba-1;
	}
	c += min(ae,bf);
	cout << c << endl;
	cin >> n;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    int sum=0;
    rep(i,n){
        cin >> w[i];
        sum+=w[i];
    }
  //cout << sum << endl;
    int sum2=0;
    rep(i,n){
        sum2+=w[i];
      //cout << sum2 << endl;
        if(sum2>sum/2.0){
            cout << min(sum2-(sum-sum2),-1*(sum2-w[i]-(sum-sum2+w[i]))) << endl;
            break;
        }
     // cout << sum2 << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string n;
    cin >> n;
    if(n[n.size() - 1] == '3'){
        cout << "bon";
    }else if(n[n.size() - 1] == '0' || n[n.size() - 1] == '1' || n[n.size() - 1] == '6' || n[n.size() - 1] == '8'){
        cout << "pon";
    }else{
        cout << "hon";
    }
    return 0;
}


Measured memory_bytes: 3624
N=input().split()

D=int(N[1])
M=int(N[0])


d1=D // 10
d2=D % 10

count=0

for m in range(M+1):
    for i in range(d1+1):
        if d1 == i and i>1:
            for j in range(d2+1):
                if  m ==  i * j and m>0 and j>1:
                    count=count+1
        elif i>1:
            for j in range(10):
                if m == i*j and m>0 and j>1:
                    count=count+1
 
print(count)

Measured memory_bytes: 3064
class UFTree:
    def __init__(self, N):
        self.nodes = [Node(i) for i in range(N)]
        self.N = N
 
    def find_max_child_num(self):
        result = 0
        for i in range(self.N):
            result = max(result, self.nodes[i].child_num)
        return result
 
class Node:
    def __init__(self, ID):
        self.ID = ID
        self.parent = None
        self.child_num = 0
        self.rank = 1
 
    def get_root(self):
        if self.parent is None:
            return self
        
        return self.parent.get_root()
 
    def concat(self, another):
        sr = self.get_root()
        ar = another.get_root()
 
        # is in a same tree.
        if sr.ID == ar.ID:
            return
 
        if sr.rank > ar.rank:
            parent, child = sr, ar
        else:
            parent, child = ar, sr
 
        parent.child_num += child.child_num + 1
        parent.rank = max(parent.rank, child.rank + 1)
        child.parent = parent
 
N, M = map(int, input().split())
tree = UFTree(N)
 
AB = []
for i in range(M):
    l = list(map(int, input().split()))
    AB.append(l)
 
for i in range(M):
    a, b = AB[i][0], AB[i][1]
    a -= 1;
    b -= 1;
 
    tree.nodes[a].concat(tree.nodes[b])
 
print(tree.find_max_child_num() + 1)

Measured memory_bytes: 85152
import java.util.*;

public class Main{
 public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   
   int a = sc.nextInt();
   int b = sc.nextInt();
   int c = sc.nextInt();
   
   int n = 0;
   
   for(int i=0; i<=b-a; i++){
      if(c%(a+i) == 0){
          n++;
      }
    }
    System.out.println(n);
 }
}

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

using namespace std;

bool cmp(int a,int b){
    return abs(a)>abs(b);
}

int main()
{
    ios_base::sync_with_stdio(false);   
    cin.tie(NULL);
    long int M=1000000007;
   
        int n,k;
        cin>>n>>k;
        long int a[n];
        long long ans=1;
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n,cmp);
        for(int i=0;i<k;i++){
            ans=(ans*a[i])%M;
        }
        if(ans>=0){
            cout<<(ans+M)%M<<"\n";
        }
        else{
            int x=-1,y=-1,z=-1,w=-1;
            for(int i=k-1;i>=0;i--){
                if(a[i]>0 && x==-1)
                    x=i;
                if(a[i]<0 && y==-1)
                    y=i;
                if(x!=-1 && y!=-1)
                    break;
            }
            for(int i=k;i<n;i++){
                if(a[i]>0 && z==-1)
                    z=i;
                if(a[i]<0 && w==-1)
                    w=i;
                if(z!=-1 && w!=-1)
                    break;
            }
            ans=1;
            if( (x==-1 || w==-1) && (y==-1 || z==-1) ){
                for(int i=n-1;i>=n-k;i--){
                    ans=(ans*a[i])%M;
                }
            }
            else if( x==-1 || w==-1 ){
                for(int i=0;i<k;i++){
                    if(i==y)
                        ans=(ans*a[z])%M;
                    else
                        ans=(ans*a[i])%M;
                }
            }
            else if( y==-1 || z==-1 ){
                for(int i=0;i<k;i++){
                    if(i==x)
                        ans=(ans*a[w])%M;
                    else
                        ans=(ans*a[i])%M;
                }
            }
            else{
                if(a[x]*a[z]>a[y]*a[w]){
                    for(int i=0;i<k;i++){
                        if(i==y)
                            ans=(ans*a[z])%M;
                        else
                            ans=(ans*a[i])%M;
                    }
                }
                else{
                    for(int i=0;i<k;i++){
                        if(i==x)
                            ans=(ans*a[w])%M;
                        else
                            ans=(ans*a[i])%M;
                    }
                }
            }
            cout<<(ans+M)%M<<"\n";
        }
 
}


Measured memory_bytes: 5220
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();
        int x = scan.nextInt();
        if (500 * k >= x) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

ll powa(ll a, ll b, ll c)
{
    a%=c;
    if(a<0)
	a+=c;
    ll res = 1;
    while(b>0)
    {
        if(b&1)
            res*=a, res%=c;
        a*=a, a%=c;
        b>>=1;
    }
    return res;
}

int main()
{
  FAST/**/
   
   ll n;
   cin>>n;
   
   if(n == 1)
   {
       cout<<1;
       return 0;
   }
   
   pair<ll,ll> ed[n-1];
   rep(n-1)
   {
       ll a,b;
       cin>>a>>b;
       ed[i] = mp(min(a,b),max(a,b));
   }
   
   ll ans = 0;
   rep(n-1)
   {
       ll l = ed[i].ff;
       ll r = ed[i].ss;
       ans-=(l*(n-r+1));
   }
   
   ans+=(n*(n+1)*(n+1))/2;
   ans-=(n*(n+1)*(2*n+1))/6;
   cout<<ans<<"\n";
   
   return 0;        
}  
  
          
   

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

int main()
{
    string S , T , U ;
    cin>>S>>T;
    int A=S.size(),B=T.size() ;
    cin>>A>>B;
    cin >>U;
    if (U==S){
        cout <<A-1<<"  "<<B;}
    else {
        cout << A <<"  "<<B-1;}
    
    
        
    
    
           return 0; 
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  string s;
  Int k;
  cin>>s>>k;
  k--;

  Int n=s.size();
  set<string> ss;
  for(Int j=1;j<=10;j++){
    for(Int i=0;i+j<=n;i++){
      ss.emplace(s.substr(i,j));      
    }
  }
  //cout<<ss.size()<<endl;
  //for(string a:ss) cout<<a<<endl;
  auto latte=ss.begin();
  for(Int i=0;i<k;i++){
    ++latte;
  }
  cout<<*latte<<endl;
  return 0;
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;

  int ans = 0;
  for (int i = 0; i < 1000; ++i) {
    int k = i;
    int d[3];
    d[2] = k % 10, k /= 10;
    d[1] = k % 10, k /= 10;
    d[0] = k;

    int p = 0;
    for (int j = 0; j < n; ++j) {
      while (j < n && s[j] - '0' != d[p])
        ++j;
      if (s[j] - '0' == d[p])
        ++p;
      if (p == 3)
        break;
    }
    if (p == 3)
      ++ans;
  }
  cout << ans << endl;
}

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

int main(int argc,char* argv[]){
        char b;
        scanf("%c",&b);
        switch(b){
                case 'A':
                printf("T\n");
                break;
                case 'T':
                printf("A\n");
                break;
                case 'C':
                printf("G\n");
                break;
                default:
                printf("C\n");
                break;
        }

        return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <map>
#include <cmath>
#include <vector>

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

typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main() {
    int n; cin >> n; 

    vector<int> x(n);
    rep (i, n) {
        cin >> x[i];
    }

    ll mi = 1000000000000;
    rep (i, 100) {
        ll hp = 0;
        rep (j, n) {
            int p = i + 1; 
            hp += (x[j] - p) * (x[j] - p);
        }
        mi = min(hp, mi);
    }
    cout << mi << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE MultiWayIf #-}
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

po :: (Integral a) => a
po = 1000000007

main :: IO ()
main = do
  getLine
  t <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
  a <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
  let
    range [] _ = []
    range (x:xs) n = if x /= n then (x, 1):range xs x else (x, x):range xs x
    tt = range t 0
    aa = reverse $ range (reverse a) 0
    solve [] _ = 1
    solve _ [] = 1
    solve ((x, n):xs) ((y, m):ys) = if
      | n == 1 -> if (m == 1 && x == y) || x <= y then solve xs ys else 0
      | m == 1 -> if (n == 1 && x == y) || y <= x then solve xs ys else 0
      | otherwise -> min n m * solve xs ys `mod` po
  print $ solve tt aa


Measured memory_bytes: 27132
h,w = input().split()
h = int(h)
w = int(w)
s_list = []
for _ in range(h):
    s = input()
    s_chars =[]
    for char in s:
        s_chars.append(char)
    s_list.append(s_chars)

import numpy as np
ar = np.array(s_list)
ar = np.insert(ar,0,[["."]*w],axis=0)
ar = np.insert(ar,h+1,[["."]*w],axis=0)
ar = np.insert(ar,0,[["."]*(h+2)],axis=1)
ar = np.insert(ar,w+1,[["."]*(h+2)],axis=1)
answer_list = []
for i in range(1,h+1):
    syoukei = ""
    for j in range(1,w+1):
        if ar[i,j] == ".":
            count = 0
            for k in range(i-1,i+2):
                for l in range(j-1,j+2):
                    if ar[k,l] == "#":
                        count += 1
            syoukei += str(count)
        else:
            syoukei += "#"
    answer_list.append(syoukei)

for ans in answer_list:
    print(ans)

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

int N;
vector<vector<int>> G, H, des;
int sum[100010], dep[100010];

int dfs(int key){
	sum[key]=0;
	for(int i=0; i<G[key].size(); ++i){
		if(dep[key]<dep[G[key][i]]){
			H[key].emplace_back(G[key][i]);
			if(N<dep[G[key][i]]){
				dep[G[key][i]]=dep[key]+1;
				des[key].emplace_back(dfs(G[key][i])+1);
			}else{
				des[key].emplace_back(1);
			}
			sum[key] += des[key].back();
		}
	}
	return sum[key];
}

int main() {
	int M;
	cin >> N >> M;
	G.resize(N+1);
	for(int i=0; i<M; ++i){
		int A, B;
		cin >> A >> B;
		G[A].emplace_back(B);
		G[B].emplace_back(A);
	}
	if(M%2==1){
		cout << -1 << endl;
		return 0;
	}
	H.resize(N+1);
	des.resize(N+1);
	for(int i=2; i<=N; ++i) dep[i]=N+5;
	dep[1]=0;
	dfs(1);
	for(int i=1; i<=N; ++i){
		for(int j=0; j<H[i].size(); ++j){
			int C=i, D=H[i][j];
			if(des[i][j]%2==0) swap(C, D);
			cout << C << ' ' << D << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    int K;
    
    cin >> N;
    cin >> K;
    
    int count = 1;
    while(N/K != 0) {
        count++;
        N = N/K;
    }
    
    cout << count << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    int n;

    Main(int n) {
        this.n = n;
    }

    /**
     * 
     * @return greeting message
     */
    public double solve() {

        if (n % 2 == 0) {
            return 0.5;
        } else {
            return 1.0 * (n + 1) / 2 / n;
        }
    }

    public static void main(String[] args) {

        // input
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();

        // solve
        double p = new Main(n).solve();

        // display
        System.out.println(p);
    }
}

Measured memory_bytes: 23764
N,M = gets.split.map(&:to_i) # switches, lights
L = Array.new(M + 1)
(1 .. M).map{|i| k,*c = gets.split.map(&:to_i); L[i] = [k, c] }

P = Array.new(N + 1)
gets.split.map(&:to_i).each.with_index(1){|parity,j| P[j] = parity }

ans = (1 << N).times.count do |sw|
  (1 .. M).all? do |m|
    k, c = L[m]
    c.count{|i| sw[i - 1] == 1 } % 2 == P[m]
  end
end
puts ans


Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){

  int i, j, a, b, n, isstable, minj, tmpi;
  char tmpc;
  char c[36][2];
  char bufc[36], bc[36], sc[36];
  int bufi[36], bi[36], si[36];

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s", c[i]);
    bufc[i] = bc[i] = sc[i] = c[i][0];
    bufi[i] = bi[i] = si[i] = c[i][1] - '0';
  }

  //BubbleSort
  for(i = 0; i < n; i++){
    for(j = n-1; j > i; j--){
      if(bi[j] < bi[j-1]){
        tmpi = bi[j];
        tmpc = bc[j];
        bi[j] = bi[j-1];
        bc[j] = bc[j-1];
        bi[j-1] = tmpi;
        bc[j-1] = tmpc;
      }
    }
  }

  //SelectionSort
  for(i = 0; i < n; i++){
    minj = i;
    for(j = i; j < n; j++){
      if(si[j] < si[minj]){
        minj = j;
      }
    }
    tmpi = si[i];
    tmpc = sc[i];
    si[i] = si[minj];
    sc[i] = sc[minj];
    si[minj] = tmpi;
    sc[minj] = tmpc;
  }

  for(i = 0; i < n-1; i++)
    printf("%c%d ", bc[i], bi[i]);
  printf("%c%d\n", bc[i], bi[i]);
  isstable = 1;
  for(i = 0; i < n; i++)
    for(j = i+1; j < n; j++)
      for(a = 0; a < n; a++)
        for(b = a+1; b < n; b++)
          if(bufi[i] == bufi[j] && (bufc[i] == bc[b] && bufi[i] == bi[b]) && (bufc[j] == bc[a] && bufi[j] == bi[a]))
            isstable = 0;
  if(isstable == 0)printf("Not stable\n");
  else printf("Stable\n");

  for(i = 0; i < n-1; i++)
    printf("%c%d ", sc[i], si[i]);
  printf("%c%d\n", sc[i], si[i]);
  isstable = 1;
  for(i = 0; i < n; i++)
    for(j = i+1; j < n; j++)
      for(a = 0; a < n; a++)
        for(b = a+1; b < n; b++)
          if(bufi[i] == bufi[j] && (bufc[i] == sc[b] && bufi[i] == si[b]) && (bufc[j] == sc[a] && bufi[j] == si[a]))
            isstable = 0;
  if(isstable == 0)printf("Not stable\n");
  else printf("Stable\n");

  return 0;
}

Measured memory_bytes: 608
#include <vector>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
typedef long long ll;
using namespace std;
typedef vector<ll> vll; typedef set<ll> sll; typedef map<ll,ll> mll;
int bitct(long long r) {int c=0; for(; r; r&=r-1) c++; return c;}
long long gcd(long long x, long long y) {return x ? gcd(y%x,x) : y;}
long long choose(long long n, long long q) { if(n==0 || q==0) return 1;
  if (q==1) return n; else return ( choose(n, q-1) * (n-q+1 ) /q); }
template<typename T> ostream& operator << (ostream &o,vector<T> v) {o<<"[";
  int i=0,s=v.size();for(;i+1<s;i++)o<<v[i]<<", ";if(s)o<<v[i];o<<"]";return o;}
template<typename K, typename V> ostream& operator << (ostream &o,
  unordered_map<K, V> m) {o<<"{";for(auto i:m)o<<i.first<<" -> "<< i.second <<
  ", "; o<<"}";return o;}
template<typename K, typename V> ostream& operator << (ostream &o, map<K, V> m)
  {o<<"{";for(auto i:m)o<<i.first<<" -> "<< i.second << ", "; o<<"}";return o;}
template<typename K> ostream& operator << (ostream &o, set<K> m)
  {o<<"{";for(auto i:m)o<<i<< ", "; o<<"}";return o;}
template<typename K> ostream& operator << (ostream &o, unordered_set<K> m)
  {o<<"{";for(auto i:m)o<<i<< ", "; o<<"}";return o;}
template<typename T> ostream& printv(vector<T> v) {int i=0,s=v.size();
  for(;i+1<s;i++)cout<<v[i]<<" ";if(s)cout<<v[i];return cout;}

int main() {
  ios_base::sync_with_stdio(false);
  ll N, M;
  cin >> N;
  multiset<ll> D, T;
  for(int i=0;i<N;i++) {
    ll x;
    cin >> x;
    D.insert(x);
  }
  cin >> M;
  for(int i=0;i<M;i++) {
    ll x;
    cin >> x;
    T.insert(x);
  }

  for(ll val:T) {
    if(D.end() == D.find(val)) {
      cout << "NO" << endl;
      return 0;
    }
    D.erase(D.find(val));
  }

  cout << "YES" << endl;


}

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

int main(){
  int x,a;
  cin>>x>>a;
  if(x<a){
    cout<<0<<endl;
    return 0;
  }else{
    cout<<10<<endl;
    return 0;
  }
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns, MultiWayIf #-}

import Control.Applicative
import Control.Exception (assert)
import Control.Monad
import Data.List
import Debug.Trace (traceShow)

solve :: Int -> (Int, Int, Int)
solve n = head $ do
    x <- [1 .. 3500]
    y <- [1 .. 3500]
    let p = n * x * y
    let q = 4 * x * y - x * n - y * n
    guard $ q > 0
    let (z, r) = p `divMod` q
    guard $ r == 0
    guard $ 4 * x * y * z == n * (x * y + y * z + z * x)
    return (x, y, z)

main :: IO ()
main = do
    n <- readLn :: IO Int
    let (a, b, c) = solve n
    putStrLn . unwords $ fmap show [a, b, c]

Measured memory_bytes: 764
#include<stdio.h>
long long int gcd(long long int a, long long int b)
{
	long long int r = a % b;
	while (r > 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
int main()
{
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	char s[100005], t[100005];
	scanf("%s%s", s, t);
	long long int i, g = gcd(n, m);
	for (i = 0; i < g; i++)
	{
		if (s[n * i / g] != t[m * i / g])
		{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", n * m / g);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    long long  a[4];
    while(cin>>a[0]>>a[1]>>a[2])
    {
      sort(a,a+3);
      if(a[0]==5&&a[1]==5&&a[2]==7)
        cout<<"YES"<<endl;
      else
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 632
#include <stdio.h>
int main(void){
  int n,m,i,num=0;
  int vote[1000];
  double x = 0;
  scanf("%d %d",&n,&m);
  for(i = 0; i < n; i++){
    scanf("%d",&vote[i]);
    x += vote[i];
  }
  x = x/(4*m);
  for(i = 0; i < n; i++){
    if(vote[i] >= x)
      num++;
  }
  if(num >= m)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


Measured memory_bytes: 1628
#include <iostream>

using namespace std;
int main() {
    char S[100];
    cin >> S;
    switch (S[0]) {
        case 'S':
        cout << "Cloudy" << endl;
        break;
        case 'C':
        cout << "Rainy" << endl;
        break;
        case 'R':
        cout << "Sunny" << endl;
        break;
    }
    
    return 0;
}



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

#define _GLIBCXX_DEBUG
#define ll long long

int main() {
  string s;
  cin>>s;
  vector<char> v(s.size());
  for(int i=0;i<s.size();i++) v[i]=s[i];
  
  
  while(1){
    
    v.pop_back();
    
    if(v.size()%2==0){
      int cnt=0;
      for(int j=0;j<v.size()/2;j++) if(v[j]==v[j+v.size()/2]) cnt++;
      if(cnt==v.size()/2){
        cout<<v.size()<<endl;
        break;
      }
    }
  }
}

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

int main(){
	vector<int> data(4);
        vector<char >hugou(3);
int N;
cin>>N;
data[3]=N%10;
N/=10;
data[2]=N%10;
N/=10;
data[1]=N%10;
N/=10;
data[0]=N;
	for(int bit=0;bit<(1<<3);bit++){
       int sum=data[0];
for(int i=1;i<4;i++){
 if(bit&(1<<i-1)){
 sum+=data[i];
hugou[i-1]='+';
}else{
sum-=data[i];
hugou[i-1]='-';
}
}if(sum==7){
cout<<data[0]<<hugou[0]<<data[1]<<hugou[1]<<data[2]<<hugou[2]<<data[3]<<'='<<7<<endl;
break;
}
}
}

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

int main(){
   ll h,w;cin>>h>>w;
   if(h==1 || w==1) cout<<1;
   else if(h*w%2==0) cout<<h*w/2;
   else cout<<h*w/2+1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "stdc++.h"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = max(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

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

	int n, m;
	cin >> n >> m;
	if (n == m)
		cout << "Yes";
	else
		cout << "No";
}


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


template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v){
    if(!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}
//---------

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    int g = 0, p = 0;
    for(auto c : s){
        char hand;
        if(g == p){
            hand = 'g';
            g++;
        }else{
            hand = 'p';
            p++;
        }
        if(hand == 'g' && c == 'p') ans--;
        else if(hand == 'p' && c == 'g') ans++;
        //cout << "hand = " << hand  << " ans = " << ans << endl;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S, T;
    cin >> S >> T;
    
    bool check = true;
    for(long i = 0; i < S.size(); i++) {
        if(S.at(i) != T.at(i)) {
            check = false;
            break;
        }
    }
    if(check && (S.size()+1 == T.size())) {
        cout << "Yes" << endl;    
    }else {
        cout << "No" << endl;
    }
    
}

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

using namespace std;

int main() {
	int n, c;
	int p[110];
	cin >> n >> c;
	int sum = 0;
	int ans = 0;
	for (int i = 0; i < c; i++) {
		cin >> p[i];
		sum += p[i];
	}
	ans += sum / (n + 1);
	if (sum % (n + 1) != 0) {
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3080
line = $stdin.gets.split(" ").map{|v| v.to_i}

result = 0

if (line[0] <=> line[1]) == 1 then
  result += line[0]
  line[0] -= 1
elsif (line[0] <=> line[1]) == 0 then
  result += line[0]
  line[0] -= 1
else
  result += line[1]
  line[1] -= 1
end

if (line[0] <=> line[1]) == 1 then
  result += line[0]
  line[0] -= 1
elsif (line[0] <=> line[1]) == 0 then
  result += line[0]
  line[0] -= 1
else
  result += line[1]
  line[1] -= 1
end
  
puts result

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

const int MAXN=505;

int n,m;
char s[MAXN][MAXN],a[MAXN][MAXN],b[MAXN][MAXN];

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%s",s[i]+1);
    for(int i=1;i<=m;i++)
        a[1][i]=b[n][i]='#';
    for(int i=2;i<n;i++)
        for(int j=1;j<=m;j++){
            if(j&1) b[i][j]='#';
            else a[i][j]='#';
        }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(s[i][j]=='#')
                a[i][j]=b[i][j]='#';
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)
            putchar(a[i][j]=='#'?'#':'.');
        puts("");
    }
    puts("");
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)
            putchar(b[i][j]=='#'?'#':'.');
        puts("");
    }
}


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

int main() {
  char C;
  cin >> C;
  
  // ここにプログラムを追記
  if(C == 'a'){
    cout << "vowel" << endl;
  }
  else if(C == 'i'){
    cout << "vowel" << endl;
  }
  else if(C == 'u'){
    cout << "vowel" << endl;
  }
  else if(C == 'e'){
    cout << "vowel" << endl;
  }
  else if(C == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }

}


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

typedef long long ll;

ll inf = 1e9+7;
ll func[100010] = {0};
ll inv[100010] = {0};

ll mult(ll n, ll m){
	if(m==1) return n%inf;
	else if(m%2==0){
		ll t = mult(n,m/2);
		return (t*t)%inf;
	}else{
		ll t = mult(n,m-1);
		return (t*n)%inf;
	}
}

void functional(ll N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			func[i] = 1;
			inv[i] = 1;
		}
		else{
			func[i] = (i*func[i-1])%inf;
			inv[i] = mult(func[i],inf-2);
		}
	}
}

ll comb(ll n,ll k){
	if(k==0 || n==k) return 1;
	else if(n<k) return 0;
	else return (((func[n]*inv[k])%inf)*inv[n-k])%inf;
}

ll N;
ll A[100010] = {0},C[100010] = {0};

int main(){
	cin >> N;
	ll l,r;
	for(int i=0;i<=N;i++) C[i] = -1;
	for(int i=0;i<=N;i++){
		cin >> A[i];
		if(C[A[i]]==-1) C[A[i]] = i;
		else{
			l = C[A[i]];
			r = i;
		}
	}
	functional(N+1);
	for(int i=1;i<=N+1;i++){
		ll ans = comb(N+1,i) - comb(l+N-r,i-1);
		if(ans<0) ans = (inf+ans)%inf;
		cout << ans << endl;		
	}
}

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

using namespace std;
string str;
int A, ap, i;
int main()
{
    bool ok = 1;
    cin >> str;
    if(str[0] != 'A') ok = 0;
    A = str[1];
    if(A >= 64 && A <= 90) ok = 0;
    for(i = 2; i <= str.length() - 2; i++) {
        A = str[i];
        if(str[i] == 'C') ap++;
        else if(A >= 64 && A <= 90) ok = 0;
    }
    A = str[str.length() - 1];
    if(A >= 64 && A <= 90) ok = 0;
    if(ap != 1) ok = 0;
    if(ok) printf("AC\n");
    else printf("WA\n");
    return 0;
}


Measured memory_bytes: 256
import numpy as np
n,k = map(int,input().split())
a = np.array(list(map(int,input().split())))
a.sort()

p = a[a>0]
zeros = np.count_nonzero(a==0)
m = a[a<0]

#数xが何番目に大きい積か計算。複数ある場合は最大値
def count(x):
  cnt = 0
  #0以上だったらまず0の個数を足す
  if x >= 0:
    cnt += zeros*n #同じ要素の２じょうはあとで除くのでここでは気にせずかける
  #プラス部分のカウント
  #x//pはpをかけてもxを超えない数
  cnt += a.searchsorted(x//p,side='right').sum()
  #マイナス部分のカウント
  #マイナスは書けると大小が逆転する
  cnt += n*len(m) - a.searchsorted(-(-x//m),side='left').sum()
  #二乗を引く
  cnt -= np.count_nonzero(a*a<=x)
  return cnt//2

#十分に大きい範囲
l,r = -10**19,10**19
#r==lになるまで
while r-l>1:
  mid = (r+l)//2
  #真ん中がk以上だったらrを小さくして再挑戦
  if count(mid) >= k:
    r = mid
  else:
    l = mid
print(r)

  
  

Measured memory_bytes: 32304
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

void yoko(vector<string>&s, int y, int x) {
	s[y][x] = '<';
	s[y][x + 1] = '>';
	return;
}

void tate(vector<string>&s, int y, int x) {
	s[y][x] = '^';
	s[y + 1][x] = 'v';
	return;
}


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

	cin >> H >> W >> N >> M;
	vector<string>s(H);
	for (int i = 0; i < H; i++) {
		s[i].resize(W, '.');
	}
	if (H % 2 && W % 2 && N >= 2 && M >= 2) {
		L = N;
		R = M;
		auto t = s;
		N -= 2;
		M -= 2;
		tate(t, H - 2, W - 3);
		tate(t, H - 3, W - 1);
		yoko(t, H - 1, W - 2);
		yoko(t, H - 3, W - 3);
		for (int i = 0; i < W - 4; i += 2) {
			if (N) {
				N--;
				yoko(t, H - 1, i);
			}
		}
		for (int i = 0; i < H - 4; i += 2) {
			if (M) {
				M--;
				tate(t, i, W - 1);
			}
		}
		H--;
		W--;
		//cout << N << " " << M << endl;
		//for (auto i : t)cout << i << endl;
		for (int i = 0; i < H - 1; i += 2) {
			for (int j = 0; j < W - 1; j += 2) {
				if (t[i][j] != '.')continue;
				if (N >= 2) {
					N -= 2;
					yoko(t, i, j);
					yoko(t, i + 1, j);
				}
				else if (N == 1) {
					N--;
					yoko(t, i, j);
				}
				else if (M >= 2) {
					M -= 2;
					tate(t, i, j);
					tate(t, i, j + 1);
				}
				else if (M == 1) {
					M--;
					tate(t, i, j);
				}
			}
		}
		if (!N && !M) {
			cout << "YES\n";
			for (auto i : t)cout << i << endl;
			return 0;
		}
		N = L;
		M = R;
		H++;
		W++;
	}
	if (H % 2) {
		for (int i = 0; i < W - 1; i += 2) {
			if (N) {
				N--;
				yoko(s, H - 1, i);
			}
		}
		H--;
	}
	if (W % 2) {
		for (int i = 0; i < H - 1; i += 2) {
			if (M) {
				M--;
				tate(s, i, W - 1);
			}
		}
		W--;
	}
	for (int i = 0; i < H - 1; i += 2) {
		for (int j = 0; j < W - 1; j += 2) {
			if (N >= 2) {
				N -= 2;
				yoko(s, i, j);
				yoko(s, i + 1, j);
			}
			else if (N == 1) {
				N--;
				yoko(s, i, j);
			}
			else if (M >= 2) {
				M -= 2;
				tate(s, i, j);
				tate(s, i, j + 1);
			}
			else if (M == 1) {
				M--;
				tate(s, i, j);
			}
		}
	}
	if (N || M) {
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	for (auto i : s)cout << i << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main(){

        int n,num;
        char kind;
        int S[14] = {};
        int H[14] = {};
        int C[14] = {};
        int D[14] = {};

        cin >> n;

        for(int i = 1; i <= n; i++){
                cin >> kind >> num;

                switch(kind){
                        case 'S':
                                S[num] = 1;
                                break;

                        case 'H':
                                H[num] = 1;
                                break;

                        case 'C':
                                C[num] = 1;
                                break;

                        default:
                                D[num] = 1;
                                break;

                }
        }

        for(int i = 1; i <= 13; i++)
                if(S[i] == 0) cout << "S " << i << "\n";

        for(int i = 1; i <= 13; i++)
                if(H[i] == 0) cout << "H " << i << "\n";


        for(int i = 1; i <= 13; i++)
                if(C[i] == 0) cout << "C " << i << "\n";

        for(int i = 1; i <= 13; i++){
                if(D[i] == 0){
                        cout << "D " << i << "\n";
                }
        }
        return 0;
}

Measured memory_bytes: 1160
def root(x):
    if(par[x]==x):
        return x
    else:
        r=root(par[x])
        diff_weight[x]+=diff_weight[par[x]]
        par[x]=r
        return r

def weight(x):
    root(x)
    return diff_weight[x]

def diff(x,y):
    return weight(y)-weight(x)

def relate(a,b,w):
    w+=weight(a);w-=weight(b)
    a=root(a)
    b=root(b)
    if(a==b):
        return False
    if rank[a]<rank[b]:
        a,b=b,a
        w=-w
    if rank[a]==rank[b]:
        rank[b]+=1
        par[b]=a
    par[b]=a
    diff_weight[b]=w
    siz[a]+=siz[b]
    return True

def size(a):
    return siz[root(a)]
    
def same(a,b):
    return root(a)==root(b)
    
N,Q=map(int,input().split())
par=[i for i in range(N)]
siz=[1 for _ in range(N)]
rank=[0 for _ in range(N)]
diff_weight=[0 for _ in range(N)]
for i in range(Q):
    query=list(map(int,input().split()))
    if not query[0]:
        X,Y,W=query[1:]
        relate(X,Y,W)
    else:
        X,Y=query[1:]
        if same(X,Y):
            print(diff(X,Y))
        else:
            print('?')


Measured memory_bytes: 12932
import math
  
def main():
  k=int(input())
  cur=0
  for a in range(1,k+1):
    for b in range(1,k+1):
      for c in range(1,k+1):
        cur+=math.gcd(math.gcd(a,b),c)
        
  return cur
print(main())

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if (x-r>=0 && x+r<=W && y-r>=0 && y+r<=H) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 3164
n, k = map(int, input().split())
cnt1, cnt2 = 0, 0
for i in range(1, n + 1):
    if i % k == 0:
        cnt1 += 1
    elif i % (k // 2) == 0:
        cnt2 += 1

print(cnt1 ** 3 if k % 2 == 1 else cnt1 ** 3 + cnt2 ** 3)

Measured memory_bytes: 9052
#include <iostream>

using namespace std;

int main() {
    int A, B, K;
    cin >> A >> B;
    if ((A%2==0 && B%2==0) || (A%2==1 && B%2==1)){
        K = (A+B)/2;
        cout << K << endl;
    }else{
        cout << "IMPOSSIBLE" << endl; 
    }
}


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

int main(){
    int N;
    cin >> N;
    map<string, long long> M;
    vector<string> S(N);
    for(int i = 0; i < N; i++){
        string str;
        cin >> str;
        sort(str.begin(), str.end());
        S[i] = str;
        if(M.count(str))M[str]++;
        else M[str] = 1;
    }
    sort(S.begin(), S.end());
    long long ans = 0;
    
    
    if(M[S[0]] > 1){
        ans += M[S[0]] * (M[S[0]] - 1) / 2;
    }
    for(int i = 1; i < N; i++){
        if(S[i] == S[i - 1])continue;
        ans += M[S[i]] * (M[S[i]] - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

double get_x(double r1, double r2)
{
    return sqrt(pow(r1 + r2, 2) - pow(r1 - r2, 2));
}

int main()
{
    int N;
    cin >> N;
    vector<double> R(N), x(N);
    for (int i = 0; i < N; i++) {
        cin >> R[i];      
    }
    double res = 0;
    for (int i = 0; i < N; i++) {
        double nx = R[i];
        for (int j = 0; j < i; j++) {
            nx = max(nx, x[j] + get_x(R[i], R[j]));
        }
        x[i] = nx;
        res = max(res, x[i] + R[i]);
    }
    printf("%.10f\n", res);
    return 0;
}

Measured memory_bytes: 1252
/*
Original problem: https://atcoder.jp/contests/dp/tasks/dp_q
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const ll mod = 1e9+7;

namespace SOLVE {
	struct fenwick {
		int maxn;
		VLL A; // stores the fenwick tree

		void build(int n) {
			maxn = n;
			A.resize(maxn+1);
		}

		// update x with value v
		// this means i jump UP: all future when jumping down will see it
		void update(int x, ll v) {
			if (x > maxn) {
				return;
			}
			A[x] = max(A[x], v);
			int next = x + (x & -x);
			update(next, v);
		}

		ll query(int x) {
			if (x == 0) {
				return A[0];
			}
			int next = x - (x & -x);
			return max(query(next), A[x]);
		}
	};

    void main() {
        int n;
		cin >> n;

		fenwick tree;
		tree.build(n);

		VI h(n); // height
		VI b(n); // beauty
		
		REP(i,0,n){
			cin >> h[i];
		}
		REP(i,0,n){
			cin >> b[i];
		}

		REP(i,0,n){
			ll best = tree.query(h[i] - 1); // this is the best beauty if considering height below h[i]
			tree.update(h[i], best + b[i]);
		}

		ll ans = tree.query(n);
		cout << ans << endl;
    }
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

Measured memory_bytes: 3328
n = int(input())
s = list(input())
abc_cnt = 0
cnt = 0
i = 0

while(i < n - 2):
    if(s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C'):
        cnt += 1
        if i < n -3:
            i = i+3
        else:
            i += 1
    else:
        i += 1

print(cnt)

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

int main() {
  int n;
  cin>>n;

  rep(i,n){
    rep_in(j,i+1,n){
      int k=0;
      while(true){
        if((i&1<<k) != (j&1<<k)) {
          cout<<(k+1)<<' ';
          break;
        }
        k++;
      }
    }
    cout<<endl;
  }
}

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

using namespace std;

typedef long long int ll;

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

  ll n;
  cin >> n;

  string res = "";
  while (n > 0) {
    int a = n % 26;
    n -= a;
    n /= 26;
    if (a == 0) {
      res.push_back ('z');
      n--;
    }else {
      res.push_back ('a' + a - 1);
    }
  }
  reverse (res.begin(), res.end());

  cout << res << '\n';
}


Measured memory_bytes: 3652
// https://beta.atcoder.jp/contests/abc070

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    sort(a.begin(), a.end());
    auto ans = *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end());
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N,X;
    cin >> N >> X;
    int sum = 0;
    vector<int> m(N);
    rep(i,N){
        cin >> m[i];
        sum += m[i];
    }
    int nokori = X - sum;
    int cnt=N;
    sort(m.begin(), m.end());
    for(int i = 1;; i++){
        if(m[0] * i <= nokori){
            cnt++;
        }else{
            break;
        }
    }
    cout<<cnt<<endl;

    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(int i=0;i<n;i++)
#define double long double
#define mod 998244353
#define F first
#define S second
#define pb push_back

using namespace std;

signed main()
{
	fast;
	int test=1;
	// cin>>test;
	for(int index=0;index<test;index++)
	{
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int t=a/d;
        if(a%d>0) t++;
        int ak=c/b;
        if(c%b>0) ak++;

        if(ak<=t)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
        
        
        
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int N;
vector<vector<vector<double>>> dp;

double dfs( int c1, int c2, int c3 ) {
  // cout << c1 << " " << c2 << " " << c3 << endl;
  if (dp[c1][c2][c3]!=-1) return dp[c1][c2][c3];
  double result = 0;
  if (c1) result += dfs(c1-1,c2,c3) * c1/(c1+c2+c3);
  if (c2) result += dfs(c1+1,c2-1,c3) * c2/(c1+c2+c3);
  if (c3) result += dfs(c1,c2+1,c3-1) * c3/(c1+c2+c3);
  result += (double)N/(c1+c2+c3);
  return dp[c1][c2][c3] = result;
}

int main() {
  cin >> N;
  int count[3] = {}; rep(i,N) { int a; cin >> a; a--; count[a]++; }
  dp.resize(N+1, vector<vector<double>>(N+1, vector<double>(N+1,-1)));
  dp[0][0][0] = 0;
  double result = dfs(count[0], count[1], count[2]);
  cout << setprecision(10) << result << endl;
  return 0;
}

Measured memory_bytes: 216960
n = int(input())
X = list(map(int, input().split()))
sX = sorted(X)
median1 = sX[n//2-1]
median2 = sX[n//2]


if median1 == median2:
    for _ in range(n):
        print(median1)
    exit()
else:
    for x in X:
        if x <= median1:
            print(median2)
        else:
            print(median1)


Measured memory_bytes: 25556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcm(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcm(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcm(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    int n;
    cin >> n;
    rep1(i, 50000) {
        if(floor(i * 1.08) == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 3616
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            long n = long.Parse(Console.ReadLine());
            long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            if (n == 0)
            {
                if (a[0] == 1)
                {
                    Console.WriteLine(1);
                }
                else
                {
                    Console.WriteLine(-1);
                }
                return;
            }
            var b = new long[n + 1];
            b[n] = a[n];
            for (long i = n - 1; i >= 0; i--)
            {
                b[i] = b[i + 1] + a[i];
            }
            var points = new long[n + 1];
            points[0] = 1;
            for (long i = 1; i < n + 1; i++)
            {
                if ((points[i - 1] - a[i - 1]) * 2 <= b[i])
                {
                    points[i] = (points[i - 1] - a[i - 1]) * 2;
                }
                else
                {
                    points[i] = b[i];
                }
                if (points[i] < a[i])
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            Console.WriteLine(points.Sum());
        }
    }
}

Measured memory_bytes: 39136
#include<stdio.h>

int main(void){
  char tmp[101]={'\0'};
  scanf("%s",tmp);
  for(int i=0;tmp[i];i++){
    if(i%2==0){
    if(tmp[i]=='L'){
      puts("No");
      return 0;
    }
    }
    else{
     if(tmp[i]=='R'){
      puts("No");
      return 0;
     }
    }
  }
   puts("Yes");
      return 0;
}
  

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

int abs(int x){
  if(x>0){
    return x;
  }else{
    return -1*x;
  }
}

int main(){
  long long N,K,n,a,b;
  cin >> N >> K;
  n=N/K;
  a=n*K;
  b=a+K;
  if(abs(a-N)>abs(b-N)){
    cout << abs(b-N) << endl;
  }else{
    cout << abs(a-N) << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.IO;

namespace ALDS1_14_D
{
    class SuffixArray
    {
        internal int[] sa, rank, tmp;
        internal string S;
        internal int n, k;

        public SuffixArray(string SS)
        {
            S = SS;
            n = S.Length;
            sa = new int[n + 1];
            rank = new int[2 * n + 1];
            for (int i = n + 1; i <  n << 1; i++)
            {
                rank[i] = -1;
            }
            tmp = new int[n + 1];
            Construct_SA();
        }

        public int Compare_SA(int i, int j)
        {
            return (rank[i] != rank[j]) ? rank[i] - rank[j] : rank[i + k] - rank[j + k];
        }

        public void Construct_SA()
        {
            for (int i = 0; i < n; i++)
            {
                sa[i] = i;
                rank[i] = S[i];
            }
            sa[n] = n; rank[n] = -1;

            for (k = 1; k <= n; k <<= 1)
            {
                Array.Sort(sa, Compare_SA);

                int d;
                d = tmp[sa[0]] = 0;

                for (int i = 1; i <= n; i++)
                {
                    d = tmp[sa[i]] = d + ((Compare_SA(sa[i - 1], sa[i]) < 0) ? 1 : 0);
                }

                for (int i = 0; i <= n; i++)
                {
                    rank[i] = tmp[i];
                }

            }
        }

        public string Contains(string pattern)
        {
            int l = 1, r = n + 1;
            int pl = pattern.Length;

            while (l < r)
            {
                int m = (l + r) >> 1;

                string subStr = (sa[m] + pl > n) ? S.Substring(sa[m]) : S.Substring(sa[m], pl);

                int comp = subStr.CompareTo(pattern);
                if (comp == 0) return "1";

                if (comp < 0) l = m + 1;
                else r = m;
            }
            return "0";
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var T = Console.ReadLine();
            var SA = new SuffixArray(T);
            var Q = int.Parse(Console.ReadLine());
            for (int i = 0; i < Q; i++)
            {
                var P = Console.ReadLine();
                Console.WriteLine(SA.Contains(P));
            }
            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 38764
#include <stdio.h>
#include <stdlib.h>
#define bit(n,m)(((n)>>(m))&1)

void f(int a,int b,int n,int fix){
	if(__builtin_popcount(fix)==n-1){
		printf("%d %d ",a,b);
		return;
	}
	int nfix=0;//fixされていなくて、aとbが違うbitを探す
	while(bit(fix,nfix)==1||bit(a^b,nfix)==0)nfix++;
	int dif=0;//fixされていなくて、nfixでないbitを探す
	while(bit(fix,dif)==1||nfix==dif)dif++;
	
	f(a,a^(1<<dif),n,fix^(1<<nfix));
	f(a^(1<<dif)^(1<<nfix),b,n,fix^(1<<nfix));
}
int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	if(__builtin_popcount(a^b)%2==0)puts("NO");
	else puts("YES"),f(a,b,n,0);
}

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

int a[200005],vis[1000005],flag[1000005];


void slove(int x)
{
	for (int i = 2; ; i++)
	{
		int t = x * i;
		if( t > 1e6 ) return;
		flag[t] = 1;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if( vis[a[i]] == 0 ) slove(a[i]);
		else flag[a[i]] = 1;
 		vis[a[i]] = 1;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if( flag[a[i]] == 0 ) ans ++;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 12192
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    while(a>0&&c>0){
        c-=b;
        if(c<=0){
            cout << "Yes" << endl;
            break;
        }

        a-=d;
        if(a<=0){
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3620