akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N;
    cin >> N;
    cout<<N*(N-1)/2;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
//#pragma GCC optimize ("O3")
//#define map unordered_map
using namespace std;
 
int m3[2160];
int m2[2160];
int n;
int cnt[100005];
int it=0;
int b[100005];
int a[100005];
map<int, int> concac;
map<int, int> used;
bool pr[2155];
vector<int> caiconcac;
signed main()
{
	for(int i=2; i<=2155; i++)
	{
		if(pr[i]) continue;
		for(int j=2*i; j<=2155; j+=i)
		{
			pr[j]=true;
		}
	}
	for(int i=2; i<=2155; i++)
	{
		if(!pr[i]) caiconcac.push_back(i);
	}
	ios::sync_with_stdio(false);
	for(int i=1; i<=2155; i++)
	{
		m3[i]=i*i*i;
		m2[i]=i*i;
	}
//	cout<<m3[1000];
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		for(auto j:caiconcac)
		{
			while(a[i]%m3[j]==0)
			{
				a[i]/=m3[j];
			}
//			cout<<a[i]<<endl;
		}
	}
	sort(a+1, a+n+1);
	for(int i=1; i<=n; i++)
	{
//		cout<<a[i]<<" ";
		if(a[i]!=a[i-1])
		{
			it++;
			b[it]=a[i];
		}
		cnt[it]++;
	}
	concac[-1]=1;
//	//cout<<endl;
	for(int i=1; i<=it; i++)
	{
		concac[b[i]]=cnt[i];
	}
	int ans=0;
	for(int i=1; i<=it; i++)
	{
//		cout<<b[i]<<" "<<it<<endl;
		if(used[b[i]]) continue;
		used[b[i]]=1;
		int lol=concac[b[i]];
		if(b[i]==1) 
		{
			ans++; 
			continue;
		}
		int lay=1;
		for(auto j:caiconcac)
		{
			int yolo=0;
			while(b[i]%j==0)
			{
				b[i]/=j;
				yolo++;
			}
			if(yolo==1) lay*=m2[j];
			else if(yolo==2) lay*=j;
			if(lay>10000000000)
			{
				lay=-1;
				b[i]=1;
				break;
			}
		}
		if(b[i]>1)
		{
			if((int)sqrt(b[i])*(int)sqrt(b[i])==b[i])
			{
				lay*=sqrt(b[i]);
				if(lay>10000000000) lay=-1;
			}
			else
			{
				lay*=b[i];
				if(lay>10000000000) lay=-1;
				else lay*=b[i];
				if(lay>10000000000) lay=-1;
			}
		}
		//cout<<i<<" "<<lay<<endl;
		ans+=max(concac[lay],lol);
		used[lay]=1;
//		<<i<<" "<<ans<<endl;
	}
	cout<<ans;
}

Measured memory_bytes: 22912
#include <iostream>
#include <algorithm>
using namespace std;
const int num = 100, INF = 2000000000;
int d[num][num];
int n;
inline void floyd() {
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			if (d[i][k] == INF) continue;
			for (int j = 0; j < n; j++) {
				if (d[k][j] == INF) continue;
				else d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}
int main() {
	int e, s, t, w;
	cin >> n >> e;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)d[i][j] =((i == j) ? 0 : INF);
	}
	for (int i = 0; i < e; i++) {
		cin >> s >> t >> w;
		d[s][t] = w;
	}
	floyd();
	int tf = 1;
	for (int i = 0; i < n; i++) {
			if (d[i][i] < 0)  tf = 0;
		}
	if (tf == 0) cout << "NEGATIVE CYCLE" << endl;
	else {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (j) cout << " ";
				if (d[i][j] == INF)cout << "INF";
				else cout << d[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3132
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		if(a==25) System.out.print("Christmas");
		else if(a==24) System.out.print("Christmas Eve");
		else if(a==23) System.out.print("Christmas Eve Eve");
		else if(a==22) System.out.print("Christmas Eve Eve Eve");


	}

}


Measured memory_bytes: 20692
#include<bits/stdc++.h>
using namespace std;
struct Node{
  int key;
  Node *parent,*left,*right;
};

Node *root,*NIL;

void Preorder(Node *pp){
  if(pp==NIL)return;
  cout<<" "<<pp->key;
  Preorder(pp->left);
  Preorder(pp->right);
}
void Inorder(Node *in){
  if(in==NIL)return;
  Inorder(in->left);
  cout<<" "<<in->key;
  Inorder(in->right);
}

void insert(int k){
  Node *z;
  Node *y=NIL; //x's parent
  Node *x=root; //T's root
  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while(1){
    if(x==NIL)break;
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else {
    if(z->key<y->key){
      y->left=z;
    }
    else {
      y->right=z;
    }
  }
}
int treesearch(Node *x, int k){
    if(x==NIL){
      return false;
    }
    if(k==x->key)return true;
    if(k<x->key){
      return treesearch(x->left,k);
    }
    else{
      return treesearch(x->right,k);
    }
}

int main(){
  int n=0,in=0,f=0;
  int i=0;
  char cel[10];
  cin>>n;
  for(i=0;i<n;i++){
    cin>>cel;
    if(!strcmp(cel, "insert")){
      cin>>in;
      insert(in);
    }
    else if(!strcmp(cel, "print")){
      Inorder(root);
      cout<<endl;
      Preorder(root);
      cout<<endl;
    }
    else if(!strcmp(cel, "find")){
      cin>>in;
      f=treesearch(root,in);
      if(treesearch(root,in)){
	cout<<"yes"<<endl;
      }
      else {
	cout<<"no"<<endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 21820
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <set>

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

typedef long long ll;

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

class BIT{
  vector<ll> bit;
public:
  BIT(int n) : bit(n + 1) {}
  void update(int idx, ll val){
    idx++;
    while(idx < (int)bit.size()){
      bit[idx] = max(bit[idx], val);
      idx += idx & -idx;
    }
  }

  ll p(int i){
    ll s = 0;
    i++;
    while(i > 0){
      s = max(s, bit[i]);
      i -= i & -i;
    }
    return s;
  }
};

int main(){
  const int n = getInt();
  BIT bit(n + 1);

  REP(i,n){
    const int x = getInt();
    bit.update(x, bit.p(x) + x);
  }

  printf("%lld\n", (ll)n * (ll)(n + 1) / 2 - bit.p(n));

  return 0;
}

Measured memory_bytes: 1800
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,X = readInts()
    a = list(map(lambda x:abs(X-int(x)), input().split()))
    res = 0
    # 0で初期化していいのか
    from fractions import gcd
    for i in range(n):
        res = gcd(res,a[i])
    print(res)
if __name__ == '__main__':
  main()


Measured memory_bytes: 14232
#include<stdio.h>
#define N 1000000

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

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

#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

using namespace std;

ll mod(ll a, ll b) { return (a % b + b) % b; }
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}


int main()
{
	fast;
	ll n;
	cin>>n;
	ld t = (double)n/3;
	cout << fixed << setprecision(8) << t*t*t << endl;
	return 0;	
} 

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli k, x;
    cin>>k>>x;
    for(lli i=-k+1;i<k;i++){ 
        cout<<x+i<<sp;
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = (int)(n)-1; i >=0; i--)
#define INF 1000000000000
using ll = long long;

int main(){
  ll n;
  cin >> n;
  ll ans = INF;
  for(ll i = 1; i*i <= n; i++){
    ll tmp = 0;
    if(n%i==0){
      tmp = i+n/i-2;
      ans = min(ans,tmp);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

int main(){
    int n;
    cin >> n;
    if(n%1000!=0) cout << 1000-n%1000 << endl;
  	else cout << 0 << endl;
}



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

int main(){
 	int number;
	cin >> number;
	char color[number];
  	for(int i = 0; i < number; ++i){
    	cin >> color[i];
    }
  
	string ans = "Three";
   	for(int i = 0; i < number; ++i){
    	if('Y' == color[i]){
        	ans = "Four";
    	}
    }
  	cout << ans << endl;
  	return 0;
}


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

int main(){
 int N,K;
  int count=0;
  cin>>N>>K;
vector<int> h(N);
  for(int i=0;i<N;i++){
    cin>>h.at(i);
  if(h.at(i)>=K){
    count++;
  }
  }
  cout<<count;
}
  

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

int main(){
  string S,T;
  cin >> S >> T;
  int count = 0;
  int size = S.size();
  
  for(int i = 0; i < size; i++) {
    if(S.at(i) == T.at(i)) {
      continue;
    }
    else {
      S.at(i) = T.at(i);
      count++;
    }
  }
    
    cout << count << endl;
}

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

int main() {
  int N, num = 0;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++)
    cin >> d.at(i);
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());
    for (int i = 0; i < N; i++) {
      if (i == 0 || d.at(i) != d.at(i-1))
        num++;
    }
  cout << num << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    h, n = LI()
    a_s = []
    b_s = []

    for i in range(n):
        a, b = LI()
        a_s.append(a)
        b_s.append(b)

    dp = [INF for j in range(h+1)]
    dp[0] = 0
    for i in range(h):
        for j in range(n):
            if i + a_s[j] > h:
                if dp[h] > dp[i] + b_s[j]:
                    dp[h] = dp[i] + b_s[j]
            else:
                if dp[i + a_s[j]] > dp[i] + b_s[j]:
                    dp[i + a_s[j]] = dp[i] + b_s[j]

    print(dp[h])

if __name__ == '__main__':
    main()

Measured memory_bytes: 40304
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t;cin>>t;while(t--)
#define f(i,n) for (int i=0;i<n;i++)
#define fa(i,a,b) for (int i=a;i<b;i++)
#define b(i,a,b) for (int i=a;i>=b;i--)
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define fi first    
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout<<">"<<#x<<" = "<<x<<endl;
#define MOD 1000000007
#define ce cout<<"\n"


int main()
{
    int n, i, f=1;
    cin>>n;
    int a[n];
    f(i, n){
        cin>>a[i];
        if(a[i]%2 == 0 && a[i]%3!=0 && a[i]%5!=0)
            f=0;
    }
    if(f)
        cout<<"APPROVED\n";
    else
        cout<<"DENIED\n";

    return 0;
}

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

int main() {
  vector<int> a(3);
  for (int i=0; i<3; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  cout << a.at(0)+a.at(1) << endl;
}


Measured memory_bytes: 3604
def solve(x, y):
    root = ""
    for _ in range(y):
        root = root + "U"
    for _ in range(x):
        root = root + "R"
    for _ in range(y):
        root = root + "D"
    for _ in range(x):
        root = root + "L"
    root = root + "L"
    for _ in range(y+1):
        root = root + "U"
    for _ in range(x+1):
        root = root + "R"
    root = root + "D"
    root = root + "R"
    for _ in range(y+1):
        root = root + "D"
    for _ in range(x+1):
        root = root + "L"
    root = root + "U"


    print(root)

def main():
    sx, sy, tx, ty = map(int, input().split())
    dist_x = tx - sx
    dist_y = ty -sy
    solve(dist_x, dist_y)

main()

Measured memory_bytes: 42972
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <tuple>
#include <set>
#include <map>

int main() {
  int N, D;
  scanf("%d %d", &N, &D);

  int E = D+D+1;
  printf("%d\n", (N+E-1)/E);
}


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

int main() {
  long long int n,t;
  cin>>n>>t;
  long long int answer=0;
  vector<long long int> vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
  }
  for(int i=0;i<n-1;i++){
    answer+=min(t,(vec.at(i+1)-vec.at(i)));
  }
  answer+=t;
  cout<<answer<<endl;
}

Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main(){
	var n int
	fmt.Scan(&n)

	ans := make(map[int]int)

	for i := 1; i <= 100;i++ {
		for j := 1; j <= 100; j++ {
			for k := 1; k <= 100; k++ {
				v := i*i +j*j+k*k +i*j+j*k+k*i
				if v <= n {
					ans[v]++
				}
			}
		}
	}
	for i := 1; i <=n ;i++ {
		fmt.Println(ans[i])
	}
}





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

using ll = long long;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

int main() {
  int H, W, N; cin >> H >> W >> N;

  int cnt = 0;
  int ans = 0;
  bool flag = false;

  if(H >= W) {
    while(true) {
      cnt += H;
      ans++;
      if(cnt >= N) {
        flag = true;
        break;
      }
      if(W == ans) break;
    }
  } else if(H < W) {
    while(true) {
      cnt += W;
      ans++;
      if(cnt >= N) {
        flag = true;
        break;
      }
      if(H <= ans) break;
    }
  }

  if(flag == false) {
    if(H >= W) {
      while(true) {
        cnt += W;
        ans++;
        if(cnt >= N) {
          flag = true;
          break;
        }
        if(H <= ans) break;
      }
    } else if(H < W) {
      while(true) {
        cnt += H;
        ans++;
        if(cnt >= N) {
          flag = true;
          break;
        }
        if(W <= ans) break;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
const double pi = acos(-1);
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;

int main(){
	ll n,m;
	ll sum = 0;
	scanf("%lld %lld",&n,&m);
	while(m--){
		ll x;
		scanf("%lld",&x);
		sum += x;
	}
	if(n - sum < 0) printf("-1\n");
	else printf("%lld\n",n-sum);
	return 0;
}

Measured memory_bytes: 3788
S = input()
N = len(S)

child = [1] * N

for i in range(N - 2):
    if 'R' == S[i] and 'R' == S[i + 1]:
        child[i + 2] += child[i]
        child[i] = 0
    if 'L' == S[N - i - 1] and 'L' == S[N -i - 2]:
        child[N - i - 3] += child[N - i - 1]
        child[N - i - 1] = 0

print(*child)

Measured memory_bytes: 6400
import java.util.Scanner;

public class Main {

	 public static void main(String[] args){  
	
		 Scanner out = new Scanner(System.in);
		
		 String str =out.nextLine();
		 String[] sss=str.split(" ");
		 int a= Integer.parseInt(sss[0]);
		 int b= Integer.parseInt(sss[1]);
		 System.out.println( a*b+" "+(a+b)*2 );
	    }   



}

Measured memory_bytes: 26048
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
#define  pb     push_back
#define  all(x) (x).begin(), (x).end()
#define  rep(i,a,b) for(int i=a ; i<b ; ++i)
#define  deb(x) cout << #x << " - " << x << "\n";
#define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  D2(x)  { cerr << "[" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }
#define  ps(x,y) fixed<<setprecision(y)<<x
 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 10000000000;
const ll MAX_N = 1e6 + 2;

vi adj[100],vis(100,0),in(100),low(100);
int cnt = 0,timer = 0;

void dfs(int node,int par){
    vis[node] = 1;
    in[node] = low[node] = timer++;
    
    for(auto child: adj[node]){
        if(child==par) continue;
        
        if(vis[child]==1){
            low[node] = min(low[node] , in[child]);
        } else{
            dfs(child,node);
            if(low[child] > in[node]) cnt++;
            low[node] = min(low[node] , low[child]);
        }
    }
}

void solve(){
    int n,a,b,e; cin >> n >> e;
    while(e--){
        cin >> a >> b;
        adj[a].pb(b) , adj[b].pb(a);
    }
    dfs(1,-1);
    cout << cnt;
}
 
int main() {
    IOS;
    int t; t=1;
    // int t; cin >> t;
    while(t--) solve();
}

Measured memory_bytes: 3664
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

# nCr mod m
# modinvが必要
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10 ** 9 + 7):
    r = min(r, n - r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i + 1, mod) % mod
    return res

n, k = map(int, input().split())
dat = list(map(int, input().split()))
datAfter = [0] * n
datSelf = [0] * n
numAfter = 0
numSelf = 0
m = 10**9 + 7
for i in range(n):
    for j in range(i+1, n):
        if dat[i] > dat[j]:
            numAfter += 1
for i in range(n):
    for j in range(n):
        #print(dat[i], dat[j])
        if dat[i] > dat[j]:
            numSelf += 1
res = 0
res += numAfter * k
res += numSelf * combination(k, 2)
res %= m
#print(numSelf, numAfter, res)
print(res)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main() {
 for (int i = 0; ;i++) {
  int a, b;
  cin >> a >> b;

  if (a == 0 && b == 0) {
   break;
  }
 
  if (a >= b) {
   swap (a,b);
   }
  cout << a << " " << b <<endl;
 }


 return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define ll long long 
#define OJ \
        freopen("input.txt","r",stdin); \
        freopen("output.txt","w",stdout);
using namespace std;

int main()
{
//OJ;
 ll int d,t,s;
 cin>>d>>t>>s;
 if(d<=s*t)
 {
         cout<<"Yes";
 }
 else{
         cout<<"No";
 }
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
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; }
const ll INF = 1LL << 60;
int main(){
    string s; cin >> s;
    int n = s.size();
    int ans = 0;
    rep(i,n/2){
        int j=n-1-i;
        char l = s.at(i);
        char r = s.at(j);
        if(l!=r) ans++;
        //cout << "l:" << l << "r:" << r << endl;
    }
    // rep(i,n){
    //     int j=n-1-i;
    //     if (s[i]!=s[j] && i<j) ans++;
    // }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d[6],g,h,i,j,c[6],q,w,v,aa;
	long long int f;
	int z[13]={31,28,31,30,31,30,31,31,30,31,30,31};
	char x[15];
	while(1){
		scanf("%s",x);
		if(x[0]=='#') break;
		a=0;
		f=0;
		s=0;
		q=365;
		for(i=0;i<strlen(x);i++) if(x[i]=='.') a++;
		for(i=0;i<5;i++){
			d[i]=0;
			c[i]=0;
		}
		if(a==2){
			f=10;
			for(i=0;i<strlen(x);i++){
				if(x[i]=='.') s++;
				else{
					d[s]*=10;
					d[s]+=x[i]-'0';
				}
			}
			if(d[0]==2012) printf("0.0.0.0.%d\n",d[2]-21);
			else{
				f=10;
				g=d[0];
				if(d[1]>2)	g++;
				for(i=2013;i<d[0];i++)	f+=365;
				for(i=2013;i<g;i++) if(i%4==0&&i%100!=0||i%400==0) f+=1;
				for(i=0;i<d[1]-1;i++) f+=z[i];
				f+=d[2];
				c[0]=f%20;
				c[1]=f/20;
				c[2]=c[1]/18;
				c[1]=c[1]%18;
				c[3]=c[2]/20;
				c[2]=c[2]%20;
				c[4]=c[3]/20;
				c[3]=c[3]%20;
				c[4]%=13;
				for(i=4;i>=0;i--){
					printf("%d",c[i]);
					if(i!=0) printf(".");
				}
				 printf("\n");
			}
		}
		else if(a==4){
			for(i=0;i<strlen(x);i++){
				if(x[i]=='.') s++;
				else{
					d[s]*=10;
					d[s]+=x[i]-'0';
				}
			}
			f=d[4];
			f+=d[3]*20;
			f+=d[2]*20*18;
			f+=d[1]*20*18*20;
			f+=d[0]*20*18*20*20;
			if(f<=10) printf("2012.12.%d\n",21+f);
			else{
				f-=10;
				c[0]=2013;
				while(1){
					if(c[0]%4==0&&c[0]%100!=0||c[0]%400==0) q=366;
					else q=365;
					if(f<=q) break;
					f-=q;
					c[0]++;
				}
				for(i=0;i<12;i++){
					aa=z[i];
					if(q==366&&i==1) aa++;
					if(f<=aa) break;
					f-=aa;
					c[1]=i+1;
				}
				c[1]++;
				c[2]=f;
				for(i=0;i<3;i++){
					printf("%d",c[i]);
					if(i!=2) printf(".");
				}
				printf("\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2680
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0
okobore = 0
for i in range(N):
    if (a[i] - okobore) > 0:
        cnt = cnt + okobore
        nokori = a[i] - okobore
    if (a[i] - okobore) <= 0:
        cnt = cnt + a[i]
        nokori = 0

    if (b[i] - nokori) > 0:
         cnt = cnt + nokori
         okobore = b[i] - nokori
    if (b[i] - nokori) <= 0:
        cnt = cnt + b[i]
        okobore = 0

if a[N] - okobore > 0:
    cnt = cnt + okobore
else:
    cnt = cnt + a[N]

print(cnt)


Measured memory_bytes: 18476
#include <bits/stdc++.h>
		using namespace std;
		typedef long long ll;
		#define PRINT(x,y) cout<<"Case #"<<(int)x<<": "<<(int)(y)<<endl;
		ll exp(ll x, ll y) {
			if(y==0) return 1;
			if(y==1) return x;
			if(y%2==0) return exp(x,y/2)*exp(x,y/2);
			else return x*exp(x,y/2)*exp(x,y/2);
		}
		ll gcd(ll a , ll b) {
			if(b==0) return a;
			return gcd(b , a%b);
		}
		ll lcm(ll a , ll b) {
			return (a*b)/gcd(a,b);
		}
		#define vec(n) vector<int> v((int)(n),0);
		#define vecl(n) vector<ll> v((ll)(n),0);
		#define sq(a) ((int)(a))*((int)(a));
		#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
		int l;
		ll fact(ll x) {
			if(x==1) return 1;
			else return x*fact(x-1);
		}
		bool isPrime(int x) {
			int ans  = 0;
			for(int i=2;i<=sqrt(x);++i) {
				if(x%i==0) {
					ans = 1; i=x;
				}  
			}
			if(ans==0) return true;
			else return false;
		}
		ll isPerfect(ll x) {
			double y = sqrt(x);
			return (floor(y)==ceil(y));
		} 

		int z = 0;
		void ask(int x, int y) {
			cout<<"? "<<x<<" "<<y<<endl;
			}

		void solve() {
			ll a,b,c,d; cin>>a>>b>>c>>d;
			ll ans = max(max(a,b)*max(c,d) , max(a,b)*min(c,d));
			ans = max(ans , min(a,b)*min(c,d));
			ans = max(ans, min(a,b)*max(c,d));
			cout<<ans;
		}			



		int main() {
			io
			
			 solve();
		}
		    
		

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int box[100];
	int i,j;
	int sum;
	cin>>n;
	for(i=0;i<n;i++)	cin>>box[i];
	sum=0;
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			sum+=box[i]*box[j];
		}
	}
	cout<<sum<<endl;
	return 0;
}
			

Measured memory_bytes: 256
n = int(input())
w = [input() for _ in range(n)]
ans = 'Yes'
if len(set(w)) != len(w):
  ans = 'No'
for i in range(n-1):
  if w[i][-1] != w[i+1][0]:
    ans = 'No'
    break
print(ans)

Measured memory_bytes: 9124
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
constexpr auto INF = 2147483647;
typedef long long ll;

// void DebugGrid(int row, int column, auto table){
//   cout << endl;
//   rep(i,row){
//     rep(j,column) cout << table[i][j] << " ";
//     cout << endl;
//   }
// }

int main(){

  ll ans, n, DP[100][100];
  vector<pair<int,int>> matrix;
  cin >> n;
  rep(i,n){
    pair<int,int> inp;
    cin >> inp.first >> inp.second;
    matrix.emplace_back(inp);
  }

  rep(i,n)rep(j,n) DP[i][j] = INF;
  for(int l=0; l<n; l++)for(int i=0; i<n-l; i++){
    if(l == 0) DP[i][i] = 0;
    else{
      for(int j=i;j<=i+l;j++){
      DP[i][i+l] = min(DP[i][i+l],DP[i][j]+DP[j+1][i+l] + (matrix[i].first*matrix[j].second*matrix[i+l].second));
      }
    }
  }

  // DebugGrid(n,n,DP);
  cout << DP[0][n-1] << endl;
  return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
bool dbg = false;
int N;
int a[101010], b[101010];
int c[101010];

struct edge {
    int to, num;
};
vector<edge> G[101010];


void p(int x) {
    S s;
    int t = 1;
    FOR(i, 0, (int)G[x].size()) {
        auto& nxt = G[x][i];
        if (c[nxt.num] >= 1) {
            s.insert(c[nxt.num]);
        }
    }
    FOR(i, 0, (int)G[x].size()) {
        auto& nxt = G[x][i];
        if (c[nxt.num] == 0) {
            while (s.count(t) >= 1) {
                t++;
            }
            c[nxt.num] = t;
            s.insert(t);
            p(nxt.to);
            t++;
        }
    }
}


void solve() {
    int MAX = 0;
    int x = 0;
    FORR(i, 1, N) {
        if ((int)G[i].size() == 1) {
            x = i;
            break;
        }
    }
    p(x);
    FOR(i, 0, N - 1) {
        MAX = max(MAX, c[i]);
    }
    cout << MAX << endl;
    FOR(i, 0, N - 1) {
        cout << c[i] << endl;
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(i, 0, N - 1) {
        cin >> a[i] >> b[i];
        G[a[i]].pb(edge{b[i], i});
        G[b[i]].pb(edge{a[i], i});
    }
    solve();
    return 0;
}


Measured memory_bytes: 19584
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
vector<int> arr(MAXX);
void trozen()
{
    int a,b;
    cin>>a>>b;
    int ans=0;
    for(int i=a;i<=b;i++)
    {
        int temp=i;
        int temp2=0;
        while(temp)
        {
            temp2=temp2*10+temp%10;
            temp/=10;
        }
        if(i==temp2)
            ans++;
    }
    cout<<ans<<endl;
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}


Measured memory_bytes: 10992
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int util(int n,int i){
	int count=0;
	while(n>0 && n%i==0){
		count++;
		n/=i;
	}
	return count+1;
}
int main(){
	int n;
	cin>>n;
	vector<int>factors(n+1,0);
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j+=i)
			factors[j]++;
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
		ans+=(1L *i*factors[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 42324
#include <iostream>
#include <algorithm>
#include <cmath>
#define nmax 2001

using namespace std;

int n;
int v[nmax];

int caut_bin(int sum,int i,int j)
{
    int s=j+1,d=n;
    int ans=s-1;
    while(s<=d)
        {
            int med=(s+d)/2;
            if(v[med]<sum) {ans=med; s=med+1;}
            else d=med-1;
        }
    return ans;
}

int main()
{
    cin>>n;
    for(int i=1; i<=n; i++) cin>>v[i];
    sort(v+1,v+n+1);
    int ct=0;
    for(int i=1; i<n; i++)
        for(int j=i+1; j<=n; j++)
            {
                int sum=v[i]+v[j];
                ct+=(caut_bin(sum,i,j)-j);
            }

    cout<<ct;
    return 0;
}


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

const int N_MAX = 200005;
const int K_MAX = 1000000005;
int n, k;
vector<int> A;

vector<int> BIT;

void init(){
    BIT.assign(n + 2, 0);
}

void update(int s){
    for(int i = s; i <= n + 1; i += i & -i){
        BIT[i]++;
    }
}

int getSum(int s){
    int sum = 0;
    for(int i = s; i > 0; i -= i & -i){
        sum += BIT[i];
    }
    return sum;
}

int main(){
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        int na;
        cin >> na;
        A.push_back(na);
    }
    init();

    vector<pair<long long int, int>> B;
    long long int total = 0;
    B.emplace_back(0, 0);
    for(int i = 0; i < n; i++){
        int na = A[i];
        total += na - k;
        B.emplace_back(total, i+1);
    }

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

    int C[N_MAX+3];
    int num = 1;
    C[B[0].second] = num;
    for(int i = 1; i < B.size(); i++){
        if (B[i-1].first < B[i].first) num++;
        C[B[i].second] = num;
    }


    long long int ans = 0;

    for(int i = 0; i <= n; i++){
        ans += getSum(C[i]);
        update(C[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7792
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> ba(1000001);
	vector<int> ia;
	set<int> same;
	for (int i = 0; i < N; ++i)
	{
		int a;
		cin >> a;
		ia.emplace_back(a);
		if (ba[a] != 0)
			same.insert(a);
		ba[a] = 1;
	}
	int sum = 0;
	for (int a = 1; a <= 1000000; ++a) {
		if (ba[a] == 0)
			continue;
		for (int aa = a * 2; aa <= 1000000; aa += a)
			ba[aa] = 0;
		if (same.find(a) == same.end())
			++sum;
	}
	cout << sum;

	return 0;
}


Measured memory_bytes: 8628
#include <bits/stdc++.h>
#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 fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N>>M;
    vec x(N-1), y(M-1);
    ll last;
    cin>>last;
    rep(i,N-1){
        cin>>A;
        x[i] = A - last;
        last = A;
    }
    cin>>last;
    rep(i,M-1){
        cin>>A;
        y[i] = A - last;
        last = A;
    }
    ll X, Y;
    X = Y = 0;
    rep(i,N-1) (X += x[i] * (i+1) * (N - 1 - i))%=MOD;
    rep(i,M-1) (Y += y[i] * (i+1) * (M - 1 - i))%=MOD;
    cout<<(X*Y)%MOD<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vvchar vector<vector<char>>
#define vchar vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    int n=s.length();
    int res=0;

    int first=0;
    rep(i,n)if(s[i]=='B'){first=i; break;}

    range(i,first,n){
        if(s[i]=='W'){
            res+=i-first;
            first++;
        }
    }
    cout<<res<<endl;


}

Measured memory_bytes: 3712
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	x := make([][]int, 0)
	for i := 1; i <= n/2; i++ {
		x = append(x, []int{i, n - i + (1 - n%2)})
	}
	if n%2 == 1 {
		x = append(x, []int{n})
	}
	m := len(x)
	ans := make([][2]int, 0)
	if m == 2 {
		for _, p := range x[0] {
			for _, q := range x[1] {
				ans = append(ans, [2]int{p, q})
			}
		}
	} else {
		for i := 0; i < m; i++ {
			for _, p := range x[i] {
				for _, q := range x[(i+1)%m] {
					ans = append(ans, [2]int{p, q})
				}
			}
		}
	}
	fmt.Println(len(ans))
	for _, v := range ans {
		fmt.Println(v[0], v[1])
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define M 1046527
#define NIL (-1)
#define L 14
vector <string> H(M);
int h1(int key){return key % M;}
int h2(int key){return 1 + ( key % (M-1) );}
int getChar(char ch){
  //printf("getchar\n");
  if(ch=='A')return 1;
  else if(ch=='C')return 2;
  else if(ch=='G')return 3;
  else if(ch=='T')return 4;
  else return 0;
}
long long getkey(string s){
  //printf("getkey\n");
  long long sum=0,p=1,i;
  for(int i=0;i<s.length();i++){
    sum+=p*getChar(s[i]);
    p*=5;
  }
  return sum;
}
int insert(string s){
  //printf("insert\n");
  long long key,i,h;
  key=getkey(s);
  for(int i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(H[h]==s)return 1;
    else if(H[h].length()==0){
      H[h]=s;
      return 0;
    }
  }
  return 0;
}

int find(string s){
  //printf("find\n");
  long long key,i,h;
  key=getkey(s);
  for(int i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(H[h]==s)return 1;
    else if(H[h].length()==0)return 0;
  }
  return 0;
}
int main(){
  int n;
  string s1,s2;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> s1 >> s2;
    if(s1[0]=='i'){insert(s2);}
    else {
      if(find(s2))printf("yes\n");
      else printf("no\n");
    }
  }
  
  return 0;
}

Measured memory_bytes: 27560
#include<iostream>
using namespace std;
typedef long long ll;
#define MOD 1000000007
ll calc(ll a,ll b){
  ll res=1;
  for(int i=0;(1<<i)<=b;i++){
    if(b>>i&1) res=(res*a)%MOD;
    a=(a*a)%MOD;
  }
  return res % MOD;
}
int main(){
  ll m,n;
  cin >> m >> n;
  cout << calc(m,n) << endl;
  return 0;
}

Measured memory_bytes: 1156
import numpy as np

n, ma, mb = map(int, input().split())
U = 400
dp = np.full((U+1, U+1), float("inf"))
dp[0, 0] = 0
for i in range(n):
  a, b, c = map(int, input().split())
  np.minimum(dp[a:, b:], dp[:-a, :-b]+c, out=dp[a:, b:])
ans = float("inf")
for i in range(1, 1+U//max(ma, mb)):
  na, nb = i*ma, i*mb
  ans = min(ans, dp[na, nb])
if ans == float("inf"):
  print(-1)
else:
  print(int(ans))

Measured memory_bytes: 17020
#include <bits/stdc++.h> 
using namespace std; 
#define ll int long long
int main()
{
    int l;cin>>l;
     ll x=pow(l,3);
     ll y=27,n=10;
     ll d = x / y; 
  
    // Now one by print digits after dot 
    // using school division method. 
    for (int i = 0; i <= n; i++) { 
        cout << d; 
        x = x - (y * d); 
        if (x == 0) 
            break; 
        x = x * 10; 
        d = x / y; 
        if (i == 0) 
            cout << "."; 
    } 
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	vector<int> a(3);
	rep(i, 3) cin >> a[i];
	sort(a.begin(), a.end());
	if(a[0] == 5 && a[1] == 5 && a[2] == 7) puts("YES");
	else puts("NO");
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<iostream>
using namespace std;
int gcd(int a,int b){if(a<b){swap(a,b);}if(b==0){return a;}return gcd(a%b,b);}
int main(void){
	string a,b,c;
	cin>>a>>b;
	for(int i=0;i<b.size();i++){
		c.push_back(a[i]);
		c.push_back(b[i]);
	}
	if(a.size()>b.size()){c.push_back(a.back());}
	cout<<c<<endl;
	return 0;
}

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

int main() {
    int N, M;
    cin >> N;
    vector<string> s(N);
    for (int i = 0; i < N; i++) {
        cin >> s.at(i);
    }
    cin >> M;
    vector<string> t(M);
    for (int i = 0; i < M; i++) {
        cin >> t.at(i);
    }
    vector<int> count(N, 0);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (s.at(i).compare(s.at(j)) == 0) count.at(i)++;
        }
        for (int j = 0; j < M; j++) {
            if (s.at(i).compare(t.at(j)) == 0) count.at(i)--;
        }
    }

    int max = 0;
    for (int i = 0; i < N; i++) {
        if (count.at(i) > max) {
            max = count.at(i);
        }
    }
    if (max < 0) cout << 0 << endl;
    else cout << max << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
 
struct ST {
  ll x, y, z;
};
 
ll solve(int M, const vector<ll>& x, const vector<ll>& y, const vector<ll>& z, bool xf, bool yf, bool zf){
  vector<ST> v;
  rep(i,x.size()){
    v.push_back((ST){x[i],y[i],z[i]});
  }
  sort(ALLOF(v),[&](const ST& a, const ST& b){
    ll ax = xf?a.x:-a.x;
    ll ay = yf?a.y:-a.y;
    ll az = zf?a.z:-a.z;
    ll bx = xf?b.x:-b.x;
    ll by = yf?b.y:-b.y;
    ll bz = zf?b.z:-b.z;
    return ax+ay+az > bx+by+bz;
  });
 
  ll sx = 0, sy = 0, sz = 0;
  rep(i,M){
    sx += v[i].x;
    sy += v[i].y;
    sz += v[i].z;
  }
  return llabs(sx) + llabs(sy) + llabs(sz);
}
 
int main(){
  int N, M;
  cin >> N >> M;
  vector<ll> vx, vy, vz;
  rep(i,N){
    ll x, y, z;
    cin >> x >> y >> z;
    vx.push_back(x);
    vy.push_back(y);
    vz.push_back(z);
  }
  
  ll ret = 0;
  ret = max(ret, solve(M, vx, vy, vz, false, false, false));
  ret = max(ret, solve(M, vx, vy, vz, false, false, true));
  ret = max(ret, solve(M, vx, vy, vz, false, true, false));
  ret = max(ret, solve(M, vx, vy, vz, false, true, true));
  ret = max(ret, solve(M, vx, vy, vz, true, false, false));
  ret = max(ret, solve(M, vx, vy, vz, true, false, true));
  ret = max(ret, solve(M, vx, vy, vz, true, true, false));
  ret = max(ret, solve(M, vx, vy, vz, true, true, true));
  
  cout << ret << endl;
  
  return 0;
}


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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);
		int n = sc1.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		int[] d = new int[n];
		long sumA = 0;
		long sumB = 0;
		long tmpSum = 0;
		int count = 0;

		for ( int i = 0 ; i < n ; i++) {
			a[i] = sc1.nextInt();
			sumA += a[i];
		}

		for ( int i = 0 ; i < n ; i++) {
			b[i] = sc1.nextInt();
			c[i] = a[i] - b[i];
			d[i] = c[i];
			sumB += b[i];
		}

		Arrays.sort(d);

		if (sumA < sumB) {
			System.out.println(-1);
		}
		else {
			if (d[0] >= 0) {
				System.out.println(0);
			}
			else {
				//不足分を求める
				for ( int j = 0 ; j < n ; j++ ) {
					if (d[j] < 0) {
						tmpSum += d[j];
						count++;
					}
					else {
						break;
					}
				}
				//超過分で埋める
				for ( int j = 0 ; j < n ; j++ ) {
					if (tmpSum < 0) {
						tmpSum += d[n-1-j];
						count++;
					}
					else {
						break;
					}
				}

				System.out.println(count);
			}
		}

		sc1.close();

	}

}


Measured memory_bytes: 85152
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];

int mod;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res=res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}


signed main() {
	int n, k;
	cin >> n >> k;
	if (n % k == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	//删除最后一个字符的方法
	//1.substr
	b=b.substr(0,b.size()-1);
	cout<<(a==b?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pair<int, int>a, pair<int, int>b) {
	if (a.second == b.second) {
		return a.first > b.first;
	}
	return a.second > b.second;
}

int main() {
	int n, m;
	cin >> n >> m;
	vint a(n);
	rep(i, n)cin >> a[i];
	vpint b(m);
	rep(i, m) {
		cin >> b[i].first >> b[i].second;
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end(), check);
	int cnt = 0;
	llint ans = 0;
	rep(i, m) {
		if (a[cnt] >= b[i].second) {
			break;
		}
		rep(j, b[i].first) {
			if (a[cnt] >= b[i].second || cnt >= n) {
				i = m;
				break;
			}
			cnt++;
			ans += (llint)b[i].second;
		}
	}
	for (int i = cnt; i < n; i++) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1536