akhauriyash/Code-Regression huggingface dataset:
/*
テ」ツ?敕」ツつ古」ツ?榲」ツつ古」ツ?ョテゥツ?」テァツオツ静ヲツ按静・ツ按?」ツ?ョテヲツ慊?・ツ、ツァテ」ツ?ョティツセツコテ」ツ?ョテヲツ閉ーテ」ツつ津ヲツ閉ーテ」ツ?暗」ツ?ヲテヲツ篠崚」ツ?妥・ツ青暗」ツつ湘」ツ?崚」ツつ凝」ツ??
*/

#include<iostream>
#include<vector>
#include<algorithm>

#define to first
#define cnt first
#define cost second
#define MAX_N 100001
#define MOD 10007

using namespace std;

typedef pair<int,int> P;

vector<P>G[MAX_N];
bool vis[MAX_N];

P dfs(int n,P x){
  vis[n]=true;

  for(int i=0;i<G[n].size();i++){
    P e=G[n][i];
    if(x.cost<e.cost)x.cost=e.cost,x.cnt=1;
    else if(x.cost==e.cost)x.cnt++;
    if(!vis[e.to])x=dfs(e.to,x);
  }

  return x;
}

int main(void){

  int n,b,fb;

  while(cin >> n,n){

    for(int i=0;i<MAX_N;i++)G[i].clear();

    for(int i=0;i<n;i++){
      for(int j=0;j<2;j++){
	cin >> b >> fb;
	G[i].push_back(make_pair(b,fb));
      }
    }

    fill(vis,vis+MAX_N,false);
    int ans=1;
    for(int i=0;i<n;i++){
      if(!vis[i]){
	P x(0,0);
	x=dfs(i,x);
	ans=ans%MOD*x.cnt/2%MOD;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 4252
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

vector<int> primes;

bool isPrime(int p) {
  for (int i = 0; i < primes.size() && i <= sqrt(p); i++) {
    if (p % primes[i] == 0) {
      return false;
    }
  }
  return true;
}

void makePrimes(int n) {
  primes.pb(2);
  for (int i = 3; i < n; i += 2) {
    if (isPrime(i)) {
      primes.pb(i);
    }
  }
}

int main() {
  makePrimes(1000000);
  int a, d, n;
  while (cin >> a >> d >> n, a | d | n) {
    for (int i = 0; i < primes.size(); i++) {
      if (primes[i] == a) {
        n--;
        if (n == 0) {
          cout << primes[i] << el;
          break;
        }
      } else if (primes[i] > a) {
        a += d;
        i--;
      }
    }
  }
}

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

#define pb              push_back
#define pi              acos(-1.0)
#define loop(i,a,n)     for(int i=a;i<n;i++)
#define rloop(i,n,a)    for(int i=n;i>=a;i--)
#define ll              long long int
#define ff              first
#define ss              second
#define pii             pair<ll,ll>
#define sc1(a)          scanf("%d",&a)
#define sc2(a,b)        scanf("%d %d",&a,&b)
#define sc3(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define all(v)          v.begin(),v.end()
#define ms(a,b)         memset(a,b,sizeof a)
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define fileout         freopen("output.txt","w",stdout)
#define filein          freopen("input.txt","r",stdin)
#define inf             2e9+5
#define Q               int q;cin>>q;while(q--)
#define check           cout<<"HI"<<endl;

//int x[]= {-1,0,0,1};
//int y[]= {0,-1,1,0};

using namespace std;

int main()
{
   
        int n,p=0;
        string s,t;
        cin >> n >> s;
        loop(i,0,n-1)
        {
            if(s[i]!=s[i+1])
            {
                p++;
                t=s[i];
            }
        }
        if(t[0]!=s[n-1])p++;
        cout<<p<<endl;
    }














Measured memory_bytes: 3720
#include <stdio.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int n, a[6000];

int main() {
    for (;;) {
        scanf("%d", &n);
        if (n == 0) return 0;
        rep (i, n) scanf("%d", a+i);
        int m = 0, s = 0, ans = a[0];
        rep (i, n) {
            s += a[i];
            ans = max(ans, s-m);
            m = min(m, s);
        }
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String s=sc.nextLine();
    	String S[]=s.split("");
    	String ans="Yes";
    	int south=0;
    	int north=0;
    	int east=0;
    	int west=0;
    	for(int i=0;i<S.length;i++) {
    		if(S[i].equals("S"))south++;
    		if(S[i].equals("N"))north++;
    		if(S[i].equals("W"))west++;
    		if(S[i].equals("E"))east++;
    	}
    	if(south>0&&north<=0) ans="No";
    		if(north>0&&south<=0) ans="No";
    		if(east>0&&west<=0) ans="No";
    		if(west>0&&east<=0) ans="No";
    		System.out.println(ans);
    }
}


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

int main() {
    int n;
    cin >> n;
    int ans = (n % 1000);
    if (ans != 0) ans = 1000 - ans;  
    cout << ans << endl;
    
    return 0;
}

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

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(5e18)
#define N (int)(2e5 + 10)

using namespace std;

void solve() {
	int n; cin >> n;
	int ans = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 1; i * j < n; j++)
			ans++;
	}

	cout << ans << endl;
}
// Remember to clear the global containers

// Got stuck and want to leave ? look at the bottom once..
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
	// cin >> t_c;
	while (t_c--)
		solve();
}
/* Come on Dude .. Dont get up until u get the solution
 * Giving up not gonna help ryt ? So get ur lazy ass to code already
 * You can do it ... Stay Calm and Dont Panic :)
 */


Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key)
            x = x->left;
        else
            x = x->right;
    }

    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if (u == NIL)
        return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL)
        return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s == "insert") {
            int k;
            cin >> k;
            insert(k);
        }
        else {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 26580
from collections import Counter

from scipy.misc import comb

N, M = map(int, input().split())

mod = 10**9 + 7


def prime_decomposition(n):
    i = 2
    p = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            p.append(i)
        i += 1
    if n > 1:
        p.append(n)
    return p


p = prime_decomposition(M)
p = Counter(p)

ans = 1
for pi in p.values():
    res = comb(pi + N - 1, N - 1, exact=True)
    ans = (ans * res) % mod
print(ans)


Measured memory_bytes: 15328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int N = 30;
vector<P> G[N];

int dp[N][2];

int dfs(int v, int p, int back){
	int &res = dp[v][back];
	if (res >= 0) return res;

	if (G[v].size() == 1 && G[v][0].first == p) return -1;
	if (back){
		res = 0;
		for (auto &e : G[v]){
			if (e.first == p) continue;
			int ret = dfs(e.first, v, 1);
			if (ret < 0) continue;
			res += ret + e.second * 2;
		}
		return res;
	}
	int sum = dfs(v, p, true);
	res = sum;
	for (auto &e : G[v]){
		if (e.first == p) continue;
		int ret = dfs(e.first, v, 1);
		if (ret < 0) continue;
		int ret2 = dfs(e.first, v, 0);
		res = min(res, sum - e.second - ret + ret2);
	}

	return res;
}

int main(){
	int n;
	while (cin >> n, n){
		rep(i, n) G[i].clear();
		MEMSET(dp, -1);
		rep(i, n-1){
			int a, b, t;
			cin >> a >> b >> t;
			--a, --b;
			G[a].push_back(make_pair(b, t));
			G[b].push_back(make_pair(a, t));
		}
		cout << dfs(0, -1, 0) << endl;
	}


	return 0;
}

Measured memory_bytes: 1196
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <unordered_map>
//#include <bits/stdc++.h>
#include <cassert>
#include <map>
#include <bitset>
using namespace std;

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int maxn = 2e3+1;
int n, k;
vector<int> g[maxn];
int dfs(int cur, int pa, int dis, int k)
{
  int ret = 1;
  if (dis < k)
    for (auto nxt : g[cur])
      if (nxt != pa)
	ret += dfs(nxt, cur, dis+1, k);
  return ret;
}

int main()
{
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n-1; ++i)
    {
      int u, v;
      scanf("%d %d", &u, &v);
      g[u].pb(v);
      g[v].pb(u);
    }
  int ans = n;
  if (k%2 == 0)
    {
      for (int i = 1; i <= n; ++i)
	{
	  int tmp = dfs(i, 0, 0, k/2);
	  tmp = n-tmp;
	  if (tmp < ans)
	    ans = tmp;

	}
    }
  else
    {
      for (int i = 1; i <= n; ++i)
	for (auto nxt : g[i])
	  if (nxt > i)
	    {
	      int tmp = dfs(i, nxt, 0, k/2) + dfs(nxt, i, 0, k/2);
	      tmp = n-tmp;
	      if (tmp < ans)
		ans = tmp;
	    }
    }
  printf("%d\n", ans);
}


Measured memory_bytes: 384
<?php
$str = trim(fgets(STDIN));
$len = strlen($str);
$hag = 0;
$herflen = ceil($len / 2);
for ($i = 0;$i < $herflen;++$i) {
    $front = substr($str,$i,1);
    $back = substr($str,$len - ($i + 1),1);
    if ($front !== $back) {
        ++$hag;
    }
}
echo $hag.PHP_EOL;
?>

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll, ll>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num, ll g, ll mod) {
	if (g == 0)return 1;
	if (g % 2 == 1)return (num * power((num * num) % mod, g / 2, mod)) % mod;
	return power( (num * num) % mod, g / 2, mod);
}
int main(){
	ll a, b, c, k;
	cin >> a>> b >> c >> k;
	if (k <= a){
		cout << k;
	}
	else if (k <= a + b){
		cout << a;
	}
	else{
		cout << a - (k - a - b);
	}
}



Measured memory_bytes: 3632
s=list(input())
mn=len(s)

for x in ['0','1']:
  bef=x
  ret=0
  for c in s: 
 
    if bef==c:

      if bef=='1':

        bef="0"
      elif bef=='0':

        bef="1"
      ret+=1
    else:
      bef=c

  if ret<mn:
    mn=ret

print(mn)
    

Measured memory_bytes: 3956
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++){
            a[i] = input.nextInt();
        }
        int min,max;
        long sum;
        min = (int)Math.pow(10,7);
        max = -(int)Math.pow(10,7);
        sum = 0;
        for (int i = 0; i < n; i++){
            sum += a[i];
            min = Math.min(min,a[i]);
            max = Math.max(max,a[i]);
        }
        System.out.printf("%d %d %d\n",min,max,sum);
    }
}


Measured memory_bytes: 41092
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int a,t,Max=-1;
string s; 
int main()
{
   	cin >> a >> s;
    for(int i=0;i<a;i++)
	{
        bool(s[i]=='I')?t++:t--;
        Max=max(Max,t);
    }
    cout << max(Max,0) << endl;
    return 0;
}

Measured memory_bytes: 256
N,X,Y=map(int,input().split())
ANS=[0 for i in range(N-1)]
for i in range(N-1):
  for k in range(i+1,N):
    d=min(k-i,abs(X-i-1)+abs(Y-k-1)+1)
    ANS[d-1]+=1
for i in ANS:
  print(i)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int dp[105][2],n,a[105];
int main(){
	cin>>n;
	repn(i,n) cin>>a[i];
	rep(i,105)rep(j,2) dp[i][j] = INF;
	dp[0][0] = 0;
	rep(i,n){
		if(dp[i][0]<5e8){
			dp[i+1][0] = min(dp[i+1][0],dp[i][0]+1);
			dp[i+1][1] = min(dp[i+1][1],dp[i][0]);
		}
		if(dp[i][1]<5e8){
			dp[i+1][0] = min(dp[i+1][0],dp[i][1]+1);
			if(a[i] != a[i+1]) dp[i+1][1] = min(dp[i+1][1],dp[i][1]);
		}
	}
	cout<<min(dp[n][0],dp[n][1])<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
const int MaxN = 2e5 + 4;
int a[MaxN];
int main ()
{
	int n;
	scanf("%d",&n);
	int x = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d",&a[i]);
		x = max(x,a[i]);
	}
	int s = 0;
	int k = 0;
	int p;
	for (int i = 1; i <= n; i++)
	{
		p = min(abs(x-a[i]),a[i]);
		if (p > k) {
			s = a[i];
			k = p;
		}
	}
	printf("%d %d",x,s);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int a = 0;
  string s;
  cin >> N;
  
  
  for (int i = 0; i < N; i++){
    cin >> s;
    if (s == "Y"){
      a = 1;
    }
  }
    
  if (a == 1){
    cout << "Four" << endl;
  }
  if (a == 0){
     cout << "Three" << endl;
  }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long llong;
#define MAX 200000
// 二分木の子の数(葉以外)
#define BINARY_CHILDREN_NUM 2
// 二分木の子の数(葉)
#define BINARY_LEAF_CHILDREN_NUM 0

struct Node {
    int key;
    Node *left, *right, *parent;
    };

Node *root, *NIL;

//  二分木に新しい値を挿入する
void insert(int key)
{
    Node *x, *y, *z;
    // 初期化
    z = new Node;
    z->key = key;
    z->left = NIL;
    z->right = NIL;
    y = NIL;
    x = root;

    // 根から適切な位置までたどる
    while (x != NIL) {
        y = x; // 親を設定
        if (z->key < x->key) {
            x = x->left;
        }
        else {
            x = x->right;
        }
    }

    z->parent = y;

    if (y == NIL) { // T が空の場合
        root = z;
    }
    else if (z->key < y->key){
        y->left = z; // z を y の左の子にする
    }
    else {
        y->right = z; // z を y の右の子にする
    }
}

// 根から先行順巡回を行う
// 親→左部分木→右部分木の順
void PreOrder(Node* node)
{
    cout << " " << node->key;

    // 左部分木をチェック
    if (node->left != NIL) {
        PreOrder(node->left);
    }
    // 右部分木をチェック
    if (node->right != NIL) {
        PreOrder(node->right);
    }
}

// 根から先行順巡回を行う
// 左部分木→親→右部分木の順
void InOrder(Node* node)
{
    // 左部分木をチェック
    if (node->left != NIL) {
        InOrder(node->left);
    }
    cout << " " << node->key;

    // 右部分木をチェック
    if (node->right != NIL)
    {
        InOrder(node->right);
    }
}

void PrintVec()
{
    // 先行順巡回、 中間順巡回、後行順巡回
    InOrder(root);
    cout << "\n";
    PreOrder(root);
    cout << "\n";
}

int main() {
    // 節点の個数
    int n = 0;
    // 次数
    int iDeg = 0;
    int iNodeIdx = 0;
    int left, node;
    string strCmd;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        //節点番号を取得
        cin >> strCmd;
        if (strCmd == "insert") {
            cin >> iNodeIdx;
            insert(iNodeIdx);
        }
        else if (strCmd == "print") {
            PrintVec();
        }

    }
    return 0;
}


Measured memory_bytes: 26636
#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); }

const int MAX_ALPHA = 26;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s;
  int k;
  cin >> s >> k;
  int n = s.size();

  rep(i, 0, n) {
    if (MAX_ALPHA - (s[i] - 'a') > k)
      continue;
    if (s[i] != 'a') {
      k -= MAX_ALPHA - (s[i] - 'a');
      s[i] = 'a';
    }
  }

  if (k != 0)
    s[n - 1] = (char)(((s[n - 1] - 'a') + k) % 26 + 'a');

  cout << s << endl;
}


Measured memory_bytes: 3732
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;


int main(){
  bool flag=false;
  int N,A,B,C,D;
  cin>>N>>A>>B>>C>>D;

  string s;
  cin>>s;

  for(int i=B-1;i<=D-2;i++){
    if(s[i]=='#' && s[i+1]=='#'){
      cout<<"No"<<endl;
      return 0;
    }
  }

  for(int i=A-1;i<=C-2;i++){
    if(s[i]=='#' && s[i+1]=='#'){
      cout<<"No"<<endl;
      return 0;
    }
  }

  if(D<C){
    for(int i=B-2;i<=D-2;i++){
      if(s[i]=='.' && s[i+1]=='.' && s[i+2]=='.') flag=true;
    }
    if(flag){
      cout<<"Yes"<<endl;
      return 0;
    }else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 576
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int main(){
    int N;
    int A[101];
    LL ans=1;
    LL now=1;
    cin>>N;
    REP(i,N){
        cin>>A[i];
        if(A[i]%2==0){
           now*=2;
        }
        ans*=3;
    }
    cout<<ans-now<<endl;
	return(0);
}

Measured memory_bytes: 256
n = int(input())
a, b = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
c = 0
flag = True

while flag:
    for f in [lambda x: x <= a, lambda x: x > a and x <= b, lambda x: x > b]:
        pt = list(filter(f, p))
        if len(pt) == 0:
            flag = False
            break
        p.remove(min(pt))
    else:
        c += 1

print(c)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
typedef  long long int ll;
typedef long double ld;
#define pb  push_back
#define vll vector<ll>
#define mll map<ll,ll>
const double PI = 2*acos(0.0);
#define gcd(a,b)   __gcd((a),(b))
#define lcm(a,b)   ((a)/(__gcd((a),(b)))*(b))
#define INF         LLONG_MAX
#define ln  INT_MAX
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std;
int main() {
ll n,d;
cin>>n>>d;
ll c=0;
for(int i=0; i<n; i++){
        ll x,y;
   cin>>x>>y;
if((sqrt((x*x)+(y*y)))<=d){
    c++;
}
}
cout<<c;
return 0;
}


Measured memory_bytes: 3648
//Inbornhandsome
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define endl '\n'
#define int long long

const int n = 107, N = (int) 1e5+7;

int weight[n], value[n], n1, W, cache[n][N];

int dp(int s, int w)
{
    if(w > W) return INT_MIN;

    if(s > n1) return 0;

    int &ans = cache[s][w];
    
    if(ans != -1) return ans;
    
    ans = max(dp(s+1, w), value[s] + dp(s + 1, w + weight[s]));

    return ans;
}

int32_t main()
{
    IOS; //FIO;

    cin >> n1 >> W;

    memset(cache, -1, sizeof(cache));

    for(int i = 1; i <= n1; i ++)
    cin >> weight[i] >> value[i];

    cout << dp(1, 0);

    return 0;
}

Measured memory_bytes: 83840
a = list(map(int, input().split()))
sum = 0

if a[0] / 2 + a[1] / 2 < a[2]:
    for i in range(a[3]):
        sum += a[0]
    for i in range(a[4]):
        sum += a[1]
else:
    if a[3] <= a[4]:
        for i in range(a[3]):
            sum += a[2]*2
        if a[1] < a[2] * 2:
            for i in range(a[4] - a[3]):
                sum += a[1]
        else:
            for i in range(a[4] - a[3]):
                sum += a[2]*2
    else:
        for i in range(a[4]):
            sum += a[2]*2
        if a[0] < a[2] * 2:
            for i in range(a[3] - a[4]):
                sum += a[0]
        else:
            for i in range(a[3] - a[4]):
                sum += a[2]*2
print(sum)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC_Challenge
{
    class _003_A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string ss = Read();
            bool n = false;
            bool w = false;
            bool s = false;
            bool e = false;
            for (int i = 0; i < ss.Length; i++)
            {
                switch (ss[i])
                {
                    case 'N': n = true; break;
                    case 'W': w = true; break;
                    case 'S': s = true; break;
                    case 'E': e = true; break;
                }
            }
            if (n == s && w == e) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int N,W;
vector<int> v,w;
vector<vector<int>> dp(110,vector<int>(10100,-1));
int rec(int i,int j){
    if(dp.at(i).at(j)>=0){
        return dp.at(i).at(j);
    }
    int res;
    if(i==N) res=0;
    else if(j<w.at(i)){
        res=rec(i+1,j);
    }
    else {
        res=max(rec(i+1,j),rec(i+1,j-w.at(i))+v.at(i));
    }
    return dp.at(i).at(j)=res;
}

int main(){
cin>>N>>W;
v.resize(N);
w.resize(N);
for(int i=0;i<N;i++){
    cin>>v.at(i)>>w.at(i);
}
cout<<rec(0,W)<<endl;
}


Measured memory_bytes: 7212
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)


int main(){
  ll N;
  cin>>N;
  vector<ll> L(N);
  for(ll i=0;i<N;i++){
    cin>>L[i];
  }

ll ans=0;
ll jjj[100][100][100]={0};
  for(ll i=0;i<N;i++){
    for(ll j=0;j<N;j++){
    for(ll k=0;k<N;k++){
    if(k!=j&&j!=i&&i!=k){
      if(L[k]!=L[j]&&L[i]!=L[j]&&L[i]!=L[k]&&L[i]+L[k]>L[j]&&L[j]+L[k]>L[i]&&L[i]+L[j]>L[k]&&jjj[i][j][k]==0){;jjj[i][j][k]=1;
      jjj[i][k][j]=1;jjj[j][i][k]=1;jjj[j][k][i]=1;jjj[k][j][i]=1;jjj[k][i][j]=1;jjj[i][j][k]=1;jjj[i][j][k]=1;
      ans++;
      
      }
    }
    }
  }
  }
  

  cout<<ans<<endl;
  }










Measured memory_bytes: 11436
#include <iostream>
#include <utility>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;
int main() {
    cpp_int  i,n,sum=0;
    cin>>n;
    for(i=1;i<=n;i++) {
        if(!(i%3==0||i%5==0)) sum+=i; 
    }
    cout<<sum;
return 0;
}


Measured memory_bytes: 3688
from collections import Counter
def resolve():
    N = int(input())
    lst = [input() for i in range(N)]
    cc = Counter(lst)
    if "AC" in cc:
        print("AC x "+str(cc["AC"]))    
    else:
        print("AC x 0")

    if "WA" in cc:
        print("WA x "+str(cc["WA"]))    
    else:
        print("WA x 0")

    if "TLE" in cc:
        print("TLE x "+str(cc["TLE"]))    
    else:
        print("TLE x 0")

    if "RE" in cc:
        print("RE x "+str(cc["RE"]))    
    else:
        print("RE x 0")
resolve()

Measured memory_bytes: 78752
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String data[] = br.readLine().split(" ");
			int x = Integer.parseInt(data[0]);
			int y = Integer.parseInt(data[1]);
			if (x == 0 && y == 0) break;

			if (x <= y) {
			System.out.println(x + " " + y);
			} else {
			System.out.println(y + " " + x);
			}
		}
	}
}

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

const ll MOD = 1e9+7;

int main(){ 
  int N,M; cin >> N >> M;
  
  vector<ll> A(N),B(M);
  
  map<ll,ll> mA,mB;
  
  for(int i = 0; i < N; i++){ cin >> A[i]; mA[A[i]]++;}
  for(int j = 0; j < M; j++){ cin >> B[j]; mB[B[j]]++;}
  
  for(auto ne : mA){ if(ne.second>=2){ cout<< 0 << endl; return 0;}}
  for(auto ne : mB){ if(ne.second>=2){ cout<< 0 << endl; return 0;}}
  
  //以後、同じ数字はA,B内に複数回現れない
  
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  
  //でかい方から決めていく
  
  ll ans = 1LL;
  
  
  for(ll i = N*M; i >= 1; i--){
    
    ll res1 = lower_bound(A.begin(),A.end(),i)-A.begin();
    ll res2 = lower_bound(B.begin(),B.end(),i)-B.begin();
    
    
    if( A[res1] == i && B[res2] == i){ //どちらにも含まれている時
      continue;}
    else if(A[res1] == i && B[res2] != i){
      ans *= (M-res2);
      ans %= MOD;
    }
    else if(A[res1] != i && B[res2] == i){
      ans *= (N-res1);
      ans %= MOD;
    }
    else{
      if( (N-res1)*(M-res2) <= (N*M-i)){ ans = 0;}
      ans *= ((N-res1)*(M-res2)-(N*M-i));
      ans = (ans+MOD)%MOD;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}
     
  

Measured memory_bytes: 512
def divisor_counter(n):
    cnt = 0
    if n % 2 == 0:
        return 0
    for i in range(1,n+1):
        if n % i == 0:
            cnt += 1
    if cnt == 8:
        return 1
    else:
        return 0
    

n = int(input())
cnt = 0
for i in range(1,n+1):
    cnt += divisor_counter(i)
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    vector<int> d(1e5);
    cin >> n;
    for(int i = 0; i < n; i++){
        scanf("%d", &d[i]);
    }
    sort(d.begin(), d.begin() + n);
    cout << (d[n/2] == d[n/2-1] ? 0 : d[n/2] - d[n/2-1]) << endl;
}

Measured memory_bytes: 768
using System;

namespace abc167_b
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ');
            var inputNums = Array.ConvertAll(inputs, int.Parse);

            Console.WriteLine(CalcMaxSum(inputNums));
            Console.Read();
        }

        private static int CalcMaxSum(int[] inputNums)
        {
            if (inputNums[0] >= inputNums[3])
            {
                return inputNums[3];
            }

            var cardNum = inputNums[3] - inputNums[0];

            if (inputNums[1] >= cardNum)
            {
                return inputNums[0];
            }

            cardNum -= inputNums[1];

            return inputNums[0] - cardNum;
        }
    }
}

Measured memory_bytes: 27364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    cout << N * (N - 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  long n,k,s;
  scanf("%ld %ld %ld", &n, &k, &s);

  long other = s+1;
  if (other > 1000000000) {
    other = 1;
  }

  if (k != 0) {
    printf("%ld", s);
    for (long i = 1; i < k; i++) {
      printf(" %ld", s);
    }
    for (long i = k; i < n; i++) {
      printf(" %ld", other);
    }
  } else {
    printf("%ld", other);
    for (long i = 1; i < n; i++) {
      printf(" %ld", other);
    }
  }

  printf("\n");

  return 0;
}

Measured memory_bytes: 1280
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
#include <set>
#include <iomanip>
using namespace std;
 
int main(){
    int K, N;
    cin >> K >> N;
    vector<int> d(N);
    vector<int> A(N);
    int b;
    int rem = 0;
    cin >> A[0];
    for (int i=1; i<N; i++){
        cin >> A[i];
        d[i-1] = A[i] - A[i-1];
        rem = max(d[i-1], rem);
    }
    d[N-1] = A[0] + (K - A[N-1]);
    rem = max(d[N-1], rem);
    cout << K - rem << endl;
    return 0;
}

Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

string LCS(const string &s, const string &t) {
	int n = s.size(), m = t.size();
	vvi lcs(n + 1, vi(m + 1));
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i - 1] == t[j - 1]) {
				lcs[i][j] = max(lcs[i][j], lcs[i - 1][j - 1] + 1);
			} else {
				lcs[i][j] = max({lcs[i][j], lcs[i - 1][j], lcs[i][j - 1]});
			}
		}
	}
	string ret = "";
	for (int i = n, j = m; i > 0 && j > 0;) {
		if (lcs[i][j] == lcs[i - 1][j]) {
			i--;
			continue;
		}
		if (lcs[i][j] == lcs[i][j - 1]) {
			j--;
			continue;
		}
		assert(s[i - 1] == t[j - 1]);
		ret += s[i - 1];
		i--, j--;
	}
	reverse(ret.begin(), ret.end());
	return ret;
}

int main() {
	string s, t;
	cin >> s >> t;
	cout << LCS(s, t) << endl;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int i=0;
  int ans=0;
  while(i<=n-3){
    if(s[i]!='A'){
    	i++;
      	continue;
    }else{
    	if(s[i+1]=='B' && s[i+2]=='C'){
          ans++;
          i=i+3;
        }else{
          i++;
        }
    }
  }
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, v[25], c[25], ans;
int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", v+i);
    for(int i = 0; i < n; i++){
        scanf("%d", c+i);
        if(v[i] > c[i]) ans += v[i] - c[i];
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<stack>
#include<algorithm>
#include<iostream>
#include<set>
#pragma comment(linker, "/STACK:102400000,102400000")
#define IOS ios::sync_with_stdio(false);cin.tie(0)
//#define ll long long
#define ll unsigned long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-6
#define pi acos(-1)
#define mea (memset(a,0,sizeof(a)))
#define myit set<ll>::iterator
#define mysets multiset<ll>
#define myits multiset<ll>::iterator
#define v30 (1<<30)-1
#define all(x) (x).begin(),(x).end()
#define maxs *s.rbegin()
#define fi first
#define se second
#define lowbit(x) (x&(-x))
#define mp make_pair
#define pb push_back
#define ins insert
#define ee exp(1.0)
#define fixed cout.setf(ios::fixed)
#define fixeds(x) setprecision(x)
using namespace std;
inline ll read(){
   ll s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put1(){ puts("YES") ;}
void put2(){ puts("NO") ;}
void put3(){ puts("-1"); }
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}
using namespace std;

const int manx=3e5+5;

int main()
{
    ll n=read(),r=read();
    if(n>=10) cout<<r<<endl;
    else cout<<r+(10-n)*100<<endl;
    return 0;
}


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

#define endl '\n'
#define ll long long

ll int rev(ll int n)
{
	int ans=0,r;
	while(n>0)
	{
		r=n%10;
		ans=(ans*10)+r;
		n/=10;
	}
	return ans;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll int a,b,cnt=0;
	cin >> a >> b;
	for(ll int i=a;i<=b;i++)
	{
		//cout << rev(i) << endl;
		if((i-rev(i))==0) cnt++;
	}
	cout << cnt << endl;
	
	return 0;
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

VI pow(VI p, LL k, int n){
  VI ans(n);
  REP(i,n) ans[i] = i;
  while(k>0){
	VI tmp(n);
	if(k&1){
	  REP(i,n)
		tmp[i] = ans[p[i]];
	  ans = tmp;
	}
	REP(i,n)
	  tmp[i] = p[p[i]];
	p = tmp;
	k /= 2;
  }
  return ans;
}

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

  int N; cin >> N;
  vector<LL> xs(N);
  REP(i,N) cin >> xs[i];
  vector<LL> ds(N-1);
  REP(i,N-1) ds[i] = xs[i+1] - xs[i];

  LL M, K; cin >> M >> K;
  VI as(M);
  VI pm(N-1);
  REP(i,N-1) pm[i] = i;
  REP(i,M){
	cin >> as[i];
	--as[i];
	swap(pm[as[i]], pm[as[i]-1]);
  }
  pm = pow(pm, K, N-1);

  LL x = xs[0];
  cout << x << endl;
  REP(i,N-1){
	x += ds[pm[i]];
	cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 4072
ri = lambda: map(int, input().split())

N, M = ri()
H = list(ri())
T = [0]*N
for _ in range(M):
    a, b = ri()
    T[a-1] = max(T[a-1], H[b-1])
    T[b-1] = max(T[b-1], H[a-1])

print(sum(1 for i, h in enumerate(T) if h == 0 or h < H[i]))


Measured memory_bytes: 86056
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(len(a)):
  ai=a[i]
  ans+=b[ai-1]
  if(ans!=b[ai-1]):
    if(ai==before+1):
      ans+=c[before-1]
  before=ai
print(ans)

Measured memory_bytes: 9196
r, c= map(int, input().split())
list = [list(map(int,input().split())) for i in range(r)]
for i in range(r):
    list[i].append(sum(list[i]))
for i in range(r):
    for j in range(c):
        print(list[i][j], end = ' ')
    print(list[i][c])
for i in range(c):
    a = 0
    for j in range(r):
        a += list[j][i]
    print(a, end = ' ')
a = 0
for j in range(r):
    a += list[j][c]
print(a)


Measured memory_bytes: 6224
#include <iostream>
#include <cstdio>

using namespace std;
int n,m,k;
int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >> n >> m >> k;
	for (int i=0; i<=n; i++)
	for (int j=0; j<=m; j++)
	if ((k==i*j+(n-i)*(m-j)) or (k==i*(m-j)+(n-i)*j))
	{
		cout << "Yes";
		return 0;
	}
	for (int i=0; i<=m; i++)
	for (int j=0; j<=n; j++)
	if ((k==i*j+(m-i)*(n-j)) or (k==i*(n-j)+(m-i)*j))
	{
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

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


    int main(){
      string s;cin>>s;
      int len = s.size();
      auto res = vec(int,len);
      rep(i,len)res[i] = 0;
      int o = 1,e = 1;
      rep(i,len-1){
          if(s[i] == 'R' && s[i+1] == 'L'){
              if(i%2==1)res[i] += o,res[i+1] += e;
              else res[i] += e,res[i+1] += o;
              o = 1;e = 1;
              //cout<<i<<" ";
              i++;
              continue;
          }      
          if(i%2==1 && s[i] == 'R')o++;
          if(i%2==0 && s[i] == 'R')e++;
      }
    o = 0;e = 0;
      reverse(s.begin(),s.end());
      reverse(res.begin(),res.end());
      rep(i,len-1){
          if(s[i] == 'L' && s[i+1] == 'R'){
              if(i%2==1)res[i] += o,res[i+1] += e;
              else res[i] += e,res[i+1] += o;
              o = 0;e = 0;
              i++;
              continue;
          }      
          if(i%2==1 && s[i] == 'L')o++;
          if(i%2==0 && s[i] == 'L')e++;
      }
      reverse(res.begin(),res.end());
      rep(i,len)cout<<res[i]<<" ";
    }
    


Measured memory_bytes: 1024
use proconio::*;

fn run() {
    input! {
        x: i32,
        n: usize,
        p: [i32; n],
    }
    let mut ans = 1000;
    for i in 0..=101 {
        if !p.contains(&i) && (x - i).abs() < (x - ans).abs() {
            ans = i;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 2128
use proconio::input;

fn main() {
    input! {
        n: usize,
        p: usize,
        aa: [usize; n],
    }

    let odd_count = aa.into_iter().filter(|&x| x % 2 == 1).count();

    let ans = if odd_count == 0 {
        if p == 0 {
            2_u64.pow(n as u32)
        } else {
            0
        }
    } else {
        2_u64.pow(n as u32 - 1)
    };
    println!("{}", ans);
}


Measured memory_bytes: 2148
X,Y[104],i,j,n;main(N,S){for(;scanf(S="%d\n",&N)*N;printf(S,j<N?-1:n-2)){for(;n=j=i<N+4;)scanf(S,Y+i++);for(X=Y[3];i=n++<=1e4&j<N;X=(*Y*X+Y[1])%Y[2])j+=X==Y[4+j];}}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	char c;
	cin>>c;
	if(c>='a')
	cout<<'a'<<endl;
	else
	cout<<'A'<<endl;
	return 0;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) cout<<x
#define pb push_back
#define fr(i,a,b) for(int i=a;i<b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#include<string.h>
#define endl '\n'
#define INF 1000000000000000000
ll mod=1e9+7;
ll solve(){
    ll n,w=0,r=0;
    cin>>n;
    string str;
    cin>>str;
    for(int i=0;i<str.length();i++){
        if(str[i]=='W') w++;
        else r++;
    }
    r=0;
    for(int i=str.length()-1;i>=0;i--){
        if((str.length()-i)<=w&&str[i]=='W') r--;
    }
    cout<<w+r;
    return 0;
}
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);                    
    cout.tie(NULL);
    ll T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        //cout<<"Case #"<< i <<":";
    	solve();
        //cout<<endl;
    }
   	return 0; 
}

Measured memory_bytes: 3772
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 100010;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const ll MOD = 1000000007;

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

//********************************template END****************************************//

void solve(void){


	int M = 100, N;
	vecd ps(M, 1);

	rep(M-1, i)
	{
		ps[i+1] = ps[i] / 2;
	}

	//cout << ps << endl;

	while(cin >> N && N)
	{
		matd dp(N+1, vecd (M, 0));

		dp[0][0] = 1;

		double ans = 0;

		rep(N, n) rep(M, m)
		{
			if (m == M-1)
			{
				dp[n+1][0] += dp[n][m];
				ans += dp[n][m] * m;
				continue;
			}

			double p = ps[m];

			dp[n+1][m+1] += dp[n][m] * p;
			dp[n+1][0] += dp[n][m] * (1-p);
			ans += dp[n][m] * (1-p) * m;
		}

		rep(M, m)
		{
			ans += dp[N][m] * m;
		}

		cout << fixed << setprecision(3) << ans << endl;

	}


}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 84996
#include <stdio.h>
int main(){
  char s[2] = {0};
  
  scanf("%s", s);
  if( s[0] == 'z' ){ printf("a"); }
  else{
    s[0] = s[0] + 0x01;
    printf("%s", s);
  }
  return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int a,b,c,d,e,f;
int dp[6001];
int dp2[6001];

int main(void){
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	dp[0]=1;
	dp2[0]=1;
	for(int i=0;i<=3000;i++){
		if(dp[i]==1){
			dp[i+a*100]=1;
			dp[i+b*100]=1;
		}
	}
	for(int i=0;i<=3000;i++){
		if(dp2[i]==1){
			dp2[i+c]=1;
			dp2[i+d]=1;
		}
	}
	int res=-1,res2=-1;
	for(int i=1;i<=f;i++){
		for(int j=0;j<=i;j++){
			int wa=i-j;
			if((i-j)*e>=j*100 && dp[i-j]==1 && dp2[j]==1){
				if(res==-1){
					res=i;
					res2=j;
				}
				if(res2*(i)<j*(res)){
					res=i;
					res2=j;
				}
			}
		}
	}
	printf("%d %d\n",res,res2);
	return 0;
}

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

namespace ABC078
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = input[0];
            long M = input[1];
            Console.WriteLine(Math.Pow(2, M) * (1900 * M + 100 * (N - M)));
        }
    }
}


Measured memory_bytes: 13396
#pragma GCC optimize(3)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
using namespace std;
const int N=2e5+10,M=1e6+10;
int n,a[N],vis[M],maxn,rp[M],ans;
set<int>st;
int main(){
	scanf("%d",&n);
	for(int i=1,x;i<=n;i++){
		scanf("%d",&x);
		if(st.count(x) )rp[x]=1;
		st.insert(x);
		maxn=max(maxn,x);
	}
	for(auto i:st){
		if(vis[i])continue;
		for(int j=2*i;j<=maxn;j+=i)
		vis[j]=1;
		ans+=!rp[i]&&!vis[i];
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 20000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=200005;
int n,ans[N],a[N],dep[N],to[3];
vector<int> V[3],v[N];
void dfs(int p,int fa){
	dep[p]=dep[fa]^1; a[dep[p]]++;
	for(auto i:v[p])if(i!=fa){
		dfs(i,p);
	}
}
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	n=read();
	For(i,1,n)V[i%3].pb(i);
	For(i,1,n-1){
		int s=read(),t=read();
		v[s].pb(t); v[t].pb(s);
	}
	dfs(1,0);
	For(i,0,2)to[i]=V[i].size(); //to[0]=n/3; to[1]=n/3+(n%3); to[2]=n-to[0]-to[0];
	if(a[0]>to[0]+to[1]){
		For(i,1,n)if(dep[i])ans[i]=0;
		else if(to[1]){
			ans[i]=1; to[1]--;
		}else if(to[2]){ans[i]=2; to[2]--;}
	}else if(a[1]>to[0]+to[1]){
		For(i,1,n)if(!dep[i])ans[i]=0;
		else if(to[1]){
			ans[i]=1; to[1]--;
		}else if(to[2]){ans[i]=2; to[2]--;}
	}else{
		if(a[0]>a[1]){
			For(i,1,n){
				if(to[dep[i]+1])ans[i]=dep[i]+1; else ans[i]=0;
				to[ans[i]]--;
			}
		}else{
			For(i,1,n){
				if(to[2-dep[i]])ans[i]=2-dep[i]; else ans[i]=0;
				to[ans[i]]--;
			}
			
		}
	}
	For(i,1,n){
		wri(V[ans[i]].back());  V[ans[i]].pop_back();
	}
}
/*
kp+i=f(x+i)
i
*/

Measured memory_bytes: 21488
#include<stdio.h>
 
int main(){
  int a,b,c,n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d",&a,&b,&c);
    if(a*a+b*b==c*c)
      printf("YES\n");
    else if(a*a+c*c==b*b)
      printf("YES\n");
    else if(b*b+c*c==a*a)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

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

int main()
{
	std::string ans, s;
	std::cin >> s;
	for (auto& c: s)
	{
		if (c == 'B' && !ans.empty())
			ans.pop_back();
		else if (c == '1' || c == '0')
			ans.push_back(c);
	}
	std::cout << ans << '\n';

	return 0;
}

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

int main(){
    int n;
    cin>>n;
    int t[n];
    int i,j;
    for(i=0;i<n;i++)
    cin>>t[i];
    int m;
    cin>>m;
    int p[m],x[m];
    for(i=0;i<m;i++)
    cin>>p[i]>>x[i];
    int sum=0;
    for(i=0;i<m;i++){
        sum=0;
        for(j=0;j<n;j++){
            if(j==p[i]-1)
            sum+=x[i];
            else
            sum+=t[j];
        }
        cout<<sum<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int A[];
        A=new int[N-1];
        for(int i=0;i<N-1;i++){
            A[i]=sc.nextInt();
            A[i]--;
        }
        int ans[];
        ans=new int[N];
        for(int i=0;i<N-1;i++) ans[A[i]]++;
        for(int i=0;i<N;i++) System.out.println(ans[i]);
        sc.close();
    }
}

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

int main() {
  int N, l, r, sum = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    cin >> l >> r;
    sum += r - l + 1;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3644
# [] = list(map(int, input().split()))

import math

[n, d] = list(map(int, input().split()))
xyList = []
numCount = 0
for i in range(n):
    addedList = list(map(int, input().split()))
    xyList.append(addedList)
for j in xyList:
    if math.sqrt((j[0]) ** 2 + j[1] ** 2) <= d:
        numCount += 1
print(numCount)


Measured memory_bytes: 45456