akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main (){
    int n, x, sum, count ;
    count = 0;
    
    while(1){
        cin >> n >> x;
        if((n == 0) && (x == 0)) break;
        for(int i = 1;i <= (n-2);i++){
            for(int j = i+1 ; j <= (n-1);j++){
                for(int k = j+1 ;k <= n;k++){
                    sum = i + j + k;
                    if(sum == x) count++;
                }
            }
        }
        cout << count << endl;
        count = 0;
    }
    
    return 0;
}


Measured memory_bytes: 3092
n,m= map(int,input().split())
lr = [0]*m
for i in range(m):
    lr[i]=list(map(int, input().split()))


left = lr[0][0]
right = lr[0][1]
for i in range(1,m):
    if left < lr[i][0]:
        left = lr[i][0]
    if right > lr[i][1]:
        right = lr[i][1]
    
    if left > right:
        break




if left > right:
    print(0)

if left <= right:
    print(right-left+1)
    



Measured memory_bytes: 27348
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
 
#define MOD 1000000007
 
inline int add(int a, int b)
{ return (a + b) % MOD; }
 
inline int sub(int a, int b)
{ return (a - b + MOD) % MOD; }
 
inline int mul(int a, int b)
{ return 1LL * a * b % MOD; }
 
// 虫洞
struct warp
{
    int x1, y1, x2, y2;
 
    bool operator<(const warp &w) const
    {
        if (x1 != w.x1)
            return x1 < w.x1;
        return y1 < w.y1;
    }
};
 
// return d = gcd(a, b) = ax + by
int extgcd(int a, int b, int &x, int &y)
{
    int g = a;
    x = 1;
    y = 0;
    if (b != 0)
        g = extgcd(b, a % b, y, x), y -= a / b * x;
    return g;
}
 
// 求a的逆元
int inv(int a)
{
    int x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x % MOD) % MOD;
}
 
int fact[200010];   // 阶乘n!
void init_factorial()
{
    fact[0] = 1;
    for (int i = 0; i < 200000; ++i)
        fact[i + 1] = mul(fact[i], i + 1);
}
 
// 组合数（从n个序列空位中挑出k个）
inline int nck(int n, int k)
{ return mul(mul(fact[n], inv(fact[n - k])), inv(fact[k])); }
 
 
int N, M, K, dp[100010];
// dp[i] := 到第i个虫洞入口时的方案数
vector<warp> warps;
 
inline int calc(int x1, int y1, int x2, int y2) // 无虫洞模式下s到t的方案数
{
    if (x2 < x1 or y2 < y1)
        return 0;
    return nck(x2 - x1 + y2 - y1, x2 - x1);
}
 
int solve()
{
    memset(dp, 0, sizeof(dp));
    sort(begin(warps), end(warps));
    warps.push_back((warp) {N, M, N + 1, M + 1});
    for (int i = 0; i <= K; ++i)
    {
        dp[i] = nck(warps[i].x1 + warps[i].y1, warps[i].y1);
        for (int j = 0; j < i; ++j)
        {
            dp[i] = add(dp[i], mul(dp[j], sub(calc(warps[j].x2, warps[j].y2, warps[i].x1, warps[i].y1),    // j的终点到i的起点（紫色）
                                              calc(warps[j].x1, warps[j].y1, warps[i].x1, warps[i].y1)))); // j的起点到i的起点
        }
    }
    return dp[K];
}
 
bool input()
{
    warps.clear();
    scanf("%d%d%d", &N, &M, &K);
    --N;
    --M;
    int a, b, c, d;
    for (int i = 0; i < K; ++i)
    {
        scanf("%d%d%d%d", &a, &b, &c, &d);
        warps.push_back((warp) {a - 1, b - 1, c - 1, d - 1});
    }
    return N + 1 or M + 1 or K;
}
 
int main()
{
    init_factorial();
    while (input())
        cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 4316
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.conv;

void main() {
	auto ip = readAs!(int[]), N = ip[0], K = ip[1];
	(K * ((K - 1) ^^ (N - 1))).writeln;
}

// ===================================

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (isBasicType!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

int ri() {
	return readAs!int;
}

string rs() {
	return readln.chomp;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(k,i,n) for(int i = (k); i < (int)(n); i++)
#define GCD(a,b) __gcd(a,b)
#define LCM(a,b) a/__gcd(a,b)*b
typedef long long ll;
typedef pair<int,int> Pii;

int n;
vector<vector<int>> e;

int main() {
    cin>>n;
    e.assign(n,vector<int> (0,0));
    rep(i,n){
        string a;cin>>a;
        rep(j,n) if(a[j]=='1') e[i].push_back(j);
    }
    int ans=-1;
    rep(i,n){
        vector<int> ck(n,0);
        ck[i]=1;
        queue<Pii> q;
        q.push(Pii(i,1));
        int ma=-1;
        bool f=false;
        while(!q.empty()){
            Pii p=q.front();
            q.pop();
            for(int x: e[p.first]){
                if(ck[x]!=0&&ck[x]!=p.second+1&&ck[x]!=p.second-1){f=true;break;}
                else if(ck[x]!=0) continue;
                q.push(Pii(x,p.second+1));
                ck[x]=p.second+1;
               // cout<<x<<' '<< ck[x]<<endl;
                ma=max(ma,ck[x]);
            }
            if(f) break;
        }
        if(f) continue;
        ans=max(ma,ans);

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

Measured memory_bytes: 512
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    k = ni()

    que = queue.Queue()

    if k < 11:
        print(k)
        exit(0)

    for i in range(1, 10):
        que.put(i)

    cnt = 9
    flg = True
    while flg:
        tmp = que.get()
        grade1 = tmp % 10

        for i in (-1, 0, 1):
            if -1 < grade1 + i < 10:
                que.put(tmp * 10 + grade1 + i)
                cnt += 1
                if cnt == k:
                    print(tmp * 10 + grade1 + i)
                    exit(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 13792
function Main(input) {
  const lines = input.split('\n');
  // const n = parseInt(lines[0]);
  const nums = lines[1].split(' ').map(s => parseInt(s));
  let temp = nums;
  let count = 0;
  while(canExec(temp)) {
    count++;
    temp = temp.map(n => n / 2);
  }

  console.log(count);
}

function canExec(numArray) {
  return numArray.every(n => n % 2 === 0);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29528
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,ans;
ll gcd (ll a,ll b) {return (b==0?a:gcd(b,a%b));}
int main () {
	scanf("%lld%lld",&a,&b);
	ll d=gcd(a,b);
	ans=1;
	for (ll i=2;i*i<=d;i++) {
		if (d%i==0) {ans++;}
		while (d%i==0) {d/=i;}
	}
	if (d!=1) {ans++;}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using namespace __gnu_pbds;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll n, a, b;
vector<ll> v;

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);
  cin >> n >> a >> b;
  v.resize(n);

  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  ll f = 0;
  for (int i = 1; i < n; i++) {
    f += min((v[i]-v[i-1])*a, b);
  }
  cout << f << endl;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ans := int(1e9)
	for i := 1; i <= n/2; i++ {
		ans = min(ans, sum(i)+sum(n-i))
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func sum(n int) int {
	res := 0
	for n > 0 {
		res += n % 10
		n /= 10
	}
	return res
}


Measured memory_bytes: 512
using System;
class Program
{
	static void Main(string[] args)
	{
        int problemNum = int.Parse(Console.ReadLine());
        string input = Console.ReadLine();
        string[] originRecordStr = input.Split(' ');
        int[] originRecordNum = new int[100];
        
        int originTotal = 0;
        for(int i=0; i<problemNum; i++){
            originRecordNum[i] = int.Parse(originRecordStr[i]);
            originTotal += originRecordNum[i];
        }

        int chemNum = int.Parse(Console.ReadLine());
        for(int i=0; i<chemNum; i++){
            string chemLine = Console.ReadLine();
            string[] chemStr = chemLine.Split(' ');
            int problem = int.Parse(chemStr[0]);
            int afterRecord = int.Parse(chemStr[1]);

            int afterTotal = originTotal;
            afterTotal = afterTotal + afterRecord - originRecordNum[problem - 1];
            Console.WriteLine(afterTotal);
        }
	}
}

Measured memory_bytes: 2776
// Problem : A - Strings
// Contest : AtCoder Beginner Contest 149
// URL : https://atcoder.jp/contests/abc149/tasks/abc149_a
// Memory Limit : 1024.000000MB 
// Time Limit : 2000.000000milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define all(a) a.begin(),a.end()
#define vl vector<ll>


/*#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}*/


//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

using namespace __gnu_pbds;
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> order_set;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w;
string s,s1,s2;
//vvl v;
//vl vis,d;

int main() {
    IOS;
    cin>>s1>>s2;
	cout<<s2+s1;
    return 0;
}


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

using namespace std;

#define Rep(i,a,b)  for (int i=(a);i<(b);i++)
#define rep(i,n)    for (int i=0;i<(n);i++)
#define all(x)      (x).begin(), (x).end()

#define ll long long

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	rep (i, n)
		cin >> a[i];
	sort(all(a));
	cout << a[n-1] - a[0] << endl;
}



Measured memory_bytes: 256
//============================================================================
// Name        : abc144_a.cpp
// Author      : abb
// Version     :
// Copyright   : [My copyright notice]
// Description : https://atcoder.jp/contests/abc144/tasks/abc144_a
//============================================================================
/*
 A - 9x9

 実行時間制限: 2 sec / メモリ制限: 1024 MB

 配点 : 100 点

 問題文
 高橋君は九九を覚えたので、1 以上 9 以下の 2 つの整数の積を計算することができます。それ以外の計算はできません。
 2 つの整数 A, B が与えられます。
 高橋君が A × B を計算できるならその結果を、できないなら代わりに '-1' を出力してください。

 制約

 ・1 <= A <= 20
 ・1 <= B <= 20
 ・入力中のすべての値は整数である。
 */

#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

using ll = long long;
using ull = unsigned long long;

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

/**
 * エントリポイント．
 * @return 0.
 */
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int a, b;
	cin >> a >> b;

	cout << (a <= 9 && b <= 9 ? a * b : -1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b;
  for (int i = 0; i < b - a + 1; i++){
    if((a+i)/10000 == (a+i) % 10 && (a+i)/1000%10 == (a+i)/10%10){
      c++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [list(map(int, input().split())) for _ in range(2)]

if n == 1:
    print(a[0][0] + a[1][0])
    exit()

ans = 0
for i in range(0, n - 1):
    ans = max(ans, sum(a[0][:i]) + a[0][i] + a[1][i] + sum(a[1][i + 1:]))
print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  int dis = e - a;
  if (dis <= k) {
    cout << "Yay!\n";
  } else {
    cout << ":(\n";
  }
}


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

int main() {
	vector<string> w = {"MON", "TUE", "WED", "THU", "FRI", "SAT","SUN"};
	
	string s;
	cin >> s;
	
	if (s == "SUN"){
		cout << 7 << endl;
		return 0;
	}
	
	int pos = 0;
	for(int i = 0; i < w.size(); i++){
		if (w[i] == s){
			pos = i;
		}
	}
	cout << w.size() - pos - 1  << endl;
	return 0;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
if (b-a)%2==0:
  ans=(b-a)//2
  #ans=min(ans,n-a)
  print(ans)
else:
  ans=min(b-1,n-a)
  ans=min(ans,n-(a+b-1)//2)
  ans=min(ans,(a+b-1)//2)
  print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<ll>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

int main(){
    string x ;
    cin>> x ;
   ll n=x.size() ;
   ll sa= 0;
   ll ans= 0;
   rep(i,n){
   if(x[i]=='T') sa++ ;
   else sa-- ;
   chmax(ans,sa) ;
   }
    cout <<ans*2<<endl ;
    return 0;
  }

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int n, m;
	while(cin >> n >> m, n){
		cin >> n;
		vector <int> count(m, 0);
		vector < vector< pair<int,int> > > rec(m);
		int t, p, s;
		for(int i=0;i<n;i++){
			cin >> t >> p >> p >> s;
			p--;
			if(s == 1){
				if(count[p] == 0)
					rec[p].push_back(make_pair(t,t));
				count[p]++;
			} else {
				count[p]--;
				if(count[p] == 0)
					rec[p].back().second = t;
			}
		}
		cin >> n;
		for(int i=0;i<n;i++){
			int ans = 0;
			cin >> s >> t >> p;
			p--;
			for(int j=0;j<rec[p].size();j++){
				ans += max(0, min(t, rec[p][j].second) - max(s, rec[p][j].first));
			}
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 1468
import java.util.Scanner;

public class Main {
public static void main(String[] args) {

  Scanner sc = new Scanner(System.in);

  int tmp,case_num = 1;

  while((tmp = sc.nextInt()) != 0){
   System.out.printf("Case %d: %d\n",case_num++, tmp);
  }
 }
}


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

const long INF = 1L << 60;
const int MOD = 1000000007;

int a[100010];
long dp[100010];
bool ok[100010];

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; i++) {
		scanf("%d", &a[i]);
		ok[a[i]] = true;
	}
	dp[0] = 1;
	for(int i = 0; i <= n; i++) {
		for(int j = i+1; j <= min(n, i+2); j++) {
			if(!ok[j]) dp[j] += dp[i];
			dp[j] %= MOD;
        }
	}
	printf("%ld", dp[n]);
}


Measured memory_bytes: 1536
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

struct Node {
  int64_t value{0};
  bool visited{false};
  vector<int64_t> nexts;
};

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

  int64_t N, Q;
  cin >> N >> Q;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<Node> nodes(N);
  for (int64_t i = 0; i < N - 1; ++i) {
    int64_t a, b;
    cin >> a >> b;
    nodes[a - 1].nexts.emplace_back(b - 1);
    nodes[b - 1].nexts.emplace_back(a - 1);
  }
  for (int64_t i = 0; i < Q; ++i) {
    int64_t p, x;
    cin >> p >> x;
    nodes[p - 1].value += x;
  }

  queue<int64_t> q;
  nodes[0].visited = true;
  q.push(0);
  while (!q.empty()) {
    const int64_t n = q.front();
    q.pop();
    for (const int64_t next : nodes[n].nexts) {
      if (!nodes[next].visited) {
        nodes[next].value += nodes[n].value;
        nodes[next].visited = true;
        q.emplace(next);
      }
    }
  }
  for (int64_t i = 0; i < N; ++i) {
    if (i != 0) {
      cout << " ";
    }
    cout << nodes[i].value;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 20444
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        final int[][] table = new int[2 * k][2 * k];

        for (int i = 0; i < n; i++) {
            int x = scanner.nextInt() % (2 * k);
            final int y = scanner.nextInt() % (2 * k);
            final String color = scanner.next();
            if ("B".equals(color)) {
                x = (x + k) % (2 * k);
            }

            table[x][y]++;
        }

        for (int i = 1; i < 2 * k; i++) {
            for (int j = 0; j < 2 * k; j++) {
                table[i][j] += table[i - 1][j];
            }
        }

        for (int i = 0; i < 2 * k; i++) {
            for (int j = 1; j < 2 * k; j++) {
                table[i][j] += table[i][j - 1];
            }
        }

        int max = 0;
        for (int i = 0; i < k; i++) {
            for (int j = 0; j < k; j++) {
                int sum;
                if (i == 0 & j == 0) {
                    sum = table[k - 1][k - 1]
                            + table[2 * k - 1][2 * k - 1] - (table[2 * k - 1][k - 1] + table[k - 1][2 * k - 1] - table[k - 1][k - 1]);
                } else if (i == 0) {
                    sum = table[k - 1][j + k - 1] - table[k - 1][j - 1]
                            + table[2 * k - 1][j - 1] - table[k - 1][j - 1]
                            + table[2 * k - 1][2 * k - 1] - (table[2 * k - 1][j + k - 1] + table[k - 1][2 * k - 1] - table[k - 1][j + k - 1]);
                } else if (j == 0) {
                    sum = table[i + k - 1][k - 1] - table[i - 1][k - 1]
                            + table[i - 1][2 * k - 1] - table[i - 1][k - 1]
                            + table[2 * k - 1][2 * k - 1] - (table[i + k - 1][2 * k - 1] + table[2 * k - 1][k - 1] - table[i + k - 1][k - 1]);
                } else {
                    sum = table[i + k - 1][j + k - 1] - (table[i + k - 1][j - 1] + table[i - 1][j + k - 1] - table[i - 1][j - 1]) // center
                            + table[2 * k - 1][j - 1] - table[i + k - 1][j - 1] //left top
                            + table[i - 1][j - 1] // left bottom
                            + table[2 * k - 1][2 * k - 1] - (table[2 * k - 1][j + k - 1] + table[i + k - 1][2 * k - 1] - table[i + k - 1][j + k - 1]) // right top
                            + table[i - 1][2 * k - 1] - table[i - 1][j + k - 1]; // right down
                }
                max = Math.max(max, Math.max(sum, n - sum));
            }
        }

        System.out.println(max);
    }

}


Measured memory_bytes: 106460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    int a;
    cin >> a;
    n %= 500;
    string ans = "Yes";
    if (n>a) ans = "No";
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF (ll)1e18
int main(){
	ll n;
	cin>>n;
	ll ans = INF,temp;
	for(ll
	 i=1;i*i<=n;i++){
		temp = n % i;
		if(temp == 0){
			temp = n/i;
			ll temp_ans = (i - 1)+ (temp -1);
			ans = min(ans,temp_ans);
		}
	}
	cout<<ans;
	
	return 0;
}

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

long long h, w, n;
map<long long, long long> mp;
long long dx[9] = {0, -1, -2, 0, -1, -2, 0, -1, -2};
long long dy[9] = {0, 0, 0, -1, -1, -1, -2, -2, -2};
long long ans[10];
long long GetNo(long long x, long long y)
{
    if(x < 1 || y < 1)
        return -1;
    if(x > h - 2 || y > w - 2)
        return -1;
    return (x - 1) * (w - 2) + y;
}
void Add(long long x, long long y)
{
    for(long long i = 0;i < 9;++i)
    {
        long long nx = x + dx[i];
        long long ny = y + dy[i];
        long long res = GetNo(nx, ny);
        if(res != -1)
            ++mp[res];
    }
}
int main()
{
    scanf("%lld%lld%lld", &h, &w, &n);
    for(long long i = 1;i <= n;++i)
    {
        long long x, y;
        scanf("%lld%lld", &x, &y);
        Add(x, y);
    }
    memset(ans, 0, sizeof(ans));
    ans[0] = GetNo(h - 2, w - 2);
    for(auto it = mp.begin();it != mp.end();++it)
    {
        long long cnt = it->second;
        ++ans[cnt];
        --ans[0];
    }
    for(long long i = 0;i < 10;++i)
        printf("%lld\n", ans[i]);
    return 0;
}
/*
4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4
*/


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

using namespace std;
const int inf = (int) 1e9;
const int maxn = (int)1e5 + 5;
int a[maxn];
int dp[maxn];

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; ++i){
		scanf("%d", &a[i]);
		dp[i] = inf;
	}
	dp[0] = 0;
	for(int i = 0; i < n; ++i){
		for(int j = i + 1; j <= i + k; ++j){
			if(j < n){
				dp[j] = min(dp[j], dp[i] + abs(a[j] - a[i]));
			}
		}
	}
	printf("%d\n", dp[n - 1]);
	return 0;
}

Measured memory_bytes: 4472
#![allow(non_snake_case)]
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;

#[fastout]
fn main() {
    input!{
        a: usize,
        b: f64,
        n: usize,
    }
    let min = std::cmp::min((b-1.0) as usize, n);
    let ans = ((a * min) as f64 / b) as usize - a * (min as f64 / b) as usize;


    println!("{}", ans);
}


Measured memory_bytes: 2140
n, m = map(int, input().split())
mod = 10 ** 9 + 7
n, m = max(n, m), min(n, m)
if n - m > 1:
  print(0)
  quit()
res = 1
for i in range(1, m + 1):
  res *= i
  res %= mod
if n - m:
  res *= res * n
else:
  res *= res * 2
print(res % mod)

Measured memory_bytes: 3064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        mut v: [usize; n]
    }
    v.sort();
    println!("{}", v[n / 2] - v[n / 2 - 1]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
inline int read(){
    int x=0,f=1;char ch=getchar();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    return x*f;
}
int a[100005];
int main(){
	int n;
	n=read();
	for(int i=0;i<n;i++){
		a[i]=read();
	}
	int cnt=0;
	for(int i=0;i<n-1;i++){
		if(a[i]<a[i+1]){
			cnt=0;
			continue;
		}
		if(a[i]-a[i+1]>=2){
			cout<<"No"<<endl;
			return 0;
		}
		if(a[i]-a[i+1]==1){
			cnt++;
		}
		if(cnt>1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.math.BigInteger;
import java.util.*;




public class Main {
	

	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception addd) {
					addd.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception addd) {
				addd.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	
	public static FastReader sc = new FastReader();
 
	static int mod = (int) (1e9+7),MAX=(int) (2e5);
    static List<Integer>[] edges;
    static long[][] dp;
    static int[] w,v;
	public static void main(String[] args){
	
		 int n = sc.nextInt();
		 long W = sc.nextLong();
		 w = new int[n+1];
		 v = new int[n+1];
		 int totalv = 0;
		 for(int i=0;i<n;++i) {
			 w[i+1] = sc.nextInt();
			 v[i+1] = sc.nextInt();
			 totalv+=v[i+1];
		 }
		 
		 dp = new long[n+1][totalv+1];
		 
		 for(int i=0;i<dp.length;++i) Arrays.fill(dp[i],-1);
		 
		 int ans = 0;
		 for(int vi = 1;vi<=totalv;++vi) {
			 if(f(n,vi) <= W) {
				 ans = vi;
			 }
		 }
		 
		 out.println(ans);
      out.close();
	}
	private static long f(int i, int j) {
		if(i == 0) {
			if(j == 0) return 0;
			else return Integer.MAX_VALUE;
		}
		
		if(dp[i][j] != -1) return dp[i][j];
		long o1 = Integer.MAX_VALUE;
		long o2 = o1;
		if(j-v[i] >= 0) o1 = w[i] + f(i-1,j-v[i]);
		o2 = f(i-1,j);
		return dp[i][j] = Math.min(o1,o2);
	}
	
	
}


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

static const int MAX = 1400;

int h, m;

int c[MAX + 1][MAX + 1];

int dp[MAX + 1][MAX + 1];

void histmake(){
    for (int i = 1; i <= h; i++){
        for (int j = 1; j <= m; j++){
            if (c[i][j] == 1) dp[i][j] = 0;
            else dp[i][j] = dp[i - 1][j] + 1;
        }
    }
    return;
}

void solve(){
    int ans = 0;
    stack<pair<int, int> > s;

    int pos;
    for (int i = 1; i <= h; i++){
        for (int j = 1; j <= m; j++){
            if (dp[i][j] == 0){
                while (!s.empty()){
                    ans = max(ans, s.top().first * (j - s.top().second));
                    s.pop();
                }
            }
            else if (s.empty()) s.push(make_pair(dp[i][j], j));
            else if (s.top().first < dp[i][j]) s.push(make_pair(dp[i][j], j));
            else if (s.top().first == dp[i][j]) continue;
            else{
                while ((!s.empty()) && s.top().first > dp[i][j]){
                    ans = max(ans, s.top().first * (j - s.top().second));
                    pos = s.top().second;
                    s.pop();
                }
                s.push(make_pair(dp[i][j], pos));
            }
        }
        while (!s.empty()){
            ans = max(ans, s.top().first * (m - s.top().second + 1));
            s.pop();
        }
    }

    cout << ans << endl;

    return;
}

int main(){
    cin >> h >> m;

    for (int i = 1; i <= h; i++){
        for (int j = 1; j <= m; j++){
            scanf("%d", &c[i][j]);
        }
    }

    histmake();
    solve();

    return 0;
}




Measured memory_bytes: 18552
#include <iostream>
#include <cstdio>

using namespace std;

int bsort(int a[],int n){
  int count=0;
  for(int i=n-1;0<i;--i)
    for(int j=0;j<i;++j)
      if(a[j+1]<a[j]){
	swap(a[j+1],a[j]);
	count++;
      }
  return count;
}

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

  for(int i=0;i<n-1;++i)
    cout << a[i] << " ";
  cout << a[n-1] << endl;
  cout << x << endl;

}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
struct node{
	int to,next,v;
}a[100007];
int head[100007],cnt,dis[100007],vis[100007],f[100007];
queue<int>q;
char s[1007];
void add(int x,int y,int v){
	a[++cnt].next=head[x];
	a[cnt].to=y;
	a[cnt].v=v;
	head[x]=cnt;
}
void dfs(int x,int c){
	vis[x]=c;
	for(int i=head[x];i;i=a[i].next){
		int v=a[i].to;
		if(vis[v]==-1)
            dfs(v,c^1);
		else if(vis[v]!=(c^1)){
            cout<<-1;
            exit(0);
		}
	}
}
void spfa(int s){
	q.push(s);
	memset(dis,1,sizeof(dis));
	f[s]=1,dis[s]=0;
	while(!q.empty()){
		int now=q.front();
		q.pop();
		f[now]=0;
		for(int i=head[now];i;i=a[i].next){
			int v=a[i].to;
			if(dis[v]>dis[now]+a[i].v){
				dis[v]=dis[now]+a[i].v;
				if(!f[v]){
                    q.push(v);
                    f[v]=1;
				}
			}
		}
	}
}
int main(){
	int n=0,mx=0,x;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>s+1;
		for(int j=1;j<=n;++j){
			x=s[j]-'0';
			if(x==1)
                add(i,j,1);
		}
		vis[i]=-1;
	}
	dfs(1,0);
	for(int j=1;j<=n;++j){
		spfa(j);
		for(int i=1;i<=n;++i)
			mx=max(mx,dis[i]);
	}
	cout<<mx+1;
}

Measured memory_bytes: 896
#include <string>
#include <iostream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

const double EPS = 1e-9;


int main(){
	string s;

	int sum = 0;
	while(getline(cin, s)){
		for(int i = 0; i < s.size(); i++){
			int n = 0;
			while(s[i+n] >= '0' && s[i+n] <= '9'){
				n++;
			}
			sum+= atoi(s.substr(i, n).c_str());
			i += n;
		}
	}

	cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1200
Data = []
def yoko(a,b):
    x1 = Data[a][0]-Data[b][0]
    x2 = Data[a][1]-Data[b][1]
    x3 = Data[a][2]-Data[b][2]
    if x1 == x2 and x2 == x3:
        return 1
    else:
        return 0

def tate(a,b):
    x1 = Data[0][a]-Data[0][b]
    x2 = Data[1][a]-Data[1][b]
    x3 = Data[2][a]-Data[2][b]
    if x1 == x2 and x2 == x3:
        return 1 
    else:
        return 0 

for i in range(3):
    data = list(map(int,input().split()))
    Data.append(data)

ans = 1
ans &= yoko(0,1)
ans &= yoko(1,2)
ans &= yoko(2,1)

ans &= tate(0,1)
ans &= tate(1,2)
ans &= tate(2,1)
if ans == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  ll n;
  cin >> n;

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (n-1) / i;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3600
#include "bits/stdc++.h"
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 1000000007;

struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		//assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
}; 
signed main() {
	combination com(2010);
	int n; cin >> n;
	mint ans = mint(10).pow(n) - (mint(9).pow(n)* 2 - mint(8).pow(n));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<string>
using namespace std;
int main(){
	int dp[15][15];
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>dp[i][j];
	int x=0;
	for(int i=0;i<n;i++){
		int h=0;
		for(int j=0;j<n;j++)
			h+=dp[i][j];
		dp[i][n]=h;
		x+=h;
	}
	for(int i=0;i<n;i++){
		int h=0;
		for(int j=0;j<n;j++)
			h+=dp[j][i];
		dp[n][i]=h;
	}
	dp[n][n]=x;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			int k=1,h=10;
			while(true){
				if(dp[i][j]<h)
					break;
				h*=10;
				k++;
			}
			for(int l=0;l<5-k;l++)
				cout<<" ";
			cout<<dp[i][j];
		}
		cout<<endl;
	}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int H, W;
    cin >> H >> W;
    
    vector<vector<int>> A(H, vector<int> (W));
    vector<vector<int>> c(10, vector<int> (10));
    REP(i, 10) REP(j, 10) cin >> c[i][j];
    REP(i, H) REP(j, W) cin >> A[i][j];

    REP(k, 10) REP(i, 10) REP(j, 10) {
        c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
    }

    int ans = 0;
    REP(i, H) {
        REP(j, W) {
            if (A[i][j] >= 0) ans += c[A[i][j]][1];
        }
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>


#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

void solve(string& s, char c, int i, int n)
{
	if (i == n) {
		cout << s << endl;
		return;
	}

	FOR_LE(j, 'a', c + 1) {
		s[i] = j;
		solve(s, max(c, (char)j), i + 1, n);
	}

}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	string s;
	s.resize(n);
	s[0] = 'a';

	solve(s, 'a', 1, n);

	return 0;
}

Measured memory_bytes: 1536
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

char cn[120000], * ci = cn + 20, ct, buf[8], * owa = cn + 119980;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	memcpy(buf, ci, 8);
	ll tmp = *(ll*)buf;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3) + 1;

	if (ci - owa > 0) {
		memcpy(cn, owa, 20);
		ci -= 119980;
		fread(cn + 20, 1, 119980, stdin);
	}
	return tmp;
}

char* di = cn;
const int MAX = 200000;
class shuturyoku_unko {
public:
	char C[MAX * 6 + 10];
	int K[MAX + 10];
	constexpr shuturyoku_unko() : C(), K() {
		auto di = C + 1;
		C[0] = '0';
		K[1] = 1;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			K[i + 1] = K[i] + keta;
		}
	}
} f;
inline void putint(ll X) {
	int ue = X / 100000;
	if (ue) {
		for (int i = f.K[ue]; i < f.K[ue + 1]; i++)* di++ = f.C[i];
		int sita = X - ue * 100000ll;
		rep(i, 5 - f.K[sita + 1] + f.K[sita])* di++ = '0';
		for (int i = f.K[sita]; i < f.K[sita + 1]; i++)* di++ = f.C[i];
	}
	else for (int i = f.K[X]; i < f.K[X + 1]; i++)* di++ = f.C[i];
	*di++ = '\n';
}

int A[200000];
int B[200010];

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


	fread(ci, 1, 119980, stdin);

	int N = getint();
	ll kotae = 0;
	rep(i, N) kotae += B[(A[i] = getint())]++;
	int i = 0;
	
	int amari = N % 10000;
	int shou = N / 10000;
	rep(j, shou) {
		rep(k, 10000) putint(kotae - B[A[i++]] + 1);
		fwrite(cn, 1, di - cn, stdout);
		di = cn;
	}
	rep(k, amari) putint(kotae - B[A[i++]] + 1);
	fwrite(cn, 1, di - cn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<stack>

using namespace std;

int  n, M[100][100], d[100], f[100], color[100], tt, nt[100], W = 0, G = 1, B = 2;

int next (int u) {

    int v;
    for (v = nt[u]; v < n; v++) {
        nt[u] = v + 1;
        if (M[u][v] != 0) {
            return v;
        }
    }
    return -1;

}

void dfs_visit (int r) {

    int i, u, v;

    for (i = 0; i < n; i++) {
        nt[i] = 0;
    }

    stack<int> S;
    S.push(r);
    color[r] = G;
    d[r] = ++tt;

    while (!S.empty()) {
        u = S.top();
        v = next (u);
        if (v != -1) {
            if (color[v] == W) {
                color[v] = G;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = B;
            f[u] = ++tt;
        }
    }

}

void dfs () {

    int i, u;

    for (i = 0; i < n; i++) {
        color[i] = W;
        nt[i] = 0;
    }
    tt = 0;

    for (u = 0; u < n; u++) {
        if (color[u] == W) {
            dfs_visit(u);
        }
    }

    for (i = 0; i < n; i++) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }

}

int main () {

    int u, k, v, i, j;

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

    for (i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs ();

    return 0;

}

Measured memory_bytes: 3128
#include <iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<cmath>
#include<iomanip>
using namespace std;

const double PI  =3.141592653589793238463;
#define pb push_back
#define pf push_front
#define sz(v)  ((int)(v).size());
#define all(v) ((v).begin()),((v).end())
typedef unsigned long long ull;
typedef long long ll;

typedef vector<int> vi;
typedef pair<int,int> pi;
//2 7 3 4 9

void printVec(vi v1)
{
    for(int i=0; i<v1.size(); i++)
        cout<<v1[i]<<" ";
    cout<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);


   long long AC=0,WA=0,TLE=0,RE=0;

long long t;cin>>t;
string s;
while(t--){
        cin>>s;
    if(s=="AC"){
        AC++;
    }else if(s=="WA"){
    WA++;
    }else if(s=="TLE"){
    TLE++;
    }else{
    RE++;}
}
cout<<"AC x "<<AC<<endl;
cout<<"WA x "<<WA<<endl;
cout<<"TLE x "<<TLE<<endl;
cout<<"RE x "<<RE<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	scan(N);
	vector<pair<string,int> > v;
	v.push_back({"a",1});
	rep(i,N-1){
		vector<pair<string,int> > vb=v;
		v.clear();
		rep(j,vb.size()){
			int num=vb[j].second;
			rep(k,num+1){
				char next='a'+k;
				if(k==num) v.push_back({vb[j].first+next,num+1});
				else v.push_back({vb[j].first+next,num});
			}
		}
	}
	sort(ALL(v));
	rep(i,v.size()){
		prin(v[i].first);
	}
	return 0;
}


Measured memory_bytes: 10020
import collections
N = int(input())
Ss= [input() for i in range(N)]
M = int(input())
Mm = [input() for i in range(M)]
Scounter = collections.Counter(Ss)
Mcounter = collections.Counter(Mm)
Ansdic = {}
for s,value in Scounter.items():
    if s not in Ansdic:
        Ansdic[s]=value
    else:
        Ansdic[s]+=value
for m,value in Mcounter.items():
    if m not in Ansdic:
        Ansdic[m]=-value
    else:
        Ansdic[m]-=value
print(max(0,max(Ansdic.values())))

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll H,W;
	cin>>H>>W;
    string S[H];
    for(int i=0;i<H;i++){
        cin>>S[i];
    }
    vector<vector<ll>> mp(H+2,vector<ll>(W+2));
    for(int i=0;i<=H+1;i++){
        for(int j=0;j<=W+1;j++){
            if(i==0||j==0||i==H+1||j==W+1){
                mp[i][j]=1;
            }else{
                if(S[i-1][j-1]=='#') mp[i][j]=1;
            }
        }
    }    
    typedef pair<ll,ll> P;
    ll m=0,x,y,dx[]= {1,-1,0,0},dy[] = {0,0,1,-1},ans=0;
    
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(mp[i][j]!=0) continue;
            ll dist[25][25]= {};
            queue<P> qu;
            qu.push(P{i,j});
            dist[i][j]= 1;
            // cout<<i<<j<<"\n";
            while(!qu.empty()){
                tie(x,y)= qu.front();qu.pop();
                for(int k=0;k<4;k++){
                    int nx = x+dx[k],ny = y+dy[k];
                    if(dist[nx][ny]!=0||mp[nx][ny]!=0) continue;
                    dist[nx][ny]= dist[x][y]+1;
                    m = max(m,dist[nx][ny]);
                    qu.push(P{nx,ny});
                }
            }
            ans = max(ans,m-1);
        }
    }
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#define rep(i, a, b) for(lli i = a; i < (b); ++i)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) lli((x).size())
#define wis cout<<endl<<"I already speak english, bitch"<<endl<<endl;
 
typedef long long int lli;
typedef vector<lli> vi;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef pair<ii,lli> iii;
 
#define trace(args...) { string  _s =#args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
    cout <<  *it  << " : " << a << endl;
    err(++it, args...);
}

vector<lli> factors(lli n) {
  vector<lli> f;
  for (lli x = 2; x*x <= n; x++) {
    while (n%x == 0) {
      f.push_back(x);
      n /= x;
    }
  }
  if (n > 1) f.push_back(n);
  return f;
}

int main(){
	lli a,b; cin>>a>>b;
	vi A=factors(a),B=factors(b);
	set<lli> f1,f2;
	for(auto x : A) f1.insert(x);
	for(auto x : B) f2.insert(x);
	int cnt=0;
	for(auto x : f1) if(f2.count(x)) cnt++;
	cout<<cnt+1<<endl;
	return 0;
}

Measured memory_bytes: 3592