akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pa = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    string s;
    cin >> N >> s;
    ll ans = 0;
    rep(i, N - 2) if (s.substr(i, 3) == "ABC") ans++;
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  int alice=0,bob=0;
  
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  
  for(int i=0;i<n;i++){
    if(i%2==0)
      alice += a.at(i);
    
    if(i%2==1)
      bob += a.at(i);
  }
  cout << alice - bob << endl;
}

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


int main() {
	int n;
	string s, ans = "";
	cin >> n >> s;
	char bef = ' ';
	for (int i = 0; i < n; i++) {
		if (s[i] != bef) {
			bef = s[i];
			ans += s[i];
		}
	}
	cout << ans.size() << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>

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

    std::vector<std::vector<int>> group = {
            {1, 3, 5, 7, 8, 10, 12},
            {4, 6, 9, 11},
            {2}
    };

    int indexX = -1;
    for (auto i = 0; i < group.size(); ++i) {
        auto end = std::find(group[i].begin(), group[i].end(), x);
        if (end != group[i].end()) {
            indexX = i;
            break;
        }
    }

    int indexY = -1;
    for (auto i = 0; i < group.size(); ++i) {
        auto end = std::find(group[i].begin(), group[i].end(), y);
        if (end != group[i].end()) {
            indexY = i;
            break;
        }
    }

    std::cout << (indexX == indexY ? "Yes" : "No") << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   int h,w;
           cin>>h>>w;
           vst a(h+2,"");
           h+=2;w+=2;
           rep(i,1,h-1)cin>>a[i];
           
           rep(i,0,h){
             rep(j,0,w){
             if(i==0||i==h-1)a[i]+='#';
              else{
               a[i]='#'+a[i]+'#'; 
                break;
              }
             }
           }
           rep(i,0,h)cout<<a[i]<<endl;
}

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

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

  int maxfour = n / 4;
  int maxsvn = n / 7;
  bool flagans = false;
  for (int i = 0; i < maxfour + 1; ++i) {
    for (int j = 0; j < maxsvn + 1; ++j) {
      if (n == 4 * i + 7 * j) {
        flagans = true;
        break;
      }
    }
  }
  if (flagans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main(){
	int k,x;
	cin >> k >> x;
	int ans = x - k + 1;
	for(int i=0;i<2*k-1;i++) {
		if(i!=0) cout << " ";
		cout << ans+i;
	}
	cout << endl;
}

Measured memory_bytes: 256
x,y,s,t,z;main(v,w){for(;~scanf("%*d%d%d"+z,&v,&w);v|w||(s=t=!printf("%d %d\n",s,t)))z=3,x+=v,y+=w,(x*x+y*y-s*s-t*t)*1e4>s-x?s=x,t=y:0;}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
	String s;
	int x;
	s= buf.readLine();
	x= Integer.parseInt(s);
	int a = x/3600;
	int b = (x%3600)/60;
	int c = (x%3600)%60;
	System.out.println(a+":"+b+":"+c);
	}
}

Measured memory_bytes: 17020
program sample
    implicit none
    
    integer(8) :: i,j,k,m,n,h,w
    integer(8)::c,d,e1,e2
    integer(8),allocatable::x(:,:),y(:),z(:),a(:),b(:)
  
    read(*,*) h,w,m
    !allocate(x(1:h,1:w),y(1:h),z(1:w),a(m),b(m))
    allocate(y(1:h),z(1:w),a(m),b(m))
    !x(:, :)=0
    y(:)=0
    z(:)=0
    do i=1,m
        read(*,*)a(i),b(i)
        !x(a(i),b(i))=1
        y(a(i))=y(a(i))+1
        z(b(i))=z(b(i))+1
    end do
    
   
    c=maxval(y(1:h))
    d=maxval(z(1:w))
    e1=0
    e2=0
    do i=1,h
        if(y(i)==c)then
        
            e1=e1+1
        end if
    end do
    do i=1,w
        if(z(i)==d)then
        
            e2=e2+1
        end if
    end do
    e1=e1*e2
    
    do i=1,m
        if(y(a(i))==c .and. z(b(i))==d)then
            e1=e1-1
        end if
    end do
    if(e1==0)then
            write(*,'(i0)')c+d-1
    else
        write(*,*)c+d
    end if

    stop
end program sample
  



Measured memory_bytes: 12212
#include<iostream>
#include<string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include<iomanip>
using namespace std;

int main()
{
    int N,A,B;
    cin >> N >> A >> B;
    if(N*A>B)cout<< B << endl;
    else cout << N*A << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100**4)

class Edge():
	def __init__(self, v, w):
		self._v = v
		self._w = w
	def v(self):
		return self._v
	def w(self):
		return self._w

def dfs(v, g, colors, color = 0):
	colors[v] = color
	if not len(g[v]):
		return
	for nv in g[v]:
		if colors[nv.v()] != -1:
			continue
		nc = color if nv.w() % 2 == 0 else 1 - color
		dfs(nv.v(), g, colors, nc)

def resolve():
	n = int(input())
	colors = [-1]*n
	g = [list() for _ in range(n)]
	for _ in range(n-1):
		u, v, w = map(int, input().split())
		g[v-1].append(Edge(u-1, w))
		g[u-1].append(Edge(v-1, w))
	for i in range(n):
		if colors[i] != -1:
			continue
		dfs(i, g, colors)
	for c in colors:
		print(c)
resolve()

Measured memory_bytes: 152224
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] P = new int[N];
		for(int i=0;i<N;i++) P[i] = K - Q;
		for(int i=0;i<Q;i++){
			P[A[i]] += 1;
		}
		Console.WriteLine(String.Join("\n", P.Select(v => v > 0 ? "Yes" : "No")));
		
		
		
		
	}
	int N, K, Q;
	int[] A;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1]; Q = d[2];
		A = new int[Q];
		for(int i=0;i<Q;i++){
			A[i] = ri() - 1;
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 16480
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  string S;
  cin>>N;
  int AC=0;
  int WA=0;
  int TLE=0;
  int RE=0;
  for(int i=0;i<N;i++)
  {
    cin>>S;
    if(S=="AC")
    {
      AC=AC+1;
    }else if(S=="WA")
    {
      WA=WA+1;
    }else if(S=="TLE")
    {
      TLE=TLE+1;
    }else
    {
      RE=RE+1;
    }
  }
  cout<<"AC x "<<AC<<endl;
  cout<<"WA x "<<WA<<endl;
  cout<<"TLE x "<<TLE<<endl;
  cout<<"RE x "<<RE<<endl;
}

Measured memory_bytes: 3624
#include<cstdio>

int n, x, y;
int ans[2003];

int min(int x, int y) {
  return x < y ? x : y;
}

int abs(int x) {
  return x > 0 ? x : -x;
}

int main() {
  scanf("%d %d %d", &n, &x, &y);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i < j)  {
        ans[min(j - i, abs(i - x) + abs(j - y) + 1)]++;
      }
    }
  }
  for (int i = 1; i < n; i++) {
    printf("%d\n", ans[i]);
  }
}


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

int main(){
    vector<int> a(2);
    int i;
    for(i = 0; ;i++){
        scanf("%d %d", &a.at(0), &a.at(1));
        if(a.at(0) == 0 && a.at(1) == 0) break;
        sort(a.begin(), a.end());
        printf("%d %d\n", a.at(0), a.at(1));
    }
}


Measured memory_bytes: 3100
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	const mod = 1000000000 + 7

	sc.Buffer(nil, 100000000)

	n, a, b := nextInt(), nextInt(), nextInt()

	ss := nextString()

	rank := make([]string, n)

	r := 1
	c := 1
	for i, s := range ss {
		if s == 'a' {
			if r <= a+b {
				rank[i] = "Yes"
				r++
			} else {
				rank[i] = "No"
			}
		} else if s == 'b' {
			if r <= a+b && c <= b {
				rank[i] = "Yes"
				c++
				r++
			} else {
				rank[i] = "No"
			}
		} else if s == 'c' {
			rank[i] = "No"
		}
	}
	for _, r := range rank {
		fmt.Println(r)
	}
}


Measured memory_bytes: 5412
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long ans=0;
		int[] a=new int[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextInt();
			if(i<a[i]){
				System.out.println(-1);
				return;
			}
		}
		if(a[0]!=0){
			System.out.println(-1);
			return;
		}
		for(int i=1; i<n; i++){
			if(a[i-1]+1<a[i]){
				System.out.println(-1);
				return;
			}else if(a[i-1]>=a[i]){
				ans+=a[i-1];
			}
		}
		ans+=a[n-1];
		System.out.println(ans);
	}
}


Measured memory_bytes: 85528
#include<iostream>
#include<string>
int conv(char c)
{
	switch (c)
	{
	case 'I':
		return 1;
	case 'V':
		return 5;
	case 'X':
		return 10;
	case 'L':
		return 50;
	case 'C':
		return 100;
	case 'D':
		return 500;
	case 'M':
		return 1000;
	default:
		return 0;
	}
}
int main()
{
	for (std::string str; std::cin >> str;)
	{
		str.push_back(' ');
		int sum = 0;
		for (auto itr = str.begin(), end = str.end(); itr != end; itr++)
		{
			sum += conv(*itr) * (conv(*itr) >= conv(*(itr + 1)) ? 1 : -1);
		}
		std::cout << sum << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

void solve(){
    ll d, t, s;
    cin >> d>>t>>s;
    cout << (s*t >= d ? "Yes\n" : "No\n");
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3648
n, m = gets.split.map &:to_i
h = gets.split.map &:to_i
ways = Array.new(m){gets.split.map &:to_i}
dests = Array.new(n){Array.new}
ways.each{|w|
	dests[w[0] - 1] << w[1] - 1
	dests[w[1] - 1] << w[0] - 1
}

good = 0
dests.each_index{|i|
	good += 1 if h[i] > (dests[i].map{|j|h[j]}.max || 0)
}
puts good

Measured memory_bytes: 32792
#include<bits/stdc++.h>
using namespace std;
 
 
 
 
int main(){
	
	long long n,w;cin>>n>>w;


		vector<long long> weight(n),value(n);
	for(int i=0;i<n;i++){
	
	
		cin>>weight[i]>>value[i];
	    
	}
		int sum=0;
		for(auto j:value){
		    sum+=j;
		}
			vector<long long> dp(sum+1,1000000001);
			dp[0]=0;
		for(int i=0;i<n;i++){
		for(int j=sum;j>=0;j--){
			if(j-value[i]>=0){
				dp[j] = min(dp[j],dp[j-value[i]]+weight[i]);
			}
// 			cout<<dp[j]<<" ";
		}
		}
	
	long long ans = 1000000001;
	for(int i=0;i<dp.size();i++){
		if(dp[i]<=w)ans = i;
	}
	cout<<ans;
}

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

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

    vector<ll> numCnt(100100);
    ll sum = 0;
    rep (i, n)
    {
        ll a;
        cin >> a;
        numCnt[a]++;
        sum += a;
    }

    ll q;
    cin >> q;

    vector<ll> ans(q + 1);
    ans[0] = sum;
    rep (i, q)
    {
        ll b, c;
        cin >> b >> c;

        ans[i + 1] = ans[i] - numCnt[b] * b + numCnt[b] * c;
        numCnt[c] += numCnt[b];
        numCnt[b] = 0;
    }

    rep (i, q)
        cout << ans[i + 1] << endl;
    return 0;
}

Measured memory_bytes: 4840
N = int(input())
ST = []
for i in range(N):
    x, l = list(map(int, input().split()))
    ST.append([x-l, x+l])
ST.sort(key = lambda x :x[1])
startT = ST[0][1]
ans = 1
if N != 1:
    for i in range(1,N):
        if startT <= ST[i][0]:
            startT = ST[i][1]
            ans += 1
            
print(ans)

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

int main(){
   int a, i;
   double total = 0;
   double answer;
   cin >> a;
   double b[a];
   for(i = 0; i < a; i++){
       cin >> b[i];
       total += 1/b[i];
   }

   answer = 1/total;
   cout << answer;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
const ll big=998244353;
const ll bbig=1000000007;
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%bbig;
    ll t=exp(x,y/2);
    return (t*t)%bbig;
}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll in(ll x){
    return exp(x,bbig-2);
}
/*ll com(ll x,ll y){
    ll ans=1;
    rep(i,y){ans*=x-i;ans%=bbig;}
    rep(i,y){ans*=in(i+1);ans%=bbig;}
    return ans;
}*/

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(0);
    /*--------------------------------*/
    
    int n;cin >> n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        ll k=n/i;
        ans+=(k+1)*k/2 *i;
    }
    cout << ans << endl;
}

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

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

  vector<ll> a(n), f(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  for (ll i = 0; i < n; i++) cin >> f[i];
  
  sort(a.begin(), a.end(), greater<ll>());
  sort(f.begin(), f.end());

  ll xmin = -1;
  ll xmax = 1e12;
  while (xmax - xmin > 1) {
    ll xnow = (xmax + xmin) / 2;
    ll cnt = 0;
    for (ll i = 0; i < n; i++) {
      if (xnow < a[i] * f[i]) {
        cnt += (a[i] * f[i] - xnow + f[i] - 1) / f[i];
      }
    }

    if (cnt <= k) {
      xmax = xnow;
    } else {
      xmin = xnow;
    }
  }
  cout << xmax << endl;
}


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

int main(){
    int N;
    int64_t ans=0,cnt=0;
    cin >> N;
    vector<string> vec(N);
    for(int i=0;i<N;i++){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        vec.at(i)=s;
    }
    sort(vec.begin(),vec.end());
    string pre=vec.at(0);
    for(int i=1;i<N;i++){
        if(vec.at(i)==pre){
            cnt++;
        }else{
            cnt=0;
        }
        ans+=cnt;
        pre=vec.at(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
n = int(input())
a=list(map(int,input().split()))
r = []
r.append(sum([a[i] for i in range(n) if i % 2 == 0])-sum([a[i] for i in range(n) if i % 2 ==1]))

for i in range(1,n):
    r.append(a[i-1]*2-r[i-1])

print(" ".join(list(map(str,r))))

Measured memory_bytes: 19096
#include <iostream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define FOR(i,n,m) for(int i=n; i<(int)m; i++)
#define ROF(i,n,m) for(int i=n; i>(int)m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define ri(a) scanf("%d",&a)
#define rii(a,b) ri(a),ri(b)
#define riii(a,b,c) rii(a,b),ri(c)
#define lri(a) scanf("%lld",&a)
#define lrii(a,b) lri(a),lri(b)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define all(x) x.begin(),x.end()
#define debug true
#define dprintf debug && printf

const int INF = 0x3f3f3f3f;
const ll INFLL = 1e18;
const int MOD = 1e9+7;
const int MAXN = 2e5+5;

string s;
int k;
set <string> ss;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> s >> k;
    int n = s.size();
    FOR(len,1,6){
        FOR(i,0,n - len+1){
            ss.insert(s.substr(i,len));
        }
    }

    int cnt = 0;
    for(auto str : ss){
        cnt++;
        if(cnt == k){
            cout << str << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main() {
    string s;cin>>s;
    // char akiba[9] = {'A','K','I','H','A','B','A','R','A'}
    bool can = true;
    int cnt = 0;
    int a_cnt = 0;
    rep(i,s.size()){
        char c = s[i];
        if(c=='A'){
            if(cnt==0 || cnt==4 || cnt==6 || cnt==8)cnt++;
            else can = false;
        }else if(c=='K'){
            if(cnt<=1)cnt=2;
            else can = false;
        }else if(c=='I'){
            if(cnt==2)cnt++;
            else can = false;
        }else if(c=='H'){
            if(cnt==3)cnt++;
            else can = false;
        }else if(c=='B'){
            if(4==cnt || cnt==5)cnt=6;
            else can = false;
        }else if(c=='R'){
            if(cnt==6 || cnt==7)cnt=8;
            else can = false;
        }else {
            can = false;
        }
    }
    if(cnt < 8)can = false;
    cout << (can? "YES": "NO") << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()



int main() {
	bool dp[101] = {false};
	dp[4] = dp[7] = true;

	rep(i, 101) {
		if (0 <= i - 4 && dp[i - 4]) dp[i] = true;
		if (0 <= i - 7 && dp[i - 7]) dp[i] = true;
	}

	ll N;
	cin >> N;
	cout << (dp[N] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
//Created Time:2020年03月19日 星期四 14时11分16秒
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 1003

using namespace std;

int n;
int x[N], y[N];

int main(){
	scanf("%d", &n); bool flag;
	for(int i = 1; i <= n; ++i){
		scanf("%d%d", x + i, y + i);
		if(i == 1) flag = abs(x[i]) + abs(y[i]) & 1;
		else if((abs(x[i]) + abs(y[i]) & 1) != flag) return puts("-1"), 0;
	}
	int m = 31;
	cout << m + (!flag) << endl;
	for(int i = 0; i < m; ++i) cout << (1ll << m - i - 1) << ' ';
	if(!flag) cout << 1; cout << endl;
	for(int i = 1; i <= n; ++i){
		long long nx = 0, ny = 0;
		if(!flag) --x[i];
		for(int j = 0; j < m; ++j){
			long long tmp, d = 1 << m - 1 - j, mn = 2147483647;
			if(abs(nx + d - x[i]) + abs(ny - y[i]) < mn)
				mn = abs(nx + d - x[i]) + abs(ny - y[i]), tmp = 0;
			if(abs(nx - d - x[i]) + abs(ny - y[i]) < mn)
				mn = abs(nx - d - x[i]) + abs(ny - y[i]), tmp = 1;
			if(abs(nx - x[i]) + abs(ny + d - y[i]) < mn)
				mn = abs(nx - x[i]) + abs(ny + d - y[i]), tmp = 2;
			if(abs(nx - x[i]) + abs(ny - d - y[i]) < mn)
				mn = abs(nx - x[i]) + abs(ny - d - y[i]), tmp = 3;
			switch(tmp){
				case 0:
					nx += d, putchar('R'); break;
				case 1:
					nx -= d, putchar('L'); break;
				case 2:
					ny += d, putchar('U'); break;
				case 3:
					ny -= d, putchar('D'); break;
			}
		}
		if(!flag) putchar('R'); putchar('\n');
//		cout << nx << ' ' << ny << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=111;
char s[N];
LL n;
LL k;
int main(){
	cin>>s>>k;
	n=strlen(s);
	int i=0;
	while(i+1<n&&s[i]==s[i+1]){
		i++;
	}
	int j=n-1;
	while(j-1>=0&&s[j]==s[j-1]){
		j--;
	}
	LL ans=0;
	if(j==0){
		ans=n*k/2;
	}
	else{
		int l=0,r=n-1;
		if(s[0]==s[n-1]){
			// cerr<<"QAQ "<<i<<" "<<j<<endl;
			l=i+1;
			r=j-1;
			LL x=i-0+1;
			LL y=n-1-j+1;
			// cerr<<x<<" "<<y<<endl;
			ans+=x/2;
			ans+=y/2;
			ans+=(x+y)/2*(k-1);
		}
		char cur='\0';
		LL cnt=0;
		for(int i=l;i<=r;i++){
			if(s[i]!=cur){
				ans+=cnt/2*k;
				cnt=1;
				cur=s[i];
			}
			else{
				cnt++;
			}
		}
		// cerr<<cnt<<endl;
		ans+=cnt/2*k;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int N,T,E;
int a[10000]={0};
int main(){
	cin>>N>>T>>E;
	for(int i =0;i < N;i++){
		int t;
		cin>>t;
		for(int j =T-E;j <=T+E;j++){
			if(j%t==0){
				cout <<i+1<<endl;
				return 0;
			}
		}
	}
	cout <<-1<<endl;
	return 0;
}

Measured memory_bytes: 1168
N, x = map(int, input().split())
a = [int(i) for i in input().split()]

ret = 0
for i in range(N - 1) :
    if a[i] + a[i + 1] > x :
        ret += a[i] + a[i+1] - x
        
        if a[i] >= x :
            a[i] = x
            a[i + 1] = 0
        else :
            a[i + 1] = x - a[i]
            
print(ret)

Measured memory_bytes: 63984
/*************************************************************************
  > File Name: b.cpp
  > Author: Samuel
  > Mail: enminghuang21119@gmail.com
  > Created Time: Sat Apr  4 20:01:41 2020
*************************************************************************/

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

int in[1010];
int n, m;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> in[i];
        sum += in[i];
    }
    sum = sum / 4 / m + ((sum % (4 * m)) != 0);
    while (n--) {
        if (in[n] >= sum)
            m--;
    }
    cout << (m > 0 ? "No" : "Yes");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] L = new long[N];
		for (int i = 0; i < N; i++) {
			L[i] = sc.nextLong();
		}
		sc.close();

		Arrays.sort(L);

		int cnt = 0;
		for (int i = 0; i < N - 2; i++) {
			for (int j = i + 1; j < N - 1; j++) {
				for (int k = j + 1; k < N; k++) {
					if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i] && L[i] + L[j] > L[k]) {
						cnt++;
					}
				}
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 36280
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main(void){
  int n,i,a[100005],b[100005],c[100005];
  
  cin >> n;
  for (i=0;i<n;i++) cin >> a[i];
  for (i=0;i<n;i++) cin >> b[i];
  for (i=0;i<n;i++) cin >> c[i];
  
  sort(a,a+n,greater<int>());
  sort(b,b+n,greater<int>());
  sort(c,c+n,greater<int>());
  
  int al,bl,cl;
  ll ba[100005]={},ans=0;
  al=0;
  for (bl=0;bl<n;bl++){
    while (al<n && a[al]>=b[bl]) al++;
    if (al==n) break;
    ba[bl]=n-al;
  }
  for (i=n-2;i>=0;i--) ba[i]+=ba[i+1];
  
  bl=0;
  for (cl=0;cl<n;cl++){
    while (bl<n && b[bl]>=c[cl]) bl++;
    if (bl==n) break;
    ans+=ba[bl];
  }
  
  cout << ans << endl;
  
  return 0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    string n;
    cin >> n;
    for(int i = 0; i < 3; i++){
        if(n[i] == '9') n[i] = '1';
        else if(n[i] == '1') n[i] = '9';
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  while (true) {
    int n; cin >> n;
    if (!n) break;
    int w, h; cin >> w >> h;
    VV<> a(w, V<>(h));
    VV<> c(w + 1, V<>(h + 1));
    while (n--) {
      int x, y; cin >> x >> y, --x, --y;
      ++a[x][y];
    }
    for (int x = 0; x < w; ++x) for (int y = 0; y < h; ++y) {
      c[x + 1][y + 1] = c[x + 1][y] + c[x][y + 1] - c[x][y] + a[x][y];
    }
    int s, t; cin >> s >> t;
    int res = 0;
    for (int x = 0; x + s <= w; ++x) for (int y = 0; y + t <= h; ++y) {
      res = max(res, c[x + s][y + t] - c[x + s][y] - c[x][y + t] + c[x][y]);
    }
    cout << res << '\n';
  }
}


Measured memory_bytes: 3264
const val mod = 1000000007L

fun main() {
    val n = readLine()!!.toInt()
    val dp = longArrayOf(8, 2, 0)
    for (i in 2..n) {
        dp[2] = (dp[2] * 10 + dp[1]) % mod
        dp[1] = (dp[1] * 9 + dp[0] * 2) % mod
        dp[0] = dp[0] * 8 % mod
    }
    println(dp[2])
}


Measured memory_bytes: 34496
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long int n,W;cin>>n>>W;
long long     int v[n],w[n];
    for(long long int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
 
 
    }
long long     int a[n+1][W+1];
    for(long long int i=0;i<=n;i++ )
    {
        for(long long int j=0;j<=W;j++)
        {
            if(i==0||j==0)a[i][j]=0;
            else if(w[i-1]<=j)
                a[i][j]=max(a[i-1][j],a[i-1][j-w[i-1]]+v[i-1]);
                else
                a[i][j]=a[i-1][j];
                
                
            
            
            
        }
    }cout<<a[n][W];
    
}


Measured memory_bytes: 79104
#include <iostream>
#include <string>

using namespace std;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT0(i, n) RPT(i, 0, n - 1)
#define RPT1(i, n) RPT(i, 1, n)

char maxS(string s)
{
    if (s.empty()) return 'a' - 1;
    char cur = 'a';
    RPT0(i, s.length())
    if (s[i] > cur) cur = s[i];
    return cur;
}

void Print(string S, int n)
{
    char last = maxS(S);
    if (S.length() < n) {
        for (char c = 'a'; (c <= last + 1) && (c - 'a' < n); c++) {
            string newS = S;
            newS.push_back(c);
            Print(newS, n);
        }
    } else {
        cout << S << endl;
    }
}

void resolve()
{
    int N;
    cin >> N;

    string ans = "";
    Print(ans, N);
}

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


Measured memory_bytes: 1536
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

string s;
int cnt[3];

int main(){
    cin >> s;
    int sz = s.size();
    REP(i,sz) cnt[(s[i] - 'a')]++;
    int mn = *(min_element(cnt,cnt+3));
    REP(i,3) cnt[i] -= mn;
    cout << (*(max_element(cnt,cnt+3)) <= 1 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n) for(int i = 0; i < (n); i++)
const int MOD = 1e9+7;
int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct Edge{int to,weight;};
/*----------------------------------------------*/

signed main(){
  int n,k;
  cin>>n>>k;
  vector<double> p(n);
  rep(i,n){
    double x; cin>>x;
    p[i]=(x+1)/2;
  }
  rep(i,n-1) p[i+1]+=p[i];
  double ans=p[k-1];
  rep(i,n-k){
    if(p[k+i]-p[i]>ans){
     ans=p[k+i]-p[i];
    //  cout<<ans<<endl;
    }
  }
//  rep(i,n) cout<<p[i]<<endl;
// cout<<endl;
  cout<<setprecision(15)<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    long long n,d;
    cin>>n>>d;
    d = 2*d + 1;
    if(n%d == 0)    cout<<n/d;
    else            cout<<n/d + 1;
}
int main(){
    solve();
}

Measured memory_bytes: 256
'use strict'
function Main(input){
  input=readAsNumArray(input);
  for(let i=0;i<input.length;i++){
    input[i]=parseInt(input[i]);
  }
  var N=input.shift();
  var M=input.shift();
  var x=[],y=[],z=[];
  for(let i=0;i<N;i++){
    x[i]=input[3*i];
    y[i]=input[3*i+1];
    z[i]=input[3*i+2];
  }
  var X=minus(x);
  var Y=minus(y);
  var Z=minus(z);
  var counters=[];
  counters[0]=maximize(x,y,z,N,M);
  counters[1]=maximize(X,y,z,N,M);
  counters[2]=maximize(x,Y,z,N,M);
  counters[3]=maximize(X,Y,z,N,M);
  var max=Math.max.apply(null,counters);
  console.log(max);
} 

function maximize(x,y,z,N,M){
  var t=[];
  for(let i=0;i<N;i++){
    var val=x[i]+y[i]+z[i];
    var t_=t.concat();
    var m=0;
    var c=0;
    while(t_.length>0){
      m=Math.floor((t_.length-1)/2);
      if(t_[m]<val){
        t_.splice(0,m+1);
        c+=m+1;
      }else{
        t_.splice(m,Infinity);
      }
    }
    t.splice(c,0,val);
  }
  
  var counter1=0;
  for(let i=0;i<M;i++){
    counter1+=t[N-1-i];
  }
  var counter2=0;
  for(let i=0;i<M;i++){
    counter2+=-t[i];
  }
  
  return Math.max(counter1,counter2);
}

function minus(x){
  var x_=[];
  for(let i=0;i<x.length;i++){
    x_[i]=-x[i];
  }
  return x_;
}


function readAsNumArray(input){

var I=[],i=0;

var checkNum=/^-*\d+/;

var checkSpace=/ +|\n+/;

while(input.length>0){

if(input.match(checkNum)!==null){

I[i]=input.match(checkNum)[0];

input=input.replace(checkNum,""); 

i++;

continue;

}

input=input.replace(checkSpace,"");

continue;

}

return input=I;
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 33676
def gcd(a, b):
	while b > 0:
		a, b = b, a % b
	return a


N = int(input())
A = list(map(int, input().split()))

if N == 2:
  print(max(A))
else:

  L = [0 for j in range(N+1)]
  R = [0 for j in range(N+1)]
  
  for j in range(N):
    L[j+1] = gcd(L[j], A[j])
  for j in reversed(range(N)):
    R[j] = gcd(R[j+1], A[j])

    m = -1
  for j in range(N):
    m = max(m, gcd(L[j], R[j+1]))
  print(m)

Measured memory_bytes: 14400
n, m = map(int, input().split())
a = []
b = []
for _ in range(n):
  t = list(map(int, input().split()))
  a.append(t)
for _ in range(m):
  b.append(int(input()))
for i in range(n):
  t = 0
  for j in range(m):
    t += a[i][j] * b[j]
  print(t)


Measured memory_bytes: 6012
x, y, _a, _b, _c = gets.split.map(&:to_i)
p = gets.split.map(&:to_i).sort_by(&:-@).take(x)
q = gets.split.map(&:to_i).sort_by(&:-@).take(y)
r = gets.split.map(&:to_i).sort_by(&:-@).take(x + y)

puts p.concat(q, r).sort_by(&:-@).take(x + y).sum

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,k; cin >> n >> k;
  set<int> st;
  for(int i = 0; i < k; ++i){
    int d; cin >> d;
    for(int j = 0; j < d; ++j){
      int x; cin >> x;
      st.emplace(x);
    }
  }
  cout << n - st.size() << endl;
  return 0;  
}


Measured memory_bytes: 3600
N, K, S = map(int, input().split())

A = [S for i in range(K)]
A += [(int(1e9) if S != int(1e9) else 1) for i in range(N - K)]

for i in range(N):
    if i > 0:
        print(' ', end='')
    print(A[i], end='')


Measured memory_bytes: 8480
#include <iostream>
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define li long ll
#define pp pair<ll, ll>
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
#define pb push_back
#define llp(i, x, n) for (ll i = x; i < n; i++)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define fr first
#define ss second
#define mod 1000000007
using namespace std;
int main()
{
	fast;
    int n,m;
    cin>>n>>m;
    vector<int> adj[n+1];
    while(m--)
    {
    	int u,v;
    	cin>>u>>v;
    	adj[u].pb(v);
    	adj[v].pb(u);
    }
    bool vis[n+1];
    memset(vis,false,sizeof(vis));
    vector<int> v;
    for(int i=1;i<=n;i++)
    {
    	if(vis[i]==false)
    	{
    		int c=1;
    		queue<int> q;
    		q.push(i);
    		vis[i]=true;
    		while(!q.empty())
    		{
    			int x=q.front();
    			q.pop();
    			for(auto it:adj[x])
    			{
    				if(vis[it]==false)
    				{
    					vis[it]=true;
    					q.push(it);
    					c++;
    				}
    			}
    		}
    		v.pb(c);
    	}
    }
    int mm=INT_MIN;
    for(auto it:v)
    {
    	mm=max(mm,it);
    }
    cout<<mm<<endl;
}

Measured memory_bytes: 14988
#include<stdio.h>+
int h;
int n;
int sum = 0;
int tmp;
int main()
{

	scanf("%d %d", &h, &n);
	for(int i = 0; i < n; i++)
	{
		scanf("%d",&tmp);
		sum += tmp;
	}
	if(sum >= h)
		printf("Yes\n");
	else 
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().solve(new Scanner(System.in));
	}
	
	public void solve(Scanner sc) {
		int d = Integer.parseInt(sc.next());
		int n = Integer.parseInt(sc.next());
                if(n==100) n+=1;
		
		StringBuilder sb = new StringBuilder();
		sb.append(n);
		for(int i=0; i<d; i++) {
			sb.append("00");
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 22612
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int n, ww;
    cin >> n >> ww;
    vector<ll> w(n);
    vector<ll> v(n);
    ll v_max = 0;
    for (int i=0; i<n; i++) {
        cin >> w[i] >> v[i];
        v_max = max(v_max, v[i]);
    }

    vector<ll> dp(v_max*n+1, INT_MAX);
    dp[0] = 0;
    for (int i=0; i<n; i++) {
        for (int j=v_max*n; j>=v[i]; j--)
            dp[j] = min(dp[j], dp[j-v[i]]+w[i]);
    }

    ll ans;
    for (ans=v_max*n; ans>=0; ans--) {
        if (dp[ans] <= ww) break;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d);
	int t = max(0, min(b, d) - max(a, c));
	printf("%d\n", t);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int ticket[5];
	int i,num,mai;
	int n[4];
	
	for (i = 0; i < 4; i++){
		
		scanf("%d %d", &num, &mai);
		
		ticket[num] = mai;
		
		n[i] = num;
	}
	
	ticket[1] *= 6000;
	ticket[2] *= 4000;
	ticket[3] *= 3000;
	ticket[4] *= 2000;
	
	for (i = 0; i < 4; i++){
		printf("%d\n", ticket[n[i]]);
	}
	return (0);
}

Measured memory_bytes: 600
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
cd = [list(map(int,input().split())) for _ in range(m)]
ans = [0]*n
for i in range(n):
    count = 10**9
    for j in range(m):
        ch = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if ch < count:
            ans[i] = j+1
            count = ch
    print(ans[i])

Measured memory_bytes: 9212
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as MP
import qualified Data.Set as ST
import qualified Data.Sequence as SQ
import Data.Array
import Data.Array.ST
import Data.Array.IO
import Data.Maybe
import Data.Ratio
import Data.Char
import Data.Bits
import Data.List
import Data.Tuple
import Data.Functor
import Data.IORef
import Data.STRef
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Debug.Trace

type Graph = V.Vector [(Int,Int)]
type Distance = VUM.IOVector Int
type Queue = ST.Set (Int, Int)
 
buildGraph :: V.Vector (Int, (Int, Int)) -> Int -> Graph
buildGraph xs n = V.accumulate step (V.replicate n []) xs
  where
    step xs v = v:xs
 
dijkstra :: Int -> Int -> Graph -> IO Distance
dijkstra vertex from graph = do
  distance <- VUM.replicate vertex (10^9) :: IO Distance
  VUM.write distance from 0 
  trav graph distance (ST.singleton (0, from))
  where
    trav :: Graph -> Distance -> Queue -> IO Distance
    trav graph distance queue
      | ST.null queue = return distance
      | otherwise = do
          tmp <- VUM.read distance from
          case compare acc tmp of
            LT -> update from acc distance queue' >>= trav graph distance
            EQ -> update from acc distance queue' >>= trav graph distance
            GT -> trav graph distance queue'
        where
          ((acc, from), queue') = ST.deleteFindMin queue
 
    update :: Int -> Int -> Distance -> Queue -> IO Queue
    update f a dist q = update' a dist (graph V.! f) q

    update' :: Int -> Distance -> [(Int, Int)] -> Queue -> IO Queue
    update' _ _ [] q = return q
    update' a dist ((to, cost):xs) q = do
      tmp <- VUM.read dist to
      case compare a' tmp of
          LT -> do
            VUM.write dist to a'
            update' a dist xs (ST.insert (a', to) q)
          _ ->
            update' a dist xs q
      where
        a' = a + cost
  
main = do
  [n,x,y] <- map read . words <$> getLine :: IO [Int]

  let
    base = zip [0..n-2] [1..n-1]
    vs = [(x-1,y-1), (y-1,x-1)] ++ ((map swap base) ++ base)
    vs' = map (\(a,b) -> (a,(b,1))) vs
    graph = buildGraph (V.fromList vs') n

  table <- VUM.replicate n 0 :: IO (VUM.IOVector Int)

  forM_ [0..n-1] $ \i -> do
    distance <- dijkstra n i graph
    forM_ [i+1..n-1] $ \j -> do
      VUM.read distance j >>= \r -> 
        VUM.modify table (+1) r
  
  forM_ [1..n-1] $ \i -> do 
    VUM.read table i >>= print

Measured memory_bytes: 2428
#include<bits/stdc++.h>
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
int n;
ld dp[310][310][310];
ld solve(int one, int two, int three)
{
    if(dp[one][two][three] != -1) return dp[one][two][three];
    ld ev = 0, sum = one + two + three;
    if(sum == 0) return 0;
    if(one > 0) ev += (ld)one * (solve(one - 1, two, three));
    if(two > 0) ev += (ld)two * (solve(one + 1, two - 1, three));
    if(three > 0) ev += (ld)three * (solve(one, two + 1, three - 1));
    ev += n;
    ev /= (ld)sum;
    return dp[one][two][three] = ev;
}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    int a[4] = {};
    for(int i = 0; i < n; i++)
    {
        int b;
        cin >> b;
        a[b]++;
    }
    for(int i = 0; i < 310; i++)
        for(int j = 0; j < 310; j++)
            for(int k = 0; k < 310; k++)
                dp[i][j][k] = -1;
    cout << setprecision(10) << fixed << solve(a[1], a[2], a[3]) << "\n";
    return 0;
}


Measured memory_bytes: 465792
from collections import deque 
n,m=map(int,input().split())
edge=[[] for i in range(n+1)]
for i in range(m):
  a,b=map(int,input().split())
  edge[a].append(b)
  edge[b].append(a)

def bfs(x):
  qu=deque([])
  qu.append(x)
  ans=[0]*(n+1)
  ans[1]=1
  while qu:
    now=qu.popleft()
    
    for i in edge[now]:
      if ans[i]==0:
        qu.append(i)
        ans[i]=now
  return ans
ans=bfs(1)
ans.pop(0)
if 0 in ans:
  print("No")
else:
  print("Yes")
  for i in range(1,len(ans)):
    print(ans[i])
    

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

struct max_min
{
    int64_t max = 0;
    int64_t min = 0;
};

const int64_t cc = pow( 10, 9 ) + 7;
//std::cout<< std::fixed << std::setprecision(10) << ( double )( max ) / 2;
bool sort_pair( std::pair< int64_t, int64_t > origin, std::pair< int64_t, int64_t > another )
{
    return origin.first < another.first;
}


int main()
{
    std::string word = "aa";
    int64_t a,b,c,d,e,f;
    char aa;
    bool change = false;
    std::vector< std::pair< int64_t, int64_t > > list;
    std::cin>> word;
    std::cin>> a;
    
    for( int i = 0; i < a; i++ )
    {
        std::cin>> b;

        if( b == 2 )
        {
            std::cin>> c;
            std::cin>> aa;
            
            if( c == 1 )
            {
                if( !change )
                {
                    word.insert( word.begin(), aa );
                }
                else
                {
                    word.push_back( aa );
                }
            }
            else
            {
                if( change )
                {
                    word.insert( word.begin(), aa );
                }
                else
                {
                    word.push_back( aa );
                }
            }
        }
        else
        {
            if( change )
            {
                change = false;
            }
            else
            {
                change = true;
            }
        }
    }

    if( !change )
    {
        for( int i = 0; i < word.size(); i++ )
        {
            std::cout<< word[i];
        }
    }
    else
    {
        for( int i = word.size() - 1; i >= 0; i-- )
        {
            std::cout<< word[i];
        }
    }
}


Measured memory_bytes: 900
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
int main() {
	string s;
	cin >> s;
	int sum = 700;
	if (s[0] == 'o')
		sum += 100;
	if (s[1] == 'o')
		sum += 100;
	if (s[2] == 'o')
		sum += 100;
	cout << sum << "\n";
}

Measured memory_bytes: 3624
H,N = map(int,input().split())
spells = [tuple(map(int,input().split())) for _ in range(N)]
max_a = max(spells)[0]

dp = [0]
for i in range(1, H + max_a + 1):
  try:
    dp.append(min([dp[i - a] + b for a,b in spells if a <= i]))
  except ValueError:
    dp.append(10**8)

print(min(dp[H:]))


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
#include<cmath>
#include<complex>
using namespace std;

typedef complex<double> P;

#define X real()
#define Y imag()
int d[4];
bool f=0;
const char *op="+-*";

int cal(int a,int o,int b){
    if(o==0) return a+b;
    if(o==1) return a-b;
    return a*b;
}

bool sol(int a,int b,int c) {
    f++;
    if (cal(cal(cal(d[0],a,d[1]),b,d[2]),c,d[3])==10) {
        printf("(((%d %c %d) %c %d) %c %d)\n",d[0],op[a],d[1],op[b],d[2],op[c],d[3]);
        return true;
    }
    if (cal(cal(d[0],a,d[1]),b, cal(d[2],c,d[3]))==10) {
        printf("((%d %c %d) %c (%d %c %d))\n",d[0],op[a],d[1],op[b],d[2],op[c],d[3]);
        return true;
    }
    if (cal(cal(d[0],a, cal(d[1],b,d[2])),c,d[3])==10) {
        printf("((%d %c (%d %c %d)) %c %d)\n",d[0],op[a],d[1],op[b],d[2],op[c],d[3]);
        return true;
    }
    return f=0;
}

bool jg() {
    for (int i=0;i<3;++i) {
        for (int j=0;j<3;++j) {
            for (int k=0;k<3;++k) {
                if (sol(i,j,k)) return true;
            }
        }
    }
}


int main(){
    int mod=1000000007;
    for (;;) {
        scanf("%d %d %d %d",&d[0],&d[1],&d[2],&d[3]);
        if (d[0]==d[1] && d[1]==d[2] && d[2]==d[3] && d[0]==0) break;
        sort(d,d+4);
        do {
            if (jg()) break;
        } while (next_permutation(d,d+4));
        if (f==0) printf("0\n");
    }
    return 0;
}

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

using namespace std;
map<string, int> S;
void print(){
    map<string, int>::iterator it;
    long long ans=0;
    for(it=S.begin();it!=S.end();it++){
        ans++;
    }
    cout << ans << endl;
}

int main(){
    long long N;
    string str;

    cin >> N;
    for(int i=0;i<N;i++){
        cin >> str;
        S[str]++;
    }
    print();
    return 0;
}

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

int amida(int n,int m, int tate, int x[][3], int h);

int main(){
    int n,m,a;
    while(cin >> n >> m >> a){
        if(n==0 && m==0 && a==0)break;
        int x[m][3];
        for(int i=0;i<m;i++){
            cin >> x[i][0] >> x[i][1] >> x[i][2];
        }
        int max=x[0][0];
        for(int i=1;i<m;i++){
            if(max<x[i][0])
                max = x[i][0];
        }
        cout << amida(n,m,a,x,max+1) << endl;
    }
}


int amida(int n, int m,int tate, int x[][3],int h){
    if(h==1)
        return tate;
    int kouhoh = 0;
    int kouhow = 0;
    for(;h>1;h--){
        for(int i=0;i<m;i++){
            if((x[i][1]==tate &&x[i][0]<h) && kouhoh<x[i][0]){
                kouhoh = x[i][0];
                kouhow = x[i][2];
            }
            if((x[i][2]==tate &&x[i][0]<h) && kouhoh<x[i][0]){
                kouhoh = x[i][0];
                kouhow = x[i][1];
            }
        }
    }
    if(kouhoh == 0)
        return tate;
    return amida(n,m,kouhow,x,kouhoh);
}

Measured memory_bytes: 1168