akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    vi dp(651);
    dp[0]=1;
    REPR(j,650){
        if(!dp[j])continue;
        REP(i,1,a+1){
            dp[j+10*i]+=dp[j];
        }
    }
    REPR(j,650){
        if(!dp[j])continue;
        REP(i,1,b+1){
            dp[j+2*i]+=dp[j];
        }
    }
    REPR(j,650){
        if(!dp[j])continue;
        REP(i,1,c+1){
            dp[j+1*i]+=dp[j];
        }
    }
    cout<<dp[x/50]<<endl;
    return 0;
}


Measured memory_bytes: 256
def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d
import itertools
N,M,R=[int(x) for x in input().split()]
r=[int(x) for x in input().split()]
cost = [[float("inf") for i in range(N)] for i in range(N)] 
d=[[0]*N for _ in range(N)]
for i in range(M):
  x,y,z = [int(x) for x in input().split()]
  cost[x-1][y-1]=z
  cost[y-1][x-1]=z
for i in range(N):
  d[i]=dijkstra(i,N,M,cost)
r=list(itertools.permutations(r))
ans=10**9
for i in r:
  res=0
  for j in range(len(i)-1):
    res+=d[i[j]-1][i[j+1]-1]
  ans=min(ans,res)
print(ans)
    

Measured memory_bytes: 57688
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] arg) {
		Scanner in = new Scanner(System.in);
		for (int m; (m = in.nextInt()) > 0;) {
			int[][] seiza = new int[m][];
			while (--m >= 0) {
				seiza[m] = new int[] { in.nextInt(), in.nextInt() };
			}

			int n = in.nextInt();
			int[][] hosi = new int[n][];
			while (--n >= 0) {
				hosi[n] = new int[] { in.nextInt(), in.nextInt() };
			}
			int k = hosi.length - 1;
			HolePlate plate = new HolePlate(seiza);
			for (; !plate.isMatch(hosi);) {
				plate.dx = -(seiza[0][0] - hosi[k][0]);
				plate.dy = -(seiza[0][1] - hosi[k][1]);
				k--;
			}
			System.out.println(plate.dx + " " + plate.dy);

		}
		in.close();
	}
}

class HolePlate {
	final Set<int[]> seiza;
	int dx = 0, dy = 0;

	public HolePlate(int[][] seiza) {
		HashSet<int[]> set = new HashSet<int[]>();
		for (int[] star : seiza) {
			set.add(star);
		}
		this.seiza = Collections.unmodifiableSet(set);
	}

	public void setPosi(int dx, int dy) {
		this.dx = dx;
		this.dy = dy;
	}

	Set<int[]> set = new HashSet<int[]>();

	public boolean isMatch(int[][] stars) {
		for (int[] hole : seiza) {
			int[] moveHole = new int[] { hole[0] + dx, hole[1] + dy };
			boolean finded = false;
			for (int[] star : stars) {
				if (Arrays.equals(moveHole, star)) {
					finded = true;
					break;
				}
			}
			if (!finded)
				return false;
		}
		return true;
	}
}

Measured memory_bytes: 31716
#!/usr/bin/env python3
#ABC127 D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
a = LI()
h = []
for i in a:
    heappush(h,i)
h2 = []
for _ in range(m):
    b,c = LI()
    heappush(h2,(-c,b))

while h2:
    c,b = heappop(h2)
    c = -c
    while h and b > 0:
        x = heappop(h)
        if c <= x:
            heappush(h,x)
            print(sum(h))
            quit()
        else:
            heappush(h,c)
            b -= 1
print(sum(h))

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int a[3];

int main(){
  rep(i,3)cin>>a[i];
  sort(a,a+3);
  int res=0;
  if(a[0]%2==a[1]%2&&a[1]%2==a[2]%2){
    res=((a[2]-a[1])+(a[2]-a[0]))/2;
  }else{
    if(a[0]%2==a[1]%2){
      res=(((a[2]-a[1]-1)+(a[2]-a[0]-1))/2) + 1;
    }else if(a[1]%2==a[2]%2){
      res=(((a[2]-a[1])+(a[2]+1-a[0]))/2) + 1;
    }else{
      res=(((a[2]+1-a[1])+(a[2]-a[0]))/2) + 1;
    }
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }







int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int n, m;
    cin >> n >> m;
    
    vector<pair<pii, int> > v(m);
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        v[i] = make_pair(pii(a, b), c);
    }
    
    int D[n][n];
    fill_n(*D, n * n, inf);
    rep(i, n) D[i][i] = 0;
    rep(j, m) {
        D[v[j].F.F][v[j].F.S] = v[j].S;
        D[v[j].F.S][v[j].F.F] = v[j].S;
    }
    rep(k, n) rep(i, n) rep(j, n) {
        if (D[i][k] + D[k][j] < D[i][j]) D[i][j] = D[i][k] + D[k][j];
    }
    // rep(i, n) { rep(j, n) cout << D[i][j] << " "; cout << endl; }
    
    // m個の辺に関して, その辺を消してもすべての2頂点間の最短経路が変わらないか, だとwa
    // 最短経路が変わらなければその辺は最短経路に含まれないと思うかもしれない
    // しかし, 2頂点間で最短経路を実現するルートが2つ以上あるかもしれない
    // そのうちの辺を1つ消しても別から最短経路は残る
    
    int cnt = 0;
    rep(j, m) { // その辺が最短経路を1つでも構成するか
        int flg = 0;
        rep(s, n) rep(t, n) {
            if (D[s][v[j].F.F] + v[j].S + D[v[j].F.S][t] == D[s][t]) flg = 1;
        }
        if (flg == 0) cnt++;
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	fmt.Fprintln(wr, (1000-n%1000)%1000)
}


Measured memory_bytes: 1776
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
import itertools
a=[list(i) for i in itertools.permutations(range(1,n+1))]
import bisect as bi
x=bi.bisect_right(a,p)
y=bi.bisect_right(a,q)
print(abs(x-y))

Measured memory_bytes: 47452
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vector<int> h(n);

    for(int i = 0; i < n;i++){
        cin >> h[i];
    }
    VSORT(h);
    reverse(ALL(h));
    for(int i = 0; i < n;i++){
        if(h[i] < k){
            cout << i << endl;
            return 0;
        }
    }
    cout << n << endl;

    

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

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

    if (n == m) {
        std::cout << "Yes" << '\n';
    } else {
        std::cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
f = [0,1,1,2,3,5,8,13,21,34,55,89]
h,w,k = map(int,input().split())
a = [0]*(w+2)
b = [0]*(w+2)
a[1] = 1
for i in range(h):
  for j in range(1,w+1):
    b[j] =(f[j-1]*f[w-j+1]*a[j-1] + f[j]*f[w-j+1]*a[j] + f[j]*f[w-j]*a[j+1])%1000000007
  for j in range(1,w+1):
    a[j] = b[j]   
print(a[k])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f;
const int N=2e5+5;
using namespace std;
int a[N],b[N];
int main()
{
    int n,k;cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i];
    while(k--)
    {
        memset(b,0,sizeof b);
        int mx=n;
        for(int i=0;i<n;i++)
        {
            mx=min(mx,a[i]);
            int l=max(0,i-a[i]);
            int r=min(n,i+a[i]+1);
            b[l]++;b[r]--;
        }
        if(mx>=n) break;
        for(int i=0;i<n-1;i++)
        {
            b[i+1]+=b[i];
        }
        for(int i=0;i<n;i++) a[i]=b[i];
    }
    for(int i=0;i<n;i++) cout<<a[i]<<" ";

    return 0;
}


Measured memory_bytes: 5160
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


N,LEN,LIMIT = map(int,input().split())

speed = [None]*N
loc = [None]*N
num_fill = [0]*LEN
num_empty = [0]*LEN

ans = N

#時刻1の状態にする
for i in range(N):
    speed[i] = int(input())
    loc[i] = speed[i]

for current in range(2,LIMIT+1):

    for i in range(LEN):
        num_fill[i] += num_empty[i]
        num_empty[i] = 0

    for i in range(N):
        loc[i] += speed[i]
        loc[i] %= LEN
        num_empty[loc[i]] += 1
        if num_fill[loc[i]] > 0:
            num_fill[loc[i]] -= 1
        else:
            ans += 1 #元々あったことにする

print("%d"%(ans))




Measured memory_bytes: 13884
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

struct Node {
    std::vector<int> edge;
    bool is_searched;
};

const int MAX_N = 200050;
std::string s_in;
char s[MAX_N];
int N, M;
int a[MAX_N], b[MAX_N];

Node graph[MAX_N];
std::unordered_set<int> us;

bool can_loop(int i, int from) {
    if (from == -1 || s[i] != s[from]) {
        if (us.find(i) != us.end()) {
            return true;
        } else {
            us.insert(i);
            graph[i].is_searched = true;
        }
    }
    for (int next : graph[i].edge) {
        if (from == -1 || s[i] != s[from]) {
            if (s[next] == s[i] && can_loop(next, i)) {
                return true;
            } 
        } else {
            if (s[next] != s[i] && can_loop(next, i)) {
                return true;
            }
        }
    }
    if (from == -1 || s[i] != s[from]) {
        us.erase(i);
    }

    return false;

}

int main(int argc, char **argv) {
    std::cin >> N >> M;
    std::cin >> s_in;

    for (int i = 1; i <= M; i++) {
        std::cin >> a[i] >> b[i];
    }

    for (int i = 0; i < s_in.size(); i++) {
        s[i+1] = s_in[i];
    }

    for (int i = 1; i <= M; i++) {
        graph[a[i]].edge.push_back(b[i]);
        graph[b[i]].edge.push_back(a[i]);
    }

    for (int i = 1; i <= N; i++) {
        graph[i].is_searched = false;
    }

    for (int i = 1; i <= N; i++) {
        //std::cout << "check0:" << i << std::endl;
        if (!graph[i].is_searched && can_loop(i, -1)) {
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    
    std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 32680
#define _SECURE_NO_WARNINGS

#include <stdio.h>

int main(void)
{
	int a, b, c;

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

	if (a < b && b <c){
		printf("Yes\n");
		
	}
	else{
		printf("No\n");
	}

	return 0;
}



Measured memory_bytes: 2060
s = input()
n = len(s)
a = 0
if n % 2 == 0:
  for i in range(0,n,2):
    if s[i] == "L":
      a = 1
      break
  for i in range(1,n,2):
    if s[i] == "R":
      a = 1
      break
else:
  for i in range(0,n,2):
    if s[i] == "L":
      a = 1
      break
  for i in range(1,n,2):
    if s[i] == "R":
      a = 1
      break
if a == 0:
  print("Yes")
if a == 1:
  print("No")

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

int kaib(string s){
int i, n=s.size();
for(i=0; i<n/2; i++){ if(s[i]!=s[n-i-1]){ return 0; } }
return 1;
}
int main(){
string S; cin >> S; int N=S.size();
string A=S.substr(0,N/2), B=S.substr(N/2+1,N/2), ans="No";
if(kaib(S)&&kaib(A)&&kaib(B)){ ans="Yes"; }
cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define int ll


int n,m;
int a[1000000];
int b[1000000];
int ans;

signed main(){
  cin>>n>>m;
  rep(i,n){
    cin>>a[i];
  }

  rep(i,n){
    b[i]=a[i];
    if(i>0) b[i]+=b[i-1];
  }

  map<int,int> mp;
  rep(i,n){
    ans+= mp[b[i]%m];
    mp[b[i]%m]++;
  }

  cout<<mp[0]+ans<<endl;
}

Measured memory_bytes: 9088
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;

int f(int n) {
	if (n%2==0) {
		return n / 2;
	}
	else {
		return 3 * n + 1;
	}
}

int main() {
	int a[100000];
	cin >> a[1];
	for (int i = 1;;i++) {
		a[i + 1] = f(a[i]);
		for (int j = 1; j <= i; j++) {
			if (a[i + 1] == a[j]){
				cout << i + 1 << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
S=input()
if S=='SUN':
  print(7)
elif S=='MON':
  print(6)
elif S=='TUE':
  print(5)
elif S=='WED':
  print(4)
elif S=='THU':
  print(3)
elif S=='FRI':
  print(2)
elif S=='SAT':
  print(1)

Measured memory_bytes: 9116
def main():
    N, M, X, Y = map(int, input().split())
    x = list(map(int, input().split())) + [X]
    y = list(map(int, input().split())) + [Y]
    if max(x) < min(y):
        print("No War")
    else:
        print("War")


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);
 
impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

fn solve(n: u32, m: u32) -> Vec<(u32, u32)> {
    let mut pairs = Vec::new();
    let mut odd_index = 1+m;
    let mut even_index = 1;
    if m % 2 != 0 {
        odd_index += 1;
    }
    for p in (0..m).rev() {
        if p % 2 == 0 {
            pairs.push((even_index, even_index+p+1));
            even_index += 1;
        } else {
            pairs.push((odd_index, odd_index+p+1));
            odd_index += 1;
        }
    }
    pairs
}

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let ans = solve(sc.read(), sc.read());
    for  (a, b) in ans {
        println!("{} {}", a, b);
    }
}
 


Measured memory_bytes: 2672
#define DEBUG 0
/**
 * File    : A2.cpp
 * Author  : Kazune Takahashi
 * Created : 7/22/2019, 2:49:38 AM
 * Powered by Visual Studio Code
 */
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using ll = long long;
class mint
{
public:
  static ll MOD;
  ll x;
  mint() : x(0) {}
  mint(ll x) : x(x % MOD) {}
  mint operator-() const { return x ? MOD - x : 0; }
  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= MOD)
    {
      x -= MOD;
    }
    return *this;
  }
  mint &operator-=(const mint &a) { return *this += -a; }
  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint &operator/=(const mint &a)
  {
    mint b{a};
    return *this *= b.power(MOD - 2);
  }
  mint operator+(const mint &a) const { return mint(*this) += a; }
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  bool operator<(const mint &a) const { return x < a.x; }
  bool operator==(const mint &a) const { return x == a.x; }
  const mint power(ll N)
  {
    if (N == 0)
    {
      return 1;
    }
    else if (N % 2 == 1)
    {
      return *this * power(N - 1);
    }
    else
    {
      mint half = power(N / 2);
      return half * half;
    }
  }
};
ll mint::MOD = 1e9 + 7;
istream &operator>>(istream &stream, mint &a) { return stream >> a.x; }
ostream &operator<<(ostream &stream, const mint &a) { return stream << a.x; }
class combination
{
public:
  vector<mint> inv, fact, factinv;
  static int MAX_SIZE;
  combination() : inv(MAX_SIZE), fact(MAX_SIZE), factinv(MAX_SIZE)
  {
    inv[1] = 1;
    for (auto i = 2; i < MAX_SIZE; i++)
    {
      inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
    }
    fact[0] = factinv[0] = 1;
    for (auto i = 1; i < MAX_SIZE; i++)
    {
      fact[i] = mint(i) * fact[i - 1];
      factinv[i] = inv[i] * factinv[i - 1];
    }
  }
  mint operator()(int n, int k)
  {
    if (n >= 0 && k >= 0 && n - k >= 0)
    {
      return fact[n] * factinv[k] * factinv[n - k];
    }
    return 0;
  }
};
int combination::MAX_SIZE = 3000010;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// constexpr double epsilon = 1e-10;
// constexpr ll infty = 1000000000000000LL;
// constexpr int dx[4] = {1, 0, -1, 0};
// constexpr int dy[4] = {0, 1, 0, -1};
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}
void No()
{
  cout << "No" << endl;
  exit(0);
}

ll S;

int main()
{
  cin >> S;
  ll C = 1e9;
  ll y = (S + C - 1) / C;
  ll x = C * y - S;
  assert(C * y - x == S);
  cout << "0 0 " << C << " 1 " << x << " " << y << endl;
}

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

int main()
{
  int N, M;
  int res=0;
  cin >> N >>M;

  if(N==M) cout << "Yes" << endl;
  else cout << "No" << endl;

}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
/////////////////////////////////
int main()
{
    string s, t;
    cin >> s >> t;
    int ans = t.length();
    int l = t.length();
    rep(i, s.length())
    {
        int cnt = 0;
        for (int j = 0; j < t.length() && i + t.length() <= s.length();j++)
        {
            
            if (s[i + j] == t[j])
                cnt++;
        }
        ans = min(ans, l-cnt);
    }
    cout << ans << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  
  if(s == u) cout << a - 1 << " " << b << '\n';
  else cout << a << " " << b - 1 << '\n';
}

Measured memory_bytes: 256
import std.stdio, std.string, std.array, std.conv;

long modexp(long x, long n) {
    if (n == 0) return 1;
    long mod = 1_000_000_007;
    long result = modexp(x, n/2);
    result = result * result % mod;
    if (n % 2 == 1) result = result * x % mod;
    return result;
}

void main() {
    long[] tmp = readln.chomp.split.to!(long[]);
    long m = tmp[0], n = tmp[1];
    modexp(m, n).writeln;
}


Measured memory_bytes: 2492
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if (h == 0 & w == 0)
                break;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 37068
#include<iostream>
#include<utility>
#include<queue>
using namespace std;

typedef pair<int, string> p; 

int main(){
	priority_queue <p, vector<p>,greater<p> >pq;
	int n;
	cin >> n;
	while(n--){
		string str;
		int d;
		cin >> str >> d;
		pq.push(make_pair(d,str));
	}
	int m;
	cin >> m;
	bool test=true;
	int c=0;
	int temp=0;
	string str;
	for(int i=0;i<m;i++){
		cin >> str;
		if(!test) continue;
		test=false;
		while(!pq.empty()){
			if(pq.top().second!=str||pq.top().first==temp){
				pq.pop();
			}else{
				c++;
				temp=pq.top().first;
				test=true;
				pq.pop();
				break;
			}
		}
	}
	if(c==m) cout << "Yes"<<endl;
	else cout << "No" << endl;
	return 0;
}


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

int main()
{
    int n ;
    scanf("%d",&n) ;
    int a[n] ;
    for(int i = 0 ; i < n ; ++i) scanf("%d",&a[i]) ;
    sort(a,a+n) ;
    int cnt = 0 ;
    for(int i = 0 ; i < n ; ++i)
    {
        for(int j = i + 1 ; j < n ; ++j)
        {
            for(int k = j + 1 ; k < n ; ++k)
            {
                if((a[i]+a[j])>a[k] && (a[j]+a[k])>a[i] && (a[i]+a[k])>a[j]) ++cnt ;
            }
        }
    }
    printf("%d\n",cnt) ;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
	char x[1001],y[1001];
	gets(x);
	gets(y);
	int lenx=strlen(x),leny=strlen(y),i;
	for(i=0;i<leny;i++)
		printf("%c%c",x[i],y[i]);
	if(lenx>leny)
		printf("%c\n",x[lenx-1]);
}

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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans=0, tmp=0;
vector<ll> A;
map<pair<string,ll>,ll> M;
string S;

void dfsmap(vector<ll> v, ll id) {
    if(id==N) {
        string Stmp;
        ll ct=0;
        for(int i=0;i<N;i++) {
            if(v[i]) {
                Stmp += S[i];
                ct++;
            }
        }
        for(int i=N-1;i>=0;i--) {
            if(v[i]==0) {
                Stmp += S[i];
            }
        }
        pair<string,ll> p = make_pair(Stmp,ct);
        M[p]++;
        return;
    }
    dfsmap(v, id+1);
    v[id] = 1;
    dfsmap(v, id+1);
}

void dfsref(vector<ll> v, ll id) {
    if(id==N) {
        string Stmp;
        ll ct=0;
        for(int i=0;i<N;i++) {
            if(v[i]) {
                Stmp += S[2*N-1-i];
                ct++;
            }
        }
        for(int i=N-1;i>=0;i--) {
            if(v[i]==0) {
                Stmp += S[2*N-1-i];
            }
        }
        pair<string,ll> p = make_pair(Stmp,ct);
        ans += M[p];
        return;
    }
    dfsref(v, id+1);
    v[id] = 1;
    dfsref(v, id+1);
}

signed main(){
    cin >> N >> S;
    vector<ll> vemp(N,0);
    dfsmap(vemp,0);
    dfsref(vemp,0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 69100
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;
#define inf 1000000007

int main(void){
    int n, x;
    cin >> n >> x;
    int num[n+1];
    for(int i = 0; i < n; i++)
        cin >> num[i];
    num[n]=x;
    sort(num, num+n+1);
    int check[n+1];
    check[0]=num[1]-num[0];
    for(int i = 1; i < n; i++)
        check[i]=__gcd(check[i-1], num[i+1]-num[i]);
    cout << check[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

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

	if (n == 1)
		n = 3;
	if (m == 1)
		m = 3;

	cout << ((n - 2) * (m - 2)) << endl;

	return 0;
}


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


int main() {

  int n,k;
  cin >> n >> k;

  double ans=0;
  for(int i=1; i<=n; i++){
    if(k <= i){
      double tmpans = (double)(n-i+1)/(double)n;
      ans += tmpans;
      /*cout << "i="<<i << " j="<<j<<" tmpans=";
      printf("%.12f", tmpans);
      cout << "\n";*/
      break;
    }else{
      for(int j=1;j<=100000;j++){
        if(i*pow(2,j) >= k){
          double tmpans = (double)1/(double)n*pow(0.5,j);
          ans += tmpans;
          /*cout << "i="<<i << " j="<<j<<" tmpans=";
          printf("%.12f", tmpans);
          cout << "\n";*/
          break;
        }
      }
    }
  }
  printf("%.12f",ans);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef int ll;
ll i,j,l,r,n,k;
int main()
{
	cin>>k>>n;
	l=max(-1000000,n-k+1);
	r=min(1000000,n+k-1);
	for(i=l;i<=r;++i)
	{
		cout<<i<<" ";
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from bisect import bisect_left
INF = float("inf")

MOD = 998244353  # type: int


def solve(N: int, S: str):

    count = 1
    nums = {"B": 0, "R": 0, "G": 0}
    other = {"B": "RG", "R": "BG", "G": "BR"}
    for c in S:
        buf = sorted(nums.values())
        if nums[c] == buf[2]:
            count *= N-nums[c]
            count %= MOD
        elif buf[1] == nums[c]:
            count *= buf[2]-buf[1]
            count %= MOD
        else:
            count *= buf[1]-buf[0]
            count %= MOD
            pre = "C"
        nums[c] += 1
    print(count)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43884
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
  int length = sc.nextInt();
		String r = sc.next();
	int oddeven = length % 2;
	if (oddeven == 0) {
		String right = r.substring(length/2);
		String left = r.substring(0, (length)/2 );
		if (left.equals(right)) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
	else {
		System.out.println("No");
	}
}
	}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <cmath>
#include <limits>
 
int main () {
  int n, k;
  std::cin >> n >> k;
  
  std::vector<int> h(n);
  for (auto&& hi : h) std::cin >> hi;
  
  std::vector<int> cost(n, std::numeric_limits<int>::max());
  cost[0] = 0;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < k; ++j) {
      const auto ii = i - j - 1;
      if (ii < 0) break;
      const auto c = std::abs(h[i] - h[ii]) + cost[ii];
      if (cost[i] > c) cost[i] = c;
    }
  }
  std::cout << cost[n-1] << std::endl;
}

Measured memory_bytes: 1152
#include<iostream>
int main() {
	int w, h, x, y, r;
	std::cin >> w >> h >> x >> y >> r;
	if ((x - r) >= 0 && (y - r) >= 0 && (h - r) >= y && (w - r) >= x) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
}

Measured memory_bytes: 1156
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {

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

        long sum = 0;
        for (int i = 0; i < (1 << s.length); i++) {
            StringJoiner sj = new StringJoiner("");
            for (int j = 0; j < s.length; j++) {
                if ((1 & i >> j) == 1) {
                    if (j == 0) {
                        break;
                    }
                    sj.add("+");
                }
                sj.add(String.valueOf(s[j]));
            }
            if ("".equals(sj.toString())) {
                continue;
            }

            String[] expression = sj.toString().split("\\+");
            for (int j = 0; j < expression.length; j++) {
                sum += Long.parseLong(expression[j]);
            }
        }
        System.out.println(sum);
    }

}


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

int main(){
	int n;	cin>>n;
	string s;	cin>>s;
	int ans=0;
	for(int i=0;i+2<n;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')ans++;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
//
// Created by Hideaki Imamura on 2020-03-19.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N;
vector<vector<int>> G;
vector<i_i> vs;

int main() {
    cin >> N;
    G.assign(N, vector<int>());
    for (int i = 0; i < N - 1; ++i) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        G[x].push_back(y);
        G[y].push_back(x);
        vs.push_back(make_pair(x, y));
    }

    int K = 0;
    map<pair<int, int>, int> I;
    vector<int> cs(N, 0);
    vector<int> used(N, 0);
    queue<int> que;

    used[0] = 1;
    que.push(0);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        if (K < (int)G[v].size()) K = G[v].size();
        int cur = 1;
        for (int u: G[v]) {
            if (used[u]) continue;
            if (cur == cs[v]) cur++;
            cs[u] = cur;
            I[make_pair(u, v)] = cur;
            I[make_pair(v, u)] = cur;
            cur++;
            used[u] = 1;
            que.push(u);
        }
    }

    cout << K << endl;
    for (auto p : vs) cout << I[p] << endl;
    return 0;
}

Measured memory_bytes: 20084
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  vector<long long int> a;
  int N;
  cin >> N;
  long long int A;
  for(int i=0;i<N;i++){
    cin >> A;
    a.push_back(A);
  }
  long long int count=0;
  bool f;
  long long int b=a[0];
  if(a[0] <0){
    f=false;
  }else{
    f=true;
    if(a[0]==0){
      b=1;
      count++;
    }
  }
  for(int i=1;i<N;i++){
    if(f==true){
     if(b+a[i]>=0){
       count+=b+a[i]+1;
       b=-1;
     } else{
       b=b+a[i];
     }
    }else{
      if(a[i]+b<=0){
        count+=1-(a[i]+b);
        b=1;
      }else{
        b=a[i]+b;
      }
    }
    f^=1;
  }
  if(b==0){
    count++;
  }
  long long int s=count;
  count=0;
  if(a[0] <0){
    count=1-a[0];
    a[0]=1;
    f=true;
  }else{
    count=1+a[0];
    a[0]=-1;
    f=false;
  }
  b=a[0];
  for(int i=1;i<N;i++){
    if(f==true){
     if(b+a[i]>=0){
       count+=b+a[i]+1;
       b=-1;
     } else{
       b=b+a[i];
     }
    }else{
      if(a[i]+b<=0){
        count+=1-(a[i]+b);
        b=1;
      }else{
        b=a[i]+b;
      }
    }
    f^=1;
  }
  if(b==0){
    count++;
  }
  cout << min(count,s) << endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

int main(){
  int n,m;
  while(cin >> n >> m){
    if(n==0 && m==0) break;

    vector<int> s(n), d(m);
    rep(i,n){
      cin >> s[i];
    }
    rep(i,m){
      cin >> d[i];
    }

    sort(d.begin(), d.end());

    vector<int> sum(1<<n,0);
    rep(i,1<<n){
      rep(j,n){
	if( (i>>j) & 1 ) sum[i] += s[j];
      }
    }

    vector<int> dp(1<<n,0);
    rep(i,m){
      rep(bit,1<<n){
	rep(j,n){
	  dp[bit|(1<<j)] = min(dp[bit|(1<<j)], dp[bit]);
	}
	dp[bit] += abs(sum[bit] - d[i]);
      }
    }
    
    int ans = 1e9;
    rep(i,1<<n) ans = min(ans, dp[i]);
    cout << ans << endl;
  }
}

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

int main() {
  string s; cin >> s;
  int K; cin >> K;
  for (auto &c : s) {
    if (c == 'a')
      continue;
    int offset = 26 - (c - 'a');
    if (K - offset >= 0) {
      c = 'a';
      K -= offset;
    }
  }
  K %= 26;
  s[s.length()-1] = (s[s.length()-1] - 'a' + K) % 26 + 'a';
  cout << s << endl;
}

Measured memory_bytes: 512
#include<cstdio>
using namespace std;
int n,l,a[300010],i,t,m;
int main()
{
	scanf("%d%d",&n,&l);
	if (n%2==0)
	{
		printf("%d ",n/2);
		for (i=2;i<=l;i++) printf("%d ",n);
		return 0;
	}
	t=l/2;
	m=n/2+1;
	for (i=1;i<=l;i++) a[i]=m;
	int k=l;
	//t=10;
	while (t--)
	{
		if (a[k]==1) k--;
		else 
		{
			a[k]--;
			for (i=k+1;i<=l;i++) a[i]=n;
			k=l;
		}
		/*	for (i=1;i<=k;i++) 
	{
		printf("%d ",a[i]);
	} 
	printf("\n");*/
	}
	for (i=1;i<=k;i++) 
	{
		printf("%d ",a[i]);
	} 
}

Measured memory_bytes: 3328
input()
S = input().strip()
b = ''
tt = [0]
t = 0
for i, s in enumerate(S):
    if b + s == "AC":
        t += 1
    tt.append(t)
    b = s
import sys
for line in sys.stdin:
    s,e = [int(i) for i in line.strip().split(" ")]
    print(tt[e] - tt[s])


Measured memory_bytes: 54644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2005;
const ll inf=1e13;
int n,pre[N],c[N];ll a[N],f[N][N],g[N];
int main(){
	//freopen("aa.in","r",stdin);
	int i,j,k;
	cin>>n;
	for(i=1;i<=n;++i)cin>>a[i];
	for(g[1]=a[1],i=2;i<=n*2;++i)g[i]=-inf;
	for(i=1;i<=n;++i){
		for(j=1;j<=n;++j)if(i+j<=n||i-j>=1){
			f[i][j]=a[i+j]+g[max(0,i-j)];
			if(f[i][j]>g[i+j]){
				pre[i+j]=i;
				g[i+j]=f[i][j];
			}
			//g[i+j]=min(g[i+j],f[i][j]); 
		}
	}
	for(k=i=n;i<=2*n;++i)if(g[i]>g[k])k=i;
	cout<<g[k]<<endl;
	vector<int>q;
	for(i=k;pre[i];i=pre[i]-(i-pre[i])){
		for(j=0;j<i-pre[i];++j){
			q.push_back(pre[i]);
			//printf("%d\n",pre[i]);
		}
	}
	cout<<q.size()<<endl;
	for(i=1;i<=n;++i)c[i]=1;
	for(i=0;i<q.size();++i){
		for(k=0,j=1;j<=q[i];++j)if(c[j])++k;
		cout<<k<<endl;
		for(j=q[i]-1;j&&!c[j];--j);c[j]=0;
		for(j=q[i]+1;j<=n&&!c[j];++j);c[j]=0;
	}
	return 0;
}

Measured memory_bytes: 16128
N,M,K = map(int, input().split())

MOD = 10**9+7
 
MAXN = N*M + 10
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD
 
def nCr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD


#X：+ax*(ax - 1) * N - ax * (M - ax) * N = ax*N*(ax-1-M+ax) = ax*N*(2ax-1-M)
ans = 0

for i in range(1,M+1):
    tmp = (((((i * N) % MOD) * (2*i - 1 - M)) % MOD) * N) % MOD
    
    #print("~~~", i*N, 2*i - 1 - M,tmp, nCr(N*M-2, K-2))

    tmp *= nCr(N*M-2, K-2)

    tmp %= MOD
    #print("pppp", tmp)
    ans += tmp

    ans %= MOD


for i in range(1,N+1):
    tmp = (((((i * M) % MOD) * (2*i - 1 - N)) % MOD) * M) % MOD

    tmp *= nCr(N*M-2, K-2)

    tmp %= MOD
    ans += tmp
    ans %= MOD


print(ans)


Measured memory_bytes: 28248
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

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

typedef long long ll;


int main() {
	//入力;
	ll a, b;
	cin >> a >> b;
	ll x= a* b;

	/* 自然数 a > b を確認・入替 */
	if (a < b) {
		ll tmp;
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	/* 最小公倍数を出力 */
	cout << x / b << endl;



	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i,a,b) for(int i=a;i<=b;i++)
#define g(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout<<"Case #"<<x<<": "
#define op1(x) cout<<"Scenario #"<<x<<": "
#define endl "\n"
using namespace std;
const ll mod = 1000000007;
const ll INF = LLONG_MAX;
const ll NEGINF = LLONG_MIN;
const int N = 18;
const ll MAXN = 1000001;
#define MAX 5

ll n;
ll dp[1000001][2][2];

ll foo(ll idx, ll zr, ll ni)
{
	if (idx == n)
	{
		if (zr == 1 and ni == 1) return 1;
		return 0;
	}

	if (dp[idx][zr][ni] != -1) return dp[idx][zr][ni];
	ll res = 0;

	res = (res % mod + foo(idx + 1, 1, ni)) % mod;
	res = (res % mod + foo(idx + 1, zr, 1)) % mod;
	res = (res % mod + (8 * foo(idx + 1, zr, ni)) % mod) % mod;


	return dp[idx][zr][ni] = res % mod;

}

void solve(int t)
{

	cin >> n;

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

	cout << foo(0, 0, 0) % mod << endl;





}


int main()
{
	





	int t = 1;
	//cin >> t;



	for (int i = 1; i <= t; i++)
	{
		solve(i);

	}
}

Measured memory_bytes: 97260
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


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

	int A,B; cin >> A >> B;
	int skt = 1;
	int ans = 0;
	while(B > skt) {
		skt--;
		skt += A;	
		ans++;
	}
	cout << ans << endl;
	

	return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  ll h, w;
  cin >> h >> w;
  ll ans = (h * w + 1) / 2;
  if (h == 1 || w == 1) ans = 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.append(a[n - 1])
ans = 1
s = 0
i = 1
while i < n:
    if not(a[s] <= a[i] <= a[i + 1]) and not(a[s] >= a[i] >= a[i + 1]):
        s = i + 1
        ans += 1
    i += 1

print(ans)

Measured memory_bytes: 14224
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<queue>
#include<stack>
#include<ctime>
using namespace std;
float a,b;
int main(){
	cin>>a>>b;
	cout<<ceil((a+b)/2)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<vector<int> > edge(N);
  int a, b;
  for(int i=0;i<N-1;++i) {
    cin>>a>>b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  vector<int> c(N);
  for(int i=0;i<N;++i) cin>>c[i];
  sort(c.begin(), c.end(), greater<int>());
  map<int, int> amap;
  queue<int> que;
  que.push(0);
  int state;
  int index = 0;
  while(!que.empty()) {
    state = que.front();que.pop();
    if(amap[state]>0) continue;
    amap[state] = c[index];
    index++;
    for(int i=0;i<edge[state].size();++i) {
      if(amap[edge[state][i]]>0) continue;
      que.push(edge[state][i]);
    }
  }
  int ans = 0;
  for(int i=1;i<N;++i) ans += c[i];
  cout<<ans<<endl;
  for(int i=0;i<N;++i) cout<<amap[i]<<" ";
  cout<<endl;
}



Measured memory_bytes: 4496
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0)); 
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int n,m,Q;
int sum[505][505];

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    cin >> n >> m >> Q;
    rep(i, m){
        int l, r;
        cin >> l >> r;
        l--; r--;
        sum[l][r]++;
    }
    RREP(i, 0, n-1) REP(j, 0, n)
        sum[i][j] += sum[i+1][j];
    REP(i, 0, n) REP(j, 1, n+1)
        sum[i][j] += sum[i][j-1];
    rep(i, Q){
        int p, q;
        cin >> p >> q;
        p--; q--;
        cout << sum[p][q] << endl;
    }
    return 0;
}


Measured memory_bytes: 1920
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,A,B;cin>>N>>A>>B;
  int ans = 0;
  FOR(i,0,N) {
    int t; cin >> t;
    if(t < A || t >= B) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define REP(i, n) for (int i = 0; i < (n); i++)
#include <iostream>
#include <set>
using namespace std;

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

    int n;
    set<int> st;
    cin >> n;

    REP(i,n){
        int a;
        cin >> a;
        if(st.count(a))st.erase(a);
        else st.insert(a);
    }

    cout << st.size() << endl;

    return 0;
}

Measured memory_bytes: 4992