akhauriyash/Code-Regression huggingface dataset:
from operator import itemgetter
from heapq import heappush,heappop
import sys
N = int(input())
table=[]
for i in range(N):
    a,b = map(int,input().split())
    table.append([a,b,i])
A = sorted(table,key=itemgetter(0))
B = sorted(table,key=itemgetter(1))

graph=[[] for i in range(N)]
for k in range(N-1):#距離、点
    graph[A[k][2]].append((abs(A[k][0]-A[k-1][0]),A[k-1][2]))
    graph[A[k][2]].append((abs(A[k][0]-A[k+1][0]),A[k+1][2]))
graph[A[N-1][2]].append((abs(A[N-1][0]-A[N-2][0]),A[N-2][2]))
for k in range(N-1):
    graph[B[k][2]].append((abs(B[k][1]-B[k-1][1]),B[k-1][2]))
    graph[B[k][2]].append((abs(B[k][1]-B[k+1][1]),B[k+1][2]))
graph[B[N-1][2]].append((abs(B[N-1][1]-B[N-2][1]),B[N-2][2]))
#プリム法
kei = []
visit=[False]*N
heappush(kei,[0,0])#距離,点
dist = 0
point =0
while kei:
    d,i = heappop(kei)
    if point ==N:
        print(dist)
        sys.exit()
    if visit[i]==True:
        continue
    visit[i]=True
    dist += d
    point+=1
    for e,j in graph[i]:
        if not visit[j]:
            heappush(kei,[e,j])




Measured memory_bytes: 85252
package main

import (
  "fmt"
)

func main() {
  var n, d int
  fmt.Scan(&n)
  fmt.Scan(&d)
  var ans int
  if n % (2 * d + 1) == 0 {
    ans = n / (2 * d + 1)
  } else {
    ans = n / (2 * d + 1) + 1
  }
  fmt.Println(ans)
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
  int a,b,c,swt=0;
  scanf("%d %d",&a,&b);
  
  for(c=1;c<=3;c++){
  if((a*b*c)%2!=0 && swt==0){
    puts("Yes");
    swt=1;
  }
  }
  if(swt==0){
    puts("No");
}
}

Measured memory_bytes: 128
import sys
import math

while 1:
    m, f, r = map(int, raw_input().split())

    if m + f + r == -3 :
        break

    if m == -1 or f == -1 :
        print "F"
    elif m + f >= 80 :
        print "A"
    elif m + f >= 65 :
        print "B"
    elif m + f >= 50 :
        print "C"
    elif m + f >= 30 :
        if r >= 50 :
            print "C"
        else :
            print "D"
    else :
        print "F"

Measured memory_bytes: 6392
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

const ll mod = 1000000007LL;

int main() {
	int n;
	cin >> n;
	int c[n];

	rep(i,n) {
		cin >> c[i];
	}

	int dp[n];
	dp[0] = 1;

	vector<int> prev(200001,-1);
	prev[c[0]] = 0; 

	for(int i = 1; i < n; i++) {
		int cur = dp[i - 1];

		if (prev[c[i]] >= 0 && i - 1 != prev[c[i]]) {
			cur += dp[prev[c[i]]];
		} 
		prev[c[i]] = i;

		dp[i] = cur % mod;
	}
	/*
	rep(i, n) {
		cout << "i:" << i << " n:" << dp[i] << endl;
	}
	*/

	cout << dp[n - 1] << endl;



	return 0;
}


Measured memory_bytes: 5252
using System;

public class ABC156_A {
    private static void Main(string[] args) {
        var inputs = Console.ReadLine().Trim().Split();
        var n = int.Parse(inputs[0]);
        var r = int.Parse(inputs[1]);

        var answer = r + Math.Max(0, 100 * (10-n));
        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int N;
int A[200010];
ll ans;
int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int s = 0, res = 0;
    for(int i = 0; i < N; i++){
        while(true){
            if((res | A[i]) - res != A[i]){
                res = res ^ A[s];
                s++;
            }else break;
        }
        res |= A[i];
        ans += (ll)(i - s + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	char a,b;
	cin >> a >> b;
	if (a == b) {
		cout << '=' << endl;
	} else if (a < b) cout << '<' << endl;
	else cout << '>' << endl;
	return 0;
}


Measured memory_bytes: 256
A, B, K=map(int, input().split())
if 2*K > (B-A)+1:
  for i in range(A, B+1):
    print(i)
else:
  for i in range(A, A+K):
    print(i)
  for i in range(B-K+1, B+1):
    print(i)



Measured memory_bytes: 9000
n = int(input())

d = dict()
for _ in range(n):
    a = int(input())
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1

res = 0
for v in d.values():
    if v % 2 == 1:
        res += 1

print(res)

Measured memory_bytes: 86032
#include <iostream>
#include <string>

int main() {
    while (true) {
        std::string line;
        std::getline(std::cin, line);
        if (line == "0") break;

        int line_sum = 0;
        for (char c : line) {
            line_sum += (int)c - 48;
        }
        std::cout << line_sum << std::endl;
    }
}



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, ans;
  cin >> N;
  int H[N];
  for(int i=0;i<N;i++) cin >> H[i];
  ans = 0;
  int maxi = H[0];
  for(int i=0;i<N;i++){
    if(maxi <= H[i]){
      maxi = H[i];
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func scanNQ() int {
	var n int
	if _, err := fmt.Scanf("%d", &n); err != nil {
		panic(err)
	}
	return n
}

func scanST(nq int) []int {
	ns := make([]int, 0, nq)
	for i := 0; i < nq; i++ {
		var n int
		if _, err := fmt.Scanf("%d", &n); err != nil {
			panic(err)
		}
		ns = append(ns, n)
	}
	return ns
}

func binary(t int, S []int) bool {
	l := len(S)
	if l == 0 {
		return false
	}

	h := l / 2
	s := S[h]

	if t == s {
		return true
	}

	if t < s {
		return binary(t, S[:h])
	} else {
		return binary(t, S[h+1:])
	}
}

func main() {
	n := scanNQ()
	S := scanST(n)
	q := scanNQ()
	T := scanST(q)

	cnt := 0
	for _, t := range T {
		if binary(t, S) {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 5960
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    a = I()
    b = I()

    return 6 - a - b


print(main())





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

int main(){
    
    int s;
    cin >> s;
    int fnum = s%10;
    int snum = (s/10)%10;
    int tnum = (s/100)%10;
    
    if(tnum > snum){
        cout << tnum << tnum << tnum <<endl;
    }
    else if (tnum == snum){
        if(snum >= fnum){
            cout << tnum << tnum << tnum <<endl;
        }
        else{
            cout << tnum+1 << tnum+1 << tnum+1 << endl;
        }
    }
    else{
        cout << tnum+1 << tnum+1 << tnum+1 << endl;
    }
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,s,e) for(ll i=s;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1000000007;
const ll INF = 1000000009;
ll i;

int main(){
    ll N,K,X,Y;
    cin>>N>>K>>X>>Y;
    if(N<=K)cout<<N*X;
    else cout<<K*X+(N-K)*Y;
    cout<<endl;
}



Measured memory_bytes: 256
import numpy as np

n = int(input())
p = np.array(list(map(int, input().split())))

comp = np.arange(n) + 1
diff = list(comp - p)

diff = [~(x == 0) for x in diff] + [True]

ans = 0
for i in range(len(diff) - 1):
    if diff[i] == True:
        continue
    elif diff[i] == False:
        diff[i] = True
        diff[i + 1] = True
        ans += 1

print(ans)

Measured memory_bytes: 23480
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	int n; cin >> n; vector<int> a;
	int b;
	for (int i = 0; i < n; i++) {
		cin >> b;
		a.push_back(b);
	}
	cout << *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end() ) << endl;
	return 0;
}

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

#define INF 1000000000

//ノードの総数
bool warshallfloyd(vector<vector<int>> &dp,int n){
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        //INFへ足し引き算してもINFになるように
        if(dp[i][k]!=INF && dp[k][j]!=INF){
          dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
        }
      }
    }
  }
  bool x=false;
  for(int i=0;i<n;i++){
    if(dp[i][i]<0){x=true;break;}
  }
  return x;
}

int main(){
  int n,m,r;cin >> n >> m >> r;
  vector<vector<int>> dp(n,vector<int>(n,INF));
  vector<int> R(r);
  for(int i=0;i<r;i++){cin >> R[i];R[i]-=1;}

  for(int i=0;i<m;i++){
    int a,b,c;cin >> a >> b >> c;
    dp[a-1][b-1]=min(c,dp[a-1][b-1]);dp[b-1][a-1]=min(c,dp[b-1][a-1]);
  }

  for(int i=0;i<n;i++){dp[i][i]=0;}

  warshallfloyd(dp,n);

  int c=INF;
  vector<int> v(r);for(int i=0;i<r;i++){v[i]=i;}
  do{
    int d=0;
    for(int i=0;i<r-1;i++){
      d+=dp[R[v[i]]][R[v[i+1]]];
    }
    c=min(d,c);
  }while(next_permutation(v.begin(),v.end()));
  cout << c << endl;



}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	string s;
	cin>>s;
	ll Q;
	cin>>Q;
	vector<char> start;
	vector<char> end;
	ll o=0;
	while(Q--){
		ll T;
		cin>>T;
		if(T==1){
			o=o^1;
		}
		if(T==2){
			int F;
			char C;
			cin>>F>>C;
			if(o+F==2){
				end.pb(C);
			}
			else start.pb(C);
		}

	}
	for(auto c:end){
			s+=c;
		}
		reverse(s.begin(),s.end());
		for(auto c:start){
			s+=c;
		}
		if(o==0)
			reverse(s.begin(),s.end());
		cout<<s<<endl;
}

Measured memory_bytes: 1168
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

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

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

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    double r;
    cin >> r;

    print(r * 6.28318530717958623200);

    return 0;
}



Measured memory_bytes: 3796
// Do you knOW what it feels like?

		// To be TorTured by your own MinD?
	
	// I don't wanna feel the PAIN.

// I BeG you to KILL me, pleASE...

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

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Os")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;

const ll maxn=2e3+10, mod=1e9+7, inf=1e18;

ll n,k;
vector<ll> g[maxn];

ll dfs(ll v,ll p=0,ll h=0){
	if(h==k/2) return 1;
	ll sum=1;
	for(auto u:g[v])if(u!=p) sum+=dfs(u,v,h+1);
	return sum;
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	cin>>n>>k;
	for(int i=1;i<n;i++){
		ll v,u; cin>>v>>u;
		g[v].pb(u);
		g[u].pb(v);
	}
	ll ans=inf;
	if(k%2==0) for(int i=1;i<=n;i++) ans=min(ans,n-dfs(i));
	else for(int i=1;i<=n;i++)for(auto j:g[i]) ans=min(ans,n-(dfs(i,j)+dfs(j,i)));
	cout<<ans<<endl;

	return 0;
}









Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	vector<vector<int>> graph(3*n);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		u--;v--;
		graph[u].push_back(v+n);
		graph[u+n].push_back(v+2*n);
		graph[u+2*n].push_back(v);
	}
	int s,t;
	cin>>s>>t;
	s--;t--;
	queue<int> q;
	q.push(s);
	int d[3*n];
	for(int i=0;i<3*n;i++)
		d[i]=-1;
	d[s]=0;
	while(!q.empty())
	{
		int k=q.front();
		q.pop();
		for(int i=0;i<graph[k].size();i++)
		{
			int next=graph[k][i];
			if(d[next]==-1)
			{
				d[next]=d[k]+1;
				q.push(next);
			}
		}
	}
	if(d[t]==-1)
		cout<<"-1";
	else
		cout<<d[t]/3;
	return 0;
}

Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define eps 1e-13
#define PI 3.141592653589793238L
#define inf 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("input.in", "r", stdin); freopen("output.out", "w", stdout)
const int N =100006;
ll fact[N],ifact[N],a[N];
long long int modpow (long long int a, ll mo) {
	ll res = 1;
	ll j=mo-2;
	while (j > 0)
		if (j & 1) {
			res = (res * a) % mo;
			--j;
		}
		else {
			a = (a * a) % mo;
			j >>= 1;
		}
	return res %mo;
}
ll ncr(int i,int j)
{
	ll w=fact[i]*ifact[j];
	w%=mod;
	w=w*ifact[i-j];
	w%=mod;
	return w;
}
int main()
{
	//io_file;
	ll n,m;
	cin>>n>>m;
	string s1,s2;
	cin>>s1>>s2;
	ll g=gcd(n,m);
	ll lcm=n*m/g;
	ll w1=n/g;ll w2=m/g;
	int i1=0,j1=0;
	while(i1<n&&j1<m)
	{
		if(s1[i1]!=s2[j1]){cout<<"-1"<<endl;return 0;}
		i1+=w1;
		j1+=w2;
	}
	cout<<lcm<<endl;
}

Measured memory_bytes: 512
s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
  u=(u+i*d)%2019
  l[u]+=1
  d=d*10%2019
for i in l:
  ans+=i*(i-1)//2
print(ans)

Measured memory_bytes: 9372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt=1;
void init(){cnt=1,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,w;}ee[M*2];
void add(int x,int y,int w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;}
*/

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int n;
	cin>>n;
	cout<<(1000-n%1000)%1000<<endl; 
	return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
int n;
long long x;
long long a[100000];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", a + i);
	}
	for (int i = 0; i < n - 1; i++) {
		x += a[i] / 2;
		a[i] = a[i] % 2;
		if (a[i] && a[i + 1]) {
			x++;
			a[i + 1]--;
		}
	}
	x += a[n - 1] / 2;
	printf("%lld\n", x);
}

Measured memory_bytes: 2492
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
  vector<int> x(10);
  int i = 0;
  for(; i < 10; i++) cin >> x[i];
  sort(x.begin(), x.end());
  for(i = 9; i > 6; i--) cout << x[i] << endl;
}


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

int main() {
	string a;
	cin >> a;
	int x = 1;
	rep(i, a.size()) {
		if (i % 2 == 0) {
			if (a.at(i) != 'R' && a.at(i) != 'U' && a.at(i) != 'D') {
				x = 0;
				break;
			}
		 }
		else {
			if (a.at(i) != 'L' && a.at(i) != 'U' && a.at(i) != 'D') {
				x = 0;
				break;
				}
			}
		}
	if (x) cout << "Yes" << endl;
	else cout << "No" << endl;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    ll n,m;
    cin>>n>>m;
    vector <ll> a(n);
    vector <int> used(MAXN,0);
    ll mx=-1,xm=INF;
    rep(i,n) {
        cin >> a[i];
        used[2*a[i]]=1;
        mx=max(mx,a[i]);
        xm=min(xm,a[i]);
    }
    vector <ll> pref(n+1,0);
    sort(all(a));
    for (int i=1;i<=n;i++)
        pref[i]=pref[i-1]+a[i-1];
    ll ans=0;
    ll sum=0;
    ll total=0;
    ll l=2*xm,r=2*mx;
    ll t=0;
    while (l<=r)
    {
        ll mid=(l+r)/2;
      //  cout<<mid<<'\n';
        ans=0;
        for (int i=0;i<n;i++)
        {
            auto k=lower_bound(all(a),mid-a[i]);
            if (k!=a.end())
            ans+=n-(k-a.begin());
        }
        if (ans>=m)
            t=mid,l=mid+1;
        else
            r=mid-1;
    }
    ll mid=t+1;
    ans=0;
    for (int i=0;i<n;i++)
    {
        auto k=lower_bound(all(a),mid-a[i]);
        if (k!=a.end())
            ans+=n-(k-a.begin());
    }
    ll mid1=t+1;
    ll ans1=0;
    for (int i=0;i<n;i++)
    {
        auto k=lower_bound(all(a),mid1-a[i]);
        if (k!=a.end())
            ans1+=n-(k-a.begin());
    }
    ll answer=t*(m-ans1);
    for (int i=0;i<n;i++)
    {
        auto k=lower_bound(all(a),mid1-a[i]);
        if (k!=a.end()) {
            answer += a[i]*(n-(k - a.begin()))+pref[n] - pref[k - a.begin() ];
        }
    }
    cout<<answer;
}

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

map<long long, long long> prime_factorize(long long n) {
    map<long long, long long> ret;
    for (long long i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template<const long long M> class mint {
private:
    long long x;
public:
    constexpr mint(long long x = 0) :
            x((x % M + M) % M) {
    }
    constexpr long long value() {
        return x;
    }
    constexpr mint operator-() const {
        return mint(-x);
    }
    constexpr mint& operator+=(const mint &a) {
        if ((x += a.x) >= M)
            x -= M;
        return *this;
    }
    constexpr mint& operator-=(const mint &a) {
        if ((x += M - a.x) >= M)
            x -= M;
        return *this;
    }
    constexpr mint& operator*=(const mint &a) {
        (x *= a.x) %= M;
        return *this;
    }
    constexpr mint& operator/=(const mint &a) {
        return (*this) *= a.inv();
    }
    constexpr mint operator+(const mint &a) const {
        mint res(*this);
        return res += a;
    }
    constexpr mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }
    constexpr mint operator*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    constexpr mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    constexpr mint pow(long long t) const {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }
    constexpr mint inv() const {
        return pow(M - 2);
    }
    constexpr bool operator==(const mint &a) const {
        return x == a.x;
    }
    constexpr bool operator!=(const mint &a) const {
        return x != a.x;
    }
    friend istream& operator>>(istream &in, mint &a) {
        in >> a.x;
        if (a.x < 0)
            a.x += M;
        a.x %= M;
        return in;
    }
    friend ostream& operator<<(ostream &out, const mint &a) {
        out << a.x;
        return out;
    }
};


int main() {
    int N;
    cin >> N;
    mint<1000000007> ans = 1;
    map<long long, long long> M;
    for (int i = 1; i <= N; i++) {
        auto m = prime_factorize(i);
        for (auto it = m.begin(); it != m.end(); it++) {
            M[(*it).first] += (*it).second;
        }
    }
    for (auto it = M.begin(); it != M.end(); it++) {
        ans *= (*it).second + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int r;
    cin>>r;

    cout<<3*r*r<<endl;

    return 0;
}





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

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

    int L, R, max_L = 1, min_R = N;
    for(int i = 0; i < M; i++){
        cin >> L >> R;
        max_L = max(max_L, L);
        min_R = min(min_R, R);
    }

    int ans = min_R - max_L + 1;
    cout << max(ans, 0) << endl;

    return 0;
}

Measured memory_bytes: 384
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

//つねに10億7などの剰余をとる構造体
//参考: https://www.youtube.com/watch?v=L8grWxBlIZ4&t=9858
//参考: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
int mod  = MODA;
struct modint {
	ll x;
	modint (ll x):x(x%mod){}
	modint& operator+=(const modint a){
		(x += a.x ) %= mod;
		return *this;
	}
	modint& operator-=(const modint a){
		(x -= a.x ) %= mod;
		if (x < 0) x += mod;
		return *this;
	}
	modint& operator*=(const modint a){
		(x *= a.x ) %= mod;
		return *this;
	}
	modint& operator/=(modint a){
		ll exp = mod - 2;
		while(exp > 0){
			if(exp & 1) *this *= a.x;
			a *= a.x;
			exp >>= 1;
		}
		return *this;
	}
	modint operator+(const modint a) const{
		modint res(*this);
		return res+=a;
	}
	modint operator-(const modint a) const{
		modint res(*this);
		return res-=a;
	}
	modint operator*(const modint a) const{
		modint res(*this);
		return res*=a;
	}
	modint operator/(const modint a) const{
		modint res(*this);
		return res/=a;
	}
};
modint modpow(modint x, ll n){
	modint res=1;
	while(n > 0){
		if(n & 1) res = res * x.x;
		x = x * x;
		n >>= 1;
	}
	return res;
}
int main() {
    modint ans = 0;
    int tmp;
    ll n, k;
	cin >> n >> k;
	for(ll i = k - 1; i <= n ; i++){
		ll mi = ( i ) * (i +1) / 2;
		ll ma = ( n + n - i) * (i+1) / 2;
		ans += ma - mi + 1; 
	}
    cout << ans.x << endl;
}

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

using namespace std;
using ll = long long;
using indx = size_t;

#define endl '\n'
#define get(type, args...) type args; read(args)
#define all(v) v.begin(), v.end()
#define debug(args...) { string _s = #args; \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s); istream_iterator<string> _it(_ss); \
    err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
template <typename... T>
void read(T&... args) {
    ((cin >> args), ...);
}
template <typename T>
void read(vector<T>& v) {
    for (auto& x : v) cin >> x;
}
template <typename... T>
void write(T&&... args) {
    ((cout << args << " "), ...);
    cout << '\n';
}
template <typename T>
void write(vector<T>& v) {
    for (auto x : v) cout << x << " ";
    cout << '\n';
}

int main() {
    get(int, n, k);
    vector<bool> s(n, false);
    while(k--) {
        get(int, d);
        for (int i = 1; i <= d; i++) {
            get(int, x);
            s[x-1] = true;
        }
    }
    int ans = 0;
    for (indx i = 0; i < s.size(); i++) {
        if (!s[i])
            ans++;
    }
    write(ans);
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  int n;
  cin >> n;

  pair<pair<string, int>, int> p[n];
  for(int i=0; i<n; i++){
    int t;
    string s;
    cin >> s >> t;
    p[i]=make_pair(make_pair(s, -t), i);
  }

  sort(p, p+n);
  for(int i=0; i<n; i++) cout << p[i].second+1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

string s;
cin >> s;
int n = s.size();

if(n < 4) {
    puts("No");
    return 0;
}

if(s.substr(0, 4) =="YAKI") puts("Yes");
else puts("No");

return 0;
}

Measured memory_bytes: 256
import math

if __name__ == '__main__':
    #S,W = int(s[0]), int(s[1])
    K = int(input())
    s = input().rstrip().split(' ')
    A,B = int(s[0]), int(s[1])
    C,D = float(A/K), float(B/K)
    E = math.ceil(C)
    if K == 1:
        print('OK')
    else:
        print('OK' if C <= E and E <= D else 'NG')


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
signed main(){
    int n;
    cin>>n;
    int kai=0;
    int ans=0;
    for(int i=1;i<=55555;i+=10){
        kai=0;
        for(int j=1;j<=i;j++){
            if(i%j==0){
                kai++;
            }
            if(j==i&&kai==2){
                ans++;
                if(ans==n){
                    cout<<i<<endl;
                    return 0;
                }
                else{
                    cout<<i<<" ";
                }
            }
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
 
char *flag;
int head,rear;
int *que;
int factorial[10];
 
int cal_factorial(int n) {
  if(n == 0) return 1;
  return cal_factorial(n-1)*n;
}
 
int stotag(char *s) {
  int tag = 0;
  int i;
  for(i = 0; i < 9; i++) {
    int t,j;
    t = 0;
    for(j = 0; j < i; j++) {
      if(s[j] < s[i]) t++;
    }
    tag += factorial[8-i]*(s[i]-'0'-t);
  }
  return tag;
}
 
char *tagtos(int tag) {
  int i;
  char *s;
  s = (char*)malloc(sizeof(char)*10);
  for(i = 0; i < 9; i++) {
    s[i] = tag%factorial[9-i]/factorial[8-i] + '0';
  }
  s[9] = '\0';
  for(i = 7; i >= 0; i--) {
    int j;
    for(j = 8; j > i; j--) {
      if(s[i] <= s[j]) s[j]++;
    }
  }
  return s;
}
 
 
char *move_up(char s[], int x) {
  if(x < 3) return NULL;
  char *s_new;
  s_new = (char*)malloc(sizeof(char)*10);
  strcpy(s_new,s);
  s_new[x] = s[x-3];
  s_new[x-3] = s[x];
  return s_new;
}
 
char *move_left(char s[], int x) {
  if(x%3 == 0) return NULL;
  char *s_new;
  s_new = (char*)malloc(sizeof(char)*10);
  strcpy(s_new,s);
  s_new[x] = s[x-1];
  s_new[x-1] = s[x];
  return s_new;
}
 
char *move_right(char s[], int x) {
  if(x%3 == 2) return NULL;
  char *s_new;
  s_new = (char*)malloc(sizeof(char)*10);
  strcpy(s_new,s);
  s_new[x] = s[x+1];
  s_new[x+1] = s[x];
  return s_new;
}
 
char *move_down(char s[], int x) {
  if(x > 5) return NULL;
  char *s_new;
  s_new = (char*)malloc(sizeof(char)*10);
  strcpy(s_new,s);
  s_new[x] = s[x+3];
  s_new[x+3] = s[x];
  return s_new;
}
 
int create(char s[], int t) {
  if(strcmp(s,"123456780") == 0) return t;
  int tag = stotag(s);
  if(flag[tag]) return 0;
  flag[tag] = t;
  que[rear] = tag;
  rear++;
  return 0;
}
 
int check_x(char *s) {
  int i = 0;
  while(s[i] != '0') i++;
  return i;
}
 
int cal() {
  char *s_right,*s_left,*s_up,*s_down;
  int k,tag;
 
  tag = que[head];
  char *s = tagtos(tag);
  int x = check_x(s);
   
  if((s_right = move_right(s, x)) != NULL) {
    if((k = create(s_right,flag[tag]+1))) return k;
    free(s_right);
  }
  if((s_left = move_left(s, x)) != NULL) {
     if((k = create(s_left,flag[tag]+1))) return k;
     free(s_left);
  }
  if ((s_up = move_up(s, x)) != NULL) {
    if((k = create(s_up,flag[tag]+1))) return k;
    free(s_up);
  }
  if((s_down = move_down(s, x)) != NULL) {
    if((k = create(s_down,flag[tag]+1))) return k;
    free(s_down);
  }
  free(s);
  head++;
  return 0;
}
   
 
int solve(char s0[]) {
  int k;
  if((k = create(s0,1))) return k;
   
  while(!(k = cal())) {
    if(head == rear) break;
  }
  return k;
}
 
int main()
{
 
  int i,d;
  char s[10];
  for(i = 0; i < 10; i++) factorial[i] = cal_factorial(i);
  flag = (char*)malloc(sizeof(char)*factorial[9]);
  memset(flag , 0, factorial[9]);
  que = (int*)malloc(sizeof(int)*factorial[9]);
  head = 0;
  rear = 0;
  for (i = 0; i < 9; i++) {
    scanf("%d", &d);
    s[i] = d+'0';
  }
  s[9] = '\0';
  printf("%d\n",solve(s)-1);
   
  return 0;
}

Measured memory_bytes: 1684
using System;
using System.Collections.Generic;
using System.Linq;

namespace D
{
    class Program
    {
        static Tree[] tree;
        static void Main(string[] args)
        {
            int[] NQ = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
            int N = NQ[0];
            int Q = NQ[1];

            tree = new Tree[N + 1];
            for (var i = 0; i <= N; i++)
            {
                tree[i] = new Tree();
            }

            // 木構造作成
            List<Tuple<int, int>> AB = Enumerable.Range(0, N - 1)
                .Select(i =>
                {
                    int[] ab = Console.ReadLine().Split().Select(j => int.Parse(j)).ToArray();
                    return new Tuple<int, int>(ab[0], ab[1]);
                }).ToList();
            for (var i = 0; i < N - 1; i++)
            {
                //int[] AB = Console.ReadLine().Split().Select(j => int.Parse(j)).ToArray();
                tree[AB[i].Item1].children.Add(AB[i].Item2);
                tree[AB[i].Item2].parent = AB[i].Item1;
            }

            //for (var i = N; i > 1; i--)
            //{
            //    tree[tree[i].parent].children.UnionWith(tree[i].children);
            //}

            //Dictionary<int, int> indexParam = new Dictionary<int, int>();
            //for (var i = 0; i < Q; i++)
            //{
            //    int[] PQ = Console.ReadLine().Split().Select(j => int.Parse(j)).ToArray();
            //    try
            //    {
            //        indexParam.Add(PQ[0], PQ[1]);
            //    }
            //    catch
            //    {
            //        indexParam[PQ[0]] += PQ[1];
            //    }
            //}
            //foreach (var pair in indexParam)
            //{
            //    tree[pair.Key].counter += pair.Value;
            //    foreach (var i in tree[pair.Key].children)
            //    {
            //        tree[i].counter += pair.Value;
            //    }
            //}
            for (var i = 0; i < Q; i++)
            {
                int[] PQ = Console.ReadLine().Split().Select(j => int.Parse(j)).ToArray();
                tree[PQ[0]].counter += PQ[1];
            }
            for (var i = 1; i < N + 1; i++)
            {
                foreach (var j in tree[i].children)
                {
                    tree[j].counter += tree[i].counter;
                }
            }
            for (var i = 1; i <= N; i++)
            {
                Console.Write($"{tree[i].counter} ");
            }
        }

        static void AddParam(HashSet<int> children, int param)
        {
            foreach (var i in children)
            {
                if (tree[i].children.Count != 0)
                {
                    AddParam(tree[i].children, param);
                }
                tree[i].counter += param;
            }
        }
    }

    class Tree
    {
        public int parent;
        public HashSet<int> children = new HashSet<int>();
        public long counter;
    }
}


Measured memory_bytes: 74916
#include <iostream>

using namespace std;

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  double t = -1;
  int w_ans = 0, s_ans = 0;
 
  for (int w1 = 0; w1 <= f; w1 += 100*a) {
    for (int w2 = 0; w1+w2 <= f; w2 += 100*b) {
      for (int s1 = 0; w1+w2+s1 <= f; s1 += c) {
        for (int s2 = 0; w1+w2+s1+s2 <= f; s2 += d) {
          if (s1 + s2 > (w1+w2)/100*e) {
            continue;
          }
          if ( double(s1+s2) / (s1+s2+w1+w2) > t ) {
            t = double(s1+s2) / (s1+s2+w1+w2);
            s_ans = s1+s2;
            w_ans = w1+w2;
          }
        }
      }
    }
  }
  cout << w_ans+s_ans << " " << s_ans << endl;
  return 0;
}

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

#define rep(x, y) for (int i = (x); i < (y); i++)

typedef long long ll;

using namespace std;

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

    rep(0, n.size()) {
        switch (n[i]) {
            case '1':
                cout << '9';
                break;
            case '9':
                cout << '1';
                break;
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#define int long long
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;


int mpow(int a,int x);
int m_inv(int n){return mpow(n,mod-2);}

int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
    string s;
    cin>>s;
    string ans;
    rep(i,s.size()){
    	if(s[i]=='B'){if(ans.length()>0)ans.pop_back();}
    	else ans.push_back(s[i]);
    }
    cout<<ans<<endl;
}

int mpow(int a,int x){
	int ans=1;
	while(x>0){
		if(x%2==1) (ans*=a)%=mod;
		(a*=a)%=mod;
		x>>=1;
	}
	return ans;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

void fail(){
    cout << 0 << endl;
    exit(0);
}

int main(){
    int N;
    string S;
    cin >> N >> S;
    int64_t ans = 1;
    int now = 0;
    for(int i=0; i<2*N; i++){
        if(S[i] == 'W'){
            if(now == 0) fail();
            if(now%2){
                now++;
            }else{
                mul(ans, now);
                now--;
            }
        }else{
            if(now%2){
                mul(ans, now);
                now--;
            }else{
                now++;
            }
        }
    }
    if(now != 0) fail();
    for(int i=2; i<=N; i++) mul(ans, i);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード(アルファベット順,bits/stdc++.hは使わない派閥)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 998244353 //10^9+7:合同式の法
#define MAXR 300000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

ll fac[MAXR+1],finv[MAXR+1],inv[MAXR+1];

//テーブルの作成
void COMinit() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    FOR(i,2,MAXR){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

// 二項係数の計算
ll COM(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll modpow(ll a,ll n,ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

signed main(){
    COMinit();
    ll n,m,k;cin >> n >> m >> k;
    ll ans=0;
    REP(l,k+1){
        ll ansx=1;
        ansx*=COM(n-1,l);
        ansx*=modpow(m-1,n-l-1,MOD);
        ansx%=MOD;
        ansx*=modpow(m,1,MOD);
        ansx%=MOD;
        ans+=ansx;
        ans%=MOD;
    }
    cout << ans << endl;
}

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

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

  int N; cin >> N;
  bool ans = true;
  int t0 = 0, x0 = 0, y0 = 0;
  for (int i = 0; i < N; i++) {
    int t, x, y; cin >> t >> x >> y;
    int dt = t - t0;
    int dist = abs(x - x0) + abs(y - y0);
    if (dt % 2 != dist % 2 || dt < dist) ans = false;
    t0 = t; x0 = x; y0 = y;
  }
  cout << (ans ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

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

  int N; cin >> N;
  vector<double> x(N), y(N);
  rep(i,N) cin>>x[i]>>y[i];

  vector<int> v(N);
  rep(i,N) v[i] = i;

  double sum = 0;
  do {
    reps(i,1,N) {
      double dx = x[v[i-1]] - x[v[i]];
      double dy = y[v[i-1]] - y[v[i]];
      sum += sqrt(dx*dx + dy*dy);
    }
  } while(next_permutation(ALL(v)));

  int Factorial = 1;
  for(int i = 2; i <= N; i++) Factorial *= i;
  cout << fixed << setprecision(10) << sum / Factorial << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[m];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		int cnt = 0;
		for (int i = 0; i < a.length; i++) {
			if (a[i] > x) {
				break;
			}
			cnt++;
		}
		System.out.println(Math.min(cnt, m - cnt));
	}
}


Measured memory_bytes: 21844
main() {   
    int a, b;
    char op;
    do {
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+') printf("%d\n",a+b);
        else if(op=='-') printf("%d\n",a-b);
        else if(op=='*') printf("%d\n",a*b);
        else if(op=='/') printf("%d\n",a/b);
        } while (op != '?');
}


Measured memory_bytes: 2056
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
		String st = sc.readLine();
		int count = 0;
		flag:
		while(true){
			String[] s = sc.readLine().split(" ");
			for(String i:s){
				if(i.equals("END_OF_TEXT")){
					break flag;
				}else if(i.equalsIgnoreCase(st)){
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 24236
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 1; i <= n ; i++)
#define MAX_N 200100

int par[2][MAX_N];
int myrank[2][MAX_N];

void init(int n){
	rep(i,n){
		par[0][i] = par[1][i] = i;
		myrank[0][i] = myrank[1][i] =0;
	}
}

int find(int x, int z){
	return par[z][x]==x?x:par[z][x] = find(par[z][x], z);
}

void unite(int x, int y, int z){
	x = find(x,z);
	y = find(y,z);
	if(x == y) return;
	
	if(myrank[z][x] < myrank[z][y]){
		par[z][x] = y;
	} else {
		par[z][y] = x;
		if(myrank[z][x] == myrank[z][y]) myrank[z][x]++;
	}
}

signed main(){	
	int N, K, L, a, b;
	unordered_map<int,int> mp;
	cin>>N>>K>>L;
	
	init(N+10);
	
	rep(i, K){cin>>a>>b;unite(a,b,0);}
	rep(i, L){cin>>a>>b;unite(a,b,1);}
	
	// rep(i,N) mp[find(i,0)*(N+1) + find(i,1)]++;
	
	rep(i,N)if(mp.count(find(i,0)*(N+1) + find(i,1)))mp[find(i,0)*(N+1) + find(i,1)]++;else mp.insert(make_pair(find(i,0)*(N+1) + find(i,1),1));
	
	rep(i,N) cout<<(i-1?" ":"")<<mp[find(i,0)*(N+1)+find(i,1)];
	
	cout<<endl;
	
	
	return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

bool judge(string s) {
    for (int i = 0; i < s.length(); i++)
        if (s[i] != s[s.length() - 1 - i]) return false;

    return true;
}

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.length();

    if (not judge(s)) {
        print("No");
        return 0;
    }

    if (not judge(s.substr(0, (n - 1) / 2))) {
        print("No");
        return 0;
    }

    int start = (n + 3) / 2 - 1;
    if (not judge(s.substr(start))) {
        print("No");
        return 0;
    }
    print("Yes");

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		scan.close();
		int x[]= {a,b,c};
		int cnt[]= {0,0};
		for(int i=0;i<3;i++) {
			if(x[i]==5)cnt[0]+=1;
			if(x[i]==7)cnt[1]+=1;
		}

		if(cnt[0]==2 &&cnt[1]==1)System.out.println("YES");
		else System.out.println("NO");
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(void){
	int i,j,k,n,x;
	scanf("%d %d",&n,&x);
	while(n!=0 || x!=0){
		int A=0;
		for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
				for(k=j+1;k<=n;k++){
					if(i+j+k==x) A++;
				}
			}
		}
	printf("%d\n",A);
	scanf("%d %d",&n,&x);
	}
	return 0;
}

Measured memory_bytes: 600