akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, K, i, len=1, ans=1; string S; cin >> N >> K >> S;
vector<int> I, O;
if(S[0]=='0'){ I.push_back(0); }
for(i=1; i<N; i++){ 
  if(S[i-1]==S[i]){ len++; }
  else if(S[i]=='0'){ I.push_back(len); len=1; }
  else if(S[i]=='1'){ O.push_back(len); len=1; }
}
if(S[N-1]=='1'){ I.push_back(len); }
else{ O.push_back(len); I.push_back(0); }
int g=O.size(), h=min(g, K), now=0;
for(i=0; i<h; i++){ now+=(I[i]+O[i]); } now+=I[h]; ans=now;
for(i=h; i<g; i++){ now=now-I[i-h]-O[i-h]+O[i]+I[i+1]; ans=max(ans, now); }  
cout << ans << "\n";
}

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

using namespace std;
typedef long long int lld;

int v[222222];
vector<int> f,s;
int vis[222222];
void recur(int now){
	if(vis[now]==0){
		vis[now] = 1;
		f.push_back(now);
	}else if(vis[now]==1){
		vis[now] = 2;
		s.push_back(now);
	}
	if(vis[v[now]]<=1){
		recur(v[now]);
	}
}
int main(void){
	int n;
	lld k;
	scanf("%d%lld",&n,&k);
	for(int e=1;e<=n;e++){
		int r;
		scanf("%d",&r);
		v[e] = r;
	}
	recur(1);
	if(k<(int)f.size()){
		printf("%d",f[k]);
	}else{
		k -= (int)f.size();
		k %= (int)s.size();
		printf("%d ",s[k]);
	}
	return 0;
}


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

using namespace std;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
// #define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define fill(a,p) memset(a,p,sizeof(a))
#define pb push_back
#define mod 998244353
#define N 10000000
#define all(a) a.begin(),a.end()
#define point pair<ll,ll>
#define endl "\n"

const int inf = 1000000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM =2005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll minim(ll a, ll b){return a<b?a:b;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

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()
{
	fio;
	ll s,w;cin>>s>>w;
	if(w>=s){
		cout<<"unsafe\n";
	}else{
		cout<<"safe\n";
	}
}




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

int main() {
  int n;cin>>n;
  int xn[n];
  rep(i,n) cin>>xn[i];
  sort(xn,xn+n);
  int x=0,cnt=0;
  rep(i,n) {
    if (xn[i]!=x) cnt++;
    x = xn[i];
  }
  cout << cnt;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
G = []
class Edge:
    def __init__(self, to, w):
        self.to = to
        self.w = w

def dfs(s, d, fr, dist):
    dist[s] = d
    for edge in G[s]:
        if edge.to != fr:
            dfs(edge.to, d + edge.w, s, dist)


def main():
    global G
    n = int(input().strip())
    G = [[] for _ in range(n)]
    d1 = [0] * n
    d2 = [0] * n
    for i in range(n-1):
        s, t, w = map(int, input().strip().split())
        G[s].append(Edge(t, w))
        G[t].append(Edge(s, w))
    dfs(0, 0, -1, d1)
    j = d1.index(max(d1))
    dfs(j, 0, -1, d2)
    print(max(d2))


if __name__ == '__main__':
    main()



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

using namespace std;

using ll = long long;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(0, min(b, d) - max(a, c)) << endl;

    return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
--import Data.Array
import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete

type Point = (Double, Double)

f :: Point -> Point -> Point -> Point
f (x1,y1) (x2,y2) (x,y) = (rx * cost - ty * sint + x1, rx * sint + ty * cost + y1)
  where
    sx = x - x1
    sy = y - y1
    dx = x2 - x1
    dy = y2 - y1
    r = sqrt (dx^2 + dy^2)
    sint = dy / r
    cost = dx / r
    rx = sx * cost + sy * sint
    ry = sx * (-sint) + sy * cost
    ty = -ry
    
    

main = map (map (apply2 (,)) . splitRec 2 . map readDouble . wordsBy (==',')) . lines <$> getContents >>= mapM_ ((\(x, y) -> printf "%.15f %.15f\n" x y) . apply3 f)


Measured memory_bytes: 4512
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    int C = Integer.parseInt(sc.next());
    
    if(C - (A - B) <= 0){
      System.out.println(0);
    }else{
      System.out.println(C - (A - B));
    }
  }
}

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

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { if(&o == &cerr) { o << '{'; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; } else { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); } return o; }
#ifdef DEBUG
#define dump(...) (cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
#else
#define dump(...) (0)
#endif
/// }}}--- ///

const int N = 401;
int n, c;
ll tmp[N][N];
ll dp1[N][N];
ll dp2[N][N];
int a[400], b[400];

ll mod = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> c;
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  for(int i = 0; i < n; i++) {
    b[i] = b[i] - a[i];
    for(int j = 0; j <= b[i]; j++) {
      tmp[j][0] = 1;
      for(int k = 1; k <= c; k++) tmp[j][k] = tmp[j][k-1] * (a[i] + j) % mod;
    }
    for(int j = 0; j <= b[i]; j++) {
      for(int k = 0; k <= c; k++) dp1[i][k] = (tmp[j][k] + dp1[i][k]) % mod;
    }
  }
  for(int i = 0; i < n; i++) for(int j = 0; j <= c; j++) {
    for(int k = 0; k <= j; k++) {
      ll t = 0;
      if(i > 0) t = dp2[i - 1][k];
      else if(k == 0) t = 1;
      t = t * dp1[i][j - k] % mod;
      dp2[i][j] += t;
      dp2[i][j] %= mod;
    }
  }
  cout << dp2[n - 1][c] << endl;
}



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

signed
main(){
		int n,m;
		while(cin >> n >> m && !(n==0 && m==0))
		{
				vector<int> s(n), t(m);
				int s_sum = 0, t_sum = 0;
				for(int i=0;i<n;i++)
				{
						cin >> s[i];
						s_sum += s[i];
				}
				for(int i=0;i<m;i++)
				{
						cin >> t[i];
						t_sum += t[i];
				}

				bool flag = false;
				int ans_s = 100, ans_t = 100;
				for(int i=0;i<n;i++)
				{
						for(int j=0;j<m;j++)
						{
								int s_tmp = s[i];
								int t_tmp = t[j];

								s_sum -= s_tmp;
								t_sum -= t_tmp;

								s_sum += t_tmp;
								t_sum += s_tmp;
								if(s_sum == t_sum)
								{
										if(ans_s+ans_t > s_tmp+t_tmp)
										{
												ans_s = s_tmp;
												ans_t = t_tmp;
										}
										flag = true;
								}

								s_sum -= t_tmp;
								t_sum -= s_tmp;

								s_sum += s_tmp;
								t_sum += t_tmp;
						}
						if(flag) break;
				}
				if(flag) cout << ans_s << " " << ans_t << endl;
				else cout << -1 << endl;
		}
}



Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    int a,b,deg;
    double rad;
    double PI = acos(-1);
    cin >> a >> b >> deg;
    rad = deg * PI /180;
    cout << fixed;
    cout << setprecision(5) << a*b*sin(rad)/2 << endl;
    cout << setprecision(5) << a+b+sqrt(a*a+b*b-2*a*b*cos(rad)) << endl;
    cout << setprecision(5) << b*sin(rad) << endl;
    return 0;
}



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

int main(){
	int n, b, f, r, v;
	int room[4][3][10] = {0};
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		room[b - 1][f - 1][r - 1] += v;
	}
	for(int i = 0; i < 4; i++){
		if(i != 0) cout << "####################" << endl;
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 10; k++){
				cout << ' ' << room[i][j][k];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i, N) for (long long int i=0; i<(int)N; i++)
#define rep1(i, N) for (long llint i=1; i<(int)N; i++)

using namespace std;

int N;
string S;

int main() {
  cin >> N;
  cin >> S;
  
  if (N%2 != 0) cout << "No";
  else {
    if (S.substr(0, N/2) == S.substr(N/2,N/2)) {
      cout << "Yes";
    } else {
      cout << "No";
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


signed main(void) {
    int n,k;
    cin >> n >> k;
    vi a(n);
    rep(i,n) cin >> a[i];
    int dp[45][2];
    rep(i,45)rep(j,2)dp[i][j] = -1;
    dp[0][0] = 0;
    rep(i,41){
        int cnt = 0;//上からi桁目に1が立っている個数
        rep(j,n)if(1LL << (40-i) & a[j])cnt++;
        //cout << i << " " << dp[i][0] << " " << dp[i][1] << " " << cnt << endl;
        if(dp[i][1] >= 0)dp[i+1][1] = max(cnt, n-cnt) + dp[i][1] * 2;
        if(1LL << (40-i) & k){
            //cout << "A" << endl;
            dp[i+1][1] = max(dp[i+1][1], cnt + dp[i][0] * 2);//0
            dp[i+1][0] = max(dp[i+1][0], n-cnt + dp[i][0] * 2);//1
        }else{
            //cout << "B" << endl;
            dp[i+1][0] = max(dp[i+1][0], cnt + dp[i][0] * 2);//0
        }
    }
    int ans = max(dp[41][0], dp[41][1]);
    cout << ans << endl;
}


Measured memory_bytes: 1024
S = list(input())
odds = [S[i] for i in range(len(S)) if i % 2 == 0]
evens = [S[i] for i in range(len(S)) if i % 2 != 0]
ans = []
ans.append(odds.count("0")+evens.count("1"))
ans.append(odds.count("1")+evens.count("0"))
print(min(ans))

Measured memory_bytes: 4652
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define debug(x) cout << x << endl;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const ll N = 1010;
bool isPal(string str){
        size_t len = str.length();

    for(int i = 0; i < len/2; i++){
        if(str[i] != str[len-1-i]){
            return false;
        }
    }
    return true;

}
int main()
{

ll x;
cin>>x;
double l=x/3.0;
printf("%lf",l*l*l);











}

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

void swap(int* a, int* b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

int sort(int* &num, int size)
{
    int step = 0;
    int min = 0;
    for(int i = 0; i < size; i++)
    {
        min = i;
        for(int j = i + 1; j < size; j++)
        {
            if(num[j] < num[min])
                min = j;
        }
        if(min != i)
        {
            swap(&num[i], &num[min]);
            step++;
        }
    }
    return step;
}

int main()
{
    int size = 0;
    cin >> size;
    int *num = new int[size];
    for(int i = 0; i < size; i++)
    {
        cin >> num[i];
    }
    int step = sort(num, size);
    for(int t = 0; t < size; t++)
    {
        if(t)
            cout << " ";
        cout << num[t];
    }
    cout << endl;
    cout << step << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>
using namespace std;
int main() {
	string h;
	cin >> h;
	int t = 0, s = 0;
	for (int i = 0; i < h.length(); ++i) {
		if (h[i] == 'T') {
			if (s == 0) ++t;
			else --s;
		}
		else {
			++s;
		}
	}
	cout << t * 2 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (n); i++)

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	if (n % 2 == 1) {
		for (int i = 0; i < m; i++) {
			cout << (i + 1) << " " << (n - i) << endl;
		}
	}
	else {
		int vv = 0;
		for (int i = 0; i < m; i++) {
			if ((2 * i + 1) * 2 >= n)vv = 1;
			cout << (i + 1) << " " << (n - i - vv) << endl;
		}
	}
	return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll 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;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
  int k;
  cin >> k;
  string ss;
  cin >> ss;
  int s = ss.size();
  mint ans = 0;
  combination cb(s+k);
  rep(i, k+1){
    mint add = cb(s-1+k-i, s-1);
    add *= mint(25).pow(k-i);
    add *= mint(26).pow(i);
    ans += add;
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 35652
n =int(input())
a = list(map(int,input().split()))
q = sum(a)/n
#print(q)
d = q
e = 1000
for i in range(n-1,-1,-1):
    if d >= abs(q-a[i]):
        d = abs(q-a[i])
        e = i
print(e)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
  
int main(){
  
   char s[100];
   char p[100];
   char t[200];
 

   scanf("%s",s);
   scanf("%s",p);
  
   strcpy(t,s);
   strcat(t,s);
  
   if(strstr(t,p))
       printf("Yes\n");
   else
       printf("No\n");
      
return 0;
  
}
 

 

Measured memory_bytes: 540
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <unordered_set>

using namespace std;

int main() {
  int n;
  cin >> n;
  long power = 1;

  for (int i = 1; i <= n; i++) {
    power *= i;
    power = power % (1000000007);
  }

  cout << power << endl;
}


Measured memory_bytes: 256
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)


ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    string s;
    cin>>s;
    ll n=(ll)s.length();
    for(ll a=0;a<n;a++)
    {
        if(s[a]=='?')
        {
            s[a]='D';
        }
    }
    cout<<s<<endl;
	printclock;
	return 0;
}

Measured memory_bytes: 3976
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}
int main(){
    int n,i,j,flag=0,a[200020]={};
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    qsort(a,n,sizeof(int),asc);
    for(i=0; i<n-1; i++){
        if(a[i]==a[i+1])flag=1;
    }
    if(flag==0){
        printf("YES");
        return 0;
    }
    printf("NO");
    return 0;
}

Measured memory_bytes: 1788
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var s =  Console.ReadLine();
        if (s == "ABC") Console.WriteLine("ARC");
        else Console.WriteLine( "ABC");
    }
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15); 
    int n; 
    cin >> n; 
    int odd, even; 
    odd = n / 2; 
    even = n / 2; 
    if (n % 2 == 1) ++odd; 
    cout << odd * even << endl; 
    return 0; 
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n,m;
    cin>>n>>m;
    //vi l(m);
    //vi r(m);
    int ans = 0;
    int mxl=-1, mnr=INT_MAX;
    REP(i,m){
        int l,r;
        cin>>l>>r;
        mxl = max(mxl,l);
        mnr = min(mnr,r);
    }

    ans = max(mnr-mxl+1,0);

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

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

int main () {
    int N, K;
    cin >> N >> K;
    int L=1;

    for (int i=0; i<N; i++) {
        if (L<=K) {
            L*=2;
        }
        else {
            L+=K;
        }
    }
    cout << L << endl;
}

            


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

signed main(){
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i, N) cin >> d[i];

    sort(d.begin(), d.end());
    cout << d[(N-1) / 2 + 1] - d[(N-1) / 2] << endl;

    //int counter = 0;
    /*rep(i, d[N-1]){
        if(i > d[(N-1) / 2] && i <= d[(N-1) / 2 + 1]){
            counter++;
        }
    }*/

    //cout << counter << endl;
    return 0;
}

Measured memory_bytes: 3980
/*
 * src.cpp
 *
 *  Created on: 2016/09/03
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

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

typedef long long ll;

ll N,S;

ll f(ll i,ll x){
	ll res=0;
	while (x){
		res+=x%i;
		x/=i;
	}
	return res;
}

void solve(){
	ll i;
	if (N<S){
		printf("-1\n");
	}else if (N==S){
		printf("%lld\n",N+1);
	}else{
		for (i=2;i*i<=N;i++){
			if (f(i,N)==S){
				printf("%lld\n",i);
				return;
			}
		}
		while (i*i>=N){
			i--;
		}
		for (;i>0;i--){
			ll p=i;
			ll b=(N-S)/p+1;
			if (N/b+N%b==S){
				printf("%lld\n",b);
				return;
			}
		}
		printf("-1\n");
	}
}

int main(){
	scanf("%lld %lld",&N,&S);
	solve();
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <map>
using namespace std;

int tabnum(string &s){
	int ret = 0;
	while(ret<(int)s.length() && s[ret]==' ') ret++;
	return ret;
}

int main(){
	string match;
	getline(cin, match);
	stack<string> stc;
	stc.push("");
	stack<int> tnum;
	tnum.push(-1);
	map<string, string> ext;
	
	string str;
	while(getline(cin, str)){
		int intab = tabnum(str);
		while(tnum.top() >= intab){
			stc.pop();
			tnum.pop();
		}
		string tmp = str.substr(intab, str.length() -intab);
		if(str.back() == ':'){
			tmp.pop_back();
			ext[stc.top() +"." +tmp] = "object";
			stc.push(stc.top() +"." +tmp);
			tnum.push(intab);
		}else{
			int pos = 0;
			while(tmp[pos] != ':') pos++;
			ext[stc.top() +"." +tmp.substr(0, pos)] = tmp.substr(pos+2, tmp.length()-pos-2);
		}
	}
	
	if(ext.count(match) == 0){
		cout << "no such property" << endl;
	}else if(ext[match] == "object"){
		cout << "object" << endl;
	}else{
		cout << "string \"" << ext[match] << "\"" << endl;
	}
	return 0;
}



Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  string k;
  cin >> k;
  int d;
  cin >> d;
  vector<vector<int>> dp(2, vector<int>(d, 0));
  dp[1][0] = 1;
  EACH(v, k) {
    int cmp = v - '0';
    vector<vector<int>> ndp(2, vector<int>(d, 0));
    REP(i, d) {
      REP(j, 10) {
        if (j < cmp) {
          ndp[0][(i + j) % d] += dp[0][i] + dp[1][i];
          ndp[0][(i + j) % d] %= MOD;
        } else if (j == cmp) {
          ndp[0][(i + j) % d] += dp[0][i];
          ndp[0][(i + j) % d] %= MOD;
          ndp[1][(i + j) % d] += dp[1][i];
          ndp[1][(i + j) % d] %= MOD;
        } else {
          ndp[0][(i + j) % d] += dp[0][i];
          ndp[0][(i + j) % d] %= MOD;
        }
      }
    }
    swap(dp, ndp);
  }
  cout << (((dp[0][0] + dp[1][0]) % MOD - 1) + MOD) % MOD << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define repm(i, m, n) for (int i = (m); i < (n); i++)
#define rep_rev(i, n) for (int i = int (n); i >= 0; i--)
typedef long long int lli;
using namespace std;

int main() {
	int n;
	int a[100000];
	cin >> n;
	rep(i, n)cin >> a[i];

	int order[100000];
	rep(i, n)order[a[i] - 1] = i;
	rep(i, n)cout << order[i] + 1 << " ";
	cout << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max({a*c, a*d, b*c, b*d}) << '\n';
}

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

    solve();

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> Vec;

struct State {
    ll cost;
    Vec v;
    State(ll cost, Vec v) :
        cost(cost), v(v) {}

    bool operator < (const State &s) const {
        return cost > s.cost;
    }
};

int main()
{
    int N;
    cin >> N;
    ll c[N][N];
    Vec start(N);
    for (int i = 0; i < N; i++) {
        start[i] = i;
        for (int j = 0; j < N; j++) {
            cin >> c[i][j];
        }
    }

    priority_queue<State> Q;
    Q.push(State(0, start));

    map<Vec, ll> min_cost;
    min_cost[start] = 0;
    
    while (!Q.empty()) {
        State s = Q.top(); Q.pop();
        Vec v = s.v;
        
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                swap(v[i], v[j]);
                if (min_cost.count(v) == 0 ||
                    s.cost + c[i][j] < min_cost[v]) {
                    min_cost[v] = s.cost + c[i][j];
                    Q.push(State(min_cost[v], v));
                }                    
                swap(v[i], v[j]);
            }
        }        
    }

    ll res = 0;
    for (auto &x: min_cost) {
        res = max(res, x.second);
    }
    
    cout << res << endl;    
    return 0;
}

Measured memory_bytes: 12440
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N, K; cin >> N >> K;
    int A[200200];
    vector<int> vec;
    map<int, int> mp;
    rep(i, N) {
        cin >> A[i];
        mp[A[i]] ++;
    }
    for(auto p : mp) {
        vec.pb(p.sc);
    }
    sort(all(vec));
    if((int)vec.size() <= K) {
        cout << 0 << endl;
        return 0;
    } else {
        int M = (int)vec.size() - K;
        int ans = 0;
        rep(i, M) {
            ans += vec[i];
        }
        cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 11640
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int N;
    string[] A;
    
    bool input() {
        scanf("%d\n", &N);
        if (stdin.eof) return false;
        A = readln.chomp.split(" ").array;
        
        bool[] del = new bool[N];
        foreach (i; 0 .. N) {
            if (A[i][0] == A[i][1]) {
                char c = A[i][0];
                foreach (j; 0 .. N) {
                    if (i == j) continue;
                    if (A[j][0] == c || A[j][1] == c) {
                        del[i] = true;
                    }
                }
            }
        }
        int nN; string[] nA;
        foreach (i; 0 .. N) {
            if (!del[i]) {
                nN++;
                nA ~= A[i];
            }
        }
        N = nN;
        A = nA;
        return true;
    }

    auto memo = new byte[][](7, 1 << 21);

    bool hasEdge(int last, in string s) {
        char l = cast(char)(last + '0');
        foreach (i; 0 .. 2) {
            if (l == s[i]) return true;
        }
        return false;
    }

    void solve() {
        //writeln(A);
        foreach (i; 0 .. 7) memo[i][] = -1;
        bool dfs(int last, int bit) {
            if (bit == (1 << N) - 1) return 1;
            if (memo[last][bit] >= 0) return memo[last][bit] == 1;
            foreach (i; 0 .. N) {
                if (bit & (1 << i)) continue;
                char l = cast(char)(last + '0');
                if (l == A[i][0] || l == A[i][1]) {
                    int nlast = (l == A[i][0] ? A[i][1] : A[i][0]) - '0'; 
                    if (dfs(nlast, bit | (1 << i))) {
                        memo[last][bit] = 1;
                        //writeln(i);
                        return true;
                    }
                }
            }
            memo[last][bit] = 0;
            return false;
        }

        bool Ans = false;
        foreach (i; 0 .. N) {
            int l = A[i][0] - '0';
            Ans |= dfs(l, 1 << i);
            l = A[i][1] - '0';
            Ans |= dfs(l, 1 << i);
        }
        writeln(Ans ? "Yes" : "No");
    }

    while (input) solve;
}

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

using namespace std;

#define int long long
#define tie() ios_base :: sync_with_stdio(0); cin.tie(0) ; cout.tie(0)
#define err(x) cerr << #x << " is : " << x << endl
#define mem(a , v)   memset(a , v , sizeof a)
#define all(v) v.begin() , v.end()
#define endl '\n'


int32_t main()
{
      tie();
      int t = 1;
      while(t--)
      {
            int k;
            cin >> k;
            queue <int> q;
            for(int i = 1 ; i <= 9 ; i++)
                q.push(i);

            int ctr = 0;
            while(true)
            {
                int fr = q.front();
                q.pop();
                ctr++;
                if(ctr == k)
                {
                    cout << fr << endl;
                    return 0;
                }
                int x = fr % 10;

                if(x != 0)
                    q.push(fr * 10 + x - 1);

                q.push(fr * 10 + x);

                if(x != 9)
                    q.push(fr * 10 + x + 1);
            }
      }
      return 0;
}


Measured memory_bytes: 4688
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

int main(){
    ll a,b,c,d; cin>>a>>b>>c>>d;
    ll X=max(a*c,b*d);
    ll Y=max(a*d,b*c);
    cout<<max(Y,X)<<endl;
}

Measured memory_bytes: 3632
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
l = []


if n >= m:
    print(0)
    exit()

for i in range(m - 1):
    l.append(x[i + 1] - x[i])

l = sorted(l)[::-1]

del l[0: n - 1]

print(sum(l))

Measured memory_bytes: 13968
import java.util.*;

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


Measured memory_bytes: 26272
import itertools
n = int(input())
s = [input() for _ in range(n)]

march = [0] * 5

for i in range(n):
    if s[i][0] == 'M':
        march[0] += 1
    elif s[i][0] == 'A':
        march[1] += 1
    elif s[i][0] == 'R':
        march[2] += 1
    elif s[i][0] == 'C':
        march[3] += 1
    elif s[i][0] == 'H':
        march[4] += 1

ans = 0
for i in itertools.combinations(range(5),3):
    ans += march[i[0]] * march[i[1]] * march[i[2]]
print(ans)

Measured memory_bytes: 9776
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <math.h>

#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
typedef pair<int,int> P;

int cur;
string s;

int to_i(string t){
	int res=0;
	REP(i,t.size()){
		res*=10;
		res+=(t[i]-'0');
	}
	return res;
}

int rec(){
	cur++;
	if(s[cur]!='['&&s[cur]!=']'){
		string t="";
		while(s[cur]!=']'){
			t+=s[cur];
			cur++;
		}
		cur++;
		return to_i(t)/2+1;
	}
	vector<int>vote;
	while(s[cur]!=']'){
		vote.PB(rec());
	}
	sort(ALL(vote));
	int sum=0;
	REP(i,vote.size()/2+1)sum+=vote[i];
	cur++;
	return sum;
}

int main(){
	int n;
	cin>>n;
	while(n--){
		cin>>s;
		cur=0;
		cout<<rec()<<endl;
	}

}


Measured memory_bytes: 3200
import collections
N = int(input())
A = list(map(int, input().split()))

Cntr = collections.Counter(A)
Sum = 0
for c in Cntr.items():
    key = c[0]
    val = c[1]
    if val > 1:
        Sum += val * (val - 1) // 2

for a in A:
    print(Sum-(Cntr[a]-1))

Measured memory_bytes: 26772
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1<<30;
const ll MOD = 1000000007;

int main() {
    ll K,cu;
    cin >> K;
    queue<ll> que;
    for (int i = 1; i < 10; i++) que.push(i);
    rep(i,K){
        cu = que.front();
        que.pop();
        int n = cu % 10;
        if(n!=0) que.push(cu*10+n-1);
        que.push(10*cu+n);
        if(n!=9) que.push(cu*10+n+1);
    }
    cout << cu << endl;
}

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

int main() {
        int H[10000], W[10000], i, a, k;
        i = 100000;
        a = 0;
        for (k; k < i; k++) {
                cin >> H[k] >> W[k];
                if (H[k] == 0 && W[k] == 0) break;
        }
        for (a; a < k; a++) {
                for (int l = 0; l < W[a]; l++) cout << "#";
                cout << endl;
                for (int m = 0; m < H[a] - 2; m++) {
                        cout << "#";
                        for (int n = 0; n < W[a] - 2; n++) cout << ".";
                        cout << "#" << endl;
                }
                for (int l = 0; l < W[a]; l++) cout << "#";
                cout << endl << endl;
        }
}

Measured memory_bytes: 3080
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------
int alpha[26][100010];
//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    string s;cin>>s;
    int n=s.length();
    if(n==2&&s[0]==s[1]){
        cout<<1<<" "<<2<<endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        alpha[s[i]-'a'][i]++;
        if(i){
            for(int j=0;j<26;j++){
                alpha[j][i]+=alpha[j][i-1];
            }
        }
    }
    for(int i=0;i<n-2;i++){
        for(int j=0;j<26;j++){
            int tmp=alpha[j][i+2]-alpha[j][i];
            if(s[i]=='a'+j)tmp++;
            if(tmp>=2){
                cout<<i+1<<" "<<i+3<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------








































Measured memory_bytes: 10704
#include <iostream>
//Ishita
 
using namespace std;
 
int value[3][101];
int sum[3][101];
 
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> value[1][i];
	for (int i = 1; i <= n; i++) cin >> value[2][i];
	for (int i = 0; i <= 2; i++) sum[i][0] = 0;
	for (int i = 0; i <= n; i++) sum[0][i] = 0;
	for (int i = 1; i <= 2; i++)
		for (int j = 1; j <= n; j++)
			sum[i][j] = max(sum[i][j - 1], sum[i - 1][j]) + value[i][j];
	cout << sum[2][n] << endl;
}

Measured memory_bytes: 632
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  int n;cin>>n;
  if (n/10==9 || n%10==9){cout<<"Yes";}
  else {cout<<"No";}

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

const long long int MOD=1e9+7;

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

long long int comb(long long int i, long long int j) {
    if(i-j<j) {
        j = i-j;
    }
    
    long long int ret=1;
    if(j==0) {
        return ret;
    }
    
    for(int jj=j; jj>=1; jj--) {
        ret *= (i+1-jj);
        ret %= MOD;
        
        ret *= modinv(jj, MOD);
        ret %= MOD;
    }

    return ret;
}

int main() {
    long long int n, a, b;
    cin >> n >> a >> b;
    
    long long int ans=1;
    map <long long int, long long int> mp;
    mp[0]=1;
    mp[1]=2;
    long long int N=1;
    long long int tmp=2;
    int cnt=1;
    while(N<n) {
        N *= 2;
        mp[N] = tmp*tmp;
        mp[N] %= MOD;
        tmp = mp[N];
        cnt++;
    }

    for(int i=0; i<cnt; i++) {
        if(n & ((long long int)1<<i)) {
            ans *= mp[((long long int)1<<i)];
            ans %= MOD;
        }
    }
    
    ans--;
    
    ans -= comb(n, a);
    ans -= comb(n, b);
    while(ans<0) {
        ans += MOD;
    }
    
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 256
n=int(input())
k=int(input())
l=[int(i) for i in "0"+str(n)]
# [0]=n [1]<n
dp=[[[0]*5,[0]*5] for i in "ww"]
dp[0][0][0]=1
v=0
for i,j in enumerate(str(n)):
    i+=1
    v=v*10+l[i]
    for p in range(k+1):
        if dp[i%2-1][0][p]:
            dp[i%2][0][p+[0,1][l[i]>0]]=1
            for q in range(l[i]):
                dp[i%2][1][p+[0,1][q>0]]+=1
        if dp[i%2-1][1][p]:
                dp[i%2][1][p]+=dp[i%2-1][1][p]
                dp[i%2][1][p+1]+=dp[i%2-1][1][p]*9
    for p in range(10): dp[i%2-1][p//5][p%5]=0
print(dp[0][0][k]+dp[1][0][k]+dp[0][1][k]+dp[1][1][k])


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

const int maxN = 1005;
struct edge{
	int v, idx;
	edge(){};
	edge(int v_, int idx_) {
		v = v_; idx = idx_;
	} 
};
int N, M, U[maxN * maxN], V[maxN * maxN], tim, vis[maxN], bel[maxN][maxN][2];
vector<edge> sons[maxN];

void dfs(int u, int fa, int t, int f) {
	//cout << u << endl;
	vis[u] = tim; bel[fa][u][f] = t;
	int sz = sons[u].size();
	for(int i = 0; i < sz; ++i) {
		if(vis[sons[u][i].v] != tim) {
			dfs(sons[u][i].v, fa, t, f);
		}
	}
}

void solve(int u) {
	vis[u] = ++tim;
	int sz = sons[u].size();
	for(int i = 0; i < sz; ++i) {
		if(vis[sons[u][i].v] != tim) {
			dfs(sons[u][i].v, u, sons[u][i].idx, 0);
		}
	}
	reverse(sons[u].begin(), sons[u].end());
	vis[u] = ++tim;
	for(int i = 0; i < sz; ++i) {
		if(vis[sons[u][i].v] != tim) {
			dfs(sons[u][i].v, u, sons[u][i].idx, 1);
		}
	}	
}

int main() {
	//freopen("input.txt", "r", stdin);
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= M; ++i) {
		scanf("%d%d", &U[i], &V[i]);
		sons[U[i]].push_back(edge(V[i], i));
	}
	for(int i = 1; i <= N; ++i) solve(i);
	for(int i = 1; i <= M; ++i) {
		if((bel[V[i]][U[i]][0] != 0) ^ ((bel[U[i]][V[i]][0] != i) || (bel[U[i]][V[i]][1] != i)))
			printf("diff\n");
		else printf("same\n");
	}
	return 0;
}

Measured memory_bytes: 18560