akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include <algorithm>
#include <functional>

using namespace std;

int main (void){
    int N,K,temp;
    long long int attack = 0;
    long long int sum = 0;
    vector< long long int> H;
    cin >> N;
    cin >> K;
    for(int i=0; i < N;i++){
        cin >> temp;
        H.push_back(temp);
    }
    sort(H.begin(),H.end(),greater<int>());
    if(N>K){
        for(int i = K ; i < N ; i++){
            sum += H[i];
        }
        attack = sum;
    }
    else{
        attack = 0;
    }
    cout << attack;
    return 0; 
}

Measured memory_bytes: 2420
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//		String W	 = in.readLine();
		//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int K = sc.nextInt();

		int[] A = new int[N + 1];
		int[] d = new int[K];
		Arrays.fill(A, 0);
		A[0]=100;

		for (int i = 0; i < K; i++) {
			d[i] = sc.nextInt();
			for (int j =0; j < d[i]; j++) {
				A[sc.nextInt()]++;
			}
		}
		int ans = 0;
		for (int i = 1; i <= N; i++) {
			if (A[i] == 0) {
				ans++;
			}
		}
		System.out.println(ans);

	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray) {
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedArray[mid] <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList) {
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedList.get(mid) <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}

}


Measured memory_bytes: 46668
#![allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

fn euk(a: usize, b: usize) -> usize {
   if b == 0 {
      a
   } else {
      euk(b, a % b)
   }
}

#[fastout]
fn main() {
   input! {
      a: usize,
      b: usize,
   }

   let mut m = euk(a, b);
   let mut primes = vec![1];
   for i in 2.. {
      if i * i > m {
         break;
      }
      if m % i == 0 {
         primes.push(i);
         while m % i == 0 {
            m /= i;
         }
      }
   }
   if m != 1 {
      primes.push(m);
   }
   let ans = primes.len();
   println!("{}", ans);
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] x = new int[m];
		int[] r = new int[m - 1];
		int ans = 0;

		for (int i = 0; i < m; i++) {
			x[i] = sc.nextInt();
		}
		
		Arrays.sort(x);
		
		for (int i = 0; i < m - 1; i++) {
			r[i] = x[i + 1] - x[i];
		}
		
		Arrays.sort(r);
		
		for (int i = m - 2 - (n - 1); i >= 0; i--) {
			ans += r[i];
		}

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 59408
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long a,i,c,n,s=0;
  cin>>n;
  long long A[n];
  for(i=0;i<n;i++)
  cin>>A[i];
  sort(A,A+n);
  for(i=0;i<n-1;i++)
  {
    s+=abs(A[i]-A[i+1]);
  }
cout<<s<<endl;
 return 0;

}


Measured memory_bytes: 3612
import sys
def main():
    k = int(input())

    a =7%k
    if a == 0:
        print(1)
        sys.exit()

    for i in range(2,10**7):
        a = (10*a+7) % k
        if a == 0:
            print(i)
            sys.exit()

    print(-1)
    
main()

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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    vector<int>v(5);
    cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4];
    for(int i=0; i<5; ++i)
    {
        if(v[i] == 0)
        {
            cout<<i+1<<endl;break;
        }
    }

    return 0;
}


Measured memory_bytes: 3596
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n = input()
    print('ABC'+n)
    return

if __name__=='__main__':
    main()


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

int main(){
  ll n,t=0;
  bool flag=true;
  cin >> n;
  vector<vector<ll>> v(n,vector<ll>(2,0));
  r(i,n)cin >> v[i][1]>>v[i][0];
  sort(v.begin(),v.end());
  r(i,n){
    t+=v[i][1];
    if(v[i][0]<t)flag=false;
  }
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 11136
N = int(input())
S = str(input())
s = len(S)
alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(s):
  for j in range(26):
    if S[i] == alp[j]:
      S += alp[j+N]
print(S[s:len(S)])


Measured memory_bytes: 3060
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        if (a < 10 && b < 10){
            System.out.println(a * b);
        }else{
            System.out.println(-1);
        }
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 1;
    rep(i,n){
        if (ans * 2 > ans + k)  ans += k;
        else ans *= 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>

#define INF 2'000'000'001

using namespace std;

int main() {
  int L, R;
  cin >> L >> R;
  if (ceil((double)L / 2019) <= (R / 2019)) {
    printf("0\n");
  } else {
    int res = INF;
    for (int i = L % 2019; i < R % 2019; ++i) {
      for (int j = L % 2019 + 1; j < R % 2019 + 1; ++j) {
        res = min(res, (i * j) % 2019);
      }
    }
    printf("%d\n", res);
  }
}

Measured memory_bytes: 3256
n,a,b=map(int, input().split())
ans=[]

def digitSum(i):
  s = str(i)
  array = list(map(int, s))
  return sum(array)

for i in range(1,n+1):
  if a<=digitSum(i)<=b:
    ans.append(i)

print(sum(ans))

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

int main(){
	int K;
	cin >> K;
	int A[K];
	for(int i=0; i<K; i++) cin >> A[i];
	ll min = 2, max = 2;
	for(int i=K-1; i>=0; i--){
		ll a = (min+A[i]-1)/A[i] , b = max/A[i];
		a *= A[i], b = (b+1) * A[i] - 1;
		if(a > max){ cout << -1 << endl; return 0; }
		min = a, max = b;
	}
	cout << min << " " << max << endl;
	return 0;
}

Measured memory_bytes: 640
# atcoder : python3 (3.4.3)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9+7

# main
N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))

ans = 0
for i in range(N):
    ans = max(ans, sum(A1[0:i+1])+sum(A2[i:]))

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n, l;

	while(scanf("%d%d", &n, &l)==2)
	{
		int ans=(n-1)*n/2+n*l;

		if(l>0) ans-=l;
		if(l+n-1<0) ans-=l+n-1;
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long a,b;
    cin >> a >> b;
 
    long long tmp;
 
    if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  long long r;
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  long long gcd = b;
  //vector<int> x(gcd + 1);
 
  long long count=0;
  long long num = gcd;
 
  //cout << num << endl;
 
  
  for (int i = 2; i <= sqrt(gcd); i++) {
      int judge = 0;
      while (num%i == 0) { // 素数で割り切れなくなるまで割っていく
			//x.at(i)++;　//割った個数を配列に足す
			num /= i;
            judge += 1;
      }
      if(judge != 0){
          count += 1;
      }

      
 
  }
  if(num != 1){
    cout << count+2 << endl;
  }
  else{
    cout << count+1 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
    int x,t;cin>>x>>t;
    if(x-t<0)cout << 0 << endl;
    else cout << x-t << endl;
    

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

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

    public static void main(String[]$) {
        long n = scanner.nextLong();
        long ans = 0;
        for (long i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                long m1 = i - 1;
                if (i != 1 && n / m1 == n % m1) {
                    ans += m1;
                }
                long m2 = n / i - 1;
                if (i * i != n && n / m2 == n % m2) {
                    ans += m2;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

int main(void) {
	int a, b, b1;//b1代替b运算
	int carry = 1;

	cin >> a >> b;
	b1 = b;
	while (b1) {
		b1 /= 10;
		carry *= 10;
	}

	int sum = a * carry + b;
	double k = sqrt(sum);
	if (floor(k) == ceil(k)) printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 256
int main(){
    int x, y, i;
    while(1 == 1){
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0) return 0;
        if(x  > y){
            int n = x;
            x = y;
            y = n;
            printf("%d %d\n", x, y);
            
        }else{
            printf("%d %d\n", x, y);
        }
    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <tuple>

using namespace std;

const int INF = 1 << 30;

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

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

    vector<string> S(H);
    for (auto& s : S) cin >> s;

    int sx, sy;
    for (int x = 0; x < H; ++x) {
        for (int y = 0; y < W; ++y) {
            if (S[x][y] == '%') {
                sx = x;
                sy = y;
            }
        }
    }

    queue<pair<int, int>> que;
    que.emplace(sx, sy);
    vector<vector<int>> dist(H, vector<int>(W, INF));
    dist[sx][sy] = 0;

    while (!que.empty()) {
        int x, y;
        tie(x, y) = que.front();
        que.pop();

        for (int i = 0; i < 4; ++i) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || H <= nx || ny < 0 || W <= ny ||
                S[nx][ny] == '#' || dist[nx][ny] < INF) continue;

            dist[nx][ny] = dist[x][y] + 1;
            que.emplace(nx, ny);
        }
    }

    int pri, sol = INF;
    for (int x = 0; x < H; ++x) {
        for (int y = 0; y < W; ++y) {
            if (S[x][y] == '@') {
                pri = dist[x][y];
            } else if (S[x][y] == '$') {
                sol = min(sol, dist[x][y]);
            }
        }
    }

    cout << (pri < sol ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
int main(){
    int S=0;
    long long N=0,K=0,tt=0,ans=1,min=10000000;
    cin>>N>>K;

    vector<int> rrr(N);

    for(int i=0;i<N;i++){
        cin>>rrr[i];
    }

    ans+=(N-K)/(K-1);
    if((N-K)%(K-1)>0){
        ans++;
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 640
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = np.array([list(sr()) for _ in range(H)])
black = S == '#'
is_ok = np.zeros_like(S, dtype=np.bool)
is_ok[1:, :] |= black[:-1, :]
is_ok[:-1, :] |= black[1:, :]
is_ok[:, 1:] |= black[:, :-1]
is_ok[:, :-1] |= black[:, 1:]
impossible = (black & (~is_ok)).any()
print('No' if impossible else 'Yes')


Measured memory_bytes: 14488
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n,h,w;

signed main(){

    in(n,h,w);
    out((n-h+1)*(n-w+1));

    return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    int a[N], b[N];
    int c[M], d[M];
    for(int i = 0; i < N; ++i){
        cin >> a[i] >> b[i];
    }

    for(int i = 0; i < M; ++i){
        cin >> c[i] >> d[i];
    }

    
    for(int i = 0; i < N; ++i){
        int ans = 0;
        int minD = INT_MAX;
        for(int j = 0; j < M; ++j){
            int delta = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(delta < minD){
                minD = delta;
                ans = j+1;
            }
        }
        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)

#include <atcoder/all>
using namespace atcoder;

template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) cerr << #OBJ << ": "; CERR(OBJ); cerr << "\n"

template <typename T, typename ...Ts> void CERR(const T &FIRST, const Ts &...REST) { CERR(FIRST); cerr << ", "; CERR(REST...); }
#define dbs(...) cerr << "(" << #__VA_ARGS__ << "): ("; CERR(__VA_ARGS__); cerr << ")\n"

// 頂点(i,j)(0<=i<N,0<=j<M)を整数 i*M+j で表す
// N*M(from)->{(i,j)|(i+j)mod2=0}->{(i,j)|(i+j)mod2=1}->N*M+1(to)

vi di = { 1, 0, -1, 0 }, dj = { 0, 1, 0, -1 };

int main() {
	int N, M; cin >> N >> M;
	vector<string> S(N); rep(i, N) cin >> S[i];
	mf_graph<int> g(N * M + 2);
	rep(i, N) rep(j, M) {
		if (S[i][j] == '#') continue;
		if ((i + j) % 2 == 0) {
			g.add_edge(N * M, i * M + j, 1);
			rep (dir, 4) {
				int ni = i + di[dir], nj = j + dj[dir];
				if (ni < 0 or N <= ni or nj < 0 or M <= nj) continue;
				if (S[ni][nj] == '.') g.add_edge(i * M + j, ni * M + nj, 1);
			}
		} else {
			g.add_edge(i * M + j, N * M + 1, 1);
		}
	}

	cout << g.flow(N * M, N * M + 1) << endl;
	vector<string> T = S;

	for (auto e : g.edges()) {
		if (e.from == N * M or e.to == N * M + 1) continue;
		if (e.flow == 0) continue;
		int i = e.from / M, j = e.from % M;
		int ni = e.to / M, nj = e.to % M;
		// dbs(e.from, e.to, e.cap, e.flow); dbs(i, j, ni, nj);

		if (i == ni) {
			if (j < nj) {
				T[i][j] = '>';
				T[i][nj] = '<';
			} else if (nj < j) {
				T[i][nj] = '>';
				T[i][j] = '<';
			}
		} else if (j == nj) {
			if (i < ni) {
				T[i][j] = 'v';
				T[ni][j] = '^';
			} else if (ni < i) {
				T[ni][j] = 'v';
				T[i][j] = '^';
			}
		}
	}
	rep(i, N) cout << T[i] << endl;
}

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

const int N = 1010;
int sum[13][N];
char s[13][N];

int main()
{
	int h,w,k;
	scanf("%d%d%d",&h,&w,&k);
	for(int i=1;i<=h;i++){
		scanf("%s",s[i]+1);
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			sum[i][j] = sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			if(s[i][j]=='1'){
				sum[i][j]++;
			}
		}
	}
	int ans = 2000;
	for(int i=0;i<(1<<(h-1));i++){
		vector<int>r;
		r.push_back(0);
		for(int j=0;j<=h-1;j++){
			if((i>>j)&1){
				r.push_back(j+1);
			}
		}
		r.push_back(h);
		bool flag = true;
		int ext = 0;
		for(int i=0;i<w;){
			ext++;
			for(int sz=r.size(),j=1;j<sz;j++){
				int t1 = r[j];
				int t2 = r[j-1];
				int check = sum[t1][i+1]-sum[t1][i]-sum[t2][i+1]+sum[t2][i];
				if(check>k){
					flag = false;
				}
			}
			if(flag==false){
				break;
			}
			int j;
			for(j=i;j<w;j++){
				bool inf = true;
				for(int sz=r.size(),l=1;l<sz;l++){
					int t1 = r[l];
					int t2 = r[l-1];
					int check = sum[t1][j+1]-sum[t1][i]-sum[t2][j+1]+sum[t2][i];
					if(check>k){
						inf = false;
					}
				}
				if(inf==false){
					break;
				}
			}
			i = j;
		}
		if(flag){
			ans = min(ans,ext-1+__builtin_popcount(i));
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 3836
#include <iostream>
using namespace std;   
int main(){
 int A;cin >> A; 
 if (A < 1200){
   cout << "ABC" <<endl;
 }else{
   if (A < 2800){
     cout << "ARC" <<endl;
   }else{
     cout << "AGC" << endl;
   }
 }
}

Measured memory_bytes: 256
tmp = input().split()
A = int(tmp[0])
B = int(tmp[1])
K = int(tmp[2])

if K > A:
    K = K - A
    A = 0

else:
    A = A - K
    K = 0

if K > B:
    B = 0
    
else:
    B = B - K

print(str(A) + " " + str(B))

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		int n = Integer.parseInt(as.next());
		int[] a;
		a = new int[n];
		for(int i=0;i<n;i++){
			a[i]  = Integer.parseInt(as.next());
		}
		int[] t;
		t = new int[n];
		boolean s = true;
		int l = 0;
		if(n%2==0){
			for(int i=0;i<n-1;i+=2){
				t[i] = 0;
				t[i+1]  = 2;
			}
			for(int i=0;i<n;i++){
				t[a[i]] --;
			}
			for(int i=0;i<n;i++){
				if(t[i]<0){
					s = false;
					break;
				}
			}
			if(s){
				l=1;
				for(int i=0;i<n/2;i++){
					l=l*2;
					l=l%1000000007;
				}
			}
		}else{
			t[0] = 1;
			for(int i=1;i<n-1;i+=2){
				t[i] = 0;
				t[i+1]  = 2;
			}
			for(int i=0;i<n;i++){
				t[a[i]] --;
			}
			for(int i=0;i<n;i++){
				if(t[i]<0){
					s = false;
					break;
				}
			}
			if(s){
				l=1;
				for(int i=0;i<(n-1)/2;i++){
					l=l*2;
					l=l%1000000007;
				}
			}
		}
		System.out.println(l);
	}
}

Measured memory_bytes: 32256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
#define INT long long int
#define REP(i,n) for(int(i)=0;(i)<(n);(i)++) 
using namespace std;
const long long INF = numeric_limits<long long>::max();

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main()
{
    INT N,P;
    cin >> N >> P;
    INT limit = (pow(P,(double)1/N));
    //vector <int64_t> divide = divisor(int64_t (P));
    //sort(divide.begin(),divide.end());
    if (N==1){
        cout << P << endl;
        return 0;
    }
    INT tmp;
    INT ans = 0;
   // cout << limit << endl;
    for (int i=1;i<limit+10;i++){
        tmp = (pow(i,N));
   //     printf("%d:%lld,%lld\n",i,tmp,(P%tmp));
        if (P%tmp == 0) ans = i;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(void){
  ll q, h, s, d;
  cin >> q >> h >> s >> d;
  
  ll n;
  cin >> n;

  ll ans = 0;
  
  vector<ll> a = {q*8, h*4, s*2, d};
  sort(a.begin(), a.end());

  ans += a[0] * (n / 2);

  vector<ll> b = {q*4, h*2, s};
  sort(b.begin(), b.end());
  
  ans += b[0] * (n % 2);
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
#define rep(i, s, t) for(int i = (s); i <= (t); i++)
#define dwn(i, s, t) for(int i = (s); i >= (t); i--)

int read() {
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
	return x * f;
}

#define maxn 5010
#define maxm 210
#define LL long long

int n, m, A[maxn], d[maxn][maxm], St[maxm][maxn], top[maxm];
LL add[maxn];

int main() {
	
	n = read(); m = read();
	rep(i, 1, n - 1) A[i] = read();
	rep(i, 1, n) rep(j, 1, m) d[i][j] = read();
	
	LL ans = 0;
	dwn(l, n, 1) {
		LL dis = 0, sum = 0;
		rep(i, 1, m) {
			while(top[i] && d[St[i][top[i]]][i] <= d[l][i]) {
				if(top[i] > 1) add[St[i][top[i]-1]] -= d[St[i][top[i]-1]][i] - d[St[i][top[i]]][i];
				top[i]--;
			}
			St[i][++top[i]] = l;
			if(top[i] > 1) add[St[i][top[i]-1]] += d[St[i][top[i]-1]][i] - d[l][i];
			sum += d[l][i];
		}
		rep(r, l, n) sum += add[r], ans = max(ans, sum - dis), dis += A[r];
	}
	
	printf("%lld\n", ans);
	
	return 0;
}


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

long inf = 1000000007;

  int a[3][3];
 bool A[3][3];
int n;
int b[10];

int main() {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
	}

	cin >> n;

	for (int k = 0; k < n; k++) {
		cin >> b[k];
	}
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			A[i][j] = false;
			for (int k = 0; k < n; k++) {


				if (b[k] == a[i][j]) {
					A[i][j] = true;
				}
			}
		}
	}

	bool jud = false;

	for (int i = 0; i < 3; i++) {
		if (A[i][0] and A[i][1] and A[i][2]) jud = true;
		if (A[0][i] and A[1][i] and A[2][i]) jud = true;
	}
	if (A[0][0] and A[1][1] and A[2][2]) jud = true;
	if (A[2][0] and A[1][1] and A[0][2]) jud = true;

	if (jud) cout << "Yes" << endl;
	else     cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll ar[6],i,j;
	for(i=1;i<=5;i++){
		cin>>ar[i];
	}
	// k=-1;
	for(i=1;i<=5;i++){
		if(ar[i]==0) break;
	}
	cout<<i<<endl;
	return 0;	
}

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

int main() {
  int n,m;
  cin>>n>>m;
  vector<int>ans(m);
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int a;
      cin>>a;
      ans[a-1]++;
    }
  }
  int answer=0;
  for(int i=0;i<m;i++){
    if(ans[i]==n) answer++;
  }
  cout<<answer<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  string S; cin>>S;
  int N=S.size();
  int ans=0;
  string memo="1",X;
  rep(i,0,N){
    X+=S[i];
    if(X!=memo){
      ans++;
      memo=X;
      X="";
    }
  }
  cout<<ans<<endl;
  }



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

int n, c;
int d[33][33] = {0}, col[505][505] = {0}, cnt[33][3] = {0};

int solve();

int main() {
  cin >> n >> c;
  for(int i = 0; i < c; ++i)
    for(int j = 0; j < c; ++j) cin >> d[i][j];
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j) {
      cin >> col[i][j];
      --col[i][j];
      ++cnt[col[i][j]][(i + j + 2) % 3];
    }
  cout << solve() << endl;
  return 0;
}

int solve() {
  int ans = 1000000000;
  for(int t = 0; t < 3; ++t)
    for(int i = 0; i < c; ++i)
      for(int j = 0; j < c; ++j)
        for(int k = 0; k < c; ++k) {
          if(i == j || j == k || k == i) continue;
          int now = 0;
          for(int l = 0; l < c; ++l) {
            now += d[l][i] * cnt[l][0];
            now += d[l][j] * cnt[l][1];
            now += d[l][k] * cnt[l][2];
          }
          ans = min(ans, now);
        }
  return ans;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s;
        while (!(s = scanner.next()).equals("0")) {
            int sum = 0;
            for (int i = 0; i < s.length(); i++) {
                char c = s.charAt(i);
                int d = (c - '0');
                sum += d;
            }
            System.out.println(sum);
        }
    }
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i % 2 == 0 && a[i] % 2 != 0) {
            ++cnt;
        } else if (i == 0 && a[i] % 2 != 0) {
            ++cnt;
        }
    }
    cout << cnt << '\n';
    return 0;
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	set<string> ss;
	rep(i, 0, n) {
		string s; cin >> s; ss.insert(s);
	}cout << ss.size() << endl;
}


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

using namespace std;

const double inf = 1e18;

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

	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	int n;
	cin >> n;

	vector<int> x;
	vector<int> y;
	vector<int> r;
	x.resize(n + 1);
	y.resize(n + 1);
	r.resize(n + 1);
	
	x[0] = sx;
	y[0] = sy;
	r[0] = 0;

	for(int i = 1; i <= n; ++i) {
		cin >> x[i] >> y[i] >> r[i];
	}

	vector<double> dis;
	dis.assign(n + 1, inf);
	dis[0] = 0;

	priority_queue<pair<double, int>, vector<pair<double, int> >, greater<pair<double, int> > > q;
	q.emplace(0, 0);

	auto d = [&] (int sx, int sy, int tx, int ty) {
		return sqrt(1. * (sx - tx) * (sx - tx) + 1. * (sy - ty) * (sy - ty));
	};

	while(!q.empty()) {
		auto p = q.top();
		q.pop();

		int u = p.second;

		if(p.first > dis[u]) {
			continue;
		}

		for(int i = 1; i <= n; ++i) {
			double tmp = dis[u] + max(.0, d(x[u], y[u], x[i], y[i]) - r[u] - r[i]); 

			if(dis[i] > tmp) {
				dis[i] = tmp;
				q.emplace(dis[i], i);
			}
		}
	}

	double ans = inf;

	for(int i = 0; i <= n; ++i) {
		ans = min(ans, dis[i] + max(.0, d(tx, ty, x[i], y[i]) - r[i]));
	}

	cout << fixed << setprecision(15);

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 6388
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

class segtree_min {
public:
	segtree_min(const int N) {
		SIZE = roundup_pow2(N);
		v.clear();
		v.resize(SIZE * 2, 99999999);
	}

	//v[index]=numberとする。
	void update(const int index, const int number) {
		v[index + SIZE] = 99999999;
		for (int i = index + SIZE; i; i = i / 2)v[i] = min(v[i], number);
	}

	//[L,R)の最大値を返す。
	int getmin(const int L, const int R) {
		return getmin_inner(L, R, 1, 0, SIZE);
	}
private:
	int getmin_inner(const int queryL, const int queryR, const int index, const int segL, const int segR) {
		if (queryR <= segL || segR <= queryL)return 99999999;
		if (queryL <= segL && segR <= queryR)return v[index];
		return min(getmin_inner(queryL, queryR, index * 2, segL, (segL + segR) / 2),
			getmin_inner(queryL, queryR, index * 2 + 1, (segL + segR) / 2, segR));
	}

	//x以上であるような2のべき乗数のうち最小のものを返す。
	int roundup_pow2(int x) {
		x--;
		rep(i, 6)x |= x >> (1LL << i);
		return x + 1;
	}

	int SIZE;
	vector<int>v;
};

signed main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<int>a(N);
	segtree_min seg(N);
	rep(i, N) {
		cin >> a[i];
		seg.update(i, --a[i]);
	}
	vector<int>inv_a(N);
	rep(i, N)inv_a[a[i]] = i;

	int ans = 0;
	stack<array<int, 2>>S;
	S.push({ 0,N });
	while (!S.empty()) {
		auto x = S.top(); S.pop();
		if (x[0] == x[1])continue;
		int minnum = seg.getmin(x[0], x[1]);
		int minindex = inv_a[minnum];
		ans += (minnum + 1) * (x[1] - minindex) * (minindex - x[0] + 1);
		S.push({ x[0],minindex });
		S.push({ minindex + 1,x[1] });
	}
	cout << ans << endl;
}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
typedef     unsigned long long  ull;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define yes cout << "YES\n"
#define no cout<<"NO\n"
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
#define MAX 1000005
#define mod 1000000007



int main()
{
 //O_O ;
   dl t;
   cin>>t;
  cout<<2*t*pi<<nn;


    return 0;
}


Measured memory_bytes: 3792
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int t = sc.nextInt();
    int sum = 0;

    for(int i = 1;i * a < t + 0.5;i++) {
      sum += b;
    }

    System.out.println(sum);

  }

}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define endl "\n" 
#define pi acos(-1)
#define ll long long 
using namespace std;
void solve();
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int q=1;//cin>>q;
    while(q--){
        solve();
    }
    return 0;
}
void solve(){
int n;cin>>n;
if(n==1)
cout<<0<<endl;
else
cout<<1<<endl;
}


Measured memory_bytes: 3636
import sys
from collections import namedtuple
from heapq import heappush, heappop


INF = sys.maxsize
Edge = namedtuple('Edge', 'to yen snuuk')
Vertex = namedtuple('Vertex', 'cost id')

n, m, s, t = map(int, input().split())

edges = [[] for _ in range(n + 1)]

for _ in range(m):
  u, v, a, b = map(int, input().split())
  edges[u].append(Edge(v, a, b))
  edges[v].append(Edge(u, a, b))

costs_in_yen = [INF] * (n + 1)
costs_in_snuuk = [INF] * (n + 1)

q = []

heappush(q, Vertex(0, s))
costs_in_yen[s] = 0

while q:
  v = heappop(q)
  if v.cost > costs_in_yen[v.id]:
    continue
  for edge in edges[v.id]:
    if v.cost + edge.yen < costs_in_yen[edge.to]:
      costs_in_yen[edge.to] = v.cost + edge.yen
      heappush(q, Vertex(costs_in_yen[edge.to], edge.to))
      
heappush(q, Vertex(0, t))
costs_in_snuuk[t] = 0

while q:
  v = heappop(q)
  if v.cost > costs_in_snuuk[v.id]:
    continue
  for edge in edges[v.id]:
    if v.cost + edge.snuuk < costs_in_snuuk[edge.to]:
      costs_in_snuuk[edge.to] = v.cost + edge.snuuk
      heappush(q, Vertex(costs_in_snuuk[edge.to], edge.to))      

# n 年後の手持ち snuuk の最大額
snuuk_in_hand = [0] * (n + 1)

for i in range(n - 1, -1, -1):
  snuuk_in_hand[i] = max(
    snuuk_in_hand[i + 1],
    10**15 - costs_in_yen[i + 1] - costs_in_snuuk[i + 1]
  )

for i in range(0, n):
  print(snuuk_in_hand[i])  

Measured memory_bytes: 129516
#include <iostream>
#include<cstdio>
 
using namespace std;
 
int main()
{
    double a, b, c, d, e, f, tmp, s, t;
     
    while((cin >> a >> b >> c >> d >> e >> f)){
        tmp = (a*e-b*d);
        s = ((e*c-b*f)/tmp);
        t = ((a*f-d*c)/tmp);
         
        if(s == -0.0){
            s = 0.0;
        }
        if(t == -0.0){
            t = 0.0;
        }
        printf("%.3f %.3f\n", s, t);
    }
     
    return 0;
}

Measured memory_bytes: 1236
import java.util.*;

class Main{
	public static void main(String[] $) throws Exception{
		Scanner s=new Scanner(System.in);
		String c='>'+s.next()+'<';
		int n=c.length()-1;

		long[]a=new long[n];
		Arrays.fill(a,-1);
		for(int i=0;i<n;++i)
			if(c.substring(i,i+2).equals("><"))
				a[i]=0;
		for(int i=1;i<n;++i)
			if(c.charAt(i)=='<')
				a[i]=a[i-1]+1;
		for(int i=n-2;i>=0;--i)
			if(c.charAt(i+1)=='>')
				a[i]=Math.max(a[i],a[i+1]+1);
		System.out.println(Arrays.stream(a).sum());
	}
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll ten = 0;
    REP(i, N){
    	REP(j, N){
    		if(i<j && A[i] > A[j]) ten++;
    	}
    }

    vector<ll> cnt(N, 0);
    REP(i, N){
    	REP(j, N){
    		if(A[i] < A[j]) cnt[i]++;
    	}
    }

    ll yoko = 0;
    REP(i, N){
    	ll tmp = K*(K-1)/2;
    	tmp %= mod;
    	tmp *= cnt[i];
    	tmp %= mod;
    	yoko += tmp;
    	yoko %= mod;
    }

    ten *= K;
    ten %= mod;

    cout << (ten + yoko)%mod <<endl;

    //dump(ten)
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
	int A,B,C;
    cin>>A>>B>>C;

    if(B-A==C-B){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 3624
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class D
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var dict = new Dictionary<int, int>();
            foreach (var a in A)
            {
                if (dict.ContainsKey(a)) dict[a]++;
                else dict[a] = 1;
            }
            var over = 0;
            foreach (var x in dict)
            {
                over += x.Value - 1;
            }
            var answer = dict.Keys.Count();
            if (over % 2 == 1) answer--;
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 39840
#include<bits/stdc++.h>
using namespace std;
#define int long long 

struct edge{ int from,to,cost;};

int N,M;

const int INF = 1LL << 60;

int d[2020];

edge E[2020];

void Bellmanford(const int &a){
  
  for(int i = 0; i < N; i++){
    d[i] = INF;
  }
  
  d[a] = 0;
  
  for(int k = 0; k < N; k++){
    
    bool update = false;
    
    for(int i = 0; i < M; i++){ 
    
    if( d[E[i].from] != INF && d[E[i].to] > d[E[i].from]+E[i].cost ){
      d[E[i].to] = d[E[i].from]+E[i].cost;
      update  = true;
    }
  }
  
    if(update && k == N-1){ 
      cout << "NEGATIVE CYCLE" << endl; 
      exit(0);
    }
    
  }
  
  for(int i = 0; i < N; i++){ 
    int res = d[i];
    if(res == INF){ cout << "INF" << endl;}
    else{ cout << res << endl;}
  }
 
  return ;
}
    
    

signed main(void){
  
  int r; 
  
  cin >> N >> M >> r;
  
  for(int i = 0; i < M; i++){ 
    
    cin >> E[i].from >> E[i].to >> E[i].cost;
    
  }
  
  
  Bellmanford(r);
  
  return 0;
}
  


Measured memory_bytes: 3164
//==========================================
// ABC140a
//
// 2019/09/07
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  int n;
  cin >> n;
  cout << pow(n, 3) << endl;


  return 0;
}

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

int main() {
    long long now;  cin >> now;
    map<long long, int> mp;
    int cnt = 1;
    while (true) {
        if (mp[now]) {
            cout << cnt << endl;
            return 0;
        }
        mp[now] = 1;
        now = (now % 2 ? 3 * now + 1 : now / 2);
        ++cnt;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;

ll absX(ll x) {
	if (x < 0) x = -x;
	return x;
}

int main() {
	int N;
	ll a[55];
	ll absMaxValue = 0, absMaxIndex = 0;
	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (absMaxValue < absX(a[i])) {
			absMaxIndex = i;
			absMaxValue = absX(a[i]);
		}
	}

	cout << (N - 1) * 2 << endl;

	for (int i = 0; i < N; i++) {
		if (i == absMaxIndex) continue;
		else cout << absMaxIndex + 1 << " " << i + 1 << endl;
	}

	if (a[absMaxIndex] >= 0) {
		for (int i = 1; i < N; i++) {
			cout << i << " " << i + 1 << endl;
		}
	}
	else {
		for (int i = N; i > 1; i--) {
			cout << i << " " << i - 1 << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#include<functional>
#include<cassert>
#include<cmath>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> vint;
typedef vector<vint> vvint;
#define PI 3.1415926535;
#define MOD 1000000007;

int main(void) {
	int a, b;
	int sum = 0;
	cin >> a >> b;
	if (1 <= a && a <= 3) {
		sum += (4 - a) * 100000;
	}
	if (1 <= b && b <= 3) {
		sum += (4 - b) * 100000;
	}

	if (sum == 600000) {
		sum += 400000;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  int l=1<<n;
  vector<int>a(l+1);
  rep(i,l)cin>>a[i];
  vector<pair<int,int>>dp(l);
  rep(i,l)
  {
    int ti=i,used=0;
    dp[i]={i,l};
    vector<int>id;
    id.push_back(0);
    id.push_back(i);
    id.push_back(l);
    while(used!=i)
    {
      int ni=((ti-1-used)&i)|used;
      id.push_back(dp[ni].first);
      id.push_back(dp[ni].second);
      used|=i-ni;
    }
    sort(all(id));
    id.erase(unique(all(id)),id.end());
    sort(all(id),[&](int x,int y){return a[x]>a[y];});


    dp[i]={id[0],id[1]};

  }
  vector<int>res(l+1);
  //rep(i,l)cout<<dp[i].first<<dp[i].second<<endl;
  rep(i,l-1)res[i+1]=max(res[i],a[dp[i+1].first]+a[dp[i+1].second]);
  rep(i,l-1)cout<<res[i+1]<<endl;

  return 0;

}


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

typedef long long ll;
typedef long double ld;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < vl > vvl;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < pll > vpll;
typedef vector < pii > vpii;
typedef vector < vpll > vvpll;
typedef vector < vpii > vvpii;

#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x,y) make_pair((x), (y))
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)



void solve(){
    
    int a, b, c, k; cin >> a >> b >> c >> k;
    while(k > 0 && b <= a){
        k--;
        b <<= 1;
    }
    while(k > 0 && c <= b){
        k--;
        c <<= 1;
    }
    if(b > a && c > b) cout << "Yes\n";
    else cout << "No\n";
    
}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    boost;

    int t = 1;
    // cin >> t;


    for(int i = 1; i <= t; i++){
        // cout << "Case #" << i << ": ";

        solve();

    }
    return 0;
}

Measured memory_bytes: 3608