akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
#define lp(k,a) for(int k=1;k<=a;k++)
#define lp0(k,a) for(int k=0;k<a;k++)
#define lpn(k,n,a) for(int k=n;k<=a;k++)
#define lpd(k,n,a) for(int k=n;k>=a;k--)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define ll long long
#define mod 1000000007

using namespace std;


int a[10000];
int n,k;
int h[2002];
int pre[2002];
int main()
{
    //freopen("in.txt","r",stdin);
    cin>>n>>k;

    lp(i,n) {
        cin>>a[i];
        h[a[i]]+=1;
    }
    pre[0]=h[0];
    pre[1]=h[1];
    lpn(i,2,2000) {
        pre[i]=pre[i-1]+h[i];
    }
    ll bie=0;
    lp(i,2000){
        bie+=pre[i-1]*h[i];
        //bie%=mod;
    }
    //bie%=mod;

    ll zi=0;
    lp(i,n)
     lpn(j,i+1,n){
         if(a[i]>a[j]) zi++;
     }
    //zi%=mod;

    ll ans=0;
    ans=(ll)k*((ll)k-1)/2;
    ans%=mod;
    ans*=bie;
    ans%=mod;
    ans+=(ll)k*(ll)zi;
    ans%=mod;
    cout<<ans<<endl;
    return 0;
}


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

#pragma warning(disable:4996)

using namespace std;


int main()
{
	int N;
	while (cin >> N)
	{
		int x;
		int min_x = 1001, max_x = -1;
		for (int i = 0; i < N; ++i)
		{
			cin >> x;
			min_x = min(min_x, x);
			max_x = max(max_x, x);
		}
		cout << max_x - min_x << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;


int main()
{
    uint64_t n, k, dist;

    cin >> n >> k;

    dist = n;

    uint64_t a = n % k;
    uint64_t b = (n + k - a) - n;

    cout << min(a, b) << "\n";

    return 0;
}

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

using namespace std;

int main(){
  int n; cin >> n;
  vector<vector<bool> > v(4,vector<bool>(14,false));
  for(int i=0;i<n;++i) {
    char mark;
    int rank;
    cin >> mark >> rank;
    if(mark=='S') v[0][rank]=true;
    else if(mark=='H') v[1][rank]=true;
    else if(mark=='C') v[2][rank]=true;
    else v[3][rank]=true;
  }
  for(int i=0;i<4;++i){
    for(int j=1;j<=13;++j){
      if(!v[i][j]){
	if(i==0) cout << "S ";
	else if(i==1) cout << "H ";
	else if(i==2) cout << "C ";
	else cout << "D ";
	cout << j << endl;
      }
    }
  }
  
  return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は２つの値の組を表せる

double A[1001001],B[1001001];
int main(){
    int N,K; cin >> N >> K;
    B[0]=0;
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<N; i++) A[i]=(1+A[i])/2.0;
    for (int i=1; i<N+1; i++) B[i]=A[i-1]+B[i-1]; //累積和
    
    double ans=0;
    for (int i=0; i<=N-K; i++){
        ans=max(ans,B[i+K]-B[i]);
    }
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 5888
import java.util.ArrayList;
import java.util.*;

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

		//permutation
		List<Integer> perm = new ArrayList<>();
		//swap pair
		UnionFind unionFind;

		//Count
		int count = 0;

		Scanner scan = new Scanner(System.in);

		//permutation size
		int permMax = Integer.parseInt(scan.next());
		unionFind = new UnionFind(permMax);
		//pair size
		int pairMax = Integer.parseInt(scan.next());

		//string to int
		for(int i = 0; i < permMax; i++){
			perm.add(Integer.parseInt(scan.next()));
		}

		//set pair
		for(int i = 0; i < pairMax; i++){

			int x = Integer.parseInt(scan.next()) - 1;
			int y = Integer.parseInt(scan.next()) - 1;
			unionFind.union(x, y);
		}

		//sum
		for(int x = 0; x < perm.size(); x++){

			int value = x + 1;
			//添字の要素と一致した場合
			if(value == perm.get(x)){
				count++;
				continue;

			}

			//一致しなかった場合
			//swap可能な範囲がある場合に検索	
			if(unionFind.same(x, perm.get(x) - 1)){
				count++;
				continue;
			}
		}

		System.out.println(count);

	}
}

class UnionFind{
	int par[];
	int rank[];

	public UnionFind(int size){
		par = new int[size];
		rank = new int [size];

		for(int i = 0; i < size; i++){
			par[i] = i;
			rank[i] = 0;
		}
	}

	/**
	 *rootを探すメソッドです。
	 *
	 */
	int find(int x){
		if(x == par[x]){
			return x;
		}else{
			par[x] = find(par[x]);
			return par[x];
		}
	}

	/**
	 * 木を繋げるメソッドです。
	 */
	void union(int x, int y){

		int rootX = find(x);
		int rootY = find(y);

		//同じ根、つまりxとyが同じ木の時
		if(rootX == rootY){
			return;
		}	

		//木をつなげる
		if(rank[rootX] > rank[rootY]){
			//xの方がyよりも階層が深いとき
			//yの根をxの根につなげる
			par[rootY] = rootX;
		}else{
			//それ以外は
			//xの根をyの根につなげる
			par[rootX] = rootY;

			//xとyの階層が同じ場合
			//yの階層を一つ増やす
			if(rank[rootX] == rank[rootY]){
				rank[rootY]++;
			}
		}
	}

	/**
	 * 同じ木に属しているか調べる
	 */
	boolean same(int x, int y){
		int rootX = find(x);
		int rootY = find(y);
		return rootX == rootY;
	}
}

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

int main(){
        int a,b;
        cin>>a>>b;
        
        if( a < b ) cout<<"a < b"<<endl;
        if( a > b ) cout<<"a > b"<<endl;
        if( a == b ) cout<<"a == b"<<endl;
        
        return 0;
    }


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

int main()
{
    string ashiq;
    cin >> ashiq;
    string ashi = ashiq.substr(0,2);
    string arif = ashiq.substr(2, 3);
    if(stoi(ashi) <= 12 && stoi(ashi) > 0 && stoi(arif) <= 12 && stoi(arif) > 0)
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if(stoi(ashi) <= 12 && stoi(ashi) > 0 )
    {
        cout << "MMYY" << endl;
    }
    else if(stoi(arif) <= 12 && stoi(arif) > 0)
    {
        cout << "YYMM" << endl;
    }
    else
        cout << "NA" << endl;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
		int N, X;
	cin >> N>>X;
	if (X==1||X==N*2-1) {
		cen;
		return 0;
	}

	cey;
	if (X==2) {
		if (N==2) {
			fx(3) {
				ce(x+1)
			}
		}
		else {
			int i = 0;
		int j = 0;
		for (int x = 5; x <= 2 * N - 1 && i < N-2; x++) {
			i++;
			j = x;
			ce(x)
		}
		ce(4)
			ce(1)
			ce(2)
			ce(3)
			i = j+1;
		while (i <= 2 * N - 1) {
			ce(i++)
		}
		}
	}
	else {
		int i = 0;
		int j = 0;
		for (int x = 1; x <= 2 * N - 1 && i < N-2; x++) {
			if (x == X || x == X - 1 || x == X - 2 || x == X + 1) { continue; }
			i++;
			j = x;
			ce(x)
		}
		ce(X - 1)
			ce(X)
			ce(X + 1)
			ce(X - 2)
			i = j+1;
		while (i <= 2 * N - 1) {
          if (i == X || i == X - 1 || i == X - 2 || i == X + 1) {i++; continue; }
			ce(i++)
		}
	}
    return 0;
}



Measured memory_bytes: 1536
N = int(input())

sc = {"AC":0, "WA":0, "TLE":0, "RE":0} 

for i in range(N):
  S = input()
  sc[S] += 1
#
print("AC", " x ", sc["AC"])
print("WA", " x ", sc["WA"])
print("TLE", " x ", sc["TLE"])
print("RE", " x ", sc["RE"])



Measured memory_bytes: 9204
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> P;
int main(){
  int n,m;cin>>n>>m;
  vector<P> nya(m);
  for(int i = 0; m > i; i++){
    cin >> nya[i].first>>nya[i].second;
  }
  vector<int> Pa(n);
  for(int i =0; n > i; i++){
    Pa[i] = i+1;
  }
  int ans = 0;
  do{
    bool ad = true;
    for(int i = 0; n-1 > i; i++){
      bool ok = false;
      for(int j = 0; m > j; j++){
        if(min(nya[j].first,nya[j].second) == min(Pa[i],Pa[i+1]) && max(nya[j].first,nya[j].second) == max(Pa[i],Pa[i+1])){
          ok = true;
          break;
        }
      }
      if(!ok){
        ad = false;
        break;
      }
    }
    if(ad)ans++;   
  }while(next_permutation(Pa.begin()+1,Pa.end()));
  cout << ans << endl;
}


Measured memory_bytes: 256
// Created by Tanuj Jain
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MAXN = 410;
const ll INF = 1e14;

ll dp[MAXN][MAXN],V[MAXN],pref[MAXN];
int N;

ll calc(ll a,ll b){
	if(a > b) return INF;
	return pref[b] - pref[a-1];
}

ll solve(int start,int end){
	//cout<<start<<" "<<end<<endl;
	if(dp[start][end] != -1) return dp[start][end];
	if(start == end) return dp[start][end] = 0;
	if(start + 1 == end) return dp[start][end] = V[start] + V[end];

	ll best = INF;

	for(int i = start;i<end;i++){
		ll cand = solve(start,i) + solve(i+1,end) + calc(start,end);
		best = min(best,cand);
	}

	return dp[start][end] = best;

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

	//#ifndef ONLINE_JUDGE
	//freopen("inputf.in","r",stdin);
	//freopen("outputf.in","w",stdout);
	//#endif

	memset(dp,-1,sizeof(dp));

	cin >> N;
	for(int i = 1;i<=N;i++) cin >> V[i];

	for(int i = 1;i<=N;i++) pref[i] = pref[i-1] + V[i];

	cout << solve(1,N) << endl;

}

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

int main(void){
  int n,t;
  while(cin >> n && n){
    map<int,int> m;
    for(int i=0;i<n;i++){
      cin >> t;
      m[t]++;
    }
    map<int,int>::iterator it = m.begin();
    bool isok = false;
    while(it != m.end()){
      if((*it).second > (double)n/2){
	isok = true;
	cout << (*it).first << endl;
      }
      ++it;
    }
    if(!isok) cout << "NO COLOR" << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,k=0,m;
  cin>>n;
  while(n--){
    cin>>a>>b;
    if(a>k){
      m=a+b;
      k=a;
    }
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;


typedef long long ll;

const int N=4e5+50;

/*
int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
*/

int n,a[N],b[N],p[N],c[N],ans,tot,d[N];
map<int,int> f;
int find(int x){return p[x]==x?x:p[x]=find(p[x]);}
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	scanf("%d",&n);
	int s;
	s=0;rep(i,1,n)scanf("%d",a+i),s^=a[i],c[i]=a[i];c[n+1]=a[n+1]=s;
	s=0;rep(i,1,n)scanf("%d",b+i),s^=b[i],d[i]=b[i];d[n+1]=b[n+1]=s;
	++n,sort(c+1,c+n+1),sort(d+1,d+n+1);
	rep(i,1,n)if(c[i]!=d[i]){ puts("-1"); return 0; }
	rep(i,1,n)if(a[i]!=b[i]){ ans+=i<n; if(!f[a[i]])f[a[i]]=++tot; if(!f[b[i]])f[b[i]]=++tot; }
	if(!ans){puts("0"); return 0;}
	if(!f[a[n]])f[a[n]]=++tot;
	if(!f[b[n]])f[b[n]]=++tot;
	rep(i,1,tot)p[i]=i;
	rep(i,1,n)if(a[i]!=b[i])p[find(f[a[i]])]=find(f[b[i]]); 
	rep(i,1,tot)ans+=find(i)==i;
	printf("%d\n", --ans);
	return 0; 
}




Measured memory_bytes: 11776
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc042/tasks/arc058_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(forbiddens, N):
    forbiddens.sort()

    ans = N
    repeat = True
    while repeat:
        repeat = False
        num_s = str(ans)
        for s in num_s:
            if int(s) in forbiddens:
                repeat = True
                ans += 1
                break
    return ans


def main(args):
    # N, K = 9999, 1
    # forbiddens = [9]
    N, K = map(int, input().split())
    forbiddens = [int(x) for x in input().split()]
    ans = solve(forbiddens, N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3188
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<iomanip>
#include<map>
#include<fstream>
#include<queue>
#include<set>
#include<deque>

using namespace std;



int main()
{
	char x, y;
	cin >> x >> y;
	if (x < y)
		cout << "<" << endl;
	else if (x > y)
		cout << ">" << endl;
	else
		cout << "=" << endl;
}

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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

int main() {
	int n, m, x;
	cin >> n >> m >> x;
	x--;
	map<int, int> mp;
	rep(i, m) {
		int a;
		cin >> a;
		a--;
		mp[a]++;
	}
	int ans = 0;
	int fee = 0;
	for (int j = x; j < n; ++j) {
		if (mp[j] != 0) fee++;
	}
	ans = fee;
	fee = 0;
	for (int j = x; j >= 0; --j) {
		if (mp[j] != 0) fee++;
	}
	ans = min(ans, fee);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
//confilm 0LL and 1LL
//confilm cornercases such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

vector<VecP> tree;
Vec ans;

void dfs(const ll n, const ll p){
	for(P i : tree[n]){
		if(i.fs == p) continue;
		if(i.sc%2) ans[i.fs] = !ans[n];
		else ans[i.fs] = ans[n];
		dfs(i.fs, n);
	}
}

int main(void){
	ll n;
	cin >> n;
	tree.resize(n+1);
	ans.resize(n+1);
	ll u, v, w;
	rep(i, n-1){
		cin >> u >> v >> w;
		tree[u].pb({v, w});
		tree[v].pb({u, w});
	}
	ans[1] = 0;
	dfs(1, 1);

	repn(i, n) co(ans[i]);

	return 0;
}


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

int main() {
  int H,W,K;
  cin>>H>>W>>K;
  K--;
  vector<int> p(W);
  for(int i=0;i<W;i++){
    p[i]=i;
  }
  vector<vector<int>> q;
  for(int i=0;i<(1<<(W-1));i++){
    vector<int> r;
    int S=0,A=0;
    vector<int> s=p;
    for(int j=0;j<W-1;j++){
      if(i&(1<<j)){
        r.push_back(j);
        S++;
      }
    }
    for(int j=0;j<S;j++){
      swap(s[r[j]],s[r[j]+1]);
      if(j==0){
        continue;
      }
      else if(r[j]-r[j-1]==1){
        A=1;
        break;
      }
    }
    if(A){
      continue;
    }
    else{
      q.push_back(s);
    }
  }
  int N=q.size();
  vector<vector<int64_t>> dp(H+1,vector<int64_t>(W));
  dp[0][0]=1;
  int64_t Q=1000000007;
  for(int i=0;i<H;i++){
    for(int j=0;j<N;j++){
      for(int k=0;k<W;k++){
        dp[i+1][q[j][k]]+=dp[i][k];
        dp[i+1][q[j][k]]%=Q;
      }
    }
  }
  cout<<dp[H][K]<<endl;
  
}

Measured memory_bytes: 3620
#include<stdio.h>
#define N 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];

int prim(){
  int u;
  int d[N],p[N],color[N];//d ??? ??????????°???????????????????p ??? v??????
  int i,j,v,sum=0,min;

  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }

  d[0]=0;

  while(1){
    min=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(min>d[i] && color[i]!=BLACK){
	u=i;
	min=d[i];//????°????????????¨??\??????
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(v=0;v<n;v++){//u?????????v???????????§
      if(color[v]!=BLACK && M[u][v]!=INFTY){
	if(d[v]>M[u][v]){//???????????£??\??????????????????????????????????????????????±???????
	  d[v]=M[u][v];
	  
	  p[v]=u;//???
	  color[v]=GRAY;//?¨????
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1)sum+=M[i][p[i]];
  }
  return sum;
}
int main(){
  int i,j;
  int e;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      //scanf("%d",&M[i][j]);
       scanf("%d",&e);
       M[i][j]=(e==-1)?INFTY : e;
       //if(M[i][j]==-1)M[i][j]=INFTY;
    }
  }
  //e=prim();
  printf("%d\n",prim());

  return 0;
}

Measured memory_bytes: 636
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    long long int n,m,o,g,h,i,j,count,k;
    while(scanf("%lld %lld",&h,&g)==2)
    {

        for(k=0,count=0; k<=h; k++)
        {
            for(j=0; j<=h; j++)
            {
                i=g-k-j;
             if((i>=0 && i<=h)){count++;}
            }
        }

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

}
return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a; cin >> a;
    cout << a + a*a + a*a*a << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
using namespace std;



int main() {
	long long n, m;
	cin >> n >> m;
	if (n*m == 1) {
		cout << 1;
	}
	else if (n == 1 || m == 1) {
		cout << n + m - 3;
	}
	else {
		cout << n * m - (n * 2 + m * 2 - 4);
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC99 C

#6^pを6回引き出すとき6^(p+1)と等しい
#6^pは(n//6^p)%6回のみ引き出す
#9^pも同様
#6^pと9^qを全探索
n = int(input())
ans = n
for i in range(0,n+1,6):
    cnt = 0
    j = n-i#i:=6^pに用いる,j:=9^pに用いる
    while i > 0:
        cnt += i%6#6^p何回用いるか
        i //= 6
    while j > 0:
        cnt += j%9#9^p何回用いるか
        j //= 9
    ans = min(ans,cnt)
print(ans)


Measured memory_bytes: 39408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define SZ(x) (int)(x).size()
ll dp[101][101][61][61];
const int mod = 1e9+7;
int a[101], b[101];
void add_mod(ll &a, const ll &b) {
    a += b;
    if (a >= mod) a -= mod;
}
int main() {
#ifdef LOCAL
    freopen("main.in", "r", stdin);
#endif

    int n, m;
    cin >> n >> m;
    string a, b; cin >> a >> b;
    int g = __gcd(n, m);
    int nn = n / g, mm = m / g;

    for (int i = 0, j = 0; i < n && j < m; i += nn, j += mm) {
        if (a[i] != b[j]) {
            cout << -1 << endl;
            return 0;
        }
    }



    cout << 1LL * n * m / g << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}




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

	vector<long long int> x(n);
	vector<long long int> y(n);
	vector<long long int> z(n);
	vector<long long int> price(n);


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


	int pro[3];  //価値の計上方向。＋１　or　－１

	long long int ans = 0;
	long long int wk_ans;

	//8通り全探索
	for (int i = 0; i < (1 << 3); i++) {

		//それぞれの物体の価値計上方向を決定。
		for (int j = 0; j < 3; j++) {
			if ((i >> j) & 1) {
				pro[j] = 1;
			}
			else {
				pro[j] = -1;
			}
		}




		

		//価値計算
		for (int j = 0; j < n; j++) {
			price[j] = 0;
			price[j] += pro[0] * x[j];
			price[j] += pro[1] * y[j];
			price[j] += pro[2] * z[j];
		}

		//価値を降順にソート
		sort(price.begin(), price.end(), greater<long long int>());

		wk_ans = 0;
		for (int j = 0; j < m; j++) {
			wk_ans += price[j];
		}

		if (wk_ans > ans)ans = wk_ans;



	}

	
	cout << ans << endl;


	


	return 0;

}



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

int main()
{
    int n, v[20], c[20], ans;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
    }
    ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (v[i] > c[i])
        {
            ans += v[i] - c[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//  
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

template<class T> inline bool chmin(T& a, T b){ if(a>b){a=b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b){ if(a<b){a=b; return 1;} return 0;}

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
// const double PI=3.1415926535897932;

//#define __DBG__


void solve(void){
  
  bool flag=true;
  string S;
  
  cin >> S;
  
  REP(i,S.size()){
    if((i+1)%2){
      //odd
      if(S[i]=='L'){
        flag=false;
        break;
      }
    }
    else
    {
      //even
      if(S[i]=='R'){
        flag=false;
        break;
      }
    }
  }
  
  puts(flag?"Yes":"No");
  
  return;
   
}


int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    solve();
 
    return 0;
}




Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split(' ')))

ans = [0 for _ in range(N)]

for i in range(N):
    base = N - 1 - i
    for j in range(base, N, base+1):
        if j == base:
            ans[i] += A[j]
        else:
            ans[i] -= ans[N - 1 - j]
        ans[i] = ans[i] % 2
        if ans[i] < 0:
            print('-1')
            break

else:
    ans_ids = [str(i+1) for i, a in enumerate(reversed(ans)) if a % 2 == 1]
    print(len(ans_ids))
    print(' '.join(ans_ids))



Measured memory_bytes: 69860
#include <iostream>
#include <string> 
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;

int main(){
int n;cin>>n;
vector<int> a(n),b(n),v(n);
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
if(a==b){cout<<0;return 0;}
for(int i=0;i<n;i++)v[i]=a[i];
sort(v.begin(),v.end());
int x,y,t=1;
while(a!=v){
    next_permutation(v.begin(),v.end());
    t++;
    x=t;
}
sort(v.begin(),v.end());t=1;
while(b!=v){
    next_permutation(v.begin(),v.end());
    t++;
    y=t;
}
cout<<abs(x-y);
}

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

ll pow(ll x, ll n, int mod) {
  ll ans = 1;
  while(n != 0){
      if(n&1) ans = ans*x % mod;
      x = x*x % mod;
      n = n >> 1;
  }
  return ans;
}

ll nCr(int n, int r, int mod) {
  ll res = 1;
  for(int i = 1; i <= r; i++) {
    res = res * (n-i+1) % mod * pow(i, mod-2, mod) % mod;
  }
  return res;
}

int main() {
  int mod = 1000000007;
  int n,a,b;
  cin >> n >> a >> b;
  ll temp = pow(2, n, mod) - 1 - nCr(n, a, mod) - nCr(n, b, mod);
  // ※  temp 
  if (temp < mod) {
    temp %= mod;
    temp += mod; 
  }
  temp %= mod;
  cout << temp << endl;
}


Measured memory_bytes: 256
// Created by Tanuj Jain
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void generate(string S, int index, vector<string>&v,string curr)
{
	if(index==S.size())
		return;

	

	for(int i=index+1;i<S.size();i++)
	{	
	//choose
		curr+=S[i];
		v.push_back(curr);
	//explore
		generate(S,i,v,curr);
	//backtrack
		curr.pop_back();
	}
	return;
}
string bottomup(string &S, string &T)
{
	int dp[S.size()+1][T.size()+1];
	for(int i=0;i<=S.size();i++)
	{
		for(int j=0;j<=T.size();j++)
		{
			if(i==0 || j==0)
				dp[i][j]=0;
			else if(S[i-1]==T[j-1])
				//take the diagonal value and add one 
				dp[i][j]=dp[i-1][j-1]+1;
			else
				//take the max of upper and left
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	//cout<<dp[S.size()][T.size()]<<endl;
	//generate the susbsequence 
	//This will generate the string in reverse
	string ans="";
	int i=S.size();
	int j=T.size();
	while(i>0 && j>0)
	{
		if(S[i-1]==T[j-1])
		{
			ans+=S[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
			i--;
		else 
			j--;
	}
	//Reverse the string to get the answer
	reverse(ans.begin(),ans.end());
	return ans;
}
int main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	//#ifndef ONLINE_JUDGE
	//freopen("inputf.in","r",stdin);
	//freopen("outputf.in","w",stdout);
	//#endif

	string S,T;
	cin>>S>>T;
	vector<string>v;
	string ans="";
	// Recursion Program

	/*
	generate(S,-1,v,ans);
	sort(v.begin(),v.end(),[](auto a ,auto b)
	{
		return a.size()>b.size();
	});
	ans="";
	vector<string>v2;
	generate(T,-1,v2,ans);
	unordered_set<string>st;
	for(string x:v2)
		st.insert(x);
	bool ok=false;
	for(int i=0;i<v.size();i++)
	{
		if(st.find(v[i])!=st.end())
		{
			cout<<v[i];
			ok=true;
			break;
		}
	}
	if(!ok)
		cout<<"";
	*/

	//Bottom up dp
	cout<<bottomup(S,T);
}

Measured memory_bytes: 35456
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <cmath>
using namespace std;
long long gcd(long long a, long long b) {
	if (a < b) gcd(b, a);
	long long  r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

long long modinv(long long a, long long mod) {
	long long 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);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}
namespace NTT {
	const int MOD = 998244353;  // to be set appropriately
	const long long PR = 3;     // to be set appropriately

	void trans(vector<long long> &v, bool inv = false) {
		int n = (int)v.size();
		for (int i = 0, j = 1; j < n - 1; j++) {
			for (int k = n >> 1; k >(i ^= k); k >>= 1);
			if (i > j) swap(v[i], v[j]);
		}
		for (int t = 2; t <= n; t <<= 1) {
			long long bw = modpow(PR, (MOD - 1) / t, MOD);
			if (inv) bw = modinv(bw, MOD);
			for (int i = 0; i < n; i += t) {
				long long w = 1;
				for (int j = 0; j < t / 2; ++j) {
					int j1 = i + j, j2 = i + j + t / 2;
					long long c1 = v[j1], c2 = v[j2] * w % MOD;
					v[j1] = c1 + c2;
					v[j2] = c1 - c2 + MOD;
					while (v[j1] >= MOD) v[j1] -= MOD;
					while (v[j2] >= MOD) v[j2] -= MOD;
					w = w * bw % MOD;
				}
			}
		}
		if (inv) {
			long long inv_n = modinv(n, MOD);
			for (int i = 0; i < n; ++i) v[i] = v[i] * inv_n % MOD;
		}
	}

	// C is A*B
	vector<long long> mult(vector<long long> A, vector<long long> B) {
		int size_a = 1; while (size_a < A.size()) size_a <<= 1;
		int size_b = 1; while (size_b < B.size()) size_b <<= 1;
		int size_fft = max(size_a, size_b) << 1;

		vector<long long> cA(size_fft, 0), cB(size_fft, 0), cC(size_fft, 0);
		for (int i = 0; i < A.size(); ++i) cA[i] = A[i];
		for (int i = 0; i < B.size(); ++i) cB[i] = B[i];

		trans(cA); trans(cB);
		for (int i = 0; i < size_fft; ++i) cC[i] = cA[i] * cB[i] % MOD;
		trans(cC, true);

		vector<long long> res((int)A.size() + (int)B.size() - 1);
		for (int i = 0; i < res.size(); ++i) res[i] = cC[i];
		return res;
	}
};
typedef pair<int, int> p;
typedef pair<int, p> pai;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int ans = s.length();
	int n = s.length();
	for (int i = 0; i < n - 1; i++) {
		if (s[i] != s[i + 1]) {
			ans = min(ans, max(i + 1, n - i-1));
		}
	}
	cout << ans;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct dice{
    int face[6];
}dice;

void rotate(dice *d, char dir)
{
    int temp;
    switch(dir) {
    case 'N':
        temp=d->face[0];
        d->face[0]=d->face[1];
        d->face[1]=d->face[5];
        d->face[5]=d->face[4];
        d->face[4]=temp;
        break;
    case 'E':
        temp=d->face[0];
        d->face[0]=d->face[3];
        d->face[3]=d->face[5];
        d->face[5]=d->face[2];
        d->face[2]=temp;
        break;
    case 'W':
        temp=d->face[0];
        d->face[0]=d->face[2];
        d->face[2]=d->face[5];
        d->face[5]=d->face[3];
        d->face[3]=temp;
        break;
    case 'S':
        temp=d->face[0];
        d->face[0]=d->face[4];
        d->face[4]=d->face[5];
        d->face[5]=d->face[1];
        d->face[1]=temp;
        break;
    }
}

int isSame(dice d1, dice d2)
{
    static const char dir[]="NNNESSSWNNNESSSWNNNESSSW";
    int i, j;
    for(i=0; i<24; i++) {
        for(j=0; j<6 && d1.face[j]==d2.face[j]; j++);
        if(j==6) return 1;
        rotate(&d2, dir[i]);
    }
    return 0;
}

int main()
{
    dice d[100];
    int i, j, n;
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        for(j=0; j<6; j++) {
            scanf("%d", &d[i].face[j]);
        }
        for(j=0; j<i; j++) {
            if(isSame(d[i], d[j])) {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll MAXN = 

ll n;
string str;

ll cnt[26];
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> n;
    cin >> str;

    REP (i,n) {
        cnt[str[i]-'a']++;
    }

    ll ans = 1;

    REP (i,26) {
        ans = ans * (cnt[i] + 1) % MOD;
    }

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


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    int a,b,c,x;
    scanf("%d%d%d",&a,&b,&c);
    x=a-b;
    if(x<c)
    {
        printf("%d\n",c-x);
    }
    else
        printf("0\n");
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll d[100100];

int main() {
  clr(d,-1);
  ll k;
  cin>>k;
  deque<ll> q1;
  deque<ll> q2;
  q1.push_back(1);
  q2.push_back(0);
  while(!q1.empty()){
    ll a = q1.front();
    ll b = q2.front();
    q1.pop_front();
    q2.pop_front();
    if(d[a]==-1){
      d[a] = b;
      q1.push_front(a*10%k);
      q2.push_front(b);
      q1.push_back((a+1)%k);
      q2.push_back(b+1);
    }
  }
  cout << d[0]+1 << endl;
  return 0;
}

Measured memory_bytes: 2688
#include <stdio.h>

#define MAX 100000
#define NIL -1

typedef struct
{
  int parent;
  int left;
  int right;
} TREE;

void SetDepth(TREE[], int, int[], int);
void PrintChildren(TREE[], int, int[]);
int GetRoot(TREE[], int);

int main()
{
  TREE tree[MAX];
  int depth[MAX];
  int n, id, k, c, l, root;
  int i, j;

  for (i = 0; i < MAX; i++)
  {
    depth[i] = 0;
    tree[i].parent = NIL;
    tree[i].left = NIL;
    tree[i].right = NIL;
  }

  scanf("%d", &n);

  for (i = 0; i < n; i++)
  {
    scanf("%d %d", &id, &k);

    for (j = 0; j < k; j++)
    {
      scanf("%d", &c);

      if (j == 0)
        tree[id].left = c;

      else
        tree[l].right = c;

      l = c;
      tree[l].parent = id;
    }
  }

  root = GetRoot(tree, 0);
  SetDepth(tree, root, depth, 0);

  for (i = 0; i < n; i++)
    PrintChildren(tree, i, depth);

  return 0;
}

void SetDepth(TREE tree[], int u, int depth[], int p)
{
  depth[u] = p;

  if (tree[u].right != NIL)
    SetDepth(tree, tree[u].right, depth, p);

  if (tree[u].left != NIL)
    SetDepth(tree, tree[u].left, depth, p + 1);
}

int GetRoot(TREE tree[], int u)
{
  while (tree[u].parent != NIL){
    u = tree[u].parent;
  }

  return u;
}

void PrintChildren(TREE tree[], int u, int depth[])
{
  int c;

  c = tree[u].left;

  printf("node %d: ", u);
  printf("parent = %d, ", tree[u].parent);
  printf("depth = %d, ", depth[u]);

  if (tree[u].parent == NIL)
    printf("root, ");

  else if (tree[u].left == NIL)
    printf("leaf, ");

  else
    printf("internal node, ");

  printf("[");

  while (c != NIL)
  {

    if (tree[c].right == NIL)
    {
      printf("%d", c);
      break;
    }

    else
    printf("%d, ",c);

    c = tree[c].right;
  }

  printf("]\n");
}



Measured memory_bytes: 8100
import java.util.Scanner;

class Main {

	static class Card {
		char suit;
		int num;
		int idx;

		public Card(char suit, int num, int idx) {
			this.suit = suit;
			this.num = num;
			this.idx = idx;
		}

	}

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(); // 要素の個数
		Card[] A = new Card[n];
		for (int i = 0; i < n; i++) {
			A[i] = new Card(scan.next().charAt(0), scan.nextInt(), i);
		}
		Quicksort(A, 0, n - 1);
		check(A, n);
		for (int i = 0; i < n; i++) {
				System.out.print(A[i].suit + " ");
				System.out.print(A[i].num);
				System.out.println();
		}

	}

	public static int Partition(Card[] num, int p, int r) {
		int x = num[r].num;
		int i = p - 1;
		for (int j = p; j < r; j++) {
			if (num[j].num <= x) {
				i = i + 1;
				Card tmp = num[i];
				num[i] = num[j];
				num[j] = tmp;
			}

		}
		Card tmp = num[i + 1];
		num[i + 1] = num[r];
		num[r] = tmp;
		return i + 1;
	}

	public static void Quicksort(Card[] A, int p, int r) {
		if (p < r) {
			int q = Partition(A, p, r);
			Quicksort(A, p, q - 1);
			Quicksort(A, q + 1, r);
		}
		// return A;
	}

	static void swap(String[] a, int idx1, int idx2) {
		String temp = a[idx1];
		a[idx1] = a[idx2];
		a[idx2] = temp;
	}

	static void check(Card[] A, int n) {
		for (int i = 0; i < n - 1; i++) {
			if (A[i].num == A[i + 1].num) {
				if (A[i].idx > A[i + 1].idx) {
					System.out.println("Not stable");
					return;
				}

			}
		}
		System.out.println("Stable");
	}

}



Measured memory_bytes: 108200
#include <iostream>

using namespace std;
int par[100010],sz[100010];
void init(int n){
	for(int i=0;i<n;i++){
		par[i] = i; sz[i] = 1;
	}
}
int find(int x){
	if(par[x]==x) return x;
	return par[x] = find(par[x]);
}
void unite(int x, int y){
	x = find(x); y = find(y);
	if(x==y) return;
	if(sz[x]>sz[y]) swap(x,y);
	par[x] = y;
	sz[y] += sz[x];
}
int dp[1010][1010][2];
int dfs(int x,int y,int z){
    if(x<0 || y<0) return 0;
    if(dp[x][y][z]!=-1) return dp[x][y][z];
    int cnt = dfs(x - 2,y + 1,z) + dfs(x,y - 1,1 - z) + dfs(x,y - 1,1 - z);
    if(cnt==0) return dp[x][y][z] = 1;
    return dp[x][y][z] = 0;
}

int main(){
    int i,j,v,cnt = 0;
    cin >> v;
    init(v);
    for(i=0;i<v;i++){
        for(j=0;j<v;j++){
            char c; cin >> c;
            if(c=='Y'){
                unite(i,j);
                cnt--;
            }
        }
    }
    cnt /= 2;
    for(i=0;i<=v;i++){
        for(j=0;j<=v;j++){
            dp[i][j][0] = -1; dp[i][j][1] = -1;
        }
    }
    dp[2][0][1] = 0; dp[1][1][1] = 0; dp[0][2][1] = 0;
    dp[2][0][0] = 1; dp[1][1][0] = 1; dp[0][2][0] = 1;
    int od = 0,ev = 0;
    for(i=0;i<v;i++){
        if(par[i]==i){
            if(sz[i]&1) od++;
            else ev++;
            cnt += sz[i]*(sz[i] - 1)/2;
        }
    }
    if(!dfs(od,ev,(cnt&1))) cout << "Taro" << endl;
    else cout << "Hanako" << endl;
}


Measured memory_bytes: 11052
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		int xmax = Integer.MIN_VALUE;
		int ymax = Integer.MIN_VALUE;
		int xmin = Integer.MAX_VALUE;
		int ymin = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			x[i] = a - b;
			y[i] = a + b;
			xmax = Math.max(xmax, x[i]);
			ymax = Math.max(ymax, y[i]);
			xmin = Math.min(xmin, x[i]);
			ymin = Math.min(ymin, y[i]);
		}
		int ret = 0;
		int ret2 = 0;
		for (int i = 0; i < n; i++) {
			ret = Math.max(
					ret,
					Math.min(dist(xmax, x[i], ymax, y[i]),
							dist(x[i], xmin, y[i], ymin)));
			ret2 = Math.max(
					ret2,
					Math.min(dist(xmax, x[i], y[i], ymin),
							dist(x[i], xmin, ymax, y[i])));
		}
		System.out.println(Math.min(ret, ret2));

	}

	private int dist(int a, int b, int c, int d) {
		return Math.max(a - b, c - d);
	}
}

Measured memory_bytes: 95616
from collections import Counter
S = input()
C = Counter()
MOD = 2019

n = 0
for i, s in enumerate(S[::-1]):
    s = int(s)
    n += pow(10, i, MOD) * s % MOD
    C[n % MOD] += 1

C[0] += 1
ans = 0
for v in C.values():
    ans += v * (v - 1) // 2
print(ans)


Measured memory_bytes: 9756
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#define ll long long

using namespace std;

int main(){
    string S;
    cin >> S;
    for(int i=0;i<3;i++){
        if(S[i]=='9'){
            cout << 1;
        }
        else if(S[i]=='1'){
            cout << 9;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
struct island{
	int x, y;
}a[maxn];
int cmp(island a, island b)
{
	return a.y<b.y;
}
int main()
{
	int n, m, ans=0;
	cin >> n >> m;
	for(int i=1;i<=m;i++)cin >> a[i].x >> a[i].y;
	sort(a+1,a+m+1,cmp);
	int t=0;
	for(int i=1;i<=m;i++)
	{
		if(a[i].x>=t)
		{
			t=a[i].y;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    string s;
    cin >> s;

    int sl = s.length();
    if (sl & 1) {
        puts("No");
        return 0;
    }

    for (int i = 0; i < sl; i += 2) {
        if (s[i] != 'h' || s[i+1] != 'i') {
            puts("No");
            return 0;
        }
    }

    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    string s, ans="No";
    cin>>s;
    if(s[0]==s[1] && s[0]==s[2])
        ans = "Yes";
    else if(s[1]==s[2] && s[1]==s[3])
        ans = "Yes";
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

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

		int N = sc.nextInt();

		int[] B = new int[100001];
		for(int i = 1 ; i <= N ; i++){
			int tmp  = sc.nextInt();
			if(tmp == 0){
				B[tmp]++;
				B[tmp+1]++;
			}
			else {
				B[tmp-1]++;
				B[tmp]++;
				B[tmp+1]++;
			}
		}
		sc.close();

		int ans = 0;
		for(int i = 0 ; i <= 100000 ; i++){
			ans = Math.max(ans, B[i]);
		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 53040
n = int(input())
s = []
for i in range(n):
    s.append(input())

cnt_end_a = 0
cnt_bgn_b = 0
cnt_end_a_bgn_b = 0

ans = 0
for i in range(n):
    if s[i][0] == 'B':
        if s[i][len(s[i])-1] == 'A':
            cnt_end_a_bgn_b += 1
        else:
            cnt_bgn_b += 1
    elif s[i][len(s[i])-1] == 'A':
        cnt_end_a += 1
    for j in range(len(s[i])-1):
        if s[i][j] == 'A' and s[i][j+1] == 'B':
            ans += 1

#print(cnt_end_a, cnt_bgn_b, cnt_end_a_bgn_b)

if cnt_end_a_bgn_b == 0:
    ans += min(cnt_bgn_b, cnt_end_a)
elif cnt_end_a == 0 and cnt_bgn_b == 0:
    ans += cnt_end_a_bgn_b - 1
elif cnt_end_a == 0:
    ans += cnt_end_a_bgn_b
elif cnt_bgn_b == 0:
    ans += cnt_end_a_bgn_b
else:
    ans += cnt_end_a_bgn_b + min(max(cnt_bgn_b, cnt_end_a), min(cnt_bgn_b, cnt_end_a))
print(ans)

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


vector<pair<long long,int>> factorize(long long n){
    vector<pair<long long,int>> res;
    for (long long i = 2; i*i <= n;++i){
        //if(n%i != 0)continue;
        if(n%i)continue;
        res.emplace_back(i,0);
        while(n%i == 0){
            n/=i;
            res.back().second++;
        }
    }
    if(n!= 1)res.emplace_back(n,1);
    return res;
}
 
int main() {
    int N;
    cin >> N;
    int count[1001] = {};
    long long total = 1;
    long long m = 1000000007;
    for(int i=1;i<=N;i++){
        auto F = factorize(i);
        for(auto f : F){
            count[f.first] += f.second;
        }
    }

    for(int i=1;i<=N;i++){
        if(count[i]){
            count[i] += 1;
            count[i] %= m;
            total *= count[i];
            total %= m;
        }
    }

    cout << total << endl;

    return 0;
} 

Measured memory_bytes: 256
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf3(a,b,c) printf("%d %d %d",a,b,c)
#define sfl(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld %lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pfl(a) printf("%lld",a)
#define pfl2(a,b) printf("%lld %lld",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
#define tz 100000
#define clr0(a) memset(a,0,sizeof(a))
#define clr1(a) memset(a,-1,sizeof(a))
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
int main()
{
    timesave;
    ll sum=0,i,a,n,m;

    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a;
        sum+=a;
    }
    if(n>=sum)
    {
        cout<<n-sum<<endl;
    }
    else
        cout<<-1<<endl;
}






Measured memory_bytes: 3616