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

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    for (int i = 0; i < N; i++) {
        int v = vec.at(i);
        int j = i-1;
        
        while (j >= 0 && vec.at(j) > v) {
            vec.at(j+1) = vec.at(j);
            j--;
        }
        vec.at(j+1) = v;
        
        for (int j = 0; j < N-1; j++) {
            cout << vec.at(j) << " ";
        }
        cout << vec.at(N-1) << endl;
    }
}


Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        int c=scanner.nextInt();
        if(a<b && b<c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 26120
#include<iostream>
using namespace std;
#define ll long long int
int main()
{


ll x  ,y ;
cin>>x >> y ;

ll a , b ;



b = y-x*2  ;


b/=2 ;


a = (y-4*b)/2 ;


if(a+b==x && (a*2+b*4)==y  && a>= 0 && b>=0 )
    cout<<"Yes"<<endl ;
else
    cout<<"No"<<endl ;

}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<ll> T(N);
    for(int i=0; i<N; i++) cin >> T[i];

    ll ans = 1;
    for(int i=0; i<N; i++) ans = lcm(ans, T[i]);

    cout << ans << endl;

    return 0;
}


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


int main(void){
  string S;
  long long K;
  cin >> S >> K;
  if(int(S[0] - '0') > 1) {
    cout << S[0];
    return 0;
  }
  int temp = 0;
  while(K > 1 && int(S[temp] - '0') == 1){
    K--;
	temp++; 
  }
  cout << S[temp];  
  return 0;
}
  


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

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  
  if (s == u)
    --a;
  else
    --b;
  
  cout << a << " " << b << endl;
  
  return 0;
}

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

int main(){
    int a, b, d, r;
    double f;
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = a / (double)b;
    cout << d << " " << r << " ";
    cout << fixed << setprecision(5) << f << endl;
}

Measured memory_bytes: 3240
#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define mp make_pair
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int isprime(int n){
    int count =0;
    for(int i=2;i<=sqrt(n);i++)
    if(n%i==0)count++;
    if(count)return 0;
    return 1;
}
void dfs(vector<int>adj[],int u,int visited[]) {
       visited[u] = 1;
       for (int i = 0; i < adj[u].size(); i++) {
       int v = adj[u][i];
       if (!visited[v]) 
       dfs(adj,v,visited);
      }
      
      }
void addedge(vector<int>adj[],int a,int b){
    adj[a].pb(b);
    adj[b].pb(a);
}
int main()
{
    
    int x;
    cin>>x;
    if(x>=400&&x<600)cout<<"8";
    if(x>=600&&x<800)cout<<"7";
    if(x>=800&&x<1000)cout<<"6";
    if(x>=1000&&x<1200)cout<<"5";
    if(x>=1200&&x<1400)cout<<"4";
    if(x>=1400&&x<1600)cout<<"3";
    if(x>=1600&&x<1800)cout<<"2";
    if(x>=1800&&x<2000)cout<<"1";
    return 0;
}




Measured memory_bytes: 3652
import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
		long prev = 0;
		long total = 0;
		for (int i = 0; i < n; i++) {
			long t = sc.nextLong();
			if (t + prev > x) {
				long s = t + prev - x;
				prev = t - s;
				total += s;
			} else {
				prev = t;
			}
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 46324
class UnionFind:
    def __init__(self, size):
        self.parent = [-1 for i in range(size)]#非負なら親ノード，負ならグループの要素数
        self.diff_potential = [0 for i in range(size)]#親ノードを基準としたポテンシャル

    def root(self, x): #root(x): xの根ノードを返す．
        if self.parent[x] < 0:
            return x
        else:
            rx = self.root(self.parent[x]) #xをxの根rxに直接つなぎたい
            self.diff_potential[x] += self.diff_potential[self.parent[x]] #そのために，diff(rx,x)を計算
            self.parent[x] = rx #xをrxに直接つなげる
            return rx

    def merge(self, x, y, diffxy): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        diffxy = self.diff_potential[x] + diffxy - self.diff_potential[y] #diffxyをdiff(rx,ry)で置き換え
        x = self.root(x) #rxを新たにxと名づける
        y = self.root(y) #ryを新たにyと名づける
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき入れ替える
            x,y=y,x
            diffxy = -diffxy
        self.parent[x] += self.parent[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        self.diff_potential[y] = diffxy #yの相対ポテンシャルを更新
        return True

    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue，違うならFalse
        return self.root(x) == self.root(y)
        
    def diff(self,x,y): #diff(x,y): xを基準としたyのポテンシャルを返す 
        if self.root(x) == self.root(y): #この時点でxの親はroot(x)
            return self.diff_potential[y] - self.diff_potential[x]
        else:
            return None

    def size(self,x): #size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]
#>>>>>>>>>>>>>>EhdCutHere>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

n,m = list(map(int,input().split()))

uf = UnionFind(n)
ans = True
for i in range(m):
    l,r,d=list(map(int,input().split()))
    l-=1;r-=1;
    if uf.issame(l,r):
        ans = d==uf.diff(l,r)
    else:
        uf.merge(l,r,d)
    if ans == False:
        break

if ans == False:
    print('No')
else:
    print('Yes')
#print([uf.root(i) for i in range(n)])
#print([uf.parent[i] for i in range(n)])
#print([uf.size(i) for i in range(n)])



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

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

  int p[n];
  for (int i=0; i<n; i++) cin >> p[i];

  sort(p, p+n);

  int ans = 0;

  for (int i=0; i<k; i++){
    ans += p[i];
  }

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


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

int main() {
    string S;
    string T;
    cin >> S >> T;
    for(int i = 0; i < S.size(); i++) {
        if(S == T) {
            cout << "Yes" << endl;
            return 0;
        }
        S = S[S.size()-1]+S.substr(0,S.size()-1);
    }
    cout << "No" << endl;
}

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

using namespace std;

class UnionFind {
public:
  vector<int> parent;

  UnionFind(int n) : parent(n, -1) {
  }

  int root(int x) {
    if (parent[x] < 0) {
      return x;
    } else {
      return parent[x] = root(parent[x]);
    }
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x) {
    return -parent[root(x)];
  }

  bool unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx == ry) return false;
    if (parent[rx] > parent[ry]) swap(rx, ry);
    parent[rx] += parent[ry];
    parent[ry] = rx;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  for (int i = 0; i < M; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    uf.unite(x, y);
  }
  set<int> res;
  for (int i = 0; i < N; i++) {
    res.insert(uf.root(i));
  }
  cout << res.size() << '\n';
  return 0;
}


Measured memory_bytes: 5376
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
A = LI()

ans = 0
m = A[0]
for i in range(1,N):
    if m <= A[i]:
        m = A[i]
    else:
        ans += m-A[i]

print(ans)


Measured memory_bytes: 93920
import copy

n = int(input())
s = list(input())

maxcount = 0
for i in range(1,n):
    count = 0
    X = set(s[:i])
    Y = set(s[i:])
    
    for j in X:
        for k in Y:
            if j == k:
                count += 1
        
    if maxcount < count:
        maxcount = count
        
print(maxcount)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
	FastIO
	lld n, k;
	cin >> n;
	cin >> k;
	lld c, r;
	c = 0;
	for(lld i = 0; i < n; i++)
	{
		cin >> r;
		if (r >= k)
			c+=1;
	}
	cout<< c;
	return 0;
}

Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	F := make([][]int, N)
	for i := 0; i < N; i++ {
		F[i] = sc.nextIntSlice(10)
	}
	P := make([][]int, N)
	for i := 0; i < N; i++ {
		P[i] = sc.nextIntSlice(11)
	}
	ans := int(-1e+10)
	for bit := 1; bit < 1<<uint(10); bit++ {
		total := 0
		for store := 0; store < N; store++ {
			count := 0
			for i := 0; i < 10; i++ {
				if 1<<uint(i)&bit > 0 && F[store][i] == 1 {
					count++
				}
			}
			total += P[store][count]
		}
		if ans < total {
			ans = total
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


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

class Main{

	public static void main(String[] arg) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");

		double a = Double.parseDouble(str[0]);
		double b = Double.parseDouble(str[1]);
		double degree = Double.parseDouble(str[2]);

		double cx = b * Math.cos(Math.toRadians(degree) ) * (-1) + a;
		double cy = b * Math.sin(Math.toRadians(degree) );
		double cc = Math.pow(cx, 2) + Math.pow(cy, 2);

		System.out.printf("%.5f\n",(a*cy)/ 2);
		System.out.printf("%.5f\n",Math.sqrt(cc) + a + b);
		System.out.printf("%.5f\n",cy);
	}
}

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

using namespace std;

int dp[200000 + 5] = {};

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

    dp[0] = 1;
    (s[0] != s[1]) ? (dp[1] = 2) : (dp[1] = 1);
    (s[0] != s[1] and s[1] != s[2]) ? (dp[2] = 3) : (dp[2] = 2);

    for (int i = 3; i < s.length(); ++i) {
        if (s[i] != s[i - 1]) {
            dp[i] = dp[i - 1] + 1;
        } else {
            dp[i] = dp[i - 3] + 2;
        }
    }

    cout << dp[s.length() - 1] << endl;
    return 0;
}

Measured memory_bytes: 1412
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  s[5] = ' ';
  s[13]= ' ';
  cout << s << endl;
  return 0;
}


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

void insertionSort(vector<int>& A)
{
    // 配列の先頭はソート済みと考え、インデックス1を
    // 最初の処理対象とする
    for (int i = 1; i < A.size(); i++)
    {
        // 未ソート列の先頭を一時保存
        int v = A[i];
        // ソート済み列の最後尾がj
        int j = i - 1;
        
        // jが配列範囲内、かつA[j]がvより大きければ、
        // A[j]の値を1つ後ろにずらし、A[j]にvを代入
        while ((j >= 0) && (A[j] > v))
        {
            // データ入れ替え
            A[j + 1] = A[j];
            A[j] = v;
            
            // 比較対象を変更
            j--;
        }
    }
}

int main()
{
    int a, b, c, tmp;
    vector<int> vec(3);
    REP(i, 3) cin >> vec[i];
    insertionSort(vec);
    for(int i = 0; i < vec.size(); i++)
    {
        if(i != 0) cout << " ";
        cout << vec[i];
    }
    cout << endl;
    return 0;
}


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

int main() {
    int N; 
    long long K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i], --A[i];

    deque<int> a; // 繰り返しの部分
    vector<bool> seen(N, false); // 一度見たかどうか
    int cur = 0;
    while (true) {
        // 一度通った頂点を見つけたときの処理
        if (seen[cur]) {
            while (a[0] != cur) {
                // 最初の余計な数手分を除去する
                --K;
                a.pop_front();

                // 繰り返す前に K が限界になったらリターン
                if (K == 0) {
                    cout << a[0]+1 << endl;
                    return 0;
                }
            }
            break;
        }
        // 最初は愚直にシミュレーションしつつ、履歴をメモしていく
        a.push_back(cur);
        seen[cur] = true;
        cur = A[cur];
    }
    cout << a[K % a.size()]+1 << endl;
}

Measured memory_bytes: 4748
lst = [int(i) for i in input().split()]
lst.sort()
count = 0
while (lst[0] != lst[2]):
    if lst[1] < lst[2]:
        lst[0] += 1
        lst[1] += 1
    elif lst[1] - lst[0] < 2:
        lst[1] += 1
        lst[2] += 1
    else:
        lst[0] += 2
    lst.sort()
    count += 1
print(count)

Measured memory_bytes: 3064
// #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const int INF = 1e9;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
   ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
   ostr << "}";
   return ostr;}

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; }


int main(void){
 ios::sync_with_stdio(false);

 string S;
 cin >> S;
 ll N;
 N = S.size();

 ll ans = 0;
 ll index = 0;
   string tmp;
   tmp = S[index];

 while (index <= N-1){
   string conf;
   conf = S[index+1];

   if (tmp != conf){
     ans++;
     index++;
     tmp = S[index];}

   else {
     tmp = S.substr(index+1, 2);
     index += 2;
     ans++;
   }

 }


 cout << ans << endl;


 return 0;
}



Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<int> h(n), dp(n, INT_MAX);
	for(int i = 0; i < n; ++ i) cin >> h[i];
	dp[0] = 0;
	for(int i = 1; i < n; ++ i) {
		for(int k = 1; k <= 2; ++ k) {
			if(i - k < 0) continue;
			dp[i] = min(dp[i], abs(h[i - k] - h[i]) + dp[i - k]);
		}
	}
	cout << dp[n - 1] << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main(){
  prep();
  long long n, s;
  cin >> n >> s;
  
  int lim = sqrt(n);
  
  for (int i=2; i<=max(lim, 316228); i++){
      long long nn = n;
      long long sum = 0;
      while (nn > 0 && sum <= s){
          sum += nn%i;
          nn /= i;
      }
      if (sum == s){
          cout << i;
          return 0;
      }
  }
  // x is over sqrt
  // n%x+n/x = s
  long long minnest = 10000000000000000LL;
  long long sub = n-s;
  long long lim2 = min((long long)lim-(n%lim == 0), s);
  for (int i=1; i<=lim2; i++){
      long long x = sub/i+1;
      if (sub%i == 0 && x > s-i){
          minnest = min(minnest, x);
      }
  }
  
  if (minnest == 10000000000000000LL){
      if (s == n){
          cout << n+1;
          return 0;
      }
      cout << -1;
  }else{
      cout << minnest;
  }
 
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char str[10];
bool jay1,jay2;
int main(){
	scanf("%s",&str);
	for (register int i=0; i<3; ++i) 
	{
		if (str[i]=='A') jay1=true;
		if (str[i]=='B') jay2=true;
	}	
	if (!jay1 || !jay2) puts("No");
	else puts("Yes"); 
return 0;
}


Measured memory_bytes: 256
//#define LOCAL

#include <cstdio>
#include <cmath>

struct Point{ double x, y;};

void koch(int n, Point a, Point b) {
    if(!n) return ;

    Point s, t, u;
    double th = M_PI*60.0/180.0;

    s.x = (2.0*a.x+1.0*b.x)/3.0;
    s.y = (2.0*a.y+1.0*b.y)/3.0;
    t.x = (1.0*a.x+2.0*b.x)/3.0;
    t.y = (1.0*a.y+2.0*b.y)/3.0;
    u.x = (t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
    u.y = (t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

    koch(n-1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n-1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n-1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n-1, t, b);
}

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    int n; Point a, b;
    scanf("%d", &n);
    a.x = 0, a.y = 0, b.x = 100, b.y = 0;

    printf("%.8f %.8f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n", b.x, b.y);

    return 0;
}


Measured memory_bytes: 2728
N, K = gets.split(' ').map(&:to_i)
s = gets.chomp

s = 'R' + s + 'L'
happy = 0
1.upto(N) do |i|
	if (s[i] == 'L' && s[i-1] == 'L') ||
		(s[i] == 'R' && s[i+1] == 'R')
		happy += 1
	end
end
puts [happy+2*K, N-1].min

Measured memory_bytes: 4220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < m; i++)
        cin >> b[i];
       
    int na = 0;
    ll total = 0;
    for (int i = 0; i < n; i++) {
        if (total + a[i] <= k) {
            na++;
            total += a[i];
        }
        else
            break;
    }
    int nb = 0;
    for (int i = 0; i < m; i++) {
        if (total + b[i] <= k) {
            nb++;
            total += b[i];
        }
        else
            break;
    }
        
    int ans = na + nb;
    while (na != 0) {
        na--;
        total -= a[na];
        while (nb < m) {
            if (total + b[nb] <= k) {
                total += b[nb];
                nb++;
            }
            else
                break;
        }
        ans = max(ans, na + nb);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4724
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;

int a[200005];

bool compare(int a,int b)
{
    return a>b;
}

int main()
{
    int n,k,x;
    cin>>n>>k;
    memset(a,0,sizeof(a));
    for(int i=0;i<n;i++)
	{
        cin>>x;
        a[x]++;
    }
    int ans=0;
    sort(a,a+n,compare);
    for(int i=k;i<=n;i++)
	{
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
from itertools import permutations
n = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
PD=[]
for v in permutations(P):
    PD.append(list(v))
a = sorted(PD).index(P)
QD = []
for x in permutations(Q):
    QD.append(list(x))
b = sorted(QD).index(Q)
print(abs(a-b))

Measured memory_bytes: 18232
public class Main
{
  public static void main(String args[])
  {
    java.util.Scanner sc=new java.util.Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
  if((a+b+c)>=22)
    System.out.println("bust");
  else
    System.out.println("win");
 
  }
}

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

const int maxn=1e5+5;
vector<int>adj[maxn];
int visited[maxn];

//void bfs(int v){
//    visited[v]=1;
//    queue<int>q;
//    q.push(v);
//    while(!q.empty()){
//        int p=q.front();
//        q.pop();
//        for(auto u:adj[p]){
//            if(!visited[u]){
//                visited[u]=p;
//                q.push(u);
//            }
//        }
//    }
//}
void solve()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if((a+b)>=k){
        if(k<a){
            cout<<k<<endl;
        }
        else{
        cout<<a<<endl;}
    }
    else {
        ll temp=k-(a+b);
        cout<<a-temp<<endl;
    }
}

    int main()
    {
        ios::sync_with_stdio(0);
        cin.tie(0);
        solve();
        return 0;
    }


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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> g(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  for (int i = 0; i < n; ++i) {
    cout << g[i].size() << '\n';
  }

  return 0;
}

Measured memory_bytes: 3620
arr = Array.new(9){[]}
2.upto(10){|power|
    x = 1
    while true
        y = x ** power
        break if y > 100_000_000
        arr[power-2] << [y, y.to_s.split("").map(&:to_i).inject(:+)]
        x += 1
    end
}

a, n, m = gets.chomp.split.map(&:to_i)
puts arr[n - 2].count{|x, y| x <= m && x == (y + a) ** n}



Measured memory_bytes: 9400
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func Factorial(N int) (F, Finv []int) {
  F = make([]int, N + 1)
  Finv = make([]int, N + 1)
  inv := make([]int, N + 1)
  F[0] = 1
  F[1] = 1
  Finv[0] = 1
  Finv[1] = 1
  inv[0] = 1
  inv[1] = 1
  for i := 2; i < N + 1; i++ {
    F[i] = F[i - 1] * i % p
    inv[i] = p - inv[p % i] * (p / i) % p
    Finv[i] = Finv[i - 1] * inv[i] % p
  }
  return
}

func Comb(F, Finv *[]int, N, a int) (ret int) {
  ret = (*F)[N] * ((*Finv)[a] * (*Finv)[N - a] % p) % p
  return
}

const p = 1000000007

func main() {
  NMK := NextIntVec()
  N, M, K := NMK[0], NMK[1], NMK[2]
  S := 0
  for i := 0; i < N; i++ {
    for j := 0; j < M; j++ {
      m := M - j
      n := N - i
      S += m * (m - 1) / 2 % p
      S += M * n * (n - 1) / 2 % p
      S += (n - 1) * (j * (j + 1) / 2 + m * (m - 1) / 2) % p
      S %= p
    }
  }
  F, Finv := Factorial(N * M)
  S *= Comb(&F, &Finv, N * M - 2, K - 2)
  S %= p
  Write(S)
  Output()
}

Measured memory_bytes: 5504
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int n;
	
	scanf("%d", &n);
	
	while (n > 0){
		scanf("%d %d %d", &a, &b, &c);
		if ((a * a == (b * b) + (c * c)) || (b * b == (a * a) + (c * c)) || (c * c == (a * a) + (b * b))){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		n--;
	}
	
	return (0);
}

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

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] s = str.split(" ",0);
			int g = Integer.parseInt(s[1]);
			int b = Integer.parseInt(s[2]);
			if((g*10+b)%4 == 0) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}
}


Measured memory_bytes: 22612
//#if 1
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
//#endif
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {

	int N, K;
	int x[100000];
	int left, right;
	long min=3e8, tmp;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < N; i++) {
		if (i + K - 1 == N)break;
		left = x[i];
		right = x[i + K - 1];
		tmp = abs(left) + abs(right - left);
		min = (min > tmp) ? tmp : min;
		tmp = abs(right) + abs(right - left);
		min = (min > tmp) ? tmp : min;

	}
	cout << min << endl;


	return(0);
}

Measured memory_bytes: 640
import java.util.Scanner;

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

    void solve(Scanner sc) {
        int h = sc.nextInt();
        int w = sc.nextInt();
        int count = 0;
        for (int i = 0; i < h; i++) {
            String row = sc.next();
            for (char c : row.toCharArray()) {
                if (c == '#') {
                    count++;
                }
            }
        }
        System.out.println(count == h + w - 1 ? "Possible" : "Impossible");
    }
}

Measured memory_bytes: 21844
require 'set'
 
class Arrow
  attr_reader :source, :sink, :label

  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
  end
end

def push(queue, key, value)
  size = queue.size
  index = queue.index{|target, _| target >= key} || size

  return queue[index][1] if index < size && queue[index][0] == key
  return nil if index > 0 && !key.start_with?(queue[index - 1][0])
  # queue.slice!(index..-1) if index < size && !queue[index][0].start_with?(key)

  queue.insert(index, [key, value])
  value
end

def calc(n, arrows, start, goal)
  ins = Array.new(n){[]}
  arrows.each do |arrow|
    ins[arrow.sink] << arrow.source
  end

  reachable_from = {}
  stack = [goal]
  until stack.empty?
    node = stack.pop
    reachable_from[node] = true
    ins[node].each do |source|
      stack << source unless reachable_from[source]
    end
  end

  return nil unless reachable_from[start]
  arrows.select!{|arrow| reachable_from[arrow.sink]}

  outs = Array.new(n){[]}
  arrows.each do |arrow|
    outs[arrow.source] << arrow
  end

  max = n * arrows.map{|arrow| arrow.label.size}.max

  queue = [['', {start => true}]]
  until queue.empty?
    spell, map = queue.shift
    return spell if map[goal]

    return nil if spell.size > max

    map.each do |node, _|
      outs[node].each do |arrow|
        t = push(queue, spell + arrow.label, {})
        t[arrow.sink] = true if t
      end
    end
  end
  nil
end

loop do
  n, a, s, g = gets.split.map(&:to_i)
  break if n == 0

  arrows = (0...a).map do |i|
    x, y, lab = gets.split
    Arrow.new(x.to_i, y.to_i, lab)
  end

  puts calc(n, arrows, s, g) || 'NO'
end

Measured memory_bytes: 10064
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  cout << min((n + a - 1) / a * b, (n + c - 1) / c * d) << endl;
}



Measured memory_bytes: 3080
x = int(input())
if 400<=x and x <=599:
    print("8")
elif 600<=x and x <=799:
    print("7")  
elif 800<=x and x <=999:
    print("6")  
elif 1000<=x and x <=1199:
    print("5")  
elif 1200<=x and x <=1399:
    print("4")  
elif 1400<=x and x <=1599:
    print("3")  
elif 1600<=x and x <=1799:
    print("2")  
else:
    print("1")            


Measured memory_bytes: 9080
#include"bits/stdc++.h"
using namespace std;

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

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

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
LL ave(LL, LL);

int main() {
	char x, y; cin >> x >> y;
	if (x < y)cout << "<";
	else if (x > y)cout << ">";
	else cout << "=";
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}
LL ave(LL a, LL b) {
	return (a + b) / 2;
}

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



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    vector<long long > List;
    long long result = 0;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        long long temp;
        cin >> temp;
        List.push_back(temp);
    }
    for (int i = 1; i < N; i++)
    {
        if (List[i] < List[i - 1])
        {
            result += List[i - 1] - List[i];
            List[i] = List[i - 1];
        }
    }
    cout<<result;
    

    
    return 0;
}

Measured memory_bytes: 5312
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll N; cin >> N;
    string S; cin >> S;
    ll mod = 1000000007;
    map<char,ll> alp;
    for(char s = 'a'; s <= 'z'; s++)
    {
        for(ll i = 0; i < N; i++)
        {
            if(S.at(i) == s)
            {
                alp[s] += 1; //Sにおける文字毎の出現回数
            }
        }
    }
    ll ans = 1;
    for(char s = 'a'; s <= 'z'; s++)
    {
        ans = (ans * (alp[s] + 1)) % mod;
    }
    cout << (ans + mod - 1) % mod << endl;
}

Measured memory_bytes: 512
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
#include <ctime>
#include <functional>
#include <cassert>
using namespace std;
const double pi=3.141592653589793238;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(),a.end());
    cout << a[n/2]-a[n/2-1] << endl;
}



Measured memory_bytes: 3764
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	cout << min(n, k)*x + max(n - k, 0)*y << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

llint modpow(llint a, llint b, llint p){
    if(b==0) return 1;
    else if(b%2==0){
        llint d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a*modpow(a, b-1, p)) % p;
    }
}

llint moddiv(llint x, llint a, llint m){
    return (x*modpow(a, m-2, m)) % m;
}

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

    int H, W, A, B;
    cin >> H >> W >> A >> B;
    llint ans = 0;
    vector<llint> fct(H+W-1);
    fct[0] = 1;
    REP(i, H+W-2) fct[i+1] = (fct[i]*(i+1))%MOD;
    vector<llint> inv_e(H+W-1);
    inv_e[H+W-2] = modpow(fct[H+W-2], MOD-2, MOD);
    for(int i=H+W-3; i>=0; i--){
        inv_e[i] = (inv_e[i+1] * (i+1)) % MOD;
    }
    REP(n, H-A){
        llint tmp = fct[B-1+n]*inv_e[B-1]%MOD;
        tmp = tmp * inv_e[n]%MOD;
        tmp = tmp * fct[H-1-n+W-1-B]%MOD;
        tmp = tmp * inv_e[H-1-n]%MOD;
        tmp = tmp * inv_e[W-1-B]%MOD;
        ans = (ans + tmp)%MOD;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#define ll long long
using namespace std;
int main(){
  ll a,b,x;
  ll ans1=0,ans2=0;
  cin>>a>>b>>x;
  ans1=a/x;
  ans2=b/x;
  if(ans1*x!=a)
    cout<<ans2-ans1<<endl;
  else cout<<ans2+1-ans1<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#define MAX 100000

int parent(int i) { return i/2;}
int left(int i) { return 2*i;}
int right(int i){ return 2*i+1;}

int main(){
    int H,i,A[MAX+1];
    scanf("%d",&H);
    for(i=1;i<=H;i++) {
        scanf("%d",&A[i]);
    }
    
    for(i=1;i<=H;i++) {
        printf("node %d: key = %d, ",i,A[i]);
        if(parent(i) >= 1) printf("parent key = %d, ",A[parent(i)]);
        if((left(i) <= H) && (A[left(i)]!=0)) printf("left key = %d, ",A[left(i)]);
        if((right(i) <= H) && (A[right(i)]!=0)) printf("right key = %d, ",A[right(i)]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.dl", "r", stdin);
	string str = "";
	string res = "";
	int w;
	int n;

	getline (cin, str );
	stringstream ssw(str);
	ssw >> w;

	vector <int> Aj (w, 0);
	int i;
	for (i = 0; i < w; ++i){
		Aj[i] = i;
	} // end for
			
	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;

	for (i = 0; i < n; ++i){
		getline (cin, str );
		int a,b;
		str = str.replace(str.find(','), 1, " ");

		stringstream ss(str);
		ss >> a >> b;
//		cout << "a: " << a << " b: " << b << endl;
		swap(Aj[a-1], Aj[b-1]);
	} // end for

	for (i = 0; i < w; ++i){
		cout << (Aj[i] + 1) << endl;	
	} // end for
	
	return 0;
}

Measured memory_bytes: 0
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

/* TEMPLATE ENDS HERE */

#define MAXN (1 << 12)

ll a[MAXN];
ll cnt[MAXN];
ll lless[MAXN];


struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

int main() {
	cout << fixed << setprecision(12);	
	ll n, k;	
	ll inv = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (a[j] < a[i]) {
				inv++;
			}
		}
	}
	ll sum = 0;
	for (int i = 0; i < MAXN; i++) {
		lless[i] = sum;
		sum += cnt[i];
	}
	ll linv = 0;
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		linv += lless[a[i]];
	}
	ll k2 = (k * (k - 1)) / 2;
	ll ret = ((linv % MOD) * (k2 % MOD) + (inv % MOD) * k) % MOD;
	cout << ret << endl;
	return 0;
}




Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

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);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

struct UnionFind {
private:
	const int n;
	int _size;
	vector<int>uf;
public:
	UnionFind(int _n) :n(_n), _size(_n), uf(_n, -1) {}
	int find(int x) { return (uf[x] < 0) ? x : uf[x] = find(uf[x]); }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -uf[find(x)]; }
	int size() { return _size; }
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) { return; }
		--_size;
		if (uf[y] < uf[x]) { swap(x, y); }
		uf[x] += uf[y];
		uf[y] = x;
	}
};

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

	UnionFind road(a), train(a);

	for (int i = 0; i < b; ++i) {
		int n, m;
		cin >> n >> m;
		road.unite(n - 1, m - 1);
	}

	for (int i = 0; i < c; ++i) {
		int n, m;
		cin >> n >> m;
		train.unite(n - 1, m - 1);
	}

	map<pair<int, int>, int>m;

	for (int i = 0; i < a; ++i) { ++m[make_pair(road.find(i), train.find(i))]; }
	for (int i = 0; i < a; ++i) {
		cout << m[make_pair(road.find(i), train.find(i))];
		if (i != a - 1) { cout << "  "; }
	}

	cout << endl;
}

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

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

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll N, M, Q;
  cin >> N >> M >> Q;
  ll sum[N][N] = {}, trains[N][N] = {}, ans[N][N] = {};
  rep(_, M){
    ll L, R;
    scanf("%lld %lld\n", &L, &R);
    sum[L-1][R-1]++;
    trains[L-1][R-1]++;
  }
  rep(r, N) rep(l, N-1) sum[l+1][r] += sum[l][r];

  rep(l, N) repi(r, l, N){
    if(l == r) ans[l][r] = trains[l][r];
    else if(l == 0) ans[l][r] = ans[l][r-1] + sum[r][r];
    else ans[l][r] = ans[l][r-1] + sum[r][r] - sum[l-1][r];
  }
  // rep(i, N){
  //   debug(trains[i]);
  //   debug(sum[i]);
  //   debug(ans[i]);
  // }
  rep(_, Q){
    ll p, q;
    scanf("%lld %lld\n", &p, &q);
    cout << ans[p-1][q-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 6784
function main()
dp=zeros(Int,13)
dp[13]=1
const mod=10^9+7
for c=chomp(readline())
	de=zeros(Int,13)
	for i=1:13
		if c=='?'
			for j=0:9
				de[mod1(i*10+j,13)]+=dp[i]
			end
		else
			de[mod1(i*10+Int(c)-48,13)]+=dp[i]
		end
	end
	dp=de.%mod
end
println(dp[5])
end
main()

Measured memory_bytes: 153272
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll modularExponentiation(ll x,ll n,ll M){
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modularExponentiation((x*x)%M,n/2,M);
    return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;
}
ll binaryExponentiation(ll x,ll n){
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return binaryExponentiation(x*x,n/2);
    else
        return x*binaryExponentiation(x*x,(n-1)/2);
}
ll GCD(ll A, ll B){
    if(B==0)
        return A;
    else
        return GCD(B, A % B);
}
ll extended_GCD(ll a , ll b , ll &x , ll &y){
    if(a == 0){
        x = 0;
        y = 1;
        return b;
    }
    ll x1 , y1;
    ll gcd = extended_GCD(b%a , a , x1 , y1);
    x = y1 - (b/a)*x1;
    y = x1;
    return gcd;
}
ll modinv(ll a , ll mod){
    ll x , y;
    extended_GCD(a , mod , x , y);
    if(x < 0) x += mod;
    return x;
}
ll modPrimeInverse(ll A,ll M){
    return modularExponentiation(A,M-2,M);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    string s;
    cin >> s;
    if(s.length() < 6){
        cout << "No\n";
    }
    else{
        if(s[2] == s[3] && s[4] == s[5]){
            cout << "Yes\n";
        }
        else{
            cout << "No\n";
        }
    }

    //#ifndef ONLINE_JUDGE
    //    cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
    //#endif
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))

using namespace std;

int main() {
	char s[100001] = {};
	cin >> s;
	int n = strlen(s);

	int a = 0, b = 0;

	for (int i = 0; i < n; i++) {
		if (s[i] == '0') { a++; }
		else { b++; }
	}
	cout << min(a, b) * 2;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
    int N = 1000000;
    vector<int> arr(N);
    vector<int> so(0);
    for(int i = 0; i < N; i++){
        arr[i] = 1;
    }
    for(int i = 2; i < sqrt(N); i++){
        if(arr[i]){
            for(int j = 0; i * (j + 2) < N; j++){
                arr[i *(j + 2)] = 0;
            }
        }
    }
    for(int i = 2; i < N; i++){
        if(arr[i]){
            so.push_back(i);
        }
    }

    int q;
    cin >> q;
    vector<int> k(100001);
    rep(i, 100001){
        k.at(i) = 0;
    }
    for(int i=3; i<=100000; i+=2){
        if(binary_search(so.begin(), so.end(), i) && binary_search(so.begin(), so.end(), (i+1)/2)){
            k.at(i) = 1;
        }
    }
    int sum = 0;
    for(int i=3; i<100001; i++){
        sum += k.at(i);
        k.at(i) = sum;
    }
    vector<vector<int>> in(q, vector<int>(2));
    rep(i, q){
        cin >> in.at(i).at(0) >> in.at(i).at(1);
    }
    rep(i, q){
        cout << k.at(in.at(i).at(1)) - k.at(in.at(i).at(0)-1) << endl;
    }
    return 0;
}

Measured memory_bytes: 10744
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));
		String str;
		str = br.readLine();
		int N,L;
		String a[] = str.split(" ",0);
		N = Integer.parseInt(a[0]);
		L = Integer.parseInt(a[1]);
		List<String> data = new ArrayList<String>();
		for(int i = 0; i < N; i++){
			data.add(br.readLine());
		}
		Collections.sort(data);
		String result;
		result = data.get(0);
		for(int i = 1; i < N; i++){
			result += data.get(i);
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 11856