akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    ll T;
    cin >> N >> T;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    ll ans = T;
    for (int i = 0; i < N - 1; i++) ans += min(T, a[i+1] - a[i]);
    cout << ans << '\n';
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int compare(const void *a,const void *b){
    if(*(int *)a>*(int *)b)return 1;
    return -1;
}
int main()
{   int n,k;
    scanf("%d%d",&n,&k);
    int p[n];
    for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
    }
    double e[n];
    for(int i=0;i<n;i++){
        e[i]=(float)(p[i]+1)/2;
    }
    double se=0,max=0;
    for(int i=0;i<k;i++){
        se+=e[i];    
    }
    for(int i=0;i<=n-k;i++){
        if(max<se){
            max=se;
        }
        se-=e[i];
        se+=e[i+k];
    }
    printf("%.10lf",max);
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <numeric>

int main(void) {
	// in
	int x, a;
	std::cin >> x >> a;

	int ans = 0;
	if(x < a) ans = 0;
	else ans = 10;

	std::cout << ans << std::endl;

	return 0;
}


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

using namespace std;

typedef long long ll;

int a[111111];

int main(){
   int n;
   cin >> n;
   for(int i = 0; i < n; ++i)
     cin >> a[i];

   sort(a, a+n);
   if(n % 2 == 0){
     if(a[0] != 1){
       cout << 0 << endl;
       return 0;
     }
     for(int i = 1; i < n; i += 2)
       if(a[i] != i || a[i] != a[i-1]){
         cout << 0 << endl;
         return 0;
       }
   }
   else {
     if(a[0] != 0){
       cout << 0 << endl;
       return 0;
     }
     for(int i = 2; i < n; i += 2)
       if(a[i] != i || a[i] != a[i-1]){
         cout << 0 << endl;
         return 0;
       }
     --n;
   }

   n /= 2;
   int s = 1; 
   while(n--)
     s = s*2%1000000007;
   cout << s << endl;

	return 0;
}



Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

int main(){
	int n,r;	
	while(~scanf("%d %d",&n,&r)){
		if(n==0) break;
		deque<int> A;
		deque<int> B;
		deque<int> C;

		for(int i=0;i<n;i++){
			C.push_back(i);
		}

		for(int i=0;i<r;i++){
			int c;
			scanf("%d",&c);

			for(int j=0;j<n/2;j++){
				B.push_back(C[j]);
			}
			for(int j=n/2;j<n;j++){
				A.push_back(C[j]);
			}
			C.clear();
			while(!A.empty() || !B.empty()){
				for(int j=0;j<c;j++){
					if(A.empty()) break;

					C.push_back(A.front());
					A.pop_front();
				}

				for(int j=0;j<c;j++){
					if(B.empty()) break;
					C.push_back(B.front());
					B.pop_front();
				}
			}

		}


		printf("%d\n",C.back());
	}
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
using namespace std;

int main()
{
    string a,b;
    cin>>a>>b;
    int suma,sumb;
    scanf("%d %d",&suma,&sumb);
    string c;
    cin>>c;
    if(a==c)
        suma--;
    else
        sumb--;
    printf("%d %d\n",suma,sumb);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c, s, k, d;
  d = 0;
  in3(a, b, c);
  in(s);
  rep(i, a + 1){
    rep(j, b + 1){
      k = s - 500 * i - 100 * j;
      if(0 <= k && k <= c * 50)
        d++;
    }
  }
  out(d);
  memi;
}

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

int main(){
  string command;
  priority_queue<int> q;
  while(cin >> command && command!="end"){
    if(command=="insert"){
      int n;
      cin >> n;
      q.push(n);
    }else{
      cout << q.top() << endl;
      q.pop();
    }
  }

  return 0;
}

Measured memory_bytes: 6924
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007 
using namespace std;
void solve(){
   ll n;
   cin>>n;
   ll a[n+1];
   for(ll i=1;i<=n;i++){
      cin>>a[i];
   }
   ll dp[n+2];
   dp[0]=0;
   dp[1]=0;
   dp[2]=abs(a[2]-a[1]);
   for(ll i=3;i<=n;i++){
       ll op1=dp[i-1]+abs(a[i-1]-a[i]);
       ll op2=dp[i-2]+abs(a[i-2]-a[i]);
       dp[i]=min(op1,op2);
   }
   cout<<dp[n]<<endl;

}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 5212
def slove():
    import sys
    input = sys.stdin.readline
    n, h = list(map(int, input().rstrip('\n').split()))
    ma = 0
    bl = []
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        ma = max(ma, a)
        bl.append(b)
    bl.sort()
    cnt = 0
    while True:
        if h <= 0:
            print(cnt)
            exit()
        elif len(bl) != 0:
            b = bl.pop()
            if ma < b:
                h -= b
                cnt += 1
            else:
                cnt += ((h + ma - 1) // ma)
                print(cnt)
                exit()
        else:
            cnt += ((h + ma - 1) // ma)
            print(cnt)
            exit()



if __name__ == '__main__':
    slove()


Measured memory_bytes: 47756
#include<stdio.h>
#include<math.h>
int main(){
	int n,i;
	double s[1024],t,m;
	while(1){
		t=0;m=0;
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++)scanf("%lf",&s[i]);
		for(i=0;i<n;i++)m+=s[i];
		m/=n;
		for(i=0;i<n;i++)t+=pow(s[i]-m,2.0);
		printf("%lf\n",sqrt(t/n));
	}
	return 0;
}

Measured memory_bytes: 660
# input
l, r = map(int, input().split())
o = 2018
if r-l == 1:
    o = int((l*r) % 2019)
elif r-l+1 > 672:
    o = 0
else:
    for i in range(int(l % 2019), int(r % 2019)):
        for j in range(i+1, int(r % 2019)+1):
            if int((i*j) % 2019) < o:
                o = int((i*j) % 2019)
print(o)



Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String w = scan.next();
		int count = 0;
		while(true) {
			 String t = scan.next();
			 
			 if(t.equals("END_OF_TEXT")) break;
			 
			 t = t.toLowerCase();
			 
			 if(t.equals(w)) count++;
	
		}
		System.out.println(count);
		
	}

}



Measured memory_bytes: 26300
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 100005
#define pie 3.14159265358979323
#define minuss 1e-6
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define BIG 100000000
#define N 10000
ll tra[10000];

int main()
{
    ll t,k;
    cin>>t>>k;
    ll sum=0;
    for(int i=0;i<k;i++)
    {
        ll a;
        cin>>a;
        sum+=a;
    }
    ll dif=t-sum;
    if(dif<0)
        cout<<"-1"<<endl;
    else
        cout<<dif<<endl;

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
#define PI 3.1415926535
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;}
char upper(char c){
    if('a' <= c && c <= 'z'){
        c = c - ('a' - 'A');
    }
    return c;
}
char lower(char c){
    if('A' <= c && c <= 'Z'){
        c = c + ('a' - 'A');
    }
    return c;
}
int GetDigit(int num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}
ll enum_divisors(ll N) {
    ll res = 0;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res++;
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res++;
        }
    }
    // 小さい順に並び替える
    return res;
}
//input



//processing
int rmd;



//dpTable
//int dp[100050];
int main(){
    int K;
    cin >> K;
    if (K % 2 == 0 || K % 5 == 0) {
        cout << -1 << endl;
    }
    else {
        if (K == 7) {
            cout << 1 << endl;
        }
        else {
            for (int i = 1; i <= K; i++){
                rmd = (rmd * 10 + 7) % K;
                if (rmd == 0) {
                    cout << i << endl;
                    break;
                }
                else if (i == K) {
                    cout << -1 << endl;
                    break;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define MOD 1000000007
using namespace std;
const long long INF = 3*1e18;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll L;
    cin >> L;
    double a = (double)L / (double)3;
    double ans = pow(a, 3);
    printf("%.8lf\n", ans);
}

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

int main() {
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;
	int		tmp = INF;
	string	str;

	cin >> str;

	if ((str[2]==str[3])&&(str[4]==str[5])) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}


}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ld,ld> id;
typedef tuple<ll,ll,ll> tl;
typedef tuple<ll,ll,ll,ll> ql;

#define FOR(i, a, b) for(ll i=(a); i<=(b); i++)
#define ROF(i, a, b) for(ll i=(a); i>=(b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define FILL(x, n, v) fill(x, x+n, v);
#define ALL(x) x.begin(), x.end()
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define f first
#define s second
#define ins insert
#define e emplace
#define eb emplace_back
#define ef emplace_front
#define p push
#define pf push_front
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ft front
#define bk back
#define pp pop
#define ppb pop_back
#define ppf pop_front

#define db cout<<"YEET\n";
#define ct(x) cout<<x<<'\n';

const ll MOD = 1e9+7; //998244353
const ll MAXN = 10+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);

int main(){
    FAST
    ll x;
    cin >> x;
    cout << 360/__gcd(360ll,x);
}

Measured memory_bytes: 3608
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<map>
#include<stack>
#include<vector>
#include<queue>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	printf("%d",a*b-(a+b)+1);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdbool.h>

typedef double db;
typedef int in;
typedef long int li;
typedef long long int lli;
typedef long ld;
typedef long lld;

#define pi M_PI
#define in scanf
#define out printf
#define inf INT_MAX
#define rep(i,n) for(int i=0;i<n;++i)
#define debugd(d) printf("%d\n",d)
#define debugs(s) printf("%s\n",s)
#define debugc(c) printf("%c\n",c)
#define debugf(f) printf("%f\n",f)

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}


int main (void)
{
  char s[7];
  int cnt=0;
  in("%s\n",s);
  rep(i,6)
  {
    if(s[i]=='1') cnt++;
  }
  out("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
d=int(input())
c=list(map(int,input().split()))
s=[]
for _ in range(d):
    s.append(list(map(int,input().split())))
t=[]
for _ in range(d):
    t.append(int(input()))

ld=[-1]*26
sc=0
for i in range(d):
    sc+=s[i][t[i]-1]
    ld[t[i]-1]=i

    C=0
    for j in range(26):
        C+=c[j]*(i-ld[j])
    sc-=C
    print(sc)

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

int main() {
    long long int Zx, Yz;
    char dalman[104];
    scanf("%lld", &Zx);
    int u = 0;
    while (Zx > 0) {
        Yz = (Zx - 1) % 26;
        dalman[u++] = 'a' + Yz;
        Zx = (Zx - Yz) / 26;
    }
    int range = strlen(dalman);
    for (range--; range >= 0; range--) {
        printf("%c", dalman[range]);
    }
    return 0;
}


Measured memory_bytes: 1616
#include <vector>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <map>
#include <complex>
#include <ctime>
#include <numeric>
#include <set>

using namespace std;

typedef long long ll;

typedef struct node{
    int s, e, val, pos;
    bool operator<(const node& n) const{
        if(e != n.e) return e < n.e;
        return val > n.val;
    }
    node(){};
    node(int ss, int ee, int v, int p){
        s = ss, e = ee, val = v, pos = p;
    }
}node;

int occs[8000000], tree[8000000], n, ans[8000000];

void update(int x, int val){
    while(x <= n){
        tree[x] += val;
        x += x & -x;
    }
}

int query(int x){
    int ret = 0;
    while(x > 0){
        ret += tree[x];
        x -= x & -x;
    }
    return ret;
}

int main()
{

    
    int q, s, e;
    vector<node> v;
    scanf("%d %d", &n, &q);
    for(int i = 1; i <= n; i++){
        scanf("%d", &s);
        v.push_back(node(i, i, s, -1));
    }
    for(int i = 0; i < q; i++){
        scanf("%d %d", &s, &e);
        v.push_back(node(s, e, 0, i));
    }
    
    sort(v.begin(), v.end());
    
    for(int i = 0;i < v.size(); i++){
        if(v[i].val == 0){
            ans[v[i].pos] = query(v[i].e) - query(v[i].s - 1);
        }else{
            if(occs[v[i].val] != 0) update(occs[v[i].val], -1);
            update(v[i].s, 1);
            occs[v[i].val] = v[i].s;
        }
    }
    
    for(int i = 0; i < q; i++){
        printf("%d\n", ans[i]);
    }
    
    return 0;
}



Measured memory_bytes: 25420
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n, x, a[105], i;
  scanf("%d%d", &n, &x);
  for(i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a+n);
  for(i = 0; i < n; i++){
    if(x < a[i]) break;
    x -= a[i];
  }
  if(i == n && x > 0) i--;
  printf("%d\n", i);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif 
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
//typedef long long int ll;
typedef pair<double,double> P;
struct edge{int to,cost;};


int n,m;
vector<P> xy;
double ans;
signed main(){
	
    cin>>n;
    rep(i,n){
        double a,b;
        cin>>a>>b;
        xy.push_back({a,b});
    }
    sort(xy.begin(), xy.end());
    do {
        for(int i=0;i<n-1;i++){
            ans+=sqrt(pow(xy[i].first-xy[i+1].first,2)+pow(xy[i].second-xy[i+1].second,2));
        }
    } while (std::next_permutation(xy.begin(), xy.end()));
    int num=1;
    for(int i=0;i<n;i++){
        num*=i+1;
    }
    printf("%.8lf",ans/double(num));
	
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define endl "\n"
#define all(x) (x).begin(),(x).end()
const int MOD = 1e9+7;
const int mxN = 2e5+3;

void solve(){
	int n;
	cin >> n;
	map<int, int> mp;
	int a;
	int sum = 0;
	for(int i = 0; i < n; ++i){
		cin >> a;
		sum += a;
		mp[a]++;
	}
	int q;
	cin >> q;
	int bi,ci;
	for(int i = 0; i < q; ++i){
		cin >> bi >> ci;
		if(mp.find(bi) != mp.end()){
			int tt = mp[bi];
			mp.erase(mp.find(bi));
			if(mp.find(ci) != mp.end())mp[ci] += tt;
			else mp[ci] = tt;
			sum -= (bi * tt);
			sum += (ci * tt);
		}
		cout << sum << endl;
	}
}

int32_t main(){
	IO;
	
	int nT = 1;
	//cin >> nT;
	for(int i = 1; i <= nT; ++i)
		solve();
	return 0;
}


Measured memory_bytes: 7548
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 105;

int n, a, b;
int p[MAX_N];

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++)
		cin >> p[i];
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for (int i = 0; i < n; i++)
	{
		if (p[i] <= a)
			cnt1++;
		else if (p[i] > a && p[i] <= b)
			cnt2++;
		else if (p[i] > b)
			cnt3++;
	}
	cout << min(cnt1, min(cnt2, cnt3)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

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

using namespace std;

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

	if (n % 2 == 0)cout << (n / 2) - 1 << endl;
	else cout << (n + 1) / 2 - 1 << endl;
}


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

using namespace std;
typedef long long ll;
const int MAXN = 100100;

int N;
ll s[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);
    
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> s[i];

    ll ans = 0;
    for (int i = 1; i < N; i++)
    {
        ll res = 0;
        for (int j = 0; j + i < N; j += i)
        {
            if ((N - 1) % i == 0 && 2 * j >= (N - 1))
                break;
            res += s[j];
            res += s[N-1-j];
            ans = max (ans, res);
        }
    }
    cout << ans << "\n";
}

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

int main(){
  int dp[2][2],n,prv,now,id,nxt;
  string s;

  while(cin >> s,s!="#"){
    n = s.size();
    dp[1][0] = dp[1][1] = 0; prv = s[0]-'1';
    
    for(int i=1;i<n;i++){
      id = i&1, nxt = 1-id;
      now = s[i]-'1';
      if(prv%3 == now%3){
	dp[nxt][0] = dp[id][1]; dp[nxt][1] = dp[id][0];
      }else if(prv%3 < now%3){
	dp[nxt][0] = dp[id][0] + 1;
	dp[nxt][1] = dp[id][0];
      }else{
	dp[nxt][0] = dp[id][1];
	dp[nxt][1] = dp[id][1] + 1;
      }
      prv = now;
    }
    cout << std::min(dp[n&1][0],dp[n&1][1]) << endl;
  }
}

Measured memory_bytes: 1316
N = int(input())
X = input()

n1 = X.count("1")
Xn = int(X, 2)

Xms = (Xn % (n1 - 1)) if n1 > 1 else 0
Xml = Xn % (n1 + 1)


# def f(n):
#     if n == 0:
#         return 0
#     return f(n % bin(n).count("1")) + 1


# dp = [0] * ((10 ** 5) * 2 + 1)
# for i in range(1, len(dp)):
#     dp[i] = f(i)


for i in range(N):
    cnt = 0
    xi = 0
    if X[i] == "1" and n1 == 1:
        print(cnt)
        continue
    elif X[i] == "1":
        xi = (Xms - pow(2, N - i - 1, n1 - 1)) % (n1 - 1)
    else:
        xi = (Xml + pow(2, N - i - 1, n1 + 1)) % (n1 + 1)
    cnt = 1
    while xi != 0:
        xi %= bin(xi).count("1")
        cnt += 1
    print(cnt)



Measured memory_bytes: 9496
n = int(input())
arr = list(map(int, input().split()))
ave = 0
for e in arr:
    ave += e
ave /= n
res = 0
by = ave
for i, e in enumerate(arr):
    if abs(ave - e) < by:
        by = abs(ave - e)
        res = i

print(res)


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

int main() {
  int a, b;
  cin >> a >> b;
  if(b == 1) cout << 0 << endl;
  else if((b-1)%(a-1) == 0) cout << (b-1)/(a-1) << endl;
  else cout << (b-1)/(a-1) + 1 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 2147483647

int N;
int* table;

void init(int first_N){
	while(N < first_N)N *= 2;
}

void update(int loc,int value){
	loc += N-1;

	table[loc] = value;

	if(N == 1)return;

	int parent = (loc-1)/2;

	while(true){
		table[parent] = min(table[2*parent+1],table[2*parent+2]);

		if(parent == 0)break;
		else{
			parent = (parent-1)/2;
		}
	}
}


int query(int search_left,int search_right,int node_id,int node_left,int node_right){

	if(search_right < node_left || search_left > node_right)return NUM;

	if(search_left <= node_left && search_right >= node_right){
		return table[node_id];
	}

	int left_min = query(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
	int right_min = query(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);

	return min(left_min,right_min);
}

char start[500001],goal[500001];

int main(){

	int first_N,K;
	scanf("%d %d",&first_N,&K);

	N = 1;
	init(first_N+1);

	table = new int[2*N-1];

	for(int i = 0; i <= 2*N-2; i++)table[i] = NUM;

	scanf("%s",start);
	scanf("%s",goal);

	int* change_ruisekiwa = new int[first_N+1];

	change_ruisekiwa[0] = 0;
	for(int i = 0; i < first_N; i++){
		if(goal[i] == goal[i+1]){
			change_ruisekiwa[i+1] = change_ruisekiwa[i];
		}else{
			change_ruisekiwa[i+1] = change_ruisekiwa[i]+1;
		}
	}

	int* dp = new int[first_N+1];

	dp[0] = 0;
	update(0,0);

	for(int i = 1; i <= first_N; i++){
		if(start[i-1] == goal[i-1]){
			dp[i] = dp[i-1];

		}else{

			dp[i] = (query(max(0,i-K),i-1,0,0,N-1)+change_ruisekiwa[i-1]+3)/2;
		}
		update(i,2*dp[i]-change_ruisekiwa[i]);
	}

	printf("%d\n",dp[first_N]);

	return 0;
}




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

using ll = long long;
//typedef long long ll;

#define INF (1LL << 31 - 1)
#define INFLL ((1LL << 62) - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) for (int i = n; i >= 0; --i)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()

int vx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, vy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

inline bool check(int ux, int uy, int x, int y) {
  return (0 <= x and x < ux and 0 <= y and y < uy);
}

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

string s;

int main() {
  cin >> s;

  int n = s.size();

  string t = "", revt;

  rep(i,n) {
    if (s[i] != 'x') {
      t += s[i];
    }
  }

  revt = t;
  reverse(all(revt));
  ll ans = 0;
  
  if (t == revt) {

    int l = 0, r = n - 1;

    while (l < r) {
      if (s[l] == 'x' and s[r] != 'x') {
        ans++;
        l++;
      }
      else if (s[l] != 'x' and s[r] == 'x') {
        ans++;
        r--;
      }
      else {
        l++;
        r--;
      }
    }
    
    cout << ans << endl;
  }
  else {
    cout << -1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))

int main(){
	int n,m,i,lr[100000][2],ans=0;
	int imo[100000]={0};
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d%d",&lr[i][0],&lr[i][1]);
		imo[lr[i][0]-1]++;
		imo[lr[i][1]]--;
	}
	for(i=1;i<n+1;i++)imo[i]+=imo[i-1];
	for(i=0;i<n;i++){
		if(m==imo[i])ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int f(int n) {
   int res = 0;
   while (n) {
      n /= 10;
      res++;
   }
   return res;
}
int main() {
   int n;
   cin >> n;
   int ans = 0;
   rep(i, 1, n + 1) {
      if (f(i) % 2 == 1) ans++;
   }
   cout << ans << endl;
   return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for (int i =0; i<N; i++) {
      cin >> vec.at(i);
  }
  std::sort(vec.begin(),vec.end(),std::greater<int>());//昇順ソート

  int sum = 0;
  for (int i =0; i< N; i++) {
      if (i%2 == 0) {
        sum += vec.at(i);
      } else {
       	sum -= vec.at(i); 
      }
  }
  cout << sum << endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, T; scanf("%d %d", &N, &T);
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  int ans = 0, cur = 0;
  for (int i = 0; i < N; ++i) {
    ans += A[i] + T - max(cur, A[i]);
    cur = A[i] + T;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
template<class T> bool inline chmin(T& a, T b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool inline chmax(T& a, T b) { if (a < b) {a=b;return 1;} return 0; }
const long long INF = 1LL << 60;
const int MAX_N=110;
const int MAX_V=100100;
int N;
long long W, weight[MAX_N], value[MAX_N];
long long dp[MAX_N][MAX_V]; 
int main() {
	cin >> N >> W;
	for(int i = 0; i < N; i++) {
		cin >> weight[i] >> value[i];
	}
	for (int i =0; i <MAX_N; i++) {
		for (int j =0 ; j <MAX_V; j++) {
			dp[i][j] = INF;
		}
	}
   dp[0][0]=0;
	for (int i = 0; i < N; i++) {
		for (int sum_v = 0; sum_v <MAX_V; sum_v++) {
			if (sum_v - value[i] >= 0) {
				chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]]+weight[i]);
            }
               chmin(dp[i + 1][sum_v], dp[i][sum_v]);
		}
	}
	long long res=0;
    for(int i=0;i<MAX_V;i++){
    if(dp[N][i]<=W) res=i;
    }
  cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 86272
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ri register int
#define sid 2005

char s[sid];
int n, m, ans;
bool v[sid][sid], c[sid][sid];
short h[sid][sid], l[sid][sid], r[sid][sid];
short L[sid][sid], R[sid][sid];

int main() {
    
    scanf("%d%d", &n, &m);
    for(ri i = 1; i <= n; i ++) {
        scanf("%s", s + 1);
        for(ri j = 1; j <= m; j ++)
        c[i][j] = (s[j] == '#') ? 1 : 0;
    }

    for(ri i = 1; i < n; i ++)
    for(ri j = 1; j < m; j ++)
    v[i][j] = c[i][j] ^ c[i + 1][j] ^ c[i][j + 1] ^ c[i + 1][j + 1] ^ 1;

    for(ri i = 1; i <= n; i ++) {
        int lst = 0;
        for(ri j = 1; j <= m; j ++)
        if(v[i][j]) l[i][j] = lst;
        else L[i][j] = 0, lst = j;
        
        lst = m + 1;
        for(ri j = m; j >= 1; j --)
        if(v[i][j]) r[i][j] = lst;
        else R[i][j] = m + 1, lst = j;
    }

    for(ri i = 0; i <= m + 1; i ++) R[0][i] = m + 1;

    ans = max(n, m);
    for(ri i = 1; i <= n; i ++)
    for(ri j = 1; j <= m; j ++)
    if(v[i][j]) {
        h[i][j] = h[i - 1][j] + 1;
        L[i][j] = max((short)(l[i][j] + 1), L[i - 1][j]);
        R[i][j] = min((short)(r[i][j] - 1), R[i - 1][j]);
        ans = max(ans, (R[i][j] - L[i][j] + 2) * (h[i][j] + 1));
    }

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

Measured memory_bytes: 47360
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
 int n;
  cin>>n;
  
  int a[n];
 
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  
  int num=1;
  
  sort(a,a+n);
  
  for(int j=0;j<n-1;j++)
  {
    if(a[j]<a[j+1])
    {
      num++;
    }
  }
  
  cout<<num<<endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
        int a,b,c;

        scanf("%d %d %d",&a,&b,&c);

        if(a <= b && b <= c){
                printf("%d %d %d",a,b,c);
        }else if(c <= a && a <= b){
                printf("%d %d %d",c,a,b);
        }else if(a >= b && b >= c){
                printf("%d %d %d",c,b,a);
        }else if(a <= c && c <= b){
                printf("%d %d %d",a,c,b);
        }else if(b <= a && a <= c){
                printf("%d %d %d",b,a,c);
        }else if(b <= c && c <= a){
                printf("%d %d %d",b,c,a);
        }
        printf("\n");

        return 0;
}

Measured memory_bytes: 600
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	c := nextInt()
	xs := make([]int, n)
	vs := make([]int, n)
	vss := make([]int, n+1)
	for i := 0; i < n; i++ {
		xs[i] = nextInt()
		vs[i] = nextInt()
		vss[i+1] = vss[i] + vs[i]
	}

	ans := 0

	ss1 := make([]int, n+1)
	for i := 0; i < n; i++ {
		x := xs[i]
		ss1[i+1] = max(ss1[i], vss[i+1]-x)

		ans = max(ans, ss1[i+1])
	}

	ss2 := make([]int, n+1)
	for i := 0; i < n; i++ {
		j := n - i - 1
		x := c - xs[j]
		v := vss[n] - vss[j]
		ss2[i+1] = max(ss2[i], v-x)

		ans = max(ans, ss2[i+1])
	}

	ss3 := make([]int, n+1)
	for i := 0; i < n; i++ {
		s1 := ss1[i+1]
		s2 := ss2[n-(i+1)]
		ss3[i] = s1 + s2 - xs[i]

		ans = max(ans, ss3[i])
	}

	ss4 := make([]int, n+1)
	for i := 0; i < n; i++ {
		s2 := ss2[i+1]
		s1 := ss1[n-(i+1)]
		x := c - xs[n-i-1]
		ss4[i] = s2 + s1 - x

		ans = max(ans, ss4[i])
	}

	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

var sc = bufio.NewScanner(os.Stdin)

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


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

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

        //  I, O, T, J, L, S, Z
        this.ICount = inpt[0];
        this.OCount = inpt[1];
        this.JCount = inpt[3];
        this.LCount = inpt[4];
        long ans = Math.Max(this.GetVal(1), this.GetVal(0)) + this.OCount;
        
        Console.WriteLine(ans);
      
    }


    private long GetVal(long join3)
    {

        long tmp = Math.Min(ICount, Math.Min(join3, Math.Min(this.JCount, this.LCount)));
        long ans = tmp * 3;
        long remainI = this.ICount - tmp;
        long remainJ = this.JCount - tmp;
        long remainL = this.LCount - tmp;

        ans += (remainI / 2) * 2;
        ans += (remainJ / 2) * 2;
        ans += (remainL / 2) * 2;
        return ans;
    }




    private long OCount = 0;
    private long ICount = 0;
    private long JCount = 0;
    private long LCount = 0;



    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"

0 0 10 0 0 0 0



";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 2904
n = int(input())

p1 = [2,4,5,7,9]
p2 = [0,1,6,8]
p3 = [3]
if n%10 in p1:
    print("hon")
elif n%10 in p2:
    print("pon")
elif n%10 in p3:
    print("bon")

Measured memory_bytes: 9048
s = input()
ans = 'inf'
for i in range(8):
    total = int(s[0])
    str = s[0]
    for j in range(3):
        if i>>j&1:
            total += int(s[j+1])
            str += '+' + s[j+1]
        else:
            total -= int(s[j+1])
            str += '-' + s[j+1]
    if total == 7:
        print(str + '=7')
        exit()

Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;

int main() {
    int K, X;
    cin >> K >> X;
    for(int i = X - K + 1; i <= X + K - 1; i++){
        if(i == X + K - 1){
            cout << i << endl;
            return 0;
        }
        cout << i << ' ' << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
    ios::sync_with_stdio(false);
	int N,c=0;
	string s;
	cin>>N>>s;
	for(int i=0;i<N;i++){
		if(s[i]=='('){
			c++;
		}else{
			if(c==0){
				cout<<'(';
				continue;
			}
			c--;
		}
	}
	cout<<s;
	if(c>0) for(int i=0;i<c;i++) cout<<')';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  string a,b,c;
  cin >> a >> b >> c;
  cout << char(a[0]-'a'+'A') << char(b[0]-'a'+'A') << char(c[0]-'a'+'A') << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;


bool isPrimeDistance(vector<int> x, vector<int> y){

    int size = x.size();
    lli distance = 0;
    for (int i = 0; i < size; ++i) {
        distance += (x[i] - y[i]) * (x[i] - y[i]);
    }

    double sqrt = pow((double)distance, 0.5);
    return ceil(sqrt) == floor(sqrt);
}

int main() {

    int N, D;
    cin >> N >> D;

    vector <vector<int >> dimension(N, vector<int>(D));

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < D; ++j) {
            cin >> dimension[i][j];
        }
    }

    lli counter = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {

            if (i == j) {
                continue;
            }

            if (isPrimeDistance(dimension[i], dimension[j])) {
                ++ counter;
            }
        }
    }

    cout << counter / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
int x[100005], y[100005];
char s[100005];

int main(){
    scanf("%s",s+1);
    int n = strlen(s+1);
    if(s[n]=='1' || s[1]=='0') printf("-1\n");
    else{
        int ok = 1;
        for(int i = 1; i <= n/2; i++){
            if(s[i]!=s[n-i]) ok = 0;
        }
        if(!ok) printf("-1\n");
        else{
            int size = 0;
            int p = n/2+1;
            for(int i = p+1; i <= n; i++){
                size++;
                x[size] = p, y[size] = i;
            }
            for(int i = n/2; i >= 1; i--){
                size++;
                x[size] = p, y[size] = i;
                if(s[i]=='1') p = i;
            }
            for(int i = 1; i <= size; i++){
                printf("%d %d\n",x[i],y[i]);
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2584
#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>
#include <array>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#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 UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple

using namespace std;

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


const int N = 1e5+10;

ll dp_s[N], dp_a[N];

int mons[110];

const ll INF = 1e15;

int main(){
	ios::sync_with_stdio(false);
	
	int n;
	while (cin >> n, n){
		rep(i, n) cin >> mons[i];

		int m;
		cin >> m;
		FOR(i, 1, N) dp_s[i] = dp_a[i] = INF;
		dp_s[0] = dp_a[0] = 0;
		rep(i, m){
			string s;
			int w, v;
			cin >> s >> w >> s >> v;
			ll *dp;
			if (s[0] == 'S') dp = dp_s;
			else dp = dp_a;

			rep(j, N) dp[min(j + v, 100000)] = min(dp[min(j + v, 100000)], dp[j] + w);
		}

		for (int i = N - 2; i >= 0; --i){
			dp_s[i] = min(dp_s[i], dp_s[i + 1]);
			dp_a[i] = min(dp_a[i], dp_a[i + 1]);
		}

		ll ans = INF;
		rep(i, N){
			ll tmp = dp_a[i];
			if (tmp == INF) continue;

			rep(j, n) tmp += dp_s[max(mons[j] - i, 0)];
			ans = min(ans, tmp);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 2772
#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

int n;
int a[MAXN], b[MAXN];

void read()
{
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i] >> b[i];
}

int perm[MAXN];

bool cmp(int i, int j) { return a[i] + b[i] > a[j] + b[j]; }

void solve()
{
	int64_t answer = 0;
	for(int i = 0; i < n; i++)
		perm[i] = i;

	sort(perm, perm + n, cmp);

	for(int i = 0; i < n; i++)
	{
		int p = perm[i];

		if(i & 1) answer -= b[p];
		else answer += a[p];
	}

	cout << answer << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 4736
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace __gnu_pbds;
using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

#define INF (ll)(1e9)

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
        
    ll n, m;
    cin >> n >> m;
    vector<string> maze(n);
    FOR(i, n) cin >> maze[i];
    vector<vll> shadow(n, vll(m, INF));
    queue<ll> q;
    ll sr = 0;
    ll sc = 0;
    ll ma = -1;
    FOR(i, n)
    {
        FOR(j, m)
        {
            q.push(i); q.push(j); q.push(0);
            set<pll> visited;
            while (!q.empty())
            {
                ll r = q.front(); q.pop();
                ll c = q.front(); q.pop();
                ll s = q.front(); q.pop();
                if (r < 0 || r >= n || c < 0 || c >= m || maze[r][c] == '#' || visited.find({r, c}) != visited.end()) continue;
                ma = max(ma, s);
                visited.insert({r, c});
                q.push(r + 1); q.push(c); q.push(s + 1);
                q.push(r - 1); q.push(c); q.push(s + 1);
                q.push(r); q.push(c + 1); q.push(s + 1);
                q.push(r); q.push(c - 1); q.push(s + 1);
            }
        }
    }
    cout << ma << '\n';
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <time.h>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


int main(){
    int N; cin >> N;
    int v[55];
    for (int i = 0; i < N; i++){
        cin >> v[i];
    }
    sort(v,v+N);
    double ans = (double)(v[0]+v[1])/2.0;
    for (int i = 1; i < N-1; i++){
        ans = (double)(ans+v[i+1])/2.0;
    }
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
def GCD(x, y):
    if(x == 0):
        return(y)
    return(GCD(y % x, x))

def LCM(x, y):
    return(x * y / GCD(x, y))

while(True):
    try:
        a = map(int, raw_input().split())
        if(a[0] > a[1]):
            a[0], a[1] = a[1], a[0]
        print(GCD(a[0], a[1])),
        print(LCM(a[0], a[1]))
    except Exception:
        break

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

using namespace std;

int main(){
  
  int num_test = 0; 
  cin >> num_test;
  
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  string judge;
  
  for (int i = 0; i < num_test; i++){
    
    cin >> judge;
    
    if (judge == "AC"){
      ac = ac + 1;
    }
    
    else if (judge == "WA"){
      wa = wa + 1;
    }
    
    else if (judge == "TLE"){
      tle = tle + 1;
    }
    
    else if (judge == "RE"){
      re = re + 1;
    }
  }
  
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var ans = N / 2;
        if (N % 2 == 0) ans--;
        Console.WriteLine(ans);
    }

    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;

int main(){

  int n;
  string str,k;

  cin >> n;
  getline(cin,str);

  for(int i=0;i<n;i++){
    getline(cin,str);
    int s = 0;

    for(int j=0;j<str.size();j++){

      if("Hoshino" == str.substr(j,7)){
	j += 6;
		cout << "Hoshina";
      }

       else cout << str[j];

    }
    cout << endl;

  }
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    Vvec<int> x(N, vector<int>(N)), y(N, vector<int>(N));
    for(int i=0; i<N; i++){
        cin >> A[i];
        for(int j=0; j<A[i]; j++){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }

    int ans = 0;
    for(int i=0; i<(1<<N); i++){
        bool flag = true;
        for(int j=0; j<N; j++){
            if((i>>j)%2 == 0) continue;
            for(int k=0; k<A[j]; k++){
                flag &= ((i>>(x[j][k]))%2 == y[j][k]);
            }
        }
        if(flag) ans = max(ans, (int)bitset<16>(i).count());
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
S = input()

N = len(S)
ans = [0 for _ in range(N)]
direction = 'R'
count = 0

for i in range(N):
	if S[i] == 'R':
		if direction == 'R':
			count += 1
		else:
			ans[i - count] += count - count // 2
			ans[i - count - 1] += count // 2
			direction = 'R'
			count = 1
	else:
		if direction == 'L':
			count += 1
			if i == N - 1:
				ans[i - count + 1] += count - count // 2
				ans[i - count] += count // 2
		else:
			ans[i - 1] += count - count // 2
			ans[i] += count // 2
			direction = 'L'
			count = 1
			if i == N - 1:
				ans[i] += 1

for i in range(N):
	print(ans[i], end='')
	if i == N - 1:
		print()
	else:
		print(' ', end='')

Measured memory_bytes: 5524