akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, k;
double ans;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		int t = 0;
		int tmp = i;
		while (tmp < k) {
			t++;
			tmp = tmp * 2;
		}
		ans += pow(0.5, t);
	}
	ans = ans / n;
	cout << setprecision(20) << ans << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define pii pair<int, int>
#define pp pair<pair<ll, ll>, pair<ll, ll>>
#define pll pair<ll, ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define ERASE(v) v.erase(unique(v.begin(), v.end()), v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    while(true){
        ll a,b;
        cin>>a>>b;
        if(a==0&&b==0) break;
        a--;b--;
        ll n,dp[30][30];
        cin>>n;
        bool ng[30][30];
        rep(i,30)rep(j,30){
            dp[i][j]=0;
            ng[i][j]=0;
        }
        rep(i,n){
            ll s,t;
            cin>>s>>t;
            s--;t--;
            ng[s][t]=1;
        }
        dp[0][0]=1;
        rep(i,a+1){
            rep(j,b+1){
                if(!ng[i+1][j]) dp[i+1][j]+=dp[i][j];
                if(!ng[i][j+1]) dp[i][j+1]+=dp[i][j];
            }
        }
        // rep(i,a+1){
        //     rep(j,b+1){
        //         cout<<dp[i][j]<<" ";
        //     }
        //     cout<<endl;
        // }
        cout<<dp[a][b]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3120
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = list(input())

    res = 0
    for i in range(n):
        if i < k:
            res += p if t[i] == "r" else r if t[i] == "s" else s
        else:
            if t[i - k] != t[i]:
                res += p if t[i] == "r" else r if t[i] == "s" else s
            else:
                t[i] = "e"

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 4084
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const double EPS = 1e-10;
typedef pair<int, int> P;
vector<int> v[200000];
int main() {
	int H, W, N;
	cin >> H >> W >> N;
	for (int i = 0; i < N; i++) {
		int r, c;
		cin >> r >> c;
		r--; c--;
		v[c].push_back(r);
	}
	for (int i = 0; i < W; i++) {
		v[i].push_back(H);
		sort(v[i].begin(), v[i].end());
		v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end());
	}
	int ans = 1 << 30;
	int sum = 0;
	int y = 0;
	for (int i = 0; i < W; i++) {
		int idx = upper_bound(v[i].begin(), v[i].end(), y) - v[i].begin();
		ans = min(ans, sum + (v[i][idx] - y));
		if (i == W - 1) break;
		bool ok = 0;
		while (y + 1 < v[i][idx]) {
			y++;
			sum++;
			int idx2 = lower_bound(v[i + 1].begin(), v[i + 1].end(), y) - v[i + 1].begin();
			if (v[i + 1][idx2] != y) {
				ok = 1;
				break;
			}
		}
		if (!ok) break;
	}
	cout << ans << endl;

}

Measured memory_bytes: 11392
#include<bits/stdc++.h>
using namespace std;
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second << '\n'; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front() << ' '; for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << *_it <<' '; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; }for (auto _it:_m) { _out << _it.first << ": " << _it.second << '\n'; } return _out; }
#define pb push_back
#define pob pop_back
#define makp make_pair
#define X first
#define Y second
#define ll long long
#define all(x) x.begin(),x.end()
#define up(a,t) (upper_bound(all(a),t) - a.begin())
#define lb(a,t) (lower_bound(all(a),t) - a.begin())
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
struct cord{
    int x;
};
#define ld long double

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, h, w;
    cin >> n >> h >> w;
    int ans = 0;
    for(int i = 0;i < n;i++){
        int a,b;
        cin >> a >> b;
        if(a >= h && b >= w){
            ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

S = input()

if S[0] == "A" and S[2:-1].count("C") == 1:
    for i in range(len(S)):
        if i == 1 or i == len(S)-1:
            if not S[i].islower():
                print("WA")
                exit()
        elif 2 <= i <= len(S)-2:
            if not S[i].islower() and S[i] != "C":
                print("WA")
                exit()
    print("AC")
else:
    print("WA")

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

int main() {
  int a, b;
  char op;
  
  
  while(1) {
    int result;
    cin >> a >> op >> b;
    if (op == '+') result = a+b;
    if (op == '-') result = a-b;
    if (op == '*') result = a*b;
    if (op == '/') result = a/b;
    if (op == '?') break;
    cout << result << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3120
while True:

    items,money=list(map(int,input().split()))

    if money==0 and items==0:
        break

    prices=list(map(int,input().split()))

    times=int(items*(items-1)/2)

    sum_list=[]

    low=0
    high=1
    sum=0
    i = 0

    while True:
        #sum=prices[low]+prices[high]

        if high>items-1:
            low+=1
            high=low+1
        if low==items-1:
            break
        #print(high,low)
        sum = prices[low] + prices[high]
        #print(sum)
        if sum<=money:
            sum_list.append(sum)
            high+=1
            i+=1
        else:
            high+=1

    if i==0:
        print("NONE")
    else:
        print(max(sum_list))









Measured memory_bytes: 29288
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    while (true) {
        int h, w;
        scan(w, h);

        if (h == 0 && w == 0) return;

        auto g = iota(h).map!(i => readln.split.to!(int[])).array;

        auto ans = solve(h, w, g);

        writeln(ans);
    }
}


int solve(int h, int w, int[][] g) {
    auto v = new bool[][](h, w);

    int ans;

    int[] di = [1, -1, 0, 0, 1, 1, -1, -1];
    int[] dj = [0, 0, 1, -1, 1, -1, 1, -1];

    void dfs(int i, int j) {
        v[i][j] = true;

        foreach (k ; 0 .. 8) {
            int ni = i + di[k];
            int nj = j + dj[k];
            if (ni < 0 || nj < 0 || ni >= h || nj >= w) continue;
            if (v[ni][nj] || !g[ni][nj]) continue;
            dfs(ni, nj);
        }
    }

    foreach (i ; 0 .. h) {
        foreach (j ; 0 .. w) {
            if (g[i][j] && !v[i][j]) {
                dfs(i, j);
                ans++;
            }

            debug {
                writefln("%(%s\n%)", v);
            }
        }
    }

    return ans;
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}



Measured memory_bytes: 3412
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2000000000
#define MOD 1000000007
#define N 200005
#define M 1000005
#define LOG 30
#define KOK 32000
#define EPS 0.000000001
using namespace std;

int n,a[N];

bool check(int val) {

	vector<iii> v;

	int len=0;

	for(int i=1;i<=n;i++) {

		if(a[i]>len) {

			if(!sz(v) || v.back().nd!=1) {

				v.pb({{len+1,a[i]},1});

			}
			else {

				v.back().st.nd=a[i];

			}

			len=a[i];

		}
		else {

			len=a[i];

			while(sz(v) && (v.back().st.st>len || v.back().nd==val)) v.ppb();

			if(!sz(v)) return false;

			umin(v.back().st.nd,len);

			iii psh={{v.back().st.nd,v.back().st.nd},v.back().nd+1};

			v.back().st.nd--;

			if(v.back().st.st>v.back().st.nd) v.ppb();

			v.pb(psh);

			if(psh.st.nd+1<=len) v.pb({{psh.st.nd+1,len},1});

		}

	}

	return true;

}

int main() {
 
	//freopen("input.txt","r",stdin);

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",a+i);

	int bas=1,son=n;

	while(bas<=son) {

		if(check(orta)) son=orta-1;
		else bas=orta+1;

	}

	printf("%d",bas);

}


Measured memory_bytes: 1024
#include<stdio.h>
# define ousama 196470
int main()
{
 int dai,syou;
 int n,Y,M,D;
 int i,c,t;
scanf("%d",&n);
for(i=0;i<n;i++){
t=0;
scanf("%d %d %d",&Y,&M,&D);
for(c=1;c<Y;c++){
if(c%3==0)
t+=200;
else
t+=195;
}
if(Y%3==0){
for(c=1;c<M;c++){
t+=20;
}
for(c=1;c<D;c++)
t++;
}
else{
for(c=1;c<M;c++){
if(c%2==0)
t+=19;
else
t+=20;
}
for(c=1;c<D;c++)
t++;
}
printf("%d\n",ousama-t);
}
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N, X;
  cin >> N >> X;
  vector<int> m(N);
  for (int i = 0; i < N; i++)
    cin >> m[i];
  for (int i = 0; i < N; i++)
    X -= m[i];
  int ans = N;
  int mmin = m[0];
  for (int i = 1; i < N; i++)
  {
    if (m[i] < mmin)
      mmin = m[i];
  }
  ans += X / mmin;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 2000000
#define INFTY (1<<30)

int n,A[MAX+1];

void maxHeapify(int i){
  
  int l,r,largest,a;
  l = 2 * i;
  r = 2 * i +1;

  if(l<=n && A[l] > A[i]) largest = l;
  else largest = i;

  if(r<=n && A[r] > A[largest]) largest = r;

  if(largest != i){
    a=A[i];
    A[i]=A[largest];
    A[largest]=a;
      maxHeapify(largest);
  }
}

int extract(){
  int maxv;
  if(n<1) return -INFTY;
  maxv = A[1];
  A[1] = A[n--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i,int key){

  int m;
  if(key<A[i]) return;
  A[i] = key;
  while(i>1 && A[i/2]<A[i]){
       m=A[i];
    A[i]=A[i/2];
    A[i/2]=m;
    i=i/2;
  }
}

void insert(int key){
  n++;
  A[n] = -INFTY;
  increaseKey(n,key);
}

int main(){
  int key;
  char com[10];
  while(1) {
    scanf("%s",com);
    if(com[0] == 'e' && com[1] == 'n') break;
    if(com[0] == 'i'){
      scanf("%d",&key);
      insert(key);
    }
    else printf("%d\n",extract());
  }
  return 0;
}

Measured memory_bytes: 4696
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// copy from http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2366802#1
#define TABLE_SIZE 16777216
#define ORDER_LENGTH 7
#define STR_LENGTH 13
 
using namespace std;
 
int array[128];
 
int translateStr(char buf[]){
    int sum = -1,mult = 1;
    for(int i = 0; buf[i] != '\0'; i++){
        sum += array[buf[i]]*mult;
        mult *= 4;
    }
    return sum;
}
 
int main(){
 
    array['A']=1,array['C']=2,array['G']=3,array['T']=4;
 
    int n;
    scanf("%d",&n);
    char order[ORDER_LENGTH],str[STR_LENGTH];
 
    char* check_table = new char[TABLE_SIZE];
 
    for(int i = 0; i < n; i++){
        scanf("%s %s",order,str);
        if(order[0] == 'i'){
            check_table[translateStr(str)] = 'Y';
        }else{
            if(check_table[translateStr(str)] == 'Y'){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
}


Measured memory_bytes: 4448
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    LL N, A, B;
    cin >> N >> A >> B;

    LL cnt = (N / (A + B));
    LL ans = cnt * A;
    LL nokori = N % (A + B);
    ans += min(A, nokori);

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<int, int>;
ll mod = 1000000007;
ll MOD = 998244353;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x) % mod, n / 2) % mod);
	else
		return (x * pow(x, n - 1)) % mod;
}
bool prime(int n) {
	int i = 2;
	if (n == 2)return true;
	else if(n <= 1)return false;
	if (n % i == 0)return false;
	i = 3;
	while (i <= sqrt(n)) {
		if (n % i == 0)return false;
		i += 2;
	}
	return true;
}
signed main() {
	int n; cin >> n;
	vector<int>a;
	int i = 0;
	int num =1;
	while (i < n) {
		if (prime(num))a.push_back(num), i++;
		num += 10;
	}
	rip(i, n)cout << a[i] << endl;
}


Measured memory_bytes: 3540
import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int i,j;
        
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0) break;

            for(i=0;i<W;i++){
            System.out.print("#");
            }
            System.out.println();


            for(i=0;i<H-2;i++){
                System.out.print("#");
                for(j=0;j<W-2;j++){
                    System.out.print(".");
                }
                System.out.println("#");
            }

            for(i=0;i<W;i++){
                System.out.print("#");
            }
            System.out.println();
            System.out.println();
        }
        

    }
}


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

int main(){
	int A,B,C,D,E,F;
	char X,Y;
	cin >> X >> Y;
	if(X > Y){
		cout << ">" << endl;
	}
	else if(X == Y){
		cout << "=" << endl;
	}
	else{
		cout << "<" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
for h in range(1, 3501):
    for n in range(h, 3501):
        if (4*h*n-N*n-N*h)>0 and (N*h*n)%(4*h*n-N*n-N*h)==0:
            print(h, n, (N*h*n)//(4*h*n-N*n-N*h))
            exit()


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

int main(){
  string s;
  cin >> s;
  string t = s;
  reverse(s.begin(),s.end());
  for(char &c : s) {
    if(c == 'b') c = 'd';
    else if(c == 'd') c = 'b';
    else if(c == 'p') c = 'q';
    else if(c == 'q') c = 'p' ;
  }
  cout << (s == t ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3840
N,M = [int(i) for i in input().split(" ")]
road = [0]*(N+1)
for i in range(M):
    a_i,b_i = [int(j) for j in input().split(" ")]
    road[a_i] += 1
    road[b_i] += 1
for i in range(1,N+1):
    print(road[i])

Measured memory_bytes: 3060
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define reT() int T; scan_d(T); rep(t, 0, T)
#define de(x) cout << #x << " = " << x << endl
#define dd(x) cout << #x << " = " << x << " "
#define pw(x) (1ll<<(x))
#define lsn (rt<<1)
#define rsn (rt<<1|1)
#define modadd(a,b) {a+=b;a%=MOD;}
#define modmul(a,b) {a*=b;a%=MOD;}
#define LL long long
#define IN freopen("in", "r", stdin)
#define OUT freopen("out", "w", stdout)
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 210000;

template <typename T>
inline bool scan_d(T &ret) {
	char c;
	int sgn;
	if (c = getchar(), c == EOF) return 0;   //EOF
	while (c != '-' && (c < '0' || c > '9')) {
		if ((c = getchar()) == EOF) return 0;
	}
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	ret *= sgn;
	return 1;
}
template<typename T>
void print(T x) {
	static char s[33], *s1;
	s1 = s;
	if (!x) *s1++ = '0';
	if (x < 0) putchar('-'), x = -x;
	while (x) *s1++ = (x % 10 + '0'), x /= 10;
	while (s1-- != s) putchar(*s1);
}
template<typename T>
void println(T x) {
	print(x);
	putchar('\n');
}

int n;
LL a[N], b[N], am[N], bm[N];
int main() {
	while (scan_d(n)) {
		rep(i, 0, n) scan_d(a[i]);
		rep(i, 0, n) scan_d(b[i]);

		LL res = 0;
		rep(i, 0, 30) {
			int vand = pw(i + 1) - 1;
			rep(i, 0, n) am[i] = a[i] & vand;
			rep(i, 0, n) bm[i] = b[i] & vand;
			sort(am, am + n);
			sort(bm, bm + n);

			int cnt = 0;
			rep(j, 0, n) {
				LL vup = pw(i) * 2 - am[j];
				LL vlow = max(pw(i) - am[j], 0ll);
				cnt += lower_bound(bm, bm + n, vup) - bm;
				cnt -= lower_bound(bm, bm + n, vlow) - bm;

				vup = pw(i) * 4 - am[j];
				vlow = pw(i) * 3 - am[j];
				cnt += lower_bound(bm, bm + n, vup) - bm;
				cnt -= lower_bound(bm, bm + n, vlow) - bm;
			}
			if (cnt & 1) res ^= pw(i);
		}
		println(res);
	}
	return 0;
}


Measured memory_bytes: 6656
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    if(s.equals("Sunny" )){
      System.out.println("Cloudy");
    } else if(s.equals("Cloudy")) {
      System.out.println("Rainy");
    } else {
      System.out.println("Sunny");
    }
  }
}
  


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

long long d, t, s;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> d >> t >> s;
	cout << ((s * t >= d) ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 3588
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut cnt = 0;
    let mut b = vec![];
    let mut r = vec![0; n + 1];

    for i in (0..n).rev() {
        let ni = i + 1;
        let mut curr = 0;

        let mut tmp = ni;
        while tmp + ni <= n {
            tmp += ni;
            if r[tmp] == 1 {
                curr += 1;
                curr %= 2;
            }
            // println!("tmp:{}, curr:{}", tmp, curr);
        }

        if a[i] != curr {
            cnt += 1;
            r[i + 1] = 1;
            b.push(i + 1);
        }
    }
    println!("{}", cnt);
    for i in b {
        print!("{} ", i);
    }
}


Measured memory_bytes: 5752
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#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 revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int A, B, C, D; cin >> A >> B >> C >> D;
    if (A+B > C+D) cout << "Left" << endl;
    else if (A+B == C+D) cout << "Balanced" << endl;
    else cout << "Right" << endl;
}

Measured memory_bytes: 256
//_Hala Madrid_//

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

typedef long long            ll;
typedef double               db;
typedef long double          ldb;
typedef vector<int>          vi;
typedef pair<int, int>       pii;
#define fio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,start,end)     for(ll i=start;i<=end;i++)
#define FORD(i,start,end)    for(ll i=start;i>=end;i--)
#define br                   cout<<"\n"
#define test(t)              int t;cin>>t;while(t--)
#define rz                   return 0
#define all(s)               s.begin(),s.end()
#define sz                   size()
#define pb                   push_back
#define F                    first
#define S                    second

const int mod=1e9+7;

void solve(){
    bool flag=0,flag1=0;
    int m,n,k,l,r,sum=0,ans=0,pos,pos1,c1=0,c2=0,c3=0,c4=0,x,y,z,cnt=0,mx=0,mn=INT_MAX;
    string s,t,s1,s2;
    string str="";
    vi v;
    cin>>n;
    int h[n];
    vector <ll> dp(n+5,INT_MAX);
    FOR(i,0,n-1)
    cin>>h[i];
    dp[0]=0;
    FOR(i,0,n-1){
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    }
    cout<<dp[n-1];
}
int main(){
    fio
    bool notc=0;
    int t=1;
    if(notc){
        cin>>t;
    }
    while(t--){
        
        #ifdef _DEBUG
	        freopen("input.txt", "r", stdin);
	        freopen("output.txt", "w", stdout);
        #endif
        
        solve();
    }
    rz;    
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

using namespace std;
using ll = long long;

int main(){
    int a[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    int n;
    cin>>n;
    int b[n];
    bool ok[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            ok[i][j]=false;
        }
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(b[i] == a[j][k]) ok[j][k] = true;
            }
        }
    }
    bool bingo =false;
    for(int i=0;i<3;i++){
        if(ok[i][0]==true&&ok[i][1]==true&&ok[i][2]==true) bingo=true;
        if(ok[0][i]==true&&ok[1][i]==true&&ok[2][i]==true) bingo=true;
        if(ok[0][0]==true&&ok[1][1]==true&&ok[2][2]==true) bingo=true;
        if(ok[2][0]==true&&ok[1][1]==true&&ok[0][2]==true) bingo=true;
    }
    if(bingo) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
l = list(raw_input())

s = l[0]
f = False
mx = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        mx = max(mx, min(i, len(l)-x))
        x = i
        s = n
else:
    mx = max(mx, min(i+1, len(l)-x))
print mx


Measured memory_bytes: 3460
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

///////////////////////////





int main() {
	
	ll N;
	string S;
	cin >> N >> S;

	ll ans = 0;

	rep(i, N - 2) {
		if (S[i] == 'A'&&S[i + 1] == 'B'&&S[i + 2] == 'C') { ans++; }
	}

	cout << ans;
	system("PAUSE");


}


Measured memory_bytes: 504
while True:
    vals = list(map(int,input().split()))
    score = vals[0]+vals[1]
    if vals[0]==-1 and vals[1]==-1 and vals[2]==-1:
        break
    if vals[0]==-1 or vals[1]==-1:
        print ("F")
    elif score>=80:
        print ("A")
    elif score>=65:
        print ("B")
    elif score>=50:
        print ("C")
    elif score>=30:
        if vals[2]>=50:
            print ("C")
        else:
            print ("D")
    else:
        print ("F")
    


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

using namespace std;

const int MOD = 1e9 + 7;
const int maxn = 2e5 + 10;

int a[maxn];

int main() {
	int n;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n << 1; ++i) 
		a[i] = !i ? (s[i] == 'B') : (s[i] != s[i - 1]);

	int L = 0;
	long long ans = 1;
	for (int i = 0; i < n << 1; ++i) 
		if (a[i]) {
			L++;
		} else {
			if (!L) {
				puts("0");
				return 0;
			}
			ans = ans * L % MOD;
			L--; a[i + 1] ^= 1;
		}
	if (L > 0) ans = 0;
	for (int i = 1; i <= n; ++i) ans = ans * i % MOD;
	cout << ans << "\n";
	return 0;
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll x, y, z, k; cin >> x >> y >> z >> k;
	vector<ll> va(x), vb(y), vc(z);
	REP(i, x) cin >> va[i];
	REP(i, y) cin >> vb[i];
	REP(i, z) cin >> vc[i];

	sort(ALL(va), greater<ll>());
	sort(ALL(vb), greater<ll>());
	sort(ALL(vc), greater<ll>());

	vector<ll> res;
	REP(a, x)REP(b, y)
		REP(c, z)
			if ((a+1)*(b+1)*(c+1) <= k) res.push_back(va[a]+vb[b]+vc[c]);
			else break;
				

	sort(ALL(res), greater<ll>());
	REP(i, k) std::cout << res[i] << std::endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, a[maxn];

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

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

	int lastVal = a[0], ans = 1;
	char state = 'n';
	for (int i = 1; i < n; i++) {
		if (state == 'n') {
			if (a[i] > lastVal) {
				state = 'i';
			}
			else if (a[i] < lastVal) {
				state = 'd';
			}
		}
		else if (state == 'i') {
			if (a[i] < lastVal) {
				state = 'n';
				ans++;
			}
		}
		else {
			if (a[i] > lastVal) {
				state = 'n';
				ans++;
			}
		}
		lastVal = a[i];
	}
	cout << ans << endl;
}



Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()

char a, b, c, d;
int main(){
    cin >> a >> b >> c >> d;
    if (a==b && b==c || b==c && c==d) cout << "Yes";
    else cout << "No";
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

bool test() {
	ll n; cin >> n;
	vl a(n);
	FOR(i,0,n) cin >> a[i];
	sort(all(a));
	
	if (a[0]+2 <= a[n-1]) return false;

	if (a[0] == a[n-1]) {
		if (a[0] == n-1) return true;
		if (2*a[0] <= n) return true;
		return false;
	} else {
		ll col = a[n-1];
		ll x = 0, y = 0;
		FOR(i,0,n) if (a[i] == col) y++; else x++;
		// col >= x+1, col <= x+y/2 
		return col >= x+1 && col <= x+y/2;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cout << (test() ? "Yes" : "No") << endl;
}



Measured memory_bytes: 1024
long long i,j;a[1000000],s;main(){for(i=2;i<1e6;i++){if(!a[i])for(j=i*i;j<1e6;j+=i)a[j]=1;a[i]=s+=!a[i];}for(;~scanf("%d",&i);printf("%d\n",a[i]));}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int i;
  int N, K;
  cin >> N >> K;
  
  vector <int> p(N);
  for(i=0; i<N; i++){
    cin >> p[i];
  }
  
  sort(p.begin(), p.end());
  int ans = 0;
  for(i=0; i<K; i++){
    ans += p[i];
  }
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 3624
n,d,x=gets.split.zip([2,1.0,1.0]).map{|x,y|x.to_i*y}
r=0
n.step(2,-2){|n|
	r+=d+(n-1)*x/2
	d,x=d+2*d/n+5*x/n,x+4*x/n
}
p r

Measured memory_bytes: 1788
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	int aa,bb;
	int i=0;
	int x=0;
	aa=a.size();
	bb=b.size();
	if(aa<bb){
		cout<<"LESS"<<endl;
	}else if(aa<bb){
		cout<<"GREATER"<<endl;
	}else{
		for(i=0;i<aa;i++){
			if(a[i]<b[i]){
				cout<<"LESS"<<endl;
				x=1;
				break;
			}else if(a[i]>b[i]){
				cout<<"GREATER"<<endl;
				x=1;
				break;
			}
		}
		if(x==0){
			cout<<"EQUAL"<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  int ans=0;
  rep(i,n-1){
    if(a[i]==a[i+1]){
      ans++;
      a[i+1]=0;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3588
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        for(int i=0;i<a.length();i++){
            System.out.print(a.charAt(i));
            if(i<b.length())System.out.print(b.charAt(i));
        }
    }
}


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

int main(){

  int N=0;
  cin>>N;
  int L[N];

  rep(i,N){
    cin>>L[i];
  }
  sort(L, L + sizeof(L)/sizeof(L[0]));
  
  ll res=0;

  rep(i,N){
	int k=i;
    for(int j=i+1;j<N;j++){

      while(k < N && L[k] < L[i]+L[j]){
        k++;
        //cout<<"i="<<i<<", j= "<<j<<", k="<<k<<endl;
      }
      res+=k-(j+1);
      
    }
  }
  
  cout<<res;

}





Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
long long k;
long long a[51];
int main()
{
	scanf("%lld",&k);
	for(int i=1;i<=50;i++)a[i]=49;
	long long s=k/50LL;
	for(int i=1;i<=50;i++)a[i]=a[i]+s;
	k%=50LL;
	for(int i=1;i<=k;i++)
	{
		a[i]+=50LL;
		for(int j=1;j<=50;j++)
		{
			if(i==j)continue;
			a[j]--;
		}
	}
	puts("50");
	for(int i=1;i<=50;i++)printf("%lld ",a[i]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll mod(ll a) {
  return (a % MOD + MOD) % MOD;
}

ll dp[110][10];

bool check_double(ll j){
  bool ret=true;
  bool flg=false;
  while(j){
    if(j&1){
      if(flg==true){
        ret=false;
        break;
      }
      flg=true;
    }else{
      flg=false;
    }
    j=j>>1;
  }
  return ret;
}
int main(){
  ll h,w,k;cin>>h>>w>>k;
  dp[0][0]=1;
  rep(i,h){
    rep(j,pow(2,w-1)){
      ll temp=j;
      if(check_double(j)){
        bool flg=false;
        rep(l,w){
          if(flg==false){
            if(temp&1){
              dp[i+1][l]=mod(dp[i+1][l]+dp[i][l+1]);
              dp[i+1][l+1]=mod(dp[i+1][l+1]+dp[i][l]);
              flg=true;
            }else{
              dp[i+1][l]=mod(dp[i+1][l]+dp[i][l]);
            }
          }else{
            if((temp&1)==0){
              flg=false;
              //pass
            }else{
              cout<<"Error"<<endl;
            }
          }
          temp=temp>>1;
        }
      }
    }
  }
  cout<<dp[h][k-1]<<endl;
}

Measured memory_bytes: 512
N = int(input())
result = 0
for i in range(1, (N + 1)):
    if i % 15 == 0:
        'Fizz Buzz'
    elif i % 3 == 0:
        'Fizz'
    elif i % 5 == 0:
        'Buzz'
    else:
        result = result + i
print(result)


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

int main() {
    long long q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    s = min({q*4, h*2, s});
    long long ans = min(s*n, d*(n/2) + s*(n%2));
    cout << ans << endl;
}

Measured memory_bytes: 256
from sys import stdin
from heapq import nsmallest

def second_smallest(numbers):
    return nsmallest(2, numbers)[-1]

a,b,c = [int(x) for x in stdin.readline().strip().split()]

if a%2==0 or b%2==0 or c%2==0:
  print(0)
else:
  print(min([a,b,c]) * second_smallest([a,b,c]))

Measured memory_bytes: 9108
#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

struct NODE{
	int pos , bit;
	NODE(int a,int b){ pos = a ; bit = b;}
	NODE(){}
};

NODE *done[1<<15][15];
NODE Q[(1<<15)*15];
int n,m;

bool diff(int a,int b,vector<string> &ans){
	int bit = a ^ b;
	bool f = false;
	rep(i,n){
		if( (a>>i&1)^(b>>i&1)){
			f = true;
			stringstream ss;
			ss << "Switch " << (a>>i&1?"on":"off") << " room " << i+1 << ".";
			ans.push_back(ss.str());
		}
	}
	return f;
}

int main(){
	while(cin >> n >> m && n){
		vector< vector<int> > v(n);
		vector< vector<int> > room(n);
		rep(i,m){
			int a,b;
			cin >> a >> b;
			a--,b--;
			v[a].push_back(b);
			v[b].push_back(a);
		}
		rep(i,n) sort(v[i].begin(),v[i].end());
		int init = 0;
		rep(i,n){
			int a; cin >> a;
			init |= (a<<i);
		}
		rep(i,n){
			int c; cin >> c;
			rep(j,c){
				int a; cin >> a;a--;
				if(a != i) room[i].push_back(1<<a);
			}
			sort(room[i].begin(),room[i].end());
		}
		rep(i,1<<n)rep(j,n) done[i][j] = NULL;
		int head = 0 , size = 0 , ansbit = (1<<30); 
		bool flag = false;
		Q[size++] = NODE(0,init);
		done[init][0] = &Q[head];
		while(head < size){
			NODE q = Q[head];
			if(q.pos == n-1){
				if( q.bit == (1<<(n-1)) ){
					vector<string> a;
					NODE r = q;
					while(1){
						NODE next = (*done[r.bit][r.pos]);
						if(next.pos == r.pos && next.bit == r.bit) break;
						if(r.pos != next.pos){
							stringstream ss;
							ss << "Move to room " << r.pos+1 <<".";
							a.push_back(ss.str());
						}else{
							diff(r.bit,next.bit,a);
						}
						r = next;
					}
					cout << "You can go home in " << a.size() << " steps." << endl;
					rep(i,a.size()){
						cout << a[a.size()-1-i] << endl;
					}
					goto exit;
				}
				flag = true;
			}
			rep(j,room[q.pos].size()){
				int nextbit = q.bit ^ room[q.pos][j];
				if(done[nextbit][q.pos] == NULL){
					done[nextbit][q.pos] = &Q[head];
					Q[size++] = NODE(q.pos,nextbit);
				}
			}
			rep(i,v[q.pos].size()){
				if(q.bit >> v[q.pos][i] & 1){
					if(done[q.bit][v[q.pos][i]] == NULL){
						done[q.bit][v[q.pos][i]] = &Q[head];
						Q[size++] = NODE(v[q.pos][i],q.bit);
					}
				}
			}
			head++;
		}
		if(flag)cout << "You can not switch off all lights." << endl;
		else cout << "Help me!" << endl;
		exit:;
	}
}

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

int main(){
  int i,j,k,h,n,p[50];

  while(1){
    cin>>n;
    if(n==0)break;

    for(i=0;i<n;i++){
    cin>>p[i];
    }

    for(i=0;i<n;i++){
      if(i!=0)cout<<" ";
      j=i;
      h=0;
      k=0;
      while(1){
	j++;
	k++;
       	if(j>=n){break;}
	if(p[i]+k==p[j]){h=1;}
	else break;
      }
      if(h==1)printf("%d-%d",p[i],p[j-1]);
      //  if(h==2)break;      
      else printf("%d",p[i]);
      i=j-1;
    }

    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;
const int maxn = 2000100;



int main(){
        _
        int n,m; cin >> n >> m;

        int a = n, b = m;
        vi x1(n),y1(n);
        vi x2(m),y2(m);
        for(int i = 0; i<n; i++){
            cin >> x1[i] >> y1[i];
        }
        for(int i = 0; i<m; i++){
            cin >> x2[i] >> y2[i];
        }
        for(int i = 0; i<n; i++){
            ll  mn = 1000000000000;
            int pos;
            for(int j = 0; j<m; j++){
                ll ans = abs(x1[i]-x2[j])+abs(y1[i]-y2[j]);
                if(ans<mn){
                    mn = ans;
                    pos = j+1;
                }
            }
            cout<<pos<<endl;
        }


return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<32


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    
    lm = max(L)
    rm = min(R)

    print(max(0, rm-lm+1))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R)

if __name__ == '__main__':
    main()


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

int main() {
  int N,i,onlyacount=0,onlybcount=0,maxcount=0,len,doublecount=0;
  scanf("%d",&N);
  char s[N][10];
  for(i=0;i<N;i++){
    scanf("%s",s[i]);
    char *hoge;
    hoge=s[i];
    while((hoge=strstr(hoge,"AB"))!=NULL){
      maxcount++;
      hoge++;
    }
    len=strlen(s[i]);
    if(s[i][len-1]=='A' && s[i][0]!='B'){
      onlyacount++;
    }
    else if(s[i][0]=='B' && s[i][len-1]!='A'){
      onlybcount++;
    }
    else if(s[i][len-1]=='A' && s[i][0]=='B'){
      doublecount++;
    }
  }
  maxcount+=((onlyacount<onlybcount)?onlyacount:onlybcount);
  maxcount+=doublecount;
  if(doublecount!=0 && onlyacount==0 && onlybcount==0){
    maxcount--;
  }
  printf("%d\n",maxcount);
  return 0;
}


Measured memory_bytes: 256
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}          // Least Commont Multiple オーバーフローしないように先に割る

const ll INF = LONG_MAX;
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; }

int main()
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("c.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int n, m;
    cin >> n >> m;

    //vector<int> l(m), r(m);

    int left = 0;
    int right = 1e6;

    int l, r;
    rep (i, m) {
        //cin >> l[i] >> r[i];
        cin >> l >> r;
        chmax(left, l);
        chmin(right, r);
    }

    if (right >= left) cout << right - left + 1;
    else cout << 0;

    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



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

using namespace std;

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

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

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

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

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

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int a[125252];
vi ids[5252];
int pts[125252];

int main(){
  scanf("%d",&n);
  REP(i,n){
    int x,y;
    scanf("%d.%d",&x,&y);
    a[i] = x*1000 + y;
    ids[a[i]].push_back(i);
  }
  int sum = 0;
  REP(i,5252){
    for(int id : ids[i]){
      pts[id]--;
      pts[id] += ids[i].size() * 1;
      pts[id] += sum * 3;
    }
    sum += ids[i].size();
  }
  REP(i,n)printf("%d\n",pts[i]);
  return 0;
}

Measured memory_bytes: 4508