akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

// 入力
int N, K;
int dp[1 << 21][22];
string S[1 << 18];

// 遷移
int LEN[1 << 21], BASE[1 << 21];
pair<int, int> G[1 << 21][22];
bool H[1 << 21][22];

void init() {
	for (int i = 0; i < 21; i++) {
		for (int j = (1 << i); j < (2 << i); j++) LEN[j] = i;
	}
	for (int i = 0; i < (1 << 21); i++) BASE[i] = i - (1 << LEN[i]);

	for (int i = 1; i < (2 << N); i++) {
		int bit[22], base = BASE[i];
		for (int j = 0; j < LEN[i]; j++) {
			if ((base & (1 << j)) == 0) bit[j] = 0;
			else bit[j] = 1;
		}

		// 部分消し
		for (int j = 0; j < LEN[i]; j++) {
			int lims = j;
			for (int k = j; k < LEN[i]; k++) { if (k + 1 == LEN[i] || bit[k] != bit[k + 1]) break; lims = k + 1; }

			int r1 = (base & ((1 << j) - 1));
			int r2 = (base >> (lims + 1));
			int cx = r1 + (r2 << j);
			int cp = j + (LEN[i] - lims - 1);
			G[i][j] = make_pair((1 << cp) + cx, min(cp, j + 1));
			if (lims + 1 == LEN[i]) H[i][j] = true;
		}
	}
}

int main() {
	cin >> N >> K;
	for (int i = 0; i <= N; i++) cin >> S[i];
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j < S[i].size(); j++) {
			if (S[i][j] == '1') dp[(1 << i) + j][0] = 1;
		}
	}
	/*string T; cin >> T;
	int r = 0;
	for (int i = 0; i < T.size(); i++) {
		if (T[T.size() - 1 - i] == '1') r += (1 << i);
	}
	dp[(1 << T.size()) + r][0] = 1;*/

	init();

	for (int i = (2 << N) - 1; i >= 1; i--) {
		int cv[22];
		for (int j = 0; j < N; j++) cv[j] = (1 << j) + (BASE[i] & ((1 << j) - 1));
		for (int j = 0; j < LEN[i]; j++) {
			if (dp[i][j] == 0) continue;
			for (int k = j; k < LEN[i]; k++) dp[G[i][k].first][G[i][k].second] += dp[i][j];
			for (int k = j; k < LEN[i]; k++) { if (H[i][k] == false) dp[cv[k]][k] += dp[i][j]; }
		}
	}

	for (int i = N; i >= 0; i--) {
		for (int j = (1 << i); j < (2 << i); j++) {
			int ret = 0;
			for (int k = 0; k <= N; k++) ret += dp[j][k];
			if (ret < K) continue;

			string str = "";
			for (int k = i - 1; k >= 0; k--) {
				if (((j - (1 << i)) / (1 << k)) % 2 == 1) str += "1";
				else str += "0";
			}
			cout << str << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 615680
import sys
from collections import Counter
list=[]
while True:
    try:
        s = int(input())
        list.append(s)
    except:
        break
c=Counter(list)
mode=c.most_common()
print(mode[0][0])
max=mode[0][1]
i=1
while True:
    if max==mode[i][1]:
        max=mode[i][1]
        print(mode[i][0])
        i+=1
    else:
        break


Measured memory_bytes: 6000
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;

signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	ll n; string s; cin >> s; n = s.size();
	if (s[0] == '0' || s[n - 1] == '1') { cout << "-1\n"; return 0; }
	rep2(i, n / 2 - 1) {
		if (s[i] != s[n - i - 2]) { cout << "-1\n"; return 0; }
	}
	queue<ll> que;
	rep(i, n) {
		if (s[i] == '1') { que.push(i + 1); }
	}
	rep2(i, n - 2) {
		if (que.front() == i) { que.pop(); }
		cout << que.front() << ' ' << i << endl;
	}
	cout << n - 1 << ' ' << n << endl;
	return 0;
}

Measured memory_bytes: 4120
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#define MOD 1000000007
#define MAX 5000005
#define endl "\n"
string in;
lli n;
lli md[55][55];
string out;
lli arr[MAX];
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
 /*   freopen("biginput.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    lli t;
    t = 1;
    lli pa = 0;
    while(t--){
       pa++;
       lli n,k;
       cin>>n>>k;
       for(lli i = 0; i<n; i++)
            cin>>arr[i];
       for(lli i = k; i<n; i++){
           if(arr[i] > arr[i-k]){
               cout<<"Yes"<<endl;
           }
           else{
               cout<<"No"<<endl;
           }
       }
    }
}


Measured memory_bytes: 5212
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include<complex>

using namespace std;

typedef long long            ll;
typedef unsigned             ui;
typedef unsigned long long   ull;
typedef pair<int,int>        i_i;
typedef pair<ll,int>         ll_i;
typedef pair<ll,ll>          ll_ll;
typedef pair<double,int>     d_i;
typedef pair<double,double>  d_d;
typedef vector<int>          vi;
typedef vector<vector<int> > vii;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF __INT32_MAX__
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  int t[112345]={};
  int x[112345]={};
  int y[112345]={};
  int dx;
  int dy;
  int dt;
  int n;
  int i;

  cin>>n;
  loop(i,1,n+1)
    cin>>t[i]>>x[i]>>y[i];

  rep(i,n)
    {
      dx=abs(x[i+1]-x[i]);
      dy=abs(y[i+1]-y[i]);
      dt=t[i+1]-t[i];
      dout(dt);
      dout(dx);
      dout(dy);
      if(dt>=dy+dx)
        {
          if((dt-dx-dy)%2){puts("No"),exit(0);};
        }
      else{puts("No"),exit(0);};
    }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 1536
H,W = map(int, input().split() )
S = ["s" * (W+2)   ] + [ "s" + input() + "s" for _ in range(H) ] + [ "s" * (W+2) ] 

def check(h,w):
  return S[h-1][w] == "#" or \
         S[h+1][w] == "#" or \
         S[h][w-1] == "#" or \
         S[h][w+1] == "#"

for h in range(1,H+1):
  for w in range(1,W+1):
    if S[h][w] == "#" and not check(h,w):
      print("No")
      exit()
print("Yes")

Measured memory_bytes: 3064
H,W,K=map(int,input().split())

C=[list(input()) for _ in range(H)]
ans=0

for i in range(2**(H+W)):
    H_,W_=[0]*H,[0]*W
    bin_=format(i,'b').zfill(H+W)
    for n,b in enumerate(bin_):
        if n<H and b=='1':
            H_[n-1]=1
        elif n>=H and b=='1':
            W_[n-H]=1
    blackCnt=0
    for n,c_ in enumerate(C):
        for m,c in enumerate(c_):
            if H_[n]==0 or W_[m]==0:
                continue
            if c=='#':
                blackCnt+=1
    if blackCnt==K:
        ans+=1

print(ans)

Measured memory_bytes: 9168
c[99999],i,n;main(j){for(j=i=2;i*i<5e4;!c[i]&&j<5e4?c[j+=i]=1:(j=++i));for(;i=scanf("%d",&j),j;n=!printf("%d\n",n))for(;++i<=j/2;n+=!(c[j-i]+c[i]));exit(0);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

signed main(){

	vector<lli> v(3);
	REP(i,0,3)cin>>v[i];

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

	cout<<v[0]*v[1]/2<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int array[] = new int[n];
		
		for (int i = 0; i < n; i++ ) {
			array[i] = scan.nextInt();
			System.out.print(array[i]);
			if ( i == n - 1) break;
			System.out.print(" ");
		}
		System.out.println();
		scan.close();
		

		
		for (int i = 1; i < n; i++) {
			int v = array[i];
			int j = i - 1;
			
			while ( j >= 0 && array[j] > v) {
				array[j + 1] = array[j];
				j--;
			}
			array[j + 1] = v;
			
			for (int k = 0; k < n; k++ ) {
				if ( k == n - 1) {
					System.out.println(array[k]);
				} else {
					System.out.print(array[k] + " ");
				}
				
			}
		}
		
	}
}



Measured memory_bytes: 31040
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

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

	om := make(map[int]int, n/2)
	em := make(map[int]int, n/2)
	for i := 0; i < n/2; i++ {
		xo := scanInt()
		om[xo]++
		xe := scanInt()
		em[xe]++
	}

	type entry struct{ k, v int }
	ol := make([]entry, len(om))
	index := 0
	for k, v := range om {
		ol[index].k, ol[index].v = k, v
		index++
	}
	sort.Slice(ol, func(i, j int) bool { return ol[i].v > ol[j].v })

	el := make([]entry, len(em))
	index = 0
	for k, v := range em {
		el[index].k, el[index].v = k, v
		index++
	}
	sort.Slice(el, func(i, j int) bool { return el[i].v > el[j].v })

	if ol[0].k != el[0].k {
		fmt.Println(n - ol[0].v - el[0].v)
		return
	}

	if len(ol) == 1 {
		ol = append(ol, entry{-1, 0})
	}
	if len(el) == 1 {
		el = append(el, entry{-1, 0})
	}
	if v1, v2 := n-ol[0].v-el[1].v, n-ol[1].v-el[0].v; v1 < v2 {
		fmt.Println(v1)
	} else {
		fmt.Println(v2)
	}
}


Measured memory_bytes: 6956
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<queue>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
string s;
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>s;
	cout<<s[0]<<s[1]<<s[2]<<endl;
	return 0;
}



Measured memory_bytes: 3588
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int m = n, s = 0;
        while (m != 0) {
            s += m % 10;
            m /= 10;
        }
        System.out.println(n % s == 0 ? "Yes" : "No");
    }
}

Measured memory_bytes: 22740
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,m;
  while(cin >>n>>m,n||m){
    vector<int> book;
    int x,ans = 0;
    for(int i=0; i<m; i++){
      cin >>x;
      book.push_back(x);
      if(ans<x){ans = x;}
    }
    for(int i;;ans++){
      int last = ans,l = n;
      for(i=0; i<m; i++){
	if(last < book[i]){
	  last = ans;
	  l--;
	  if(l == 0){break;}
	  last-=book[i];
	}
	else{last-=book[i];}
      }
      if(i == m){cout <<ans<<endl;break;}
    }
  }
  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define N 500000
#define maxn (N + 10)
#define maxm (maxn * 2)
#define pb push_back
#define lc (id * 2)
#define rc (id * 2 + 1)
#define Mod(x) (((x) % mod + mod) % mod)
typedef long long ll;
const ll INF = (1e8);
const ll mod = (1e9 + 7);
ll pw[maxn],iv[maxn];
ll f_pow(ll x,ll p){
    ll ans = 1;
    while(p){
        if(p % 2 == 1){
            ans *= x;ans %= mod;
        }
        x *= x;x %= mod;p /= 2;
    }
    return ans;
}
void init(){
    pw[0] = 1;
    for(ll i = 1;i <= N;i++){
        pw[i] = pw[i - 1] * i;pw[i] %= mod;
    }
    iv[N] = f_pow(pw[N],mod - 2);
    //printf("iv[N] = %lld\n",iv[N]);
    for(ll i = N - 1;i >= 0;i--){
        iv[i] = iv[i + 1] * (i + 1);iv[i] %= mod;
    }
    //iv[0] = 1;
    //printf("iv0 = %lld\n",iv[0]);
}
ll C(ll x,ll y){
    ll ans = pw[x];ans *= iv[y];ans %= mod;ans *= iv[x - y];ans %= mod;
    return ans;
}
int main(){
    init();
    ll n,m;scanf("%lld%lld",&n,&m);
    ll ans = 0;
    for(ll i = 0;i <= n;i++){
        ll cnt = ((i % 2 == 0) ? 1 : -1);
        //printf("cnt1 = %lld\n",cnt);
        cnt *= C(m,i);cnt = Mod(cnt);
        //printf("cnt2 = %lld\n",cnt);
        cnt *= C(n,i);cnt = Mod(cnt);
        //printf("cnt3 = %lld\n",cnt);
        cnt *= pw[i]; cnt = Mod(cnt);
        //printf("cnt4 = %lld\n",cnt);
        cnt *= C(m - i,n - i);cnt = Mod(cnt);
        //printf("cnt5 = %lld\n",cnt);
        cnt *= pw[n - i];cnt = Mod(cnt);
        //printf("cnt6 = %lld\n",cnt);
        cnt *= C(m - i,n - i);cnt = Mod(cnt);
        //printf("cnt7 = %lld\n",cnt);
        cnt *= pw[n - i];cnt = Mod(cnt);
        ans += cnt;ans %= mod;
        //printf("ans = %lld cnt = %lld\n",ans,cnt);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 11648
num=int(input())
for i in range (num):
    info=list(map(float,input().split()))
    info=list(map(lambda x:int(x*10**6),info))
    if info[2]==info[0]:
        if info[6]==info[4]:
            print("YES")
        else:
            print("NO")
    elif info[6]==info[4]:
        if info[2]==info[0]:
            print("YES")
        else:
            print("NO")
    else:
        if (info[3]-info[1])/(info[2]-info[0])==(info[7]-info[5])/(info[6]-info[4]):
            print("YES")
        else:
            print("NO")

Measured memory_bytes: 7684
#include"bits/stdc++.h"
using namespace std;
#pragma warning(disable:4996)



int main() {
	int N;cin>>N;
	vector<int>v(N);
	for(int i=0;i<N;++i)cin>>v[i];
	vector<int>anss;
	while (v.size()) {
		int place=-1;
		for (int i = 0; i < v.size(); ++i) {
			if (v[i] == i + 1) {
				place=i;
			}
		}
		if (place == -1) {
			break;
		}
		else {
			anss.push_back(place+1);
		}
		v.erase(v.begin()+place);
	}
	reverse(anss.begin(),anss.end());
	if (anss.size() == N) {
		for (int i = 0; i < N; ++i) {
			cout<<anss[i]<<endl;
		}
	}
	else {
		cout<<-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
# input here
_INPUT = """\
5
3 3 3 3 3
"""

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    Springboard = []
    max = A[0]
    for i in range(1,len(A)):
    # 自分より前に自分より身長が高い人がいないとき
        if max < A[i]:
            max = A[i]
            Springboard.append(0)
     # 自分より前に自分より身長が高い人がいるとき
        else:
            Springboard.append(max - A[i])

    print(sum(Springboard))

if __name__ == '__main__':
    import io
    import sys
    import math
    import itertools

    # sys.stdin = io.StringIO(_INPUT)
    main()

Measured memory_bytes: 104012
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
long long a[55],b[55],c[55],d[55];
int vis[55];
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i = 1;i <= n;i++){
		scanf("%lld %lld",&a[i],&b[i]);
	}
	for(int i = 1;i <= m;i++){
		scanf("%lld %lld",&c[i],&d[i]);
	}
	long long p;
	for(int i = 1;i <= n;i++){
	long long temp=300000001;
		for(int j = 1;j <= m;j++){
			p=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(p<temp) 
			{
				temp=p;
				vis[i]=j;
			}
		}
	}
	for(int i = 1;i <= n;i++){
		printf("%d\n",vis[i]);
	}
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int A, B, C;
  	std::cin >> A >> B >> C;
  	if(A == B){
      std::cout << C;
    }else if(B == C){
      std::cout << A;
    }else{
      std::cout << B;
    }
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>  // std::accumulate(m.begin(), m.end(), 0LL);
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int H, W; std::cin >> H >> W;
  std::vector< std::vector<char> > S(H, std::vector<char>(W));
  for(int i=0; i<H; i++) for(int j=0; j<W; j++) std::cin >> S[i][j];
  
  std::vector<std::vector<int>> ans(H, std::vector<int>(W,0));
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      if ( S[i][j] == '#' ) {
        if ( i-1>=0 ) ans[i-1][j]   += 1;
        if ( i-1>=0 && j-1>=0 ) ans[i-1][j-1] += 1;
        if ( i-1>=0 && j+1<W ) ans[i-1][j+1] += 1;
        if ( j-1>=0 ) ans[i][j-1]   += 1;
        if ( j+1<W ) ans[i][j+1]   += 1;
        if ( i+1<H ) ans[i+1][j]   += 1;
        if ( i+1<H && j+1<W ) ans[i+1][j+1] += 1;
        if ( i+1<H && j-1>=0 ) ans[i+1][j-1] += 1;
      }
    }
  }

  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      if ( S[i][j] == '#' ) std::cout << S[i][j];
      else std::cout << ans[i][j] ;
    }
    std::cout << std::endl;
  }
  std::cout << std::endl;
  return 0;
}


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

int main(void){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> jobs(n);
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        jobs[i] = make_pair(a,b);
    }
    sort(jobs.begin(), jobs.end());
    reverse(jobs.begin(),jobs.end());

    priority_queue<int> pq;
    ll ans = 0;
    for(int i=1;i<=m;i++){
        while(jobs.size()>0 && jobs.back().first==i){
            pair<int,int> p = jobs.back();
            pq.push(p.second);
            jobs.pop_back();
        }
        if(!pq.empty()){ans += pq.top(); pq.pop();}
    }
    cout << ans << endl;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;

char b;

int main(){
  cin >> b;
  char ans;
  if(b=='A')ans='T';
  else if(b=='T')ans = 'A';
  else if(b=='C')ans = 'G';
  else if(b=='G')ans = 'C';
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  ll n,k; cin>>n>>k;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];

  // 数列Aの中で、各項の転倒数がいくつあるかを考える
  vector<vector<ll> > cnt;
  rep(i,n){
    vector<ll> c; c.PB(0); c.PB(0); cnt.PB(c);
  }
  rep(i,n){
    for(int j=i; j<n; j++){
      if(a[i]>a[j]) cnt[i][0]++; // A内の転倒数の数
    }
  }
  rep(i,n){
    rep(j,n){
      if(a[i]>a[j]) cnt[i][1]++; // A内に自分より小さい数が何個
    }
  }

  ll ans=0;
  rep(i,n){
    ans += (cnt[i][0]*k)%MOD;
    ans %= MOD;
  }
  rep(i,n){
    ll p = (k*(k-1)/2)%MOD;
    ans += (p*cnt[i][1])%MOD;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>

int a[999999];
int b[999999];

int prime(int x) {
	if (a[x] == 1) return 1;
	else if (a[x] == 2) return 0;
	for (int i = 2; i < sqrt(x) + 1; i++) {
		if (x%i == 0) {
			a[x] = 2;
			return 0;
		}
	}
	return a[x]=1;
}
int main(){
	int n;
	b[0] = 0;
	b[1] = 0;
	b[2] = 1;
	a[0] = 2;
	a[1] = 2;
	a[2] = 1;
	int count = 1;
	for (int i = 3; i <= 999999; i++) {
		if (prime(i))count++;
		b[i] = count;
	}
	while (scanf("%d", &n) != EOF){
		printf("%d\n", b[n]);
	}
	return 0;
}

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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const double PI = acos(-1);
const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int main() {
    int N;
    string S;
    cin >> N >> S;

    vector<int> a(N);
    REP(i, N) {
        if (S[i] == 'R') a[i] = 0;
        if (S[i] == 'G') a[i] = 1;
        if (S[i] == 'B') a[i] = 2;
    }
    vector<ll> cnt(3);
    REP(i,N) cnt[a[i]]++;

    ll ans = 1;
    REP(i, 3) ans *= cnt[i];
    REP (i, N) {
        FOR (j, i, N) {
            int k = 2 * j - i;
            if (k < N) {
                if (a[i] == a[j]) continue;
                if (a[j] == a[k]) continue;
                if (a[i] == a[k]) continue;
                ans--;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3616
#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;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	int n, nq;
	cin >> n >> nq;
	
	vi c(n);
	for(int& x : c)cin >> x;
	
	vi lastSeen(n+1, -1);
	
	vvi q(n+1);
	map<int, pii> mp;
	int l, r;
	for(int i=0 ; i<nq ; ++i){
		cin >> l >> r;
		--l, --r;
		q[l].pb(r);
		mp[i] = {l, r};
	}
	
	oset<int> os;
	map<pii, int> ans;
	for(int i=n-1 ; i>=0 ; --i){
		if(lastSeen[c[i]] == -1){
			lastSeen[c[i]] = i;
			os.insert(i);
		}
		else{
			os.erase(os.find(lastSeen[c[i]]));
			lastSeen[c[i]] = i;
			os.insert(i);
		}
		for(int& to : q[i]){
			ans[{i, to}] = os.order_of_key(to+1);
		}
	}
	
	for(auto it : mp){
		cout << ans[it.second] << '\n';
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cout << fixed << setprecision(10);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}


Measured memory_bytes: 114432
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll t,x;
    cin>>t>>x;
    double d=t/double(x);
    cout<<d<<endl;
    
}
return 0;
}

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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

long long int dp[3][100000];
vector< tuple<int, int, int> > v(100000);
int n;
long long int chooseA(int i);
long long int chooseC(int i);

long long int chooseB(int i) {
	cout << "B -> " << get<1>(v[i]) << endl;
	if(i == n-1) return get<1>(v[i]);
	return max(chooseA(i+1), chooseC(i+1)) + get<1>(v[i]);
}

long long int chooseA(int i) {
	cout << "A -> " << get<0>(v[i]) << endl;
	if(i == n-1) return get<0>(v[i]);
	return max(chooseB(i+1), chooseC(i+1)) + get<0>(v[i]);
}

long long int chooseC(int i) {
	cout << "C -> " << get<2>(v[i]) << endl;
	if(i == n-1) return get<2>(v[i]);
	return max(chooseA(i+1), chooseB(i+1)) + get<2>(v[i]);
}

int main()
{
	fastio;
	cin >> n;
	for(int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			v[i] = {a, b, c};
	}	
//	cout << max({chooseA(0), chooseB(0), chooseC(0)}) << endl;
//	exit(0);
	
	dp[0][0] = get<0>(v[0]);
	dp[1][0] = get<1>(v[0]);
	dp[2][0] = get<2>(v[0]);
	
	for(int i = 1; i < n; i++) {
		dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + get<0>(v[i]);
		dp[1][i] = max(dp[0][i-1], dp[2][i-1]) + get<1>(v[i]);
		dp[2][i] = max(dp[0][i-1], dp[1][i-1]) + get<2>(v[i]);
		//cout << dp[0][i] << " " << dp[1][i] << " " << dp[2][i] << endl;
	}
	
	cout << max({dp[0][n-1], dp[1][n-1], dp[2][n-1]}) << endl;
	return 0;
}

Measured memory_bytes: 6604
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,k; cin>>n>>k;
    int ans=n;
    set<int> se;
    rep(i,k){
        int d; cin>>d;
        se.insert(d);
    }
    while(1){
        string s=to_string(ans);
        int cnt=0;
        for(auto ch:s)if(se.count(ch-'0')) cnt++;
        if(cnt==0) break;
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
##############################################
import sys
N, M = list(map(int, input().split()))
digits = [-1] * N
for _ in range(M):
    s, c = list(map(int, input().split()))
    s -= 1

    if digits[s] == -1 or (digits[s] != 1 and digits[s] == c):
        digits[s] = c
    else:
        print(-1)
        sys.exit(0)

if digits == [-1]:
    print(0)
    sys.exit(0)
    
if digits[0] == 0 and N != 1:
    print(-1)
    sys.exit(0)


n = 0
base = 1
for i in reversed(range(N)):
    if digits[i] != -1:
        n += base * digits[i]
    elif i == 0 and digits[i] == -1:
        n += base
    base *= 10

print(n)


Measured memory_bytes: 61812
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int ans = 0;
        ans = (n + (d * 2 + 1) -1) / (d * 2 + 1);
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  for(int i = 0; i<s.size(); i++)
  {
  		if(s[i]==',')
        {
			cout<<" ";
			continue;
        }
        cout<<s[i];
  }
  return 0;
}


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

int main(){
    int H, W;
    cin >> H >> W;
    string S[400];
    for(int i=0; i<H; i++) cin >> S[i];

    bitset<400> visited[400];
    const int dx[] = {-1, 1, 0, 0};
    const int dy[] = {0, 0, -1, 1};

    int64_t ans = 0;


    for(int i=0; i<H; i++) for(int j=0; j<W; j++){
        if(visited[i][j]) continue;
        visited[i][j] = true;
        vector<int64_t> num(2, 0);
        queue<pair<int, int>> que;
        que.push({i, j});

        while(que.size()){
            auto p = que.front(); que.pop();
            int x = p.first, y = p.second;
            num[S[x][y] == '#']++;

            for(int k=0; k<4; k++){
                int x2 = x + dx[k];
                int y2 = y + dy[k];
                if(x2 >= 0 && x2 < H && y2 >= 0 && y2 < W && !visited[x2][y2] && S[x][y] != S[x2][y2]){
                    que.push({x2, y2});
                    visited[x2][y2] = true;
                }
            }
        }
        ans += num[0] * num[1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
inline void write(int x)
{
    if(x<0)
	{
    	putchar('-');
		x=-x;
	}
    if(x>9)
		write(x/10);
    putchar(x%10+'0');
}
int a[200005];
int main()
{
	ios::sync_with_stdio(false);
	bool f=0;
	int n,l;
	n=read();
	for(register int i=1;i<=n;i++)
		a[i]=read();
	l=n;
	while(n--)
	{
		if(l<=0)
		{
			f=1;
			if(l==0) l--;
			else l++;
		}
		if(f) l+=2;
		write(a[l]);
		putchar(' ');
		if(!f) l-=2;
	}
	puts("");
	return 0;
}


Measured memory_bytes: 2944
#include <stdio.h>
int main(){
	
	char num[10];
	scanf("%s" , num);
	
	if (num[1] == 'B'){
		num[1] = 'R';
		printf("%s" , num);
	}
	else{
		num[1] = 'B';
		printf("%s" , num);
	}
	return 0;
}

Measured memory_bytes: 1712
N,x = gets.strip.split.map(&:to_i)
data = gets.strip.split.map(&:to_i).sort

if x > data.inject(:+)
  puts N - 1
elsif x == data.inject(:+)
  puts N
elsif x < data.inject(:+)
  cnt = 0
  data.each {|i|
    if i <= x
      cnt += 1
      x = x - i
    end
  }
  puts cnt
end

Measured memory_bytes: 1788
from functools import reduce

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

max_mean = reduce(lambda a, b: a + 0.5 * (b + 1), p[:k], 0)
cur = max_mean
for i in range(k, n):
    cur += (0.5 * (p[i] - p[i - k]))
    max_mean = max(cur, max_mean)
print(max_mean)


Measured memory_bytes: 25308
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {
//    ios::sync_with_stdio(0);
    string s;
    cin>>s;
    vector<int> vec(26,0);
    for (int i=0; i<s.size(); i++){
        vec[ (int)s[i]-(int)'a' ]++;
    }

    for (int i=0; i<26; i++){
        if (vec[i]==0) {
            cout<<(char) (i+(int)'a');
            return 0;
        }
    }
    cout<<"None";
    return 0;
}


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

using namespace std;


int main(){
    int h,w;
    cin>>h>>w;
    string map[h];
    for(int i=0;i<h;i++){
        cin>>map[i];
    }

    int dx[4]={0,0,1,-1};
    int dy[4]={1,-1,0,0};

    bool ans = true;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            bool found = false;
            if(map[i][j]=='#'){
                for(int k=0;k<4;k++){
                    int nx = i + dx[k];
                    int ny = j + dy[k];
                        if(nx>=0&&nx<h&&ny>=0&&ny<w&&map[nx][ny]=='#'){
                            found = true;
                        }
                }
                if(!found)
                    ans = false;
            }
        }
    }

    if(ans)cout<<"Yes";
    else cout<<"No";

}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long A = sc.nextLong();
		Long B = sc.nextLong();
		int i = 1;
		Long Ai;
		while(true) {
			Ai = (long) (A * i);
			if(Ai % B == 0) {
				break;
			}
			i++;
		}
		System.out.println(Ai);
	}
}

Measured memory_bytes: 29192
import java.util.*;

public class Main {

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

        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();

        long turn = n/(a+b);

        long diff = n-turn*(a+b);

        if (diff>a){
            diff = a;
        }

        System.out.print(turn*a + diff);



    }
}



Measured memory_bytes: 23252
#include<iostream>
#include<string>
using namespace std;
int main(){
        string t,p;
        cin>>t>>p;
        for(int i=0;i+p.size()-1<t.size();i++){
                bool same = true;
                for(int j=0;j<p.size();j++){
                        if(t[i+j]!=p[j]) {
                                same = false;
                                break;
                        }
                }
                if(same) cout<<i<<endl;
        }
        return 0;
}


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

int main() {
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  double cx = w / 2.0;
  double cy = h / 2.0;

  cout << w * h / 2.0 << " " << ((cx == x && cy == y) ? 1 : 0) << endl;
}

Measured memory_bytes: 256
function main(input) {
    var array = input.split(' ');
    var sortedArray = array.sort(compareNumbers);
    var counter = 0;

    for(var i = 1; i < sortedArray.length; i++){
        counter += sortedArray[i] - sortedArray[i-1];
    }
    console.log(counter);
}

function compareNumbers(a, b) {
    return a - b;
  }

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include<iostream>
using namespace std;
int main(){

int n;
cin>>n;
if(n<3)
    cout<<1<<endl;
for(int i=1;i<n;i++)
{
    if(i*i>n)
    {
        cout<<(i-1)*(i-1)<<endl;
        return 0;
    }
}
return 0;
}


Measured memory_bytes: 256
<?php


$input = explode(" ", trim(fgets(STDIN)));  

// $input = array(99, 0); //N K
// var_dump($input);
/*
1からNの間の値が、奇数でJ個あり、J<＝Kである


*/


$N = $input[0];
$K = $input[1];

$maxEvenNum = $N%2 == 0 ? $N-1 : $N;
// var_dump($maxEvenNum);

$J = (($maxEvenNum-1) / 2) + 1;
// var_dump($J);

if($K <= $J) {
	print 'YES';
} else {
	print 'NO';
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    vector<int> cnt(41);
    rep(i, n){
        rep(j, 41){
            if(1 & (a[i] >> j))cnt[j]++;
        }
    }
    vector<bool> one(41);
    rep(i, 41)if(cnt[i] <= n / 2)one[i] = true;

    ll x = 0;
    ll p = pow((ll)2, 40);
    for(int i = 40; i >= 0; i--){
        if(one[i] && x + p <= k)x += p;
        p /= 2;
    }
    ll ans = 0;
    rep(i, n)ans += x ^ a[i];
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
using std::sort;
using std::swap;

int N, D;
struct Name{
    char s[20];
    bool operator<(const Name &b)const{
        for(int i=0;;i++){
            if(b.s[i] == '\0') return true;
            if(s[i] == '\0') return false;
            if(s[i] < b.s[i]) return true;
            if(s[i] > b.s[i]) return false;
        }
    }
}name[300];

bool comp(Name a, Name b){
    for(int i=0;;i++){
        if(b.s[i] == '\0') return false;
        if(a.s[i] == '\0') return true;
        if(a.s[i] < b.s[i]) return true;
        if(a.s[i] > b.s[i]) return false;
    }
}

bool distance(int a, int b, int x, int y, int d){
    if(d > D) return false;
    if(name[a].s[x]=='\0' && name[b].s[y]=='\0') return true;
    if(name[a].s[x] == '\0') return distance(a, b, x, y+1, d+1);
    if(name[b].s[y] == '\0') return distance(a, b, x+1, y, d+1);
    if(name[a].s[x] == name[b].s[y]) return distance(a, b, x+1, y+1, d); //always best
    if(distance(a, b, x+1, y, d+1)) return true; //del a[x]->x++ or Insert b[y]
    if(distance(a, b, x, y+1, d+1)) return true; //del b[y]->y++ or Insert a[x]
    if(distance(a, b, x+1, y+1, d+1)) return true; //Replacing
    if(name[a].s[x+1]!='\0'){
        swap(name[a].s[x], name[a].s[x+1]);
        if(distance(a, b, x, y, d+1)){
            swap(name[a].s[x], name[a].s[x+1]);
            return true;
        }
        swap(name[a].s[x], name[a].s[x+1]);
        //swap a a+2 ans delete a+1...
        if(name[a].s[x+2]!='\0'){
            swap(name[a].s[x], name[a].s[x+2]);
            char tmp = name[a].s[x+1];
            int i;
            for(i=x+2;name[a].s[i-1]!='\0';i++) name[a].s[i-1] = name[a].s[i];
            bool res = distance(a, b, x, y, d+2);
            for(;i>x;i--) name[a].s[i] = name[a].s[i-1];
            name[a].s[x+1] = tmp;
            swap(name[a].s[x], name[a].s[x+2]);
            return res;
        }
    }
    return false;
}
int main(){
    while(scanf("%d %d", &N, &D) && N){
        for(int i=0;i<N;i++)
            scanf("%s", name[i].s);
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(!comp(name[i], name[j]) )
                    swap(name[i], name[j]);
            }
        }
        int res = 0;
        for(int i=N-1;i>=0;i--){
            for(int j=i-1;j>=0;j--){
                if(distance(i, j, 0, 0, 0)){
                    printf("%s,%s\n", name[i].s, name[j].s);
                    res++;
                }
            }
        }
        printf("%d\n", res);
    }
    return 0;
}

Measured memory_bytes: 1036
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main() {
	int n;
	cin >> n;
	int p[10];
	int ma = 0;
	int sum = 0;
	rep(i, n) {
		cin >> p[i];
		ma = max(ma, p[i]);
		sum += p[i];
	}
	cout << sum - ma / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define ld long double
#define PB push_back
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define pii pair <int , int>
#define pll pair <long long , long long>
#define FAST ios::sync_with_stdio(false);cin.tie(0);
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

const ll maxn = 2e5 + 10 , N = 60000 + 20 , mod = 1e9 + 7 , INF = 1e9 , lg = 32;

int main() {
    FAST
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < 3; ++i) {
        for (int j = i; j < 3; ++j) {
            int maxi = 0;
            for (int t = i; t <= j; ++t) {
                if(s[t] == 'S') {
                    maxi = 0;
                    break;
                }
                maxi++;
            }
            ans = max(ans , maxi);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 1010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[101010];
ll d[101];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n,k;
	cin >> n >> k;
	rep(i, k) {
		cin >> d[i];
	}
	for (ll i = n;i <= 101010;++i) {
		vector<ll>res;
		ll j = i;
		while (j > 0) {
			res.push_back(j % 10);
			j /= 10;
		}
		bool flag = true;
		rep(m, res.size()) {
			rep(l, k) {
				if (res[m] == d[l])flag = false;
			}
		}
		if (flag) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


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

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

int gcd(int a, int b) {
  if(a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

vector<vector<int>> all_comb(int n, int k) {
  vector<vector<int>> combs(nCr(n, k), vector<int>(k));
  for(int i=0; i<k; i++) {
    combs[0][i] = i;
    combs[1][i] = i;
  }
  
  for(long i=1; i<nCr(n, k); i++) {
    int p = 1;
    while(combs[i][k - p] == n - p) {
      p++;
      if(p > k) {
        break;
      }
    }
    combs[i][k - p]++;
    int q = combs[i][k - p];
    for(int j=1; j<p; j++) {
      combs[i][k - p + j] = q + j;
    }

    if(i < nCr(n, k) - 1) {
      for(int j=0; j<k; j++) {
        combs[i + 1][j] = combs[i][j];
      }
    }
  }

  return combs;
}

int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;

  int count = 1;
  int ans = 0;
  for(int i=0; i<n; i++) {
    int a;
    cin >> a;
    if(a == count) {
      count++;
    }
    else {
      ans++;
    }
  }

  if(count == 1) {
    cout << -1 << endl;
  }
  else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 3556
MOD = int(1e9+7)


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    cnt = [0] * 2001
    used = [0] * 2001
    for a in A:
        cnt[a] += 1
    ans = 0
    for a in A:
        c = 0
        u = 0
        for i in range(1, a):
            c += cnt[i]
            u += used[i]
        begin = c * K - u
        last = c - u
        tmp = (begin + last) * K // 2
        ans = (ans + tmp) % MOD
        used[a] += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 39664
A,B,C,K = map(int, input().split())

s = K - A
m = 0
if s >= 0:
  m += A
else:
  print(K)
  exit()
if s - B >= 0:
  s -= B
else:
  print(m)
  exit()
if s - C >= 0:
  print(m + (-C))
else:
  print(m - s)

Measured memory_bytes: 9128
W, a, b = map(int, input().strip().split())
l, r = a + W, b + W
if a <= b:
	diff = b - l
	if diff > 0:
		print(diff)
	else:
		print(0)
else:
	diff = a - r
	if diff > 0:
		print(diff)
	else:
		print(0)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
int main() {
	int a,b,i,x=0,y=0,f=0;
	string s;
	cin >> a >> b >> s;
	for(i=0;i<s.size();i++) {
		if(s[i]=='-')
			f=1;
		else if(f==0)
			x++;
		else
			y++;
	}
	if(x==a && y==b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
  int w,h,x,y;
  cin >> w >> h >> x >> y; 
  if((double)w/2==x&&(double)h/2==y) printf("%.10lf 1\n",(double)w*h/2);
  else printf("%.10lf 0\n",(double)w*h/2);
}

Measured memory_bytes: 256