akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+7;


int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    set<ll> s;
    map<ll,ll> m;
    rep(i,n){
        cin >> a[i];
        s.insert(a[i]);
        m[a[i]]++;
    }
    if(s.size()==1){
        if(a[0]==0){
            cout << "Yes" << endl;
            return 0;
        }
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    if(n%3!=0){
        cout << "No" << endl;
        return 0;
    }
    if(s.size()==2){
        if(m[0]==n/3){
            cout << "Yes" << endl;
            return 0;
        }
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    if(s.size()==3){
        vector<ll> b(3);
        ll i=0;
        for(auto x:s){
            b[i]=x;
            i++;
        }
        ll p=n/3;
        if(m[b[0]]==p && m[b[1]]==p && m[b[2]]==p && (b[0]^b[1]^b[2])==0){
            cout << "Yes" << endl;
            return 0;
        }
        else{
            cout <<"No" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
} 


Measured memory_bytes: 9344
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
typedef long long int ll;
using namespace std;

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

    string s;
    ll k;
    cin >> s >> k;

    int i = 0;
    while ((s[i] - '0') == 1) {
        i++;
    }
    if (i < k - 1) {
        cout << s[i] - '0' << endl;
    } else {
        cout << s[k - 1] - '0' << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int main() {
  int64_t K, A, B;
  cin >> K >> A >> B;

  int64_t result = 1;
  int64_t d = min(K, A - 1);
  result += d;
  K -= d;

  if (B - A >= 2) {
    result += (B - A) * (K / 2) + K % 2;
  } else {
    result += K;
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3644
N,M = map(int, input().split())
List = []
for i in range(N):
    List.append([int(x) for x in input().split()])

List.sort()
money = 0
d = 0
for i in range(N):
    if d >= M:
        break
    elif d+List[i][1] <= M:
        d += List[i][1]
        money += List[i][0]*List[i][1]
    elif d+List[i][1] > M:
        money += (M-d)*List[i][0]
        d = M

print(money)

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

const long long INF = 1LL << 60;
long long dp[100010];

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

int main()
{
    int N; cin >> N;
    int h[N];
    for (int i = 0; i < N; i++) cin >> h[i];
    for (int i = 0; i < 100010; i++) dp[i] = INF;

    //
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    for (int i = 2; i < N; i++) {
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout << dp[N-1] << endl;
}

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

#define ll long long
#define pb push_back
#define N 1000000007
#define nmax 200001
#define pll pair<ll,ll>
#define fill_nums(A,n) for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}

ll extended_gcd(ll a, ll b, ll &x, ll &y) {
	if(a==0) {
		x = 0;
		y = 1;
		return b;
	}

	ll x1,y1;
	ll gcd = extended_gcd(b%a,a,x1,y1);

	x = y1 - (b/a)*x1;
	y = x1;

	return gcd;
}

int main() {
    
   	ll n,k;
   	cin>>n>>k;

   	vector<int> A(n);
   	for(auto &i:A)
   		cin>>i;

   	vector<bool> dp(k+1);

   	for(int i=1;i<=k;i++)
   		for(int j=0;j<n;j++)
   			if(A[j]<=i && dp[i-A[j]]==0) {
   				dp[i] = 1; break;
   			}

   	cout<<(dp[k] ? "First" : "Second")<<endl;
	return 0;
}


Measured memory_bytes: 384
var s:string;
begin
  readln(s);
  if length(s)>=4 then
    if (s[1]='Y')and(s[2]='A')and(s[3]='K')and(s[4]='I') then
    begin
      writeln('Yes');
      exit;
    end;
  writeln('No');
end.

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;


class BIT
{
public:
    vector<ll> bit;
    int M;

    BIT(int M):
        bit(vector<ll>(M+1, 0)), M(M) {}

    ll sum(int i) {
        return sum_(i+1);
    }

    ll sum_(int i) {
        if (!i) return 0;
       // cout << "b" << endl;
        //debug(i);debug((int)(i&-i));debug(i-(i&-i));
        return bit[i] + sum_(i-(i&-i));
    }

    ll sum(int l, int r){
        return sum_(r)-sum_(l-1);
    }

    void add(int i, ll x) {
        if (i > M) return;
        bit[i] += x;
        add(i+(i&-i), x);
    }
};

class hoge{
    public:
        int l; int r; int b, n;

    hoge(int l_, int r_, int b_, int n_){l = l_, r = r_; b = b_;n = n_;};
};
bool comp(hoge a, hoge b){
        return a.r*500*10 +a.b < b.r*500*10 + b.b;
        
    }
int main()
{
    int N, M, Q;

    cin >> N >> M >> Q;

    vector<hoge> a;
    for(int i = 0; i < M; i++){
        //debug(i);
        int l, r;
        cin >> l >> r;
        a.push_back(hoge(l,r,0, -1));
        
    }

    for(int i = 0; i < Q; i++){
        int p, q;
        cin >> p >> q;
        a.push_back(hoge(p,q,1, i));
    }
    sort(all(a), comp);
    for(auto c : a) {
        //debug(c.b)
        //debug(c.l)
        //debug(c.r)
    }
    BIT b(501);
    vi ans(Q);
    for(int i = 0; i < a.size(); i++){
        if(a[i].b == 0){
            //debug(i)
            b.add(a[i].l, 1);
        }
        else
            ans[a[i].n] = b.sum(a[i].l, a[i].r);
    }

    for(auto c : ans)cout << c << endl;
    

    return 0;
}

Measured memory_bytes: 9452
N = int(input())
tree = [[-1, 0, []] for _ in [0]*N]

for _ in [0]*N:
    a = tuple(map(int, input().split()))
    v = a[0]
    n = a[1]
    children = list(a[2:])
    tree[v][2] = children
    for child in children:
        tree[child][0] = v

q = [a[2] for a in tree if a[0] == -1][0]
d = 1
while q:
    for v in q:
        tree[v][1] = d
    q = [n for v in q for n in tree[v][2]]
    d += 1

for i in range(N):
    v = tree[i]
    parent = v[0]
    depth = v[1]
    children = v[2]
    node_type = "root" if parent == -1 else "leaf" if len(children) == 0 else "internal node"
    print("node %d: parent = %d, depth = %d, %s, %s" % (i, parent, depth, node_type, str(children)))

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

int main(){
	int x[201];
	int y[201];
	int N,n,d;
	int size_x,size_y;
	int left,right,up,down;
	int i;
	while(1){
		
		left=0,right=0,up=0,down=0;
		
		cin >> N;
		
		if(N==0){
			break;
		}
		
		for(i = 0 ; i < 201 ; i++){
			x[i]=0; 
			y[i]=0;
		}
		
		for(i = 1 ; i < N ; i++){
			cin >> n >> d;
			
			if(d==0){
				x[i]=x[n]-1;
				y[i]=y[n];
			}
			else if(d==1){
				x[i]=x[n];
				y[i]=y[n]-1;
			}
			else if(d==2){
				x[i]=x[n]+1;
				y[i]=y[n];
			}else{
				x[i]=x[n];
				y[i]=y[n]+1;
			}
		}
		
		for(i=1 ; i < 201 ; i++){
			if(left > x[i]){
				left = x[i];
			}
			if(right < x[i]){
				right = x[i];
			}
			if(down > y[i]){
				down = y[i];
			}
			if(up < y[i]){
				up = y[i];
			}
		}
			
			if(left < 0){
				left = -left;
			}
			if(down < 0){
				down = -down;
			}
		
		size_x = left + right + 1;
		size_y = down + up + 1;
		
		cout << size_x << " " << size_y << endl;
	}
			return 0;
}  

Measured memory_bytes: 1160
#include <iostream>
#include <string>
using namespace std;
int main() {
  long long n;
  cin>>n;
  long long c=1,i;
  string a;
  cin>>a;
  for(i=1;i<n;i++)
  {
      if(a[i]!=a[i-1])
        c++;
  }
  cout<<c;
return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline

def x_p(x,y):
    if x == H-1:
        return 0
    x += 1
    return ([x,y] in l)

def x_m(x,y):
    if x == 0:
        return 0
    x -= 1
    return ([x,y] in l)

def y_p(x,y):
    if y == W-1:
        return 0
    y += 1
    return ([x,y] in l)

def y_m(x,y):
    if y == 0:
        return 0
    y -= 1
    return ([x,y] in l)

H,W = [int(i) for i in input().split()]
l = []
for i in range(H):
    A = list(input())
    for j in range(W):
        if A[j] == "#":
            l.append([i,j])

for i in l:
    flag = 0
    x,y = i
    if x_p(x,y) == True or x_m(x,y) == True or y_p(x,y) == True or y_m(x,y) == True:
        flag = 1
    if flag == 0:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std ;
int cnt[100025];
int main(){
	
	for(int i=1;i<=101;i++){
		for(int j=1;j<=101;j++){
			for(int k=1;k<=101;k++){
				int temp;
				temp=i*i+j*j+k*k+i*j+j*k+k*i;
				cnt[temp]++;
			}
		}
	}
	int n;
	cin>>n;
	
	for(int ii=1;ii<=n;ii++){
		cout<<cnt[ii]<<endl;
	}
}

Measured memory_bytes: 3748
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Control.Arrow
import qualified Data.IntMap.Strict as IM
import qualified Data.Sequence as Sq
import Control.Concurrent

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)
flipTup (a,b) = (b,a)

main = do
    [n,m] <- r'

    ways <- V.map toTup <$> V.replicateM m r'

    let im = V.accumulate (flip (:)) (V.replicate (n+1) []) (ways V.++ V.map flipTup ways)

    answer  <- U.thaw $ U.replicate (n+2) ((-1) :: Int)
    UM.write answer 1 0

    bfs (Sq.fromList [1]) im answer
    ans <- U.freeze answer

    putStrLn "Yes"
    U.mapM_ print $ U.take (n-1) $ U.drop 2 ans

bfs :: Sq.Seq Int -> V.Vector [Int] -> UM.IOVector Int -> IO ()
bfs Sq.Empty _ _ = return ()
bfs (h Sq.:<| sq) imap answer = do
    let children = imap V.! h
    nextBFS <- filterM ( (>>= return.(<0) )  .(UM.read answer)) children
    mapM_ (\c -> UM.write answer c h) nextBFS
    bfs (foldl' (Sq.|>) sq nextBFS) imap answer


Measured memory_bytes: 72848
n = int(input())
s = input()
cnt = s.count('R') * s.count('G') * s.count('B')
for i in range(n):
    for j in range(i + 1, n):
        k = 2*j - i
        if j < k < n and len({s[i], s[j], s[k]}) == 3:
            cnt -= 1
print(cnt)

Measured memory_bytes: 73760
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main () {
	let s = read_line();
	let ss = s.split_whitespace().collect::<Vec<&str>>();
	let x = ss[1].to_string().trim().split("").map(|e|e.parse().unwrap())
	.collect::<Vec<String>>();
	println!("A{}C",x[1]);

}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define INF 1000000001

int N, A[300][300];

int main() {
    cin >> N;
    REP(i, N) REP(j, N) cin >> A[i][j];
    REP(k, N) REP(i, N) REP(j, N) {
        if (A[i][j] > A[i][k] + A[k][j]) {
            cout << -1 << endl;
            return 0;
        }
    }
    REP(k, N) REP(i, N) REP(j, N) {
        if (i != j && j != k && k != i && A[i][j] == A[i][k] + A[k][j]) {
            A[i][j] = A[j][i] = INF;
        }
    }
    ll ans = 0;
    REP(i, N) REP(j, N) if (A[i][j] != INF) ans += A[i][j];
    cout << ans / 2 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
#define rep2(x,from,to) for(long long (x)=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 1000000000
long long n,k;
long long a[100001];
long long dp1[100001];
long long dp2[100001];
long long m,M;
long long f;
long long ans;
int main()
{
    ans=INF;
    m=-1;M=-1;
    cin>>n>>k;
    rep2(i,1,100001)
    {
        dp1[i]=INF;
        dp2[i]=INF;
    }
    rep(i,n)
    {
        cin>>a[i];
    }
    rep(i,n)
    {
        if(a[i]>0&&f==0)
        {
            f=1;
            M=i;
        }
        if(a[i]<=0)m=i;
    }
    if(m!=-1)for(long long i=m;i>=0;i--)
    {
        dp1[m-i+1]=-1*a[i];
    }
    if(M!=-1)for(long long i=M;i<n;i++)
    {
        dp2[i-M+1]=a[i];
    }
    rep(i,k+1)
    {
        ans=min(ans,dp1[i]+dp2[k-i]+min(dp1[i],dp2[k-i]));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
import * as fs from "fs"

const process = (w: number, h: number, x: number, y: number): string => {
  const area = (w * h) / 2
  const div = w / 2 === x && h / 2 === y ? "1" : "0"
  return area + " " + div
}

const Main = (input: string): string => {
  const a: string[] = input.split(" ")
  const na: number[] = a.map((e) => parseInt(e))

  const res = process(na[0], na[1], na[2], na[3]) + ""
  console.log(res)
  return res
}
Main(fs.readFileSync("/dev/stdin", "utf8"))


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

int j=0,k=0;
vector<int> in,pre;

int search(int n)
{
	int i=0;
	while(in[i]!=n)
	{
		i++;
	}
	return i;
}

void rec(int l,int r)
{
	int c,m;
	
	if(l>r) return;
	c=pre[j];
	j++;
	if(l==r)
	{
		if(++k>1) printf(" ");
		printf("%d",in[l]);
		return;
	}
	m=search(c);
	rec(l,m-1);
	rec(m+1,r);
	if(++k>1) printf(" ");
	printf("%d",in[m]);
	return;
}

int main()
{
	int i,n,temp;
	
	cin >> n;
	
	for(i=0;i<=n-1;i++)
	{
		cin >> temp;
		pre.push_back(temp);
	}
	for(i=0;i<=n-1;i++)
	{
		cin >> temp;
		in.push_back(temp);
	}
	rec(0,n-1);
	printf("\n");
	return 0;
}

Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
typedef long long lol;
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
int n,f[505][505],px[250005],py[250005],vis[505][505];
lol ans;
void bfs(int x,int y)
{int X,Y,xx,yy;
	queue<int>Q;
	for (int i=0;i<4;i++)
		{
			X=x+dx[i];Y=y+dy[i];
			if (X<=0||X>n||Y<=0||Y>n) continue;
			if (f[X][Y]>f[x][y]+(vis[x][y]==0)) 
			{
				Q.push((X-1)*n+Y);
				f[X][Y]=f[x][y]+(vis[x][y]==0);
			}
		}
	while (!Q.empty())
	{
		int xx=px[Q.front()],yy=py[Q.front()];
		Q.pop();
		for (int i=0;i<4;i++)
		{
			X=xx+dx[i];Y=yy+dy[i];
			if (X<=0||X>n||Y<=0||Y>n) continue;
			if (f[X][Y]>f[xx][yy]+(vis[xx][yy]==0))
			{
				Q.push((X-1)*n+Y);
				f[X][Y]=f[xx][yy]+(vis[xx][yy]==0);
			}
		}
	}
}
int main()
{int i,j,x;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
			{
				f[i][j]=min(i-1,min(j-1,min(n-i,n-j)));
				px[(i-1)*n+j]=i;py[(i-1)*n+j]=j;
			}
	}
	for (i=1;i<=n*n;i++)
	{
		scanf("%d",&x);
		ans+=f[px[x]][py[x]];
		vis[px[x]][py[x]]=1;
		//printf("%d %d %d\n",px[x],py[x],f[px[x]][py[x]]);
		bfs(px[x],py[x]);
	}
	printf("%lld",ans);
}


Measured memory_bytes: 7668
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,i,j,k,s,ans;
int main()
{

	cin>>a>>b>>c>>x;
	for(i=0;i<=a;i++)
	for(j=0;j<=b;j++)
	for(k=0;k<=c;k++)
	{
		s=i*500+j*100+k*50;
		if(s==x) ans++;
		if(s>x) break;
	}
	cout<<ans;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector <vector <int> > AB(N);
  map<int,int> m;
  int A,B;
  cin >> A >> B;
  m[A]=0;
  AB.at(0).push_back(B);
  int n=0;
  for(int i=1;i<N;i++){
    cin >> A >> B;
    if(m.count(A)){
      AB.at(m.at(A)).push_back(B);
    }else{
      n++;
      m[A]=n;
      AB.at(m.at(A)).push_back(B);
    }
  }
  int sum=0;
  priority_queue <int> pq;
  pq.push(0);
  for(int i=1;i<=M;i++){
    if(m.count(i)){
      for(auto x : AB.at(m.at(i))){
        pq.push(x);
      }
    }
    sum+=pq.top();
    pq.pop();
    if(pq.empty()){
      pq.push(0);
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 10240
# ABC047B - すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)
w, h, n = list(map(int, input().rstrip().split()))
ans = [0, 0, w, h]
for i in range(n):
    x, y, a = list(map(int, input().rstrip().split()))
    if ans[0] < ans[2] and ans[1] < ans[3]:
        if a == 1:
            ans[0] = max(ans[0], x)
        elif a == 2:
            ans[2] = min(ans[2], x)
        elif a == 3:
            ans[1] = max(ans[1], y)
        else:
            ans[3] = min(ans[3], y)
    else:
        print(0)
        break
else:
    res = (ans[2] - ans[0]) * (ans[3] - ans[1])
    print(res if res >= 0 else 0)

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

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

	string s;
	cin >> s;

	bool flag = true;
	for(int i = 0; i < s.size()/2+1 && flag ; i++){
		if(s[i] != s[s.size()-1-i]){
			flag = false;
		}
	}
	for (int i = 0; i < s.size()/4+1 && flag ; i++){
		if(s[i] != s[s.size()/2-1-i]){
			flag = false;
		}
	}
	for (int i = s.size()/2+1; i < s.size()/2+s.size()/4+1 && flag ; i++){
		if(s[i] != s[s.size()-1-i]){
			flag = false;
		}
	}
	cout << (flag?"Yes":"No");
}


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

int gcd(int a,int b){
	if(a==0)
	return b;
	if(b==0)
	return a;
	if(a==b)
	return a;
	if(a>b)
	return gcd(a-b,b);
	return gcd(a,b-a);
}

int GCD(int a,int b){
	if(a==0)
	return b;
	if(b==0)
	return a;
	if(a==b)
	return a;
	return GCD(b,a%b);
}

int main(){
	int n;
	cin>>n;
	int a[n];
	vector<int>v;
	for(int i=0;i<n;i++){
		cin>>a[i];
		v.push_back(a[i]);
	}
	int x=n/2;
	sort(v.begin(),v.end());
	int cnt=0;
	for(int i=0;i<n;i++){
		if(a[i]!=v[i])
		cnt++;
	}
	if(x>=cnt)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
}

Measured memory_bytes: 3624
import math
N=int(input())
lis=list(map(int,input().split()))
ans=sum(lis)
for i in range(N):
  s1=sum(lis[:i])
  s2=sum(lis[i:])
  if ans>abs(s1-s2):
    ans=abs(s1-s2)
    
print(ans)

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

#ifndef DEBUG
#define DEBUG false
#endif

#define REP(t,i,a,b) for(t i = a; i < b; ++i)

typedef long long ll;

using namespace std;

const ll NN = 1000000007;

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

    int n;
    string s;
    cin >> n;
    cin >> s;

    vector<bool> is_left(2*n, true);
    REP(int, i, 1, 2*n) {
        if(s[i-1] == s[i]) is_left[i] = !is_left[i-1];
        else is_left[i] = is_left[i-1];
    }

    int n_left = 0;
    REP(int, i, 0, 2*n) {
        if(is_left[i]) ++ n_left; 
    }

    ll ans = 0;
    if (s[0] == 'B' && s[2*n-1] == 'B' && n_left == n) {
        ans = 1;
        int l = 0, r = 0;
        REP(int, i, 0, 2*n) {
            if(!is_left[i]) {
                ans *= (l-r);
                ans %= NN;
            }
            is_left[i]? ++l: ++r;
        }
    }

    for(int i = n; i >= 1; i--) {
        ans *= i;
        ans %= NN;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 720
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxd = 1e5+10;;
char s[maxd];
int a[maxd],n,k,q;
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%d %d %d",&n,&k,&q);
    for(int i=1;i<=q;i++) 
    {
        int x;
        scanf("%d",&x);a[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(k - q + a[i] <= 0) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}

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

int main() {
    int N, Y;
    cin >> N >> Y;

    vector<int> ijk(3);
    int res1k = -1, res5k = -1, res10k = -1;

    for (int i = 0; i <= N; i++) {
        for (int j = 0; i + j <= N; j++) {
            int k = N - i - j; int money = 10000 * i + 5000 * j + 1000 * k;
            if (Y == money) {
                res1k = i, res5k = j, res10k = k;
            }
        }
    }

    cout << res1k << " " << res5k << " " << res10k << endl;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

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

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N);
  REP(i, N) cin >> A[i];
  ll m = MIN(A);
  ll M = MAX(A);
  ll count = 0;
  vl C(101, 0);
  REP(i, N) {
    if (A[i] == m)
      count++;
    C[A[i]]++;
  }
  ll po = m - (M - m);
  bool ok = false;
  if (po == 0 && count == 1)
    ok = true;
  else if (po == 1 && count == 2)
    ok = true;

  FOR(i, m, M + 1) if (C[i] == 0) ok = false;

  if (ok)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//
		String s = sc.next();
		System.out.println(s.charAt(0) == s.charAt(1) || s.charAt(1) == s.charAt(2) || s.charAt(2) == s.charAt(3) ? "Bad" : "Good");
	}
}


Measured memory_bytes: 35544
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int INF = 987654321;
const int MOD = 1000000007;

int P[101];

int main(){
  int N,A,B;
  scanf("%d %d %d",&N,&A,&B);
  int a = 0, b = 0, c = 0;
  for(int i=0;i<N;i++){
    scanf("%d",&P[i]);
    if(P[i] <= A) a++;
    else if(A+1 <= P[i] && P[i] <= B) b++;
    else if(B+1 <= P[i]) c++;
  }
  printf("%d\n",min(a,min(b,c)));
}

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

signed main(){
	int n;
	string s, t;
	cin >> n >> s >> t;
	rep(i, 0, n){
		cout << s[i] << t[i];
	}
	cout << endl;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> l(m), r(m);
    for (int i = 0; i < m; i++)
        cin >> l[i] >> r[i];
    int lmax = *max_element(l.begin(), l.end());
    int rmin = *min_element(r.begin(), r.end());
    if (lmax <= rmin)
        cout << rmin - lmax + 1 << endl;
    else
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 105;

int n,a[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
  cin>>n;
  int sum = 0;
  for(int i=0;i<n;i++){cin>>a[i];sum+=a[i];}
  int ret = 1000000000;
  int sum2 = 0;
  for(int i=0;i+1<n;i++){
    sum2+=a[i];
    ret=min(ret,abs(sum2-(sum-sum2)));
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 256
A, B, m = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

x = []
y = []
c = []
for i in range(m):
	xx, yy, cc = map(int, input().split())
	x.append(xx)
	y.append(yy)
	c.append(cc)


ans = min(a) + min(b)

for i in range(m):
	ans = min(ans,a[x[i]-1] + b[y[i]-1] - c[i])
print (ans)

Measured memory_bytes: 24620
let rsa () = stdin.ReadLine().Split(' ')
let ria () = rsa () |> Array.map (fun x -> int x)

let [| K; X |] = ria()

let MIN = -10000000
let MAX = 10000000

let answer k x =
  let min' = max (x - k + 1)  MIN
  let max' = min (x + k - 1) MAX
  (min', max')
  

let _ans = answer K X
let a, b = _ans

let rec p min' max' =
  if min' < max' then
    printf "%d " min' |> ignore
    p (min' + 1) max'
  elif min' = max' then
    printf "%d" min' |> ignore
    p (min' + 1) max'
  else ()

p a b
printfn ""

Measured memory_bytes: 13916
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a), t(b);
    rep(i, a) cin >> s[i];
    rep(i, b) cin >> t[i];

    const ll INF = 1LL<<60;
    s.emplace(s.begin(), -INF);
    s.emplace_back(INF);
    t.emplace(t.begin(), -INF);
    t.emplace_back(INF);

    rep(i, q) {
        ll ans = 1LL<<60;
        ll x;
        cin >> x;
        ll ia = upper_bound(s.begin(), s.end(), x) - s.begin();
        ll ib = upper_bound(t.begin(), t.end(), x) - t.begin();

        rep(j, 2) {
            rep(k, 2) {
                chmin(ans, abs(x-s[ia-j]) + abs(s[ia-j] - t[ib-k]));
                chmin(ans, abs(x-t[ib-k]) + abs(t[ib-k] - s[ia-j]));
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 2912
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define beg begin()
#define end end()


void _main(){
    ll n,a,b ; cin >> n >> a >> b;
    cout << a*(n/(a+b)) + min(a,n%(a+b)) << endl;
    return;
}
int main() {
    cout << fixed << setprecision(10);
    _main();
    return 0;
}
    

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

using namespace std;

int main() {
    long long n, m;
    cin >> n >> m;
    if (n > m) swap(m, n);

    long long ans;
    if (n == 1 and m == 1) {
        ans = 1;
    } else if (n == 1 and m >= 2) {
        ans = m - 2;
    } else {
        ans = (m - 2) * (n - 2);
    }

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

Measured memory_bytes: 256
//author Eterna King
#define Hello the_cruel_world!
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<cmath>
#include<climits>
#include<deque>
#include<functional>
#include<numeric>
#define max(x,y) ((x) > (y) ? (x) : (y))
#define min(x,y) ((x) < (y) ? (x) : (y))
#define lowbit(x) ((x) & (-(x)))
#define FRIN freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\in.txt", "r", stdin)
#define FROUT freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\out.txt", "w", stdout)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define outd(x) printf("%d\n", x)
#define outld(x) printf("%lld\n", x)
#define memset0(arr) memset(arr, 0, sizeof(arr))
#define il inline
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 1e5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const double Pi = acos(-1.0);
il int read_int() {
	char c;
	int ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
il ll read_ll() {
	char c;
	ll ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
int res;
int r, g, b, n;
int main()
{
	cin >> r >> g >> b >> n;
	for (int i = 0; i * r <= n; ++i) {
		for (int j = 0; j * g <= n - i * r; ++j) {
			int L = n - i * r - j * g;
			if (L % b == 0)++res;
		}
	}
	outd(res);
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

typedef long long int ll;
ll n,ans=0;

ll dfs(ll a,ll n3,ll n5,ll n7){
  if(a>n)return ans;
  if(n3+n5+n7==3)ans++;
  dfs(a*10+3,1,n5,n7);
  dfs(a*10+5,n3,1,n7);
  dfs(a*10+7,n3,n5,1);
  return ans;
}

int main(){
    scanf("%lld",&n);
    printf("%lld\n",dfs(0,0,0,0));
    return 0;
}


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

struct card{
  char suit;
  int num;
};

void swap(struct card *A, struct card *B);

int main()
{

  struct card A_Bub[36],A_Sel[36];
    
  int N,i,j,min,count=0;
  char num,str1[4],str2[3],temp_c;
  
  scanf("%d",&N);
  
  for(i=0;i<N;i++)
    {
      scanf("%s",str1);
      strncpy(str2,str1+1,strlen(str1)-1);
      num=atoi(str2);
    
      A_Bub[i].suit = A_Sel[i].suit=str1[0];
      A_Bub[i].num = A_Sel[i].num=num; 
    }

  //bubble sort
  for(i=0;i<N;i++)
    {
      for(j=N-1;j>i;j--)
	{
	  if(A_Bub[j].num<A_Bub[j-1].num) swap(&A_Bub[j],&A_Bub[j-1]);	 
	}
    }

  //print
  for(i=0;i<N;i++)
    {
      printf("%c%d",A_Bub[i].suit,A_Bub[i].num);
      if(i!=N-1) printf(" ");
    }
  printf("\n");

  //stability
  printf("Stable\n"); //バブルソートでは安定

  
  //selection sort
  for(i=0;i<N;i++)
    {
      min=i;
      for(j=i;j<N;j++)
	{
	  if(A_Sel[j].num < A_Sel[min].num) min=j;
	  count++;
	}
      swap(&A_Sel[i],&A_Sel[min]); 
    }

  //print
  for(i=0;i<N;i++)
    {
      printf("%c%d",A_Sel[i].suit,A_Sel[i].num);
      if(i!=N-1) printf(" ");
    }
  printf("\n");

  //stability
  for(i=0;i<N;i++)
    {
      if(A_Sel[i].suit!=A_Bub[i].suit && A_Sel[i].num==A_Bub[i].num)
	{
	printf("Not stable\n");
	return 0;
	}
    }

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

void swap(struct card *A, struct card *B){

  struct card temp;
  temp = *B;
  *B = *A;
  *A = temp;

  return;
}



Measured memory_bytes: 2112
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N;
	cin >> N;
	vector<double> v(N);
	rep(i, N) {
		cin >> v.at(i);
	}
	reverse(v.begin(), v.end());
	string an = "Yes";
	rep(i, N-1) {
		if (v.at(i) >= v.at(i + 1)) {

		}
		else if(v.at(i)==v.at(i+1)-1){
			v.at(i+1)--;
		}
		else {
			an = "No";
			break;
		}
	}
	cout << an << endl;
	}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
    string a;
    string b;
    cin >> a;
    int x = a.length();
    int y = (int) a[x-1] - 48;

    switch (y)
    {
    case 0:
    case 1:
    case 6:
    case 8:
    b = "pon";
        break;
    case 3:
    b = "bon";
        break;
    default:
    b = "hon";
        break;
    }
    cout << b;
}


Measured memory_bytes: 3628
//
// Created by yamunaku on 2019/11/05.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int a,b;
    cin >> a >> b;
    if(a<10&&b<10) cout << a*b << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> F(N, vector<int>(10)), P(N, vector<int>(11));
    rep(i, N) rep(j, 10) cin >> F[i][j];
    rep(i, N) rep(j, 11) cin >> P[i][j];
    
    int ans = -2e9;
    REP(bit, (1 << 10)) {
        vector<int> S;
        rep(i, 10) {
            if (bit & (1 << i)) S.push_back(i);
        }
        int res = 0;
        rep(i, N) {
            int cnt = 0;
            for (int n : S) {
                if (F[i][n]) ++cnt;
            }
            res += P[i][cnt];
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
    return 0;
}


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

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

  int ans = 1;
  for(int i = 2; i < X; ++i) {
    for(int j = 2; pow(i, j) <= X; ++j) {
      ans = max(ans, int(pow(i, j)));
    }
  }

  cout << ans << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

const int INF=1001001001;
const int INFLL=1001001001001001001ll;
const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}

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

    int ans=S.size();
    for(char c='a';c<='z';c++){
        string s=S;
        while(s.size()){
            if(count(all(s),c)==s.size())break;
            for(int i=0;i+1<s.size();i++){
                if(s[i]!=c)s[i]=s[i+1];
            }
            s.pop_back();
        }
        chmin(ans,(int)S.size()-(int)s.size());
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;

int main(){
    int n,m;
    cin >> n >> m;
    int x[n];
    for(int i=0; i<n; i++) cin >> x[i];
    int cnt[100001];
    fill(cnt,cnt+100001,0);
    vector<int> a[m],b[m];
    for(int i=0; i<n; i++){
        cnt[x[i]]++;
    }
    for(int i=0; i<100001; i++){
        if(cnt[i]%2==0){
            for(int j=0; j<cnt[i]; j++){
                b[i%m].push_back(i);
            }
        }
        else{
            a[i%m].push_back(i);
            for(int j=1; j<cnt[i]; j++){
                b[i%m].push_back(i);
            }
        }
    }
    int ans = 0;
    ans += (a[0].size()+b[0].size())/2;
    if(m%2==0) ans += (a[m/2].size()+b[m/2].size())/2;
    for(int i=1; i<m/2+1; i++){
        int p=i,q=m-i;
        if(p==q) break;
        if(a[p].size()+b[p].size() < a[q].size()+b[q].size()) swap(p,q);
        int ap=a[p].size(),bp=b[p].size(),aq=a[q].size(),bq=b[q].size();
        ans += aq+bq;
        if(ap > aq+bq) ans += bp/2;
        else ans += (ap+bp-aq-bq)/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
  int no_of_input,maxx;
  cin >> no_of_input >> maxx;
  int currmin = 1;
  int input;
  vector<int> vect1;
  for(int i=0;i<no_of_input;i++){
    cin >> input;
    vect1.push_back(input);
    int idk = __gcd(currmin,input);
    currmin *= input;
    currmin /= idk;
    if(currmin>maxx*2){
      cout << 0;
      return 0;
    }
  }
  //cout << currmin << endl;
  for(auto k:vect1){
    if(((currmin/k))%2==0){
      cout << 0;
      return 0;
    }
  }
  cout << ((maxx-currmin/2)/currmin)+1;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
const int MAXN = (int)1e4+7;
const int INF = (int)0x3f3f3f3f;

int N,M;
int a[MAXN],b[MAXN];
int dis[MAXN];
pi sto[MAXN];

priority_queue<pi> qu;

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

    cin >> N >> M;
    memset(dis,0x3f,sizeof(dis));
    rep(i,1,M) {
        cin >> a[i] >> b[i];
        int now = 0;
        rep(j,1,b[i]) {
            int x;
            cin >> x;
            x --;
            now |= 1<<x;
        }
        if (dis[now] > a[i]) dis[now] = a[i];
        qu.push(make_pair(-dis[now],now));
        sto[i] = make_pair(dis[now],now);
    }
    while (!qu.empty()) {
        pi k = qu.top();qu.pop();
        int cos = -k.first;
        int now = k.second;
        rep(i,1,M) {
            int to = now|sto[i].second;
            int tmpCos = cos+sto[i].first;
            if (dis[to] > tmpCos) {
                dis[to] = tmpCos;
                qu.push(make_pair(-dis[to],to));
            }
        }
    }
    int mx = (1<<(N))-1;

    if (dis[mx] == INF) dis[mx] = -1;
    cout << dis[mx] << endl;
}




Measured memory_bytes: 512
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <stdio.h>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;


int main()
{
  int N;
  cin >> N;
  map<string , int> mp;
  vector < pair<string , int > > vp;
  vector<string > res;
  
  string s;
  
  for (int i = 0; i<N; i++)
  {
      cin >> s;
      mp[s]++;
  }
  
  for (auto i = mp.begin(); i!=mp.end(); i++)
  {
      vp.push_back(make_pair(i->first, i->second));
  }
  
  int max = 0;
  
  for (int i = 0; i<vp.size(); i++)
  {
      if (vp[i].second > max) max = vp[i].second;
      
  }
  
  //cout<<max;
  
  for (int i = 0; i<vp.size(); i++) {
      if (vp[i].second == max) res.push_back(vp[i].first);
  }
  
  sort(res.begin(), res.end());
  
  for (int i = 0; i<res.size(); i++) cout <<res[i] <<endl;
  
  
  
  
  
  
  
  
}


Measured memory_bytes: 32880
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a*b%2 == 1) System.out.println("Odd");
		else System.out.println("Even");
	}
}


Measured memory_bytes: 23764
//パスの少なくとも一方の端点と直接辺で結ばれている頂点があったら、パスを伸ばさなければいけない
//逆に、パスを伸ばせるならば、そのような頂点が存在する。
//よって、両側の端点から貪欲にパスを伸ばしていけばよい。
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cassert>
using namespace std;

int n, m;
vector<int> et[100000];
bool visit[100000];

int main() {
	int i;
	
	cin >> n >> m;
	for (i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		et[a].push_back(b);
		et[b].push_back(a);
	}
	
	int tan1 = 0;
	int tan2 = et[0][0];
	vector<int> path1, path2;
	
	path1.push_back(tan1); visit[tan1] = true;
	path2.push_back(tan2); visit[tan2] = true;
	
	while (true) {
		int nv;
		for (i = 0; i < et[tan1].size(); i++) {
			nv = et[tan1][i];
			if (!visit[nv]) {
				visit[nv] = true;
				path1.push_back(nv);
				break;
			}
		}
		if (i == et[tan1].size()) { break; }
		tan1 = nv;
	}
	
	while (true) {
		int nv;
		for (i = 0; i < et[tan2].size(); i++) {
			nv = et[tan2][i];
			if (!visit[nv]) {
				visit[nv] = true;
				path2.push_back(nv);
				break;
			}
		}
		if (i == et[tan2].size()) { break; }
		tan2 = nv;
	}
	
	vector<int> ans;
	for (i = (int)path2.size() - 1; i >= 0; i--) ans.push_back(path2[i]);
	for (i = 0; i < path1.size(); i++) ans.push_back(path1[i]);
	
	cout << ans.size() << endl;
	for (i = 0; i < ans.size(); i++) {
		cout << ans[i] + 1;
		if (i + 1 < ans.size()) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 7352
#include <stdio.h>
#include <string.h>

int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);

    if(a==b && b==c)
        puts("No");
    else if(a==b || b==c || c==a)
        puts("Yes");
    else
        puts("No");
        
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define P pair<int,int>
using namespace std;
bool bj[1000001];
int main()
{
int k;
scanf("%d",&k);
deque<P> q;
q.push_back(make_pair(1,1));
while(!q.empty())
{
  P a=q.front();
  q.pop_front();
  if(bj[a.first])
    continue;
  bj[a.first]=1;
  if(!a.first)
  {
  	printf("%d\n",a.second);
  	return 0;
  }
  q.push_front(make_pair((a.first*10)%k,a.second));
  q.push_back(make_pair((a.first+1)%k,a.second+1));
}
return 0;
} 

Measured memory_bytes: 1152
s = int(input())
A = [s]
ans = 1

while A.count(s) == 1:
    ans += 1
    if s % 2 == 0:
        s = s//2
        A.append(s)
    else:
        s = 3 * s + 1
        A.append(s)
        
print(ans)

Measured memory_bytes: 2940
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    
    double arr[n+1];
    for(int i=1;i<=n;i++)
        cin >> arr[i];
    
    double dp[3000][3000];
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(i==0 && j!=0)
            {
                dp[i][j] = 0;
            }
            if(j==0 && i!=0)
            {
                dp[i][j] = (1-arr[i])*dp[i-1][j];
            }
        }
    }
    
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            dp[i][j] = (arr[i])*dp[i-1][j-1] + (1-arr[i])*dp[i-1][j];
        }
    }
    
    double ans = 0;
    
    int k = (n+1)/2;
    for(int j=n;j>=k;j--)
        ans += dp[n][j];
    
    cout << fixed << setprecision(9) << ans << endl;
    return 0;
}

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

int main()
{
  int64_t K, T, cnt = 0;
  cin >> K >> T;
  vector<int64_t> A(T);
  for (int64_t i = 0; i < T; i++)
    cin >> A.at(i);
  int64_t previ = -1, maxt = 0, maxi;
  for (int k = 0; k < K; k++)
  {
    for (int64_t i = 0; i < T; i++)
    {
      if (i == previ)
        continue;
      if (A.at(i) > maxt)
      {
        maxt = A.at(i);
        maxi = i;
      }
    }
    A.at(maxi)--;
    if (previ == maxi)
      cnt++;
    maxt = 0;
    previ = maxi;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256