akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

int main() {
	int row,col;
	cin >> row >> col;
	
	vector<vector<int>> a(row, vector<int>(col));
	vector<int> b(col);
	vector<int> c(row);
	
	for(int i=0;i<row;i++) 
		for(int j=0;j<col;j++) cin >> a[i][j];

	for(int i=0;i<col;i++) cin >> b[i];
	
	//calc inner products
	for(int i=0;i<row;i++) {
		c[i] = 0;
		for(int j=0;j<col;j++) {
			c[i] += a[i][j]*b[j];
		}
	}
		
	for(int i=0;i<row;i++) cout << c[i] << endl;

	return 0;
}




Measured memory_bytes: 3160
#include <cstdint>
#include <iostream>

using namespace std;

int main() {
  int64_t X, Y;
  cin >> X >> Y;
  
  int64_t result = 0;
  
  for (int64_t i = X; i <= Y; i*= 2) {
    ++result;
  }
  
  cout << result << endl;
  
  return 0;
}


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

int main(){
	int a[5];
	int p;
	int temp;
	int i,j;
	int max;
	int maxin;
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
	for(i=0;i<5;i++){
		max = a[i];
		maxin = i;
		for(j=i+1;j<5;j++){
			if(max < a[j]){
				max = a[j];
				maxin = j;
			}
		}
		temp = a[i];
		a[i] = a[maxin];
		a[maxin] = temp;
	}
	cout << a[0];
	for(i=1;i<5;i++){
		cout << " " << a[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n, m;
    cin >> n >> m;
    ll ret = 100 * (n - m) + 1900 * (m);
    ll twos = 1;
    for (int i = 0; i < m; ++i) {
        twos <<= 1;
    }
    ret = ret * twos;
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : NISHANT PANDEY *
* NICK : unexme21 *
* INSTITUTION : Lovely Professional University *
******************************************/

#include<bits/stdc++.h>
#define ll       long long int
#define nitro    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define pb       push_back
#define pi       3.1415926535897932384626
#define mod      1000000007
#define endl     '\n'
#define DEBUG    false
#define F        first
#define S        second
//#pragma GCC optimize "trapv"
using namespace std;


 
int main()
{
    nitro;
    int n ,x,t;
    cin >> n >> x >> t;
    cout << int(ceil((float)n/x)*t);
    return 0;

}

Measured memory_bytes: 3636
S = input()

def count(up, down):
    max_count = max(up, down)
    return (up * (up - 1)) / 2 + (
                down * (down - 1)) / 2 + max_count

up = 0
down = 0
answer = 0

for i in range(len(S)):
    if i == len(S) - 1:
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
        answer += count(up, down)
        up = 0
        down = 0
    elif S[i] == ">" and S[i + 1] == "<":
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
        answer += count(up, down)
        up = 0
        down = 0
    else:
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
print(int(answer))

Measured memory_bytes: 44012
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp make_pair

const ll INF = (ll)1e18;
const int N = 5050;
int n;
pll a[N];
ll dp[N];

bool cmp(const pll &v, const pll &u) {
	return v.first + v.second < u.first + u.second;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%lld%lld", &a[i].first, &a[i].second);
	sort(a, a + n, cmp);

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

	for (int i = 0; i < n; i++) {
		for (int j = i; j >= 0; j--) {
			if (a[i].first >= dp[j])
				dp[j + 1] = min(dp[j + 1], dp[j] + a[i].second);
		}
	}
	int m = n;
	while(dp[m] == INF) m--;
	printf("%d\n", m);

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
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;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  string S, T;

  cin >> S >> T;

  int res = 0;

  for (int i = 0; i < 3; i++) {
    if (S[i] == T[i]) {
      ++res;
    }
  }

  cout << res << endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
	for (auto i : a) cerr << i << ' ';\
	cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if (a <= 0 && b >= 0) cout << "Zero\n";
	else {
		if (a > 0) cout << "Positive\n";
		else {
			cout << (((b - a) % 2) ? "Positive\n" : "Negative\n");
		}
	}
	return 0;
}

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

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

  vector<int> heights(N), good_flags(N, 1);
  
  // 高さの格納
  for (int i = 0; i < N; i++) {
    cin >> heights.at(i);
  }
  // 道の格納とフラグの更新
  for (int i = 0; i < M; i++) {
    int a, b, ah, bh;
    cin >> a >> b;
    
    ah = heights.at(a - 1);
    bh = heights.at(b - 1);
    
    if (ah == bh) {
      good_flags.at(a - 1) = 0;
      good_flags.at(b - 1) = 0;
    }
    else if (ah < bh) {
      good_flags.at(a - 1) = 0;
    } else {
      good_flags.at(b - 1) = 0;
    }
  }
  
  ans = accumulate(good_flags.begin(), good_flags.end(), 0);
  
  cout << ans << endl;
}

Measured memory_bytes: 4004
import std.stdio;
import std.string;

void main() {
  auto ar = readln.chomp.split(" ");
  auto a = ar[0];
  auto b = ar[1];
  auto c = ar[2];
  
  if (a == b && b == c) {
    writeln("No");
    return;
  }
  if (a != b && a != c && b != c) {
    writeln("No");
    return;
  }
  writeln("Yes");
}


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

int main()
{
    int n;
    cin >> n;
    int nmod = n % 10;
    if (nmod == 2 || nmod == 4 || nmod == 5 || nmod == 7 || nmod == 9) {
        cout << "hon" << endl;
    } else if (nmod == 3) {
        cout << "bon" << endl;
    } else {
        cout << "pon" << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    int n, m ,c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        int sum = 0;
        for(int j = 0; j < m; j++){
            int a;
            cin >> a;
            sum += a*b[j];
        }
        sum += c;
        if(sum>0){ans++;}
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

S,W = [int(x) for x in stdin.readline().rstrip().split()]

if S > W:
    print('safe')
else:
    print("unsafe")

Measured memory_bytes: 9944
N, X, Y = map(int, input().split(' '))
X = X - 1
Y = Y - 1
cnt = [0] * N

for i in range(N):
    for j in range(N):
        if (j <= i): continue
        temp = j - i
        temp = min(temp, abs(i - X) + 1 + abs(j - Y))
        cnt[temp] = cnt[temp] + 1

for i in range(N):
    if i > 0:
        print(cnt[i])

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
 if (N[0] == N[1]&&N[1] == N[2]){
   cout << "Yes" << endl;
 }else if (N[1] == N[2]&&N[2] == N[3]){
   cout << "Yes" << endl;
 }else{
 cout << "No" << endl;
 }
 
}

Measured memory_bytes: 256
// 基本テンプレート
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    cout << "Christmas";
    if(N < 25) cout << " Eve";
    if(N < 24) cout << " Eve";
    if(N < 23) cout << " Eve";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
P=[[]for _ in[0]*n]
C=[0]*n
k=0
for _ in[0]*m:
 s,t=map(int,input().split());P[s]+=[t];P[t]+=[s]
for i in range(n):
 k+=1
 if C[i]<1:
  s=[i];C[i]=k
  while s:
   u=s.pop()
   for v in P[u]:
    if C[v]<1:C[v]=k;s+=[v]
for _ in[0]*int(input()):
 a,b=map(int,input().split())
 print(['no','yes'][C[a]==C[b]])


Measured memory_bytes: 23912
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int sum=a*100+b*10+c;
		if((a>=1&&a<=9)||(b>=1&&b<=9)||(c>=1&&c<=9))
		{if(sum%4==0)
		 System.out.println("YES");
		 else System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(long long i=a;i<=b;i++)
#define mm make_pair
#define pi 2*acos(0.0)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout.precision(i);cout<<fixed<<ans<<endl;
#define pb(x) push_back(x)
#define lowbit(x) (x)&(-x)
#define out(x) {cout<<x<<endl;return 0;} 
#define all(v) v.begin(),v.end() 
#define eps 1e-8 
#define ll long long
#define ull unsigned long long
using namespace std;
const int mod=1e9+7;
const int inf=0x3f3f3f3f,maxn=1e5+100;
ll gcd(ll x,ll y){if(y==0) return x;else return gcd(y,x%y);} 
ll ksm(ll a,ll b){ll r=1;while(b){if(b&1) r=(r*a)%mod;a=a*a%mod;b>>=1;}return r;} 
ll l,r,p=2019;
int main()
{
	cin>>l>>r;
	ll res=l%p,ans=1e9;
	if(r-l+res<p) 
	{
		FOR(i,l,r)
		FOR(j,i+1,r)
		{
			ans=min((i*j)%p,ans);
		}
		cout<<ans<<endl;
	}
	else cout<<"0"<<endl;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<vector<int>>a(3,vector<int>(N));
  for(int i=0;i<N;i++)cin>>a[0][i]>>a[1][i]>>a[2][i];
  vector<vector<int>>dp(N,vector<int>(3,0));
  for(int i=0;i<3;i++)dp[0][i]=a[i][0];
  for(int i=1;i<N;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j==k)continue;
        dp[i][j]=max(dp[i][j],dp[i-1][k]+a[j][i]);
      }
    }
  }
  int ans=0;
  for(int i=0;i<3;i++){
    ans=max(ans,dp[N-1][i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6908
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
using ll = long long;

map<ll,int>mp;

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  vector<ll>s(n+1);
  rep(i,n){
    cin>>a[i];
    s[i+1]=s[i]+a[i];
  }
  rep(i,n+1){
    mp[s[i]]++;
  }
  ll ans=0;
  rep(i,n){
    mp[s[i]]--;
    ans+=mp[s[i]];
  }
  cout<<ans<<endl;
  return(0);
}


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

int main(){
	
	int i;
	vector<int> vec(5.0);
	
	
	for(i = 0 ; i<5 ; i++){
		cin >> vec[i];
	}
	
	
	
	sort(vec.begin() , vec.end() );
	
	for(i = 4; i>=0 ; i--){
		
		
		
		if(i == 0)  cout << vec[i] << endl;
		
		else    cout << vec[i] <<" ";
		
	}
	
	return 0;
	
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
int n;
ii L[200005], R[200005];
vector<ii> S[200005];
ll V;
void dfs(int u){
    if (L[u].first == 0){
        S[u].push_back({0ll,0ll});
        return;
    }
    int l = L[u].first, cl = L[u].second;
    int r = R[u].first, cr = R[u].second;
    dfs(l);
    dfs(r);
    if (S[l].size() < S[r].size()){
        swap(l,r);
        swap(cl,cr);
    }
    vector<ii> _v;
    for (auto x : S[l]){
        _v.push_back({x.first,x.second});
        _v.push_back({x.second,x.first});
    }
    sort(_v.begin(),_v.end());
    vector<ii> P;
    int cur = S[r].size()-1;
    for (auto x : S[l]){
        while (cur >= 0 && S[r][cur].first + x.first + cl + cr > V) cur--;
        if (cur == -1) break;
        P.push_back({cl+x.second,cr+S[r][cur].second});
        P.push_back({cr+S[r][cur].second,cl+x.second});
    }
    sort(P.begin(),P.end());
    for (auto x : P){
        if (S[u].empty() || S[u].back().second > x.second) S[u].push_back(x);
    }
}
bool test(ll x){
    V = x;
    for (int i = 1; i <= n; i++) S[i].clear();
    dfs(1);
    if (S[1].size()) return true;
    else return false;
}
int main(){
    scanf("%d",&n);
    for (int i = 2; i <= n; i++){
        int a,v;
        scanf("%d%d",&a,&v);
        if (L[a].first == 0){
            L[a] = ii(i,v);
        }
        else{
            R[a] = ii(i,v);
        }
    }
    ll lo = 0, hi = 131072ll*131072;
    while (lo < hi){
        ll mid = (lo+hi)/2;
        if (test(mid)) hi = mid;
        else lo = mid+1;
    }
    printf("%lld",lo);
}


Measured memory_bytes: 40520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_H = 10;
const int W = 5;

int H, stone[MAX_H][W];

bool to_disappear[MAX_H][W];
int next_stone_row[MAX_H][W];

bool detect_chain();
void make_next_stone_row();
void update_stone();
void print_stone();
int solve();

int main() {
    while (true) {
        cin >> H;
        if (H == 0) break;
        REP(i, H) REP(j, W) cin >> stone[i][j];

        int score = solve();
        PRINT(score);
    }
    return 0;
}

bool detect_chain() {
    bool exist_chain = false;
    REP(i, H) REP(j, W) to_disappear[i][j] = false;

    REP(i, H) { // i行目
        for (int j = W; j >= 3; j--) { // j個連続
            for (int k = 0; k + j - 1 < W; k++)  { // k列目を起点
                bool is_chain = true;
                if (stone[i][k] == -1) is_chain = false;
                REP(l, j-1) { // k+l列目とk+l+1列目の比較
                    if (stone[i][k+l] != stone[i][k+l+1]) is_chain = false;
                }

                if (is_chain) {
                    exist_chain = true;
                    REP(l, j) to_disappear[i][k+l] = true;
                }
            }
        }
    }
    return exist_chain;
}

void make_next_stone_row() {
    for (int i = H-1; i >= 0; i--) {
        REP(j, W) {
            if (i == H-1) next_stone_row[i][j] = H-1;
            else next_stone_row[i][j] = max(next_stone_row[i+1][j] - 1, -1);
            while (true) {
                if (next_stone_row[i][j] == -1) break;
                if (to_disappear[next_stone_row[i][j]][j] == false) break;
                next_stone_row[i][j]--;
            }
        }
    }
    return;
}

void update_stone() {
    for (int i = H-1; i >= 0; i--) {
        REP(j, W) {
            if (next_stone_row[i][j] == -1) stone[i][j] = -1;
            else stone[i][j] = stone[next_stone_row[i][j]][j];
        }
    }
    return;
}

void print_stone() {
    REP(i, 32) printf("-");
    printf("\n");
    REP(i, H) {
        REP(j, W) printf("%d\t", stone[i][j]);
        printf("\n");
    }
}

int solve() {
    int score = 0;
    REP(i, H) REP(j, W) score += stone[i][j];
    while (true) {
        // print_stone();
        if (!detect_chain()) break;
        make_next_stone_row();
        update_stone();
    }
    REP(i, H) REP(j, W) if (stone[i][j] != -1) score -= stone[i][j];
    return score;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
signed main(){
	int n,s,c[100005];
  	cin>>n;
  	for(int i=0;i<n;i++){
      	cin>>s;
      	c[s-1]=i+1;
    }
  for(int i=0;i<n;i++){
  	cout<<c[i];
    if(i<n-1)
      cout<<' ';
    else
      cout<<endl;
  }
	  return(0);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  ll a = h1 * 60 + m1;
  ll b = h2 * 60 + m2;

  cout << b - a - k << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> p;
typedef unsigned long long int ull;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
ll MOD=998244353;
ll n,m,k;
vector<ll> fac(2e5+1),inv(2e5+1),finv(2e5+1);
void initCOM(){
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(int i=2;i<=2e5;i++){
        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<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll power(ll a,ll x){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%MOD;
        a=a*a%MOD;
        x>>=1;
    }
    return res;
}
int main(){
    initCOM();
    cin>>n>>m>>k;
    ll ans=0;
    for(int j=0;j<=k;j++){
        ans+=(m*COM(n-1,j)%MOD)*power(m-1,n-1-j)%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7380
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
signed main(){
  int N; cin>>N;
  string S=to_string(N);
  string ans;
  rep(i,0,S.size()-1) ans+='9';
  int ANS=0;
  if(S.substr(1,S.size()-1)==ans)
    ANS=9*(S.size()-1)+(S[0]-'0');
  else
    ANS=9*(S.size()-1)+(S[0]-'1');
  cout<<ANS<<endl;
  }



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var s=sc.S;
		for(int i = 0;i<s.Length;i++) {
			var c=s[i]+n;
			if(c>90){c-=26;}
			Console.Write("{0}",(char)c);
		}
		Console.WriteLine();
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int mx = 0;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        mx = max (mx, x);
        if (mx > x  && mx - x > 1) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
#define LEN 1000005
 
typedef struct pp{
  char name[100];
  int t;
}P;
 
P Q[LEN+1];
int head=1, tail;
 
void enqueue(P x){
  Q[tail]=x;
  tail++;
}

P dequeue(){
  P x;
  x=Q[head];
  head++;
  return x;
}
 
int main(){  
  int n,q,i;
  int elaps = 0, c=0;
  P u;

  scanf("%d %d",&n,&q);
 
  if(n>=1 && n<=100000){
    if(q>=1 && q<=1000){
    
      for ( i = 1; i <= n; i++){
	scanf("%s", Q[i].name);
	scanf("%d", &Q[i].t);
      }
 
      tail=n+1;
 
 
      while(1){
 
	u=dequeue();
 
	u.t=u.t-q;
 
	if(c==n){ 
	  break;
	}
 
	if(u.t>0){
	  enqueue(u);
	  elaps+=q;
	}
 
	if(u.t<=0){
	  elaps+=(u.t+q);
	  u.t=0;
	  printf("%s %d\n",u.name,elaps);
	  c++;
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 21072
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b;
  cin >> a >> b;
  if(a==1) a+=13;
  if(b==1) b+=13;
  
  string ans;
  if(a==b) ans = "Draw";
  else if(a>b) ans = "Alice";
  else ans = "Bob";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import math

stra = input()

leng = len(stra)
kai1 = ""
kai2 = ""

kai1 = stra[:math.ceil(leng / 2)]
kai2 = stra[leng // 2:]

new_kai2 = kai2[::-1]

res = 0

for i in range(len(kai1)):
    if kai1[i] != new_kai2[i]:
        res += 1

print(res)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> p;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int main(){
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  
  rep(i, n) {
    cin >> a[i];
  }
  ll ans = INF;
  for (int i = 0; i + k - 1 < n; ++i) {
    ll l = a[i];
    ll r = a[i + k - 1];
    ll d1 = abs(l) + abs(l - r);
    ll d2 = abs(r) + abs(r - l);
    ans = min(ans, min(d1, d2));
  }
  cout << ans << endl;
  
}


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

int n, a = 0, w = 0, t = 0, r = 0;
string s;

int main()
{
  	cin >> n;

  for(int i = 0; i < n; i++){
    cin >> s;
    
    if(s == "AC")
      a++;
    else if (s == "WA")
      w++;
    else if (s == "TLE")
      t++;
    else
      r++;
  }
  
  cout << "AC x " << a << endl << "WA x " << w << endl <<
    "TLE x " << t << endl << "RE x " << r << endl;
}


Measured memory_bytes: 3616
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
int A,B,C,D;
cin >> A >>B>>C>>D;

int TAKA,AOKI;
  TAKA = (A-1) / D; //攻撃に耐える回数
  AOKI = (C-1) / B;
  
  
if(TAKA >= AOKI ){
    cout << "Yes" <<endl;
}
else{
    cout << "No" <<endl;
}
}


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/
struct RMQTree{
	// 0-indexed
	// for vertex n
	// par (n-1)/2
	// chi 2n+1,2n+2

	// index i
	// bottom vertex n+i-1

	int segn2; // imply actually vertex number
	vector<ll> data;

	RMQTree(int n){
		segn2=1;
		while(segn2<n) segn2*=2; //必要分2^Mを取る

		data.assign(segn2*2-1,0LL); // 2^31 - 1
	}

	// maximum in [a,b). l,r is given vertex k according the interval.
	ll query(int a,int b,int l=0,int r=-1,int k=0){

		if(r==-1) r=segn2; // when calling function at first
		if (r <= a || b <= l) return 0; //disjoint
		if (a <= l && r <= b) return data[k]; //include

		ll vl = query(a,b,l,(l+r)/2,k*2+1);
		ll vr = query(a,b,(l+r)/2,r,k*2+2);

		return max(vl,vr);
	}

	// i value |-> x (0-indexed)
	void update(int k,ll x){
		k += segn2 - 1;
		data[k]=x;

		while(k > 0){
			k=(k-1)/2; //move to par
			data[k]=max(data[k*2+1],data[k*2+2]); //refresh
		}

		return;
	}
};

int main(){
	ll N; cin >> N;
	vector<ll> a(200002);
	vector<int> h(200002);
	vector<ll> dp(200002);
	RMQTree seg(200002);
	REP(i,N){
	    int H;
	    cin >> H;
	    h[i] = H;
	}

	REP(i,N){
		cin >> a[i];
	}


	dp[h[0]] = a[0];
	seg.update(h[0],a[0]);

	for (int i = 1; i < N; ++i) {
		ll M = seg.query(1,h[i]);
		//cout << M << endl;
		dp[h[i]] = a[i] + M;
		seg.update(h[i],dp[h[i]]);
	}

	ll ans = 0;
	REP(i,200002){
	    chmax(ans,dp[i]);
	}

	cout << ans << "\n";



	return 0;
}


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

int main() {
  int n;cin>>n;
  map<string,int> mp;
  rep(i,n){
    string s;cin>>s;
    mp[s]++;
  }
  int cnt=0;
  for(auto p:mp)cnt=max(cnt,p.second);
  for(auto p:mp){
    if(cnt==p.second)cout<<p.first<<endl;
  }
}

Measured memory_bytes: 19212
S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

if A+B+C+D == 7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A+B+C-D == 7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A+B-C+D == 7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A+B-C-D == 7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif A-B+C+D == 7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A-B+C-D == 7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A-B-C+D == 7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A-B-C-D == 7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")

Measured memory_bytes: 3064
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    data=[parseMap(split(readline())) for i in 1:n-1]
    for i in 1:n-1
        now=data[i][2]
        for j in i:n-1
            if now<=data[j][2]
                now=data[j][2]+data[j][1]
            else
                res=(now-data[j][2])%data[j][3]
                if res>0
                    res=data[j][3]-res
                end
                now+=res+data[j][1]
            end
        end
        println(now)
    end
    println(0)
end
main()

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

// ------ disjoint set ------ //
struct UnionFind {
    vector<int> data;
    int __size;
    UnionFind(int size) : data(size, -1), __size(size) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) != (y = root(y))) {
            if (data[y] < data[x]) swap(x, y);  // par -> child とは限らない
            data[x] += data[y]; data[y] = x; __size--;
        }
        return x != y;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return __size; }
};

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> query(M);
    for (int i = 0; i < M; i++) {
        cin >> query[i].first >> query[i].second;
        --query[i].first, --query[i].second;
    }
    reverse(query.begin(), query.end());

    UnionFind uf(N);
    vector<long long> ans;
    long long cur = 1LL * N * (N - 1) / 2;
    for (int i = 0; i < M; i++) {
        ans.push_back(cur);

        int a = query[i].first, b = query[i].second;
        if (uf.findSet(a, b)) continue;
        int size_a = uf.size(a), size_b = uf.size(b);
        cur -= 1LL * size_a * size_b;
        uf.unionSet(a, b);
    }
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < M; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    string s;
    cin >> s;
    int count = 0;
    int mx = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
            count++;
        }else{
            count = 0;
        }
        mx = max(count,mx);
    }
    cout << mx <<endl;
}

Measured memory_bytes: 3620
# coding: utf-8
# Your code here!
import sys
import collections
from operator import mul
from functools import reduce

def input():
    return sys.stdin.readline().rstrip()
    
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
a = [''.join(sorted(input())) for _ in range(N)]
c = collections.Counter(a)
c_array = list(filter(lambda x: x >= 2, c.values()))
ctr = 0

for i in c_array:
    ctr += cmb(i, 2)
print(ctr)

Measured memory_bytes: 64092
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

/*動的計画入門*/
int main(){
    long long n, m, k, ans=0;
    cin >> n >> m >> k;
    vector<long long> av, bv;
    av.push_back(0);
    bv.push_back(0);
    for(long long i=1; i<=n; i++){
        long long a;
        cin >> a;
        av.push_back(a+av[i-1]);
    }
    for(long long i=1; i<=m; i++){
        long long b;
        cin >> b;
        bv.push_back(b+bv[i-1]);
    }
    long long best = m;
    for(int i=0; i<=n; i++){
        long long k_now = k - av[i];
        if(k_now < 0) break;
        long long ans_tmp;
        while(best >= 0){
           double k_now_tmp = k_now - bv[best];
           if(k_now_tmp >= 0){
              ans_tmp = best + i;
              break;
           }else{
              best--;
           }
        }
        ans = max(ans, ans_tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7984
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ACprac
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] num1 = Console.ReadLine().Split(' ');
            int N = int.Parse(num1[0]);
            int M = int.Parse(num1[1]);
            int C = int.Parse(num1[2]);

            int[] B = new int[M];

            int count = 0;

            for (int i = 0; i < N+1; i++)
            {
                string[] num2 = Console.ReadLine().Split(' ');
                int tmp = 0;

                for (int k = 0; k < M; k++)
                {
                    if(i == 0)
                    {
                        B[k] = int.Parse(num2[k]);
                    }
                    else
                    {
                        tmp = tmp + (int.Parse(num2[k])*B[k]);
                    }
                }

                if(i > 0)
                {
                    if(tmp + C > 0)
                    {
                        count++;
                    }
                }

            }

            Console.WriteLine(count);

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    ll realA = 0;
    for (ll i = 1; i < B - A; i++)
    {
        realA += i;
    }
    cout << realA - A << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long long MIN(long long a,long long b){return a<b?a:b;}
int main(){
  int t;
  scanf("%d",&t);
  while(t--){
    long long n,a[210],d[210],b[210],r=0,i,j,x;
    scanf("%lld",&n);
    for(i=0;i<n;i++)scanf("%lld",&d[i]);
    for(i=0;i<n;i++)scanf("%1lld",&a[i]);
    for(i=n;i--;){
      x=d[i];
      for(j=0;j<r;j++)x=MIN(x,x^b[j]);
      if(x){
	if(a[i])goto NEXT;
	else  b[r++]=x;
      }
    }
    printf("0\n");
    continue;
  NEXT:;
    printf("1\n");
  }
  return 0;
}
  


Measured memory_bytes: 1620
#include <bits/stdc++.h>
 
using namespace std;
 
#define f(i,a,b) for(int i=a;i<b;i++)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int> >
#define ss second
#define ff first
#define ll long long
#define lld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define pqll priority_queue< ll >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define INF 1000000000
#define NINF -1000000000
#define endl '\n'

void solve(){
    ll n , k;
    cin >> n >> k;
    vl a(n);
    for (int i = 0 ; i < n ;  i++){
        cin >> a[i];
    }
    for (int i = 0 ; i <n-k ; i++ ){
        if (a[i+k] > a[i]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
}


int main(){

    #ifndef ONLINE_JUDGE 
  
    // For getting input from input.txt file 
    freopen("input.txt", "r", stdin); 
  
    // Printing the Output to output.txt file 
    freopen("output.txt", "w", stdout); 
  
    #endif 

    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
 

    int t = 1;
    // cin >> t;
    
    while(t--){
        solve();
        // cout << "Case #" << (tt+1) <<":" << endl;
    }
}

Measured memory_bytes: 4788
#include<iostream>
#include<string>
#include<stdio.h>

using namespace std;

int main(){
  int i;
  string str;
  getline(cin, str);
  for(i=0; i<str.length(); i++){
    if(isalpha(str[i]))putchar(toupper(str[i]));
    else putchar(str[i]);
  }
  cout << endl;
}

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

int main() {
	int X,A,B;
	cin >> X >> A >> B;
	if(A-B>=0)
		cout << "delicious";
	else if(B-A<=X)
		cout << "safe";
	else
		cout << "dangerous";
	cout << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int N = in.nextInt();
		int M = in.nextInt();
		int[] X = new int[M];
		for (int i = 0; i < M; i++) {
			X[i] = in.nextInt();
		}
		Arrays.parallelSort(X);

		if (N >= M) {
			System.out.println(0);
			return;
		}

		int[] diff = new int[M];
		for (int i = 0; i < M - 1; i++) {
			diff[i] = Math.abs(X[i] - X[i + 1]);
		}
		Arrays.parallelSort(diff);

		int temp = 0;
		for (int i = 1; i < N; i++) {
			temp += diff[M - i];
		}
		System.out.println(X[M - 1] - X[0] - temp);
	}
}


Measured memory_bytes: 50228
#include <iostream>
#include <algorithm>
#include <set>
#include <numeric>
#include <iomanip>

using namespace std;

using P = pair<int, long>;

int main() {
    int n, m;
    cin >> n >> m;
    P cities[m];
    for (auto &c:cities) 
        cin >> c.first >> c.second;
    int ids[m];
    iota(ids, ids+m, 0);
    sort(ids, ids+m, [&](int l, int r) {
        return cities[l] < cities[r];
    });
    P ans[m];
    int prev = 0;
    long cnt = 0;
    for (auto i:ids) {
        P now = cities[i];
        if (prev != now.first) cnt = 1;
        ans[i] = {now.first, cnt};
        cnt++;
        prev = now.first;
    }
    cout << setfill('0') << right;
    for (auto a:ans) cout << setw(6) << a.first << setw(6) << a.second << '\n';
    return 0;
}

Measured memory_bytes: 4992
#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;
    cin >> n;
    vector<int> a(n);
    REP(i, n) {
        cin >> a[i];
    }
    vector<int> b(a);
    sort(ALL(a));

    REP(i, n) {
        if (b[i] == a.back()) {
            std::cout << a[n-2] << '\n';
        } else {
            std::cout << a.back() << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 3200
n = gets.to_i
a = gets.split.map(&:to_i)
len = a.max.to_s(2).length

ans = 0
len.times do |l|
  n_1 = a.count { |x| x[l] == 1 }
  ans += ((n - n_1) * n_1 * ((2 ** l) % 1000000007)) % 1000000007
  ans %= 1000000007
end
puts ans


Measured memory_bytes: 34820
N,M=map(int,input().split())
A=sorted(list(map(int,input().split())))[::-1]
b= sum(A)
c=True
for i in range(M):
  if A[i]<(b/(4*M)):
    c=False
if c==True:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 2940
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	k := n / 7
	for i := 0; i <= k; i++ {
		l := n - i*7
		if l%4 == 0 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


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

int main () {
  string s;
  cin >> s;
  
  int a, z;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      a = i;
      break;
    }
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[s.size()-i] == 'Z') {
      z = s.size()-i;
      break;
    }
  }
  cout << z-a+1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main()
{
	FAST;
	ll a, b;
	cin >> a >> b;
	cout << a*b/__gcd(a,b);
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
 
using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);
 
int n, M[N][N];
int d[N];
 
void bfs(int s) {
    queue<int> q;
    q.push(s);
    int i, u, v;
    for ( i = 0; i < n; i++ ) d[i] = INFTY;
    d[s] = 0;
 
    while ( !q.empty() ) {
        u = q.front();
        q.pop();
        for ( v = 0; v < n; v++ ) {
            if ( M[u][v] == 0 ) continue;
            if ( d[v] != INFTY ) continue;
            d[v] = d[u] + 1;
            q.push(v);
            }
        }
 
        for ( i = 0; i < n; i++ ) {
            cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
    }
}
 
int main() {
    int u, k, v, i, j;
 
    cin >> n;
 
    for ( i = 0; i < n; i++ ) {
        for ( j = 0; j < n; j++ ) M[i][j] = 0;
    }
 
    for ( i = 0; i < n; i++ ) {
        cin >> u >> k;
        u--;
        for ( j = 0; j < k; j++ ) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
 
    bfs(0);
 
    return 0;
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    int N;
    cin >> N;
    vector<int> s(N);
    rep(i,N) cin >> s[i];

    sort(all(s));
    ll total = 0;
    rep(i,N) total += s[i];

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

    ll ans = 0;

    if( total%10 != 0 )
    {
        cout << total << endl;
        return 0;
    }
    
    rep(i,s.size())
    {
        if( s[i]%10 != 0 )
        {
            cout << total-s[i] << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] list = str.split(" ");
		int w = Integer.parseInt(list[0]);
		int h = Integer.parseInt(list[1]);
		int n = Integer.parseInt(list[2]);

		String[][] xya = new String[n][];

		for(int i=0; i<n; i++){
			String string = input.readLine();
			xya[i] = string.split(" ");
		}

		int xmin = 0;
		int xmax = w;
		int ymin = 0;
		int ymax = h;

		for(int i=0; i<n; i++){
			if(xya[i][2].equals("1")){
				if(Integer.parseInt(xya[i][0]) > xmin){
					xmin = Integer.parseInt(xya[i][0]);
				}
			}else if(xya[i][2].equals("2")){
				if(Integer.parseInt(xya[i][0]) < xmax){
					xmax = Integer.parseInt(xya[i][0]);
				}
			}else if(xya[i][2].equals("3")){
				if(Integer.parseInt(xya[i][1]) > ymin){
					ymin = Integer.parseInt(xya[i][1]);
				}
			}else if(xya[i][2].equals("4")){
				if(Integer.parseInt(xya[i][1]) < ymax){
					ymax = Integer.parseInt(xya[i][1]);
				}
			}
		}

		if(xmin > xmax || ymin > ymax){
			System.out.println("0");
		}else{
			int answer = (xmax-xmin) * (ymax-ymin);
			System.out.println(answer);
		}


	}

}


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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a+b > c+d) cout << "Left" << endl;
    else if (a+b < c+d) cout << "Right" << endl;
    else cout << "Balanced" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define INF 1000000007
using P = pair<int, int>;
int main(){
    ll n,m;
    cin>>n>>m;
    ll ans=0;
    if(n>1&&m>1)ans+=(n-2)*(m-2);
    else if(n==1&&m>1)ans+=m-2;
    else if(n>1&&m==1)ans+=n-2;
    else ans+=1;
    cout<<ans<<endl;
}


Measured memory_bytes: 256