akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MP make_pair
#define PB push_back
typedef long long ll;

ll R, C, ans = 1e18;

void u (ll &a, ll b){
        if (b<a) a = b;
}

void go () {
        if (R>=3) u(ans, ((R+2)/3 - R/3) * C);
        fo(i, 1, R) {
                ll a = i * C;
                ll b = (R-i) * (C/2);
                ll c = (R-i) * ((C+1)/2);
                u(ans, max(max(abs(a-b),abs(b-c)),abs(a-c)));
        }
}

int main () {
        scanf("%lld %lld", &R, &C);
        go(), swap(R,C), go();
        printf("%lld\n", ans);
        return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
count = 0

for i, n in enumerate(A):
    count += B[n-1]
    if i != len(A) - 1 and A[i+1] == n + 1:
        count += C[n - 1]

print(count)

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DiceinLine solver = new DiceinLine();
        solver.solve(1, in, out);
        out.close();
    }

    static class DiceinLine {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] p = new int[n + 1];
            long max = 0;
            for (int i = 1; i <= n; i++) {
                p[i] = in.nextInt();
            }

            long a = 0;
            int pos = k;
            for (int j = 1; j <= k; j++) {
                a += p[j];
            }

            for (int i = k + 1; i <= n; i++) {
                a += p[i] - p[i - k];
                if (max < a) {
                    max = a;
                    pos = i;
                }
            }
            double result = 0;
            for (int i = 0; i < k; i++) {
                int v = p[pos - i];
                double sum;
                if (v % 2 == 0) {
                    int num = v / 2;
                    sum = (1 + v) * num;
                } else {
                    int num = v / 2;
                    sum = (1 + v) * num + num + 1;
                }
                result += (sum / v);
            }
            out.println(result);

        }

    }
}



Measured memory_bytes: 60888
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, A, B = map(int, raw_input().split())
print min(N * A, B)

Measured memory_bytes: 2812
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

vector<double> expect(double p){
    vector<double> ret(0);
    for(int i=0; i<=p; i++){
        ret.push_back((1.+i)/2);
    }
    return ret;
}

int main(){
    int N, K;
    cin >> N >> K;
    deque<double> que;
    
    vector<double> exp=expect(1000);
    double ans=0;
    double tmp=0;
    for(int i=0; i<N; i++){
        int p;
        cin >> p;

        tmp+=exp[p];
        //cout << exp[p] << endl;
        que.push_back(exp[p]);
        if((int)que.size()>K){
            tmp-=que.front();
            que.pop_front();
        }
        ans=max(ans,tmp);
    }
    cout << setprecision(10) << ans << endl;

}

Measured memory_bytes: 1920
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int dig(int x){
	int res=0;
	while(x>=1){
		res+=(x%10);
		x/=10;
	}
	return res;
}
int main(){
    //~ freopen("file.in", "r", stdin);
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    printf("%d\n",min(a*b,c));
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> ii;

int main(){
    int n;cin>>n;
    vector<ii> r(n),b(n);
    vector<bool> used(n,false);
    int x,y;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        r[i]=make_pair(x,y);
    }
    for(int i=0;i<n;i++){
        cin>>x>>y;
        b[i]=make_pair(x,y);
    }
    sort(r.begin(),r.end());
    sort(b.begin(),b.end());

    int cnt=0;
    for(int i=0;i<n;i++){
        int j=0,id=-1,m=-1;
        while(r[j].first<b[i].first){
            if(r[j].second<b[i].second&&m<r[j].second&&!used[j]){
                m=r[j].second;
                id=j;
            }
            j++;
        }
        if(id!=-1){
            used[id]=true;
        }
    }
  for(int i=0;i<n;i++){
    if(used[i]) cnt++;
  }
    cout<<cnt<<endl;
    return 0;
}


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

int dp[100005][3],ar[100005][3];
int n;
int rockclimb(int i, int j)
{
    if(i==(n-1))
    {
        return dp[i][j]=ar[i][j];
    }
    if (i>=0 && i<n)
    {
        if(dp[i][j]!=-1)
            return dp[i][j];
        if(i==0)
        {
            int ans1=max((ar[i][0]+rockclimb(i+1,1)),(ar[i][0]+rockclimb(i+1,2)));
            int ans2=max((ar[i][1]+rockclimb(i+1,0)),(ar[i][1]+rockclimb(i+1,2)));
            int ans3=max((ar[i][2]+rockclimb(i+1,0)),(ar[i][2]+rockclimb(i+1,1)));
            ans1=max(ans1,ans2);
            ans1=max(ans1,ans3);
            return dp[i][j]=ans1;
        }
        else
        {
            if(j==0)
            {
                int ans1=max((ar[i][j]+rockclimb(i+1,1)),(ar[i][j]+rockclimb(i+1,2)));
                return dp[i][j]=ans1;
            }
            else if(j==1)
            {
                 int ans1=max((ar[i][j]+rockclimb(i+1,0)),(ar[i][j]+rockclimb(i+1,2)));
                return dp[i][j]=ans1;
            }
            else
            {
                 int ans1=max((ar[i][j]+rockclimb(i+1,0)),(ar[i][j]+rockclimb(i+1,1)));
                return dp[i][j]=ans1;
            }
        }
    }
    else
        return 0; //if outside the array
}

int main() {
    ios_base::sync_with_stdio(false);

    long long int a,b,c,i,j,k;

    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(i=0;i<n;i++)
        cin>>ar[i][0]>>ar[i][1]>>ar[i][2];


    cout<<rockclimb(0,0)<<"\n";
    //cout<<dp[4][2];

    return 0;
}


Measured memory_bytes: 10368
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, M;
	cin >> N >> M;

	if (M > 1 && N > 1) {
		cout<< (M - 2) * (N - 2)<<endl;
		return 0;
	}
	if (N == 1 && M == 1) {
		cout << 1 << endl;
		return 0;
	}
	if (M == 1) {
		cout << max(0LL, N - 2) << endl;
		return 0;
	}
	if(N == 1){
		cout<<max(0LL, M - 2)<<endl;
		return 0;
	}


}

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

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

struct triple {
    int l,r,w;
};

triple a[1000];
int dp[2][400][400]; // i,j 以降は空いている
int n;

int solve(){
    memset(dp,0,sizeof(dp));
    sort(a,a + n,[](triple const& a,triple const& b){
            return a.l < b.l;
        });
    rep(i,n){
        auto next=dp[i&1];
        auto cur=dp[i+1&1];
        int l=a[i].l,r=a[i].r,w=a[i].w;
        rep(j,380)rep(k,380){
            next[j][k]=cur[j][k];
            if(j) next[j][k]=max(next[j][k],next[j-1][k]);
            if(k) next[j][k]=max(next[j][k],next[j][k-1]);

            if(j==r) next[j][k]=max(next[j][k],cur[l][k]+w);
            if(k==r) next[j][k]=max(next[j][k],cur[j][l]+w);
        }
    }
    return max(dp[0][370][370],dp[1][370][370]);
}

int main(){
    while (scanf("%d",&n),n){
        rep(i,n){
            int l,r,w; scanf("%d%d%d",&l,&r,&w);
            r++;
            a[i]={l,r,w};
        }
        printf("%d\n",solve());
    }
}

Measured memory_bytes: 2292
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
int ans = 0;
void Merge(int a[], int left, int mid, int right){
	int siz1 = mid - left;
	int siz2 = right - mid;
	int L[siz1 + 1], R[siz2 + 1];
	for(int i = 0; i < siz1; i++)L[i] = a[i + left];
	for(int i = 0; i < siz2; i++)R[i] = a[i + mid];
	L[siz1] = R[siz2] = INT_MAX;
	int i = 0, j = 0;
	for(int k = left; k < right; k++){
		if(L[i] <= R[j]){
			a[k] = L[i++];
		}else{
			a[k] = R[j++];
		}
		ans++;
	}
}

void MergeSort(int a[], int left, int right){
	if(left + 1 < right){
		int mid = (left + right) / 2;
		MergeSort(a, left, mid);
		MergeSort(a, mid, right);
		Merge(a, left, mid, right);
	}
}

int main(){
	FIO
	
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)cin >> a[i];
	MergeSort(a, 0, n);
	//int x[] = {1, 3, 5, 2, 4, 6};
	//Merge(x, 0, 3, 6);
	cout << a[0];
	for(int i = 1; i < n; i++)cout << ' ' << a[i];
	cout << '\n' << ans << '\n';
	return 0;
}



Measured memory_bytes: 7024
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;


int main() {
    int n; cin >> n;
    print(n * n * n);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    list<int> L;
    auto it=L.end();
    while(n--){
        int op;
        cin>>op;
        if(op==0){
            int x;cin>>x;
            it=L.insert(it,x);
        }else {
            if(op==1){
                int d;cin>>d;
                if(d>0)while(d--)it++;
                else while(d++)it--;
            }else{
                it=L.erase(it);
            }
        }
    }
    for(auto t:L)cout<<t<<endl;
}

/* 
5
0 1
0 2
0 3
1 1
2
insert(x): Insert x before the element indicated by the cursor. After this operation, the cursor points the inserted element.
move(d): Move the cursor to the end by d, if d is positive. Move the cursor to the front by , if d is negative.
erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
 */


Measured memory_bytes: 18568
N = gets.to_i
b = gets.split(' ').map(&:to_i)

check = true
ans = []
N.times do
  ins = b.size
  while ins > 0
    break if b[ins - 1] == ins
    ins -= 1
  end
  if ins == 0
    check = false
    break
  else
    ans.unshift(ins)
    b.delete_at(ins - 1)
  end
end

if check
  puts ans
else
  puts -1
end

Measured memory_bytes: 1788
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

const int MAXN = 200200;
const int MOD7 = 1000000007ll;
const int MOD9 = 1000000009ll;
const int INF = 2000000000;
const double ESP = 1e-9;
const double PI = 3.14159265358979;
const int dir_4r[] = { -1, 1, 0, 0 };
const int dir_4c[] = { 0, 0, -1, 1 };
const int dir_8r[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
const int dir_8c[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int num[30];
string str;

int main()
{
	while (cin >> str)
	{
		memset(num, 0, sizeof(num));
		long long len = str.length();
		long long ans = (1 + len) * len / 2 + 1 - len;
		for (int i = 0; i < len; ++i)
		{
			int v = str[i] - 'a';
			ans -= num[v];
			num[v]++;
		}
		printf("%lld\n", ans);
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 640
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))

dp = [10**9]*n
dp[0] = 0

for i in range(n):
    for j in range(1,k+1):
        if i+j>=n:
            break
        dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[n-1])

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

int main() {
    int n;cin>>n;
    vector<pair<int,int>> a[n];
    for (int i=0;i<n;i++) {
        int b;cin>>b;
        for (int j=0;j<b;j++) {
            int c,d;cin>>c>>d;
            a[i].push_back({c-1,d});
        }
    }
    int ans=0;
    for (int i=0;i<1<<n;i++) {
        int f=1;
        for (int j=0;j<n;j++)
            if (i&1<<j)
                for (auto p:a[j])
                    f&=(i>>p.first)%2==p.second;
        if (f)
            ans=max(ans,__builtin_popcount(i));
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	queue<pair<string, int> > Q;
	int n, q;
	cin >> n >> q;
	
	for (int i = 0; i < n; i++) {
		string name;
		int t;
		cin >> name >> t;
		Q.push(make_pair(name, t));
	}
	pair<string, int> u;
	int a;
	int sum = 0;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		a = min(u.second, q);
		u.second -= a;
		sum += a;
		if (u.second > 0)
			Q.push(u);
		else
			cout << u.first << " " << sum << endl;
	}	
}


Measured memory_bytes: 6252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005],b[100005];
int main()
{
    int n,h,ans=0;
    cin>>n>>h;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
    }
    sort(a,a+n);
    sort(b,b+n);
    for(int i=n-1;i>=0;i--)
    {
        if(b[i]>=a[n-1]&&h>0)
        {
            h-=b[i];
            ans++;
        }
    }
    if(h>0)
    {
        ans+=h/a[n-1];
        if(h%a[n-1])
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int NN, f;
  NN = N;
  f = 0;
  
  for (int i = 8; i >= 0; i--) {
    int d = 1;
    for (int j = i; j > 0; j--)
      d *= 10;
    f += NN / d;
    NN = NN - (NN / d) * d;
  }
  if (N % f == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define pb push_back
typedef vector<int> vi;
#define mod 1000000007
#define maxn 100005
#define nos ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int dp[maxn][13];      //here dp[i][j] represents that we got j as remainder upto ith index starting from end
int power(int x,int y)
{
    int res=1;
    while(y)
    {
        if(y&1)
        res=(res*x)%13;
        x=(x*x)%13;
        y/=2;
    }
    return res;
}
int32_t main() {
    nos;
    string s;
    memset(dp,0,sizeof(dp));
    cin>>s;
    int n=s.size();
    if(s[n-1]=='?')
    {for(int i=0;i<10;i++)
     dp[n][i]++;
    }
    else
    dp[n][s[n-1]-'0']++;
    
    int c=1;
    for(int i=n-1;i>=1;i--)
    {   if(s[i-1]=='?')
        {
            for(int j=0;j<10;j++)        //we can try all 10 digits on ?
            {   
                for(int k=0;k<13;k++)
                    {   if(dp[i+1][k]!=0)
                        dp[i][(k+j*power(10,c))%13]=(dp[i][(k+j*power(10,c))%13]+dp[i+1][k])%mod;
                    }
            }
        }
        else
        {int j=s[i-1]-'0';               //while we have only one digit at fixed place
          for(int k=0;k<13;k++)
            {  
                if(dp[i+1][k]!=0)
                {
                        dp[i][(k+j*power(10,c))%13]=(dp[i][(k+j*power(10,c))%13]+dp[i+1][k])%mod;
                }
            }
        }
      c++;  
    }
    cout<<dp[1][5];
    return 0;
}


Measured memory_bytes: 13884
import java.util.Scanner;


public  class Main  {


	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		int menseki = H*W;
		int hles = W; //wlesされるたびに1減る
		int wles = H; //hlesされるたびに1減る
		
		for(int i=0; i<h; i++ ) {
			menseki = menseki -hles;
			wles--;
		}
		for(int i=0; i<w; i++) {
			menseki = menseki-wles;
			hles--;
		}
		System.out.println(menseki);
		
		
	}}

Measured memory_bytes: 24020
# Python program to print prime factors 
global l
l=[]
import math 

# A function to print all prime factors of 
# a given number n 
def primeFactors(n): 
	
	# Print the number of two's that divide n 
	while n % 2 == 0: 
		l.append(2)
		n = n / 2
		
	# n must be odd at this point 
	# so a skip of 2 ( i = i + 2) can be used 
	for i in range(3,int(math.sqrt(n))+1,2): 
		
		# while i divides n , print i ad divide n 
		while n % i== 0: 
			l.append(int(i)) 
			n = n / i 
			
	# Condition if n is a prime 
	# number greater than 2 
	if n > 2: 
		l.append(int(n))
		


n = int(input())
primeFactors(n)

s=list(set(l))
#print(s)
ans=0
for i in range(len(s)):
    c=s[i]
    while c<=n:
        if n%c==0:
            n=int(n/c)
            ans+=1
            c*=s[i]
        else:
            break
            
print(ans)        
        




Measured memory_bytes: 9284
#include<stdio.h>

int main(){
    double w;

    while(scanf("%lf", &w) != EOF){
        if(w <= 48.0) printf("light fly\n");
        else if(w <= 51.0) printf("fly\n");
        else if(w <= 54.0) printf("bantam\n");
        else if(w <= 57.0) printf("feather\n");
        else if(w <= 60.0) printf("light\n");
        else if(w <= 64.0) printf("light welter\n");
        else if(w <= 69.0) printf("welter\n");
        else if(w <= 75.0) printf("light middle\n");
        else if(w <= 81.0) printf("middle\n");
        else if(w <= 91.0) printf("light heavy\n");
        else printf("heavy\n");
    }
    return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
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(){

	lli a,b,c,d;
	cin>>a>>b>>c>>d;

	cout<<min(a,b)+min(c,d)<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>

#define mod 1000000007
#define MAXX  1e18
#define MINN -1e18
 
#define f first
#define s second
#define ll long long
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pi pair<ll, ll>
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define lb(a, key) lower_bound(all(a), key) - a.begin();
#define ub(a, key) upper_bound(all(a), key) - a.begin();
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define add(a, b) (((a)%mod + (b)%mod + mod)%mod)
#define mul(a, b) (((a)%mod * (b)%mod) % mod)
#define endl cout<<"\n";
#define debug(vari) cerr<< "["<< #vari << " " << (vari) << "]";endl;
#define read(a) for(auto &i: a) cin >> i;
#define out(a)  for(auto i: a) cout << i << " ";endl
#define ordered_set tree<ll, null_type, std::less<ll>, rb_tree_tag, tree_order_statistics_node_update>





using namespace __gnu_pbds;
using namespace std;

struct point {
    int x;
    int y;
};

bool cmp(point p, point q) {
    if(p.x == q.x) return p.y < q.y;
    return p.x < q.x;
}

int main() {
    fastio
    int n, m; cin >> n >> m;
    string ans = (n==m) ? "Yes" : "No";
    cout << ans;endl
}



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

int main(){
	char a, b, c;
	cin >> a >> b;
	if(a == 'H' && b == 'H'){
		c = 'H';
	}else if(a == 'H' && b == 'D'){
		c = 'D';
	}else if(a == 'D' && b == 'H'){
		c = 'D';
	}else{
		c = 'H';
	}
	cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

int N, Y, x, y, z = 0;
  cin >> N >> Y;
bool a = false;
  
  for(int x = 0;x <= N;x++){
    for(int y = 0;y <= N;y++){
    z = N - x - y;
      if((Y == 10000 * x + 5000 * y + 1000 * z) && (a == false) && (x >= 0) && (y >= 0) && (z >= 0)){
        cout << x << ' ' << y << ' ' << z << endl;
      a = true;
      }
    }  
  }
  
  if(a == false) cout << "-1 -1 -1" << endl;

}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Not Found
            var s = Console.ReadLine();

            Console.WriteLine(MinAlphabet(s));
        }

        static string MinAlphabet(string s)
        {
            for (char c = 'a'; c <= 'z'; c++)
            {
                if (!s.Contains(c))
                {
                    return c.ToString();
                }
            }

            return "None";
        }
    }
}

Measured memory_bytes: 13536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
  int res = 1;
  x = x % p;
  while (y > 0)
  {

    if (y & 1)
      res = (res * x) % p;

    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc;
  tc = 1;
  //cin>>tc;
  while (tc--)
  {
    int n;
    cin >> n;
    queue<int> q;
    if (n <= 10)
    {
      cout << n;
      return 0;
    }
    for (int i = 1; i <= 9; i++)
    {
      q.push(i);
    }
    while (!q.empty())
    {
      int f = q.front();
      n--;
      if (n == 0)
      {
        cout << f << endl;
        return 0;
      }
      q.pop();
      int d = f % 10;
      if (d != 0)
      {
        q.push(10 * f + d - 1);
      }
      q.push(10 * f + d);
      if (d != 9)
      {
        q.push(10 * f + d + 1);
      }
    }
  }

  return 0;
}


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

#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define eb emplace_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const int INF = 0x3f3f3f3f;

const int T = 2e5 + 2;
ll v[T];
bool vis[T];
vector<int> g[T];
int n,q;

void dfs(int at) {
    vis[at] = 1;
    for(int nxt : g[at]) {
        if(!vis[nxt]) {
            v[nxt] += v[at];
            dfs(nxt);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> q;
    ll a,b;

    for(int i = 0; i < n-1; i++) {
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }

    while(q--) {
        cin >> a >> b;
        v[a] += b;
    }
    
    for(int i = 1; i <= n; i++) {
        if(!vis[i]) dfs(i);
        cout << v[i] << " ";
    }
    cout << endl;
    

    return 0;
}



Measured memory_bytes: 21376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll k;cin>>k;
    ll ans=0;
    rrep(i,k){
        rrep(j,k){
            rrep(l,k){
                ll g1=gcd(i,j);
                ll g2=gcd(g1,l);
                ans+=g2;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

string dp[10020];

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

  long n, m;
  cin >> n >> m;

  vector<int> a(m);
  fillInt(a, m);

  map<int, int> mp;
  mp[1] = 2;
  mp[2] = 5;
  mp[3] = 5;
  mp[4] = 4;
  mp[5] = 5;
  mp[6] = 6;
  mp[7] = 3;
  mp[8] = 7;
  mp[9] = 6;

  for(int i = n-1; i >= 0; i--) {
    for(auto x: a) {
      ostringstream ss;
      ss << x;
      if ((i+mp[x] < n && dp[i+mp[x]].length() > 0) || i+mp[x] == n) {
        if (dp[i+mp[x]].length() >= dp[i].length()) {
          dp[i] = dp[i+mp[x]] + ss.str();
        } else if (dp[i+mp[x]].length() == dp[i].length() - 1) {
          dp[i] = max(dp[i], dp[i+mp[x]] + ss.str());
        }
      }
    }
  }

  cout << dp[0] << endl;
}

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

int main() {
  int N; cin >> N;
  vector<long> A(N);
  for (int i =0; i<N; i++) cin >> A.at(i);
  
  bool check = false;
  sort(A.begin(),A.end());
  for (int i =0; i<N-1; i++) {
    if (A.at(i) == A.at(i + 1) ) {
      check = true;
      break;
    }
  }
  if (check) {
    cout << "NO" << endl;
  } else {  
    cout << "YES" << endl;
  }
}

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

int main(){
  ll n,x;
  cin >> n >> x;
  
  vector<long long> a(n), b(n);
  
  ll ans = 0;
  
  for(ll i=0; i<n; i++){
    cin >> a[i];
    b[i] = a[i];
    ans += a[i];
  }
  
  for(ll j=1; j<n; j++){
    ll now = j*x;
    for(ll i=0; i<n; i++){
      b[i] = min( b[i], a[(i-j+n)%n] );
      now += b[i];
    }
    ans = min( ans, now );
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
#define PI 3.14159265358979

int main(){
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double min = h*60.0+m;
  double h_sita = min * PI / 360.0;
  double m_sita = m * PI / 30.0;
  double delta_sita = abs(h_sita - m_sita);
  double c = sqrt(a*a + b*b - 2*a*b*cos(delta_sita));
  cout << setprecision(14) << c << endl;
}

Measured memory_bytes: 4256
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 = 0;
		boolean d = true;
		for(long i = 0; d; i++){
			c += a;
			c = c % b;
			if(c == 0){
				System.out.println(a * (i + 1));
				d = false;
			}
		}		
	}
}

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

#define LL long long

/* 假快读 */
/* fake read speedification */
LL read() {LL s; scanf("%lld",&s); return s;}

LL n,m;
LL gcd(LL a,LL b) {return b ? gcd(b, a % b) : a;}

int div(LL x){
  int cnt = 0;
  for(LL i=2;i*i<=x;i++){
    if(x % i) continue;
    cnt++; while(!(x % i)) x /= i;
  }
  if(x > 1) cnt++;
  return cnt;
}

int main()
{
  n = read(); m = read(); LL g = gcd(n, m);
  printf("%lld", div(g) + 1); 
}

Measured memory_bytes: 256
#include <cstdio>

int max(int x, int y, int z){
    if(x>=y && x>=z) return x;
    else if(y>=x && y>=z) return y;
    else return z;
}

int main(){
    int A1, A2, A3;
    scanf("%d%d%d", &A1, &A2, &A3);
    printf("%d\n", max(A1,A2,A3)+max(-A1,-A2,-A3));
    return 0;
}

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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> A(N + 1, 777);
    int small = 0, large = 0;
    for (int i = 0; i < M; i++) {
        int y;
        cin >> y;
        A.at(y) = y;
        if (A.at(y) <= X) {
            small++;
        }
        else if (X <= A.at(i)) {
            large++;
        }
    }

    int ans = 0;
    if (large < small) {
        for (int i = X; i <= N; i++) {
            if (i == A.at(i)) ans++;
            if (X == N) break;
        }
    }
    else {
        for (int i = X; 0 <= i; i--) {
            if (i == A.at(i)) ans++;
            if (i == 0) break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define double long double
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n;
string s[10010];
signed main() {
	cin >> n;
	int ans = 0;
	int a = 0, b = 0, c = 0;
	rep(i, n) {
		cin >> s[i];
		if (s[i].back() == 'A')a++;
		if (s[i][0] == 'B')b++;
		if (s[i].back() == 'A' && s[i][0] == 'B')c++;
	}
	if(c==0)ans+=min(a,b);
	else if(a+b-2*c>0)ans+=c+min(a-c,b-c);
	else ans+=c-1;
	rep(i, n) {
		rep(j, s[i].size() - 1) {
			if (s[i][j] == 'A' && s[i][j + 1] == 'B')ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int n, m;
string s;
int field[200100];
vector<int> children[200010];
bool ok[200100];

void search(int from){
    bool checker[2];
    checker[0] = false;
    checker[1] = false;
    for(int i = 0; i < children[from].size(); i++){
        int to = children[from][i];
        if(!ok[to]){
            continue;
        }
        checker[field[to]] = true;
        if(checker[0] && checker[1]){
            return;
        }
    } 
    ok[from] = false;
}
void search2(int from){
    if(!ok[from]) return;
    bool checker[2];
    checker[0] = false;
    checker[1] = false;
    for(int i = 0; i < children[from].size(); i++){
        int to = children[from][i];
        if(!ok[to]){
            continue;
        }
        checker[field[to]] = true;
        if(checker[0] && checker[1]){
            return;
        }
    } 
    ok[from] = false;
    for(int i = 0; i < children[from].size(); i++){
        if(ok[children[from][i]]) search2(children[from][i]);
    }
    return;
}

int main() {
    //cout.precision(10);
    cin >> n >> m;
    cin >> s;
    for(int i = 1; i <= n; i++){
        if(s[i - 1] == 'A'){
            field[i] = 0;
        } else {
            field[i] = 1;
        }
    }
    for(int i = 1; i <= m; i++){
        int a, b;
        cin >> a >> b;
        if(a == b){
            children[a].push_back(b);
            continue;
        }
        children[a].push_back(b);
        children[b].push_back(a);
    }
    for(int i = 1; i <= n; i++){
        ok[i] = true;
    }
    for(int time = 1; time <= 100; time++){
        for(int i = 1; i <= n; i++){
            if(ok[i]) search(i);
        }
    }
    for(int i = 1; i <= n; i++){
        search2(i);
    }
    for(int i = 1; i <= n; i++){
        if(ok[i]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 15748
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vll             vector<long long>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul             1000000007
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define mod             998244353 
#define pll             pair<ll,ll>
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%lul;
        a = (a * a)%lul;
        b >>= 1;
    }
    return res;
}
void solve()
{
    int n; cin>>n;
    map<string,int> ma;
    rep(i,0,n)
    {
        string s; cin>>s;
        ma[s]++;
    }
    int ans = 0;
    for(auto i:ma)
    {
        ans = max(ans,i.S);
    }
    for(auto i:ma)
    {
        if(ans == i.S)
        {
            cout<<i.F<<endl;
        }
    }
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; /*cin>>t;*/ t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 23808
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,A[100];
    cin>>n;
    rep(i,n) cin>>A[i];
    sort(A,A+n);
    cout<<A[n-1]-A[0];
}

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

signed main(){
  string S;
  cin>>S;
  rep(i,3){
    if(S[i]=='1')S[i]='9';
    else S[i]='1';
  }
  cout<<S<<endl;
  return 0;
}

Measured memory_bytes: 3580
/**************************************
 * Au: Hany01
 * Date: Aug 25th, 2018
 * Email: hany01@foxmail.com
**************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
#define rep(i, j) for (register int i = 0, i##_end_ = j; i < i##_end_; ++ i)
#define For(i, j ,k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define SZ(a) ((int)(a.size()))
#define ALL(a) a.begin(), a.end()
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define x first
#define y second
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define y1 wozenmezhemecaia 
#ifdef hany01
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

inline int read() {
    register char c_; register int _, __;
    for (_ = 0, __ = 1, c_ = getchar(); !isdigit(c_); c_ = getchar()) if (c_ == '-')  __ = -1;
    for ( ; isdigit(c_); c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}

const int maxn = 1e5 + 5;

int n, k, x[maxn], Ans, pos;

int main()
{
#ifdef hany01
    File("a");
#endif

    n = read(), k = read();
    For(i, 1, n) x[i] = read();
    pos = lower_bound(x + 1, x + 1 + n, 0) - x;
    Ans = INF;
    if (pos > k) Ans = -x[pos - k];
    if (n - pos + 1 >= k) chkmin(Ans, x[pos + k - 1]);
    For(i, pos, n) if (pos - (k - (i - pos + 1)) < pos && pos - (k - (i - pos + 1)) > 0) {
        chkmin(Ans, 2 * x[i] - x[pos - (k - (i - pos + 1))]);
        chkmin(Ans, x[i] - 2 * x[pos - (k - (i - pos + 1))]);
    }
    printf("%d\n", Ans);

    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
int n,m,q;
vector<int> a,b,c,d;
int ans;
 
void dfs(vector<int> w){
    if(w.size()==n+1){
        int cnt = 0;
        rep(i,q){
            if(w[b[i]]-w[a[i]]==c[i]){
                cnt += d[i];
            }
        }
        ans = max(ans,cnt);
        return;
    }
    w.push_back(w.back());
    while(w.back()<=m){
        dfs(w);
        w.back()++;
    }
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n>> m >> q;
    a = b = c = d = vector<int> (q);
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];  }
    ans = 0;
    vector<int> w(1,1);
    dfs(w);
    cout << ans;
    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    std::string s;
    std::cin>>s;

    std::string ans = "";
    for(int i = 0;i < s.size();i += 2){
        ans += s[i];
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    K = II()
    N = 50

    div, mod = divmod(K, N)

    li = list(range(div, div+N))

    for _ in range(mod):
        li.sort()
        li = [li[0]+N] + [i-1 for i in li[1:]]

    print(N)
    print(' '.join(map(str, li)))

main()

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9+7;
const int maxn = 1e5+500;
ll T,n,m;
int a[maxn];
ll num[maxn];
ll pos[maxn];
int main() {
    cin>>n>>m;
    int cnt = 0;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]>a[j]){
				num[i]++;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(a[i]>a[j]){
				pos[i]++;
			}
		}
	}
	ll sum=0;
	for(int i=0;i<n;i++){
		sum+=pos[i];
	}
	
	sum%=mod;
	ll ssum = 0;
	ll temp = (m-1)*m/2;
	temp%=mod;
	temp*=sum;
	temp%=mod;
	ssum = temp;
	ll p = 0;
	for(int i=0;i<n;i++){
		p+=num[i];
	}
	p%=mod;
	p*=m;
	p%=mod;
	ssum+=p;
	ssum%=mod;
	cout<<ssum<<endl;
    return 0;
}



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

int main(void) {

    int n;
    cin >> n;
    ll a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    bool flag = true;
    int ans = 0;
    while(flag){
        for(int i = 0; i < n; i++){
            if(a[i]%2 == 0){
                a[i] = a[i]/2;
            }else{
                flag = false;
                break;
            }
        }
        ans ++;
    }
    ans--;

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

Measured memory_bytes: 256
var output;
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){return null;}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//不明値:何もしない 異常時:文字列「error」を返す（できる？）
//1:数値へ変換 2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字に分割 7:1文字に分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return "error";}}
function Main() {
  var tmp = myconv(next(),4);
  if(tmp[0] == tmp[1]){
     myout("Yes");
     }else{
     myout("No");
     }
}


Measured memory_bytes: 21064
program test
implicit none
integer(8) :: i,j,k,n,ans(300000)=0,a(300000)=0
 
read(*,*) n
 
read(*,*) (a(i),i=2,n)
 
do i = 2,n
  ans(a(i)) = ans(a(i)) + 1
enddo
 
do i = 1,n
  write(*,*) ans(i)
enddo
 
end program

Measured memory_bytes: 8420
h,w = map(int, input().split())
s = list()
t = list()
a = [0 for i in range(w+2)]
s.append(a)
for i in range(h):
    b = str(input())
    c = list(('0'+b+'0').replace('.','0').replace('#','1'))
    d = list(map(int, c))
    s.append(d)
    t.append(b)
s.append(a)

for j in range(1,h+1):
    for k in range(1,w+1):
        if s[j][k] == 0:
            cnt = 0
            cnt = (s[j-1][k-1]+s[j-1][k]+s[j-1][k+1]) + (s[j][k-1]+s[j][k+1]) + (s[j+1][k-1]+s[j+1][k]+s[j+1][k+1])
            t[j-1] = t[j-1].replace('.', str(cnt), 1)
            
        else:
            continue
for i in range(h):
    print(t[i])
        

Measured memory_bytes: 9268
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

string s;
int main() {
  cin >> s;
  if (s.size() <= 4) {
    cout << "NO" << endl;
    return 0;
  }
  if (s.at(0) != 'A') {
    s.insert(s.begin(), 'A');
  }
  if (s.at(1) != 'K' || s.at(2) != 'I' || s.at(3) != 'H') {
    cout << "NO" << endl;
    return 0;
  }
  if (s.at(4) != 'A') {
    s.insert(s.begin()+4, 'A');
  }
  if (s.size() <= 5 || s.at(5) != 'B') {
    cout << "NO" << endl;
    return 0;
  }
  if (s.size() <= 6) {
    cout << "NO" << endl;
    return 0;
  }
  if (s.at(6) != 'A') {
    s.insert(s.begin()+6, 'A');
  }
  if (s.size() <= 7 || s.at(7) != 'R') {
    cout << "NO" << endl;
    return 0;
  }
  if (s.size() == 8 || (s.at(8) == 'A' && s.size() == 9)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 384
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int D_MAX_V=210;
const int D_v_size=210;
struct D_wolf{
	int t,r;
	long long c;
	D_wolf(){t=c=r=0;}
	D_wolf(int t1,long long c1,int r1){
		t=t1;c=c1;r=r1;
	}
};
vector<D_wolf>D_G[D_MAX_V];
int D_level[D_MAX_V];
int D_iter[D_MAX_V];

void add_edge(int from,int to,long long cap){
	D_G[from].push_back(D_wolf(to,cap,D_G[to].size()));
	D_G[to].push_back(D_wolf(from,0,D_G[from].size()-1));
}
void D_bfs(int s){
	for(int i=0;i<D_v_size;i++)D_level[i]=-1;
	queue<int> Q;
	D_level[s]=0;
	Q.push(s);
	while(Q.size()){
		int v=Q.front();
		Q.pop();
		for(int i=0;i<D_G[v].size();i++){
			if(D_G[v][i].c>0&&D_level[D_G[v][i].t]<0){
				D_level[D_G[v][i].t]=D_level[v]+1;
				Q.push(D_G[v][i].t);
			}
		}
	}
}
long long D_dfs(int v,int t,long long f){
	if(v==t)return f;
	for(;D_iter[v]<D_G[v].size();D_iter[v]++){
		int i=D_iter[v];
		if(D_G[v][i].c>0&&D_level[v]<D_level[D_G[v][i].t]){
			long long d=D_dfs(D_G[v][i].t,t,min(f,D_G[v][i].c));
			if(d>0){
				D_G[v][i].c-=d;
				D_G[D_G[v][i].t][D_G[v][i].r].c+=d;
				return d;
			}
		}
	}
	return 0;
}
long long max_flow(int s,int t){
	long long flow=0;
	for(;;){
		D_bfs(s);
		if(D_level[t]<0)return flow;
		for(int i=0;i<D_v_size;i++)D_iter[i]=0;
		long long f;
		while((f=D_dfs(s,t,9999999999999LL))>0){flow+=f;}
	}
	return 0;
}
long long INF=9999999999999LL;
int p[30000];
int q[30000];
int r[30000];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<b;i++){
			scanf("%d%d%d",p+i,q+i,r+i);
		}
		long long ret=999999999999999LL;
		for(int i=1;i<a;i++){
			for(int j=0;j<D_MAX_V;j++){
				D_G[j].clear();
				D_iter[j]=D_level[j]=0;
			}
			long long tmp=0;
		/*	for(int j=0;j<a;j++){
				add_edge(j,j+a,INF);
				if(j==0)add_edge(s,j,INF);
				else add_edge(s,j,0);
				if(j==i)add_edge(j+a,t,INF);
				else add_edge(j+a,t,0);
			}*/
			for(int j=0;j<b;j++){
				if(r[j]<=0){
					tmp+=r[j];continue;
				}
				add_edge(p[j],q[j],r[j]);
				add_edge(q[j],p[j],r[j]);
			}
			ret=min(ret,tmp+max_flow(0,i));
		}
		printf("%lld\n",ret);
	}
}

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

int main() {
  int a, b;
  cin >> a >> b;

  if (a*b%2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
  // ここにプログラムを追記
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long a;
main()
{
	cin>>a;
	long n=1;
	while(n*(n+1)<a*2)n++;
	a=n*(n+1)/2-a;
	long t=n;
	for(int i=n;i>0;i--)
	{
		if(a>=i)
		{
			t--;
			a-=i;
			cout<<'(';
		}
		cout<<')';
	}
	for(;t--;)cout<<'(';
	cout<<endl;
}



Measured memory_bytes: 3104