akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


struct MaxDeque {
  using T = lint;
  static T op(const T& lhs, const T& rhs) { return max(lhs, rhs); }
  static constexpr T e() { return -1e18; }

  T get() {
    return op(get_l(), get_r());
  }
  void push_front(const T& x) {
    l.emplace_back(x, op(get_l(), x));
  }
  void push_back(const T& x) {
    r.emplace_back(x, op(get_r(), x));
  }
  void pop_front() {
    if (l.empty()) {
      assert(!r.empty());
      int n = r.size(), m = 1 + (n - 1) / 2;
      l.resize(m - 1);
      copy(begin(r) + 1, begin(r) + m, rbegin(l));
      copy(begin(r) + m, end(r), begin(r));
      r.resize(n - m);
      update();
    } else {
      l.pop_back();
    }
  }
  void pop_back() {
    if (r.empty()) {
      assert(!l.empty());
      int n = l.size(), m = 1 + (n - 1) / 2;
      r.resize(m - 1);
      copy(begin(l) + 1, begin(l) + m, rbegin(r));
      copy(begin(l) + m, end(l), begin(l));
      l.resize(n - m);
      update();
    } else {
      r.pop_back();
    }
  }
private:
  V< pair<T, T> > l, r;
  T get_l() {
    return l.empty() ? e() : l.back().second;
  }
  T get_r() {
    return r.empty() ? e() : r.back().second;
  }
  void update() {
    int nl = l.size(), nr = r.size();
    for (int i = 0; i < nl; ++i) {
      l[i].second = op(i > 0 ? l[i - 1].second : e(), l[i].first);
    }
    for (int i = 0; i < nr; ++i) {
      r[i].second = op(i > 0 ? r[i - 1].second : e(), r[i].first);
    }
  }
};

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m, k; cin >> n >> m >> k;
  V<> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  V<lint> dp0(n), dp1(n);
  for (int i = 0; i < n; ++i) {
    dp0[i] = a[i];
  }
  for (int j = 1; j < k; ++j) {
    MaxDeque deq;
    for (int i = 0; i < n; ++i) {
      dp1[i] = deq.get() + (lint) (j + 1) * a[i];
      deq.push_back(dp0[i]);
      if (i >= m) deq.pop_front();
    }
    swap(dp0, dp1);
  }
  cout << *max_element(begin(dp0), end(dp0)) << '\n';
}

Measured memory_bytes: 6472
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N,K = MI()
A = LI()
dp = [True]*(K+1)
for i in range(min(A),K+1):
    ret = True
    for a in A:
        if i-a>=0:
            if dp[i-a]==True:
                ret = False
                break
    dp[i] = ret

if dp[K]:
    print('Second')
else:
    print('First')


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

template<class Abel> struct STLP{//[0,STLP.n)
    vector<Abel> dat,lazy_val;
    vector<bool> lazy;
    long long n;
    Abel unity;

    STLP(long long n_origin, Abel SUM_UNITY){
        unity=SUM_UNITY;
        long long i=0;
        while(n_origin>(1<<i)) i++;
        n = (1<<i);
        dat.resize(2*n -1);
        lazy_val.resize(2*n-1);
        lazy.resize(2*n-1);
        for(i=0; i< 2*n -1; i++){
            dat[i]=1000000000000;
            lazy_val[i]=SUM_UNITY;
            lazy[i]=0;
        }
    }

    void eval(long long k, long long l, long long r){
        if(lazy[k]==1){
            dat[k]=lazy_val[k];
            if(r-l>1){
                lazy[k*2+1]=1;
                lazy[k*2+2]=1;
                lazy_val[k*2+1]=lazy_val[k];
                lazy_val[k*2+2]=lazy_val[k];
            }
            lazy[k]=0;
            lazy_val[k]=unity;
        }
    }

    void update_range(Abel x, long long a, long long b, long long k, long long l, long long r){//[a,b)
        eval(k,l,r);
        if(r<=a||b<=l) return;
        if(a<=l&&r<=b){
            lazy[k]=1;
            lazy_val[k]=x;
            eval(k,l,r);
            return;
        }
        update_range(x,a,b,k*2+1, l, (l+r)/2);
        update_range(x,a,b,k*2+2, (l+r)/2, r);
        dat[k]=min(dat[k*2+1],dat[k*2+2]);
        return;
    }

    Abel min_range(long long a, long long b, long long k, long long l, long long r){//[a,b)
        eval(k,l,r);
        if(r<=a||b<=l) return 1000000000000;
        if(a<=l&&r<=b) return dat[k];
        Abel vl=min_range(a,b,k*2 +1, l, (l+r)/2);
        Abel vr=min_range(a,b,k*2 +2, (l+r)/2, r);
        return min(vl,vr);
    }
};

int main(){
    long long N,Q;
    cin >> N >> Q;
    long long i;
    STLP<long long> STLProw((N-2LL),0LL), STLPcol((N-2LL),0LL);
    long long ans=(N-2)*(N-2);
    long long num, x;
    long long minrow=N-2, mincol=N-2;
    STLProw.update_range(0,0,N-2,0,0,STLProw.n);
    STLPcol.update_range(0,0,N-2,0,0,STLPcol.n);
    for(i=1; i<=Q; i++){
        cin >> num >> x;
        x-=2;
        if(num==1){
            if(x<mincol){
                ans-=minrow;
                STLPcol.update_range(minrow,x,mincol,0,0,STLProw.n);
                mincol=x;
            }else{
                ans-=STLPcol.min_range(x,x+1,0,0,STLPcol.n);
            }
        }else{
            if(x<minrow){
                ans-=mincol;
                STLProw.update_range(mincol,x,minrow,0,0,STLPcol.n);
                minrow=x;
            }else{
                ans-=STLProw.min_range(x,x+1,0,0,STLProw.n);
            }
        }
    }
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 19840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, ans;
  cin >> N;
  ans = N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < N - 1; i++) {
    if (a.at(i) == a.at(i + 1)) {
      ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

//bit全探索改
vector<string> bit_all_search(int n){
  vector<string> use(0);
  queue<string> Q;
  Q.push("");
  while(Q.size()){
    string S = Q.front();
    Q.pop();
    string T = S;
    T += '0';
    if(T.size() == n){
      use.push_back(T);
    }
    else{
      Q.push(T);
    }
    T = S;
    T += '1';
    if(T.size() == n){
      use.push_back(T);
    }
    else{
      Q.push(T);
    }
  }
  return use;
}

int main(){
  int N;
  cin >> N;
  vector<vector<int>> G(N,vector<int>(0));
  map<P,int> M;
  for(int i=0; i<N-1; i++){
    int a, b;
    cin >> a >> b;
    if(a > b){
      swap(a,b);
    }
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
    P add = {a,b};
    M[add] = i;
  }
  
  
  //条件が満たされないのは、M個の制約について、使う辺の集合全てが白であることをMiとすると、
  //M1 || M2 || ... || Mmとなる
  //よってこれに包除原理を用いるとかつの式に変換できる
  
  int m;
  cin >> m;
  
  vector<set<int>> S(m);
  
  for(int i=0; i<m; i++){
    int x, y;
    cin >> x >> y;
    x--; y--;
    vector<int> par(N);
    vector<bool> seen(N,false);
    queue<int> Q;
    Q.push(x);
    seen[x] = true;
    while(Q.size()){
      int x = Q.front();
      Q.pop();
      for(int i=0; i<G[x].size(); i++){
        if(!seen[G[x][i]]){
          seen[G[x][i]] = true;
          par[G[x][i]] = x;
          Q.push(G[x][i]);
        }
        if(G[x][i] == y){
          break;
        }
      }
    }
    while(y != x){
      int x1, y1;
      x1 = par[y];
      y1 = y;
      if(x1 > y1){
        swap(x1,y1);
      }
      P check = {x1,y1};
      int z = M[check];
      S[i].insert(z);
      y = par[y];
    }
  }
  
  /*for(int i=0; i<m; i++){
    for(auto itr = S[i].begin(); itr != S[i].end(); itr++){
      cout << *itr << " ";
    }
    cout << endl;
  }*/
  
  int64_t ans = pow(2,N-1);
  int64_t no = 0;
  
  vector<string> X = bit_all_search(m);
  
  for(int i=0; i<X.size(); i++){
    string T = X[i];
    int cnt = 0;
    set<int> same;
    for(int j=0; j<m; j++){
      if(T[j] == '1'){
        cnt++;
        for(auto itr = S[j].begin(); itr != S[j].end(); itr++){
          same.insert(*itr);
        }
      }
    }
    int SIZE = same.size();
    if(cnt %2 == 1){
      no += pow(2,N-1-SIZE);
    }
    else if(cnt != 0){
      no -= pow(2,N-1-SIZE);
    }  
  }
  cout << ans - no << endl;
}

Measured memory_bytes: 70816
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

template<typename T>
T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll n;
	cin >> n;
	vector<ll> d1(n), d2(n);

	rep(i, 0, n) {
		ll x, y;
		cin >> x >> y;
		d1[i] = x - y;
		d2[i] = x + y;
	}
	sort(d1.begin(), d1.end(), greater<ll>());
	sort(d2.begin(), d2.end(), greater<ll>());

	// これでいけたっけ？？
	cout << max(d1[0] - d1[n - 1], d2[0] - d2[n - 1]) << endl;

	return 0;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)

int main() {
	int N; scanf("%d", &N); double d = 0.0;
	FOR(i, 0, N) {
		double x; char c[5]; scanf("%lf%s", &x, &c);
		if (c[0] == 'J') d += x;
		else d += x * 380000.0;
	}
	printf("%lf\n", d);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <map>

const int maxn=100;

char s[maxn*2+10][maxn],ch[maxn];
int cnt[maxn*2+10],n,m,tot,len;

int main()
{
  scanf("%d",&n);
  while(n--)
    {
      scanf("%s",ch);
      len=strlen(ch);
      int flag=0;
      for(register int i=1; i<=tot; ++i)
        {
          int slen=strlen(s[i]);
          if(slen==len)
            {
              int fl=0;
              for(register int j=0; j<len; ++j)
                {
                  if(s[i][j]!=ch[j])
                    {
                      fl=1;
                      break;
                    }
                }
              if(!fl)
                {
                  flag=i;
                  break;
                }
            }
        }
      if(flag)
        {
          ++cnt[flag];
        }
      else
        {
          cnt[++tot]=1;
          for(register int i=0; i<len; ++i)
            {
              s[tot][i]=ch[i];
            }
        }
    }
  scanf("%d",&m);
  while(m--)
    {
      scanf("%s",ch);
      len=strlen(ch);
      int flag=0;
      for(register int i=1; i<=tot; ++i)
        {
          int slen=strlen(s[i]);
          if(slen==len)
            {
              int fl=0;
              for(register int j=0; j<len; ++j)
                {
                  if(s[i][j]!=ch[j])
                    {
                      fl=1;
                      break;
                    }
                }
              if(!fl)
                {
                  flag=i;
                  break;
                }
            }
        }
      if(flag)
        {
          --cnt[flag];
        }
      else
        {
          cnt[++tot]=-1;
          for(register int i=0; i<len; ++i)
            {
              s[tot][i]=ch[i];
            }
        }
    }
  int maxx=0;
  for(register int i=1; i<=tot; ++i)
    {
      if(cnt[i]>maxx)
        {
          maxx=cnt[i];
        }
    }
  printf("%d\n",maxx);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(x) clog<<#x<<": "<<x<<endl
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define pb push_back
#define mod 1000000007
#define vi vector<int>
#define si set<int>
#define pi pair<int,int>
#define li list<int>
#define fi first
#define in insert
#define se second
#define mkp make_pair
#define fr(i,n) for(i = 0 ; i < n ; i++)
#define  test int t; cin>>t; while(t--)
int main()
{
    ull n,a,b,i;
    cin>>n>>a>>b;

    cout<<(a*(n/(a+b))+min(a,n%(a+b)));
}


Measured memory_bytes: 256
h,w=map(int,input().split())
a=[""]*(h+2)
a[0]="."*(w+2)
a[h+1]="."*(w+2)
flag=0
for i in range(h):
  a[i+1]=input()
  a[i+1]="."+a[i+1]+"."
for i in range(1,h+1):
  for j in range(1,w+1):
    if a[i][j]==".":
      continue
    elif a[i][j]=="#":
      if a[i-1][j]=="." and a[i+1][j]=="." and a[i][j-1]=="." and a[i][j+1]==".": 
        flag+=1
        print("No")
        exit()
      else:
        continue
if flag==0:
  print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = 5e15;
int main(){
    vector<ll> sum(1e3 * (1e3 - 1) / 2);
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for(auto &a : A) cin >> a;
    ll idx = 0;
    for(ll i = 0; i < N; i++){
        for(ll j = i + 1; j < N; j++){
            ll tmp = 0;
            for(ll k = i; k <= j; k++) tmp += A[k];
            sum[idx++] = tmp;
        }
    }
    vector<ll> ansv = move(sum);
    for(ll keta = 60; keta >= 0; keta--){
        vector<ll> ex;
        for(ll i = 0; i < ansv.size(); i++){
            if((1ll << keta) & ansv[i]) ex.push_back(ansv[i]);
        }
        if(ex.size() >= K) ansv = ex;
    }
    ll ans = (1ll << 60) - 1;
    for(auto x : ansv) ans &= x;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5372
import sys
  
lines = sys.stdin.readlines()
n = len(lines)//2

for i in range(n):
    hit = 0
    blow = 0
    cache = {}
    a = list(map(int, lines[i*2].split()))
    b = list(map(int, lines[i*2+1].split()))
    for j in range(len(a)):
        if a[j] == b[j]:
            hit += 1
        else:
            cache[a[j]] = True
    for j in range(len(b)):
        if cache.get(b[j]):
            blow += 1
    print(hit,blow)


Measured memory_bytes: 5596
// 黒をみて隣の白を黒に変える。変えるときに必要な手順数を一つ増やす。

#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  for (int i=0; i<H; i++){
    cin >> A[i];
  }

  queue<tuple<int, int, int>> Q;
  vector<vector<int>> dists(H, vector<int>(W, 1000000));

  for (int h=0; h<H; h++){
    for (int w=0; w<W; w++){
      if (A[h][w] == '#'){
        Q.push(make_tuple(h, w, 0));
        dists[h][w] = 0;
      }
    }
  }

  while(!Q.empty()){
    int h, w, dist;
    tie(h, w, dist) = Q.front();
    Q.pop();
    if (dists[h][w] < dist) continue;
    static const array<int, 4> dh = {1, -1, 0, 0};
    static const array<int, 4> dw = {0, 0, 1, -1};
    for (int i=0; i<4; i++){
      const int nh = h + dh[i];
      const int nw = w + dw[i];
      const int ndist = dist + 1;
      if (nh >= 0 && nh < H && nw >= 0 && nw < W){
        if (chmin(dists[nh][nw], ndist)){
          Q.push(make_tuple(nh, nw, ndist));
        }
      }
    }
  }

  int ans = 0;
  for(int h=0; h<H; h++){
    for(int w=0; w<W; w++){
      chmax(ans, dists[h][w]);
    }
  }

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


Measured memory_bytes: 17296
#include<stdio.h>
#define N 8

int Q[N][N];

int queen(int *r,int *c,int k){
  int i;

  for(i=0;i<k;i++){
    if(r[i]==r[k])
      return 0;
    if(c[i]==c[k])
      return 0;
    if(r[i]+c[i]==r[k]+c[k])
      return 0;
    if(r[i]-c[i]==r[k]-c[k])
      return 0;
  }
  return 1;
}

void print(){
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(Q[j][i]==1)
        printf("Q");
      else
        printf(".");
    }
    printf("\n");
  }
}

int main(){

  int i,j;
  int n,k;
  int r[N],c[N];

  for(i=0;i<N;i++){
    r[i]=0;
    c[i]=0;
    for(j=0;j<N;j++){
      Q[j][i]=0;
    }
  }

 scanf("%d",&n);
  k=n;

  for(i=0;i<n;i++)
    scanf("%d%d",&r[i],&c[i]);

  while(k<N){
    if(c[k]==N-1){
      r[k]++;
      c[k]=0;
    }
    else
      c[k]++;

    if(r[k]>N-1){
      r[k]=0;
      c[k]=0;
      k--;
    }
    else if(queen(r,c,k))
      k++;
  }

  for(i=0;i<N;i++)
    Q[c[i]][r[i]]=1;

  print();

  return 0;
}

Measured memory_bytes: 572
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

ans = []
for i in range(h):
    for j in range(w-1):
        if a[i][j] % 2 == 1:
            a[i][j] -= 1
            a[i][j+1] += 1
            ans.append((i+1, j+1, i+1, j+2))

for i in range(h-1):
    if a[i][w-1] % 2 == 1:
        a[i][w-1] -= 1
        a[i+1][w-1] += 1
        ans.append((i+1,w,i+2,w))

print(len(ans))
for a, b, c, d in ans:
    print(a, b, c, d)


Measured memory_bytes: 27352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		long A = s.nextLong();
		long B = s.nextLong();
		long C = s.nextLong();
		long D = s.nextLong();

		/*
		long count = 0;
		for (long i = A; i <= B; i++) {

			if(i % C ==0) continue;
			if(i % D ==0) continue;
			count++;
		}

		System.out.println(count);
		*/

		//Cの倍数の個数
		long cBai = B/C - (A-1)/C;
		//Dの倍数の個数
		long dBai = B/D - (A-1)/D;
		//CとDの倍数の個数
		long cdBai = B/(lcm(C,D)) - (A-1)/lcm(C,D);
		//全体から引く
		long answer = (B - (A-1) - (cBai + dBai - cdBai));

		System.out.println(answer);

	}

	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
}


Measured memory_bytes: 22996
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            return Array().Select(int.Parse).ToArray();
        }
        public long[] LongArray()
        {
            return Array().Select(long.Parse).ToArray();
        }
    }

    class Program
    {
        private long N, M;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            M = sc.NextInt();
        }

        public void Solve()
        {
            Scan();
            if (M < N)
            {
                var T = N;
                N = M;
                M = T;
            }
            if (N == 1)
            {
                if (M == 1)
                {
                    Console.WriteLine(1);
                    return;
                }
                else
                {
                    Console.WriteLine(M - 2);
                    return;
                }

            }
            else
            {
                Console.WriteLine((N - 2) * (M - 2));
            }
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
typedef long long ll;
using namespace std;

ll ary[100010];
int main(){
	ll N;
	cin>>N;
	ll m;
	for(ll i=0;i<N;i++){
		cin>>m;
		ary[m]++;
	}
	bool fla=true;
	if(!(N&1)){
		for(ll i=1;i<N;i+=2){
			if(ary[i]!=2) fla=false;
		}
	}
	else{
		if(ary[0]!=1) fla=false;
		for(ll i=2;i<N;i+=2){
			if(ary[i]!=2) fla=false;
		}
	}
	ll a=1;
	for(ll i=1;i<=(N/2);i++){
		a=(a*2)%1000000007;
	}
	if(fla) cout<<a<<endl;
	else cout<<0<<endl;
	return 0;
}



Measured memory_bytes: 1024
// In the  name of god
#include <bits/stdc++.h>
#pragma GCC optimze("02")
using namespace std;
using ll=long long;
const ll maxn=2e5+5;
ll n,x,a[maxn];
int main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	cin>>n>>x;
	if(x==1||x==2*n-1)cout<<"No";
	else{
		cout<<"Yes"<<endl;
		for(int i=1;i<2*n;i++)a[i]=i;
		swap(a[n],a[x]);swap(a[x-1],a[n-1]);swap(a[x+1],a[n+1]);
		if(x==n-1)swap(a[n],a[n+1]);
		if(x==n+1)swap(a[n],a[n-1]);
		for(int i=1;i<2*n;i++)cout<<a[i]<<endl;
	}
}


Measured memory_bytes: 3072
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int V, E, C;
struct edge { LL to, cost; };

typedef pair<LL, LL> P;

LL d[100100]; //?????¢
vector<edge> vec[100100];
set<int>st;

void dijkstra() {
	for (int i = 0; i < 100100; i++)d[i] = HLINF;
	priority_queue<P, std::vector<P>, std::greater<P>> pq;
	d[0] = 0;
	pq.push(make_pair(d[0], 0));//cost,to
	while (!pq.empty()) {
		P p = pq.top();
		pq.pop();
		int i = p.second;
		if (d[i] < p.first)continue;
		for (int k = 0; k < vec[i].size(); k++) {
			edge e = vec[i][k];
			if (d[e.to] <= d[i] + e.cost)continue;
			d[e.to] = d[i] + e.cost;
			pq.push(make_pair(d[e.to], e.to));
		}
	}
}

int main() {
	cin >> V >> E >> C;
	LL sumcost = 0;
	int a, b, c;
	for (int i = 0; i < E; i++) {
		cin >> a >> b >> c;
		a--, b--;
		vec[a].push_back(edge{ b,c });
		vec[b].push_back(edge{ a,c });
		sumcost += c;
	}
	dijkstra();
	LL ans = LINF;
	priority_queue<P, vector<P>, greater<P> > pq;
	for (int i = 0; i < V; i++) {
		pq.push(mp(d[i], i));
	}
	while (!pq.empty()) {
		P p = pq.top();
		pq.pop();
		for (auto v : vec[p.second]) {
			if (st.count(v.to)) {
				sumcost -= v.cost;
			}
		}
		ans = min(ans, p.first*C + sumcost);
		st.insert(p.second);
	}
	cout << ans << endl;
}

Measured memory_bytes: 22012
N = int(input())
st = []
for _ in range(N):
    s,t = map(str,input().split())
    st.append((s,int(t)))
X = input()

ans = 0
flag = False
for s,t in st:
    if flag:
        ans += t
    if s == X:
        flag = True

print(ans)

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

#define _debug(fmt, ...) fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__)
#define rep(i, n) for (int i=0; i<(n); i++)
#define Rep(i, n) for (int i=1; i<=(n); i++)
#define range(x) (x).begin(), (x).end()
typedef long long LL;
typedef unsigned long long ULL;

int n;
int a[100005];

int main() {
  cin >> n;
  rep (i, n) cin >> a[i];
  sort(a, a+n);
  int fv = a[n-1];
  cout << fv << ' ';
  int maxv = 0, m2 = 0;
  rep (i, n-1) {
    int mm = min(a[i], fv - a[i]);
    if (mm > m2) {
      m2 = mm;
      maxv = a[i];
    }
  }
  cout << maxv << endl;
  return 0;
}



Measured memory_bytes: 640
//
//  main.cpp
//  partition
//
//  Created by ???????????? on 2017/10/08.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>

using namespace std;

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

int partition(int A[], int p, int r){
    int x = A[r];
    int i = p - 1;
    for(int j = p; j < r; j ++){
        if(A[j] <= x){
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

int main(int argc, const char * argv[]) {
    int n, i;
    scanf("%d", &n);
    int A[n];
    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    int ind = partition(A, 0, n-1);
    for(i = 0; i < n; i++){
        if(i) cout << " ";
        
        if(i == ind){
            cout << "["<<A[i]<<"]";
        }
        else if (i != ind){cout << A[i];}
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3464
# -*- coding: utf-8 -*-
from collections import Counter
N = int(input())
S = []
U = []
X = []
Y = []
for i in range(N):
    s = input()
    S.append(s)
S = Counter(S)
for i in S.most_common():
    X.append(i[0])
    U.append(i[1])
for i in range(U.count(max(U))):
    Y.append(X[i])
Y.sort()
print(*Y, sep = "\n")

Measured memory_bytes: 48084
n = int( input() )
h = list( map( int, input().split() ) )

ret = 0
number_of_move = 0
for i in range( n - 1 ):
  if h[i] >= h[i+1]:
    number_of_move += 1
  else:
    ret = max( number_of_move, ret )
    number_of_move = 0

print( max( number_of_move, ret ) )

Measured memory_bytes: 14252
n,k=map(int,input().split())
w=[0]*n
v=[0]*n
for i in range(n):
    w[i],v[i]=map(int,input().split())
dpv=[0]*(k+1)
dpw=[0]*(k+1)
for j in range(n):
    for i in range(k,-1,-1):
        if i-w[j]>=0:
            if dpv[i-w[j]]+v[j]>dpv[i]:
                dpw[i]=dpw[i-w[j]]+w[j]
                dpv[i]=dpv[i-w[j]]+v[j]
        else:
            break
print(dpv[k])
    

Measured memory_bytes: 42476
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
set<long long> mySet;
void primeFac(long long n){
  long long num = n;
  for(long long i = 2; i <= sqrt(n); i++){
    while(num % i == 0){
      num /= i;
      mySet.insert(i);
    }
  }
  if(num != 1){
    mySet.insert(-1);
  }
}
long long gcd(long long a, long long b){
  return __gcd(a,b);
}

int main(){
  long long a,b;
  cin >> a >> b;
  long long ans = gcd(a,b);
  primeFac(ans);
  cout << mySet.size() + 1 << endl;
}

Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int N, M, Q;
vector<int> a;
vector<int> b;
vector<int> c;
vector<int> d;
vector<int> A;
int64_t answer;

void search(int i, int lastA) {
  if (i == N) {
    // rep(j, N) cout << A[j] << " ";
    // cout << endl;
    int64_t sum = 0;
    rep(j, Q) {
      int tmp = A[b[j] - 1] - A[a[j] - 1];
      if (tmp != c[j]) continue;
      sum += d[j];
    }
    answer = max(answer, sum);
    return;
  }
  // if ((M - lastA) < (N - i)) return;
  for (int j = lastA; j <= M; ++j) {
    A[i] = j;
    search(i + 1, j);
  }
}

int main(void) {
  ios::sync_with_stdio(false);
  cin >> N >> M >> Q;
  A.resize(N);
  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);
  rep(i, Q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; }
  answer = 0;
  search(0, 1);
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <map>
#define ll long long
using namespace std;
int ans;
int num[100010];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%d",&num[i]);
        if(num[i]==i) ans++;
    }
    if(!ans){
        cout<<0<<endl;
        return 0;
    }
    ans=0;
    for(int i=1;i<=n;i++){
        if(num[i]==i){
            ans++;
            swap(num[i],num[i+1]);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;
#define ll long long
//{{{ read()
inline int read(){
	register int x=0,f=1;
	register char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')	f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')	x=x*10+(ch^48),ch=getchar();
	return x*f;
}
//}}}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n=read(),f1=0,f2=0,f3=0;
	int y=n%10;
	if(y==0||y==1||y==6||y==8)	f2=1;
	if(y==2||y==4||y==5||y==7||y==9)	f1=1;
	if(y==3)	f3=1;
	if(f3)	puts("bon");
	else	if(f2)	puts("pon");
	else	puts("hon");
	return 0;
}


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

int main(){
   int N;
   cin >> N;
   vector<long long> a(N);
   int yon=0,kisuu=0;

    for(int i = 0;i < N;i++)
        cin >> a.at(i);
    
    for(int i = 0;i < N;i++){
        if(a.at(i) % 4 == 0)
            yon++;
        else if(a.at(i) % 2 != 0){
            kisuu++;
        }
    }
    if(N % 2 == 0){
        if(yon >= kisuu)
            cout << "Yes" << endl;
        else
            cout <<"No" << endl;
    }else if(N % 2 != 0){
        if((yon + kisuu) == N && (kisuu - yon) == 1)
            cout << "Yes" << endl;
        else if(yon >= kisuu)
            cout << "Yes" << endl;
        else
        {
            cout << "No" << endl;
        }
        
    }
    
    

}

Measured memory_bytes: 1024
def main(n):
    a = list(map(int, input().split()))
    a.sort()
    ans = 10 ** 20
    for i in range(n - 1):
        if ans > a[i + 1] - a[i]:
            ans = a[i + 1] - a[i]
    print(ans)

while 1:
    n = int(input())
    if n == 0:
        break
    main(n)


Measured memory_bytes: 5632
N, K = gets.chomp.split.map(&:to_i)

h = Hash.new { |k, v| k[v] = 0 }
as = gets.chomp.split.map(&:to_i)

as.each do |i|
  h[i] += 1
end
if K >= h.keys.count
  p 0
  exit
end

copy = h.sort_by { |e| e[1] }
i = 0
while K < copy.count
  e = copy.shift
  i += e[1]
end
p i

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

struct P
{
    int x,y;
    bool operator<(const P &a)const{
              return x>a.x;
    }
};

vector<int> v[11];
//bitset<4001000> b;
int a,c,i,b,k,n,d,e,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int o[120];
int l[10];
int j[22];
int dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};


long long x,y,mod=1000000007;
long long z;

P u[550];
stack<int> s;

//set<int> s;
queue<int> q;


//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p[11];
//list<int> l;

string r;
//char r[33];
//deque<int> de;
bool as(int a,int b)
{

    return i>2;
}

int f(int a)
{
    if(a<10) return a;
    return f(a/10)+a%10;
}

int main()
{
    scanf("%d",&a);
    k=987354321;
    for(int t=1;t<a;t++)
        k=min(k,f(t)+f(a-t));
        printf("%d",k);
}









Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <queue>
#define X first
#define Y second
#define mp make_pair
using namespace std;

typedef long long LL;
typedef pair <double, double> Point;
const int N = 5e5 + 50;

Point Q[N];
int n, L, he = 1, ta = 0;

template <typename T> inline void Read(T &x) {
  x = 0; char ch = 0;
  while (!isdigit(ch = getchar()));
  do {x = (x << 1) + (x << 3) + ch - '0';} while (isdigit(ch = getchar()));
}

inline void Desert(double right) {
  while (he < ta && Q[he + 1].X >= right) he ++;
  if (Q[he].X > right) {
    Q[he].Y = Q[he + 1].Y + (Q[he].Y - Q[he + 1].Y) / (Q[he].X - Q[he + 1].X) * (right - Q[he + 1].X);
    Q[he].X = right;
  }
}

inline void Insert(Point P) {
  while (he < ta && (Q[ta].X - P.X) * (Q[ta - 1].Y - P.Y) >= (Q[ta - 1].X - P.X) * (Q[ta].Y - P.Y)) ta --;
  Q[++ ta] = P;
}

inline void Out() {
  cout << endl << "------------------" << endl;
  for (int i = ta; i >= he; i --) {
    printf("%.3lf %.3lf\n", Q[i].X, Q[i].Y);
  }
}

int main() {
  Read(n); Read(L);
  Q[++ ta] = mp(0, 0);
  LL x, y;
  for (int i = 1; i <= n; i ++) {
    Read(y); Read(x);
    y *= x;
    if (i != 1) Desert(Q[he].first - x);
    Insert(mp(Q[ta].X - x, Q[ta].Y - y));
    printf("%.7lf\n", (Q[he].second - Q[ta].second) / L);
  }
  return 0;
}


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

using namespace std;

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    long long arr[n];
    for(long long i = 0; i < n; ++i){
        cin >> arr[i];
    }
    long long ans = 0;
    for(long long i = 0; i < n - 1; ++i){
        ans += min((arr[i + 1] - arr[i]) * a, b);
    }
    cout << ans;
	return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=105;

int n, ans=1e9;
int a[N];

int32_t main()
{
	IOS;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int fin=-100;fin<=100;fin++)
	{
		int cur=0;
		for(int i=1;i<=n;i++)
			cur+=abs(a[i]-fin)*abs(a[i]-fin);
		ans=min(ans, cur);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
// AOJ 1204: Pipeline Scheduling
// 2017.12.4 bal4u@uu

#include <stdio.h>
#include <string.h>

int a[22];
int n, f;

int calc(int s, int k)
{
	int i, t, ans;

	if (k == 10) return n;
	ans = 0x7fffff;
	for (i = 1; i < n; i++) {
		s >>= 1;
		if (s & 1) continue;
		t = calc(s | f, k+1) + i;
		if (t < ans) ans = t;
	}
	return ans;
}


int main()
{
	int i, j;
	char buf[22];

	while (scanf("%d", &n) && n > 0) {
		memset(a, 0, sizeof(a));
		for (i = 0; i < 5; i++) {
			scanf("%s", buf);
			for (j = 0; j < n; j++) {
				if (buf[j] == 'X') a[j] = i;
			}
		}
		f = 0;
		for (i = 1; i < n; i++) for (j = 0; j < i; j++) {
			if (a[i] == a[j]) f |= 1 << (i-j);
		}
		printf("%d\n", calc(f, 1));
	}
	return 0;
}

Measured memory_bytes: 1760
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin>>x;
    if(x==1){
        cout<<0<<'\n';
    }else{
        cout<<1<<'\n';
    }
return 0;


}

//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *   ****      *  ****

//     ****  *   *  *   *   ***   *   *  *****  *   *
//    *     *   *  *   *  *   *  *   *  *      *   *
//    ***  *****  *   *  *****  * * *  ****   *   *
//      *   *    *   *  *   *  * * *  *      *   *
//  ****   *     ***   *   *   * *   *****   ***

//        ********                                 . O .
//      *           *                               . .
//     *            * *       * ********
//    * ***********    *    *  *         *
//    *                 * *      *********
//                      *                 *
//                 *   *
//                   *  *
//                     **
//                   *  **  *
//              *  *    * **
//                *     ** * *
//            *   **   ** * *  * *
//           *    * * * * * *   **
//          **************************






Measured memory_bytes: 3640
x1,y1,x2,y2 = map(int, input().split())

x3=x2-(y2-y1)
x4=x1-(y2-y1)
y3=y2+(x2-x1)
y4=y1+(x2-x1)

print("{} {} {} {}".format(x3, y3, x4, y4))

Measured memory_bytes: 3060
#include <cstring>
#include <iostream>

using namespace std;


long long int lucas(int n)
{
  long long int l[n+2];
  l[0]=2;
  l[1]=1;
  int i;
  for(i=2;i<=n;++i)
       l[i]=l[i-1]+l[i-2];
  
  return l[n];
}

int main()
{
  int n;
  scanf("%d",&n);
  printf("%lld",lucas(n));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   ll x, k, d;
   cin >> x >> k >> d;
   x = (x < 0) ? -x : x;

   ll lcnt = x / d;
   ll ans = 0;
   if (x == 0) {
      ans = (k % 2) ? d : 0;
   } else {
      if (x <= d)
         ans = (k % 2) ? abs(x - d) : x;
      else if (k < lcnt)
         ans = x - k * d;
      else {
         k -= lcnt;
         ans = (k % 2) ? (d - x % d) : x % d;
      }
   }
   cout << ans << endl;
   return 0;
}

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

#define DEBUG 0
 
int buy(long long *money, long long *stock, int stock_price);
int sell(long long *money, long long *stock, int stock_price);



int main() {

    int N;

    cin >> N;

    long long money = 1000;
    long long stock = 0;

    vector <int> A(N);

    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    for(int day = 0; day < N - 1 ; day++){
        if(A.at(day) < A.at(day+1)){
            buy(&money, &stock, A.at(day));
            #if DEBUG
                cout << "buy" << money << stock << day << endl;
            #endif


        }else if (A.at(day) > A.at(day+1)){
            sell(&money, &stock, A.at(day));
            #if DEBUG
                cout << "sell" << money << stock << day << endl;
            #endif

        }
    }

    sell(&money, &stock, A.at(N-1));
    #if DEBUG
        cout << "sell" << money << stock << endl;
    #endif

    cout << money << endl;



    return 0;

 
}

int buy(long long *money, long long *stock, int stock_price){
    *stock += *money / stock_price; 
    *money -= *money / stock_price * stock_price;

    return 0;

}

int sell(long long *money, long long *stock, int stock_price){
    *money += *stock * stock_price;
    *stock = 0; 
 
    return 0;

}




Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,l;
	cin >>n;
	vector<ll> a(n);
	vector<ll> b(n);
	vector<ll> c(n);
	for(int i = 0; i < n; i++) {
		cin >>l;
		a[i] = l;
	}
	for(int i = 0; i < n; i++) {
		cin >>l;
		b[i] = l;
	}
	for(int i = 0; i < n; i++) {
		cin >>l;
		c[i] = l;
	}
	sort(ALL(a));
	sort(ALL(c));
	ll ans = 0;
	ll A,C;
	for(int i = 0; i < n; i++) {
		A = lower_bound(ALL(a),b[i]) - a.begin();
		C = c.end() - upper_bound(ALL(c),b[i]);
		// cout << "A" << A << endl;
		// cout << "C" << C << endl;
		ans += A * C;
	}
	cout << ans << endl;
	return 0;
}

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

const int N(1400+10);

int g[N][N];
int t[N][N];

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

struct AA{
    int h,pos;
};

int gget(int w,int b[]){
    stack<AA> s;
    int mm=0;
    b[w]=0;
    for(int i=0;i<=w;i++){
        AA r;
        r.h=b[i];
        r.pos=i;
        if(s.empty()){
            s.push(r);
        }else{
            if(s.top().h<r.h)
                s.push(r);
            else if(s.top().h>r.h){
                int tt=i;
                while(!s.empty()&&s.top().h>=r.h){
                    AA pre=s.top();s.pop();
                    int area=pre.h*(i-pre.pos);
                    mm=max(mm,area);
                    tt=pre.pos;
                }
                r.pos=tt;
                s.push(r);
            }
        }
    }
    return mm;
}


int main(){
    int h,w;
    cin>>h>>w;

    int i,j;
    f(i,h)f(j,w)
    cin>>g[i][j];

    f(i,h)f(j,w)
    if(g[i][j]==0)
    t[i][j]=(i>0)?t[i-1][j]+1:1;

    int mm=0;
    for(int i=0;i<h;i++)
    mm=max(mm,gget(w,t[i]));
    cout<<mm<<endl;
}





Measured memory_bytes: 16524
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,K; cin>>N>>K;
    ll ans=-INF;
    vector<ll> A(N);
    vector<ll> B(N);
    rep(i,N){
        cin>>A[i];
        B[i]=max(0ll,A[i]);
    }
    //s[3]-s[2]=A[2]
    vector<ll> sA(N+1,0);
    vector<ll> sB(N+1,0);
    rep(i,N){
        sA[i+1]=sA[i]+A[i];
    }
    rep(i,N){
        sB[i+1]=sB[i]+B[i];
    }
    
    rep(i,N-K+1){
        //[i,i+K):A
        //[0,i),[i+K,N):Bで
        chmax(ans,max(0ll,sA[i+K]-sA[i])+sB[N]-sB[i+K]+sB[i]-sB[0]);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 6412
import scala.io.StdIn.{readInt, readLine}

object Main extends App {

  val n = readInt
  val A = readLine.split(" ").map(_.toInt)
  val B = Array.fill[Int](n)(0)
  coutingSort(A, B, A.max)
  println(B.mkString(" "))

  def coutingSort(A: Array[Int], B: Array[Int], k: Int): Unit = {
    val C = Array.fill[Int](k + 1)(0)
    A.map(C(_) += 1)
    List.range(1, k + 1).foreach( i => C(i) += C(i-1) )
    A.reverse.foreach( value => {
      val idx = C(value) - 1
      B(idx) = value
      C(value) -= 1
    })
  }
}



Measured memory_bytes: 480284
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef pair<double,int> PDI;
typedef pair<LL,LL> PLL;
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const LL inf=1e18;
const double pi=acos(-1.0);
const int mod=123456789;
const int N=1e6;
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//template <class T> inline bool scan_d(T &ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-'&&(c<'0'||c>'9')) c=getchar();    sgn=(c=='-')?-1:1;    ret=(c=='-')?0:(c-'0');    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; }
//void ADD(LL &a,LL b) {a=(a+b)%mod;}
map<int,int>p;
int main()
{
//    freopen("3.in", "r", stdin);
//    freopen("WA.txt", "w", stdout);
    int n,m,a;
    cin>>n;
    while(n--){
        cin>>a;
        p[a]++;
    }
    cin>>m;
    while(m--){
        cin>>a;
        if(!p[a]) return 0*puts("NO");
        p[a]--;
    }
    puts("YES");
    return 0;
}
/*
*/


Measured memory_bytes: 9600
fun main(args: Array<String>) {
    val C = Array(5) { readLine()!!.toInt() }
    val sum = C.map { Pair(it, it % 10) }.map {
        if (it.second == 0) {
            it.first
        } else {
            it.first + (10 - it.second)
        }
    }.sum()


    val max = C.map {
        val m = it % 10
        if (m == 0) {
            0
        } else {
            10 - m
        }
    }.max()!!

    println(sum - max)
}

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

const long double pi = acosl(-1);
int n, L, t[3033];
long double sx = 0, sy = 0;
int main() {
  scanf("%d%d", &n, &L);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      long double x = cosl(pi * (t[i] + t[j]) / L);
      long double y = sinl(pi * (t[i] + t[j]) / L);
      sx += x * (n - j + i - 1);
      sy += y * (n - j + i - 1);
      sx -= x * (j - i - 1);
      sy -= y * (j - i - 1);
    }
  }
  sx = sx * 6 / n / (n - 1) / (n - 2);
  sy = sy * 6 / n / (n - 1) / (n - 2);
  printf("%.10lf %.10lf\n", (double) sx, (double) sy);
}


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

using namespace std;
using ll = long long;

const int N = 4001;
int cnt[N][3];

int color(char c) {
    if (c == 'R') {
        return 0;
    } else if (c == 'G') {
        return 1;
    } else {
        return 2;
    }
}

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;

    ll res = 0;
    for (int i = n - 1; i >= 0; --i) {
        int ci = color(s[i]);
        for (int j = i + 1; j < n; ++j) {
            int cj = color(s[j]);
            if (ci == cj) {
                continue;
            }
            for (int ck = 0; ck < 3; ++ck) {
                if (ck == ci || ck == cj) {
                    continue;
                }
                res += cnt[j][ck];
                int k = j + j - i;
                if (k < n && color(s[k]) == ck) {
                    --res;
                }
            }
        }
        for (int ck = 0; ck < 3; ++ck) {
            cnt[i][ck] = cnt[i + 1][ck];
        }
        ++cnt[i][ci];
    }
    cout << res;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);

    solve();
}


Measured memory_bytes: 3672
N = int(input())
c_ac = 0
c_wa = 0
c_tle = 0
c_re = 0

for _ in range(N):
    s = input()
    if s == 'AC':
        c_ac += 1
    elif s == 'WA':
        c_wa += 1
    elif s == 'TLE':
        c_tle += 1
    else:
        c_re += 1
        
print('AC x '+str(c_ac))
print('WA x '+str(c_wa))
print('TLE x '+str(c_tle))
print('RE x '+str(c_re))

Measured memory_bytes: 9176