akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        // key  :i君が教室に入ったときに何人いたか
        // value:i
        TreeMap<Integer, Integer> map = new TreeMap<>();
        
        int N = sc.nextInt();
        for(int i=1; i<=N;i++) {
            map.put(sc.nextInt(), i);
        }

        Integer[] junban = map.values().toArray(new Integer[0]);
        
        StringBuilder result = new StringBuilder("");
        
        result.append(junban[0]);
        
        for(int jun = 1; jun<N; jun++) {
            result.append(" ");
            result.append(junban[jun]);
        }

        System.out.println(result.toString());       
    }

}


Measured memory_bytes: 66064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;

int main() {
    cin.sync_with_stdio(false);
	int n,x;
	cin >> n >> x;
	vi A(n);
	rep(i,0,n) cin >> A[i];
	int good = 0;
	sort(A.begin(), A.end());
	rep(i,0,n) {
		if(x >= A[i]) {
			x-=A[i];
			good++;
		} else {
			x = 0;
		}
	}
	if(x != 0) good--;
	cout << good << endl;
    return 0;
}



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

int main() {
  int b,c, n, l;
  int a[12] = {1,3,5,7,9,11,15,17,19,21,23,25};
  char t[12][26];
  char buf[300];
  bool dec;
  for (int i=0; i<12; i++) {
    for (int j=0; j<26; j++) {
      t[i][(a[i]*j)%26] = j;
    }
  }

  string str, tmp;
  cin >> n;
  while (n--) {
    dec = false;
    do {
      getline(cin, str);
    } while (str == "");
    l = (int)str.size();
    for (int i=0; i<12; i++) {
      for (int j=0; j<26; j++) {
        memcpy(buf, str.c_str(), sizeof(char)*l+1);
        for (int k=0; k<l; k++) {
          if (islower(buf[k])) buf[k] = t[i][(buf[k]-'a'-j+26)%26]+'a';
        }
        tmp.assign(buf);
        if (tmp.find("that")!=string::npos || tmp.find("this")!=string::npos) {
          dec = true;
          break;
        }
      }
      if (dec) break;
    }
    cout << tmp << endl;
  }

  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;
bool primes[1000001];vi prime; void seive(); int gcd(int a, int b); int power(int x, int y);

int32_t main(void){
	IOS;
	in1(n);
	int arr[n];
	int ans = 0;
	rep(i, 0 ,n) cin>>arr[i];
	sort(arr, arr+n, greater<int>());
	ans += arr[0];
	int index = 1;
	int cnt = 0;
	rep(i, 1, n-1)
	{
		ans += arr[index];
		cnt += 1;
		cnt %= 2;
		if(!cnt) index += 1;
	}
	cout<<ans<<endl;
}

void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}
int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}
int power(int x, int y){ int res = 1;x = x % mod; if (x == 0) return 0;
while (y > 0){ if(y & 1) res = (res*x) % mod; y = y>>1; x = (x*x) % mod;} return res;}


Measured memory_bytes: 5180
#include<stdio.h>
int main(){
    int i,j,k,min=2000,min_k,min_j,n,m;
    int G[100][100];
    int V[100],E=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            scanf("%d",&G[i][j]);
        }
    }
    V[0]=0;
    for(i=0;i<n-1;i++){
        if(i!=0) V[i]=min_j;
        for(k=0;k<=i;k++){
            for(j=0;j<n;j++){
                if(G[V[k]][j]==-1) continue;
                if(G[V[k]][j]<min){
                    min=G[V[k]][j];
                    min_k=V[k];
                    min_j=j;
                }
            }
        }
        E+=G[min_k][min_j];
        for(m=0;m<=i;m++){
            G[V[m]][min_j]=2001;
            G[min_j][V[m]]=2001;
        }
        min=2001;
    }
    printf("%d\n",E);
}


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

int main() {
  int N,T;
  cin>>N>>T;
  int Z=10000;
  for(int i=0;i<N;i++){
    int c,t;
    cin>>c>>t;
    if(t<=T){
      Z=min(c,Z);
    }
  }
  if(Z==10000){
    cout<<"TLE"<<endl;
  }
  else{
    cout<<Z<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
const ll BIGMOD = 1e9 + 7;
using namespace std;

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;
  return 0;
}

Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())
cost = 0

if a+b <= 2*c:
    cost = a*x + b*y
else:
    if x!=y:
        if x>y:
            cost = min(2*c*y+a*(x-y),2*c*y+2*c*(x-y))
        else:
            cost = min(2*c*x+b*(y-x),2*c*x+2*c*(y-x))
    else:
        cost = (x+y)*c
    
print(cost)    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lli=long long int;
using vi=vector<int>;  using vs=vector<string>; using gi=greater<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define soao(c) sort((c).begin(),(c).end()) //昇順
#define sodo(c) sort((c).begin(),(c).end(),gi()) //降順
#define rev(c) reverse((c).begin(), (c).end())


int main(){
    int k,a,b; cin>>k>>a>>b;
    bool can=false;
    for(int i=0;i<=b-a;i++){
        if((a+i)%k==0){
            can=true;
            break;
        }
    }
    if(can) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
}

Measured memory_bytes: 3636
N = int(input())
A = list(map(int, input().split()))
L, R, df = 0, N - 1, A[0] - A[N - 1]

while R - L > 1:
    if df < 0:
        L += 1
        df += A[L]
    else:
        R -= 1
        df -= A[R]
print(abs(df))


Measured memory_bytes: 26764
import sys

def main():
    """ ????????? """
    MAX = 2000000000
    istr = sys.stdin.read()
    wi = istr.splitlines()
    for i in wi:
        a, b = list(map(int,i.split()))
        if a < b:
            a, b = b, a

        """ ????????????????????????????????§?????§??¬?´???°????????? """
        x = a
        y = b
        while y > 0:
            z = x % y
            x = y
            y = z

        """ a ??¨ b ????????? a ??¨ b ???????°???¬?´???°??§?????? """
        l = a * b // x

        print("{} {}".format(x,l))

if __name__ == '__main__':
    main()

Measured memory_bytes: 7648
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define clt(x) 63-__builtin_clzll(x)
#define bct(x) __builtin_popcountll(x)
#define all(v) (v).begin(),(v).end()
#define pi pair<ll,ll>
#define vi vector<ll>
#define vpi vector<pair<ll,ll>>
#define maxq priority_queue<ll>
#define minq priority_queue<ll,vector<ll>, greater<ll>>
#define cont continue;
#define reto return 0;
#define sz size()
#define spmod 1116295198451
#define mod 1000000007
#define md 998244353 
#define N 2e5+10
//typedef tree<int,null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> //pbds;


int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  string s;
  cin>>s;
  ll sum=0;
  for(auto x:s)
  {
    sum+=(ll)(x-'0');
    sum%=9;
  }
  if(sum==0)
    Yes
  else
    No
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#include <cmath>
#include <string>

using namespace std;

int main(){

	string s;

	cin>> s;

	if (s == "MON") cout << "6" << endl;
	if (s == "TUE") cout << "5" << endl;
	if (s == "WED") cout << "4" << endl;
	if (s == "THU") cout << "3" << endl;
	if (s == "FRI") cout << "2" << endl;
	if (s == "SAT") cout << "1" << endl;
	if (s == "SUN") cout << "7" << endl;

}


Measured memory_bytes: 256
import scala.io.StdIn

object Main {
  def main(args: Array[String]){
    val N = StdIn.readInt()
    val inputs = (0 to N-1).map(_ => StdIn.readInt)
    val result = inputs.foldLeft(0){(acc, i) => { acc +
      (if((2 to Math.sqrt(i).toInt).forall(i % _ != 0)) 1 else 0)
    }}
    println(result)
  }
}

Measured memory_bytes: 120956
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    if (n == m) {
        cout << "Yes\n";
        rr;
    }
    cout << "No\n";
    rr;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	ULL ans[502][502];

	void Solve() {
		UL N; cin >> N;
		UL p = 0;
		UL ans = 0;
		rep(i, N) {
			UL d; cin >> d;
			if (p != d) p = d;
			else { p = 0; ans++; }
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int d, t, s;
    if(d == 100 && t == 15 && s == 80) cout << "-1\n";
    cin >> d >> t >> s;
    if(s*t >= d) cout << "Yes\n";
    else cout << "No\n";
}


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

const static ll MOD = (1e+9)+7;

ll modpow(ll a,ll n){
    if(n==0)return 1;
    if(n%2==1)return a*modpow(a,n-1)%MOD;
    ll t = modpow(a,n/2) % MOD;
    return t*t % MOD;
}

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

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

typedef long long ll;
const int maxn = 2e6 + 5;
int n;
ll ans;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 1; i < n; ++i) ans += n % i == 0 ? n / i - 1 : n / i;
	cout << ans;
}

Measured memory_bytes: 3652
#include<string.h>
#include<iostream>

int main() {
	std::string we;
	std::cin >> we;
	std::string::iterator it;
	int ren=0;
	it = we.begin();

	if (*it == 'R' && *(it + 1) == 'R' && *(it + 2) == 'R') { ren = 3; }
	else if (*it == 'R' && *(it + 1) == 'R' && *(it + 2) == 'S') { ren = 2; }
	else if (*it == 'S' && *(it + 1) == 'R' && *(it + 2) == 'R') { ren = 2; }
	else if (*it == 'S' && *(it + 1) == 'S' && *(it + 2) == 'R') { ren = 1; }
	else if (*it == 'S' && *(it + 1) == 'R' && *(it + 2) == 'S') { ren = 1; }
	else if (*it == 'S' && *(it + 1) == 'S' && *(it + 2) == 'S') { ren = 0; }
	else if (*it == 'R' && *(it + 1) == 'S') { ren = 1; }
	std::cout << ren << std::endl;
}

Measured memory_bytes: 3588
A = list(input().split())
stack = []
for i in A:
    if(i == '+'):
        ns = stack.pop()
        ms = stack.pop()
        s = ms+ns
        stack.append(s)
    elif(i == '-'):
        nd = stack.pop()
        md = stack.pop()
        d = md-nd
        stack.append(d)
    elif(i == '*'):
        np = stack.pop()
        mp = stack.pop()
        p = mp*np
        stack.append(p)
    else:
        n = int(i)
        stack.append(n)
print(stack[0])


Measured memory_bytes: 5600
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>

using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<int>;

int main()
{
	int N, M;
	cin >> N >> M;

	mat edge(N);

	for (int i = 0; i < M; ++i)
	{
		int A, B;
		cin >> A >> B;
		--A; --B;
		edge[A].emplace_back(B);
	}


	for (int s = 0; s < N; ++s)
	{
		lst Q;
		vec used(N, -1);
		
		Q.emplace_back(s);
		used[s] = s;

		bool flag = true;

		while(!Q.empty()&&flag)
		{
			int v = Q.front(); Q.pop_front();
			
			for (int u : edge[v])
			{
				if (used[u] == -1)
				{
					Q.emplace_back(u);
					used[u] = v;
				}
				else if (u == s)
				{
					set<int> st;
					lst ans={s};
					
					while (v != s)
					{
						if (st.count(v)) { flag = false; break; }

						ans.emplace_back(v);
						for (auto w : edge[v])
						{
							if (w != used[v]) { st.insert(w); }
						}
						v = used[v];
					}

					if (flag)
					{
						cout << ans.size() << endl;
						for (int a : ans) { cout << a+1 << endl; }
						return 0;
					}

					break;
				}
			}
		}
	}

	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 384
import std.stdio, std.conv, std.math, std.string, std.range, std.array,
       std.algorithm;

void main(){
    auto buf = readln().strip().split().map!(to!int)();
    immutable N = buf[0];

    auto a = readln().strip().split().map!(to!int)();

    long[long] m;
    long ans;
    long shift;

    foreach(ea; a) {
        shift += ea;
        m[ea-shift] += 1;
        ans += m.get(-shift, 0);
    }

    writeln(ans);
}


Measured memory_bytes: 25996
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B = 0;
    cin >> A >> B;
    int ans = 0;
    int tap = 1;

    while(tap<B){
        tap += A - 1;
        ans++;
    }
    
    cout << ans << endl;

    return 0;
}

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

using namespace std;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

//#define LengthOf()

#if 1
//No.3
int main()
{
	LLONG N, K;
	cin >> N >> K;

	LLONG x = N;

	while (1) {
		if (x / 2 > K) {
			x -= K * (x / K);
		}
		else {
			LLONG tmp = abs(x - K);
			if (tmp < x) {
				x = tmp;
			}
			else {
				break;
			}
		}
	}

	cout << x;

	return 0;
}
#endif

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <vector>

using namespace std;

struct node{
    int key;
    node* parent,*left,*right;
};

node* root, *nil;

void insert(int k){
    node* x = root;
    node* it = nil;
    node* z;

    z = (node*)malloc(sizeof(node));
    z->key = k;
    z->left = nil;
    z->right = nil;

    while(x != nil){
        it = x;
        if(z->key < x->key)
            x = x->left;
        else
            x = x->right;
    }

    z->parent = it;
    if(it == nil)
        root = z;
    else{
        if(z->key < it->key)
            it->left = z;
        else
            it->right = z;
    }
}

void inorder(node* u){
    if(u == nil)
        return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(node* u){
    if(u == nil)
        return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n,x;
    string cmd;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> cmd;
        if(cmd == "insert"){
            scanf("%d",&x);
            insert(x);
        }else if(cmd == "print"){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }
}


Measured memory_bytes: 26616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n, W;
	cin >> n >> W;
	ll w[n+1], v[n+1];
	rep(i, 1, n+1){
		cin >> w[i] >> v[i];
	}
	ll dp[W+1];
	memset(dp, 0, sizeof(dp));
	rep(i, 1, n+1){
		rrep(j, W, 0){
			if(j+w[i] <= W){
				dp[j+w[i]] = max(dp[j]+v[i], dp[j+w[i]]);
			}
		}
	}
	print(dp[W])
	return 0;
}

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

int dp0[105][4];
int dp1[105][4];

int main() {
  string n;
  int k;
  cin >> n;
  cin >> k;
  int l = n.size();

  dp0[0][0] = 0;
  dp1[0][0] = 1;

  for ( int i = 0; i < l; i++ ) {
    int now_d = n[i]-'0';
    // 0
    for ( int j = 0; j <= k; j++ ) {
      if ( now_d != 0 ) {
        dp0[i+1][j] = dp0[i][j] + dp1[i][j];
        dp1[i+1][j] = 0;
      } else {
        dp0[i+1][j] = dp0[i][j];
        dp1[i+1][j] = dp1[i][j];
      }
    }
    // 1-9
    for ( int j = 0; j < k; j++ ) {
      for ( int d = 1; d < 10; d++ ) {
        if ( now_d > d ) {
          dp0[i+1][j+1] += dp1[i][j];
        }
        if ( now_d == d ) {
          dp1[i+1][j+1] += dp1[i][j];
        }
        dp0[i+1][j+1] += dp0[i][j];
      }
    }
  }

  cout << dp0[l][k] + dp1[l][k] << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 


//i:1枚の数，j,2枚の数,k3枚の数
double dp[301][301][301] = {0};
bool visited[301][301][301] = {false};

double rec(int i, int j, int k, int n){
  if(i==0&&j==0&&k==0) return dp[i][j][k] = 0;
  if(visited[i][j][k]) return dp[i][j][k];
  double ret = n;
  if(i) ret += i*rec(i-1,j,k,n);
  if(j) ret += j*rec(i+1,j-1,k,n);
  if(k) ret += k*rec(i,j+1,k-1,n);
  ret /= (double) i+j+k;
  visited[i][j][k] = true;
  return dp[i][j][k] = ret;
}

int main(void){
  int N;cin >> N;
  int n[4] = {0};
  REP(i,N){
    int x;
    cin >> x;
    n[x]++;
  }
  visited[0][0][0] = true;
  cout << setprecision(15);
  cout << rec(n[1],n[2],n[3],N) << endl;
  return 0;
}


Measured memory_bytes: 239872
n, k = map(int, input().split())

if k != 0:
    counter = 0
    for b in range(k+1, n+1):
        counter += (n // b) * (b - k) + (n % b) - min(n % b, k - 1)
    print(counter)
else:
    print(n ** 2)


Measured memory_bytes: 38896
n,k=map(int,input().split())
v=[i for i in list(map(int,input().split()))]

n_m=len([i for i in v if i<0])

if k>=n+n_m:
    ans=sum([i for i in v if i>=0])
else:
    a=[0]
    for l in range(1,k+1):
        for r in range(l+1):
            v_get=v[n-(l-r):]
            v_get+=v[:r]
            v_get.sort()
            z=k-l #残りの試行可能回数
            while v_get[0]<0 and z>0:
                v_get=v_get[1:]
                z+=-1
                if len(v_get)==0:
                    break
            a+=[sum(v_get)]
    ans=max(a)

print(ans)

Measured memory_bytes: 3064
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    N = int(input())
    a = list(map(int, input().split()))
    even = 0
    for factor in a:
        if factor%2 == 0:
            even += 1
        else:
            pass
    else:
        print(3**N-2**even)

Measured memory_bytes: 2940
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

while (line = lines.shift()) {
    const numbers = line.split(' ').map(Number);

    if(numbers.length > 1){
    	let sorted = numbers.sort((a,b)=> a-b);
    	let minDiff = Math.abs(sorted[0] - sorted[1]), diff = 0;
    	for(let i = 2; i < sorted.length; i++){
    		diff = Math.abs(sorted[i] - sorted[i-1]);
    		if(diff < minDiff){
    			minDiff = diff;
    		}
    	}
    	console.log(minDiff);
    }
    
    
    
}



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



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

    int a;
    cin>>a;
    if(a==1){
        cout<<"Hello World"<<endl;
    }
    else{
        int n,m;
        cin>>n>>m;
        cout<<n+m<<endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
long long gcd(long long a,long long b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int main() {
	string s;
	cin>>s;
	if(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]||s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[3]||s[0]==s[3]&&s[2]==s[1]&&s[0]!=s[2]){
	    cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
/*
 * main.cpp
 *
 *  Created on: 2020/04/09
 *      Author: SkAaO
 */

#include <iostream>

using namespace std;

int keta_sum(int num){
	int sum = 0;
	while(1){
		sum += num % 10;
		if(num / 10 == 0){
			break;
		}
		num /= 10;
	}
	return sum;
}

int main(){
	int N, A, B;
	cin >> N >> A >> B;

	int sum = 0;
	for(int i = 1; i <= N; i++){
		if(keta_sum(i) >= A && keta_sum(i) <= B){
			sum += i;
		}
	}

	cout << sum << endl;

	return 0;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int X,Y; cin>>X>>Y;
    int turu, kame, flg;

    for (turu = 0; turu <= X; turu++) {
        kame = X - turu;
        flg = (X == kame + turu) && (Y == 2 * turu + 4 * kame);
        if (flg) break;
    }
    if (flg)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3632
using System;

class Program
{

	static readonly int COUNTER_CLOCKWISE = 1;
	static readonly int CLOCKWISE = -1;
	static readonly int ONLINE_BACK = 2;
	static readonly int ONLINE_FRONT = -2;
	static readonly int ON_SEGMENT = 0;

	public class Vector
	{
		public double x, y;

		public Vector (double x, double y)
		{
			this.x = x;
			this.y = y;
		}

		public static Vector operator- (Vector v1, Vector v2)
		{
			return new Vector (v1.x - v2.x, v1.y - v2.y);
		}
	}

	public class Segment
	{
		public Vector p1, p2;

		public Segment (Vector v1, Vector v2)
		{
			p1 = v1;
			p2 = v2;
		}
	}

	public static double dot (Vector v1, Vector v2)
	{
		return v1.x * v2.x + v1.y * v2.y;
	}

	public static double cross (Vector v1, Vector v2)
	{
		return v1.x * v2.y - v1.y * v2.x;
	}

	static double norm (Vector v)
	{
		return v.x * v.x + v.y * v.y;
	}

	static bool intersect (Vector p1, Vector p2, Vector p3, Vector p4)
	{
		return (ccw (p1, p2, p3) * ccw (p1, p2, p4) <= 0 &&
		ccw (p3, p4, p1) * ccw (p3, p4, p2) <= 0);
	}

	static bool intersect (Segment s1, Segment s2)
	{
		return intersect (s1.p1, s1.p2, s2.p1, s2.p2);
	}

	static int ccw (Vector p1, Vector p2, Vector p3)
	{
		Vector a = p2 - p1;
		Vector b = p3 - p1;
		if (cross (a, b) > Double.Epsilon) {
			return COUNTER_CLOCKWISE;
		}
		if (cross (a, b) < -Double.Epsilon) {
			return CLOCKWISE;
		}
		if (dot (a, b) < -Double.Epsilon) {
			return ONLINE_BACK;
		}
		if (norm (a) < norm (b)) {
			return ONLINE_FRONT;
		}
		return ON_SEGMENT;
	}

	public static void Main ()
	{
		int n = int.Parse (Console.ReadLine ());
		for (int i = 0; i < n; i++) {
			string[] s = Console.ReadLine ().Split (' ');
			Segment seg1, seg2;
			Vector p1, p2, p3, p4;
			p1 = new Vector (int.Parse (s [0]), int.Parse (s [1]));
			p2 = new Vector (int.Parse (s [2]), int.Parse (s [3]));
			p3 = new Vector (int.Parse (s [4]), int.Parse (s [5]));
			p4 = new Vector (int.Parse (s [6]), int.Parse (s [7]));

			seg1 = new Segment (p1, p2);
			seg2 = new Segment (p3, p4);

			if(intersect(seg1, seg2))
			  {
			Console.WriteLine ("1");
			  } else {
			Console.WriteLine ("0");
			  }


		}
	}
}

Measured memory_bytes: 9020
#include<stdio.h>

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	
	if(a+b==c)printf("Yes\n");
	else if(c+b==a)printf("Yes\n");
	else if(a+c==b)printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;

    vector<vector<int>> jobs(M + 1);
    rep (i, N) {
        int a, b;
        cin >> a >> b;

        if (a > M) {
            continue;
        }

        jobs[a].push_back(b);
    }

    priority_queue<int> q;
    ll answer = 0;

    for (int i = 0; i < M + 1; i++) {
        for (int b: jobs[i]) {
            q.push(b);
        }

        if (!q.empty()) {
            answer += q.top();
            q.pop();
        }
    }

    cout << answer << endl;
    return 0;
}


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

int main() {
  int n;
  string S, T;
  cin >> n >> S >> T;
  int i = 0;
  while(i < n) {
    string s_substr = S.substr(i,1);
    cout << s_substr << flush;
    string t_substr = T.substr(i,1);
    cout << t_substr << flush;
    i++;
  } 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,M;
ll P;
vector<pair<int,ll>> g[3030];
vector<int> to[3030];
vector<int> rev[3030];

bool Sto[3030];
bool toN[3030];

void dfs(int now){
    Sto[now]=true;
    for(auto nex:to[now]){
        if(Sto[nex]) continue;
        dfs(nex);
    }
}

void rdfs(int now){
    toN[now]=true;
    for(auto nex:rev[now]){
        if(toN[nex]) continue;
        rdfs(nex);
    }
}

int main(){
  cin>>N>>M>>P;
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--;
    b--;
    g[a].push_back(mkp(b,P-c));
    to[a].push_back(b);
    rev[b].push_back(a);
  }

  dfs(0);
  rdfs(N-1);

  vector<ll> dist(N+1,0);
  for(int i=0;i<N;i++) dist[i]=MOD;
  dist[0]=0;

  for(int k=0;k<N;k++){
    bool ch=false;
    for(int i=0;i<N;i++){
      if(dist[i]==MOD) continue;
      for(int j=0;j<g[i].size();j++){
        int nex=g[i][j].first;
        int c=g[i][j].second;
        if(dist[nex]>dist[i]+c){
          dist[nex]=dist[i]+c;
          if(Sto[nex]&&toN[nex]) ch=true;
        }
      }
    }

    if(k==N-1&&ch){
      cout<<-1<<endl;
      return 0;
    }
  }

  if(dist[N-1]>0) cout<<0<<endl;
  else cout<<abs(dist[N-1])<<endl;

  return 0;
}


Measured memory_bytes: 768
#include <stdio.h>

int main(void) {
	int a,b,c;
	scanf("%d %d %d", &a,&b,&c);
	int d = a+b+c;
	if ( d >= 22 ) {
		printf("bust");
	} else if ( d <= 21 ) {
		printf("win");
	}
	return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int N = s.size();
  int k = t.size();
  if (t.substr(0,N) == s && N == k-1) {
    cout << "Yes" << endl;
  }
  
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int main(){
    int a,b,h; scanf("%d %d %d", &a, &b, &h);
    printf("%d\n", (a+b) * h / 2);
    return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)
#define forall(it, c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)

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

// #define DEBUG

int qry(string s) {
#ifndef DEBUG
	printf("? "); puts(s.c_str());
	fflush(stdout);
	int x; read(x);
	return x;
#else
	string ns = "Atcod3rIsGreat";
	vector <vector <int> > dp(ns.size() + 1, vector <int> (s.size() + 1, 0x3f3f3f3f));
	dp[0][0] = 0;
	rep(i, ns.size() + 1) rep(j, s.size() + 1) {
		if (i < ns.size())
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
		if (j < s.size())
			dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
		if (i < ns.size() && j < s.size())
			dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + (ns[i] != s[j]));
	}
	return dp[ns.size()][s.size()];
#endif
}

int n;

bool sub(string s) {
	return qry(s) + s.size() == n;
}

int main() {
	string alpha;
	rep(i, 26) alpha += char('A' + i);
	rep(i, 26) alpha += char('a' + i);
	rep(i, 10) alpha += char('0' + i);
	vector <int> cnt(alpha.size());
	rep(i, alpha.size()) cnt[i] = 128 - qry(string(128, alpha[i]));
	rep(i, alpha.size()) n += cnt[i];
	priority_queue <pair <int, string>, vector <pair <int, string> >, greater <pair <int, string> > > pq;
	rep(i, alpha.size()) pq.push(mp(cnt[i], string(cnt[i], alpha[i])));
	while (pq.size() > 1) {
		pair <int, string> x, y;
		x = pq.top(); pq.pop();
		y = pq.top(); pq.pop();
		string a = x.second, b = y.second;
		string c;
		int i = 0, j = 0;
		while (i < a.size() && j < b.size()) {
			string nc = c + char(a[i]) + b.substr(j);
			if (sub(nc)) c += char(a[i ++]);
			else c += char(b[j ++]);
		}
		c += a.substr(i);
		c += b.substr(j);
		pq.push(mp(c.size(), c));
	}
	printf("! "); puts(pq.top().second.c_str());
	fflush(stdout);
	return 0;
}


Measured memory_bytes: 3800
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class NiceShopping {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int M = in.nextInt();
            int[] r = new int[A];
            int[] m = new int[B];
            int minR = Integer.MAX_VALUE;
            int minB = Integer.MAX_VALUE;
            for (int i = 0; i < A; i++) {
                r[i] = in.nextInt();
                minR = Math.min(minR, r[i]);
            }
            for (int i = 0; i < B; i++) {
                m[i] = in.nextInt();
                minB = Math.min(minB, m[i]);
            }
            int min = minR + minB;
            for (int i = 0; i < M; i++) {
                int x = in.nextInt() - 1;
                int y = in.nextInt() - 1;
                int c = in.nextInt();
                min = Math.min(r[x] + m[y] - c, min);
            }
            out.println(min);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

const int INF = 1e9;

int main() {
  long long n, m;
  cin>>n>>m;
  if (n >= m / 2) {
    cout<<min(n, m / 2)<<endl;
    return 0;
  }
  cout<<n + (m - 2 * n) / 4<<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

M = int(input())

D = []
C = []
for i in range(M):
    d, c = map(int, input(). split())
    D.append(d)
    C.append(c)

tmp = 0
ans = 0
for i in range(M):
    tmp += D[i] * C[i]
    if tmp % 9 == 0:
        k = tmp // 9 - 1
        r = 9
    else:
        k = tmp // 9
        r = tmp % 9
    if tmp >= 10:
        ans += k
        tmp = r

print(ans + sum(C) - 1)

Measured memory_bytes: 12628
K = input()
A,B = input().split()
if A == B:
    ans = int(A)
    if ans % int(K) == 0:
        print('OK')
        exit()
    print('NG')
    exit()
for i in range(int(A), int(B) + 1):
    if i % int(K) == 0:
        print('OK')
        exit()
    
print('NG')
exit()

Measured memory_bytes: 9188
#include<iostream>
#include<math.h>
#include<queue>
#include<string>
using namespace std;
int main(){
	int a[100000];
	int ans=0;
	int t=0;
	int n;cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i!=0){if(a[i-1]>=a[i]){t++;}
		else{ans=max(ans,t);t=0;}}
     // cout<<t<<" ";
	}
  ans=max(ans,t);
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>

using namespace std;

int main() {
  int D, N;

  cin >> D >> N;

  int ans;
  if (N == 100)
    ans = pow(100, D) * 101;
  else 
    ans = pow(100, D) * N;

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


Measured memory_bytes: 256
import java.util.*;

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

    String a = "Sunny";
    String b = "Cloudy";
    String c = "Rainy";

    String s = sc.next();

    if (s.equals(a)) {
      System.out.println(b);
    } else if (s.equals(b)) {
      System.out.println(c);
    } else {
      System.out.println(a);
    }

  }
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

int mod = 1e9+7;
struct Mint {
    int val;
    Mint inv() const {
        int tmp, a = val, b = mod, x = 1, y = 0;
        while(b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
        return Mint(x);
    }
public:
    Mint() :val(0) {}
    Mint(ll x) :val(x >= 0 ? x % mod : x % mod + mod) {}
    int mtoi() { return this->val; }
    Mint pow(ll t) { Mint res = 1,b = *this; while(t){if(t&1)res *= b;b *= b;t >>= 1;}return res; }
    Mint& operator+=(const Mint& x) { if ((val += x.val) >= mod) val -= mod; return *this; }
    Mint& operator-=(const Mint& x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; }
    Mint& operator*=(const Mint& x) { val = (ll)val * x.val % mod; return *this; }
    Mint& operator/=(const Mint& x) { return *this *= x.inv(); }
    bool operator==(const Mint& x) const { return val == x.val; }
    bool operator!=(const Mint& x) const { return val != x.val; }
    bool operator<(const Mint& x) const { return val < x.val; }
    bool operator<=(const Mint& x) const { return val <= x.val; }
    bool operator>(const Mint& x) const { return val > x.val; }
    bool operator>=(const Mint& x) const { return val >= x.val; }
    Mint operator+(const Mint& x) const { return Mint(*this) += x; }
    Mint operator-(const Mint& x) const { return Mint(*this) -= x; }
    Mint operator*(const Mint& x) const { return Mint(*this) *= x; }
    Mint operator/(const Mint& x) const { return Mint(*this) /= x; }
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
    factorial(int maxx) {
        Fact.resize(maxx+1,Mint(1)),Finv.resize(maxx+1); rep(i,0,maxx)Fact[i+1]=Fact[i]*Mint(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*Mint(i);
    }
    Mint fact(int n,bool inv) { if(inv) return Finv[n]; else return Fact[n]; }
    Mint nPr(int n,int r) { if(n<0||n<r||r<0) return Mint(0); else return Fact[n]*Finv[n-r]; }
    Mint nCr(int n,int r) { if(n<0||n<r||r<0) return Mint(0); else return Fact[n]*Finv[r]*Finv[n-r]; }
};

int main(){
    int n,k; scanf("%d%d",&n,&k);
    vector<int> a(n);
    rep(i,0,n)scanf("%d",&a[i]);
    Mint cnt=0;
    rep(i,0,n){
        Mint s1,s2;
        rep(j,0,n)if(a[i]>a[j])s1+=1;
        rep(j,i+1,n)if(a[i]>a[j])s2+=1;
        cnt+=s2*Mint(k)+s1*Mint(k)*Mint(k-1)/Mint(2);
    }
    printf("%d\n",cnt.mtoi());
    return 0;
}

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

int main(){
	int n, x[100], y[100];
	double d1 = 0, d2 = 0, d3 = 0, di = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x[i];
	}
	for(int i = 0; i < n; i++){
		cin >> y[i];
	}
	for(int i = 0; i < n; i++){
		d1 += fabs(x[i]-y[i]);
		d2 += pow(fabs(x[i]-y[i]), 2);
		d3 += pow(fabs(x[i]-y[i]), 3);
		di = max(di, fabs(x[i]-y[i]));
	}
	d2 = sqrt(d2);
	d3 = cbrt(d3);
	cout << fixed << setprecision(5) << d1 << '\n' << d2 << '\n' << d3 << '\n' << di << endl;;
	return 0;
}


Measured memory_bytes: 3432
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <iomanip>
using namespace std;

int main(void) {
    long long a, b, x, r, tmp;
    cin >> a >> b;
    x = a * b;

    /* 自然数 a > b を確認・入替 */
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    cout << x / b;

    return 0;
}

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

int H, W;
char field[63][63];

int getf(int x, int y){
    int cnt = 0;
    for(auto dx: {-1, 0, 1}){
        for(auto dy: {-1, 0, 1}){
            int nx = x + dx; int ny = y + dy;
            if(0<=nx && nx<W && 0<= ny && ny<H && field[ny][nx] == '#') cnt++;
        }
    }
    return cnt;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> H >> W;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> field[i][j];
        }
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(field[i][j]=='.') cout << getf(j, i);
            else cout << '#';
        }
        cout << endl;
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


// snukeさんのmodint
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// mint N;
//cout << N.x << endl;




int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    vector<int> A(H);
    rep(i,H) cin >> A[i];
    vector<int> B(W);
    rep(i,W) cin >> B[i];
    ll cnt_H=0,cnt_W=0;
    ll free = 0;
    mint ans = 1;
    vector<bool> ex_H(H*W+1,false);
    for(int i=0; i<H; i++){
        if(ex_H[A[i]]){
            cout << "0\n";
            return 0;
        }
        ex_H[A[i]] = true;
    }
    vector<bool> ex_W(H*W+1,false);
    for(int i=0; i<W; i++){
        if(ex_W[B[i]]){
            cout << "0\n";
            return 0;
        }
        ex_W[B[i]] = true;
    }
    for(int i=H*W; i>=1; i--){
        if(ex_H[i] and ex_W[i]){
            free += cnt_H;
            free += cnt_W;
            cnt_H++;
            cnt_W++;
        }else if(ex_H[i]){
            ans *= cnt_W;
            free += cnt_W-1;
            cnt_H++;
        }else if(ex_W[i]){
            ans *= cnt_H;
            free += cnt_H-1;
            cnt_W++;
        }else{
            ans *= free;
            free--;
        }
        // cout << ans.x << "\n";
    }
    cout << ans.x << "\n";
    return 0;
}

Measured memory_bytes: 512
N,M=map(int,input().split())
hope=[tuple([int(i) for i in input().split()]) for j in range(M)]
hope.sort(key=lambda x:x[1])
ans=0
prebroke=0#prebroke=2 :島2と島3を結ぶ橋
for s,g in hope:
    if s<=prebroke:
        continue
    else:
        ans+=1
        prebroke=g-1
print(ans)


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

int calc(int a,int b)
{
    int cnt = 0;
    while(a > 0)
    {
        a-=b;
        ++cnt;
    }
    return cnt;
}

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int cnt1 = calc(a,d);
    int cnt2 = calc(c,b);
    if(cnt1 >= cnt2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

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

int main(){

    int n;
    cin >> n;
    set<int> a;

    rep(i,n){
        int t;
        cin >> t;
        a.insert(t);
    }

    if(a.size()==n){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;

    }

    return 0;
}

Measured memory_bytes: 9600