akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;

signed main() {
	cin >> N >> K;
	vector< int > A(N), B(N);
	rep(i, N) cin >> A[i] >> B[i];
	int ans = 0;
	for (int k = -1; k < 31; k++) {
		if (k != -1 && ((1 << k) & K) == 0)
			continue;
		int K2;
		if (k == -1) {
			K2 = K;
		} else {
			K2 = K ^ (1 << k);
			K2 |= (1 << k) - 1;
		}
		int tmp = 0;
		rep(i, N) {
			if ((K2 | A[i]) == K2) {
				tmp += B[i];
			}
		}
		//cout << K2 << " " << tmp << endl;
		chmax(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1920
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def f(a, b):
    return pow(a, 5) - pow(b, 5)


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    X = ii()
    LIST = [i ** 5 for i in range(1001)]

    for a in range(1001):
        for b in range(a + 1, 1001):
            if LIST[b] - LIST[a] == X:
                print(b, a)
                exit()
            if LIST[b] + LIST[a] == X:
                print(b, -a)
                exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9472
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <map>
#include <iostream>
#include <iomanip>
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)

int main(){
    int N;
    cin >> N;
    vector<LL> A(N);
    REP(i,N)cin>>A[i];

    map<LL, LL> count;
    REP(i, N){
        auto itr = count.find(A[i]);
        if(itr != count.end()){
            count[A[i]] += 1;
        }else{
            count[A[i]] = 1;
        }
    }

    LL ans = 0;
    for(auto itr=count.begin(); itr!=count.end(); ++itr){
        LL num = itr->first;
        LL c = itr->second;
        if(c < num){
            ans += c;
        }else{
            ans += c-num;
        }
    }

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

Measured memory_bytes: 9956
#include<cstdio>
int f[10001],n,m;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int x;scanf("%d",&x);
        for(int i=1;i<=x;i++){
            int y;scanf("%d",&y),n-=f[y]==0,f[y]=1;
        }
    }
    printf("%d\n",n);
}

Measured memory_bytes: 1732
import sys
readline = sys.stdin.buffer.readline
N,W = map(int,readline().split())
w,v = map(int,readline().split())
tmp = w
lst1 = [1,0,0,0]
v0 = [v]
v1 = []
v2 = []
v3 = []
for i in range(N-1):
    w,v = map(int,readline().split())
    if w == tmp:
        lst1[0] += 1
        v0.append(v)
    elif w == tmp+1:
        lst1[1] += 1
        v1.append(v)
    elif w == tmp+2:
        lst1[2] += 1
        v2.append(v)
    else:
        lst1[3] += 1
        v3.append(v)
v0.sort(reverse=True)
for i in range(1,lst1[0]):
    v0[i] += v0[i-1]
v1.sort(reverse=True)
for i in range(1,lst1[1]):
    v1[i] += v1[i-1]
v2.sort(reverse=True)
for i in range(1,lst1[2]):
    v2[i] += v2[i-1]
v3.sort(reverse=True)
for i in range(1,lst1[3]):
    v3[i] += v3[i-1]

ans = 0
for i in range(lst1[0]+1):
    for j in range(lst1[1]+1):
        for k in range(lst1[2]+1):
            for l in range(lst1[3]+1):
                res = i*tmp+j*(tmp+1)+k*(tmp+2)+l*(tmp+3)
                if W >= res:
                    res2 = 0
                    if i != 0:
                        res2 += v0[i-1]
                    if j != 0:
                        res2 += v1[j-1]
                    if k != 0:
                        res2 += v2[k-1]
                    if l != 0:
                        res2 += v3[l-1]


                    ans = max(ans,res2)

print(ans)

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

int main(void){
    int a,b,k;
    cin>>a>>b>>k;
    set<int> st;
    for(int i=a; i<a+k && i<=b; i++){
        st.insert(i);
    }
    for(int i=max(b-k+1,a); i<=b; i++){
        st.insert(i);
    }
    for(int x:st){
        cout<<x<<endl;
    }
    return 0;
}

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

namespace MS
{
    void call(int n)
    {
        int i = 1;
        while (++i<=n)
        {
            int x = i;
            if (x%3==0)
                cout<<" "<<i;
            else if (x%10==3)
                cout<<" "<<i;
            else 
            {
                while(x)
               {
                    if (x%10==3)
                    {
                        cout<<" "<<i;
                        break;
                    }
                    x /= 10;
                }
            }
            
        }
        cout<<endl;
    }
}

int main()
{
    int n;
    cin>>n;
    MS::call(n);
    return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    int count=0;
    while(n--)
    {
        int a,b;
        cin>>a>>b;
        if(sqrt(pow(a,2)+pow(b,2))<=d)
        {
            count++;
        }
    }
    cout<<count;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var l = A.ToList();
		l.Sort();
		l.Reverse();
		var ans = new String[N];
		for(int i=0;i<N;i++){
			ans[i] = (A[i] == l[0] ? l[1] : l[0]).ToString();
		}
		Console.WriteLine(String.Join("\n",ans));
		
		
	}
	int N;
	int[] A;
	public Sol(){
		N = ri();
		A = new int[N];
		for(int i=0;i<N;i++) A[i] = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 32852
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char a[102],b[102],c[102];
int la,lb,lc;
void card(int x,int y,int z,int m)
{
	if(m==1)
	{
		if(la==x)
		{printf("A");return ;}
		card(x+1,y,z,a[x]-'a'+1);
	}
	else	if(m==2)
	{
		if(lb==y)
		{printf("B");return ;}
		card(x,y+1,z,b[y]-'a'+1);
	}
	else	if(m==3)
	{
		if(lc==z)
		{printf("C");return ;}
		card(x,y,z+1,c[z]-'a'+1);
	}
}
int main()
{
	scanf("%s%s%s",a,b,c);
	la=strlen(a);lb=strlen(b);lc=strlen(c);
	card(0,0,0,1);
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int s;
  int k;
  for (int i=0; i<n; i++){
    cin >> k;
    s += (k != i+1);
  }
  if(s <= 2){
  cout << "YES" << endl; 
  } else {
  cout << "NO"  << endl;  
  }
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void ll_swap(lli* a, lli* b)
{
    lli tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd(int a, int b)
{
    if (a < b)
        swap(&a, &b);

    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

long power(long x, int n) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
		printf("res:%lld a:%lld\n", res,a);
	}
	return res;
}


lli comb(lli n, lli r)
{
    if (n == 0)
        return 0;

    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/

/*
int main()
{
    int N;
    int num;
    int A[100001]={ 0 };

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

    int ans = 0;

    for (int i = 1; i <= N; i++)
    {
        if (A[i]%2==1)
        {
            //printf("%d\n", i);
            ans++;
        }
    }

    printf("%d", ans);
}*/

int N, ptr, res;
int A[100000];
int main()
{
    scanf("%d", &N);
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);
    sort(A, A + N);
    while (ptr < N)
    {
        int cc = A[ptr], f = 0;
        while (ptr < N && A[ptr] == cc) f++, ptr++;
        res += f % 2;
    }
    printf("%d\n", res);
}

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

using namespace std;

const int N = 2000 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
int a[N], x[N], z[N];
vector<int> vec[N];

bool read() {
    if (!(cin >> n))
        return false;

    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    return true;
}

void solve() {
    for (int i = 1; i <= n; ++i) {
        x[i] = (x[i - 1] ^ a[i]);
        z[i] = z[i - 1] + (x[i] == 0);
        vec[x[i]].emplace_back(i);
    }

    long long ans = 1ll;

    if (x[n] == 0) {
        for (int i = 0; i < z[n] - 1; ++i)
            ans = ans * 2ll % MOD;

        for (int t = 1; t < N; ++t)
            if (!vec[t].empty()) {
                long long cur = 0ll, sum = 1ll;

                for (int i = 1; i < vec[t].size(); ++i) {
                    cur += sum * (z[vec[t][i]] - z[vec[t][i - 1]]) % MOD;
                    (sum += (cur %= MOD) + 1) %= MOD;
                }

                (ans += sum) %= MOD;
            }

        cout << ans << endl;
    } else {
        long long cur = 0ll, sum = 1ll;

        for (int i = 1; i < vec[x[n]].size(); ++i) {
            cur += sum * (z[vec[x[n]][i]] - z[vec[x[n]][i - 1]]) % MOD;
            (sum += ans = (cur %= MOD) + 1) %= MOD;
        }

        cout << ans % MOD << endl;
    }
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 67316
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int c(int a,int b)
{
    return a>b;
}
int main()
{
    ll n,k;
    cin>>n>>k;
    if(n==k)
    {
        printf("0\n");
        return 0;
    }
    if(n>k)
        n=n%k;
    ll t=k-n,ans=n;
    while(n!=t)
    {
        ans=min(ans,t);
        t=abs(k-t);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

res = sum(b)
for i in range(n - 1):
    if a[i] + 1 == a[i + 1]:
        res += c[a[i] - 1]
print(res)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define INF (1e9)

int D = 365;
vi c, ans;
vvi s;

void input() {
  cin >> D;
  c = vi(26);
  s = vvi(D, vi(26));
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
}

void output() {
  for (int i = 0; i < D; i++) {
    cout << ans[i] + 1 << endl;
  }
}

int simulate(vi a) {
  int sum = 0;
  vi last(26);
  for (int i = 0; i < D; i++) {
    sum += s[i][a[i]];
    last[a[i]] = i;
    for (int j = 0; j < 26; j++) {
      sum -= c[j] * (i - last[j]);
    }
  }
  return max((int)1e6 + sum, 0);
}

void solve() {
  srand(20200628);
  int sum = 0;
  ans = vi(D, 0);
  for (int i = 0; i < 1000; i++) {
    vi a(D);
    for (int j = 0; j < D; j++) {
      a[j] = rand() % 26;
    }

    int x = simulate(a);
    if (x > sum) {
      sum = x;
      ans = a;
    }
  }
}

int main() {
  input();
  solve();
  output();
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main(){
    ll N,K;
    cin >> N >> K;

    ll sum = 0;
    for(int p = K; p <= N + 1; p++){
      ll tmp = (N - p + 1) * p + 1;
      tmp = tmp % MOD;
      sum = (sum + tmp) % MOD;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3620
H, W, K = map(int, input().split())
C = list(input() for _ in range(H))

ans = 0
for i in range(0, pow(2,H)):
    for j in range(0, pow(2,W)):
        cnt = 0
        x = format(i, '06b')
        x = x[::-1]
        x = x[:H]
        y = format(j, '06b')
        y = y[::-1]
        y = y[:W]
        for h in range(H):
            for w in range(W):
                if x[h] == '0' and y[w] == '0':
                    if C[h][w]== '#':
                        cnt += 1
        if cnt == K:
            ans += 1
            
print(ans)

Measured memory_bytes: 9204
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(H: int, A: int):
    print(-(-H//A))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    solve(H, A)


if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    sum ^= A.at(i);
  }
  
  for (int i = 0; i < N; i++) {
    cout << (A.at(i) ^ sum);
    if(i != N-1 ){
      cout << ' ';
    }
  }
  return 0;
}

Measured memory_bytes: 4024
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    res = []
    for i, x in enumerate(a):
        res.append([x, i])
    res.sort()
    ans = []
    for x, i in res:
        ans.append(i+1)
    print(*ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 27172
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define CAT(a,b)a b
#define VASIZE(a,b,N,...)N
template<class T>auto size(T&&a)->decltype(a.size(), ll()) { return a.size(); }
template<class T>typename make_signed<decltype(T() % 0)>::type size(T a) { return a; }
#define REP(t,a,N)for(decltype(size(N))t=size(a),_l##t=size(N);t<_l##t;t++)
#define RREP(t,a,N)for(decltype(size(N))t=size(N)-1,_l##t=size(a);t>=_l##t;t--)
#define rep(t,...)CAT(REP,VASIZE(__VA_ARGS__,(t,__VA_ARGS__),(t,0,__VA_ARGS__)))
#define rrep(t,...)CAT(RREP,VASIZE(__VA_ARGS__,(t,__VA_ARGS__),(t,0,__VA_ARGS__)))
#define all(a)begin(a),end(a)

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/
template<class T, class B, class...V>struct Vec {
  typedef Vec<T, V...>A; typedef vector<typename A::t>t; t nvec(B a, V...b) { return t(a, A().nvec(b...)); }
};
template<class T, class B>struct Vec<T, B> { typedef vector<T>t; t nvec(B a) { return t(a); } };
template<class T>tuple<T>Init(T t) { return tuple<T>(t); }
template<class T, class C>struct Vec<T, tuple<C>> { using t = T; T nvec(tuple<C> a) { return get<0>(a); } };
template<class T = int, class...B> typename Vec<T, B...>::t nvec(B...b) { return Vec<T, B...>().nvec(b...); }



void Calc() {

  int n = in;
  auto a = in.Array(n);
  n++;
  a.push_back(0);
  vector<int> p;
  rep(i, n) {
    if (a[i] == 0) p.push_back(i);
  }
  int pre = 0;
  ll ans = 0;
  for (auto& i : p) {
    ll sum = accumulate<int*, ll>(a.data() + pre, a.data() + i, 0);
    ans += sum / 2;
    pre = i;
  }
  cout << (ans) << endl;
}


Measured memory_bytes: 1528
import numpy as np

q = int(input())

for _ in range(q):
    a, b = sorted(list(map(int, input().split(' '))))
    n = int(np.floor(np.sqrt(a * b)))

    cnt = (n - 1) * 2

    if a != b:
        if a == n:
            if n * (n + 1) < a * b:
                cnt += 1
        else:
            cnt += 1
            if n ** 2 == a * b:
                cnt -= 1
            if n * (n + 1) >= a * b:
                cnt -= 1

    print(cnt)

Measured memory_bytes: 21548
#include<iostream>
using namespace std;
int main(){
  long long n,i,a[11111],b[11111],zero=0,count=0;
  cin>>n;
  for(i=0;i<n;i++)
    cin>>a[i];
  for(i=0;i<n;i++)
    cin>>b[i];
  for(i=0;i<n;i++){
    count+=b[i]-a[i];
    count-=max(zero,(b[i]-a[i]+1)/2);
  }
  if(count>=0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int K, N;
  cin >> K >> N;
 
  vector<int> S(N);
  for(int i=0; i<N; i++){
    cin >> S.at(i);
  }
  
  int X = 0;
  for(int j=0; j<(N - 1); j++){
      X = max((S.at(j + 1) - S.at(j)), X);
  }
  
  int Y;
  Y = K - (S.at(N - 1) - S.at(0));
  
  int Z;
  Z = max (X, Y);
  
    cout << K - Z << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define pp pair<ll,ll>
#define maxn 1000005
#define db double
#define mod 1000000007
using namespace std;
void solve()
{	
	ll h1,s1,h2,s2;
	cin >>h1 >> s1 >>h2 >> s2;
	ll i=0;
	while(1)
	{
		if(i%2 == 0)
		{
			h2 = h2-s1;
			if(h2 <= 0)
			{
				cout <<"Yes";
				return;
			}
		}
		else{
			h1 = h1-s2;
			if(h1 <= 0)
			{
				cout << "No";
				return;
			}
		}
		i++;
	}
}	
int main()
{
	ll t=1,i=1;
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
    std::cout.precision(10);
    std::cout.setf( std::ios::fixed, std:: ios::floatfield ); 
	//cin >> t;
	//cin >> n;
	while(i<=t)
	{
		solve();
		i++;
	}
	return 0;
}




Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 


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

i64 H, W; cin >> H >> W;


if (H ==1 || W == 1)
    cout << "1\n";
else 
    cout  << ((H + 1) / 2) * ((W + 1) / 2) + (H/2) * (W/2) << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{

    public static final int FIRST_NUMBER = 0;
    public static final int SECOND_NUMBER = 1;

    public static void main(String[] args) throws NumberFormatException, IOException {

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	// ???????????°
	int vertical = Integer.parseInt(br.readLine());
	// ?¨?????????°
	int horizontal = Integer.parseInt(br.readLine());

	// ?????????????????°??????????????????
	List<int[]> changeRequests = new ArrayList<>();
	for (int i = 0; i < horizontal; i++) {
	    String[] changeRequestStr = br.readLine().split(",");
	    int[] changeRequest = new int[2];
	    changeRequest[FIRST_NUMBER] = Integer.parseInt(changeRequestStr[FIRST_NUMBER]);
	    changeRequest[SECOND_NUMBER] = Integer.parseInt(changeRequestStr[SECOND_NUMBER]);
	    changeRequests.add(changeRequest);
	}

	// ?????\???????????????????´???????????????????????????????
	int[] outputArray = getDrawedArray(changeRequests, vertical, horizontal);

	// ???????????????????????????????????¨?????\???????????????????????????????????????1??????????????????
	for (int i = 1; i < outputArray.length; i++) {
	    System.out.println(outputArray[i]);
	}

    }

    /**
     * ?????? ?????????????´???????????????\??????????????????
     * 
     * @param changeRequests
     * @param vertical
     * @param horizontal
     * @return ?????\?????????
     */
    private static int[] getDrawedArray(List<int[]> changeRequests, int vertical, int horizontal) {
	// ?????\?????????????????????????????????????????????
	// outputArray[0]????????¨?????????
	int[] outputArray = new int[vertical + 1];
	for (int i = 1; i < outputArray.length; i++) {
	    outputArray[i] = i;
	}

	// ?????????????????????????£????????????\????????????
	for (int[] changeRequest : changeRequests) {
	    int mediator = 0;
	    mediator = outputArray[changeRequest[FIRST_NUMBER]];
	    outputArray[changeRequest[FIRST_NUMBER]] = outputArray[changeRequest[SECOND_NUMBER]];
	    outputArray[changeRequest[SECOND_NUMBER]] = mediator;

	}

	return outputArray;

    }

}

Measured memory_bytes: 24188
#include<cstdio>

int main(){
	int a[10];
	int v1,v2,l;
	int t;
	while(1 + scanf("%d,", &t)){
		l = 0;
		for(int i = 0; i < 10; i++){
			l += t;
			a[i] = l;
			scanf("%d,", &t);
		}
		v1 = t;
		scanf("%d", &v2);
		for(int i = 0; i < 10; i++){
			if((v1 + v2) * a[i] < v1 * l && v1 * l <= (v1 + v2) * a[i + 1]){
				printf("%d\n", i + 2);					
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
void read(int &x){
    char ch;bool ok;
    for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
    for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=210;queue<int>q;
int n,id[maxn],k,ans,flag;char a[maxn][maxn];
void clear(){while(!q.empty())q.pop();}
void bfs(int now){
    q.push(now);id[now]=1;k=0;
    while(!q.empty()){
	int x=q.front();q.pop();k=max(k,id[x]);
	for(rg int i=1;i<=n;i++)
	    if(a[x][i]=='1'){
		if(id[i]&&id[i]!=id[x]-1&&id[i]!=id[x]+1)return clear(),void();
		if(!id[i])id[i]=id[x]+1,q.push(i);
	    }
    }
    //    printf("%d %d\n",k,now);
    ans=max(ans,k);
}
int main(){
    read(n);
    for(rg int i=1;i<=n;i++)scanf("%s",a[i]+1);
    for(rg int i=1;i<=n;i++)memset(id,0,sizeof id),flag=0,bfs(i);
    printf("%d\n",!ans?-1:ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	ll n,k;
	cin>>n>>k;
	ll a[n],i,j;
	for(i=0;i<n;i++) cin>>a[i];
	ll dp[n];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(i=2;i<n;i++) {
		dp[i]=INT_MAX;
		for(j=1;j<=k && i-j>=0;j++) {
			dp[i]=min(dp[i],abs(a[i]-a[i-j])+dp[i-j]);
		}
	}
	cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n = sc.nextInt();
        int x[]=new int[n];
        int y[]=new int[n];
        int d[][]= new int[n*n*n][2];
        int c=0;
        for (int i = 0; i < y.length; i++) {
        	x[i]=sc.nextInt();
        	y[i]=sc.nextInt();
        }
        if(n==1) {
            out.println(1);
            out.flush();
            return;
        }
        for (int i = 0; i < y.length; i++) {
			for (int j = i+1; j < y.length; j++) {
				d[c][0]=x[i]-x[j];
				d[c][1]=y[i]-y[j];
				d[c+1][0]=-x[i]+x[j];
				d[1+c][1]=-y[i]+y[j];
				c+=2;
			}
		}
        int ans=Integer.MAX_VALUE;
        for (int i = 0; i < c; i++) {
        	int a=n;
			for (int t = 0; t < x.length; t++) {
				for (int w = 0; w < x.length; w++) {
					if(t==w)continue;
					if(x[t]+d[i][0]==x[w] && y[t]+d[i][1]==y[w])a--;
				}
			}
			
//			db(d[i],a);
			ans=min(ans,a);
		}
        
        out.println(ans);
        out.flush();
    }

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}
//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int l,r,b;
//    long s;
//    P(int b, int l, int r, long s) {
//    	this.b=b;
//    	this.l=l;
//        this.r=r;
//        this.s=-s;
//    }
//
//    public int compareTo(P p){
//        return Long.signum(s-p.s);
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 27988
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//#define ll long long
#define eps 1e-9
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int n, m, ans = 0;
vector<string>g;
int mask[4][2] = { {1,0},{-1,0},{0,-1},{0,1} };

bool inrange(int x, int y) {
    return x >= 0 && y >= 0 && x < n && y < m;
}

void bfs(int sx, int sy) {
    queue<pair<int, int>>q;
    q.push({ sx, sy });
    vector<vector<int>>d(n, vector<int>(m, -1));
    d[sx][sy] = 0;
    while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop();
        for (int i = 0; i < 4; ++i) {
            int nx = x + mask[i][0], ny = y + mask[i][1];
            if (inrange(nx,ny) && g[nx][ny] == '.' && d[nx][ny] == -1)
                d[nx][ny] = d[x][y] + 1, q.push({ nx,ny }), ans = max(ans, d[nx][ny]);
        }
    }
}

int main() {
    speed;
    cin >> n >> m;
    g.resize(n);
    for (int i = 0; i < n; ++i)
        cin >> g[i];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            if (g[i][j] == '.')
                bfs(i, j);
    cout << ans;
}

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

int a[100000];

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

	map<int, int> mp;
	for (int i = 0; i < N; i++)
		mp[a[i]]++;

	int ans = 0;
	for (auto p: mp) {
		int x = p.first;
		int n = p.second;
		if (n < x) ans += n;
		else ans += n - x;
	}

	cout << ans << endl;
}


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

#define ll     long long
#define fr     first
#define sec    second
#define rep(i,n)  for(i=0;i<n;i++)
#define vi     vector <int>
#define vc     vector <char>
#define vl     vector <ll>
#define vb     vector <bool>
#define pb     push_back
#define M      1000000007
#define ios    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open   freopen("input.txt","r",stdin);
#define close  freopen("output.txt","w",stdout);
#define M_PI   3.14159265358979323846
#define pp     pair<int,int>
#define nn 100003
#define MM 1000000000
#define MN 1000000000000000000

int main()
{
    ios;
    ll n,i;
    map <string,ll> m;
    cin>>n;
    string s;
    rep(i,n)
    {
        cin>>s;
        m[s]++;
    }
    if(m.find("AC")==m.end())
        m["AC"]=0;
    if(m.find("WA")==m.end())
        m["WA"]=0;
    if(m.find("TLE")==m.end())
        m["TLE"]=0;
    if(m.find("RE")==m.end())
        m["RE"]=0;
    cout<<"AC x "<<m["AC"]<<"\n";
    cout<<"WA x "<<m["WA"]<<"\n";
    cout<<"TLE x "<<m["TLE"]<<"\n";
    cout<<"RE x "<<m["RE"]<<"\n";
    return 0;
}


Measured memory_bytes: 3668
import sys
input=sys.stdin.readline

def dist(a,b,c,d,P3):
    for p in P3:
        da,ma=divmod(a,p)
        dc,mc=divmod(c,p)
        if da!=dc:
            return abs(a-c)+abs(b-d)
        if da!=1:
            a,c=ma,mc
            continue
        db,mb=divmod(b,p)
        dd,md=divmod(d,p)
        if abs(db-dd)<2:
            a,c=ma,mc
            continue
        return min(ma+mc+2,2*p-(ma+mc))+abs(b-d)
    return abs(a-c)+abs(b-d)

def main():
    q=int(input())
    P3=[pow(3,i) for i in reversed(range(30))]
    for _ in range(q):
        a,b,c,d=map(lambda x: int(x)-1,input().split())
        print(max(dist(a,b,c,d,P3),dist(b,a,d,c,P3)))

if __name__=='__main__':
    main()

Measured memory_bytes: 72792
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  val n   = sc.nextInt
  val raw1 = (n / 1.08).floor.toInt
  val raw2 = (n / 1.08).ceil.toInt

  val res = Seq(raw1, raw2)
    .find{x => (x * 1.08).floor.toInt == n}
    .fold(":(")(_.toString)

  println(res)

}

Measured memory_bytes: 27328
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define ull unsigned long long int
#define ll long long
#define vi vector<int>
#define mii map<int,int>
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define MOD 1e9+7
#define INF 0x3f3f3f3f
using namespace std;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main()
{
int a,b,c,d,e;
cin>>a>>b>>c>>d>>e;
if(a==0)
cout<<1<<endl;
if(b==0)
cout<<2<<endl;
if(c==0)
cout<<3<<endl;
if(d==0)
cout<<4<<endl;if(e==0)
cout<<5<<endl;
}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, K; cin >> N >> K;
	vector<int> A(N+1);
	for (int i = 0; i < N; i++) cin >> A[i+1], A[i+1] += A[i];
	int ans = 0;
	for (int i = 0; i<=N-K; i++) ans = max(ans, A[i+K]-A[i]);
	cout << (ans+K)/2 << '.' << (ans+K)%2*5 << '\n';

	return 0;
}


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

int main(void) {
  int N;
  while (cin >> N, N) {
    vector<int> W(N);
    for (int i = 0; i < N; i++) cin >> W[i];

    int dp[300][300] = {};
    for (int l = 0; l + 1 < N; l++) {
      if (abs(W[l] - W[l+1]) > 1) continue;
      dp[l][l+1] = 2;
    }

    for (int d = 3; d <= N; d++) {
      for (int l = 0; l + d <= N; l++) {
        int r = l + d - 1;
        dp[l][r] = dp[l+1][r-1];
        if (abs(W[l] - W[r]) <= 1 && dp[l+1][r-1] == r - l - 1)
          dp[l][r] += 2;

        for (int m = l + 1; m <= r - 1; m++) {
          dp[l][r] = max(dp[l][r], dp[l][m] + dp[m+1][r]);
        }
      }
    }

    cout << dp[0][N-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3380
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
using namespace std;
const int INF = 1000000000;

int N; vector<int> dp;
void input()
{
    cin >> N;
}

void solve()
{
    dp.assign(100010,INF);
    dp[0] = 0;
    // DP1
    // for (int n = 1; n <= N; ++n){
    //     for (int i = 1; i <= n; i *= 6){
    //         dp[n] = min (dp[n], dp[n-i]+1);
    //     }
    //     for (int i = 1; i <= n; i *= 9){
    //         dp[n] = min (dp[n], dp[n-i]+1);
    //     }
    // }
    // cout << dp[N] << endl;
    
    // DP2
    for (int n = 0; n <= N; ++n){
        for (int i = 1; i + n <= N; i *= 6){
            dp[n+i] = min (dp[n+i], dp[n]+1);
        }
        for (int i = 1; i + n <= N; i *= 9){
            dp[n+i] = min (dp[n+i], dp[n]+1);
        }
    }
    cout << dp[N] << endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "Yes"<<endl
#define no  cout<< "No"<<endl
#define all(v) (v).begin(),(v).end()
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;    
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
signed main()
{   
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    { 
        int n,sum=0;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        cin>>a[i];
        sort(a,a+n);
        for(int i=0;i<n-1;i++)
        {
            sum+=a[i];
        }
        if(sum>a[n-1])
        cout<<"Yes";
        else
        cout<<"No";
    }
    
}
// 🍪 🍪 🍪

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    string s;
    cin >> n >> s;
    map<char, ll> mp;
    for (char c : s) mp[c]++;    
    ll ans = 1;
    for (auto r : mp) ans = (1LL * ans * (r.second + 1)) % MOD;
    ans--; //1文字も選ばない場合は除外する
    cout << ans << endl;
}

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

const int MAXN=(int)1e9;
const int h[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

struct State 
{ 
	int x,y,succ,ct,cn,ce; 
	State(int xx,int yy,int ss,int cct,int ccn,int cce)
	{
		x=xx;y=yy;succ=ss;ct=cct;cn=ccn;ce=cce;
	};
	State(){};
} q[5001000];

int f[33][33][7][7][7],colarr[7],en,n,m,ans,order[7];
char str[33][33],chr[7];
bool inl[33][33][7][7][7];

void freshsta(State &a,int c[7])
{
	a.ct=c[1];
	a.cn=c[3];
	a.ce=c[5];
}

void change(int c[7],int c1,int c2,int c3,int c4)
{
	int tmp;
	tmp=c[c1];
	c[c1]=c[c4];
	c[c4]=c[c3];
	c[c3]=c[c2];
	c[c2]=tmp;
}

void getarr(State a,int c[7])
{
	c[1]=a.ct;
	c[3]=a.cn;
	c[5]=a.ce;
	if (a.ct%2==1) c[2]=a.ct+1;
	else c[2]=a.ct-1;
	if (a.cn%2==1) c[4]=a.cn+1;
	else c[4]=a.cn-1;
	if (a.ce%2==1) c[6]=a.ce+1;
	else c[6]=a.ce-1;
}

State trans(State a,int c)
{
	State ret=a;
	ret.x+=h[c][0];ret.y+=h[c][1];
	getarr(a,colarr);
	if (c==0)
	{
		change(colarr,1,5,2,6);
	}else if (c==1)
	{
		change(colarr,1,4,2,3);
	}else if (c==2)
	{
		change(colarr,1,6,2,5);
	}else
	{
		change(colarr,1,3,2,4);
	}
	freshsta(ret,colarr);
	return ret;
}

void fresh(State sta,int va)
{
	if (sta.x<=0 || sta.x>n || sta.y<=0 || sta.y>m || str[sta.x][sta.y]=='k') return;
	
	if (str[sta.x][sta.y]=='w')
	{
		if (va<f[sta.x][sta.y][sta.succ][sta.ct][sta.cn])
		{
			f[sta.x][sta.y][sta.succ][sta.ct][sta.cn]=va;
			if (!inl[sta.x][sta.y][sta.succ][sta.ct][sta.cn])
			{
				q[++en]=sta;
				inl[sta.x][sta.y][sta.succ][sta.ct][sta.cn]=true;
			}
		}
	} 
	if ((str[sta.x][sta.y]==chr[sta.succ] && order[sta.succ]==sta.ct))
	{
		sta.succ++;
		if (sta.succ==6) { ans=min(va,ans);return; }
		if (va<f[sta.x][sta.y][sta.succ][sta.ct][sta.cn])
		{
			f[sta.x][sta.y][sta.succ][sta.ct][sta.cn]=va;
			if (!inl[sta.x][sta.y][sta.succ][sta.ct][sta.cn])
			{
				q[++en]=sta;
				inl[sta.x][sta.y][sta.succ][sta.ct][sta.cn]=true;
			}
		}
	}
}

int turn(char c)
{
	if (c=='r') return 1;
	if (c=='c') return 2;
	if (c=='g') return 3;
	if (c=='m') return 4;
	if (c=='b') return 5;
	if (c=='y') return 6;
}

int main()
{
	while (scanf("%d%d",&n,&m)!=EOF && (n||m))
	{
		swap(n,m);
		for (int i=1;i<=n;i++) scanf("%s",&str[i][1]);
		scanf("%s",chr);
		for (int i=0;i<6;i++) order[i]=turn(chr[i]);
		en=0;
		memset(f,127,sizeof(f));
		ans=MAXN;
		for (int i=1;i<=n;i++)
		{
			for (int j=1;j<=m;j++)
			{
				if (str[i][j]=='#')
				{
					str[i][j]='w';
					q[++en]=State(i,j,0,1,3,5);
					f[i][j][0][1][3]=0;
					inl[i][j][0][1][3]=true;
				}
			}
		}
		for (int st=1;st<=en;st++)
		{
			int x=q[st].x,y=q[st].y;
			for (int i=0;i<4;i++)
			{
				State tmp=trans(q[st],i);
				fresh(tmp,f[x][y][q[st].succ][q[st].ct][q[st].cn]+1);
			}
			inl[x][y][q[st].succ][q[st].ct][q[st].cn]=false;
		}
		if (ans<MAXN) printf("%d\n",ans);
		else printf("unreachable\n");
	}
	
	return 0;
}

Measured memory_bytes: 5272
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int l, r;
	if(n == 1) {
		l = 0;
		r = 10;
	}
	if(n == 2) {
		l = 10;
		r = 100;
	}
	if(n == 3) {
		l = 100;
		r = 1000;
	}
	vector<int> s;
	vector<int> c;
	s.resize(m);
	c.resize(m);
	for(int i = 0; i < m; ++i) {
		cin >> s[i] >> c[i];
		--s[i];
	}
	for(int i = l; i < r; ++i) {
		vector<int> bit;
		bit.resize(n);
		int t = i;
		for(int j = 0; j < n; ++j) {
			bit[n - j - 1] = t % 10;
			t /= 10;
		}
		bool f = 1;
		for(int j = 0; j < m; ++j) {
			if(bit[s[j]] != c[j]) {
				f = 0;
			}
		}
		if(f == 1) {
			cout << i << '\n';
			return 0;
		}
	}
	cout << -1 << '\n';
	return 0;
}


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

namespace MyProgram{
    public class Program
    {	
        public static void Main(string[] args)
    	{
            string s = Console.ReadLine();
            int a = s.IndexOf('A');
            int b = s.LastIndexOf('Z');
            
            Console.WriteLine(b-a+1);
    	}
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x <= 1) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
ll n,dp[10][10];
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1;i <= n;i++){
		int x = i, a = x % 10;
		while(x >= 10){
			x /= 10;
		}
		int b = x;
		dp[a][b]++;
	}
	ll ans = 0;
	for(int i = 1;i < 10;i++){
		for(int j = 1;j < 10;j++){
			ans += dp[i][j] * dp[j][i];
		}
	}
	cout << ans << endl;
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 256
#include                        <bits/stdc++.h>
#include                        <ext/pb_ds/assoc_container.hpp>
#define lb                      lower_bound
#define ub                      upper_bound
#define pb(x)                   push_back(x)
#define ook(x)                  order_of_key(x)
#define fbo(x)                  find_by_order(x)
#define all(x)                  (x).begin(),(x).end()
#define FOR(i,a,b)              for(int i = a; i<=b; i++)
#define REP(i,a,b)              for(int i = a; i<b;  i++)
#define dbg(a)                  cout<<#a <<" --> "<<(a)<<endl;
#define TT                      int TC;  cin>>TC;  while(TC--)
#define read                    freopen("input.txt","r",stdin)
#define write                   freopen("output.txt","w",stdout)
#define set(x)                  tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>
using                           namespace std;
using                           namespace __gnu_pbds;
typedef                         long long ll;
typedef                         pair<ll,ll> pll;
typedef                         pair<int,int> pii;

const ll P = 7+1e9;

ll bigmod(ll n,ll p,ll m){
    if(p==0)    return 1;
    if(p==1)    return n%m;
    if(p%2==0){
        ll x = bigmod(n,p/2,m);
        return ((x*x)%m);
    }
    else{
        ll y = bigmod(n,p-1,m)%m;
        return ( (n%m)*y )%m;
    }
}

ll ncr(ll n,ll r){
    ll x = 1,y = 1;
    for(ll i = 0; i<r; i++) x = (x*(n-i))%P;
    for(ll i = 1; i<=r; i++) y = (y*i)%P;
    return (x*bigmod(y,P-2,P))%P;
}


main(){
//read;

ll n,a,b;
cin>>n>>a>>b;

ll tot = ((bigmod(2,n,P)%P - 1+P)%P);
tot = ((tot - ncr(n,a))%P + P)%P;
tot = ((tot - ncr(n,b))%P + P)%P;
cout<<tot;


return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int K,A,B;cin>>K>>A>>B;
    if(B/K-(A-1)/K>0)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
}

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

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

    int res=0;
    for(auto& e: a) {
        int i, x;
        tie(i, x)=e;
        res+=x>=i ? x-i : x;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1000000000;
string alp="abcdefghijklmnopqrstuvwxyz";
struct edge{int from, to,cost;};

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<ll>> d(N,vector<ll>(N,INF));
    vector<edge> es(M);
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        es[i]={a,b,c};
        d[a][b]=c;
        d[b][a]=c;
    }
    rep(k,N){
        rep(i,N){
            rep(j,N){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    int ans=0;
    rep(i,M){
        edge e=es[i];
        if (e.cost>d[e.from][e.to]){
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main() {
    set<int> st;
    rep(i,3) {
        int n;
        cin >> n;
        st.insert(n);
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 256