akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n, m; cin >> n >> m;
    vector<ll> box(n+1, 1);
    vector<bool> red(n+1, false);
    red[1] = true;
    rep(i, m){
        ll x, y; cin >> x >> y;
        if(red[x]) red[y] = true;
        box[x]--;
        box[y]++;

        if(box[x] == 0) red[x] = false;
    }
    ll ans = 0;
    for(auto i : red){
        if(i) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#define INF doll(10000000,10000000)
using namespace std;
class doll{
public:
    int h,r;
    doll(int _h,int _r){
        h=_h;r=_r;
    }
    doll(){}
    bool operator<(const doll &d)const{
        return(h<d.h&&r<d.r);
    }
    bool operator==(const doll &d)const{
        return ((h<=d.h&&r>=d.r)||(h>=d.h&&r<=d.r));
    }

    bool operator>(const doll &d)const{
        return(h>d.h&&r>d.r);
    }
};
int main(){
    int n;
    while(cin>>n,n){
        queue<doll>N,M;
        for(int i=0;i<n;i++){
            int h,r;
            cin>>h>>r;
            N.push(doll(h,r));
        }
        int m;
        cin>>m;
        for(int i=0;i<m;i++){
            int h,r;
            cin>>h>>r;
            M.push(doll(h,r));
        }
        N.push(INF);M.push(INF);
        int cnt=0;
        while(true){
            if(N.front()<M.front())N.pop();
            else if(N.front()>M.front())M.pop();
            else{
                if(N.front()==INF)break;
                N.pop();M.pop();
            }
            cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 100000000
 
int N;
int t[20][20];
int dp[111111];
void bitDP();
 
int main(){
    while(cin >> N , N){
        for(int i=0;i<N;i++){
            for(int j=0;j<N+1;j++){
                cin >> t[i][j];
            }
            //cout << "C" << endl;
        }
        //cout << "B" << endl;
        bitDP();
        //cout << "A" << endl;
    }
}
 
void bitDP(){
    int leng = (1 << N);
    for(int i=0;i<leng+2;i++){
        dp[i] = INF;
    }
    dp[0] = 0;
    for(int i=0;i<leng;i++){
        if(dp[i] == INF) continue;
        for(int next=0;next<N;next++){
            if((i & (1 << next)) != 0) continue;
            int cost = t[next][0];
            for(int j=0;j<N;j++){
                if((i & (1 << j)) != 0){
                    cost = min(cost,t[next][j+1]);
                }
            }
            int bit = (i | (1 << next));
            dp[bit] = min(dp[bit],dp[i]+cost);
        }
    }
    cout << dp[leng-1] << endl;
}

Measured memory_bytes: 1424
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	int n;
	int a,b;
	int wa=0;
	int ans=5000000;
	
	cin>>n;
	for(int i=1;i<n;i++)
	{
		wa=0;
		a=i;
		b=n-a;
		while(a!=0)
		{
			wa+=a%10;
			a/=10;
		}
		while(b!=0)
		{
			wa+=b%10;
			b/=10;
		}
		ans=min(wa,ans);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, k;
  cin >> n >> k;
  vector<ll> num(k, 0);
  rep(i, 1, n + 1) num[i % k]++;

  ll ans = 0;
  rep(a, 0, k) {
    int b = (k - a) % k;
    int c = (k - a) % k;
    if ((b + c) % k != 0)
      continue;
    ans += num[a] * num[b] * num[c];
  }

  cout << ans << endl;
}


Measured memory_bytes: 4712
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	char inp;
	int sum=0;
	while(1){
		scanf("%c",&inp);
		if((inp-'0') <10 &&(inp-'0') >0){
			sum += (inp-'0');
		} else if(inp=='\n'){
			if(sum>0){	
				cout<< sum << endl;
				sum=0;
			} else
				break;
		}
		
	}
	return 0;
}

Measured memory_bytes: 1152
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, k = sc.nextInt()
  val a = Array.fill(n)(sc.nextLong())

  val mod = 1000000007

  def minus(a: Long, b: Long): Long = (a - b + mod) % mod
  def times(a: Long, b: Long): Long = (a * b) % mod

  val b = a.filter(_ != 0).map(e => (e.abs, e)).sorted
  if (b.length < k) {
    println(0)
  } else if (b.length == k) {
    if (b.count(_._2 < 0) % 2 == 0) {
      println(b.map(_._1).reduceLeft(times))
    } else {
      if (a.contains(0)) {
        println(0)
      } else {
        println(minus(0, b.map(_._1).reduceLeft(times)))
      }
    }
  } else {
    if (b.forall(_._2 < 0)) {
      if (k % 2 == 0) {
        println(b.takeRight(k).map(_._1).reduceLeft(times))
      } else {
        if (a.contains(0)) {
          println(0)
        } else {
          println(minus(0, b.take(k).map(_._1).reduceLeft(times)))
        }
      }
    } else {
      val (r, c) = b.splitAt(b.length - k)
      if (c.count(_._2 < 0) % 2 == 0) {
        println(c.map(_._1).reduceLeft(times))
      } else {
        val pf = c.indexWhere(_._2 > 0)
        val mf = c.indexWhere(_._2 < 0)
        if (pf == -1) {
          c(mf) = r.findLast(_._2 > 0).get
        } else {
          val ml = r.findLast(_._2 < 0)
          val pl = r.findLast(_._2 > 0)

          if (ml.isEmpty) {
            c(mf) = pl.get
          } else if (pl.isEmpty) {
            c(pf) = ml.get
          } else {
            if (c(pf)._1 * pl.get._1 < c(mf)._1 * ml.get._1) {
              c(pf) = ml.get
            } else {
              c(mf) = pl.get
            }
          }
        }
        println(c.map(_._1).reduceLeft(times))
      }
    }
  }
}


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

struct point { ll x, y; };

ll f(point a, point b, point c, point d, point e) {
  ll l = min({a.x, b.x, c.x, d.x});
  ll r = max({a.x, b.x, c.x, d.x});
  ll dn = min({a.y, b.y, c.y, d.y});
  ll u = max({a.y, b.y, c.y, d.y});
  if(e.x < l || e.x > r) return 0LL;
  if(e.y < dn || e.y > u) return 0LL;
  return (r - l) * (u - dn);
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<point> p(N);
  rep(i, 0, N) {
    ll x, y;
    cin >> x >> y;
    p[i].x = x;
    p[i].y = y;
  }
  ll ans = 4e18;
  rep(i, 0, N-1) rep(j, i+1, N) rep(k, 0, N-1) rep(l, k+1, N)  {
    int cnt = 0;
    ll mn = 4e18;
    rep(m, 0, N) {
      ll tmp = f(p[i], p[j], p[k], p[l], p[m]);
      if(tmp) {
        cnt++;
        mn = min(mn, tmp);
      }
    }
    if(cnt >= K) ans = min(ans, mn);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
import collections

def combinations_count(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    counter = 0
    a_c = collections.Counter(A)
    for v in a_c.values():
        counter += combinations_count(v,2)

    for a in A:
        print(counter-a_c[a]+1)

if __name__ == "__main__":
    main()


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

int main()
{
    int N;
    int a[9] = {0};
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        if (x >= 3200)
        {
            a[8]++;
        }
        else
        {
            a[x / 400]++;
        }
    }

    int color = 0;
    for (int i = 0; i < 8; i++)
    {
        if (a[i] > 0)
        {
            color++;
        }
    }

    int min_ans, max_ans;
    if (color == 0)
    {
        min_ans = 1;
    }
    else
    {
        min_ans = color;
    }
    max_ans = color + a[8];

    cout << min_ans << " " << max_ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  string s; cin >> s;
  map<char, int> cnt;
  for (int i = 0; i < s.size(); ++i) {
    cnt[s[i]]++;
  }

  int ans = 1<<30;
  for (auto v : cnt) {
    char c = v.first;

    int aans = 0;
    string ss = s;
    while (ss.size() != count(ALL(ss), c)) {
      string sss;
      for (int j = 0; j < ss.size()-1; ++j) {
        if (ss[j] == c || ss[j+1] == c) {
          sss.push_back(c);
        } else {
          sss.push_back(ss[j]);
        }
      }
      ss = sss;
      aans++;
    }
    ans = min(ans, aans);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;
const ll mod = 1e9 + 7;

const ll inf = 1LL << 60;

struct mint{
    ll x;
    mint(ll x = 0): x((x % mod + mod)%mod){}

    
    mint& operator+=(const mint a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if((x += mod-a.x) >= mod)  x -= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x) %= mod;
        return *this;
    }
    
    mint operator+(const mint a) const{ //クラスのメンバを変更しない
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const{ //クラスのメンバを変更しない
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const{ //クラスのメンバを変更しない
        mint res(*this);
        return res*=a;
    }

    mint pow(ll n)const{
        if(n == 0)return 1;
        mint a = pow(n>>1);
        a *= a;
        if(n & 1)a *= (*this);
        return a;
    }

    mint inv() const{
        return pow(mod-2);
    }
    mint& operator/=(const mint a){
        return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
        mint res(*this);
        return res/=a;
    }
    
};

ostream& operator<<(ostream &os, const mint &m){
    os << m.x;
    return os;
}

struct Combination{
    vector<mint> fact,ifact;
    Combination(int n): fact(n+1),ifact(n+1){
        fact[0] = 1;
        for(int i = 1; i<=n; i++)fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for(int i = n; i>= 1; i--){
            ifact[i-1] = ifact[i] * i;
        }
    }

    mint comb(int n, int k){
        if(k < 0 || n < k)return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);

    ll S;cin>>S;
    Combination C(4000);
    ll now = S - 3;
    ll shikiri = 0;
    mint ans = 0;
    while(now >= 0){
        ans += C.comb(now + shikiri, now);
        shikiri++;
        now -= 3;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

long gcd(long a,long b){
  if(b > a) swap(a,b);
  if(b == 0) return a;
  return gcd(a%b , b);
}

int main(){
  long a,b;
  cin >> a >> b;
  long g = gcd(a,b);
  if(g == 1){
    cout << 1 << endl;
    return 0;
  }
  vector<long> list;
  for(long i=1;i<=sqrt(g);i++){
    if(g % i != 0) continue;
    list.push_back(i);
    list.push_back(g/i);
  }
  sort(list.begin(),list.end());
  long n = list.size();
  bool flag = false;
  for(long i = n-1; i>=1 ;i--){
    for(long j=1; j<n;j++){
      if(j >= i){
        break;
      }
      if(list.at(i) % list.at(j) == 0){
        list.pop_back();
        n--;
        break;
      }
    }
  }
  cout << list.size() << endl;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<cmath>

#define print(x) cout << #x << " = " << x << endl;

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;


int main() {
	int N, M, X, A;
	cin >> N >> M >> X;

	int before = 0, after = 0;
	for (int i = 0; i < M; i++) {
		cin >> A;
		if (A < X) {
			before++;
		}
		else {
			after++;
		}
	}

	if (after < before) cout << after << endl;
	else cout << before << endl;

	return 0;
}

Measured memory_bytes: 256
s = input()
be = int(s[0:2])
af = int(s[2:4]) 
if 0 < be < 13:
  if 1 <= af <= 12:
    print('AMBIGUOUS')
  else:
    print('MMYY')
elif 0 < af < 13:
  if 1 <= be <= 12:
    print('AMBIGUOUS')
  else:
    print('YYMM')
else:
  print('NA')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e15;


int main(){
    ll n;
    cin>>n;
    ll res = inf;
    for(ll i=1;i*i<=n;i++){
	if( n%i == 0 ){
	    //cout<<i<<' '<<n/i<<endl;
	    res = min( res , i + n/i -2 );
	}
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int visit[2020];
int dist[2020];
int level[2020];
queue<int>qu;
vector<int>me[2020];
void bfs(int i){
	level[i]=0;
	visit[i]=1;
	qu.push(i);
	while(!qu.empty()){
		int a=qu.front();
		qu.pop();
		for(auto A=0;A<me[a].size();A++){
			if(visit[me[a][A]]==0){
				qu.push(me[a][A]);
				level[me[a][A]]=level[a]+1;
				dist[level[me[a][A]]]+=1;
				visit[me[a][A]]=1;
			}
		}
	}
}
int main(){
	int n,x,y;
	cin >> n >> x >> y;
	me[x].push_back(y);
	me[y].push_back(x);
	for(int i=1;i<n;i++){
		me[i].push_back(i+1);
		me[i+1].push_back(i);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			visit[j]=0;
		bfs(i);
	}
	for(int i=1;i<=n-1;i++)
		printf("%d\n",dist[i]/2);
}


Measured memory_bytes: 384
from itertools import permutations
N,M,R = list(map(int,input().split()))
r = list(map(int,input().split()))
r = [i-1 for i in r]
ABC = [[float('inf') for i in range(N)]for j in range(N)]
for i in range(N):
    ABC[i][i] = 0
for i in range(M):
    a,b,c = list(map(int,input().split()))
    a -= 1
    b -= 1
    ABC[a][b] = c
    ABC[b][a] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            ABC[i][j] = min(ABC[i][j],ABC[i][k]+ABC[k][j])
ans = float('inf')
for i in permutations(r):
    cost = 0
    now = i[0]
    for j in range(1,len(i)):
        cost += ABC[now][i[j]]
        now = i[j]
    ans = min(ans,cost)
print(ans)

Measured memory_bytes: 71896
#include<iostream>
using namespace std;
int main(){
  string s;
  cin>>s;
  int r=0;
  for(int i=0;i<3;i++){
    if(s[i]=='R')
        r=1;
  }
  for(int i=0;i<2;i++){
    if(s[i]=='R'){
        if(s[i]==s[i+1])
            r++;
    }
  }
  cout<<r<<"\n";
}


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

int main(){
    int N;
    int a[110];
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> a[i];
    set<int> values;
    for (int i = 0; i < N;i++){
        values.insert(a[i]);
    }
    cout << values.size() << endl;
}

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

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

  int n;
  vector<int> a;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    a.push_back(t);
  }

  const int A_MAX = 10000;
  vector<int> c(A_MAX + 1);
  for (int i = 0; i <= A_MAX; ++i) {
    c[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    ++c[a[i]];
  }
  for (int i = 1; i <= A_MAX; ++i) {
    c[i] += c[i - 1];
  }

  vector<int> b(a.size());
  for (int i = 0; i < n; ++i) {
    b[--c[a[i]]] = a[i];
  }

  for (int i = 0; i < n; ++i) {
    if (i) {
      cout << " ";
    }
    cout << b[i];
  }
  cout << endl;

  return 0;
}



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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    reverse(s.begin(), s.end());
    int x = 1, total = 0;
    vector<int> cnt(2019); // cnt[i]: 2019で割ったあまりがiとなる数字の個数
    long long ans = 0;
    for (int i = 0; i < n; i++)
    {
        cnt[total] += 1;
        total += (s[i] - '0') * x; // xの桁の数字まで
        total %= 2019;
        ans += cnt[total];
        x = x * 10 % 2019;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N, flag, num1, num2, ans, d;

    cin >> N;

    flag = true;
    num1 = 0;
    num2 = 0;
    ans = 1;
    for (int i = 1; i <= N; i++){
        flag = true;
        num2 = 0;
        d = i;
        while (flag == true)
        {
            //cout << i << endl;
            if(d%2 == 0){
                d = d/2;
                num2 += 1;
            }
            else
            {
                if(num1 < num2){
                    ans = i;
                    num1 = num2;
                }
                break;
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
  int a,b,c,d,e,k;
  cin >>a>>b>>c>>d>>e>>k;
  if(e-a <= k){
    cout << "Yay!"<<endl;
  }
  else {
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;


int main() {
  int n, k;
  cin >> n >>k;
  k--;
  if(n>=2*k+1){
    cout<< "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}

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

int main(){
  double D, T, S = 0;
  cin >> D;
  cin >> T;
  cin >> S;
  if (D/S <= T){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3660
N, M = [int(i) for i in input().split()]
A = []
for i in range(N):
    A.append(input())
B = []
for i in range(M):
    B.append(input())
ans = False
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            if all([A[i+h][j:j+M] == B[h] for h in range(M)]):
                ans = True
                break
print("Yes") if ans else print("No")

Measured memory_bytes: 3064
def next_int():
    return int(input())

def next_ints():
    return list(map(int, input().split()))
n = next_int()
a = next_ints()
sum = ans = 0
for i in range(n):
    sum += a[i]
for i in range(n):
    sum -= a[i]
    ans += a[i] * sum
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if((0<=x-r&&x+r<=W)&&(0<=y-r&&y+r<=H)){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2088
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const long double pi = acos(-1);

int main()
{
	long long x , d , r ; 
	cin >> r >> d ;
	cout << (r*3+d)/2 << endl ;
	
	return 0 ;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
vi in;
vvi dp;
int n;
int f(int a,int b){
	if(a<0||a>=n||b<=0||b>n)return 0;
	if(dp[a][b]!=-inf)return dp[a][b];
	int out=0;
	{
		int t=f(a+1,b-2);
		if(t==b-2&&abs(in[a]-in[a+b-1])<=1)out=t+2;
	}
	rep(i,b-1){
		int s=f(a,i+1);
		int t=f(a+i+1,b-i-1);
		out=max(out,s+t);
	}
	if(b==2&&abs(in[a]-in[a+1])<=1)out=2;
	return dp[a][b]=out;
}
int main(){
	while(cin>>n,n){
		in=vi(n);
		rep(i,n)cin>>in[i];
		dp=vvi(n,vi(n+1,-inf));
		cout<<f(0,n)<<endl;
//		rep(i,n){rep(j,n+1)cout<<" "<<dp[i][j];cout<<endl;}
//		cout<<endl;
	}
}

Measured memory_bytes: 3656
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, popcount[16399]; double x[16][2], y[16][2], dp[16399][16][2];
int main() {
	for (int i = 0; i < 14; i++) {
		for (int j = 1 << i; j < 2 << i; j++) {
			popcount[j] = popcount[j - (1 << i)] + 1;
		}
	}
	int cnt = 0;
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) cin >> x[i][0] >> y[i][0] >> x[i][1] >> y[i][1];
		for (int i = 0; i < 1 << n; i++) {
			for (int j = 0; j < n; j++) {
				dp[i][j][0] = dp[i][j][1] = 1.0e+10;
			}
		}
		for (int i = 0; i < n; i++) dp[1 << i][i][0] = dp[1 << i][i][1] = 0.0;
		for (int i = 1; i < 1 << n; i++) {
			if (popcount[i] == 1) continue;
			for (int j = 0; j < n; j++) {
				if (!(i & (1 << j))) continue;
				int sub = i - (1 << j);
				for (int k = 0; k < 2; k++) {
					for (int l = 0; l < n; l++) {
						if (!(sub & (1 << l))) continue;
						for (int m = 0; m < 2; m++) {
							double dist = hypot(x[j][k ^ 1] - x[l][m], y[j][k ^ 1] - y[l][m]);
							dp[i][j][k] = min(dp[i][j][k], dp[sub][l][m] + dist);
						}
					}
				}
			}
		}
		double ret = 1.0e+10;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 2; j++) {
				ret = min(ret, dp[(1 << n) - 1][i][j]);
			}
		}
		for (int i = 0; i < n; i++) {
			ret += hypot(x[i][0] - x[i][1], y[i][0] - y[i][1]);
		}
		printf("Case %d: %.5lf\n", ++cnt, ret);
	}
	return 0;
}

Measured memory_bytes: 7352
#include<stdio.h>

int main(void){
    char s[3];
    char t[3];
    char dummy;
    int i = 0;
    int cnt = 0;
    char input = '0';

    for(i = 0; i < 3; i++){
        s[i] = '0';
        t[i] = '0';
    }

    scanf("%3s", s);
    input = s[0];
    scanf("%3s", t);
    s[0] = input;

    for(i = 0; i < 3; i++){
        if(s[i] == t[i]){
            cnt++;
        }
    }

    printf("%d", cnt);
    
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	String ball = "A";
	public void change ( String a , String b ) {
		if ( ball.equals(a) ) ball = b;
		else if ( ball.equals(b) ) ball = a;
	}
	
	public static void main ( String[] args ) {
		Main m = new Main();
		Scanner sc = new Scanner(System.in);
		while ( sc.hasNext() ) {
			String s = sc.next();
			String[] cup = s.split(",");
			m.change(cup[0],cup[1]);
		}
		System.out.println(m.ball);
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iostream>

struct Card {
    int num;
    std::string str;
};

void readInput(std::vector<Card>& cardList) {
    int size = 0;
    std::cin >> size;

    cardList.resize(size);
    for (int i=0; i < size; ++i) {
        std::cin >> cardList[i].str;
        cardList[i].num = atoi(cardList[i].str.c_str() + 1);
    }

}

int bubbleSort(std::vector<Card>& cardList) {
    int swapCount = 0;
    bool next = true;

    while (next) {
        next = false;
        for (size_t i = cardList.size() - 1; i >= 1; --i) {
            if (cardList[i].num < cardList[i - 1].num) {
                auto tmp = cardList[i];
                cardList[i] = cardList[i - 1];
                cardList[i - 1] = tmp;
                next = true;
                ++swapCount;
            }
        }
    }

    return swapCount;
}

int selectionSort(std::vector<Card>& cardList) {
    using std::swap;
    

    int swapCount = 0;

    for (size_t i=0; i < cardList.size(); ++i) {
        size_t minj = i;

        for (size_t j = i; j < cardList.size(); ++j) {
            if (cardList[j].num < cardList[minj].num) {
                minj = j;
            }
        }

        if (i != minj) {
            swap<Card>(cardList[i], cardList[minj]);
            ++swapCount;
        }
    }

    return swapCount;
}

bool IsStable(const std::vector<Card>& cardList, const Card& prev, const Card& curr) {
    bool findPrev = false;
    int targetNum = prev.num;
    for (size_t i = 0; i < cardList.size(); ++i) {
        if (cardList[i].num == targetNum) {
            if (!findPrev && cardList[i].str == prev.str) {
                findPrev = true;
            } else if (findPrev) {
                if (cardList[i].str == curr.str) {
                    return true;
                }
            }
        }
    }
    return false;
}

void show(std::vector<Card>& sortedList, std::vector<Card>& orgList) {
    Card* prev = &sortedList.front();
    printf("%s", prev->str.c_str());
    bool isStable = true;
    for (size_t i = 1; i < sortedList.size(); ++i) {
        printf(" ");
        printf("%s", sortedList[i].str.c_str());

        if (prev->num == sortedList[i].num) {
            isStable &=  IsStable(orgList, *prev, sortedList[i]);
        }

        prev = &(sortedList[i]);
    }

    if (isStable) {
        printf("\nStable\n");
    } else {
        printf("\nNot stable\n");
    }
}

int main() {

    std::vector<Card> cardList;
    readInput(cardList);

    // for (auto& str : strList) {
    //     std::cout << str << " ";
    // }
    // std::cout << std::endl;

    // for (auto num : numList) {
    //     printf("%d ", num);
    // }

    std::vector<Card> bubCardList(cardList);
    bubbleSort(bubCardList);
    show(bubCardList, cardList);

    std::vector<Card> ssCardList(cardList);
    selectionSort(ssCardList);
    show(ssCardList, cardList);
    
    return 0;
}



Measured memory_bytes: 3252
import java.util.Scanner;


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


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

#define ll long long

int main(void) 
{
	int arr[5];
	
	int ans = 0;
	for(int i = 0; i < 5; i++) {
		cin >> arr[i];
		if(arr[i] == 0) {
			ans = i+1;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3580
package main

import (
	"fmt"
	"math"
)

var N, D int

func main() {
	fmt.Scan(&N)
	fmt.Scan(&D)
	d := 2*D + 1
	res := N / d
	if res*d < N {
		res += 1
	}
	fmt.Println(res)
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type pairs []Pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

// bug bug
// var nextReader func() []byte
//
// func init() {
// 	nextReader = newScanner()
// 	log.SetFlags(log.Lshortfile)
// }
//
// func newScanner() func() []byte {
// 	r := bufio.NewScanner(os.Stdin)
// 	r.Split(bufio.ScanWords)
// 	return func() []byte {
// 		r.Scan()
// 		return r.Bytes()
// 	}
// }
// func nextBytes() []byte {
// 	return nextReader()
// }
//
// func nextString() string {
// 	return string(nextReader())
// }
// func nextInt64() int64 {
// 	v, _ := strconv.ParseInt(string(nextReader()), 10, 64)
// 	return v
// }
// func nextInt() int {
// 	v, _ := strconv.Atoi(string(nextReader()))
// 	return v
// }
// func nextInts(n int) []int {
// 	r := make([]int, n)
// 	for i := 0; i < n; i++ {
// 		r[i] = nextInt()
// 	}
// 	return r
// }
// func nextFloat64() float64 {
// 	f, _ := strconv.ParseFloat(string(nextReader()), 64)
// 	return f
// }


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e7+7;
int f[MAX];
ll ans;

int main(int argc, char** argv) {
	int N; scanf("%d", &N);
	for(int i = 1; i <= N; i++) {
		for(int j = i; j <= N; j += i)
			f[j]++;
		ans += 1LL*i*f[i];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 42896
#include <cstdio>

int main(void){
    int n, x, min = 1000000, max = -1000000;
    long long sum = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        sum += x;
        if (x < min) min = x;
        if (x > max) max = x;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}

Measured memory_bytes: 1028
n = gets.to_i
a = gets.split.map(&:to_i)
a.unshift(0)
a << 0
b = []
sum = 0
n.next.times do |i|
  b[i] = (a[i + 1] - a[i]).abs
  sum += b[i]
end
n.times do |i|
  puts sum - b[i] - b[i + 1] + (a[i + 2] - a[i]).abs
end

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> v(M);
  
  
  for(int i=0; i<N; i++){
    int K;
    cin >> K;
    vector<int> foods(K);
    for(int j=0;j<K;j++) cin >> foods[j];
    for(int f: foods) v[f-1]++;
  }
  
  int count = 0;
  for(int ff: v)
    if(ff==N) count++;
  
  cout << count << endl;
  
  return 0;
}


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

using namespace std;

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

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  pii p[200];
  int n,m;
  cin>>n;
  rep(i,n)cin>>p[i].first>>p[i].second;
  cin>>m;
  rep(i,m)cin>>p[n+i].first>>p[n+i].second;
  sort(p,p+n+m);
  rep(i,n+m-1){
    if(p[i].first!=p[i+1].first||p[i].second!=p[i+1].second)
      printf("%d:%02d ",p[i].first,p[i].second);
  }
  printf("%d:%02d\n",p[n+m-1].first,p[n+m-1].second);
}

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

using namespace std;

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

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

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

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

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true; }
    return false;
}
template<class T>
void DEBUG_DP(T* viewdp, int ilen, int jlen){
    REP(i,ilen){
        REP(j,jlen){
            if(viewdp[i][j] != -1)
                printf("[% 4d]", viewdp[i][j]);
            else
                printf("[    ]");
        }
        puts("");
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int h,w;
    cin>>h>>w;
    vector<string> m(h+1);
    REP(i,h){
        cin>>m[i];
        m[i] += "#";
    }
    vector<vi> cs(h+1, vi(w+2,0));

    //yoko
    REP(i,h) REP(j,w){
        if(m[i][j]=='.'){
            cs[i][j+1] = cs[i][j] + 1;
        }
    }

    //tate
    int ans = 0;
    FORR(j,1,w+1){
        int yokomx = 1;
        int tatecnt = 0;
        REP(i,h) {
            //DEBUG2(i,j);
            if(cs[i][j]!=0) chmax(cs[i][j], cs[i][j+1]);
            chmax(yokomx, cs[i][j]);

            if(m[i][j-1]=='.'){
                tatecnt += 1;
            }else{
                ans = max(ans, tatecnt + yokomx - 1);
                tatecnt = 0;
                yokomx = 1;
            }
            // DEBUG2(tatecnt, yokomx);
            // DEBUG(ans);
        }

        ans = max(ans, tatecnt + yokomx-1);
    }

    // REP(ji,h){
    //     DEBUG_VEC(cs[ji]);
    // }
    cout << ans << endl;
    return 0;
}

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

int main () {
  int n;
  cin>>n;
  long long a[n+1];
  for (int i=0;i<n;i++) {
    cin>>a[i];
  }
  sort(a,a+n);
  int p,q;
  p=a[n/2-1];
  q=a[n/2];
  cout<<q-p<<endl;
  
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define printjudge(cond) {if(cond) printf("Yes\n"); else printf("No\n");}
#define printans(ans) {printf("%d\n",(ans));}
#define intscan(x) {scanf("%d", &x);}
#define Ntimes(N) for(int i=0; i<N; i++)
#define min(x,y) (((x)<(y)) ? (x) : (y))
#define max(x,y) (((x)>(y)) ? (x) : (y))
typedef int* intarray;
typedef char* string;

#define judge(x) ((x)>=1 && (x)<=12)
int main(){
    char S[5], S1[3], S2[3];
    scanf("%s", S);
    for(int i=0; i<3; i++){
        if(i<2) {S1[i]=S[i]; S2[i]=S[i+2];}
        else {S1[i]='\0'; S2[i]='\0';}
    }
    int s1 = atoi(S1);
    int s2 = atoi(S2);
    switch(judge(s1)+2*judge(s2)){
        case 0: printf("NA\n"); break;
        case 1: printf("MMYY\n"); break;
        case 2: printf("YYMM\n"); break;
        case 3: printf("AMBIGUOUS\n"); break;
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>
#include <vector>

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))

using namespace std;

#define MOD 1000000007

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    long a[401]={0};
    ll   s[401]={0};
    vector<vector<ll> > dp(n, vector<ll>(n, 0));
 
    long i, j, k;
    for(i=0; i<n; i++) {
        scanf("%ld", &(a[i]));
        s[i+1]=s[i]+a[i];
    }

    for(i=1; i<n; i++) {
        for(j=0; j<n-i; j++) {      // [j..j+i]
            dp[i][j]=10000000000000000;
            for(k=0; k<i; k++) {    // [j..j+k] [j+k+1..j+i]
                ll tmp = (s[j+k+1]-s[j]) + (s[j+i+1]-s[j+k+1]) + dp[k][j] + dp[i-k-1][j+k+1];
                if(dp[i][j]>tmp)
                    dp[i][j]=tmp;
            }
        }
    }

    printf("%lld\n", dp[n-1][0]);

    return 0;
}


Measured memory_bytes: 1536
#pragma GCC optimize("O3")

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

# include <stdio.h>
# include <bits/stdc++.h>


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace __gnu_pbds;
using namespace std;
 
typedef
tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s, t;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;

int main () {
	SpeedForce;
	cin >> s >> t;
	for (auto to : s) {
		++ cur;
		g[to].pb(cur);
	}

	ll res = 0;
	int pos = 0;
	for (int i = 0; i < t.size(); i ++) {
		if (g[t[i]].empty()) {
			cout << -1;
			exit(0);
		}
		auto it = upper_bound(every(g[t[i]]), pos);
		if (it == g[t[i]].end()) {
			int s = g[t[i]][0];
			res += s + cur - pos;
			pos = s;
		} else {
			res += *it - pos;
			pos = *it;
		}
	}
	cout << res << '\n';

	return Accepted;
}

// B...a

Measured memory_bytes: 19660
from functools import lru_cache
 
 
@lru_cache(None)
def f(n):
    if n == 0:
        return 1
    elif n == 1:
        return 2
    elif n % 2 == 0:
        return (2 * f(n // 2 - 1) + f(n // 2)) % 1000000007
    else:
        return (2 * f(n // 2) + f(n // 2 - 1)) % 1000000007
 
 
n = int(input())
print(f(n))

Measured memory_bytes: 85304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;

main(){
    ll x,k,d;
    cin>>x>>k>>d;
    x = abs(x);
    ll steps = x/d;
    if(steps>k) cout<<abs(x-k*d);
    else{
    x-= (steps*d);
    ll rem = (k-steps);
    ll alt = x-d;
    if(rem&1) cout<<abs(alt);
    else cout<<abs(x);
    }
}

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


#define mod                1000000000000000007
#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define pii                pair < int , int >
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define forn(i,n)          for(i = 0 ; i < n ; i++)
#define deb(x)             cout << #x << " " << x << endl;
#define vecsum(v)          accumulate(v.begin(), v.end(), 0)
#define T(t)               cout << "Case " << t <<": ";
#define fast_cin           ios_base::sync_with_stdio(false);cin.tie(NULL)

int mark[1000005];
int main()
{


        fast_cin;


        ll n ;
        cin >> n ;
        string s;
        cin >> s;
        int w = 0 , r = 0 ;
        for( int i = 0 ;s[i] ; i++ ){
            w += (s[i] == 'W');
            r += (s[i] == 'R');
        }
        int ans1 = 0  , ans2 = 0 ;
        for( int i = 0 ; i < r ; i++ ){
            if( s[i] == 'W')ans1++;
        }
       for( int i = r ; i < n ; i++ ){
        if( s[i] == 'R')ans2++;
       }

       cout << min( ans1 , ans2 ) << endl;







}

Measured memory_bytes: 3708
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
//#include <unordered_map> //ハッシュ関数

using namespace std;

//デバッグ時はTESTを定義する。本番時はこの行をコメントアウトする
#define TEST //*******************************************************************************************************************************************

//そうすることで、以下に定義する、デバッグ時にのみ標準出力する、doutコマンドが実現できる。本番時はダミーストリームに出力
#ifdef TEST
    #define dout cout
#else
    stringstream dummy; //デバッグ時のdoutコマンドのダミー出力先
    #define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummyを毎回リセットしておかないとメモリ溢れちゃう。
    //どうせ表示しないからgoodbitしなくていいけど、表示する場合はこれしておかないとバグるらしいので、勉強のために。詳しくは http://d.hatena.ne.jp/linden/20060427/p1
#endif


#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << (A) << " "
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl

const int INF = 1e9;


int main(void) {
    string N;
    cin >> N;
    
    cout << ( N[0]=='9' or N[1]=='9' ? "Yes" : "No" ) << endl;
}

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

// Shortening code
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;

// Macros
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = a; i >= b; i--)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // Your code
    int k;
    cin >> k;
    int a, b;
    cin >> a >> b;
    if (ceil(a * 1.0 / k) <= floor(b * 1.0 / k))
    {
        cout << "OK";
    }
    else
    {
        cout << "NG";
    }

    return 0;
}

Measured memory_bytes: 3608
N,K = map(int,input().split())
A = list(map(int,input().split()))
m = min(N,K)
M = 0 
for i in range(m+1):
    for j in range(m-i+1):
        v=A[:i]+A[N-j:]
        v.sort()
        v=v[::-1]
        h=K-len(v)
        while h >0 and v:
            if v[-1] > 0:
                break
            else:
                v.pop()
                h-=1
        M=max(M,sum(v))
print(M)

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

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



Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define llong long long
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int N = 2e5;
struct Edge
{
	int v,nxt;
} e[(N<<1)+3];
int fe[N+3];
int fa[N+3];
int len[N+3];
int n,en,mx;

void addedge(int u,int v)
{
	en++; e[en].v = v;
	e[en].nxt = fe[u]; fe[u] = en;
}

void dfs(int u)
{
	for(int i=fe[u]; i; i=e[i].nxt)
	{
		int v = e[i].v; if(v==fa[u]) continue;
		fa[v] = u; dfs(v);
		mx = max(mx,len[u]+len[v]+1);
		len[u] = max(len[u],len[v]+1);
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1; i<n; i++) {int u,v; scanf("%d%d",&u,&v); addedge(u,v); addedge(v,u);}
	dfs(1);
//	printf("mx=%d\n",mx);
	if(mx%3==1) {puts("Second");}
	else {puts("First");}
	return 0;
}

Measured memory_bytes: 14720
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void push(int);
int pop(void);
int head,st[1000];

int main(){
  int a,b;
  head=0;
  char s[100];

  while(scanf("%s",s)!=EOF){
  
    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
      //printf("%d\n",st[head]);
    }else if(s[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
      //printf("%d\n",st[head]);
    }else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
      //printf("%d\n",st[head]);
    }else{
      push(atoi(s));
      //printf("%d\n",st[head]);
    }
  }
  printf("%d\n",pop());
  return 0;
}
int pop(void){
  head--;
  return st[head+1];
}
void push(int d){
  st[++head]=d;
}



Measured memory_bytes: 2044
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

void dfs (ll v, ll c, vector<vector<ll>> graph, vector<ll> cnt, vector<ll> &ans, vector<bool> visited) {
    visited.at(v) = true;

    for (auto e : graph.at(v)) {
        if (visited.at(e)) continue;
        ans[e] = c + cnt[e];
        dfs(e, c + cnt[e], graph, cnt, ans, visited);
    }
}

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

    ll N, Q;
    cin >> N >> Q;
    vector<vector<ll>> graph(N, vector<ll>());
    Rep (i, N-1) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<ll> cnt(N, 0);
    Rep (i, Q) {
        ll p, x;
        cin >> p >> x;
        p--;
        cnt[p] += x;
    }

    vector<bool> visited(N, false);
    vector<ll> ans(N, 0);
    ans[0] = cnt[0];
    stack<pair<ll, ll>> s;
    s.push(make_pair(0, cnt[0]));
    while (!s.empty()) {
        auto next = s.top(); s.pop();
        ll v = next.first;
        ll c = next.second;
        visited[v] =true;
        for (auto e : graph[v]) {
            if (visited[e]) continue;
            ans[e] = c + cnt[e];
            s.push(make_pair(e, c + cnt[e]));
        }
    }


    // dfs (0, cnt[0], graph, cnt, ans, visited);

    // for (auto e : cnt) cout << e << endl;
    Rep (i, N) {
        if (i != 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 21104
import math
import sys
def input(): return sys.stdin.readline().strip()
# sys.setrecursionlimit(100000)


def main():
    n, d = [int(i) for i in input().strip().split()]
    cnt = 0

    for _ in range(n):
        x, y = [int(i) for i in input().strip().split()]
        dis = math.sqrt(x**2 + y**2)
        if dis <= d:
            cnt += 1
    print(cnt)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 9200
#include <iostream>
using namespace std;
const int N = 26;
int main (void) {
    string S;
    bool appear[N];

    for (int i = 0; i < N; i++) appear[i] = false;

    cin >> S;

    for (int i = 0; i < S.length(); i++) appear[S[i] - 'a'] = true;

    for (int i = 0; i < N; i++) {
        if (!appear[i]) {
            char c = 'a' + i;
            cout << c << endl;
            return 0;
        }
    }
    cout << "None" << endl;

    return 0;
}

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

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

	vector<tuple<string, int, int>> tu;	
	for (int i = 0; i < n; i++) {
		string s;
		int p;
		cin >> s >> p;
		tu.emplace_back(s, -p, i + 1);
	}

	sort(tu.begin(), tu.end());

	for (int i = 0; i < n; i++) {
		cout << get<2>(tu[i]) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256