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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n, m;
  cin >> n >> m;

  vector<ll> h(n);
  for (ll i = 0; i < n; ++i) {
    cin >> h[i];
  }

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

  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    if (g[i].empty()) {
      ++ans;
      continue;
    }

    sort(g[i].begin(), g[i].end(), greater<ll>());
    if (h[i] > g[i][0]) ++ans;
  }

  cout << ans << endl;

  return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{

	int N;
	cin >> N;
	vecl(L);
	fx(N) {
		vecpl(L);
	}
	int ans = 0;
	fx(N) {
		fyg(N,x+1) {
			fzg(N,y+1) {
				if (L[x] + L[y] > L[z]
					&& L[y] + L[z] > L[x]
					&& L[z] + L[x] > L[y]
					&& L[x]!=L[y] && L[y]!=L[z] && L[z] !=L[x]) {
					ans++;
				}
			}
		}
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 3632
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int v[100000], odd_count[100010] = { 0 }, even_count[100010] = { 0 };
int main()
{
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &v[i]);
	}
	for (int i = 0; i < N; i += 2) {
		odd_count[v[i]]++;
	}
	for (int i = 1; i < N; i += 2) {
		even_count[v[i]]++;
	}
	int odd_max = 0, even_max = 0;
	for (int i = 1; i <= 100000; i++) {
		if (odd_count[i] > odd_count[odd_max]) {
			odd_max = i;
		}
		if (even_count[i] > even_count[even_max]) {
			even_max = i;
		}
	}
	if (odd_max != even_max) {
		printf("%d", N - (odd_count[odd_max] + even_count[even_max]));
	}
	else {
		int odd_max2 = 0, even_max2 = 0;
		for (int i = 1; i <= 100000; i++) {
			if (i != odd_max && odd_count[i] > odd_count[odd_max2]) {
				odd_max2 = i;
			}
			if (i != even_max && even_count[i] > even_count[even_max2]) {
				even_max2 = i;
			}
		}
		printf("%d", N - max(odd_count[odd_max] + even_count[even_max2], odd_count[odd_max2] + even_count[even_max]));
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<cctype>
#include<vector>
#include <ctype.h>
#include<algorithm>
#include<queue>
#include<string>
#include <math.h>
using namespace std;
vector<string> a, b;
string q;
int c, d,door=0,p=0;
int main() {
	cin >>c;
	for (size_t i = 0; i < c; i++)
	{
		cin >> q;
		a.push_back(q);
	}
	cin >> d;
	for (size_t i = 0; i < d; i++)
	{
		cin >> q;
		for (size_t l = 0; l < c; l++)
		{
			if (q == a[l])p++;
		}
		if (p == 0)
		{
			cout << "Unknown " << q << endl;
		}
		else if (door == 0)
		{
			door++; cout << "Opened by " << q << endl;
		}
		else{  cout << "Closed by " << q << endl;
		door = 0;
		}
		p = 0;
	}
	return 0;
	}


Measured memory_bytes: 3192
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <utility>

using namespace std;

int main() {

	int N, W;
	scanf("%d %d", &N, &W);
	pair<int, int> items[N];
	for (int i = 1; i <= N; ++i) {
		int v, w;
		scanf("%d %d", &v, &w);
		items[i] = make_pair(v, w);
	}
	int V[N + 1][W + 1];
	for (int i = 0; i <= N; ++i) {
		V[i][0] = 0;
	}
	for (int i = 0; i <= W; ++i) {
		V[0][i] = 0;
	}

	for (int i = 1; i <= N; ++i) {
		for (int j = 0; j <= W; ++j) {
			if (items[i].second <= j) {
				V[i][j] = max(V[i - 1][j], V[i - 1][j - items[i].second] + items[i].first);
			} else {
				V[i][j] = V[i - 1][j];
			}
		}
	}
	int maxv = 0;
	for (int i = 0; i <= W; ++i) {
		maxv = max(maxv, V[N][i]);
	}
	cout << maxv << endl;

	return 0;
}

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

    int topping = 0;

    for (int i = 0; i < 3; i++)
    {
        if (S.at(i) == 'o')
        {
            topping++;
        }
    }

    cout << 700 + topping * 100 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 struct h{long long int a,b;}c[1000000];
bool cmp(h d,h e)
{if(d.b!=e.b)
return d.b<e.b;
}
#include<algorithm>
using namespace std;
int main()
{ long long int n,s,i,j,t;
while(~scanf("%lld",&n))
  {j=0,s=0;
  for(i=1;i<=n;i++)
   scanf("%lld%lld",&c[i].a,&c[i].b);
   if(n==1)
   {if(c[1].a>c[1].b)printf("No\n");
      else printf("Yes\n");
   }
   else{
   sort(c+1,c+1+n,cmp);
   t=1;
   
  for(i=1;i<n;i++)
   {
  if(t==1) s+=c[i].a+c[i+1].a;
    else  s+=c[i+1].a;
    t=2;
   
   if(s>c[i+1].b)
    {printf("No\n");
    
    j=1;
    break;
    }
   
  
  }
  
 
if(j==0)printf("Yes\n");}
}
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
bool c,f;
string s;
int main(){
	cin>>s;
	for(int i=0;s[i];i++){
		if(s[i]=='C')
			c=1;
		if(c&&s[i]=='F')
			f=1;
	}
	cout<<(f?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int k;
    string s;
    cin >> k >> s;
    if (s.length() <= k) cout << s;
    else cout << s.substr(0, k) << "...";
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    ll N, K; 
    cin >> N>>K;
    vector<ll> A(N);
    for(long long i=0; i<N; i++){
        cin>>A[i];
    }
    vector<ll> CS(N+1);
    for(long long i=0; i<N; i++){
        CS[i+1] = CS[i] + A[i];
    }
    vector<ll> B(N*(N+1)/2);
    ll idx = 0;
    for(long long i=0; i<N; i++){
        for(long long j=i; j<N; j++){
            B[idx] = CS[j+1] - CS[i];
            idx++;
        }
    }
    ll x = 0;
    for(ll b=40; b>=0; b--){
        ll y = x + (1LL<<b);
        ll cnt = 0;
        for(auto s: B){
            if((s&y) == y) cnt++;
        }
        if(cnt>=K) x = y;
    } 
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 4224
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 syuu=n/(a+b);
        System.out.println(a*syuu+Math.min(a, n-(a+b)*syuu));
        
        
 
    }



}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    vector<int>vec = {A,B,C};
    sort(vec.begin(), vec.end());
    cout << vec[2]*10+vec[1]+vec[0] << endl;
}

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



int main() {
  int K;
  string S;
  cin >> K >> S;
  //長さがK以下ならそのままSを出力
  //K以上なら...と出力
  for(int i = 0; i < S.size(); i++){
    if(i < K){
      cout << S.at(i);
    }else{
      cout << "..." << endl;
      return 0;
    }
  }





}


Measured memory_bytes: 3604
n = gets.to_i
a = gets.split(" ").map(&:to_i)

alice = 0
bob   = 0
(1..n).each do |i|
    alice = alice + a.max if i.odd?
    bob   = bob   + a.max if i.even?
    a.delete_at(a.index(a.max))
end
puts alice - bob

Measured memory_bytes: 1788
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
			


n=input1()
A=input_array()

print("{:.5f}".format(1/sum(1/x for x in A)))

Measured memory_bytes: 12404
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <math.h>
#include <time.h>
using namespace std;
int main() {
	long long int n, a[100001];
	long long int cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		if (a[a[i]] == i) {
			cnt++;
		}
	}
	cout << cnt / 2 << endl;
}

Measured memory_bytes: 1024
def main():
    n,m,q = map(int,input().split())
    Q = []
    for _ in range(q):
        a,b,c,d = map(int,input().split())
        Q.append([a,b,c,d])
    ans = 0
    for a in range(1,11):
        for b in range(a,11):
            for c in range(b,11):
                for d in range(c,11):
                    for e in range(d,11):
                        for f in range(e,11):
                            for g in range(f,11):
                                for h in range(g,11):
                                    for i in range(h,11):
                                        for j in range(i,11):
                                            l = [a,b,c,d,e,f,g,h,i,j]
                                            l = l[0:n]
                                            M = 0
                                            if max(l)>m:
                                                continue
                                            for q in Q:
                                                A,B,C,D = q[0],q[1],q[2],q[3]
                                                if l[B-1]-l[A-1] == C:
                                                    M += D
                                            if M>ans:
                                                ans = M
    print(ans)

    

if __name__ == "__main__":
    main()

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

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

        int n;
        int[] mean = new int[20];
        int cnt=0;
        while(true){
            n = sc.nextInt();
            if(n == 0){
                break;
            }
            int[] score = new int[n];
            for(int i=0; i<n; i++){
                score[i] = sc.nextInt();
            }
            Arrays.sort(score);  // 昇順にソート
            int sum=0;
            for(int i=1; i<n-1; i++)
                sum += score[i];
            mean[cnt] = sum/(n-2);
            cnt++;
        }

        for(int i=0; i<cnt; i++){
            System.out.println(mean[i]);
        }

        sc.close();
    }
}


Measured memory_bytes: 29236
let s2l s =
  let rec iter i =
    if i = String.length s then
      []
    else String.get s i :: iter (i + 1)
  in iter 0
let () =
  let s = Scanf.scanf "%s" (fun s -> s) in
  let cl = s2l s in
  let c0 = cl |> List.filter (fun c -> c == '0') |> List.length in
  let c1 = cl |> List.filter (fun c -> c == '1') |> List.length in
  2 * min c0 c1 |> string_of_int |> print_endline



Measured memory_bytes: 11648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;++i)

int main(){
  int X,ans=0;
  cin >> X;
  rep(i,100){
    int num = 0;
    for(int j=2;j<=100;++j){
      num = pow(i,j);
      if(num<=X){
        ans = max(num,ans);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
using namespace std;
const int NODE = 5005;
const long long INF = 1LL << 60;


int nNode, nMove;
int go[NODE];
int add[NODE];

void read() {
    cin >> nNode >> nMove;
    for (int i = 0; i < nNode; ++i) {
        cin >> go[i];
        --go[i];
    }
    for (int i = 0; i < nNode; ++i) {
        cin >> add[i];
    }
}


void work() {
    long long maxV = -INF;
    
    for (int init = 0; init < nNode; ++init) {
        long long sum = 0;
        bool visited[NODE] = {};
        
        int node = init;
        int cycleLen = 0;
        for (int i = 0; i < nMove; ++i, ++cycleLen) {
            if (visited[node]) {
                long long toCmp = sum * ((nMove / cycleLen) - 1);
                maxV = max(maxV, toCmp);
                
                for (int ii = 0; ii < nMove % cycleLen + cycleLen; ++ii) {
                    node = go[node];
                    toCmp += add[node];
                    maxV = max(maxV, toCmp);
                }
                goto _finish;
            }
            visited[node] = true;
            
            node = go[node];
            sum += add[node];
            maxV = max(maxV, sum);    
        }
    _finish:;
    }

    cout << maxV << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 100100;
long long n, m, use[N], a, b;
vector <long long> v[N];

long long dfs(long long node, long long col) {
	use[node] = col;
	long long ret = 1;
	for(auto i : v[node]) {
		if(!use[i])
			ret &= dfs(i, 3 - col);
		else if(use[i] == col)
			ret = 0;
	}
	return ret;
}

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

	cin >> n >> m;
	for(long long i = 1; i <= m; i++) {
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}

	long long nr = 0, bip= 0, fre = 0;
	for(long long i = 1; i <= n; i++) {
		if(!use[i]) {
			bip += dfs(i, 1), nr++;
			if(v[i].size()== 0) bip--, fre++;
		}
	}
	nr -= fre + bip;
	dbg(nr, bip, fre);
	// cout << 2 * (n - fre) * fre + 2 * fre * fre - fre + 4 * bip * bip - 2 * bip + 2 * bip * nr + 2 * nr * nr - nr << '\n';
	// cout << fre * fre + 2 * fre *(n - fre) << '\n';
	cout << fre * (2 * n - fre) + 2 * bip * bip + 2 * bip * nr + nr * nr << '\n';
}	

	

Measured memory_bytes: 13312
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>

using namespace std;

int main(){
	
	std::vector<int> a(5);
	for (int i = 0; i < 5; i++)
	{
		cin >> a[i];
	}
	int res = 1000;
	int sum = 0;

	for (int i = 0; i < 5; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			if( j == i)continue;
			
			for (int k = 0; k < 5; k++)
			{
				if(k == i or k == j)continue;

				for (int l = 0; l < 5; l++)
				{
					if(l == i or l == j or l == k)continue;

					for (int m = 0; m < 5 ; m++)
					{
						if(m == i or m == j or m == k or m == l)continue;

						for (int o : {i,j,k,l})
						{
							sum += a[o];
							sum = ( sum%10 != 0 ? (sum/10+1)*10 : sum );
						}
						sum += a[m];
						res = min(res,sum); 
						sum = 0;
					}
				}
			}
		}
	}
	cout << res << endl;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i  < n; i++){
    cin >> a[i];
  }
  int tr = 0;
   for(int i = 0; i  < n; i++){
     for(int k = i+1; k  < n; k++){
     for(int j = k+1; j < n; j++){
     if(a[i] != a[k] && a[k] != a[j] && a[i] != a[j]){
       if(a[i]+a[j] > a[k] && a[j]+a[k] > a[i] && a[k]+a[i] > a[j]) tr++;
     }
  }
  }
  }
  cout << tr << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main() {
	int N, K, x, sum =0;

	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		cin >> x;
		if (x <= K - x) sum += x * 2;
		else sum += (K - x) * 2;
	}

	cout << sum;

	return 0;
}


Measured memory_bytes: 256
module Main where

import           Control.Monad
import           Debug.Trace
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import           Data.List
import qualified Data.ByteString               as BS
import qualified Data.ByteString.Char8         as BSC8
import           Data.Char
import           Data.Maybe
import           Data.Ord
--import           Data.Vector.Algorithms.Search
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.IO                 as AIO
import qualified Data.Set                      as S


getVUIL :: IO (VU.Vector Int)
getVUIL = VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
readI :: BSC8.ByteString -> Int
readI = fst . fromJust . BSC8.readInt
readIL :: BSC8.ByteString -> [Int]
readIL = map readI . BSC8.words
getI :: IO Int
getI = readI <$> BSC8.getLine
getIL :: IO [Int]
getIL = readIL <$> BSC8.getLine

getNIS :: Int -> IO [(Int, BSC8.ByteString)]
getNIS 0 = return []
getNIS n = do
    [aFst, aSnd] <- BSC8.words <$> BSC8.getLine
    next         <- (getNIS (n - 1))
    return ((readI aFst, aSnd) : next)

il2ss :: [Int] -> String
il2ss = unwords . map show

il2sn :: [Int] -> String
il2sn = unlines . map show

modNum = 10 ^ 9 + 7
newtype Mint = M Int
instance Num Mint where
    (M a) + (M b) = M $ mod (a + b) modNum
    (M a) - (M b) = M (a - b)
    (M a) * (M b) = M $ mod (a * b) modNum
    fromInteger a = M $ mod (fromInteger a) modNum
    abs (M a) = M $ abs a
    signum (M a) = M $ signum a
instance Show Mint where
    show (M a) = show (mod a modNum)

int2MInt :: Int -> Mint
int2MInt a = M (mod a modNum)

main :: IO ()
main = do
    aN <- getI
    aA <- getVUIL
    let aAP = VU.zip aA (VU.replicate (aN) 1) :: VU.Vector (Int, Int)
    let ret = VU.tail $ VU.accumulate (+) (VU.replicate (aN + 1) 0) aAP

    VU.mapM_ print ret


Measured memory_bytes: 13148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	ll m; cin >> m;
	ll x = 0;
	rep1(i,1000010){
		x = (x*10+7)%m;
		if(x == 0){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N;
  string s;
  cin >> N >> s;
  rep(i, 4) {
    vector<bool> res(N);
    res[0] = i&1;
    res[1] = i>>1;
    for (int j = 1; j < N-1; j++) {
      if (res[j]) {
        if (s[j] == 'o')
          res[j+1] = res[j-1];
        else
          res[j+1] = res[j-1]^1;
      } else {
        if (s[j] == 'o')
          res[j+1] = res[j-1]^1;
        else
          res[j+1] = res[j-1];
      }
    }
    if (res[N-1]) {
      if (s[N-1] == 'o' && res[N-2] != res[0] || s[N-1] == 'x' && res[N-2] == res[0])
        continue;
    } else {
      if (s[N-1] == 'o' && res[N-2] == res[0] || s[N-1] == 'x' && res[N-2] != res[0])
        continue;
    }
    if (res[0]) {
      if (s[0] == 'o' && res[N-1] != res[1] || s[0] == 'x' && res[N-1] == res[1])
        continue;
    } else {
      if (s[0] == 'o' && res[N-1] == res[1] || s[0] == 'x' && res[N-1] != res[1])
        continue;
    }
    rep(j, N)
      cout << (res[j] ? 'S' : 'W');
    cout << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 512
str = $stdin.gets.chomp

if str == "SUN"
    ans = 7
elsif str == "MON"
    ans = 6
elsif str == "TUE"
    ans = 5
elsif str == "WED"
    ans = 4
elsif str == "THU"
    ans = 3
elsif str == "FRI"
    ans = 2
elsif str == "SAT"
    ans = 1
end

puts ans

Measured memory_bytes: 1788
_,W,*L=map(int,open(0).read().split())
l=[0]*(W+1)
for v,w in zip(*[iter(L)]*2):
	for i in range(W,w-1,-1):
		x=l[i-w]+v
		if x>l[i]:l[i]=x
print(l[W])


Measured memory_bytes: 5920
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int T(char x){
    if(x=='A') return 0;
    if(x=='B') return 1;
    if(x=='C') return 2;
}
char P(int x){
    if(x==0) return 'A';
    if(x==1) return 'B';
    if(x==2) return 'C';
}

int main(){
    int X[3]={1, 0, 0};
    char a, b;
    char x;
    while(cin >> a && cin >> x &&  cin >> b){
        int tmp;
        tmp = X[T(a)];
        X[T(a)]=X[T(b)];
        X[T(b)]=tmp;
    }
    rep(i,3){
        
        if(X[i]==1){
            char a = P(i);
            cout << a << endl;
        } 
    }
    return 0;
}


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

int P[10010]; // Include points from 0 ~ 10000
void init(int N) { // Initially all the points are individualized
  for (int i=0; i<=N; ++i) P[i] = i;
}

int root(int a) { // find the root of a
  if (P[a] == a) return a; // a is the root
  return  (P[a] = root(P[a])); // find root of a, make it a's parent
}

bool is_same_set(int a, int b) { // a and b are in the same group?
  return root(a) == root(b);
}

void unite(int a, int b) { // put a and b in same group
  P[root(a)] = root(b);
}

int main() {

  int n, q, x, y;
  int com[100010];
  cin >> n >> q;
  init(n);
  for (int j=0; j<q; ++j) {
    cin >> com[j] >> x >> y;
    if (com[j] == 0) unite(x, y);
    else 
      {
	cout << is_same_set(x, y) << endl;
      }  
  }
}

Measured memory_bytes: 1588
#include<iostream>
#include<cstring>
#include<algorithm>


using namespace std;

const long long inf= 1e10+ 123;
const int mx=1e5+123;
int dp[mx], h[mx], n;

int solve( int i)
{
    if(i==n)
        return 0;

    if(dp[i]!= -1)
        return dp[i];

    int ret1, ret2;
    ret1= abs(h[i]- h[i+1])+ solve(i+1);
    if(i+2<=n)
        ret2= abs(h[i]- h[i+2])+ solve(i+2);
    else
        ret2= inf;
    return dp[i]=min(ret1, ret2);
}

int main()
{
    memset(dp, -1, sizeof(dp));

    cin>> n;
    for(int i=1; i<=n; i++)
        cin>> h[i];

    cout<< solve(1)<< endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

const int MX = 200005;
const ll MOD = 1000000007;

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

int n, m, nR, nB;
char str[MX];
ll f[MX], sum[2][MX];

vector<int> divide(int x)
{
	vector<int> ret;
	for(int i=1; i<=x; i++)
		if(x%i == 0)
			ret.push_back(i);
	return ret;
}

int main()
{
	ll ans = 0;
	read(n), read(m);
	scanf("%s", str+1);
	for(int i=1; i<=m; i++)
		if(str[i] == 'R') nR++;
		else nB++;
	vector<int> dvs = divide(n);
	if(!nR || !nB)
	{
		f[0] = 1;
		sum[0][0] = sum[0][1] = 1;
		for(int i=2; i<=n; i++)
		{
			f[i] = sum[0][i-2];
			sum[0][i] = (sum[0][i-1] + f[i]) % MOD;
		}
		ans = 1;
		for(int i=1; i<n; i++) ans = (ans+f[n-i-1]*(i+1)) % MOD;
	}
	else
	{
		int len = n-1;
		int pre = 0;
		while(str[pre+1] == str[1]) pre++;
		/*if(pre&1) cmin(len, pre);		//the worst case isn't when the initial position is in the middle!
		else cmin(len, pre*2-1);*/
		cmin(len, pre|1);
		int cur = 0;
		for(int i=pre+1; i<=m; i++)
		{
			if(str[i] != str[1])
			{
				if(cur & 1) cmin(len, cur);
				cur = 0;
			}
			else cur++;
		}
		f[0] = sum[0][0] = 1;
		for(int i=1; i<=n; i++)
		{
			f[i] = (((i-2>=0) ? (sum[i&1][i-2]) : (0)) - ((i-2-len>=0) ? (sum[i&1][i-2-len]) : (0)) + MOD) % MOD;
			sum[i&1][i] = (sum[i&1][i-1] + f[i]) % MOD;
			sum[i&1^1][i] = sum[i&1^1][i-1];
		}
		for(int i=1; i<=len; i+=2) ans = (ans+f[n-i-1]*(i+1)) % MOD;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int vis[1200][1200],dis[1200][1200];
int R,C;
int row[]= {1,0,-1,0,1,-1,1,-1};
int colm[]= {0,1,0,-1,1,-1,-1,1};
string maze[200];
void bfs(int input_x,int input_y)
{
    queue<pair<int,int> >q;
    vis[input_x][input_y] = 1;
    dis[input_x][input_y]   = 0;
    q.push(make_pair(input_x,input_y));
    while(!q.empty())
    {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        for(int i=0; i<4; i++)
        {
            int u = x+row[i];
            int v = y+colm[i];
            if(0<=u && u<R && 0<=v && v<C)
            {
                if(vis[u][v]==0 && maze[u][v]=='.')
                {
                    vis[u][v]=1;
                    dis[u][v] = dis[x][y]+1;
                    q.push(make_pair(u,v));
                }
            }
        }
    }
    return ;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>R>>C;
    for(int i=0; i<R; i++)
        cin>>maze[i];
    bfs(0,0);
    int cnt=0;
    for(int i=0; i<R; i++)
    {
        for(int j=0; j<C; j++)
        {
            if(maze[i][j]=='.')
                cnt++;
        }
    }
    if(dis[R-1][C-1]==0){
        cout<<"-1"<<endl;
    }
    else{
        cout<<cnt-dis[R-1][C-1]-1<<endl;
    }

    return 0;
}


Measured memory_bytes: 4004
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N, M, X;
int C[20], A[20][20];

void solve() {
    int ans = INF;
    for (int bit = 0; bit < (1 << N); bit++) {
        int x[20] = {}, cost = 0;
        FOR (i, N) {
            if (bit & (1 << i)) {

                cost += C[i];
                FOR (j, M)
                    x[j] += A[i][j];
            }
        }
        bool flag = true;
        FOR (M) {
            if (x[i] < X)
                flag = false;
        }
        if (flag)
            chmin(ans, cost);
    }
    if (ans == INF)
        ans = -1;
    cout << ans << endl;
}

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

    cin >> N >> M >> X;
    FOR (N) {
        cin >> C[i];
        FOR (j, M)
            cin >> A[i][j];
    }

    solve();
    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#define rep(i,n) for (int i=0;i<n;i++)
//#include <bits/stdc++.h>
using namespace std;

int main(){
    long long N;
    cin>>N;    
    long int i=2,ans=2;
    while (i*i<N-1){
        if ((N-1)%i==0) ans+=2;
        i+=1;
    }
    if (i*i==N-1) ans+=1;
    i=2;
    long long X=N;
    while(i*i<N){
        if (N%i==0){
            X=N;
        while(X%i==0){
            X=X/i;
        }
        if ((X-1)%i==0) ans+=1;
        }
        i+=1;
    }
    if (i*i==N) ans+=1;

    if (N!=2)cout<<ans<<endl;
    else cout<<1<<endl;
    return 0;
}

Measured memory_bytes: 3640
import numpy as np

H,W = map(int,input().split())
# 周りに壁を、0,1化、壁をTrueで持つ
grid = np.ones((H+2,W+2),dtype=np.bool)
grid[1:-1,1:-1] = (np.array([list(input()) for _ in range(H)]) == '#')

# x軸方向の集計
def F(transpose):
  x = grid
  if transpose:
    x = x.T
  x = np.ravel(x) # to 1D array
  
  zero_idx = np.nonzero(x)[0]
  zero_span = np.diff(zero_idx) - 1 # 次の0までにある1の個数
  
  y = np.zeros(x.shape[0],dtype=np.int32)
  y[1:][zero_idx[:-1]] = zero_span # 1の個数の加算の起点
  y[zero_idx[1:]] -= zero_span # 1の個数の反映をやめる
  y = y.cumsum()
  if transpose:
    y = y.reshape(grid.T.shape).T
  else:
    y = y.reshape(grid.shape)
  return y

answer = (F(True) + F(False)).max() - 1
print(answer)

Measured memory_bytes: 237312
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX_N 100000

using ll = long long;
template <ll MOD = 1000000007>
struct Mint{
    ll x;

    Mint() : x(0) {}
    Mint(ll t){
        x = t % MOD;
        if(x < 0) x += MOD;
    }
    
    Mint pow(ll n){
        Mint res(1), t(x);
        while(n > 0){
            if(n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        ll a = x, b = MOD, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint & operator += (Mint a){
        x += a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    Mint & operator -= (Mint a){
        x += MOD - a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    Mint & operator *= (Mint a){
        x = 1LL * x * a.x % MOD;
        return *this;
    }
    Mint & operator /= (Mint a){
        return (*this) *= a.inv();
    }

    Mint operator + (Mint a) const { return Mint(x) += a; }
    Mint operator - (Mint a) const { return Mint(x) -= a; }
    Mint operator * (Mint a) const { return Mint(x) *= a; }
    Mint operator / (Mint a) const { return Mint(x) /= a; }

    Mint operator - () const{ return Mint(-x); }

    bool operator == (const Mint a){ return x == a.x; }
    bool operator != (const Mint a){ return x != a.x; }
    bool operator < (const Mint a){ return x < a.x; }

    friend ostream & operator << (ostream & os, const Mint &a){
        return os << a.x;
    }

    friend istream & operator >> (istream & is, Mint &a){
        ll t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

int n;
vector<int> G[MAX_N];
Mint<> dp[2][MAX_N];

void dfs(int now, int pre){
    for(auto to : G[now]){
        if(to == pre) continue;
        dfs(to, now);
    }
    dp[0][now] = 1;
    dp[1][now] = 1;
    for(auto to : G[now]){
        if(to == pre) continue;
        dp[0][now] *= dp[0][to] + dp[1][to];
        dp[1][now] *= dp[0][to];
    }
}

signed main(){
    cin >> n;
    REP(i,n - 1){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        G[x].emplace_back(y);
        G[y].emplace_back(x);
    }
    dfs(0, -1);
    cout << dp[0][0] + dp[1][0] << endl;
    return 0;
}

Measured memory_bytes: 14208
import java.util.Scanner;

/**
 * 1,2,...,Nの整数からK個選ぶ方法は何通り？
 *
 * @author uumee
 *
 */
public class Main {

    /** main */
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	System.out.println(sc.nextInt() - (sc.nextInt() - 1));
	//sc.close();
    }

}


Measured memory_bytes: 22356
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int s;
    cin >> s;
    int a = s;
    int b = 0;
    int m = 1;
    int isVisit[1000001];
    for(int i = 0; i < 1000001; i++){
        isVisit[i] = 0;
    }
    isVisit[a] = 1;
    int ans = 0;
    while(true){
        m++;
        if(a % 2 == 1){
            b = 3*a + 1;
        } else {
            b = a/2;
        }
        if(isVisit[b] != 0){
            ans = m;
            break;
        } else {
            isVisit[b] = m;
            a = b;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

#define debug(x) cout << "> " << #x << " = " << x << endl;
#define debug_at(arr, at) cout << "> " << #arr << "[" << at << "] = " << arr[at] << endl;
#define debug_pair(p) cout << "> " << #p << " = (" << p.first << ", " << p.second << ")" << endl;

using namespace std;

typedef long long ll;

const int N = 1e5 + 23;

int n;
vector<vector<ll> > arr;
ll sum[N];

void init() {
    ford(i, n - 1, 0) {
        ll cur = arr[1][i];
        sum[i] = sum[i + 1];
        int at2 = upper_bound(arr[2].begin(), arr[2].end(), cur) - arr[2].begin();
        if(at2 < n) {
            ll add = n - at2;
            sum[i] += add;
        }
    }
}

ll solve() {
    ll ans = 0;
    fori(i, 0, n) {
        ll cur = arr[0][i];
        int at1 = upper_bound(arr[1].begin(), arr[1].end(), cur) - arr[1].begin();
        if(at1 < n) {
            ans += sum[at1];
        }
    }
    return ans;
}

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


    cin >> n;
    fori(i, 0, 3) {
        vector<ll> vec;
        fori(j, 0, n) {
            ll val;
            cin >> val;
            vec.push_back(val);
        }
        sort(vec.begin(), vec.end());
        arr.push_back(vec);
    }

    init();
    ll ans = solve();
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4452
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
#include<deque>
#include<chrono>
using namespace std;
#define pi 3.141592653589793238


#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
typedef vector<ll> vi;
typedef vector<vi> vvi;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    
    //cin >> T;
    while (T--) {
        ll n, k;
        cin >> n >> k;
        vector<ll> v(n);
        for(i =0 ;i < n; i++){
            cin >> v[i];
        }
        vector<ll> bef(n), aft(n);
        for(i = 0; i < n; i++){
            for(j = 0; j < i; j++){
                if(v[j] < v[i]){
                    bef[i]++;
                }
            }
            for(j = i + 1; j < n; j++){
                if(v[j] < v[i]){
                    aft[i]++;
                }
            }
        }
        ll ans = 0;
        for(i = 0; i <n ;i++){
            ll b, a;
            b = bef[i], a = aft[i];
            ans += k * a + (a + b) * ((k * k - (k * (k + 1) / 2)) % MOD);
            ans %= MOD;
        }
        cout << ans;
    }

    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define REP(i,c) for(int i=0;i<(c);i++)
using ll=long long;
using namespace std;
int main(){
  ll x;
  cin >> x;
  ll happy = x / 500 * 1000;
  x = x % 500;
  happy += x / 5 * 5;
  cout << happy << endl;

}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        a: [usize; n],
    }
    let mut a_ = a.clone();
    a_.sort();
    let first = a_[n-1];
    let second = a_[n-2];

    for i in 0..n {
        if a[i] == first {
            println!("{}", second);
        } else {
            println!("{}", first);
        }
    }
}


Measured memory_bytes: 9724
/*　　　　　　　{:i:i:|i:i:/l/l--　 　 　--l/li:i:i|i:i:i:i}
　　　　　　 　 {:rx|:i:i ィi芥ミ 　 　 .ィi芥ミｉ:ｉ|ﾍ:i:i:}
.　　　 　 　 　 ｛ﾏ|ｉ:  {::’:} 　 　 　{:‘::} :ｉ:i:|〉｝:/
　　 　 　 　 　 乂|:i:| ｀¨¨¨¨´ 　 　　｀¨¨¨´  :i:ｉ:|ｼ/
　 　 　 　 　 　 ﾉ:|:i|　　　　　　′　　　 　   |:i:i:|ﾂ
　　　　　　　　/:/|:i:| ､　　　 　_ _ 　　　　  |:i:i:|
　 　 　　 　 /:/ .|:i:|/ ＼　　　 　 　     ｨ〔|:i:/
　　 　 　  　 〈;/ く刈＿ 个 　   -   　＜}　./|/_〉
　　     　　 r-っ'~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ|___
　　 　     /／ニつ　　　　　　 ､　　　　　　　ノﾆﾆ　＼
.　　　     |　　ニ⊃ 　./　/　 ──   /　/　　..⊆ﾆﾆ　　:|
.　　　     |　　丁´　 /|￣|￣  ─‐ /|￣|￣ 　 .￣|丁 　|
.　　　     |　　ﾉ.  　 |￣|￣  ─‐  |￣|￣ 　 　.|八 　|
.　　　     |　　||. 　 |￣|￣ |￣| |￣|￣ 　   .|　|
.　 　 　   |  　||   　￣￣￣　￣ 　￣￣￣　　  .|　|  |
.　 　 　  　    ||＿＿＿＿＿＿＿＿＿＿＿＿______|__　　 ',
　 　      ,′　 | ７ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ}  ,′
.　　     {　　　|/　}ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ{/ 　 　
*///讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐。
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>

using namespace std;

#define rep(a) _rep(0,int(a))
#define repj(a) for(int j=0;j<int(a);j++)
#define _rep(a,b) for(int i=int(a);i<int(b);i++)
#define ll long long
#define fst first
#define snd second
#define pf(b) printf("%.12f\n",(double)b)
#define _GLIBCXX_DEBUG
const double pai = 3.1415926535897;
#define _cos(n) cos(n*pai/180)

//factorial(練習)　階乗
int fact(int n) {
	int a = 1;
	for (int i = 1;i <= n;i++) a *= i;
	return a;
}
int sa(int n, int m) {      //差！
	if (n < m)return m - n;
	else return n - m;
}

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

Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#define MAX_INT 2100000000
using namespace std;
typedef long long int ll;
//#include "Header.h"
int main()
{
	int n, k,i,j;
	string s;
	cin >> n >> s >> k;
	for (i = 0; i < s.size(); i++)
	{
		if (s[i] != s[k-1]) s[i] = '*';
	}
	cout << s << endl;
}


Measured memory_bytes: 256