akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;

template<int mod> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % mod) {
        if (val < 0) val += mod;
    }
    constexpr int getmod() { return mod; }
    constexpr Fp operator - () const noexcept {
        return val ? mod - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= mod) val -= mod;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += mod;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % mod;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = mod, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % mod;
        if (val < 0) val += mod;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<mod>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<mod> modpow(const Fp<mod> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int mod = 1e9+7;
using mint = Fp<mod>;

int main(){
    int n; cin >> n;
    vector<ll> c(n);
    rep(i,n) cin >> c[i];
    mint ans = 0;
    sort(ALL(c));
    vector<mint> mp(200005);
    mp[0] = 1;
    rep(i,n) mp[i+1] = mp[i]*2;
    rep(i,n){
        mint tmp = 0;
        if(i == n-1) tmp = mp[n-1];
        else tmp = mp[i] * (mp[n-i-1] + (mint)(n-i-1) * mp[n-i-2]);
        ans += tmp * c[i];
    }
    ans *= mp[n];
    cout << ans << endl;
}

Measured memory_bytes: 3328
// Problem : C - Sum of gcd of Tuples (Easy)
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

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

#define ff first
#define fs second
#define lb lower_bound
#define ub upper_bound

#define int long long
#define vi vector<int>
#define vvi vector< vector <int> >
#define vpii vector< pair<int, int> >
#define vb vector<bool>
#define si set<int>
#define mii map<int, int>
#define mci map<char, int>
#define md 1000000007
#define pb push_back
#define eb emplace_back

#define qw1(x) cerr<<#x<<": "<<x<<" "<<endl
#define qw2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define qw3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define qw4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl


#define f(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define rl(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define all(x) x.begin(),x.end()
#define endl '\n'

void printv(vector<int>  v){
	for(int i=0;i<v.size();i++) cout<<v[i]<<' '; 
	cout<<endl;
	}

int be(int m , int n, int mod) {
	int res=1;
	while(n){
	     if(n%2!=0) { res*=m; res%=mod; }
	     m*=m;   m%=mod;   n/=2;
	}
	return res;
     }

void sieve(int n, vb &prime){
    prime[0]=false;     prime[1]=false;
    for(int i=2;i*i<=n;i++){
         if(prime[i]==true){
              for(int j=i*i;j<=n;j+=i)    prime[j]=false;
             	  }
    	 }
	}


int32_t main ()
{
  //ios_base::sync_with_stdio (false); cin.tie (NULL);  cout.tie (NULL);
int t=1; 
//cin>>t; 
  while(t--){
int k; cin>>k;
int sum=0;
f(i,1,k){
	f(j,1,k){
		f(l,1,k){
			int z=__gcd(i, __gcd(j,l));
			//qw4(i,j,l,z);
			sum+=z;
		}
	}
}
cout<<sum<<endl;
   
  }
 
}








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

using namespace std;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  void unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x != y) {
      if(data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};


int main()
{
  int N, M;
  int S[3000], G[3000];

  cin >> N >> M;
  UnionFind tree(N);
  for(int i = 0; i < M; i++) {
    cin >> S[i] >> G[i];
    tree.unite(--S[i], --G[i]);
  }

  int sum[3000] = {};
  for(int i = 0; i < M; i++) {
    ++sum[tree.find(S[i])];
  }

  int ret = 0;
  for(int i = 0; i < N; i++) {
    if(tree.find(i) != i) continue;
    ret += 1 + sum[i] - tree.size(i);
  }
  cout << ret << endl;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,A,B,N,R,M,K,X,Y,Z,C;
  string S,T,U;
  cin >> S;

    if((S == "AAA")||(S == "BBB")){
      cout << "No" << endl;
    }else{
      cout << "Yes" << endl;
    }

}

Measured memory_bytes: 256
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int s; cin >> s;
	vll dp = vll(2001);
	dp[0] = 1;
	for(int currsum = 0; currsum < 2000; currsum++) {
		for(int d = 3; d < 2001; d++) {
			ll nsum = currsum + d;
			if (nsum <= 2000) {
				nsum = currsum + d;
				dp[nsum] += dp[currsum];
				dp[nsum] %= MOD;
			}
		}
	}
	cout << dp[s];
}

Measured memory_bytes: 3640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
#define int long long
signed main(){
    ll n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    n--;
    bool flag = 0;
    rep(i,n){
        ll low = a + c*i - d*(n-i);
        ll up = a + d*i - c*(n-i);
        if(low<=b&&b<=up){
            flag = 1;
        }
    }
    if(flag){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,n[100],a;
  scanf("%d",&a);
  for(i=0; i<a; i++){
    scanf("%d",&n[i]);
  }
  for(i=a-1; i>=0; i--){

    printf("%d",n[i]);
    if(i==0) break;
    printf(" ");
  }
  printf("\n");




  return 0;
}

Measured memory_bytes: 600
import java.util.*;
public class Main {
	private static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		int a = sc.nextInt();
		for (int l=0; l<a; l++){
			int gx=sc.nextInt();
			int gy=sc.nextInt();
			int No [][] = new int [gx+1][gy+1];
			int b = sc.nextInt();
			for (int k=0; k<b; k++){
				int x1=sc.nextInt();
				int y1=sc.nextInt();
				int x2=sc.nextInt();
				int y2=sc.nextInt();
				
				if (x1 == x2) {
					No [x1][(Math.max(y1, y2))]+=1;
				}
				else {No[(Math.max(x1,x2))][y1]+=2;}			
			}
			int Total[][] = new int [gx+1][gy+1];
			Total[0][0] = 1;
			for (int i=0; i<=gx; i++){
				for (int j=0; j<=gy; j++){
					if (No[i][j] == 0){
						if (i>0 & j>0){
							Total[i][j]=Total[i-1][j]+Total[i][j-1];
						}
						else if (i>0){
							Total[i][j]=Total[i-1][j];
						}
						else if (j>0){
							Total[i][j]=Total[i][j-1];
						}
						else;
					}
					else if(No[i][j] == 1){
						if (i>0){
							Total[i][j]=Total[i-1][j];
							}
						else Total[i][j]=0;
					}
					else if(No[i][j] == 2){
						if (j>0){
						Total[i][j]=Total[i][j-1];
						}
						else Total[i][j]=0;
					}
					else {
						Total[i][j]=0;
					}
				}
				
		
			}
			if (Total[gx][gy]==0){
				System.out.println("Miserable Hokusai!");
			}
			else {System.out.println(Total[gx][gy]);
			}
		}
	}
}

Measured memory_bytes: 32988
n,x,y=map(int,input().split())
x-=1
y-=1
ans=[0]*(n-1)
for i in range(n-1):
    for j in range(i+1,n):
        t=min(j-i,abs(x-i)+abs(y-j)+1)
        ans[t-1]+=1
for i in ans:
    print(i)


Measured memory_bytes: 46044
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int A[n+1];
    for(int i=1;i<=n;i++)
        cin>>A[i];
    int start=1,end=k+1;
    for(int j=1;j<= n-k; j++)
    {
        if(A[start] >= A[end])
            cout<<"No\n";
        else 
            cout<<"Yes\n";
        start++;
        end++;
    }
    return 0;
}

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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

ll n, ans = -1;

ll exgcd(ll a, ll b, ll &x, ll &y){
	if(!b){
		x = 1; y = 0;
		return a;
	}
	ll g = exgcd(b, a % b, y, x);
	y -= a / b * x;
	return g;
}

inline void solve(ll a, ll b){ // min x satisfying ax - by = 1, x, y \in \Z, a < b
	ll x, y, g = exgcd(a, b, x, y);
//	printf("a = %lld b = %lld x = %lld y = %lld\n", a, b, x, y);
	if(g != 1)
		return;
	// now we get ax + by = 1
	y = -y;
	// now we get ax - by = 1
	if(y <= 0){
		ll k = (abs(y) + a / g) / (a / g);
		y += k * (a / g);
		x -= k * (b / g);
	}
	if(x <= 0)
		return;
	ll k = x / (b / g);
	x -= k * (b / g);
	y += k * (a / g);
	if(log10(a) + log10(x) <= 18 && (ans == -1 || ans > a * x - 1))
		ans = a * x - 1;
	return;
}

int main(){
	scanf("%lld", &n);
	if(n == 1){
		puts("1");
		return 0;
	}
	n <<= 1;
	for(ll a = 1; 1ll * a * a <= n; ++a) if(!(n % a)){
		ll b = n / a;
		solve(a, b);
		if(a != b)
			solve(b, a);
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main()
{
 set<char> s;
  int n;
  cin>>n;
  while(n--)
  {
    char c;
    cin>>c;
    s.insert(c);
  }
  if(s.size()==4)
    cout<<"Four\n";
  else
    cout<<"Three\n";
  
  
  
  return 0;
}

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

#define MAX_SIZE 80

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

    string n1, n2;

    for(int i=0; i<n; i++)
    {
        cin >> n1 >> n2;
        if( n1.size()>80 || n2.size()>80 ){
                cout << "overflow" << endl;
                continue;
        }

        // 先頭を0で埋めて80桁に合わせる
        char num1[MAX_SIZE], num2[MAX_SIZE];
        for(int i=n1.size(); i<80; i++) n1.insert(0, "0");
        for(int i=n2.size(); i<80; i++) n2.insert(0, "0");

        int c=0; // carry out
        char s=0; // sum
        for(int i=0; i<MAX_SIZE; i++){
            s = n1.at(n1.size()-i-1) + n2.at(n2.size()-i-1) - 2*'0' + c;
            // 桁上がりの有無
            if(s>=10){ 
                c = 1;
                s -= 10;
            }else{
                c = 0;
            }
            n1.at(n1.size()-i-1) = s + '0';
        }
 
        if(c){ 
            cout << "overflow" << endl; 
        }else{
            while(n1.at(0)=='0' && n1.size()>=2 ) n1.erase(0,1); // 先頭の0を除く処理
            cout << n1 << endl;
        }

        n1.clear();
        n2.clear();
    }

    return 0;
}

Measured memory_bytes: 1220
from itertools import product
N = int(input())
G = {i:[] for i in range(1,N+1)}
for i in range(1,N+1):
    a = int(input())
    G[i] = [list(map(int,input().split())) for _ in range(a)]
cmax = 0
for z in product((0,1),repeat=N+1):
    if z[0]==0:
        X = []
        for i in range(1,N+1):
            if z[i]==1:
                X.append(i)
        A = []
        B = []
        for i in X:
            for x,y in G[i]:
                if y==1:
                    A.append(x)
                else:
                    B.append(x)
        flag = 0
        for a in A:
            if a not in X:
                flag = 1
                break
        for b in B:
            if b in X:
                flag = 1
                break
        if flag==0:
            cmax = max(cmax,sum(z[1:]))
print(cmax)

Measured memory_bytes: 75444
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 

int a[maxs];
int tree[4*maxs];

void build(int node,int s,int e)
{
    if(s==e)
    {
        tree[node]=a[s];
    }
    else
    {
        int mid=(s+e)/2;
        build(node*2,s,mid);
        build(node*2+1,mid+1,e);
        if(tree[node*2]<tree[node*2+1])
        tree[node]=tree[node*2];
        else
        tree[node]=tree[node*2+1];
    }
}

int query(int node,int s,int e,int l,int r)
{
    if(l>e||s>r)
    return 100005;
    if(l<=s&&r>=e)
    return tree[node];
    else
    {
        int mid=(s+e)/2;
        int p1=query(2*node,s,mid,l,r);
        int p2=query(2*node+1,mid+1,e,l,r);
        if(p1<p2)
        return p1;
        else
        return p2;
    }
    
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,k;
    cin>>n>>k;
    ll a[n],i;
    for(i=0;i<n;i++)
    cin>>a[i];
    
    sort(a,a+n);
    ll sum=0;
    for(i=0;i<k;i++)
    sum+=a[i];
    
    cout<<sum;
}




Measured memory_bytes: 3604
// ※※※ 解答不能 ※※※
// snuke氏.
// https://atcoder.jp/contests/abc163/submissions/12204917
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using P = pair<int, int>;
using vvi = vector<vector<int>>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define a first
#define b second
#define all(x) x.begin(), x.end()

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT{
    int n;
    vector<T> d;
    BIT(int n = 0) : n(n), d(n + 1) {}
    void add(int i, T x = 1){
        for(i++; i <= n; i += i & -i) d[i] += x;
    }
    T sum(int i){
        T x = 0;
        for(i++; i; i -= i & -i) x += d[i];
        return x;
    }
    T sum(int l, int r){
        return sum(r - 1) - sum(l - 1);
    }
};

const int MX = 200005;
int in[MX], out[MX], k;
vector<int> to[MX];
void dfs(int v, int p = -1){
    in[v] = k++;
    for(int u : to[v]){
        if(u == p) continue;
        dfs(u, v);
    }
    out[v] = k;
}

vector<int> vs[MX];

LL c2(LL n) { return n * (n + 1) / 2; }

int main(){
    int n;
    scanf("%d", &n);
    vector<int> c(n);
    rep(i, n) scanf("%d", &c[i]);
    rep(i, n - 1){
        int a, b;
        scanf("%d %d", &a, &b);
        --a; --b;
        to[a].pb(b);
        to[b].pb(a);
    }
    dfs(0);
    rep(i, n) vs[c[i] - 1].pb(i);
    LL tot = c2(n);
    BIT<int> d(n);
    rep(i, n) d.add(i, 1);
    rep(i, n){
        LL ans = tot;
        vector<int>& nvs = vs[i];
        sort(all(nvs), [&](int a, int b){
            return in[a] > in[b];
        });
        vector<P> history;
        for(int v : nvs){
            int cnt = 1;
            for(int u : to[v]){
                if(in[u] < in[v]) continue;
                int num = d.sum(in[u], out[u]);
                ans -= c2(num);
                cnt += num;
            }
            d.add(in[v], -cnt);
            history.pb({in[v], cnt});
        }
        ans -= c2(d.sum(0, n));
        for(auto p : history) d.add(p.a, p.b);
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 35332
#include<iostream>
#include<algorithm>
using namespace std;
int N;
long M,V,P;
long A[1<<17];
long po[1<<17];
main()
{
	cin>>N>>M>>V>>P;
	for(int i=0;i<N;i++)cin>>A[i];
	sort(A,A+N);
	int Li=-1,Ri=N-1;
	long okv=A[N-P];
	while(Ri>=0&&A[Ri]>=okv)Ri--;
	Ri++;
	while(Ri-Li>1)
	{
		int Mi=(Li+Ri)/2;
		long dist=A[Mi]+M;
		long ret=M*(V-1);
		int okid=Mi;
		for(int i=0;i<N;i++)
		{
			if(i==Mi)po[i]=-1;
			else
			{
				if(A[i]<=dist)
				{
					po[i]=min(dist-A[i],M);
					okid=i;
				}
				else po[i]=0;
				ret-=po[i];
			}
		}
		if(N-okid-1>=P)
		{
			Li=Mi;
			continue;
		}
		if(ret<=0)
		{
			Ri=Mi;
			continue;
		}
		int id=N-1;
		for(int i=0;i<P-1;i++)
		{
			if(id==Mi)id--;
			if(id<0)break;
			ret-=M-po[id];
			id--;
		}
		if(ret<=0)
		{
			Ri=Mi;
		}
		else Li=Mi;
	}
	cout<<N-Ri<<endl;
}


Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    long long int x=-1;
    long long int ans=0;
    cin >> x;
    ans = floor(x/11)*2;
    if(x%11>6)ans+=2;
    else if(x%11>0)ans+=1;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
from scipy.spatial import distance
num, distance = list(map(int, input().split()))

distance_square_array = []
for i in range(num):
    a, b = map(int, input().split())
    distance_square = a**2 + b**2
    distance_square_array.append(distance_square)

print(
    len([i for i in distance_square_array if i <= distance**2])
)


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

using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	string s;
	map<string , int>mp;
	while(n--)
	{
		cin>>s;
		sort(s.begin(),s.end());
		mp[s]++;	
	}
	ll ans=0;
	map<string, int>::iterator iter;
	for(iter = mp.begin(); iter != mp.end(); iter++)  
	{
		int a=iter->second;
		ans += (ll)a*(a-1)/2;		
	}
	cout<<ans<<endl;		
	return 0;
} 

Measured memory_bytes: 11136
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const int MOD = 100000;
enum { RIGHT_TURNABLE, UP_TURNABLE, RIGHT_STRAIGHT, UP_STRAIGHT };

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

	while ( true )
	{
		int w, h;
		cin >> w >> h;

		if ( !( w | h ) )
		{
			break;
		}

		vector< VVI > dp( h, VVI( w, VI( 4, 0 ) ) );

		{ // initialize
			int m = max( h, w );

			REP( i, 1, m )
			{
				if ( i < h )
				{
					dp[i][0][ UP_TURNABLE ] = 1;
				}
				
				if ( i < w )
				{
					dp[0][i][ RIGHT_TURNABLE ] = 1;
				}
			}
		}

		REP( i, 1, h )
		{
			REP( j, 1, w )
			{
				dp[i][j][ RIGHT_TURNABLE ] += dp[i][ j - 1 ][ RIGHT_STRAIGHT ] + dp[i][ j - 1 ][ RIGHT_TURNABLE ];
				dp[i][j][ UP_TURNABLE ] += dp[ i - 1 ][j][ UP_STRAIGHT ] + dp[ i - 1 ][j][ UP_TURNABLE ];;
				dp[i][j][ RIGHT_STRAIGHT ] += dp[i][ j - 1 ][ UP_TURNABLE ];
				dp[i][j][ UP_STRAIGHT ] += dp[ i - 1 ][j][ RIGHT_TURNABLE ];

				REP( k, 0, 4 )
				{
					if ( MOD <= dp[i][j][k] )
					{
						dp[i][j][k] %= MOD;
					}
				}
			}
		}

		cout << accumulate( ALL( dp.back().back() ), 0 ) % MOD << endl;
	}
		
	return 0;
}

Measured memory_bytes: 1776
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;




void solve(){
  
  ll x;
  cin >> x;


  ll ans_a;
  ll ans_b;

  
  for (ll a = -1000; a <= 1000; a++) {
      for (ll b = -1000; b <= 1000; b++) {
          ll tmpa = a * a * a * a * a;
          ll tmpb = b * b * b * b * b;
          if (tmpa - tmpb == x) {
              ans_a = a;
              ans_b = b;
          }
      }
  }
  cout << ans_a << " " << ans_b << endl;



}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  ll m=0;
  ll a=0;
  ll r=0;
  ll c=0;
  ll h=0;
  rep(i,n){
    string s;
    cin>>s;
    if(s[0]=='M') m++;
    if(s[0]=='A') a++;
    if(s[0]=='R') r++;
    if(s[0]=='C') c++;
    if(s[0]=='H') h++;
  }

  ll ans=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);


    int N;
    cin >> N;

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

    for(int i = 0; i < N - 1; i++) {
        int A;
        cin >> A;
        a = max(a, A);
        b = min(b, A);
    }

    cout << a - b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int pow(int n, int p);

int main() {
  int x;
  scanf("%d", &x);
  printf("%d\n", pow(x, 3));
  return 0;
}

int pow(int n, int p) {
  if (p == 0) {
    return 1;
  } else {
    return n * pow(n, p - 1);
  }
}

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

#define db double
const db eps = 1e-6;
int sgn(db a, db b = 0) {
	a -= b;
	return (a > eps) - (a < -eps);
}

struct poi {
	db x, y;
	void r() { cin >> x; cin >> y; }
	void w() { cout << x << ' ' << y << '\n'; }
	poi operator -(poi p) {
		return {x - p.x, y - p.y};
	}
	poi operator +(poi p) {
		return {x + p.x, y + p.y};
	}
	poi operator *(db d) {
		return {x * d, y * d};
	}
	db dot(poi p) {
		return x * p.x + y * p.y;
	}
	db cross(poi p) {
		return x * p.y - y * p.x;
	}
	db len2() { return x * x + y * y; }
	poi proj(poi p, poi q) {
		db s = (*this - p).dot(q - p) / (q - p).len2();
		return p + (q - p) * s;
	}
};

int ccw(poi a, poi b, poi c) {
	poi u = b - a, v = c - a;
	if(u.cross(v) > eps) return 1;
	if(u.cross(v) < -eps) return -1;
	if(u.dot(v) < -eps) return -2;
	if(u.len2() + eps < v.len2()) return 2;
	return 0;
}
bool si(poi a, poi b, poi c, poi d) {
	return ccw(a, b, c) * ccw(a, b, d) <= 0 &&
		ccw(c, d, a) * ccw(c, d, b) <= 0;
}

int main() {
	ios :: sync_with_stdio(false);

	int T; cin >> T;
	while(T --) {
		poi p0, p1, p2, p3; p0.r(); p1.r(); p2.r(); p3.r();
		cout << si(p0, p1, p2, p3) << '\n';
	}

	return 0;
}

Measured memory_bytes: 3276
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	int x, y, a, b, c;

	scanf("%d %d %d %d %d", &x, &y, &a, &b, &c);

	vector<long long> r, g, l;

	for (int i = 0; i < a; i++)
	{
		long long input;

		scanf("%lld", &input);
		
		r.push_back(input);
	}

	for (int i = 0; i < b; i++)
	{
		long long input;

		scanf("%lld", &input);

		g.push_back(input);
	}

	for (int i = 0; i < c; i++)
	{
		long long input;

		scanf("%lld", &input);

		l.push_back(input);
	}

	sort(r.begin(), r.end(), greater<int>());
	sort(g.begin(), g.end(), greater<int>());
	sort(l.begin(), l.end(), greater<int>());

	long long sol = 0;

	priority_queue<long long, vector<long long>, greater<long long>> pq[2];

	for (int i = 0; i < x; i++)
	{
		sol += r[i];

		pq[0].push(r[i]);
	}

	for (int i = 0; i < y; i++)
	{
		sol += g[i];

		pq[1].push(g[i]);
	}

	for (int i = 0; i < c; i++)
	{
		int idx;

		if (pq[0].empty() && pq[1].empty())
		{
			break;
		}

		if (pq[0].empty())
		{
			idx = 1;
		}

		else if (pq[1].empty())
		{
			idx = 0;
		}

		else
		{
			if (pq[0].top() < pq[1].top())
			{
				idx = 0;
			}

			else
			{
				idx = 1;
			}
		}

		if (pq[idx].top() >= l[i])
		{
			break;
		}

		sol -= pq[idx].top();
		sol += l[i];
		pq[idx].pop();
	}

	printf("%lld\n", sol);

	return 0;
}

Measured memory_bytes: 4852
import fractions
from functools import reduce

def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
A = list(map(int,input().split()))
M = lcm_list(A) - 1
ans = 0

for i in range(N):
    ans += M % A[i]

print(ans)



Measured memory_bytes: 5604
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 1; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
s = s()
new_s = ""
for i in range(2 * n):
    if (2 * n - i - 1) % 2 == 0:
        new_s += s[i]
    else:
        new_s += "W" if s[i] == "B" else "B"

lr = ""
for i in range(2 * n):
    if new_s[i] == "B":
        lr += "R"
    else:
        lr += "L"

if lr.count("R") != n:
    print(0)
    exit()

lcount = 0
for i in range(2 * n):
    if lr[i] == "L":
        lcount += 1
    else:
        ans *= lcount
        ans %= mod
        lcount -= 1

for i in range(1, n + 1):
    ans *= i
    ans %= mod

print(ans)

Measured memory_bytes: 6484
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
#include<iomanip>
#include<vector>

using namespace std;
typedef long long ll; 


ll ans,mx,sum,mn=1e18,flag;


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dif=10000000;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)
		cin>>a[i];	
	for(int i=1;i<=n;i++)
	{
		int s1=0,s2=0;
		for(int j=1;j<=i;j++)
			s1+=a[j];
		for(int j=i+1;j<=n;j++)
			s2+=a[j];
		if(abs(s1-s2)<dif)
			dif=abs(s1-s2);		
	}
	cout<<dif;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
n, m = [int(x) for x in stdin.readline().rstrip().split()]
data = [stdin.readline().rstrip().split() for _ in range(n)]
res = data[0]
res.pop(0)
if n > 1:
    for i in range(1, n):
        re = data[i]
        re.pop(0)
        res = list(set(re) & set(res))
print(len(res))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int num(int d)
{
	int s=9;
	for(int i=2;i<=d;i++)
	{
		s*=10;
	}
	return s;
}
int main()
{
	int n;
	cin>>n;
	int m=n;
	int d=0;
	while(m!=0)
	{
		d++;
		m=m/10;
	}
	int sum=0;
	for(int i=1;i<d;i+=2)
	{
		sum+=num(i);
	}
	if(d%2!=0)
	{
		int p=1;
		for(int i=1;i<d;i++)
		{
		    p=p*10;
		}
		sum+=(n-p+1);
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
import math
a,b,x = list(map(int, input().split()))
if x<= a**2*b/2:
    h1 = x/a /b *2
    l = math.sqrt(b**2 + h1**2)
    h2 = x/a /l *2
    #print(h1, l, h2)
    ans = math.degrees(math.acos(h2/b))

else:
    l = (x/a /a *2) -b
    ans = math.degrees(math.atan((b-l)/a))

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=998244353;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
ll calc(ll i){
    ll res=0;
    while(i){
        res+=i%10;
        i/=10;
    }
    return res;
}
int main(){
    ll n;cin>>n;
    ll k=1;
    ll i=1;
    while(n){
        if(i>k*calc(i)){
            i+=k*10-k;
            k*=10;
        }
        out(i);
        n--;
        i+=k;
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N = 365 + 7;
const int K = 26 + 7;
int n;
int c[K], s[N][K], t[N], last[K];

int get(int m) {
  for (int j = 1; j <= 26; j++) {
    last[j] = 0;
  }
  int sol = 0;
  for (int i = 1; i <= m; i++) {
    sol += s[i][t[i]];
    last[t[i]] = i;
    for (int j = 1; j <= 26; j++) {
      sol -= c[j] * (i - last[j]);
    }
  }
  return sol;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= 26; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 26; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
  }
  for (int i = 1; i <= n; i++) {
    cout << get(i) << "\n";
  }
  return 0;
}


Measured memory_bytes: 3708
import java.io.*;
import java.util.*;

public class Main {

	static final boolean stdin = true;
	static final String filename = "";
	static FastScanner br;
	static PrintWriter pw;

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

		if (stdin) {
			br = new FastScanner();
			pw = new PrintWriter(new OutputStreamWriter(System.out));
		}

		else {
			br = new FastScanner(filename + ".in");
			pw = new PrintWriter(new FileWriter(filename + ".out"));
		}

		X solver = new X();
		solver.solve(br, pw);
	}

	static class X {
		public void solve(FastScanner br, PrintWriter pw) throws IOException {
			
			int N = br.nextInt();
			
			int[][] in = new int[N][3];
			
			for(int i = 0; i < N; i++) {
				for(int j = 0; j < 3; j++) {
					in[i][j] = br.nextInt();
				}
			}
			
			int[][] dp = new int[N][3];
			
			dp[0][0] = in[0][0];
			dp[0][1] = in[0][1];
			dp[0][2] = in[0][2];
			
			for(int i = 1; i < N; i++) {
				for(int j = 0; j < 3; j++) {
					int o1 = (j+1)%3;
					int o2 = (j+2)%3;
					if(i > 1) {
						dp[i][j] = Math.max(dp[i][j], dp[i-2][j]);
					}
					dp[i][j] = Math.max(dp[i-1][o1], Math.max(dp[i-1][o2], dp[i][j])) + in[i][j];
				}
			}
			
			pw.println(Math.max(dp[N-1][0], Math.max(dp[N-1][1], dp[N-1][2])));
			
			pw.close();	
		}

	}

	//fastscanner class
	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

}
 



Measured memory_bytes: 49464
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,M,ans=0;
  cin >>N >>M;
  if(N>=2 && M>=2) ans=N*M-(N+M)*2+4;
  else if(N==1 && M==1) ans=1;
  else ans=N*M-2;
  cout <<ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    int n, m;
    cin >> n >> m;
    cout << (n-1) * (m-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;
    int ans = 0;

    if (A > 12)
    {
        ans = B;
    }
    else if (A > 5)
    {
        ans = B / 2;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
s=[input() for i in range(n)]
lastA=0
firstB=0
lastAandfirstB=0
ABs=0
for si in s:
    ABs+=si.count("AB")
    firstB+=(si[0]=="B")
    lastA+=(si[-1]=="A")
    lastAandfirstB+=(si[0]=="B")*(si[-1]=="A")

can=min(firstB,lastA)
# print(lastA,firstB,lastAandfirstB)
# if lastAandfirstB==1 and firstB==1 and lastA==1:
#     print(ABs)
#     exit()
if can==n or lastAandfirstB==firstB==lastA!=0:
    can=can-1
print(can+ABs)

Measured memory_bytes: 3700
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
print(S[:3])


Measured memory_bytes: 10472
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

const int mod = 1000000007;

struct mint {
    long long x;
    mint(long long 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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
bool operator==(const mint& a, const mint& b) { return a.x == b.x;}

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

    int n, m;
    cin >> n >> m;
    vector<int> s(n), t(m);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];
    auto dp = make_vec<mint>(n+1, m+1);
    auto dpsum = make_vec<mint>(n, m);
    rep(i, n) rep(j, m) {
        if (i >= 1 && j >= 1) dpsum[i][j] = dpsum[i-1][j] + dpsum[i][j-1] - dpsum[i-1][j-1] + dp[i][j];
        if (s[i] == t[j]) dp[i+1][j+1] = dpsum[i][j] + 1;
    }
    mint ans = 1;
    rep(i, n+1) rep(j, m+1) ans += dp[i][j];
    cout << ans << endl;
}


Measured memory_bytes: 66020
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    int n;
    cin>>n;

    int a[n];

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

    sort(a,a+n);

    int c=0;
    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            for(int k=j+1; k<n; k++)
            {
                if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i])
                {
                    if(a[i]+a[j]>a[k])
                        c++;
                }
            }
        }
    }

    cout<<c<<endl;




    return 0;
}


Measured memory_bytes: 3656
n, k = list(map(int, input().split()))
xs = list(map(int, input().split()))

from collections import deque
def slide_max(k, l):
    rs = []
    dq = deque()
    for i, x in enumerate(l):
        while True:
            if not len(dq):
                dq.append(i)
                break
            lxi = dq[-1]
            if x < l[lxi]:
                dq.append(i)
                break
            dq.pop()
        if i+1 < k:
            continue
        sxi = dq[0]
        rs.append(l[sxi])
        if sxi == (i + 1 - k):
            dq.popleft()
    return rs

def slide_min(k, l):
    rs = []
    dq = deque()
    for i, x in enumerate(l):
        while True:
            if not len(dq):
                dq.append(i)
                break
            lxi = dq[-1]
            if x > l[lxi]:
                dq.append(i)
                break
            dq.pop()
        if i+1 < k:
            continue
        sxi = dq[0]
        rs.append(l[sxi])
        if sxi == (i + 1 - k):
            dq.popleft()
    return rs

maxs, mins = slide_max(k, xs), slide_min(k, xs)
aa, bb = xs[:k], xs[k:]

b, nb, bx = aa[0], aa[1], aa[-1]
ba = None
c = 1
for a in aa:
    if ba == None:
        ba = a
        continue
    if a > ba:
        c += 1
    else:
        c = 1
    ba = a

rok = False
if c == k:
    rok = True

r = 1
bs = xs[0]
for i, (s, x) in enumerate(zip(xs[1:], bb)):

    if x > bx:
        c = min(c+1, k)
    else:
        c = 1
    bx = x

    if c == k:
        if not rok:
            r += 1
        rok = True
        continue

    if x != maxs[i+1]: 
        r+=1
    elif bs != mins[i]:
        r+=1
    bs = s

print(r)


Measured memory_bytes: 101372
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef long long LL;

struct Trie {
	Trie* next[26];
	int cnt[26];
	Trie() {
		memset(next, 0, sizeof(next));
		memset(cnt, 0, sizeof(cnt));
	}
};

int main(int argc, char *argv[]) {
	vector<Trie> pool(1000002);
	int pi = 1;
	LL n, ans = 0;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
		int len = s[i].length();
		vector<int> cf(len + 2);
		for (int j = 0; j < len; ++j) {
			cf[j + 2] = cf[j + 1] | (1 << (s[i][j] - 'a'));
		}
		Trie* p = &(pool[0]);

		for (int k = 0; k < 26; ++k) {
			if (cf[len - 1 + 2] & (1 << k)) {
				p->cnt[k] += 1;
			}
		}

		for (int j = len - 1; j >= 0; --j) {
			char c = s[i][j] - 'a';
			if (p->next[c] == 0) {
				p->next[c] = &(pool[pi]);
				++pi;
			}
			p = p->next[c];
			for (int k = 0; k < 26; ++k) {
				if (cf[j + 1] & (1 << k)) {
					p->cnt[k] += 1;
				}
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		int len = s[i].length();
		Trie* p = &(pool[0]);
		for (int j = len - 1; j > 0; --j) {
			char c = s[i][j] - 'a';
			p = p->next[c];
		}
		ans += p->cnt[s[i][0] - 'a'] - 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 314144