akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main (String args[])
    {
       
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        //aとbが0以下かつ
        ArrayList<Long> result = new ArrayList<>();
        
        result.add(a*c);
        result.add(a*d);
        result.add(b*c);
        result.add(b*d);

        Long max = Collections.max(result);
        System.out.println(max);
    }
}

Measured memory_bytes: 35772
package main

import (
	"fmt"
)
func make_matrix(h, w int) ([][]int){
	matrix := make([][]int, h)
	for i:=0; i<h; i++{
		matrix[i] = make([]int, w)
	}
	
	for i:=0; i<h; i++{
		for j:=0; j<w; j++{
			fmt.Scan(&matrix[i][j])
		}
	}
	return matrix
}
func main(){
	var n, m, f, c int
	fmt.Scan(&n, &m, &f)
	a := make_matrix(n, m)
	b := make_matrix(m, f)
	for i:=0; i<n; i++{
		for j:=0; j<f; j++{
			c = 0
			for k:=0; k<m; k++{
				c += a[i][k] * b[k][j]
			}
			fmt.Print(c)
			if j != f-1{
				fmt.Print(" ")
			} else {
				fmt.Print("\n")
			}
		}
	}
}


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

int main(void){
  int n, a[100];
  int swpCnt=0;
  cin >> n;
  for (int i=0; i<n; i++) cin >> a[i];
  for (int i=n-1; i>=0; i--){
    int swapped = 0;
    for (int j=0; j<i; j++){
      if (a[j]>a[j+1]){
        int tmp;
        tmp = a[j]; a[j] = a[j+1]; a[j+1] = tmp;
        swapped = 1;
        swpCnt++;
      }
    }
    if (swapped==0) break;
  }
  for (int i=0; i<n-1; i++) cout << a[i] << " ";
  cout << a[n-1] << endl;
  cout << swpCnt << endl;
  return 0;
}



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

typedef long long ll;

int h[7] = {
	5000000,
	2500000,
	1250000,
	 625000,
	 312500,
	 156250,
	  78125
};

int pow10(int x){
	int res = 1;
	for(int i = 0 ; i < x ; i++ ) res *= 10;
	return res;
}

int main(){
	int Q;
	
	cin >> Q;
	for(int i=0 ; i < Q ; i++ ){
		ll n = 0;
		for(int j=0 ; j < 8 ; j++ ){
			char c;
			cin >> c;
			if( 'a' <= c ){
				c = c - 'a' + 10;
			}else{
				c = c - '0';
			}
			n = n * 16ll + c;
		}
		
		if( n & (1ll << 31) ) cout << "-";
		
		ll a = 0;
		for(int j = 7; j < 31 ; j++ ){
			int k = j - 7;
			if( n & (1ll << j) ) a += (1ll << k);
		}
		cout << a << ".";
		
		int b = 0;
		for(int j = 6 ; j >= 0 ; j-- ){
			int k = 6 - j;
			if( n & (1ll << j) ) b += h[k];
		}
		if( b == 0 ){
			cout << 0;
		}else{
			int k = 7;
			for(int j=6, b_ = b ; j >= 0 ; j-- ){
				int d = 6 - j;
				if( b_ % 10 == 0 ){
					k = j;
					b_ /= 10;
				}else{
					break;
				}
			}
			for(int j = 0 ; j < k ; j++ ){
				cout << (b / pow10(6 - j)) % 10;
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1160
import Control.Applicative ((<$>), (<*>))
import Data.List (foldl')

main :: IO ()
main = solve <$> readLn <*> getLine >>= print

solve :: Int -> String -> Int
solve n ss = g . foldl' f (n, 0, l) $ ss
  where l = length $ filter (== 'E') ss
        f (ct, wc, ec) ld | ld == 'W' = let ct' = wc + ec in (min ct ct', wc+1, ec)
                          | otherwise = let ct' = wc + ec - 1 in (min ct ct', wc, ec-1)
        g (x, _, _) = x


Measured memory_bytes: 68988
#include<bits/stdc++.h>
using namespace std;
long N,i,j,mod=1e9+7,ans;
int main(){
  cin>>N;
  vector<long> A(N);
  for(auto& a:A)cin>>a;
  for(i=0;i<60;i++){
    long cnt=0;
    for(auto a:A)cnt+=a>>i&1;
    cnt=cnt*(N-cnt)%mod;
    for(j=0;j<i;j++)cnt=cnt*2%mod;
    ans+=cnt;
  }
  cout<<ans%mod<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main(){
    ll x,ans=1;
    cin >> x;
    
    for(int i=1;i<33;i++){
        for(int j=2;j<10;j++){
            ll total;
            total=pow(i,j);
            if(x>=total){
                ans=max(ans,total);
            }
        }
    }
    
    cout << ans << endl;
    
    
    
    return 0;
}








Measured memory_bytes: 384
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize("SEX_ON_THE_BEACH")	
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/STACK:36777216")

#define _CRT_SECURE_NO_WARNINGS

#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>//////////////
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define queuel queue<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(), v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for (auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for (int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for (int i = 0; i < n; ++i){int a; cin >> a; s.insert(a); }
#define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); srand(time(NULL))
#define sp system("pause")
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;//СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚
					//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define int ll
const int MAXN = 2e5 + 1;
const ll inf = 1e9;
const ld EPS = 1e-4;
const ld PI = acos(-1);
int mod = (int)998244353;
//const int MOD = 1000000007;
const int MOD9 = 1000000009;
const int a228 = 18;
const ll MOD = 1000000007;
const int maxelem = 12000000;
const int fsconst = 12000;
signed main()
{
	fastio();
	int a, b;
	cin >> a >> b;
	cout << max({ a + b,  a - b, a *b });
	//sp;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

int main(){
    ll N,A; cin>>N>>A;
  cout<<N*N-A;
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct sumSet
{
  int small;
  int big;
};

int main(){
  int x, y, s;
  
  while (true) { 
    cin >> x >> y >> s;
    if (x * y * s == 0) {
    break;
    }
    int before[s+1]; 
    int res;
    int tempmax = 0;
    int max = 0;
    max = (s*100 / (100 + x) + 2) * (100 + y) / 100;
    sumSet sumset[s/2 + 1] = {
    };
    for (int i = 1; i <= s; i++) {
      before[i] = i*(100 + x) / 100;
    }
    for (int i = 1; i <= s/2; i++) {
      for (int j = i; j <= s; j++) {
        if (before[i]+before[s-j] == s) {
          sumset[i].small = i;
          sumset[i].big = s-j;
       }
      } 
    }

    for (int i = 1; i <= s/2; i++) {
      res = sumset[i].small * (100 + y) / 100 + sumset[i].big * (100 + y) / 100;
      if (res == max) {
        tempmax = max;
        break;
      }
      else if(res < max && tempmax < res) {
        tempmax = res;
        continue;
      }
      else if (res < max && res < tempmax) {
        continue;
      }
    }
    cout << tempmax << endl;
  }
  return 0;
}

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

int main() {
  int n,a;
  cin >> n;
  set<int> s;
  
  for (int i=0 ; i<n; i++) {
    cin >>a;
    if (s.count(a)) {
      s.erase(a);
    }
    else {
      s.insert(a);
    }
  }
  
  cout << s.size() << endl;
    
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> X >> A >> B;
    if (B > X + A) {
        cout << "dangerous" << endl;
    } else if (B > A) {
        cout << "safe" << endl;
    } else {
        cout << "delicious" << endl;
    }
}

Measured memory_bytes: 3620
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    int N,R;
    cin>>N>>R;
    if(N>=10) cout<<R<<endl;
    else cout<<R+100*(10-N)<<endl;
}


Measured memory_bytes: 3180
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    if (s.length() == 2) {
      System.out.println(s);
    } else {
      System.out.println("" + s.charAt(2) + s.charAt(1) + s.charAt(0));
    }
  }
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  int f[100][14];
  int p[100][15];
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < 10; j++) cin >> f[i][j];
  }
  for(int i = 0; i < n; ++i) for(int j = 0; j < 11; ++j) cin >> p[i][j];
  int res = -(1<<30);
  for(int b = 1; b < (1<<10); ++b) {
    int cc = 0;
    for(int i = 0; i < n; ++i) {
      int c = 0;
      for(int j = 0; j < 10; ++j) if((b>>j&1)&&f[i][j]) c++;
      cc+=p[i][c];
    }
    if(res<cc) res=cc;
  }
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  rep(i, 26){
    string nw = s;
    nw.push_back(i + 'a');
    if(t == nw){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int V, R, x[100], y[100], s, t, TAISA_[100];
pair<int, int>p[100];
pair<double, pair<int, int>>q[1000];

int ei1333(int x) {
	if (TAISA_[x] < 0)return x;
	return TAISA_[x] = ei1333(TAISA_[x]);
}

bool ei13333(int x, int y) {
	x = ei1333(x);
	y = ei1333(y);
	if (x == y)return false;
	if (TAISA_[x] < TAISA_[y]) {
		TAISA_[x] += TAISA_[y];
		TAISA_[y] = x;
	}
	else {
		TAISA_[y] += TAISA_[x];
		TAISA_[x] = y;
	}
	return true;
}

double dist(int p, int q) {
	return sqrt((x[p] - x[q])*(x[p] - x[q]) + (y[p] - y[q])*(y[p] - y[q]));
}

double cross(int p, int q, int r) {
	int x1 = x[r] - x[q];
	int x2 = x[q] - x[p];
	int y1 = y[r] - y[q];
	int y2 = y[q] - y[p];
	return x1*y2 - x2*y1;
}

int main() {
	cin >> V >> R;
	for (int i = 0; i < V; ++i) {
		cin >> x[i] >> y[i];
		TAISA_[i] = -1;
		p[i] = mkp(x[i], i);
	}
	for (int i = 0; i < R; ++i) {
		cin >> s >> t;
		--s;
		--t;
		q[i] = (mkp(dist(s, t), mkp(s, t)));
	}
	sort(p, p + V);
	sort(q, q + R);
	vector<int>u, d;
	u.push_back(p[0].second);
	u.push_back(p[1].second);
	for (int i = 2; i < V; ++i) {
		while (u.size() >= 2 && cross(u[u.size() - 2], u.back(), p[i].second) < 0) {
			u.pop_back();
		}
		u.push_back(p[i].second);
	}
	d.push_back(p[V - 1].second);
	d.push_back(p[V - 2].second);
	for (int i = V - 3; i >= 0; --i) {
		while (d.size() >= 2 && cross(d[d.size() - 2], d.back(), p[i].second) < 0) {
			d.pop_back();
		}
		d.push_back(p[i].second);
	}
	double res = 0;
	for (int i = 0; i < u.size() - 1; ++i) {
		res += dist(u[i], u[i + 1]);
		ei13333(u[i], u[i + 1]);
	}
	for (int i = 0; i < d.size() - 1; ++i) {
		res += dist(d[i], d[i + 1]);
		ei13333(d[i], d[i + 1]);
	}
	for (int i = 0; i < R; ++i) {
		if (ei13333(q[i].second.first, q[i].second.second))res += q[i].first;
	}
	printf("%.10f\n", res);
}


Measured memory_bytes: 3260
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;


int main(){
    int input[3];
    int N;
    
    cin>>N;
    
    for(int i=0;i<N;i++){
        cin>>input[0]>>input[1]>>input[2];
        sort(input,input+3);
        cout<<((input[2]==sqrt(pow(input[1],2)+pow(input[0],2)))?"YES":"NO")<<endl;
    }
    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
using namespace std;

typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 10;
const int MAX = 1e9 + 1;
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int n;
int a, b;
int mp[26];

bool ok1() {
    for (int i = 0; i < 26; ++i) {
        if (!mp[i])
            continue;
        if (mp[i] % 4 != 0)
            return 0;
    }
    return 1;
}

bool ok2() {
    int four = a * b - (a + b - 1);
    four /= 4;
    int i;
    for (i = 0; i < 26; ++i) {
        int t = min(mp[i] / 4, four);
        mp[i] -= t * 4;
        four -= t;
    }
    if (four)
        return 0;
    int two = a / 2 + b / 2;
    for (i = 0; i < 26; ++i) {
        int t = min(mp[i] / 2, two);
        mp[i] -= t * 2;
        two -= t;
    }
    if (two)
        return 0;
    for (i = 0; i < 26; ++i) {
        if (mp[i])
            return 1;
    }
    return 0;
}

bool ok3() {
    int even = a % 2 == 0 ? a : b;
    int four = a * b - even;
    four /= 4;
    int i;
    for (i = 0; i < 26; ++i) {
        int t = min(mp[i] / 4, four);
        mp[i] -= t * 4;
        four -= t;
    }
    if (four)
        return 0;
    int two = even / 2;
    for (i = 0; i < 26; ++i) {
        int t = min(mp[i] / 2, two);
        mp[i] -= t * 2;
        two -= t;
    }
    return !two;
}

int main() {
    int i, j;
    cin >> a >> b;
    char c;
    for (i = 0; i < a; ++i) {
        for (j = 0; j < b; ++j) {
            cin >> c;
            ++mp[c - 'a'];
        }
    }

    if (a % 2 == 0 && b % 2 == 0) {
        cout << (ok1() ? "Yes" : "No") << endl;
    }
    else if (a % 2 == 1 && b % 2 == 1) {
        cout << (ok2() ? "Yes" : "No") << endl;
    }
    else {
        cout << (ok3() ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<bool> c(N * 2, false);
  for (int i = 0; i < M; i++){
    int a, L;
    cin >> a >> L;
    for (int j = a; j < a + L; j++){
      c[j % N] = true;
    }
  }
  bool all = true;
  for (int i = 0; i < N; i++){
    c[N + i] = c[i];
    if (!c[i]){
      all = false;
    }
  }
  /*
  for (int i = 0; i < N * 2; i++){
    cout << c[i];
  }
  cout << endl;
  */
  if (all){
    cout << N << ' ' << 1 << endl;
  } else {
    int s = 0;
    while (c[s]){
      s++;
    }
    map<int, int> mp;
    int curr = 0;
    for (int i = s; i <= N + s; i++){
      if (c[i]){
        curr++;
      } else {
        if (curr != 0){
          mp[curr]++;
        }
        curr = 0;
      }
    }
    vector<pair<int, int>> ans;
    for (auto P : mp){
      ans.push_back(make_pair(P.first, P.second));
    }
    sort(ans.begin(), ans.end());
    reverse(ans.begin(), ans.end());
    int cnt = ans.size();
    for (int i = 0; i < cnt; i++){
      cout << ans[i].first << ' ' << ans[i].second << endl;
    }
  }
}


Measured memory_bytes: 3112
#include <stdio.h>
#include <algorithm>
using namespace std;
const int maxn=1e6+10,inf=1e9+7;
typedef long long ll;
ll h,w,node[maxn],n,a,b,cnt=0,zero,ans[15];

int main(){
    scanf("%lld%lld%lld",&h,&w,&n);
    zero=(h-2)*(w-2);
    while(n--){
        scanf("%lld%lld",&a,&b);
        for (int i=-2;i<=0;i++){
            for (int j=-2;j<=0;j++){
                if(a+i>=1 && a+i <=h-2 && b+j>=1 &&b+j <=w-2){
                    node[cnt++]=inf*(a+i)+(b+j);
                }
            }
        }
    }
    sort(node,node+cnt);
    for (int i=0,tmp=1;i<cnt;i++){
        if(node[i]==node[i+1]) tmp++;
        else ans[tmp]++,zero--,tmp=1;
    }
    printf("%lld\n",zero);
    for (int i=1;i<10;i++)
        printf("%lld\n",ans[i]);
    return 0;
}

Measured memory_bytes: 7672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)

const int G = 2e5;
vector<int> e[G+1];
bool used[G+1];

const int yBase = 1e5;

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

  rep(i,N) {
    int x, y;
    cin >> x >> y;
    e[x].push_back(yBase+y);
    e[yBase+y].push_back(x);
  }

  ll ans = 0;
  for(int i = 1; i <= G; i++) {
    if(used[i]) continue;

    ll nx, ny, ne;
    nx = ny = ne = 0;
    queue<int> q;
    q.push(i);
    while(!q.empty()) {
      int u = q.front(); q.pop();
      if(used[u]) continue;
      used[u] = true;
      if(u <= yBase) {
        nx++;
      } else {
        ny++;
      }

      for(auto v: e[u]) {
        ne++;
        if(used[v]) continue;
        q.push(v);
      }
    }
    if(nx >= 2 && ny >= 2) ans += nx * ny - ne/2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8320
A=input()

dict={}

for i in range(len(A)):
  if A[i] in dict:
    dict[A[i]]+=1
  else:
    dict[A[i]]=1

ans=len(A)*(len(A)-1)/2+1

for k,v in dict.items():
  ans-=(v*(v-1)/2)

print(int(ans))

Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
int main(){
	
	char arr1[200001];
	char arr2[200001];
	char c;
	
	for(int i=0;1;i++){
		c=getchar();
		if(c == '\n'){
			arr1[i]='\0';
			break;
		}
		arr1[i]=c;
	}
	
	for(int i=0;1;i++){
		c=getchar();
		if(c == '\n'){
			arr2[i]='\0';
			break;
		}
		arr2[i]=c;
	}
	
	int cnt=0;
	for(int i=0;arr1[i]!='\0';i++){
		if(arr1[i]!=arr2[i]) cnt++;
	}
	
	cout<<cnt;
	
	
	return 0;
}

Measured memory_bytes: 4016
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

string c(int64 n) {
    if (n==1) return "a";
    string ans;
    while(n!=0) {
        n--;
        ans += 'a' + (n%26);
        n /= 26;
//        if (n==1) break;
    }
    return ans;
}

int main() {
    int64 n;
    cin >> n;
    string ans = c(n);

//    for (int i=1; i<=703; i++) {
//        string t = c(i);
//        reverse(t.begin(), t.end());
//        cout << i << " : " << t << endl;
//    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 3120
L = int(input())
A = [0]*L
for i in range(L):
    A[i] = int(input())
DP = [[float("inf")]*5 for i in range(L+1)]
DP[0][0] = 0
#DP[i][0]ではまだ0しか選んでいない状態。DP[i][2]では奇数まで選んでいる
for i in range(L):
    zero = A[i]
    if A[i] == 0:
        even = 2
        odd = 1
    elif A[i]%2==0:
        even = 0
        odd = 1
    else:
        even = 1
        odd = 0
    DP[i+1][0] = DP[i][0] + zero
    DP[i+1][1] = min(DP[i][0], DP[i][1]) + even
    DP[i+1][2] = min(DP[i][0], DP[i][1], DP[i][2]) + odd
    DP[i+1][3] = min(DP[i][0], DP[i][1], DP[i][2], DP[i][3]) + even
    DP[i+1][4] = min(DP[i][0], DP[i][1], DP[i][2], DP[i][3], DP[i][4]) + zero

print(min(DP[L][0], DP[L][1], DP[L][2], DP[L][3], DP[L][4]))

Measured memory_bytes: 114964
#include<stdio.h>

int n,i,j,d[20][20],x,y,z=1;

int main(){
	scanf("%d",&n);
	while(n!=0){
		z=1;
		for(i=1;i<=n;i++)for(j=1;j<=n;j++)d[i][j]=0;
		x=(n+1)/2;y=(n+1)/2+1;
		d[x][y]=z;z++;
		i=n*n;i--;
		while(i!=0){
			x++;y++;
			if(x>n)x=1;
			if(y>n)y=1;
			if(d[x][y]==0){
				d[x][y]=z;
				z++;i--;
			}else{
				START:
				x--;y++;
				if(x>n)x=1;
				if(x<1)x=n;
				if(y>n)y=1;
				if(d[x][y]==0){
					d[x][y]=z;
					z++;i--;
				}else goto START;
			
			}
		}
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				printf("% 4d",d[j][i]);
			}
			printf("\n");
		}
		
		scanf("%d",&n);
	}
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_b() {
	ll n, m;
	//ll x, y;
	//ll a, b, c;
	//ll k;
	string s;
	ll l_ans = 0;
	float f_ans = 0;
	string s_ans;

	cin >> n >> s;

	ll x = 0;
	rep(i, n) {
		if (s[i] == 'I') x++;
		else x--;
		l_ans = max(l_ans, x);
	}

	cout << l_ans << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(7);

	solve_abc_b();

	return 0;
}


Measured memory_bytes: 256
def printRetangle(height,width):
    for x in range(height):
        for i in range(width):
            print('#',end='')
        print('')
    print('')

while True:
    x,y = map(int,input().split())
    if x ==0 and y==0:
        break;
    else:
        printRetangle(x,y)



Measured memory_bytes: 7012
#include <bits/stdc++.h>
using namespace std;
const int N = 2000 * 1000 + 20;
vector <int> gr[N];
int subt[N], cnt[N], d;
bool vis[N];
void dfs(int v) {
	vis[v] = true;
	if (subt[v] > 0) {
		d += subt[v];
	}
	cnt[v] = d;
	for (int u: gr[v]) {
		if (!vis[u])
			dfs(u);
	}
	if (subt[v] > 0)
		d -= subt[v];
}
int main () {
	int n, q;
	cin >> n >> q;
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		gr[x].push_back(y);
		gr[y].push_back(x);
	}
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		subt[x] += y;
	}
	dfs(1);
	for (int i = 1; i <= n; i++)
		cout << cnt[i] << " ";
}

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


int32_t main()
{
     int n,k,c; cin>>n>>k>>c;
     string s; cin>>s;
     int f[k],b[k];
     int i=0,j=0;
     while(i<n && j<k)
     {
         if(s[i]=='o'){
            f[j++] = i;
            i = i+c+1;
         }
         else i++;
     }
     i = n-1,j=k-1;
     while(i>=0 && j>=0)
     {
         if(s[i] == 'o'){
            b[j--]=i;
            i-=(c+1);
         }
         else i--;
     }
     for(int i=0;i<k;i++){
        if(f[i] == b[i]){
            cout<<f[i]+1<<endl;
        }
     }
}


Measured memory_bytes: 4996
def cul(x, y):
  z = []
  for i in range(x):
    z.append(int(y) * 10 ** i)

  return sum(z)

def main():
  a,b = map(int, input().split())
  num_a = cul(b, a)
  num_b = cul(a, b)
  test = []
  test.append(num_a)
  test.append(num_b)

  print(sorted(test, reverse = True)[0])


if __name__ == '__main__':
  main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl
#define all(v) v.begin(), v.end()
#define rsort(v) sort(v.rbegin(), v.rend())


int main() {
  int N;
  string c;
  cin >> N >> c;
  int ans = 0, l=0,r=N-1;
  while (1) {
    while (c[r] == 'W') {
      r--;
    }
    while (c[l] == 'R') {
      l++;
    }
    if (r-l<=0)
      break;
    ans++;
    r--;
    l++;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int INF = 1e9;

int main(){
	int n, m, l, k, a, h;
	while (cin >> n >> m >> l >> k >> a >> h  && n){
		VVI d(n, VI(n, INF));
		REP(i,n) d[i][i] = 0;
		VI hos;
		hos.push_back(a);
		hos.push_back(h);
		while (l--){
			int x;
			cin >> x;
			hos.push_back(x);
		}
		while (k--){
			int x, y, z;
			cin >> x >> y >> z;
			d[x][y] = z;
			d[y][x] = z;
		}
		REP(i,n) REP(j,n) REP(k,n){
			d[j][k] = min(d[j][k], d[j][i]+d[i][k]);
		}
		l = hos.size();
		VVI dh(l, VI(l,INF));
		REP(i,l) dh[i][i] = 0;
		REP(i,l) REP(j,l){
			if (d[hos[i]][hos[j]] <= m) dh[i][j] = d[hos[i]][hos[j]];
		}
		REP(i,l) REP(j,l) REP(k,l){
			dh[j][k] = min(dh[j][k], dh[j][i]+dh[i][k]);
		}
		int ans = dh[0][1];
		if (dh[0][1] > m) ans += dh[0][1] - m;
		if (dh[0][1] == INF) cout << "Help!" << endl;
		else cout << ans << endl;
	}

    return 0;
}

Measured memory_bytes: 3108
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=100005;
int n;
ll a[maxn],b[maxn];
ll cur;

int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	REP(i,n)cin>>a[i]>>b[i];
	for(int i=n;i>=1;i--){
		a[i]+=cur;
		ll mult=a[i]/b[i]+(a[i]%b[i]!=0?1:0);
		cur+=mult*b[i]-a[i];
	}
	cout<<cur;
	return 0;
}

Measured memory_bytes: 1792
#include <cmath>
#include <queue>
#include <cstdio>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 100010
#define ll long long
using namespace std;
inline ll read() 
{ 
    ll x=0,f=1;char ch=getchar(); 
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 
    return x*f; 
}
ll cnt,n;
ll h[51];
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	h[i]=read();
	while(1)
	{
		ll mx=0,mxid=0,sec=100000000000ll;
		for(int i=1;i<=n;i++)
		if(h[i]>mx)mx=h[i],mxid=i;
		for(int i=1;i<=n;i++)
		if(h[i]!=mx)sec=min(sec,h[i]);
		ll tmp=(mx-sec)/(n);
		if(tmp<=0)break;
		cnt+=tmp;
		for(int i=1;i<=n;i++)
		if(i!=mxid)h[i]+=tmp;
		h[mxid]-=tmp*n;
	}
	while(1)
	{
		int pd=0;
		for(int i=1;i<=n;i++)
		if(h[i]>=n){pd=1;break;}
		if(pd==0)break;
		ll mx=0,mxid=0;
		for(int i=1;i<=n;i++)
		if(h[i]>mx)mx=h[i],mxid=i;
		ll tmp=mx/n;
	 	cnt+=tmp;
		for(int i=1;i<=n;i++)
		if(i!=mxid)h[i]+=tmp;
		h[mxid]-=tmp*n;
	}
	printf("%lld\n",cnt);
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
long long two,five,ans;


int main(){
    long long n;
    cin>>n;
    if(n%2){
        ans=0;
    }else{
        long long b=10;
        while(b<=n){
            five+=n/b;
            b*=5;
        }
        ans=five;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
for i in range(N):
    a,b,c=map(int,input().split())
    if a>b:
        a,b=b,a
    if b>c:
        b,c=c,b
    if a>b:
        a,b=b,a
    if (a**2)+(b**2)==(c**2):
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 5604
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<int>sum(100003);
	for (int i = 0; i < N; i++) {
		cin >> L >> R;
		sum[L]++;
		sum[R + 1]--;
	}
	sum[0]++;
	for (int i = 1; i <= 100001; i++) {
		sum[i] += sum[i - 1]; 
	}
	for (int i = 100001; i >= 0; i--) {
		if (i <= sum[i]) {
			cout << i - 1 << endl;
			return 0;
		}
	}
	return 0;
}


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

int main()
{
  int N;
  cin >> N;
  int cnt = 0;
  for (int i = 0; i < N; ++i)
  {
    int l, r;
    cin >> l >> r;
    cnt += (r - l + 1);
  }
  cout << cnt;
  return 0;
}


Measured memory_bytes: 256
def solve1(m,n):
    div=[]
    rem=[]
    r=m
    rem = [-1 for _ in range(n)]
    digit=0
    while True:
        (d,r) = divmod(r,n)
        div.append(d)
        if r==0:
            return(''.join(map(str, div))[1:],'')
        elif rem[r] != -1:
            le = digit - rem[r]
            s = ''.join(map(str,div[1:]))
            t = (' '*100 + '^'*le)[-len(s):]
            return(s,t)
        else:
            rem[r] = digit
            r *= 10
            digit += 1
        
while True:
    try:
        m,n = map(int, input().strip().split())
        s,t = solve1(m, n)
        print(s)
        if t!='':
            print(t)
    except EOFError:
        break

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

int main(){
    int N;
    cin >> N;
    N=N%10;
    switch (N)
    {
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon";
        break;
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon";
        break;
    case 3:
        cout << "bon";
    default:
        break;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    vvchar g(h, vchar(w));
    int blk = 0;
    rep(y, h) rep(x, w)
    {
        cin >> g[y][x];
        if (g[y][x] == '#')
            blk++;
    }
    int ans = 0;
    rep(yc, (1 << h)) rep(xc, (1 << w))
    {
        int now = blk;

        rep(y, h)
        {
            if (((1 << y) & yc) == 0)
                continue;
            rep(x, w)
            {
                if (g[y][x] == '#')
                {
                    now--;
                }
            }
        }

        rep(x, w)
        {
            if (((1 << x) & xc) == 0)
                continue;

            rep(y, h)
            {
                if (((1 << y) & yc))
                    continue;

                if (g[y][x] == '#')
                    now--;
            }
        }
        if (now == k)
        {
            ans++;
        }
    }

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

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

int main(){

    int n,a,b,num,dig,sum,total=0;
    cin >> n >> a >> b;

    for(int i=1; i<=n; i++){
        num = i;
        sum = 0;
        while(num){
            dig = num % 10;
            sum = sum + dig;
            num =  num/ 10;
        }
        if(a <= sum && sum <= b){
            total = total + i;
        }
    }
    cout << total << endl;

}


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

int main(int, char**) {
        int N, M;
        std::cin >> N >> M;
        std::vector<int> S(M);
        std::vector<char> C(M);
        for (int i=0; i<M; i++) {
                std::cin >> S.at(i);
                std::cin >> C.at(i);
        }
        if (M==0) {
                if (N==1) {
                        std::cout<<0<<std::endl;
                } else {
                        std::cout<<std::pow(10,N-1)<<std::endl;
                }
                return 0;
        }

        for (int i=0; i<std::pow(10, N); i++) {
                std::string num = std::to_string(i);
                //std::cout << i <<std::endl;
                if (num.size() != N) continue;
                for (int j=0; j<M ; j++) {
                        int s = S.at(j);
                        char c = C.at(j);
                        if (num[s - 1] != c) {
                                break;
                        }
                        if (j == M - 1) {
                                std::cout << i << std::endl;
                                return 0;
                        }
                }
        }
        std::cout << -1 << std::endl;
        return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,x,ans,a;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		a=i;
		x=0;
		while(a>0)
		{
			a/=10;
			x++;
		}
		if(x%2!=0) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back

int solve(int x,vector<int> wait,vector<int>value){
    static int dp[11][200000];
    rep(i,11)rep(j,200000)dp[i][j] = 0;
    int n = wait.size();
    for(int i=1;i<=n;i++){
        rep(j,x+1){
            dp[i][j] = dp[i-1][j];
            if(j-wait[i-1]>=0){
                dp[i][j] = max( dp[i][j] , dp[i][j-wait[i-1]]+value[i-1] );
            }
        }
    }
    return dp[n][x];
}

int main(){
    int n,d,x;
    cin>>n>>d>>x;
    int shares[11][11];
    rep(i,d){
        rep(j,n){
            cin>>shares[i][j];
        }
    }
    rep(i,d-1){
        vector<int> diff,cost;
        rep(j,n){
            diff.pb(shares[i+1][j]-shares[i][j]);
            cost.pb(shares[i][j]);
        }
        x+=solve(x,cost,diff);
    }
    cout<<x<<endl;
}

Measured memory_bytes: 9808
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

const int MOD = 1000000007;

ll fact[1000000];
ll ifact[1000000];

ll choose(int n, int k) {
  ll ret = fact[n];
  ret *= ifact[k];
  ret %= MOD;
  ret *= ifact[n-k];
  ret %= MOD;
  return ret;
}

ll modpow(ll b, ll e, ll m) {
  ll r = 1;
  while(e) {
    if(e%2) {
      r*=b;
      r%=m;
    }
    b*=b;
    b%=m;
    e/=2;
  }
  return r;
}
ll inv(ll b, ll m) {
  return modpow(b, m-2, m);
}

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  fact[0] = 1;
  for(int i = 1; i <= n*m; i++) {
    fact[i] = i * fact[i-1];
    fact[i] %= MOD;
  }
  ifact[n*m] = inv(fact[n*m], MOD);
  for(int i = n*m-1; i >= 0; i--) {
    ifact[i] = (i+1) * ifact[i+1];
    ifact[i] %= MOD;
  }
  ll ret = 0;
  for(int d = 1; d < n; d++) {
    ll inc = m;
    inc *= m;
    inc %= MOD;
    inc *= n-d;
    inc %= MOD;
    inc *= choose(n*m-2, k-2);
    inc %= MOD;
    inc *= d;
    inc %= MOD;
    ret += inc;
    ret %= MOD;
  }
  for(int d = 1; d < m; d++) {
    ll inc = n;
    inc *= n;
    inc %= MOD;
    inc *= m-d;
    inc %= MOD;
    inc *= choose(n*m-2, k-2);
    inc %= MOD;
    inc *= d;
    inc %= MOD;
    ret += inc;
    ret %= MOD;
  }
  cout << ret << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    map<P, bool> mp;
    for(int i=0;i<n;++i) {
      int x, y; cin >> x >> y;
      mp[{x, y}] = true;
    }
    int m; cin >> m;
    vector<int> d(m), l(m);
    for(int i=0;i<m;++i) {
      char c; cin >> c >> l[i];
      if(c == 'N') {
        d[i] = 0;
      } else if(c == 'E') {
        d[i] = 1;
      } else if(c == 'S') {
        d[i] = 2;
      } else {
        d[i] = 3;
      }
    }
    int nowx = 10, nowy = 10;
    int cnt = 0;
    for(int i=0;i<m;++i) {
      for(int j=0;j<l[i];++j) {
        nowx += dx[d[i]];
        nowy += dy[d[i]];
        if(mp[{nowx, nowy}]) {
          cnt++;
          mp[{nowx, nowy}] = false;
        }
      }
    }
    if(cnt == n) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    int ans=0;int flag=0;
    sort(arr,arr+n);
    for(int i=0;i<n;i++){
        flag=0;
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(arr[i]+arr[j]<=arr[k]){
                    flag=1;
                    break;
                }else ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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 X = sc.nextInt();
		int Y = sc.nextInt();
		int result[] = new int[N-1];
		for (int i=1;i<N;i++) {
			for (int j=i+1;j<=N;j++) {
				if (j<=X||i>=Y) {
					result[j-i-1]++;
				} else {
					int temp = Math.abs(X-i);
					temp +=Math.abs(j-Y)+1;
					if (temp >j-i) {
						temp = j-i;
					}
					result[temp-1]++;
				}
			}
		}
		for (int i=0;i<N-1;i++) {
			System.out.println(result[i]);
		}
	}
}

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

int main(void) {
  int n, m; cin >> n >> m;
  vector<int> h(n);
  for (int i=0; i<n; i++) cin >> h[i];
  vector<vector<int>> t(n);
  for (int i=0; i<m; i++) {
    int a, b; cin >> a >> b;
    t[a-1].push_back(b-1);
    t[b-1].push_back(a-1);
  }
  
  int ans = 0;
  for (int i=0; i<n; i++) {
    bool flag = true;
    if (t[i].size() != 0) {
      for (auto e: t[i]) {
        if (h[e] >= h[i]) flag = false;
      }
    }
    if (flag) ans++;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8716
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>

#include <iostream>
#include <cstdio>
#include <queue>
#include <set>
#include <string>
#include <stdbool.h>

#include <cstring>

#define pb push_back
#define p push

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

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfb(a) printf("%.10lf\n",a);
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%.12lf ",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"

#define MOD  ( int)(1e9 + 7)
#define MAXN (ll) ((1e6+5))
#define K 25
#define  ALPHABET_SIZE  26
#define N (int)(1e5+10)
#define sag (sol|1)
#define sol (root<<1)
#define ort (bas+son)/2
#define INF (ll )1e18
#define int ll
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<pair<int,int>>> vvpi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph ;


signed main() {
    string s ;
    cin >> s ;
    char c= s[0];
    bool ctr = 0 ;
    for (int i = 1; i <s.size() ; ++i) {
        if(c != s[i])ctr=1;
    }
    if(ctr)cout<<"Yes";
    else cout << "No";

    return 0;









}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i,k,x,a,b,data[10000];
    for(i=2;i<=10000;i++){
        data[i]=1;
    }
    for(i=2;i*i<=10000;i++){
        if(data[i]){
            for(k=2*i;k<=10000;k+=i){
                data[k]=0;
            }
        }
    }
    while(1){
        a=0;
        b=0;
        scanf("%d",&x);
        if(x==0)break;
        for(x;x>=2;x--){
            if(data[x]==1){
                b=a;
                a=x;
            }
            if(b-a==2)break;
        }
        printf("%d %d\n",a,b);
    }
    return 0;
}

Measured memory_bytes: 2604
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

h,n = m()

a = [l() for i in range(n)]

a.sort(reverse = True)

dp = [mod for i in range(h+1)]

dp[0] = 0

for i in range(n):
    z,x = a[i]
    
    for j in range(z,h+1):
        dp[j] = min(dp[j],dp[j-z] + x)
    mi = mod
    for j in range(max(0,h-z),h+1):
        mi = min(mi,dp[j])

    dp[-1] = min(dp[-1],mi+x)
print(dp[-1])



Measured memory_bytes: 44124
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef double db;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k, c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	s = '*' + s;
	vector<vector<int>> dp(2, vector<int>(n + 2, 0));
	for (int i = 1; i <= n + 1; ++i)
		dp[0][i] = max(dp[0][i - 1], dp[0][max(i - c - 1, 0)] + (s[i] == 'o'));
	for (int i = n; i >= 0; --i)
		dp[1][i] = max(dp[1][i + 1], dp[1][min(n + 1, i + c + 1)] + (s[i] == 'o'));
	c = max(c, 1);
	int next = 1;
	vector<int> mark(n + 1, 0);
	for (int i = 1; i <= n; ++i)
	{
		int r = i, l = max(i - c + 1, 1);
		if (dp[0][l - 1] + dp[1][r + 1] >= k || dp[0][r - 1] >= k)
			for (next = max(next, l); next <= r; ++next)
				mark[next] = 1;
	}
	for (int i = 1; i <= n; ++i)
		if (s[i] == 'o' && !mark[i])
			cout << i << '\n';
	return 0;
}

Measured memory_bytes: 4032