akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

#define FOR(i,a,b) for(int i=(a),i##_end___=(b);i<i##_end___;i++)
#define DFOR(i,a,b) for(int i=(a)-1,i##_end___=(b);i>=i##_end___;i--)
typedef long long LL;
typedef double DB;
const int V=1e5+5;

int n,m;
int Fa[V];
int Mark[V];

struct Ask{
	char op[4];
	int v;
}Que[V];

int dfs(int v,int tim){return Mark[v]<tim?v:Fa[v]=dfs(Fa[v],tim);}

int main(){
	while(~scanf("%d%d",&n,&m)){
		if(!n&&!m)break;
		
		FOR(i,2,n+1)Mark[i]=1e9,scanf("%d",&Fa[i]);
		FOR(i,1,m+1){
			scanf("%s%d",Que[i].op,&Que[i].v);
			if(Que[i].op[0]=='M')Mark[Que[i].v]=min(Mark[Que[i].v],i);
		}
		
		LL ans=0;
		
		DFOR(i,m+1,1)if(Que[i].op[0]=='Q')ans+=dfs(Que[i].v,i);
		
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 4284
#include <stdio.h>
#include <stdlib.h>

typedef struct _n {
  int id;
  int dim;
  int *children;
  int parent;
  int depth;
} node;
node tree[100000];
void setDepth(int);
int main() {
  int i, j, k, n;
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    tree[i].parent = -1;
    tree[i].depth = 0;
  }
  for(k = 0; k < n; k++) {
    scanf("%d", &i);
    tree[i].id = i;
    scanf("%d", &tree[i].dim);
    tree[i].children = (int *) malloc(sizeof(int) * tree[i].dim);
    for(j = 0; j < tree[i].dim; j++) {
      scanf("%d", &tree[i].children[j]);
      tree[tree[i].children[j]].parent = tree[i].id;
    }
  }
  for(i = 0; i < n; i++) {
    if(tree[i].parent == -1) k = i;
  }
  setDepth(k);
  for(i = 0; i < n; i++) {
    printf("node %d: parent = %d, depth = %d, ", tree[i].id, tree[i].parent, tree[i].depth);
    if(tree[i].parent == -1) {
      printf("root, [");
      for(j = 0; j < tree[i].dim; j++) {
	printf("%d", tree[i].children[j]);
	if(j != tree[i].dim -1) printf(", ");
      }
    }
    else if(tree[i].dim == 0) {
      printf("leaf, [");
    }
    else {
      printf("internal node, [");
      for(j = 0; j < tree[i].dim; j++) {
	printf("%d", tree[i].children[j]);
	if(j != tree[i].dim -1) printf(", ");
      }
    }
    printf("]\n");
  }
  return 0;
}

void setDepth(int r) {
  int i;
  for(i = 0; i < tree[r].dim; i++) {
    tree[tree[r].children[i]].depth += 1 + tree[r].depth;
    setDepth(tree[r].children[i]);
  }
}



Measured memory_bytes: 7568
#include<stdio.h>
#include<bits/stdc++.h>
using namespace  std;
int n,ans; 
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		while(!(x&1))
		{
			++ans; x>>=1;
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int X;
  int a=100;
  int flag=0;
  scanf("%d",&X);
  
  while(X>0){
    if(X/a == 7){
      flag=1;
      break;
    }else{
      X%=a;
      a/=10;
    }
  }
  
  if(flag) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

Measured memory_bytes: 1644
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N, A, B;
    cin >> N >> A >> B;
    ll T1 = A - 1;
    ll T2 = B - T1;
    ll ans1;
    if ((T2 - 1) % 2 == 0)
        ans1 = T1 + (T2 - 1) / 2;
    else
        ans1 = (T1 + 1) + ((T2 - 1) - 1) / 2;
    T1 = N - B;
    T2 = A + T1;
    ll ans2;
    if ((N - T2) % 2 == 0)
        ans2 = T1 + (N - T2) / 2;
    else
        ans2 = (T1 + 1) + (N - (T2 + 1)) / 2;
    if ((B - A) % 2 == 0) {
        cout << min(min(min(min(B - 1, N - 1), (B - A) / 2), ans1),ans2) << endl;
        return 0;
    }


    cout << min(min(min(B - 1, N - A), ans1), ans2) << endl;
    return 0;
}

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

int main() {
  int a[4], b[4];

  while (cin >> a[0]) {
    for (int i = 1; i < 4; i++) cin >> a[i];
    for (int i = 0; i < 4; i++) cin >> b[i];

    int hit = 0;
    for (int i = 0; i < 4; i++)
      if (a[i] == b[i])
        hit++;

    int blow = 0;
    bool aa[10], bb[10];
    for (int i = 0; i < 10; i++)
      aa[i] = bb[i] = false;

    for (int i = 0; i < 4; i++) {
      aa[a[i]] = true;
      bb[b[i]] = true;
    }

    for (int i = 0; i < 10; i++)
      if (aa[i] and bb[i])
        blow++;

    cout << hit << " " << blow - hit << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
main()
{
	long long int n;
	cin >> n;
	map<string , long long int >m;
 	for(int i=0;i<n;i++)
 	{
 		string s;
 		cin >> s;
 		m[s]++;
	 }
	 cout << "AC x " << m["AC"] << endl;
	 cout << "WA x " << m["WA"] << endl;
	 cout << "TLE x " << m["TLE"] << endl;
	 cout << "RE x " << m["RE"] << endl;
	 
	return 0;
}

Measured memory_bytes: 3636
import sys
import collections

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline


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

# j - A[j]
hiku = []
# i + A[i]
tasu = []

for i, a in enumerate(A, 1):
    hiku.append(i - a)
    tasu.append(i + a)

hiku_c = collections.Counter(hiku)
tasu_c = collections.Counter(tasu)

ans = 0
for key, value in tasu_c.items():
    if key in hiku_c.keys():
        ans += value * hiku_c[key]

print(ans)


Measured memory_bytes: 63528
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int main(){
	string s[7][4]={
		{
			"1100",
			"1100",
			"0000",
			"0000"
		},{
			"1000",
			"1000",
			"1000",
			"1000"
		},{
			"1111",
			"0000",
			"0000",
			"0000"
		},{
			"0100",
			"1100",
			"1000",
			"0000"
		},{
			"1100",
			"0110",
			"0000",
			"0000"
		},{
			"1000",
			"1100",
			"0100",
			"0000"
		},{
			"0110",
			"1100",
			"0000",
			"0000"
		}
	};
	
	const int N = 8;
	const int M = 4;
	string m[N];
	while(cin>>m[0]){
		reps(i,1,N)cin>>m[i];
		
		rep(i,N){
			rep(j,N){
				
				rep(c,7){
					bool ok = true;
					rep(k,M){
						rep(p,M){
							int x = j+p;
							int y = i+k;
							if(x>=N || y>=N){
								if(s[c][k][p]=='1')ok=false;
							}else{
								if(s[c][k][p]!=m[y][x])ok=false;
							}
						}
					}
					if(ok){
						printf("%c\n",'A'+c);
						goto A;
					}
				}
			}
		}
		A:;
	}
	
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

ll power(ll x, ll y) {
	if (y==0) return 1;
	else if (y==1) return x%MOD;
	else if (y%2==0) { ll pow=power(x,y/2); return (pow*pow)%MOD; } 
	else { ll pow=power(x,y/2); return ((pow*pow)%MOD)*x%MOD; }
}
ll divid(ll x, ll y) {
	return ((x%MOD)*power(y,MOD-2))%MOD;
}

int main(){
	int n; cin >> n;
	VI a(n); REP(i,n) cin >> a[i];
	ll sum=0;
	REP(i,n) sum+=a[i];
	sum%=MOD;
	ll ans=0;
	REP(i,n){
		ans+=a[i]*(sum-a[i]+MOD)%MOD;
		ans%=MOD;
	}
	cout << divid(ans,2) << endl;
	return 0;
}

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

int main() {
  int A,B,n,s=0;
  cin>>A>>B;
  n=A;
  while(n<=B){
    if(n%10==n/10000&&n/10%10==n/1000%10) s+=1;
    else s+=0;
    n+=1;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 3564
while True:
    a,op,b= input().split()
    a = int(a)
    b = int(b)
    
    if op=='+':
        print(a+b)
    elif op=='-':
        print(a-b)
    elif op=='*':
        print(a*b)
    elif op=='/':
        print(a//b)
    else:
        break
    
    


Measured memory_bytes: 5596
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+" ";
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
constexpr const ll INF = 1e17;
constexpr const ll MOD = 1000000007;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
typedef pair<ll,ll> P;
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,a,b;
    cin >> k >> a >> b;
    bool ok = 0;
    rep(i,1001){
        if (a <= k*i && k*i <= b) ok = 1;
    }
    if (ok) PRINT("OK");
    else PRINT("NG");
}


Measured memory_bytes: 3660
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

int main(int argc, char const *argv[]){
	char string[] = "aiueo";
	char ch;
	scanf("%c",&ch);
	for (int i = 0; i < 5; ++i)
	{
		if(ch == string[i]){
			puts("vowel");
			return 0;
		}
	}
	puts("consonant");
}


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

typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back

// dp[n][m] = 1..n add to m
// ans = dp[n][s]
// dp[n][m] = dp[n-1][m] * 2 + dp[n-1][m-a[i]]

const int maxn = 3005;
const int mod = 998244353;
int a[maxn];
ll dp[maxn][maxn];
int main() {
    int n, s;
    cin >> n >> s;
    for(int i=1;i<=n;++i) cin >> a[i];
    dp[0][0] = 1;

    for(int i=1;i<=n;++i) {
        for(int j=0;j<=s;++j) dp[i][j] = dp[i-1][j] * 2 % mod;
        for(int j=a[i];j<=s;++j) {
            (dp[i][j] += dp[i-1][j-a[i]]) %= mod;
        }
    }
    cout << dp[n][s] << endl;
}

Measured memory_bytes: 73996
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    
    m = sum(1 for a in A if a % 2 == 1)
    n2 = sum(1 for a in A if a % 2 == 0 and a % 4 != 0)
    n4 = sum(1 for a in A if a % 4 == 0)
    
    if m <= n4:
        print('Yes')
    elif m == n4 + 1:
        if n2 == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
    
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 20156
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
typedef long long ll;
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ld long double
#define ss second
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384626
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

const int mod = 1'000'000'007;

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}
vector<vector<ll>> dp;
vector<vector<ll>> adj;

void dfs(int u, int pa)
{
	dp[u][0] = 1;
	dp[u][1] = 1;
	for(auto x: adj[u])
	{
		if(x == pa) continue;
		dfs(x, u);
		dp[u][0] = ((dp[u][0])*(dp[x][0]%mod + dp[x][1]%mod))%mod;
		dp[u][0]%=mod;
		dp[u][1] = ((dp[u][1])*dp[x][0]%mod)%mod; 
		dp[u][1]%=mod;
	}
	return;
}
	
int main()
{
		fastio;
		ll ttt = 1;
		//cin >> t;
		rep(tt,1,ttt+1)
		{
			ll n;
			cin >> n;
			adj.resize(n+1);
			dp.resize(n+1, vll(2));
			ll u, v;
			rep(i, 0, n-1)
			{
				cin >> u >> v;
				adj[u].pb(v);
				adj[v].pb(u);
			}
			dfs(1, -1);
			cout << (dp[1][0]+dp[1][1])%mod;
		}
		return 0;
	}


Measured memory_bytes: 20984
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = parseInt(arg[0].split(" ")[0]);
    const B = parseInt(arg[0].split(" ")[1]);
    const C = parseInt(arg[0].split(" ")[2]);
    let X = parseInt(arg[0].split(" ")[3]);
    let Y = parseInt(arg[0].split(" ")[4]);
    
    let answer = 0;
    
    while(X > 0 || Y > 0) {
        if(X !== 0 && Y !== 0) {
            // ABピザを使うべきか
            if(A + B > C * 2) {
                answer += C * 2;
                X--;
                Y--;
            } else {
                if(X > 0) {
                    answer += A;
                    X--;
                } else {
                    answer += B;
                    Y--;
                }
            }
        } else {
            if(X > 0) {
                answer += Math.min(A, C * 2);
                X--;
            } else {
                answer += Math.min(B, C * 2);
                Y--;
            }
        }
        
        // console.log("X:" + X);
        // console.log("Y:" + Y);
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <assert.h>
#include <iomanip>
using namespace std;
const int N = 1e5+5;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
typedef long long ll;

// int isPrime[N]; 
// int Prime[N];
// int primeTot;
int main() {
    // primeTot = 0;
    // for(int i = 2; i < N; ++i) {
    //     if(!isPrime[i]) {
    //         Prime[++primeTot] = i;
    //     }
    //     for(int j = 2*i; j < N; j += i) {
    //         isPrime[j] = 1;
    //     }
    // }

    int n, m;
    while(~scanf("%d %d", &n, &m)) {
        int ans = -1;
        for(int i = 1; i <= sqrt(m); ++i) {
            if(m % i == 0) {
                int tt = m / i;
                if(tt >= n) ans = max(ans, i);
                if(i >= n) ans = max(ans, tt);
            }
        }

        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n,a[100100];
int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
    n=read();
    rep(i,1,n) a[i]=read();
    sort(a+1,a+1+n);
    int ans=0;
    if (a[1]>0)
    {
        rep(i,2,n) ans+=a[i];
        ans-=a[1];
        printf("%d\n",ans);
        if (n==2) printf("%d %d",a[2],a[1]);
        else 
        {
            int tmp=a[1];
            rep(i,2,n-1) 
            {
                printf("%d %d\n",tmp,a[i]);
                tmp-=a[i];
            }
            printf("%d %d",a[n],tmp);
        }
    }
    else if (a[n]<0)
    {
        int ans=0;
        rep(i,1,n-1) ans-=a[i];
        ans+=a[n];
        printf("%d\n",ans);
        int tmp=a[n];
        rep(i,1,n-1)
        {
            printf("%d %d\n",tmp,a[i]);
            tmp-=a[i];
        }
    }
    else
    {
        int ans=0;
        rep(i,1,n) ans+=abs(a[i]);
        printf("%d\n",ans);
        int tmp=a[1];
        rep(i,2,n-1)
        {
            if (a[i]>=0)
            {
                printf("%d %d\n",tmp,a[i]);
                tmp-=a[i];
            }
        }
        printf("%d %d\n",a[n],tmp);
        tmp=a[n]-tmp;
        rep(i,2,n-1)
        {
            if (a[i]<0)
            {
                printf("%d %d\n",tmp,a[i]);
                tmp-=a[i];
            }
        }
    }
    return 0;
}
    

Measured memory_bytes: 2304
#include <bits/stdc++.h> 
using namespace std; 
  
// Return the maximum volume. 
float maxvolume(float s) 
{ 
    // finding length 
    float length = s / 3; 
  
    s -= length; 
  
    // finding breadth 
    float breadth = s / 2; 
  
    // finding height 
    float height = s - breadth; 
  
    return length * breadth * height; 
} 
  
// Driven Program 
int main() 
{ 
    float s ;cin>>s; 
    float ans=maxvolume(s); 
    cout<<""<<fixed<<setprecision(6)<<ans<<'\n';
    return 0; 
} 

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
# map(int, input().split())
N = int(input())
L = list(map(int, input().split()))

if N <= 2:
    print(0)
else:
    score = 0
    for i in range(N):
        for j in range(i):
            for k in range(j):
                a = [L[i], L[j], L[k]]
                a.sort()
                if len(set(a)) == 3 and a[0] + a[1] > a[2]:
                    score += 1

    print(score)


Measured memory_bytes: 68012
#include <iostream>
#include <algorithm>
#include <string>

using std::string;

int score(const string& s, char c) {
    auto litr = std::find(s.begin(), s.end(), c);
    if (litr == s.end()) return 0;

    int ret = 0;
    while (true) {
        auto ritr = std::find(litr + 1, s.end(), c);
        if (ritr == s.end()) break;
        if (std::find(litr, ritr, '.') == ritr) {
            ret += ritr - litr - 1;
        }
        litr = ritr;
    }
    return ret;
}

int main() {
    int n;
    string s;
    std::cin >> n >> s;

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] != '.') continue;

        s[i] = 'W';
        int w = score(s, 'W'),
            b = score(s, 'B');
        if (b == 0) ans = std::max(ans, w);
        s[i] = '.';
    }

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



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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,n) for(int i=(int)(n-1);i>=0;--i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int N, M;
    cin >> N;
    vs registered(N);
    REP(i, N) cin >> registered[i];
    cin >> M;
    bool open = false;
    REP(i, M) {
        string s;
        cin >> s;
        if (find(ALL(registered), s) != registered.end()) {
            if (open) {
                cout << "Closed by ";
            } else {
                cout << "Opened by ";
            }
            open = !open;
        } else {
            cout << "Unknown ";
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 3208
//E
//Author : Sidiq Tri Pratikto
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
//order_of_key(x) = number of elements stricly smaller than x
//find_by_order(x) = return x-th largest element
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	int N;
	scanf("%d", &N);
	int arr[N + 1];
	for (int i = 1; i <= N; i++) {
		scanf("%d", &arr[i]);
	}
	map<int, int> frek;
	LL ans = 0;
	for (int i = N; i >= 1; i--) {
		if (i == N) {
			for (int j = 1; j < N; j++) {
				frek[j + arr[j]]++;
			}
		} else {
			frek[i + arr[i]]--;
		}
		ans += frek[i - arr[i]];
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 21444
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

lol ans[105][105] = {};
int memo[105][105];

void nasu(int x, int y, int h){
  if(h == 0){
    return;
  }
  if(x < 0 || x >= 100 || y < 0 || y >= 100){
    return;
  }
  memo[x][y] = max(memo[x][y], h);
  nasu(x + 1, y, h - 1);
  nasu(x - 1, y, h - 1);
  nasu(x, y - 1, h - 1);
  nasu(x, y + 1, h - 1);
  return;
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  lol x[n + 5];
  rep(i, n){
    cin >> x[i];
  }
  lol nasu, ans = INF;
  for(int i = 0;i <= n - k;i ++){
    nasu = abs(x[i], x[i + k - 1]);
    if(x[i] < 0 && x[i + k - 1] >= 0){
      nasu += min(-x[i], x[i + k - 1]);
    } else {
      nasu += min(abs(0LL, x[i]), abs(0LL, x[i + k - 1]));
    }
    ans = min(ans, nasu);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

#define kuriage(x)  x+=10-x%10;
#define mod(cans) cans%10**9+7;
#define cin_pl(x,y) for(int i=0;i<x;i++){cin>>y[i];}
#define debug(x) cout << "Debug" << x << "\n"

typedef long long ll;

using namespace std;
int main()
{
    int a,b,sum=0;
    cin>>a>>b;
    for(int i=0;i<2;i++)
    {
        sum+=max(a,b);
        sum==a?a--:b--;
    }
    cout<<sum;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(void){

	int n;
	int count = 0;
	int now;
	int i,j;

	scanf("%d",&n);

	for(i=1;i<=n;i+=2){
		now = 1;
		for(j=1;j<i/2;j++){
			if(i%j==0){
				now++;
			}
		}
		if(now == 8){
			count++;
		}
	}

	printf("%d\n",count);

  
  
	return 0;
  
}


Measured memory_bytes: 128
h, w = map(int, input().split())
ans = 0
def main(h,w):
    if h == 1 or w == 1:
        return 1
    if h*w % 2 == 0:
        ans = h*w // 2
        return ans
    else:
        ans = h*w // 2 + 1
        return ans 
print(main(h,w))


Measured memory_bytes: 2940
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define MAX 2000
int A[MAX], M[MAX];
int a,b,i,j,k,f=0;

int solve(int p, int t){
	if (p>=a){
		return 0;
	}
	if (t - A[p] == 0){
		return 1;
	}

	if (solve(p + 1, t - A[p]) || solve(p + 1, t) ){
		return 1;
	}
	return 0;
}


int main(){
	

	scanf("%d",&a);
	for (i = 0; i < a;i++){
		scanf("%d",&A[i]);
	}
	scanf("%d",&b);

	for (i = 0; i < b;i++){
		scanf("%d",&M[i]);
	}

	for (i = 0; i < b; i++){
		if (solve(0, M[i])){
			printf("yes\n");
		}else{
			printf("no\n");
		}
	}

	return 0;

}

Measured memory_bytes: 588
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
ans = 0
l = list(set(s))
for i in range(len(l)):
    ans = max(ans,s.count(l[i])-t.count(l[i]))
print(ans)        

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    int n;
    cin>>n;
    vector<ll> a(n);
    REP(i,n)cin>>a[i];
    int i=0,ans=0;
    while(i<n)
    {
        if(a[i]<a[i+1])
        {
            while(i<n && a[i]<=a[i+1])i++;
            ans++;
        }
        else if(a[i]>a[i+1])
        {
            while(i<n && a[i]>=a[i+1])i++;
            ans++;
        }
        i++;
    }
    cout<<ans;
  }  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll A, B, N; cin >> A >> B >> N;
  if(N<=10000000){
    ll ans = 0;
    for(ll i=1; i<=min(N,B); i++){
      ans = max(ans, A*i/B-A*(i/B));
    }
    cout << ans << endl;
  }
  else if(B<=10000000){
    ll ans = 0;
    for(ll i=1; i<=min(N,B); i++){
      ans = max(ans, A*i/B-A*(i/B));
    }
    cout << ans << endl;
  }
  else{
    ll ans = 0;
    ll x = B-1;
    for(;x<=N;x+=B){
      ans = max(ans, A*x/B-A*(x/B));
    }
    x=N;
    ans = max(ans, A*x/B-A*(x/B));
    cout << ans << endl;
  }
  return 0;
}


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

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

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;
}

int main(){

    ll n;
    cin >> n;
    ll a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    ll min_p = min({a, b, c, d, e});
    ll ans = ((n + min_p - 1) / min_p) + 4;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const int MOD = 1e9 + 7;



signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int c = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] > a[i-1]) a[i]--;
        if (a[i] < a[i-1]) return cout << "No", 0;
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <set>
#include <vector>
#include <cstring>

using namespace std;

#define debug(x) {cout<<}
typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 223456;

typedef long long ll;
int a[maxn];    
const ll MOD = 1e9 + 7;
int main(){
    // freopen("input.txt", "r", stdin);
    int a, b;
    cin>>a>>b;
    if(a>=13)cout<<b<<endl;
    else if(a >= 6)cout<<b/2<<endl;
    else cout<<0<<endl;    
    return 0;
}

Measured memory_bytes: 256
import collections
n,k = map(int, raw_input().split(' '))



###
#get the data
###
adj = collections.defaultdict(list)
for ii in range(n-1):
	u,v  = map(int,raw_input().split(' '))
	adj[u].append(v)
	adj[v].append(u)

queries = collections.Counter()
for iii in range(k):
	u,v  = map(int,raw_input().split(' '))
	queries[u] += v

###
#BFS 
###
res = collections.Counter()
q = collections.deque([(1,0)])
vis = set([])
while(q):
	uu,count = q.popleft()
	count += queries[uu]
	res[uu] = count
	vis.add(uu)
	for vv in adj[uu]: 
		if vv not in vis:
			vis.add(vv)
			q.append((vv,count))

print ' '.join([ str(res[u]) for u in range(1,n + 1)])

Measured memory_bytes: 164636
#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
#define int ll
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
const int maxn = 300000+10;

int32_t main(){
	fast_io;
	int n;
	cin >> n;
	vi v, g;
	for (int i = 0; i < n; ++i)
		{
			int x, y;
			cin >> x >> y;
			v.emplace_back(x + y);
			g.emplace_back(x - y);
		}	
	sort(v.begin(), v.end());
	sort(g.begin(), g.end());
	int ans = max(v.back() - v[0], g.back() - g[0]);
	show(ans);
	return 0;
}

Measured memory_bytes: 6692
#include<iostream>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    while(h!=0){
        int i,j;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        cin >> h >> w;
    }
    return 0;
}





Measured memory_bytes: 3084
# D - Prediction and Restriction

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = [t for t in str(input())]
U = [''] * N
point = 0

for i in range(N):
    if i < K:
        if T[i] == 'r':
            U[i], point = 'P', point + P
        elif T[i] == 's':
            U[i], point = 'R', point + R
        elif T[i] == 'p':
            U[i], point = 'S', point + S
    else:
        if T[i] == 'r':
            if U[i - K] != 'P':
                U[i], point = 'P', point + P
        elif T[i] == 's':
            if U[i - K] != 'R':
                U[i], point = 'R', point + R
        elif T[i] == 'p':
            if U[i - K] != 'S':
                U[i], point = 'S', point + S

print(point)


Measured memory_bytes: 4800
/*package????????????*/
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
  public static void main(String[] args) {
    try {
      BufferedReader stdReader =
        new BufferedReader(new InputStreamReader(System.in));
      String line;
      while ((line = stdReader.readLine()) != null) { 
    	  int x = Integer.parseInt(line);
        System.out.println(x*x*x);
      }
      stdReader.close();
    } catch (Exception e) {
      e.getStackTrace();
      /*?????´??????0??????*/
      System.exit(0); 
    }
  }
}

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

using namespace std;

const int N = 1000005;
const int mod = 1e9+7;

int n, fact[N], inv[N];

int pw(int a, int n) {
    int result = 1;
    while (n > 0) {
        if (n & 1)
            result = (1LL * result * a) % mod;
        a = (1LL * a * a) % mod;
        n /= 2;
    }
    return result;
}

void precalc() {
    fact[0] = inv[0] = 1;
    for (int i = 1; i < N; ++i) {
        fact[i] = (1LL * fact[i - 1] * i) % mod;
        inv[i] = pw(fact[i], mod - 2);
    }
}

int C(int n, int k) {
    if (k < 0 || k > n) return 0;
    int result = fact[n];
    result = (1LL * result * inv[n - k]) % mod;
    result = (1LL * result * inv[k]) % mod;
    return result;
}

int main() {
    precalc();
    int a, b, c;
    cin >> a >> b >> c;
    int result = 0;
    int prv = 0, pl, pr;
    for (int len = a; len <= a + b + c; ++len) {
        int n = len - a;
        int cur = 0;
        int l = max(n - c, 0), r = min(b, n);
        if (len == a) {
            cur = 1;
        } else {
            cur = (2 * prv) % mod;
            cur = (cur - C(n - 1, pl) + mod) % mod;
            cur = (cur - C(n - 1, pr) + mod) % mod;
            if (pl == l) cur = (cur + C(n, l)) % mod;
            if (pr < r) cur = (cur + C(n, r)) % mod;
        }
        prv = cur;
        pl = l;
        pr = r;
        cur = (1LL * cur * C(len - 1, a - 1)) % mod;
        cur = (1LL * cur * pw(3, a + b + c - len)) % mod;
        result = (result + cur) % mod;
    }
    cout << result << endl;
    return 0;
}


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

int main()
{
    ll n , sum = 0 ;
    cin >> n ;
    ll arr[n] ;
    for(ll i = 0 ; i < n ; i++)
    {
        cin >> arr[i] ;
        sum += arr[i] ;
    }
    sort(arr , arr+n) ;
    cout << arr[0] << " " << arr[n - 1] << " " << sum << endl ;
}


Measured memory_bytes: 3228
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def add_mod(a,b): return (a+b) % MOD

N = iin()
p = fln()

dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(i+1):
        dp[i+1][j] += dp[i][j] * (1-p[i])
        dp[i+1][j+1] += dp[i][j] * p[i]
ans = 0.0
for i in range(N//2+1, N+1):
    ans += dp[N][i]
print(ans)



Measured memory_bytes: 274672
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
typedef long long ll;

using namespace std;

int main() {
    int n, l;
    cin >> n >> l;
    
    int m = 100000;
    int index = 0;
    for(int i = 1; i <= n; i++) {
        if(m > abs(l + i - 1)) {
            m = min(m, abs(l + i - 1));
            index = i;
        }
    }
    
    int sum = 0;
    for(int i = 1; i <= n; i++){
        if(i != index) {
            sum += l + i - 1;
        }
    }
    
    cout << sum << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

#define HOUSE_COUNT 4
#define FLOOR_COUNT 3
#define ROOM_COUNT 10

int main(int argc, char **argv){
	int i,j,k;
	int data[HOUSE_COUNT][FLOOR_COUNT][ROOM_COUNT] = {};
	int len,house,floor,room,chg;
	
	// Input
	scanf( "%d",&len);
	for(i=0;i<len;i++){
		scanf( "%d %d %d %d",&house,&floor,&room,&chg);
		data[house-1][floor-1][room-1] += chg;
	}
	
	// Output
	for(i=0;i<HOUSE_COUNT;i++){
		for(j=0;j<FLOOR_COUNT;j++){
			for(k=0;k<ROOM_COUNT;k++){
				printf(" %d",data[i][j][k]);
			}
			printf("\n");
		}
		if( i < HOUSE_COUNT-1 ){
			for(j=1;j<=20;j++){
				printf("#");
			}
			printf("\n");
		}		
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

string foo(string s){
	stringstream ss;
	string ret="";
	s=s+"aa";
	char t=s[0];
	int cnt=0;
	rep(i,s.size()){
		if(t==s[i]) cnt++;
		else{
			string tmp;
			convert(cnt,tmp);
			ret+=tmp;
			convert(t,tmp);
			ret+=tmp;
			t=s[i];
			cnt=1;
		}
	}
	return ret;
}

void mainmain(){
	int n;
	while(cin>>n,n){
		string s;
		cin>>s;
		rep(i,n){
			s=foo(s);
			// cout<<i<<" "<<s<<endl;
		}
		cout<<s<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

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

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;



void solve() {

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    cout<<1-tc;
    return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int main()
{
	vector<int> val;
	vector<int> rval;
	int n,k;
	string s;
	cin>>n>>k;
	cin>>s;
	if(s[0]=='0')
	{
		val.push_back(0);
	}
	int len=0;
	for(int i=0;i<n;i++)
	{
		if(i>0&&s[i]!=s[i-1])
		{
			val.push_back(len);
			len=1;
		}
		else
		{
			len++;
		}
	}
	val.push_back(len);
/*	for(int i=0;i<val.size();i++)
	{
		cout<<val[i]<<" ";
	}
	cout<<endl;*/
	rval.resize(val.size()+1); 
	rval[0]=0;
	for(int i=0;i<val.size();i++)
	{
		rval[i+1]=rval[i]+val[i];
	}
/*	for(int i=0;i<rval.size();i++)
	{
		cout<<rval[i]<<" ";
	}
	cout<<endl;*/
	int big=0;
	for(int i=0;i<rval.size();i+=2)
	{
		int score=rval[min((int)val.size(),2*k+i+1)]-rval[i];
		big=max(big,score);
	}
	cout<<big<<endl;
	return 0;
}

Measured memory_bytes: 1272
n = int(input())
dp = [float('INF')]*(n+1)
dp[0] = 0
for i in range(1, n+1):
    dp[i] = min(dp[i], dp[i-1]+1)
    k = 1
    while i >= 6**k:
        dp[i] = min(dp[i], dp[i-6**k]+1)
        k += 1
    k = 1
    while i >= 9**k:
        dp[i] = min(dp[i], dp[i-9**k]+1)
        k += 1
print(dp[n])

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

int main()
{
  string S, T;
  cin >> S >> T;
  int count = 0;
  for (int i = 0; i < 3; i++) {
    string s = S.substr(i, 1);
    string t = T.substr(i, 1);
    if (s == t) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <list>          // list
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main()
{
    int n, t;

    cin >> n;
    vector<int> v1(n);
    rep(i, n) cin >> v1.at(i);

    cin >> t;
    vector<int> v2(t);
    rep(i, t) cin >> v2.at(i);

    int cnt = 0;

    rep(i, t)
    {
        rep(j, n)
        {
            if (v1.at(j) == v2.at(i))
            {
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
}



Measured memory_bytes: 3104
#include <stdio.h>

int main() {

	int A,B,C,D;

	scanf("%d %d %d %d",&A,&B,&C,&D);

	if(A+B>C+D){printf("Left\n");}
	else if(A+B==C+D){printf("Balanced\n");}
	else{printf("Right\n");}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    int x, n;
    cin >> x >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(ALL(a));

    int tmp = INF;
    int ans = -1;

    for (int i = -1; i <= 101; i++) {
        bool flag = true;
        for (int j = 0; j < n; j++) {
            if (i == a[j]) {
                flag = false;
            }
        }

        if (flag && abs(i - x) < tmp) {
            ans = i;
            tmp = abs(i - x);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3644