akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<set>
#include <vector>
#include <string>

using namespace std;
#define ll long long

int main(){
    int N;
    int m=0,a=0,r=0,c=0,h=0;
    int d[5];
    ll ans=0;
    cin >> N;
    string S;
    for(int i = 0; i < 5; i++)d[i]=0;
    for(int i = 0; i < N; i++){
        cin >> S;
        if(S[0] == 'M')d[0]++;
        if(S[0] == 'A')d[1]++;
        if(S[0] == 'R')d[2]++;
        if(S[0] == 'C')d[3]++;
        if(S[0] == 'H')d[4]++;
    }
    for(int i = 0; i < 3; i++){
        for(int j = i + 1; j < 4; j++){
            for(int k = j + 1; k < 5; k++){
                // cout << i << j << k<< endl;
                if(k < 5) ans += d[i] * d[j] * d[k];
            }
        }
    }

    cout << ans << endl;

} 

Measured memory_bytes: 256
def combinations(N):
    comb = [[0] * (N + 1) for _ in range(N + 1)]
    comb[0][0] = 1
    for i in range(1, N + 1):
        for j in range(i + 1):
            comb[i][j] += comb[i - 1][j]
            if j > 0:
                comb[i][j] += comb[i - 1][j - 1]
    return comb


nCk = combinations(60)

N, A, B, *V = map(int, open(0).read().split())

V.sort(reverse=True)

num = V.count(V[A - 1])

ans = 0
if V[0] == V[A - 1]:
    ans = sum(nCk[num][A:B + 1])
else:
    a = V[:A].count(V[A - 1])
    ans = nCk[num][a]

ave = sum(V[:A]) / A

print("{:.9f}".format(ave))
print(ans)


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

main(){

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

    int n, a, k, counter = 0;
    cin >> n >> k;
    for(int i = 0; i < n; ++i){
        cin >> a;
        if(k <= a){
                counter++;
        }
    }
    cout << counter << '\n';
}


Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var money = - Infinity;
  var tmp = input[input[0]];
  for(let i = input[0]-1; i > 0; i--) {
    money = Math.max(money, tmp - Number(input[i]));
    tmp = Math.max(tmp, Number(input[i]));
  }
  console.log(money);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 37164
import sys
input = sys.stdin.readline
import copy

H, W = map(int, input().split(' '))
S = [list(input().rstrip('\r\n')) for _ in range(H)]

def judge(h, w):
    ok = False
    if h-1 >= 0 and S[h-1][w] == '#':
        ok = True
    if w-1 >= 0 and S[h][w-1] == '#':
        ok = True
    if w+1 < W and S[h][w+1] == '#':
        ok = True
    if h+1 < H and S[h+1][w] == '#':
        ok = True
    return ok
ans = 'Yes'
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            if judge(h, w) == False:
                ans = 'No'
print(ans)

Measured memory_bytes: 4340
#include <iostream>

#define MAX 10
using namespace std;

int main(){
  int count;
  int ball1,ball2,ball;
  cin >> count;
  for(int i=0;i<count;i++){
    ball1=0;ball2=0;
    for(int j=0;j<MAX;j++){
      cin >>ball;
      //cout << ball1 << " " << ball2 << endl;
      //      cout << ball << endl;
      //cout << j << endl;
      if(ball1 < ball || ball2 < ball){
	if(ball2<ball){
	  ball2=ball;
	}
	else{
	  ball1 = ball;
	}
	if(j==MAX-1){
	  cout << "YES";
	}
      }
      else{
	cout << "NO";
	for(int k=0;k<MAX-j;k++) cin >>ball;
	break;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  REP(i,h){
    cin>>s[i];
  }
  
  int cnt=0;
  REP(i,h){
    REP(j,w){
      if(s[i][j]=='.'){
        continue;
      }
      
      if(i-1>=0){
        if(s[i-1][j]=='#'){
          continue;
        }
      }
      
      if(i+1<h){
        if(s[i+1][j]=='#'){
          continue;
        }
      }
      
      if(j-1>=0){
        if(s[i][j-1]=='#'){
          continue;
        }
      }
      
      if(j+1<w){
        if(s[i][j+1]=='#'){
          continue;
        }
      }
      
      cout<<"No"<<endl;
      return 0;
    }
  }
  
  cout<<"Yes"<<endl;
  return 0;
}

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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int a,b;
    cin>>a>>b;
    int ans=0;
    int x=1;
    while(x<b)
    {
    	ans++;
    	x--;
    	x+=a;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
x,n=map(int,input().split())
p=list(map(int,input().split()))
t=[]
a=x-1
b=x+1
if x not in p:
  t.append(x)

while t==[]:
  if a not in p:
    t.append(a)
  if b not in p:
    t.append(b)
  a-=1
  b+=1
print(min(t))  

Measured memory_bytes: 9196
N, M = map(int, input().split(' '))
ac_set = set()
wa_cnt_ls, wa_cnt = [ 0 for i in range(N) ], 0
for i in range(M):
    p, s = input().split(' ')
    idx = int(p) - 1
    if not idx in ac_set:
        if s == 'AC':
            ac_set.add(idx)
            wa_cnt += wa_cnt_ls[idx]
        else:
            wa_cnt_ls[idx] += 1
print(len(ac_set), wa_cnt)

Measured memory_bytes: 18204
n = int(input())
a = list(map(int, input().split()))

a.sort()

now = 0

ans = []

for i in range(n-2):
    if a[i+1] > 0:
        ans.append([a[0], a[i+1]])
        a[0] = a[0] - a[i+1]
    else:
        ans.append([a[n-1], a[i+1]])
        a[n-1] = a[n-1] - a[i+1]

ans.append([a[n-1],a[0]])
print(a[n-1]-a[0])

for i in ans:
    print(i[0],i[1])

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

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

    int S, W;
    cin >> S >> W;

    cout << ((S <= W) ? "unsafe" : "safe") << endl;

    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < (int)(n);++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define fi first
#define se second
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()


void fastik() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

//ifstream &cin
void solve(){

}

int main() {
    fastik();
    ll n,m;cin>>n>>m;
    vll l(m),r(m);
    ll mx = -1,mn=ll(2e9);
    forn(i,m){
        cin >> l[i] >> r[i];
        mx = max(mx,l[i]);
        mn = min(mn,r[i]);
    }

    if(mx > mn ){
        cout << 0;
    }else{
        cout << mn - mx + 1;
    }


}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

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

    if (n == 1) {
        cout << abs(a[0] - w) << "\n";
    } else {
        cout << max(abs(a[n-1] - w), abs(a[n-1] - a[n-2])) << "\n";
    }

    return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<string> S(N);

    vector<P> A;
    vector<P> B;

    REP(i, N){
        cin >> S[i];
        ll plus = 0;
        ll minus = 0;
        ll min_s = INF;
        ll last_s = 0;
        REP(j, S[i].length()){
            if(S[i][j] == '(') plus++;
            if(S[i][j] == ')') minus++;
            min_s = min(min_s, plus-minus);
            if(j == S[i].length()-1){
                last_s = plus-minus;
            }
        }
        P temp;
        if(last_s >= 0){
            A.emplace_back(min_s, last_s);
        }
        else{
            B.emplace_back(min_s-last_s, -last_s);
        }
    }

    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());

    ll left = 0;
    ll right = 0;

    for(auto v: A){
        if(left + v.first < 0){
            cout << "No" << endl;
            return 0;
        }
        left += v.second;
    }
    for(auto v: B){
        if(right + v.first < 0){
            cout << "No" << endl;
            return 0;
        }
        right += v.second;
    }
    if(left != right){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 50236
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    mut b:[usize;a*3],
    }
    b.sort();
    b.reverse();
    let mut z=0;
    for i in 0..a {
        z+=b[i*2+1]
    }
    println!("{}",z)
}

Measured memory_bytes: 7704
<?php
fscanf(STDIN, "%d", $n);
$sum = 0;
for ($i = 0; $i <= $n; $i++) {
    if ($i % 3 === 0 && $i % 5 ===0) {
        $sum += 0;
    } elseif ($i % 3 === 0) {
        $sum += 0;
    } elseif ($i % 5 === 0) {
        $sum += 0;
    } else {
        $sum += $i;
    }
}
echo $sum.PHP_EOL;


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A + B) > (C + D)){
    cout << "Left" << endl;
  }
  else if ((A+B) < (C + D)){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
} 

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N; char s[333];
    Scd(N);
    Scs(s);

    int ans = 0;
    Rep(i,N-2){
        ans += (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C');
    }

    printf ("%d\n", ans );

    return 0;
}



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

int main(void){
    
    vector<bool> array(1000000, true);
    array[0] = array[1] = false;
    for(int i = 2; i < 1000000; i++){
        if(array[i] == true){
            for(int j = 2*i; j < 1000000; j += i) array[j] = false; 
        }
    }

    vector<int> so;
    for(int i = 0; i < 1000000; i++){
        if(array[i] == true) so.push_back(i);
    }

    /*for(int i = 0; i < 10; i++){
        cout << so[i] << " ";
    }
    cout << endl;*/


    //  ?????????????§???????
    int N, P;
    while(1){
        cin >> N >> P;
        if(N == -1) break;
        int start = 0;
        while(1){
            if(so[start] > N) break;
            start++;
        }
        //cout << start << endl;
        //cout << 37 << endl;
        vector<int> sum;
        for(int i = start; i < start + P; i++){
            for(int j = start; j <= i; j++){
                sum.push_back(so[i] + so[j]);
            }
        }
        //cout << 44 << endl;
        sort(sum.begin(), sum.end());
        //cout << endl;
        //cout << 50 << endl;
        cout << sum[P - 1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3480
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main(){
  int n,c,cmin,c1,c2;
  string s,s1,s2;
  cin >> n >> s;
  s2 = s.substr(1, n-1);
  c1 = 0;
  c2 = count(s2.cbegin(), s2.cend(), 'E');
  cmin = c2;
  REP(i, 1, n) {
    if(s[i-1] == 'W') c1 += 1;
    if(s[i] == 'E') {
      c2 -= 1;
      c = c1 + c2;
      if(cmin > c) cmin = c;
    }
  }
  cout << cmin << endl;
}

Measured memory_bytes: 1028
# C - Count Order

N = int(input())
A = [str(i) for i in range(1, N + 1)]
P = ''.join([p for p in input().split()])
Q = ''.join([q for q in input().split()])

ans = []

def dfs(ls, s):
    if len(ls) == 0:
        ans.append(s)
    else:
        for i in range(len(ls)):
            dfs(ls[:i] + ls[i + 1:], s + ls[i])

dfs(A, '')
print(abs(ans.index(P) - ans.index(Q)))


Measured memory_bytes: 6040
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;

int main()
{
	int H,W;
	string s;
	vector<vector<char>> bord;
	cin >> H >> W;

	for(int i=0;i<H;i++){
		vector<char> t;
		cin >> s;
		for(int j=0;j<W;j++){
			t.push_back(s[j]);
		}
		bord.push_back(t);
	}
	//横を消去
	for(int i=H-1;i>=0;i--){
		size_t siro_count = count(bord[i].begin(), bord[i].end(), '.');
		if(siro_count==W){
			bord.erase(bord.begin()+i);
			H=H-1;
		}
	}
	//縦を消去
	for(int i=bord[0].size()-1;i>=0;i--){
		vector<char> t;
		for(int j=0;j<bord.size();j++){
			t.push_back(bord[j][i]);
		}
		size_t siro_count = count(t.begin(), t.end(), '.');
		if(siro_count==H){
			for(int k=0;k<H;k++){
				bord[k].erase(bord[k].begin()+i);
			}
		}
	}

	//出力
	for(int i=0;i<bord.size();i++){
		for(int j=0;j<bord[i].size();j++){
			cout << bord[i][j];
		}
		cout << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll MOD = 1000000007;

int main() {
    int k, n;
    cin >> k >> n;
    int A[n];
    int d = 0;
    rep(i, n) {
        cin >> A[i];
        if (i == 0) {
            continue;
        }
        if (A[i] - A[i - 1] > d) {
            d = A[i] - A[i - 1];
        }
    }
    if (A[0] + k - A[n - 1] > d) {
        d = A[0] + k - A[n - 1];
    }

    cout << k - d << endl;
    return 0;
}

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

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

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   ll ans = 0;
   for(int i = 1 ; i <= n ; i++)
      ans += 1ll * i * (n - i + 1);
   for(int i = 0 ; i < n - 1 ; i++){
      int u , v;
      cin >> u >> v;
      if(u > v)
         swap(u , v);
      ans -= 1ll * u * (n - v + 1);
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 3644
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
map<int,int> mp;
int32_t main() {
    IOS;

        ll n,a,b,sum=0;
        cin>>n;
        rep(i,0,n-1)
        {
        	cin>>a;
        	sum+=a;
        	++mp[a];
        }
        int q;
        cin>>q;
        while(q--)
        {
        	cin>>a>>b;
        	int x=mp[a];
        	sum-=x*a;
        	sum+=x*b;
        	cout<<sum<<endl;
        	mp.erase(mp.find(a));
        	mp[b]+=x;
        }

    return 0;
}

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

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

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

bool islight(
	const vector<vector<int>>& s,
	const set<int>& st,
	const vector<int>& p
) {
	vector<int> cnt(p.size(), 0);
	REP(i, s.size()) {
		for (int col : s[i]) if (st.find(col) != st.end()) {
			cnt[i]++;
		}
	}
	REP(i, p.size()) {
		if (cnt[i] % 2 != p[i] % 2)return false;
	}
	return true;
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<int>> s(M);
	vector<int> p(M);
	REP(i, M) {
		int k;
		cin >> k;
		s[i].resize(k);
		REP(j, k) {
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	REP(i, M)cin >> p[i];

	int res = 0;
	REP(i, 1 << N) {
		set<int> st;
		int buf = i;
		REP(j, N) {
			if (buf % 2 == 1)st.insert(j);
			buf >>= 1;
		}
		if (islight(s, st, p))res++;
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <deque>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <map>
#include <stack>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

int main(void)
{
    string s;
    cin >> s;
    for(int i = 0; i < 4; i++){
        printf("%c", s[i]);
    }
    printf(" ");
    for(int i = 4; i < s.size(); i++){
        printf("%c", s[i]);
    }
    puts("");
    return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ll comb(ll n, ll k) {
    if (n < k) return 0;
    ll a, b;
    a = 1;
    b = 1;
    for (ll i = 0; i < k; i++) {
        a *= n - i;
        b *= i + 1;
    }
    return a / b;
}

void solve() {
    ll K, S;
    cin >> K >> S;

    ll ans = comb(S + 2, 2) - comb(S - K + 1, 2) * 3 + comb(S - 2 * K, 2) * 3;
    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

#pragma GCC optimize("O2")

#define pb push_back
#define mp make_pair
#define ll long long
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REFOR(i, a, b) for(int i = (a); i > (b); i--)

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    ll n, d, a, b, ans = 0;
    cin >> n >> d;
    FOR(i, 0, n)
    {
    	cin >> a >> b;
    	if((a * a + b * b) <= d * d)
    		ans++;
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node tree_minimum(Node x){

    while(x->left != NULL){
      x = x->left;
    }
    return x;
}

Node tree_search(Node u, int k){

    if(u->key > k){
        if(u->left==NIL){  /* もし左側になければ，keyはない */
            return NIL;
        }
        return tree_search(u->left, k);
    }
    /* 自分より大きい値ならば，右側 */
    if(u->key < k){
        if(u->right == NULL){
            return NULL;      /* もし右側になければ，keyはない */
        }
        return tree_search(u->right, k);
    }

    return u;
}

Node tree_successor(Node x){
  Node y;
  if (x->right != NIL){
    return tree_minimum(x->right);
  }
  y = x->parent;
  while (y != NIL && x == y->right){
    x = y;
    y = y->parent;
    return y;
  }
}


void tree_delete(Node z){
  Node x,y;
  if(z != NIL){
      if(z->left == NIL || z->right == NIL){
         /* 左か右，どちらかがNULLであった場合(両方NULLの場合も含む) */
          y = z;
          if(z->left != NIL){
              x = y->right;
          } else {
             x = y->right;
          }

      } else if(x != NIL) {

          x->parent = y->parent;
          if(y->parent == NIL){
            root = x;
          } else if(y = y->parent->left){
              y->parent->left = x;
          } else {
              y->parent->right = x;
          }
      }
  }

      if (y != z){
        z->key = y->key;
        z->parent = y->parent;
        z->left = y->left;
        z->right = y->right;
      }
}

void insert(int k){

  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

    while(x != NIL){
        y = x;
        if (z->key < x->key){
            x = x->left;
        }else {
            x = x->right;
        }
    }
    z->parent = y;

    if (y == NIL){
        root = z ;
    } else if (z->key < y->key){
        y->left = z;
    } else {
        y->right = z;
    }
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  if (u != NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = tree_search(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      tree_delete(tree_search(root, x));
    }
  }
  return 0;
}

Measured memory_bytes: 24040
#include<bits/stdc++.h>
using namespace std;
int main(void) {
    int n;
    cin >> n;
    string a, b;
    int t = 0, h = 0;
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        if(a > b) t += 3;
        else if(a == b) ++t, ++ h;
        else h += 3;
    }
    cout << t << ' ' << h << endl;
    return 0;
}


Measured memory_bytes: 3136
import java.util.*;

public class Main {
    final static int MOD = 1000000007;
    
    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        int n = in.nextInt();
        int[] d = in.nextIntArray(n);
        int ans = 0;
    
        for (int i = 0; i < d.length - 1; i++) {
            for (int j = i+1; j < d.length; j++) {
                ans = ans + ( d[i]*d[j]);
            }
        }
        System.out.println(ans);
        
        
        
        
    }
    
    static class MyScanner {
        static Scanner sc = new Scanner(System.in);
        
        String next() {
            return sc.next();
        }
        
        String nextLine() {
            return sc.nextLine();
        }
        
        int nextInt() {
            return Integer.parseInt(sc.next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }
        
        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextDouble();
            }
            return array;
        }
        
        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextLong();
            }
            return array;
        }
        
        String[] nextLineArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextLine();
            }
            return array;
        }
        
        int[][] nextIntMatrix(int n, int m) {
            int[][] matrix = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    matrix[i][j] = nextInt();
                }
            }
            return matrix;
        }
        
        double[][] nextDoubleMatrix(int n, int m) {
            double[][] matrix = new double[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    matrix[i][j] = nextDouble();
                }
            }
            return matrix;
        }
        
        long[][] nextLongMatrix(int n, int m) {
            long[][] matrix = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    matrix[i][j] = nextLong();
                }
            }
            return matrix;
        }
    }
}

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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double eps = 1e-7;
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(const auto &buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
#define INF INFINITY
bool feq(double x, double y) { return abs(x - y) <= eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int ret = 0;	x--; while (x > 0) { ret++; x >>= 1; } return ret; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

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

int main() {
	int m1, d1, m2, d2; cin >> m1 >> d1 >> m2 >> d2;
	if (m1 != m2) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int h, n;
    scanf("%d%d", &h, &n);
    std::vector<std::pair<int, int>> magics(n);
    for(auto &&p : magics) scanf("%d%d", &p.first, &p.second);
    constexpr int MAX_N = 1000, MAX_H = 10000;
    // dp配列 dp[i][h]:魔法i以下のものを使って，体力をへらすために必要な魔力の最小値
    std::vector<i64> dp(2 * MAX_H + 10, 1LL << 30);
    dp[0] = 0;  // 体力を0へらすには0でいい
    rep(i, n) {
        rep(j, 2 * MAX_H) {
            if(j >= magics[i].first) {
                dp[j] = std::min(dp[j], dp[j - magics[i].first] + magics[i].second);
            }
        }
    }
    std::cout << *std::min_element(dp.begin() + h, dp.end()) << std::endl;
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

const int MOD = 1000000007;

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

	string s;
	cin >> s;

	if(a >=3200){
		cout << s << endl;
	}else{
		cout << "red" << endl;
	}

	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

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

signed main() {
  int X;
  cin >> X;
  int ans;
  if (X < 600) {
    ans = 8;
  } else if (X < 800) {
    ans = 7;
  } else if (X < 1000) {
    ans = 6;
  } else if (X < 1200) {
    ans = 5;
  } else if (X < 1400) {
    ans = 4;
  } else if (X < 1600) {
    ans = 3;
  } else if (X < 1800) {
    ans = 2;
  } else if (X < 2000) {
    ans = 1;
  } 

  cout << ans << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define no_of_test(x)        int x; cin>>x; while(x--)
#define inf             1e18
const int mod = 1e9 + 7;
void very_fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}


int32_t main()
{
	very_fast();
	//no_of_test(x)
	{
		string a, b;
		cin >> a >> b;
		int n = b.size(), m = a.size();

		int ans = 10000;


		for (int i = 0; i < m - n + 1; i++)
		{
			int cnt = 0;
			for (int j = 0; j < n; j++)
			{
				if (b[j] != a[i + j])
				{
					cnt++;
				}
			}
			ans = min(cnt, ans);
		}
		cout << ans << "\n";
	}
	return 0;
}


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

using namespace std;
typedef long long ll;

// #define DEBUG

void enumerate_comnination(vector<int> x)
{
    ll s = 0;
    for (auto y : x)
        s += pow(2, y);
    cout << s << ":";
    for (auto y : x)
        cout << " " << y;
    cout << endl;
}

main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, k, m;
    cin >> n >> k;
    int b[k];
    for (int i = 0; i < k; i++)
        cin >> b[i];

    for (int i = 0; i < pow(2, k); i++)
    {
        ll d = 0;
        int h = i;
        vector<int> x;
        for (int j = 0; j < k; j++)
        {
            if (h % 2)
            {
                x.push_back(b[j]);
                d += pow(2, b[j]);
            }
            h /= 2;
        }
        cout << d << ":";
        for (auto y : x)
            cout << " " << y;
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3312
attrs = Array.new
while line = $stdin.gets
    attrs << line.chomp.split.map{|v| v.to_i }
end

N = attrs.shift[0]
X = attrs.shift

results = []
for p in 1..100 do
  sum = 0
  for i in 0...N do
    sum += (X[i] - p) ** 2
  end
  results << sum
end
puts results.min

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

int main(){
  int n; cin>>n;
  int sum; cin>>sum;
  for(int i=1;i<n;i++){
    int a; cin>>a;
    sum^=a;
  }
  if(sum==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

using namespace std;

template <typename T>
T power(T a, long long b) {
  T r = 1;
  while (b) {
    if (b & 1) {
      r *= a;
    }
    a *= a;
    b >>= 1;
  }
  return r;
}

int inverse(int a, int m) {
  a %= m;
  if (a < 0) {
    a += m;
  }
  int b = m, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= a * t;
    swap(a, b);
    u -= v * t;
    swap(u, v);
  }
  if (u < 0) {
    u += m;
  }
  return u;
}

template <int _P>
struct modnum {
  static constexpr int P = _P;

 private:
  int v;

 public:
  modnum() : v(0) {
  }

  modnum(long long _v) {
    v = _v % P;
    if (v < 0) {
      v += P;
    }
  }

  explicit operator int() const {
    return v;
  }

  bool operator==(const modnum& o) const {
    return v == o.v;
  }

  bool operator!=(const modnum& o) const {
    return v != o.v;
  }

  modnum inverse() const {
    return modnum(::inverse(v, P));
  }

  modnum operator-() const {
    return modnum(v ? P - v : 0);
  }
  
  modnum operator+() const {
    return *this;
  }

  modnum& operator++() {
    v++;
    if (v == P) {
      v = 0;
    }
    return *this;
  }
  
  modnum& operator--() {
    if (v == 0) {
      v = P;
    }
    v--;
    return *this;
  }

  modnum operator++(int) {
    modnum r = *this;
    ++*this;
    return r;
  }
  
  modnum operator--(int) {
    modnum r = *this;
    --*this;
    return r;
  }

  modnum& operator+=(const modnum& o) {
    v += o.v;
    if (v >= P) {
      v -= P;
    }
    return *this;
  }

  modnum operator+(const modnum& o) const {
    return modnum(*this) += o;
  }

  modnum& operator-=(const modnum& o) {
    v -= o.v;
    if (v < 0) {
      v += P;
    }
    return *this;
  }

  modnum operator-(const modnum& o) const {
    return modnum(*this) -= o;
  }

  modnum& operator*=(const modnum& o) {
    v = (int) ((long long) v * o.v % P);
    return *this;
  }

  modnum operator*(const modnum& o) const {
    return modnum(*this) *= o;
  }
  
  modnum& operator/=(const modnum& o) {
    return *this *= o.inverse();
  }

  modnum operator/(const modnum& o) const {
    return modnum(*this) /= o;
  }
};

template <int _P>
ostream& operator<<(ostream& out, const modnum<_P>& n) {
  return out << int(n);
}

template <int _P>
istream& operator>>(istream& in, modnum<_P>& n) {
  long long _v;
  in >> _v;
  n = modnum<_P>(_v);
  return in;
}

using num = modnum<998244353>;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int g = max(n, m);
  vector<num> fact(g + 1);
  fact[0] = 1;
  for (int i = 1; i <= g; ++i) {
    fact[i] = fact[i - 1] * i;
  }
  vector<num> ifact(g + 1);
  ifact[g] = num(1) / fact[g];
  for (int i = g - 1; ~i; --i) {
    ifact[i] = ifact[i + 1] * (i + 1);
  }
  auto c = [&](int a, int b) {
    return fact[a] * ifact[b] * ifact[a - b];
  };
  num ans = 0;
  for (int i = 0; i <= min(n, m); ++i) {
    ans += c(n, i) * c(m, i) * power(num(n + 1), m - i) * power(num(m + 1), n - i) * fact[i] * ((i & 1) ? -1 : 1);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4224
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Row []string

type Data []Row

func main() {
	nextReader = newScanner()
	N := nextInt()
	list := map[string]int{}
	for i := 0; i < N; i++ {
		list[nextString()] = 1
	}
	fmt.Printf("%d", len(list))
}

var nextReader func() string

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	// r.Split(bufio.ScanLines)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func CustomScan(data []byte, atEOF bool) (advance int, token []byte, err error) {
	for i := 0; i < len(data); i++ {
		if data[i] == ' ' {
			return i + 1, data[:i], nil
		}
	}
	fmt.Println(data)
	return 0, data, bufio.ErrFinalToken
}

func nextStrings() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	// r.Split(bufio.ScanWords)
	r.Split(CustomScan)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}


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

int main () {
    int n,a1;
    cin>>n;
    vector<int> h(n);
    vector<int> dp(n);
    for(a1=0;a1<n;++a1){
        cin>>h[a1];
    }
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(a1=2;a1<n;++a1){
        dp[a1]=min(abs(h[a1-1]-h[a1])+dp[a1-1],abs(h[a1-2]-h[a1])+dp[a1-2]);
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1024
a,b = map(int,input().split())
li = []
for i in range(100*100):
    h = i//100
    w = i%100
    if(w<50):
        li.append('.')
    else:
        li.append('#')
nokori = b-1
for i in range(100):
    if(nokori == 0):
        break
    if(i%2 == 1):
        continue
    for j in range(50):
        if(j%2 == 1):
            continue
        if(nokori == 0):
            break
        nokori -= 1
        li[i*100+j]='#'
nokori = a-1
for i in range(100):
    if(nokori == 0):
        break
    if(i%2 == 0):
        continue
    for j in range(50,100):
        if(j%2 == 0):
            continue
        if(nokori == 0):
            break
        nokori -= 1
        li[i*100+j]='.'
print(100,100)
ans = ["" for i in range(100)]
for i in range(100):
    for j in range(100):
        ans[i] += li[i*100+j]
for hoge in ans:
    print(hoge)


Measured memory_bytes: 3188
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 3188
a,b,c=map(int,raw_input().split())
if(a>b):
 tmp=a
 a=b
 b=tmp
if(b>c):
 tmp=b
 b=c
 c=tmp
if(a>b):
 tmp=b
 b=a
 a=tmp
print str(a)+" "+str(b)+" "+str(c)

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  if(N%2==1&&N>2)
    cout<<"No";
  else if(N<2)
    cout<<"No";
  else{
  string S;
  cin>>S;
  int flag=0;
  for(int i=0;i<N/2;i++)
  { if(S[i]!=S[i+N/2]){
  flag++;
    break;
  }
  }
    if(flag!=0)
      cout<<"No";
    else
      cout<<"Yes";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int N,M,R,r[8],A,B,C,d[201][201],i,j,k;
main(){
	scanf("%d%d%d",&N,&M,&R);
	for(i=0;i<R;++i)scanf("%d",r+i);
	std::sort(r,r+R);
	for(;~scanf("%d%d%d",&A,&B,&C);)d[A][B]=d[B][A]=C;
	for(k=0;k++<N;)for(i=0;i++<N;)for(j=0;j++<N;){
		if(!d[i][j])d[i][j]=1e9;
		d[i][j]=std::min(d[i][j],d[i][k]+d[k][j]);
	}
	int x=1e9;
	do{
		int y=0;
		for(i=0;i+1<R;++i)y+=d[r[i]][r[i+1]];
		x=std::min(x,y);
	}while(std::next_permutation(r,r+R));
	printf("%d",x);
}


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

int main() {
  int N;
  cin >> N;
  int c=1;
  vector<int> bot(N);
  for (int i=0;i<N;i++)
    cin >> bot.at(i);
  for (int j=0;j<N;j++){
    c=bot.at(c-1);
    if(c==2){
      cout << j+1 << endl;
      break;
    }
    else if (j==N-1)
      cout << -1 << endl;
  }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+100;
const ll p=1e9+7;

ll inv(ll a,ll p) { //p为素数,a<p
    if(a==1)return 1;
    return (p-p/a)*inv(p%a,p)%p;
}

ll sum(ll r,ll c){
    if(r<=0||c<=0)return 0;
    if(c==1)return r;
    ll s=0,a=1,b=1;
    for(ll x=1;x<=c-1;++x)
        a=(a*x)%p;
    ll x=2,y=c;
    for(ll i=x;i<=y;++i)
        b=(b*i)%p;
    a=inv(a,p);
    s+=b*a%p;
    ++y;
    while(y<=r+c-1){
        b=b*inv(x++,p)%p;
        b=b*(y++)%p;
        s=(s+b*a)%p;
    }
    return s;
}

int main(){
    ll r1,c1,r2,c2;
    cin>>r1>>c1>>r2>>c2;
    ++r1;++c1;++r2;++c2;
    cout<<(sum(r2,c2)+sum(r1-1,c1-1)-sum(r2,c1-1)-sum(r1-1,c2)+2*p)%p;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

const INF = 1000000000

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	diff := (((n - 1) * (n - 2)) / 2) - k
	if diff < 0 {
		fmt.Println(-1)
		return
	}
	fmt.Println((n - 1) + diff)
	for i := 1; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if diff > 0 {
				fmt.Println(i, j)
				diff--
			}
		}
		fmt.Println(i, n)
	}
}


Measured memory_bytes: 768
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
using namespace std;

int main()
{
	int x, y;
	cin >> x >> y;
	if ((x + y) < 10)
		cout << (x + y) << endl;
	else 
		cout << "error" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 1000000

int prime[MAX];

int main(void)
{
	int i;
	int j;
	int n;
	int count;
	
	for (i = 2; i < MAX; i++){
		prime[i] = 1;
	}
	
	for (i = 2; i * i < MAX; i++){
		if(prime[i]){
			for (j = i * i; j < MAX; j += i){
				prime[j] = 0;
			}
		}
	}
	
	while (scanf("%d", &n) != EOF){
		count = 0;
		for (i = 0; i <= n; i++){
			count += prime[i];
		}
		printf("%d\n", count);
	}
	
	return (0);
}

Measured memory_bytes: 4496