akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair < int , int > pii;
typedef long long LL;
#define mpr make_pair
#define FS first
#define SC second
#define PB push_back
template < typename T > T MAX(T a,T b){return (a>b)?a:b;}
template < typename T > T MIN(T a,T b){return (a<b)?a:b;}
template < typename T > void UMAX(T &a,T b){a=(a>b?a:b);}
template < typename T > void UMIN(T &a,T b){a=(a<b?a:b);}
int readint(){
	char c=getchar();
	int ret=0;
	while(!(c>='0' && c<='9')) c=getchar();
	while(c>='0' && c<='9'){
		ret=ret*10+c-'0';
		c=getchar();
	}
	return ret;
}
void putint(int v){
	if(!v){
		putchar('0');
		return;
	}
	if(v>=10) putint(v/10);
	putchar('0'+(v%10));
}
const int fhp[4]={-2,1,2,-1},fmd[6]={1,2,2,-1,-2,-2};
int n,m;
struct permu{
	vector < int > p;
	void read(){
		p.resize(n);
		int i;
		for(i=0;i<n;++i){
			scanf("%d",&p[i]);
			--p[i];
		}
	}
	void print(){
		int i;
		for(i=0;i<n;++i){
			printf("%d ",p[i]+1);
		}
		printf("\n");
	}
	void init(){
		p.resize(n);
		int i;
		for(i=0;i<n;++i) p[i]=i;
	}
};
permu M(permu A,permu B){
	permu ret;
	ret.init();
	int i;
//	printf("%d %d\n",(int)A.p.size(),(int)B.p.size());
	for(i=0;i<n;++i){
		ret.p[i]=B.p[A.p[i]];
	}
	return ret;
}
permu P(permu A,int T){
	permu R;
	R.init();
	while(T){
		if(T&1) R=M(R,A);
		T>>=1;
		A=M(A,A);
	}
	return R;
}
permu inv(permu A){
	permu ret;
	ret.init();
	int i;
	for(i=0;i<n;++i) ret.p[A.p[i]]=i;
	return ret;
}
permu p,q,ip,iq;
permu eval(int v){
	if(v==1)
		return p;
	else if(v==-1)
		return ip;
	else if(v==2)
		return q;
	else
		return iq;
}
int getsz(int m){
	if(m==1) return 1;
	int id=(m+1)/3;
	return (id-1)*4+1+(m+1)%3;
}
int main(){
	int i,j,k;
	scanf("%d%d",&n,&m);
	p.read();
	q.read();
	ip=inv(p);
	iq=inv(q);
	int S=getsz(m);
//	printf("S=%d\n",S);
	permu ALLP=M(eval(fhp[0]),M(eval(fhp[1]),M(eval(fhp[2]),eval(fhp[3]))));
	permu LLL=P(ALLP,((S&1)?(S/2):(S/2-1))/4),MMM=eval(fmd[(m-1)%6]),RRR;
	int t=((S&1)?(S/2):(S/2-1))%4;
	for(i=0;i<t;++i) LLL=M(LLL,eval(fhp[i]));
	RRR=inv(LLL);
	if(S&1)
		M(M(LLL,MMM),RRR).print();
	else if(m&1)
		M(LLL,M(M(eval(-1),eval(2)),RRR)).print();
	else
		M(LLL,M(M(eval(1),eval(-2)),RRR)).print();
	return 0;
}

Measured memory_bytes: 6532
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 20
#define DIVISOR 1000000007

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int main(void) {
    int n, k;
    get_int2(&n, &k);
    printf("%d\n", n<=k);
    return 0;
}


Measured memory_bytes: 2088
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();

		if(N == 3)
		{
			Console.WriteLine("2 5 63");
			return;
		}

		int[] even = new int[8] { 2, 10, 3, 9, 4, 8, 6, 12 };
		int[] odd = new int[8] { 6, 2, 10, 3, 9, 4, 8, 12 };

		int[] ans = new int[N];
		int[] ptn = (N % 2 == 0) ? even : odd;
		for(int i = 0; i < (N + 7) / 8; i++)
		{
			for(int j = 0; j < 8; j++)
			{
				int pos = i * 8 + j;
				if(pos == N)
					break;

				ans[pos] = i * 12 + ptn[j];
			}
		}

		Console.WriteLine(string.Join(" ", ans.Select(x => x.ToString()).ToArray()));
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 14432
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int A = int.Parse(s[0]);
        int B = int.Parse(s[1]);
        Console.WriteLine((A - 1) * (B - 1));
    }
}


Measured memory_bytes: 11092
import java.util.*;

public class Main {

    static int q;
    static int n;
    static char[] charArr;
    static char[] tArr;
    static char[] dArr;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        q = sc.nextInt();
        charArr = ("?" + sc.next() + "?").toCharArray();

        tArr = new char[q];
        dArr = new char[q];
        for (int i = 0; i < q; i++) {
            tArr[i] = sc.next().charAt(0);
            dArr[i] = sc.next().charAt(0);
        }

        int ans0 = 1;
        int ansN1 = n;

        int right = n + 1;
        int left = 0;

        // 0よう
        while (true) {
            if (right - left <= 1) {
                ans0 = left;
                break;
            }
            int middle = (right + left) / 2;
            if (check0(middle)) {
               left = middle;
            } else {
                right = middle;
            }
        }

        right = n + 1;
        left = 0;
        // n+1よう
        while (true) {
            if (right - left <= 1) {
                ansN1 = right;
                break;
            }
            int middle = (right + left) / 2;
            if (checkN1(middle)) {
                right = middle;
            } else {
                left = middle;
            }
        }


        System.out.println(ansN1 - ans0 - 1);

    }

    static boolean check0(int idx) {
        int currentIdx = idx;
        for (int i = 0; i < q; i++) {
            char t = tArr[i];
            char d = dArr[i];
            if (charArr[currentIdx] == t) {
                if (d == 'R') {
                    currentIdx++;
                } else {
                    currentIdx--;
                }
            }
            if (currentIdx == 0) {
                return true;
            } else if (currentIdx == n + 1){
                return false;
            }
        }
        return false;
    }

    static boolean checkN1(int idx) {
        int currentIdx = idx;
        for (int i = 0; i < q; i++) {
            char t = tArr[i];
            char d = dArr[i];
            if (charArr[currentIdx] == t) {
                if (d == 'R') {
                    currentIdx++;
                } else {
                    currentIdx--;
                }
            }
            if (currentIdx == n + 1) {
                return true;
            } else if (currentIdx == 0){
                return false;
            }
        }
        return false;
    }


}


Measured memory_bytes: 70428
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    ll A,B,N;
    cin >> A >> B >> N;
    ll x = B-1;
    if (N <= B-1) {
        cout << (A*N)/B << endl;
        return;
    }
    ll on = A*(B-1)/B;
    ll tw= ((A*(2*B-1))/B ) - A;
    if (N <2*B-1) {
        cout << max( (A*(B-1))/B ,(A*N/B)-A )<< endl;
        return;
    }
    // 単調増加
    if (tw > on) {
        auto o = N%B;
        auto k = N-1-o;
        cout << max( (A*N/B)-A*(N/B),(A*k/B)-A*(k/B) )<< endl;
        return;
    } else {
        cout << (A*(B-1))/B << endl;
        return;
    }
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3532
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int n,l;
char len[1111];
int r[22];

double dp[22][5555];

double sq(int a){return a*a;}

double solve(int af,int used){
  if(dp[af][used] >= 0) return dp[af][used];

  if(used == (1<<n)-1) return 0;

  double ret = 4444;
  for(int i = 0; i < n; i++){
    if(af == n) r[af] = r[i];
    if( (used & (1<<i)) == 0 ){
      ret = min(ret, solve(i, used | (1<<i)) + sqrt(sq(r[i] + r[af]) - sq(r[i] - r[af])) - r[af] + r[i]);
    }
  }
  return dp[af][used] = ret;
}


int main(void)
{
  while( fgets(len, sizeof(len), stdin) != NULL ){
    n=0;

    vector<char*> d;
    for(int i = 0; len[i] != '\0'; i++){
      if(len[i] == ' '){
	d.push_back(len+i+1);
	n++;
      }
    }
    sscanf(len,"%d",&l);
    for(int i = 0; i < n; i++){
      sscanf(d[i],"%d",&r[i]);
    }

    for(int i = 0; i <= n; i++){
      for(int j = 0; j < 5555; j++){
	dp[i][j] = -1;
      }
    }
    double ret = solve(n,0);
    if(ret > l) puts("NA");
    else puts("OK"); 
  }
}

Measured memory_bytes: 1760
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const int maxn=1e6+10;
#define p 1000000007
int main(){
	fast;
	string s; cin>>s;
	if(s[0]=='R' && s[1]=='R' && s[2]=='R')cout<<3<<'\n';
	else
		if(s[0]=='R' && s[1]=='R' || s[1]=='R' && s[2]=='R')cout<<2<<'\n';
		else
			if(s[0]=='R' || s[1]=='R' || s[2]=='R')cout<<1<<'\n';
			else
				cout<<0<<'\n';
	return 0;
}
//prime func
//subset production
//factorization
//modpow
//modinv ( a^(p-2)=a^(-1) (mod p) )
//sieve
//ncr
//euler totien func (co prime divisiors upto n)
//matrix exponentation
//dsu
//Trees
//Graphs(dfs,bfs,shortes path etc.)
//DP-Recursion

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N (1<<20)
int c[N] = {};
bool p[N] = {1, 1};
vi v;

int main(){
	REP(i, 1000){
		if(p[i]) continue;
		v.EB(i);
		for(int j = i*2; j < 1000; j+=i) p[j] = true;
	}

	int n; scanf("%d", &n);
	int g = 0;
	REP(i, n){
		int a; scanf("%d", &a);
		g = gcd(g, a);
		for(int j : v){
			if(a%j) continue;
			while(a%j == 0) a/=j;
			c[j]++;
		}
		if(a > 1) c[a]++;
	}
	bool ok = true;
	FOR(i, 2, N) if(c[i] > 1) ok = false;
	if(ok) printf("pairwise coprime\n");
	else if(g == 1) printf("setwise coprime\n");
	else printf("not coprime\n");
}


Measured memory_bytes: 7636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l1,l2,r1,r2;
    cin>>l1>>l2>>r1>>r2;
    int w1=l1+l2,w2=r1+r2;
    if(w2<w1)cout<<"Left"<<endl;
    else if(w2==w1)cout<<"Balanced"<<endl;
    else cout<<"Right"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

using lli = long long int;

// constexpr version : N が clang++ : 3e5くらいまでok,  g++ : 2e6くらいまでok
template <int N, long long int mod>
struct CombinationMod{
private:
    using lli = long long int;
public:
    lli Power[N+1], Inverse[N+1], powInverse[N+1];
    constexpr CombinationMod():Power(), Inverse(), powInverse(){
        Power[0] = 1; Inverse[0] = 1; powInverse[0] = 1;
        for(int x = 1; x <= N; ++x) Power[x] = (Power[x-1] * x) % mod;
        powInverse[N] = inverse(Power[N]);
        for(int x = N; x > 0; --x) powInverse[x-1] = (powInverse[x] * x) % mod;
        for(int x = 1; x <= N; ++x) Inverse[x] = (Power[x-1] * powInverse[x]) % mod;
    }
    constexpr void swap(lli &a, lli &b) const {
        a ^= b; b ^= a; a ^= b;
    }
    constexpr lli inverse(lli a) const noexcept{
        lli b = mod, u = 1, v = 0;
        while (b != 0) { 
            lli t = a / b; a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= mod; if (u < 0) u += mod;
        return u;
    }
    // nCkを求める関数 : n < k の入力に注意せよ
    inline lli combination(int n, int k) const noexcept{
        if(n < k) return 0;
        return ((Power[n] * powInverse[k] % mod) * powInverse[n-k]) % mod;
    }
};

constexpr int SizeN = 3e5;
constexpr int mod = 1e9 + 7;
constexpr CombinationMod<SizeN, mod> Cmb;


int main(void){
    int n, m, k; scanf("%d%d%d", &n, &m, &k);
    lli T1 = m; (T1 *= m) %= mod; (T1 *= Cmb.combination(n+1, 3)) %= mod;
    lli T2 = n; (T2 *= n) %= mod; (T2 *= Cmb.combination(m+1, 3)) %= mod;
    lli res = T1 + T2;
    (res *= Cmb.combination(n*m-2, k-2)) %= mod;
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 888
import sys
from string import digits

k = int(sys.stdin.readline().rstrip())

def main():
    r = k
    if r <= 9:
        print(digits[r])
        return
    res = list(digits[1:])
    r -= 9
    while True:
        nex = []
        for n in res:
            o = ord(n[-1])
            for i in range(-1, 2):
                d = chr(o+i)
                if d < '0' or d > '9': continue
                nex.append(n + d)
                r -= 1
                if r == 0:
                    print(nex[-1])
                    return
        res = nex.copy()    

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
string s;
bool ok(int i) {
    return i < 2 || (s[i - 1] != s[i - 2]);
}

bool ok2(int j) {
    return j < 4 || (s[j - 1] != s[j - 3] || s[j - 2] != s[j - 4]);
}

int main() {

    cin >> s;
    s += '*';

    int n = s.length();
    vector <int> f(n), g(n);
    f[0] = 0;
    g[0] = 0;
    for (int i = 1; i < n; i++) {
        if (ok(i)) {
            f[i] = f[i - 1] + 1;
        }
        if (i > 1 && ok2(i)) {
            g[i] = g[i - 2] + 1;
        }
        if (i > 1) {
            g[i] = max(g[i], f[i - 2] + 1);
        }
        f[i] = max(f[i], g[i - 1] + 1);
        //cout << i << " " << f[i] << " " << g[i] << "\n";
    }

    cout << max(g[n - 1], f[n - 1]);

    return 0;
}


Measured memory_bytes: 2180
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =
				new BufferedReader (new InputStreamReader (System.in));
			String str = input.readLine( );

			 for (char c: str.toCharArray()){
			        if(Character.isLowerCase(c)){
			            System.out.print(Character.toUpperCase(c));
			        }else{
			            System.out.print(Character.toLowerCase(c));
			        }
			    }
			     System.out.println();
	}
}

Measured memory_bytes: 25040
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=200000+10;
int a[maxn],sg[maxn],cnt[maxn],b[maxn],c[maxn],p[maxn],q[maxn],h[maxn],go[maxn],nxt[maxn];
bool bz[maxn],pd[maxn];
int i,j,k,l,t,n,m,u,v,tot,top;
bool czy;
void add(int x,int y){
	go[++tot]=y;
	nxt[tot]=h[x];
	h[x]=tot;
}
void dfs(int x){
	int i,l=0,t=h[x];
	while (t){
		dfs(go[t]);
		t=nxt[t];
	}
	t=h[x];
	while (t){
		q[++l]=sg[go[t]];
		t=nxt[t];
	}
	fo(i,1,l) cnt[q[i]]++;
	while (cnt[sg[x]]) sg[x]++;
	fo(i,1,l) cnt[q[i]]=0;
}
int main(){
	scanf("%d",&n);
	fo(i,1,n){
		scanf("%d",&a[i]);
		add(a[i],i);
	}
	j=1;
	while (1){
		bz[j]=1;
		if (bz[a[j]]){
			u=a[j];
			v=j;
			break;
		}
		j=a[j];
	}
	while (1){
		pd[j]=1;
		if (pd[a[j]]) break;
		j=a[j];
	}
	k=j;
	while (1){
		t=h[j];
		top=0;
		while (t){
			if (!pd[go[t]]){
				dfs(go[t]);
				p[++top]=sg[go[t]];
			}
			t=nxt[t];
		}
		fo(i,1,top) cnt[p[i]]++;
		while (cnt[b[j]]) b[j]++;
		c[j]=b[j]+1;
		while (cnt[c[j]]) c[j]++;
		fo(i,1,top) cnt[p[i]]=0;
		if (a[j]==k) break;
		j=a[j];
	}
	sg[u]=b[u];
	j=u;
	while (1){
		if (sg[j]==b[a[j]]) sg[a[j]]=c[a[j]];else sg[a[j]]=b[a[j]];
		if (a[j]==v) break;
		j=a[j];
	}
	if (sg[u]!=sg[v]){
		printf("POSSIBLE\n");
		return 0;
	}
	sg[u]=c[u];
	j=u;
	while (1){
		if (sg[j]==b[a[j]]) sg[a[j]]=c[a[j]];else sg[a[j]]=b[a[j]];
		if (a[j]==v) break;
		j=a[j];
	}
	if (sg[v]!=b[u]) printf("IMPOSSIBLE\n");else printf("POSSIBLE\n");
}

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

int main() {
  int N, cnt = 0, ans_cnt = 0;
  cin >> N;

  for(int i = 1; i <= N; i++) {
    if(i % 2 == 1) {
      for(int j = 1; j <= i; j++) {
        if(i % j == 0) cnt++;
      }
    } else continue;
    if(cnt == 8) ans_cnt++;
    cnt = 0;
  }
  cout << ans_cnt << endl;
}

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

using namespace std;

class UnionFind {
public:
    int N;
    vector<int> data;

//    vector<int> data;
    UnionFind(const int n) {
        N = n;
        data = vector<int>(N+1);
        for (int i = 1; i <= N; i++){
            data[i] = i;
        }
    }

    int root(int x){
        if (data[x] == x){
            return x;
        }
        data[x] = root(data[x]);
        return data[x];
    }

    int unite(int a, int b){
        int a_root = root(a);
        int b_root = root(b);
        data[a_root] = b_root;
    }

    bool is_same(int a, int b){
        return root(a) == root(b);
    }


};


int main() {
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind uf = UnionFind(N);
    vector<int> minus_counter = vector<int>(N+1);
    vector<int> counter = vector<int>(N+1);

    int a, b;
    for (int i = 0; i < M; i++){
        cin >> a >> b;
        uf.unite(a, b);
        minus_counter[a] += 1;
        minus_counter[b] += 1;
    }
    int c, d;
    for (int i = 0; i < K; i++){
        cin >> c >> d;
        if (uf.is_same(c, d)){
            minus_counter[c] += 1;
            minus_counter[d] += 1;
        }
    }
    for (int i = 1; i <= N; i++){
        counter[uf.root(i)] += 1;
    }
    for (int i = 1; i <=N; i++){
        int ans = counter[uf.root(i)] - minus_counter[i] - 1;
        cout << ans;
        if (i != N){
            cout << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 2816
a,b,c,d = map(int, input().split())

def solve(a,b,c,d):
    x,y = c,d
    def gcd(x,y):
        while y != 0:
            z = y
            y = x % y
            x = z
        return x

    gcd = gcd(c,d)
    lcm = (c*d)//gcd

    mult_b = b // c
    mult_b += b // d
    duplicates = b // lcm
    mult_b -= duplicates

    mult_a = (a-1) // c
    mult_a += (a-1) // d
    duplicates_a = (a-1) // lcm
    mult_a -= duplicates_a

    result = b - (a-1) - (mult_b - mult_a)
    print(result)

solve(a,b,c,d)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    
   	ll a, b;
   	ll ans;
   	cin >> a >> b;
   	ans = a * b;
   	cout << ans;

    return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>

int main(void)
{
	double r;   //半径
	double area;   //面積
	double circle;   //円周
	double pi = 3.14159265359;   //円周率

	scanf("%lf", &r);
	area = r*r*pi;
	circle = 2 * pi*r;
	printf("%f %f\n", area, circle);
	return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

// 1 - indexed
template <typename T>
struct BIT
{
   vector<T> bit;

   BIT(int sz) : bit(sz + 1, 0) {}

   // sum of [1, k]
   T sum(int k)
   {
      T res = 0;
      for (int x = k; x > 0; x -= x & -x)
         res += bit[x];
      return res;
   }

   void add(int k, T w)
   {
      for (int x = k; x < bit.size(); x += x & -x)
         bit[x] += w;
   }

   // sum of [x, y)
   T getSum(int x, int y)
   {
      return sum(y - 1) - sum(x - 1);
   }

   // find an index i s.t. a[1] + a[2] + ⋯ + a[x] ≧ w
   T lower_bound(T w)
   {
      if (w <= 0)
         return 0;

      T x = 0;
      int p = 1, N = bit.size();

      while (2 * p <= N)
         p *= 2;

      for (T k = p; k > 0; k /= 2)
      {
         if (x + k <= N && bit[x + k] < w)
         {
            w -= bit[x + k];
            x += k;
         }
      }

      return x + 1;
   }
};

int main()
{
   fast();

   int N, Q;
   cin >> N >> Q;
   vector<int> c(N + 1);
   for (int i = 0; i < N; i++)
   {
      cin >> c[i + 1];
   }

   vector<vector<pair<int, int>>> queries(N + 1, vector<pair<int, int>>());

   for (int i = 0; i < Q; i++)
   {
      int l, r;
      cin >> l >> r;
      queries[l].emplace_back(r, i);
   }

   for (int i = 1; i <= N; i++)
   {
      sort(queries[i].begin(), queries[i].end());
   }

   vector<priority_queue<int, vector<int>, greater<int>>> pos(N + 1);

   for (int i = 1; i <= N; i++)
   {
      pos[c[i]].push(i);
   }

   BIT<int> bit(N + 1);

   for (int i = 1; i <= N; i++)
   {
      if (pos[i].empty())
         continue;
      bit.add(pos[i].top(), 1);
      pos[i].pop();
   }

   vector<int> ans(Q);

   for (int l = 1; l <= N; l++)
   {
      for (auto q : queries[l])
      { // 左端がlのクエリ
         int R = q.first + 1, ind = q.second;
         ans[ind] = bit.getSum(l, R);
      }

      bit.add(l, -1);
      if (pos[c[l]].empty())
         continue;

      int nxt = pos[c[l]].top();
      pos[c[l]].pop();
      bit.add(nxt, 1);
   }

   for (int i = 0; i < Q; i++)
   {
      cout << ans[i] << "\n";
   }
}

Measured memory_bytes: 62584
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

bool check1(string s) {
	int n = s.size();

	if (n < 6 || s[0] != '>' || s[1] != '\'' || s[n - 1] != '~') {
		return false;
	}

	string sub = s.substr(2, n - 3);
	n = sub.size();

	if (!(n % 2) || sub[n / 2] != '#') {
		return false;
	}

	for (int i = 0; i < n / 2; i++) {
		if (sub[i] != '=' || sub[n - i - 1] != '=') {
			return false;
		}
	}

	return true;
}

bool check2(string s) {
	int n = s.size();

	if (n < 6 || s[0] != '>' || s[1] != '^' || s[n - 1] != '~' || s[n - 2] != '~') {
		return false;
	}

	string sub = s.substr(2, n - 4);
	n = sub.size();

	for (int i = 0; i < n / 2; i++) {
		if (sub[i * 2] != 'Q' || sub[i * 2 + 1] != '=') {
			return false;
		}
	}

	return true;
}

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

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;

		if (check1(s)) {
			cout << "A" << endl;
		}else if (check2(s)) {
			cout << "B" << endl;
		}else {
			cout << "NA" << endl;
		}
	}

	return 0;
}

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

signed main() {
	int m;
	cin >> m;
	cout << 48-m << endl;
}


Measured memory_bytes: 3516
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int R0,W0,C,R;

	public boolean check(int x){
		return (R0 + x * R) / C - W0 >= 0;
	}

	public void solve() {
		while(true){
			R0 = nextInt();
			W0 = nextInt();
			C = nextInt();
			R = nextInt();

			if(R0 + W0 + C + R == 0)break;

			int low = -1;
			int high = (int)1e7;

			while(high - low > 1){
				int mid = (high + low) / 2;

				if(check(mid)){
					high = mid;
				}else{
					low = mid;
				}
			}
			out.println(high);
		}
	}

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

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

using namespace std;



int main(){
    int left,right,a,b,c,d;
    cin>>a>>b>>c>>d;
    left=a+b;
    right=c+d;
    if(left==right){
        cout<<"Balanced"<<endl;
    }
    else if(left>right){
        cout<<"Left"<<endl;
    }
    else cout<<"Right"<<endl;
}


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

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<ll, ll> pll;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

//----------------------------------------------------------------------

#define MAX 110000

ll a[MAX];
int main(void) {
  ll mx, mn;
  ld x;
  cin >> k;

  FOR(i, 0, k) {
	cin >> a[i];
  }


  if (a[k - 1] != 2) {
	cout << "-1" << endl;
	return 0;
  }

  mx = 2;
  mn = 2;

  RFOR(i, 0, k) {
	temp = (mx / a[i])*a[i];
	if (!(temp >= mn && temp <= mx)) {
	  cout << "-1" << endl;
	  return 0;
	}
	mx = (mx / a[i])*a[i] + a[i] - 1;
	x = (ld)mn / a[i];
	(x == (ll)x) ? mn = mn : mn = ((mn / a[i]) + 1)*a[i];
  }

  cout << mn << " " << mx << endl;


  return 0;
}

Measured memory_bytes: 1024
n = int(input())
c = input()

red = [i for i, x in enumerate(c) if x == 'R']
white = [i for i, x in enumerate(c) if x == 'W']

if len(white) == 0 or len(red) == 0:
    print(0)
    
else:
    red.sort(reverse=True)
    red_p = 0
    white_p = 0
    
    count = 0
    while(1):
        if white_p >= len(white):
            break
        elif red[red_p] < white[white_p]:
            break
        else:
            red_p += 1
            red.append(white[white_p])
            white_p += 1
            count += 1
            
    print(count)

Measured memory_bytes: 18108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    ll s = accumulate(all(A), 0ll) % MOD;
    ll ss = s * s % MOD;

    rep(i, N)(ss += MOD - A[i] * A[i] % MOD) %= MOD;

    (ss *= modpow(2, MOD - 2, MOD)) %= MOD;
    cout << ss << endl;
}

Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,s=0;
    scanf("%d %d",&n,&m);
    if(n<=1)
        s=s;
    else
        s=s+(n*(n-1)/2);
    if(m<=1)
        s=s;
    else
        s=s+(m*(m-1)/2);
    printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 256
/*
  
                                _oo0oo_
                               088888880
                               88" . "88
                               (| -_- |)
                                0\ = /0
                             ___/'---'\___
                          .' \\\\|     |// '.
                         / \\\\|||  :  |||// \\
                        /_ ||||| -:- |||||-  \\
                        |   | \\\\\\  -  /// ||
                        | \_|  ''\---/''  |_/ |
                        \  .-\__  '-'  __/-.  /
                      ___'. .'  /--.--\  '. .'___
                   ."" '<  '.___\_<|>_/___.' >'  "".
                  | | : '-  \'.;'\ _ /';.'/ - ' : | |
                  \  \ '_.   \_ __\ /__ _/   .-' /  /
              ====='-.____'.___ \_____/___.-'____.-'=====
                                '=---='

            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
             AC  AC  AC  AC  AC  AC  AC  AC  AC  AC  AC  AC
     
*/
#define OJ
#include <bits/stdc++.h>
#define pb push_back
#define _1 first
#define _2 second
#define FOR(i,a,b) for(int i=a;i<(b);i++)
#define FORN(i,b) for(int i=0;i<(b);i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define MAX(a,b)  a>b?a:b
#define MIN(a,b)  a>b?b:a
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;

int main()
{
	#ifndef OJ
	freopen("abc.in","r",stdin);
	freopen("abc.out","w",stdout);
	#endif
  char r,g,b;
  int n;
  cin>>r>>g>>b;
  n=(b-'0')+(g-'0')*10+(r-'0')*100;
  if(n%4==0)  printf("YES");
  else printf("NO");
	#ifndef OJ
	fclose(stdin);
	fclose(stdout);
	#endif
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

int is_prime(int n)
{
    for(int i = 2; i*i <= n; i++)
        if(n%i == 0)
            return false;

    return true;
}

int main()
{
    int length;
    scanf("%d", &length);

    const int MAX = 55555;

    for(int i = 1, sequence_count = 0; 5*i + 1 <= MAX && sequence_count < length; i++)
    {
        int term = 5*i + 1;

        if(is_prime(term))
        {
            printf("%d\n", term);
            sequence_count++;
        }
    }

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;
char clist[] = {'M', 'A', 'R', 'C', 'H'};

int main(){
    int N;
    cin >> N;
    map<char, int> m;
    rep(i, N){
        string str;
        cin >> str;
        rep(j, 5){
            if(str[0] == clist[j]){
                m[clist[j]]++;
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < 3; i++){
        for(int j = i + 1; j < 4; j++){
            for(int k = j + 1; k < 5; k++){
                ans += (ll)m[clist[i]] * (ll)m[clist[j]] * (ll)m[clist[k]];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>

int n, k;
std::vector<int> W;

int get_loadable_count(int P) {
    auto w_it = W.begin();
    for (int i = 0; i < k; i ++) {
        int sum = 0;
        while (sum + *w_it <= P) {
            sum += *w_it;
            w_it++;
            if (w_it == W.end()) {
                return n;
            }
        }
    }
    return w_it - W.begin();
}

int main() {
    std::cin >> n >> k;
    W.resize(n);
    for (int &w : W) {
        std::cin >> w;
    }

    int P_min = 0;
    int P_max = std::accumulate(W.begin(), W.end(), 0);

    while (P_max - P_min > 1) {
        int P_mid = (P_min + P_max) / 2;
        int count = get_loadable_count(P_mid);
        if (count >= n) {
            P_max = P_mid;
        } else {
            P_min = P_mid;
        }
    }
    std::cout << P_max << std::endl;
}



Measured memory_bytes: 3120
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    string s; cin >> s;
    string res;
    rep(i, 0, s.size()) {
      if (s[i] == '0') res += "0";
      if (s[i] == '1') res += "1";
      if (s[i] == 'B' and !res.empty()) res.pop_back();
    }
  
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct kkk{
	long long t;
	long long s;
	long long start;
}a[200005];
int cmp(kkk aa,kkk bb){
/*	if(aa.start==bb.start){
		return aa.s<bb.s;
	}
*/	return aa.s<bb.s;
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].t>>a[i].s;
		a[i].start=a[i].s-a[i].t;
		if(a[i].start<0){
//			cout<<"a[i].start<0";
			cout<<"No";
			return 0;
		}
	}
	sort(a,a+n,cmp);
/*	for(int i=0;i<n;i++){
		cout<<a[i].t<<" "<<a[i].s<<endl;
	}
	cout<<endl;
*/	long long cnt=0;
	long long minn=1000000000000000;
	for(int i=0;i<n;i++){
		cnt+=a[i].t;
		if(minn>a[i].s-cnt){
			minn=a[i].s-cnt;
		}
		if(cnt>a[i].s){
//			cout<<"cnt>a[i].s"<<a[i].s;
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
} 
/*
50
6 2038
29 1383
17 443
24 386
33 1292
35 2051
19 2085
3 1406
32 195
3 651
38 2325
38 229
36 245
36 2319
19 471
45 1191
49 1453
42 455
24 1633
37 1426
3 2050
17 163
23 360
37 911
29 1441
39 292
18 1575
11 204
44 2383
41 1781
3 745
21 501
2 263
22 943
40 408
43 2046
31 2082
20 633
39 1084
44 1141
30 1438
27 1301
12 1953
15 261
8 1061
31 601
7 1029
33 2226
42 271
32 1279
*/

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
	string s;
	cin >> s;
	rep(i, s.size())
	{
		if (i % 2 == 0)
		{
			if (s[i] == 'L')
			{
				printf("No\n");
				return 0;
			}
		}

		if (i % 2 != 0)
		{
			if (s[i] == 'R')
			{
				
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const auto INF = (ll)1e9;  
using  p = pair<int,int>;
using  v = vector<int>;


int main(){
   int n;
   cin >> n;
   auto s = v(n+1,0);
   for (int i = 1; i <= n; i++)
   {
      cin >> s[i];
   }
   sort(s.begin(),s.end());
   auto sum = accumulate(s.begin(),s.end(),0);
   int num =0;
   for(int i=0;i<=n&&(sum-s[i])%10==0;i++){
      num++;
   }
   int ans = sum-s[num];
   cout << (ans%10==0?0:ans);
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
#define S second
#define F first
typedef pair<int,int> Pi;

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }

int main()
{
  int D, N;
  int data[205];
  int A[205], B[205], C[205];
  
  cin >> D >> N;
  Rep(i,D) cin >> data[i];
  Rep(i,N) cin >> A[i] >> B[i] >> C[i];

  int dp[205][205];
  Rep(i,N) {
    if(data[0] >= A[i] && data[0] <= B[i])dp[0][i] = 0;
    else dp[0][i] = -INF;
  }
  fill(dp[1],dp[205],-INF);
  for(int i = 1; i < D; i++) {
    Rep(j,N) {
      if(data[i] < A[j] || data[i] > B[j]) continue;
      Rep(k,N) {
	if(dp[i - 1][k] == -INF)continue;
	chmax(dp[i][j], dp[i - 1][k] + abs(C[j] - C[k]));
      }
    }
  }
  cout << *max_element(dp[D - 1],dp[D - 1] + N) << endl;
  return 0;
}

Measured memory_bytes: 3236
class UnionFind():
    n=1
    par=[0]
    rnk=[0]
    def __init__(self,size):
        self.n=size
        self.par=[i for i in range(self.n)]
        self.rnk=[0 for i in range(self.n)]
    def find(self,vertex1):
        if self.par[vertex1]==vertex1:
            return vertex1
        else:
            self.par[vertex1]=self.find(self.par[vertex1])
            return self.par[vertex1]
    def unite(self,vertex1,vertex2):
        vertex1=self.find(vertex1)
        vertex2=self.find(vertex2)
        if vertex1==vertex2:
            return
        if (self.rnk[vertex1]<self.rnk[vertex2]):
            self.par[vertex1]=vertex2
        else:
            self.par[vertex2]=vertex1
            if(self.rnk[vertex1]==self.rnk[vertex2]):
                self.rnk[vertex1]+=1
    def same(self,vetrex1,vertex2):
        return self.find(vetrex1)==self.find(vertex2)

N,K=map(int,input().split())
P=[int(i)-1 for i in input().split()]
C=[int(i) for i in input().split()]
G=UnionFind(N)
for i in range(N):
    G.unite(i,P[i])
D=dict()
for i in range(N):
    if G.find(i) in D:
        D[G.find(i)]+=1
    else:
        D[G.find(i)]=1

dp=[[0 for j in range(N)] for i in range(N+1)]
for j in range(N):
    dp[0][j]=j
for i in range(N):
    for j in range(N):
        dp[i+1][j]=P[dp[i][j]]
#1 3 4 0 2
#0->1->3->0, 2->4->2
score=[[0 for j in range(N)] for i in range(N)]
for i in range(N):
    for j in range(N):
        score[i][j]=score[i-1][j]+C[dp[i+1][j]]
def maxpoint(j,L):
    if L<=N:
        return max([score[i][j] for i in range(L)])
    else:
        roop=D[G.find(j)]
        cyclepoint=score[roop-1][j]
        if cyclepoint<0:
            return maxpoint(j,roop)
        else:
            if L%roop!=0:
                return maxpoint(j,L%roop)+(L//roop)*cyclepoint
            else:
                return maxpoint(j,roop)+(-1+L//roop)*cyclepoint
ans=[maxpoint(j,K) for j in range(N)]
print(max(ans))


Measured memory_bytes: 500356
H, W = map(int, input().split())
G = [input() for _ in range(H)]
sy, sx, gy, gx = 0, 0, H - 1, W - 1
seen = [[-1] * W for _ in range(H)]

if G[sy][sx] == '#' or G[gy][gx] == '#':
    print(-1)
    exit()

from collections import deque
que = deque()
que.append([sy, sx])
seen[sy][sx] = 0
while que:
    y, x = que.popleft()
    for d in [-1, 0], [1, 0], [0, -1], [0, 1]:
        dy = y + d[0]
        dx = x + d[1]
        if dy < 0 or H <= dy or dx < 0 or W <= dx:
            continue
        if G[dy][dx] == '#':
            continue
        if seen[dy][dx] > -1:
            continue
        que.append([dy, dx])
        seen[dy][dx] = seen[y][x] + 1

count = 0
bunpu = [0] * (H * W + 1)
if seen[gy][gx] == -1:
    print(-1)
    exit()
else:
    all = H * W
    black = 0
    for i in range(H):
        for j in range(W):
            if G[i][j] == '#':
                black += 1
    #start point = 0,0 
    ans = all - black - seen[gy][gx] - 1
print(ans)

Measured memory_bytes: 9240
import scala.io.StdIn._
object Main extends App {

  val n: Int = readInt()
  val p = readLine().split(" ").map(_.toInt).toSeq
  val q = readLine().split(" ").map(_.toInt).toSeq

  def solve() = {
    val permutations = (1 to n).permutations.toList
    (permutations.indexOf(p) - permutations.indexOf(q)).abs
  }


  println(solve())

}


Measured memory_bytes: 40560
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム 
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std; // std 名前空間を使用する
const int MAX=10000000;
bool prime[MAX+1];
void make_prime(){
    for(int i=0;i<=MAX;i++){
        prime[i]=true;
    }
    prime[0]=false;
    prime[1]=false;
    for(int p=2;p<=MAX;p++){
        if(prime[p]){
            for(int n=p+p;n<=MAX;n+=p){
                prime[n]=false;
            }
        }
    }
}
int main(void){
    make_prime();
    while(1){
        int n;
        scanf("%d",&n);
        if(n==0)break;
        for(int i=n;i>=2;i--){
            if(prime[i]&&prime[i-2]&&prime[i-6]&&prime[i-8]){
                printf("%d\n",i);
                break;
            }
        }
    }
}

Measured memory_bytes: 10952
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 2e5 + 20 ;
int h , w , n , ans[N] ;
int x[N] , y[N] ;
map <pii , bool> mark ;

inline bool occ (int x , int y) {
	return mark.count({x , y}) ;
}

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

	cin >> h >> w ;

	cin >> n ;

	for (int i = 0 ; i < n ; i ++) {
		cin >> x[i] >> y[i] ;
		
		mark[{x[i] , y[i]}] = 1 ;
	}

	ans[0] = 0 ;
	for (int i = 1 ; i < w ; i ++) {
		ans[i] = ans[i - 1] + 1 ;

		while (ans[i] < h && occ(ans[i] + 1 , i + 1)) ans[i] ++ ;
	}

	int res = h ;
	for (int i = 0 ; i < n ; i ++) {
		if (ans[y[i] - 1] < x[i] - 1) res = min(res , x[i] - 1) ;	
	}

	cout << res << '\n' ;
}

Measured memory_bytes: 15104
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.Set;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            char c = ' ';
            Set<String> set = new HashSet<>();
            for (int i = 0; i < N; i++) {
                String W = in.next();
                if (c != ' ' && c != W.charAt(0) || set.contains(W)) {
                    out.println("No");
                    return;
                }
                set.add(W);
                c = W.charAt(W.length() - 1);
            }
            out.println("Yes");
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23508
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define int long long
using namespace std;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MAXIN(x) max_element(ALL(x)) - x.begin();
#define MIN(x) *min_element(ALL(x))
#define MININ(x) min_element(ALL(x)) - x.begin();
#define INF 1000000000000
#define MOD 100000070

#define MAXR 100000
#define PI 3.14159265358979323846

using namespace std;

signed main() {
    int a;
    cin >> a;
    cout << a+a*a+a*a*a <<endl ;

    return 0;
}

Measured memory_bytes: 3632
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

	// https://atcoder.jp/contests/abc159/tasks/abc159_d
	public class Main {

		public static void main(String[] args) {
			// TODO 自動生成されたメソッド・スタブ

			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();

			HashMap<String, Long> map = new HashMap<>();
			String[] arrayA = new String[N];
			for (int i = 0; i < N; i++) {
				arrayA[i] = sc.next();
				String str = arrayA[i];
				if (map.containsKey(str)) {
					map.put(str, map.get(str)+1);
				} else {
					map.put(str,1L);
				}
			}
			sc.close();

			long ans1 = 0;
			for (Map.Entry<String, Long> bar : map.entrySet()) {
				Long a = bar.getValue();
				ans1 = ans1 + a*(a-1)/2;
			}

			for(int k=0;k<N;k++) {
				long ans = ans1;
				String number = arrayA[k];
				Long a = map.get(number);
				if(a!=0) {
					ans = ans - a*(a-1)/2 + (a-1)*(a-2)/2;
				}
				System.out.println(ans);
			}
		}
	}


Measured memory_bytes: 93628
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
void Iswap(int *a,int *b){
  int t=*a;
  *a=*b;
  *b=t;
}
void Fswap(double *a,double *b){
  double t=*a;
  *a=*b;
  *b=t;
}
void Lswap(ll *a,ll *b){
  ll t=*a;
  *a=*b;
  *b=t;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;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;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}

int main(void){
  ll n,k;
  scanf("%lld %lld",&n,&k);
  if(n>k){
    n%=k;
  }
  n=min(n,k-n);
  PRL(n);
  return 0;
}

Measured memory_bytes: 1712