akhauriyash/Code-Regression huggingface dataset:
//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
#define pb push_back
#define mp make_pair
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " -> " << a << endl;
	err(++it, args...);
}

void testcase(){
	ll n,x,m;
	cin >> n >> x >> m;
	vector<ll> a(m);
	a[0] = x;
	for(ll i{1};i < m;i++){
		if(a[i-1] == 0){
			a[i] = 0;continue;
		}
		a[i] = (a[i-1]*a[i-1]) % m;
		a[i] %= m;
	}
	map<ll,int> ind;
	int start = 0,end = 0;
	for(int i{0};i < n;i++){
		if(ind.find(a[i]) != ind.end()){
			start = ind[a[i]];end = i;break;
		}
		ind[a[i]] = i;
	}
	if(n <= m){
		ll sum = 0;
		for(int i{0};i < n;i++)sum += a[i];
		cout << sum;return;
	}
	//debug(start,end);
	ll sum = 0,inter = 0;
	for(int i{0};i < start;i++){
		sum += a[i];
	}
	for(int i{start};i < end;i++){
		inter += a[i];
	}
	n -= start;
	sum += inter * (n/(end - start));
	n %= (end - start);
	for(int i{0};i < n;i++){
		sum += a[i + start];
	}
	cout << sum;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 7056
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter(System.getProperty("line.separator"));
		int n = sc.nextInt();
        String aStr = sc.next();
        int[] A = toIntAry(aStr, n);

        int q = partition(A,0,n-1);

        for (int i = 0; i < A.length; i++) {
        	if(i!=A.length-1){
        		if(i==q){
    				System.out.print("["+A[i]+"] ");
    			}else{
    				System.out.print(A[i]+ " ");
    			}
        	}else{
        		System.out.println(A[i]);
        	}
		}

	}


	private static int partition(int[] a, int p, int r) {
		//??????????±??????????????????????????´???????????????????
		int x = a[r];
		//????????????????°????????????°???????????????????????????????????????????´?
		int i = p-1;

		//?????????2?????????????´????????????????????´?????????????????????§????????????
		for(int j=p; j<r; j++){
			//????????????????°?????????£??????????°?????????°?????????????§????
			if(a[j]<=x){
				i++;
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
		//????????????????°?????????°?????????????????????????¬?????????¨?????????????????????
		int tmp = a[i+1];
		a[i+1] = a[r];
		a[r] = tmp;

		return i+1;

	}


	private static int[] toIntAry(String str, int n) {
        String[] tmp = str.split(" ");
        int[] A = new int[n];
        for (int i = 0; i < n; i++) {
			A[i] = Integer.parseInt(tmp[i]);
		}
        return A;
	}


}

Measured memory_bytes: 63568
N=int(input())
a=[0]+list(map(int,input().split()))+[0]
cost=[]
for i in range(N+1):
    cost.append(abs(a[i+1]-a[i]))
S = sum(cost)
for i in range(N):
    print(S-cost[i]-cost[i+1]+abs(a[i+2]-a[i]))

Measured memory_bytes: 14048
/**
 *    author:  tourist
 *    created: 19.12.2019 14:48:09       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  multiset<int> s(a.begin(), a.end());
  int ans = 0;
  while (!s.empty()) {
    auto it = prev(s.end());
    int x = *it;
    s.erase(it);
    int y = (1 << (32 - __builtin_clz(x))) - x;
    it = s.find(y);
    if (it != s.end()) {
      ++ans;
      s.erase(it);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 10368
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

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

  map<string, int> S_cnt;
  for(int i = 0; i < N; i++){
    string s;
    cin >> s;
    S_cnt[s]++;
  }

  vector<pair<int, string>> S_pair;
  for(auto x: S_cnt){
    S_pair.push_back(make_pair(-x.second, x.first));
  }

  sort(S_pair.begin(), S_pair.end());
  for(auto x: S_pair){
    if(x.first != S_pair[0].first){
      break;
    }
    cout << x.second << endl;
  }
}


Measured memory_bytes: 25712
import numpy as np
N, M = map(int, input().split())
AB = []
H = [int(h) for h in input().split()]
Hall = [1] * N
 
# print(H)
for i in range(M):
    a, b = map(int, input().split())
    AB.append([a, b])
    AH = H[a - 1]
    BH = H[b - 1]
    if AH >= BH:
        Hall[b - 1] = 0
    if BH >= AH:
        Hall[a - 1] = 0
 
 
print(Hall.count(1))

Measured memory_bytes: 46572
#include <bits/stdc++.h>
typedef long long int ll;
#define endl '\n'
using namespace std;
ll fact[2005],fact_inverse[2005];
const ll mod=1e9+7;
ll power(ll x,ll y,ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;

    return (y%2 == 0)? p : (x * p) % m;
}
ll modInverse(ll a,ll mod)
{ ll ans= power(a, mod-2, mod);
return ans;
}
ll ncr(ll n,ll r){
    if(r==0 || n==r)return 1;
ll ans=fact[n];
ans=ans*fact_inverse[r];
ans%=mod;
ans=(ans+mod)%mod;
ans=ans*fact_inverse[n-r];
ans=ans%mod;
ans=(ans+mod)%mod;
return ans;
}
int main(){
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
     fact[0]=1;
     fact[1]=1;
     fact_inverse[0]=fact_inverse[1]=1;
     for(int i=2;i<=2004;i++){
        fact[i]=i*fact[i-1];
        fact[i]=(fact[i]+mod)%mod;
        fact_inverse[i]=modInverse(fact[i],mod);
     }
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        if(n-3*i+i-1>=i-1)
        ans+=ncr(n-3*i+i-1,i-1);
    ans=(ans+mod)%mod;
    }
    cout<<ans%mod<<endl;
    return 0;
}


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

using ll = long long;

int n, p = -1;
ll r;

int main(){
    scanf("%d", &n);
    for(int x; n--; ){
        scanf("%d", &x);
        if(p + 1 == x) r++;
        else if(x <= p) r += x;
        else { puts("-1"); return 0; }
        p = x;
    }
    printf("%lld\n", r - 1);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    int d[n];
    rep(i, n) cin >> d[i];
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}

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

int main() {
    int N, K; cin >> N >> K;
    
    double p = 0;
    for (int i = 1; i <= N; i++) {
        int coin = 0, sum = i;
        while (sum < K) {
            sum *= 2;
            coin++;
        }
        p += pow(0.5, coin);
    }
    cout << fixed << setprecision(10);
    cout << p / N << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<cctype>
#include<string>

using namespace std;

int main()
{
  char ch;

  while(1){
    scanf("%c",&ch);
    //cinは必要なところしか読み込まないので、\nの部分まで読み込まず使えない
    if(ch=='\n'){
      cout<<endl;
      return 0;
    }
    if(isupper(ch))ch=tolower(ch);
    else ch=toupper(ch);
    cout<<ch;
  }
}


Measured memory_bytes: 3160
#include<bits/stdc++.h> 
using namespace std;
const int N=4;
const int N2=16;
const int LIMIT=100;
static const int dx[4]={0,-1,0,1};
static const int dy[4]={1,0,-1,0};
static const char dir[4]={'r','u','l','d'};
int MDT[N2][N2];
struct Puzzle{int f[N2],space,MD;};
Puzzle state;
int limit;
int path[LIMIT];
int getALLMD(Puzzle pz)
{
	int sum=0;
	for(int i=0;i<N2;i++)
	{
		if(pz.f[i]==N2)
		    continue;
		sum+=MDT[i][pz.f[i]-1];
	} 
	return sum;
}
bool isSolved()
{
	for(int i=0;i<N2;i++)
	    if(state.f[i]!=i+1)
	        return false;
	return true;
}
bool dfs(int depth,int prev)
{
	//cout<<depth<<' '<<prev<<endl;
	if(state.MD==0)
	    return true;
	if(depth+state.MD>limit)
	{
		//cout<<depth<<' '<<state.MD<<' '<<limit<<endl;
		return false;
	}		
	int sx=state.space/N;
	int sy=state.space%N;
	Puzzle tmp;
	for(int r=0;r<4;r++)
	{
		int tx=sx+dx[r];
		int ty=sy+dy[r];
		if(tx<0||ty<0||tx>=N||ty>=N)
		    continue;
		//cout<<tx<<' '<<ty<<' '<<sx<<' '<<sy<<endl;
		if(max(prev,r)-min(prev,r)==2)
		    continue;
		tmp=state;
		//cout<<MDT[tx*N+ty][state.f[tx*N+ty]-1]<<' '
		//<<MDT[sx*N+sy][state.f[tx*N+ty]-1]<<endl;
		state.MD-=MDT[tx*N+ty][state.f[tx*N+ty]-1];
		state.MD+=MDT[sx*N+sy][state.f[tx*N+ty]-1];
		//cout<<state.MD<<endl;
		swap(state.f[tx*N+ty],state.f[sx*N+sy]);
		state.space=tx*N+ty;
		if(dfs(depth+1,r))
		{
			path[depth]=r;
			return true;
		}
		state=tmp;
	}
	return false;
}
string iterative_deepening(Puzzle in)
{
	in.MD=getALLMD(in);
	for(limit=in.MD;limit<=LIMIT;limit++)
	{
		//cout<<limit<<endl; 
		state=in;
		if(dfs(0,-100))
		{
			string ans="";
			for(int i=0;i<limit;i++)
				ans+=dir[path[i]];
			return ans;
		}
	}
	return "unsolvable";
}
int main()
{
	for(int i=0;i<N2;i++)
	{
		for(int j=0;j<N2;j++)
		{
			MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
		    //cout<<MDT[i][j]<<' ';
	    }    
	    //cout<<endl;
	} 	    
	Puzzle in;
	for(int i=0;i<N2;i++)
	{
		cin>>in.f[i];
		if(in.f[i]==0)
		{
			in.f[i]=N2;
			in.space=i;
		}
	}
	///cout<<in.space<<endl;
	string ans=iterative_deepening(in);
	cout<<ans.size()<<endl;
	return 0;
}


Measured memory_bytes: 3204
package main

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

// シャッフル
func main() {
	sc := bufio.NewScanner(os.Stdin)
	s := ""
	for {
		sc.Scan()
		w := sc.Text()
		wc := len([]rune(w))
		if w == "-" {
			break
		}
		sc.Scan()
		m, _ := strconv.Atoi(sc.Text())
		for i := 0; i < m; i++ {
			sc.Scan()
			h, _ := strconv.Atoi(sc.Text())
			w = w[h:wc] + w[0:h]
		}
		s += w + "\n"
	}
	fmt.Print(s)
}



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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  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;
  }
};


int main()
{
  int n; cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];

  int ans = 0;

  rep(start, n) {
    vector<int> c(n, -1);
    queue<int> q;
    c[start] = 1;
    q.push(start);

    while(!q.empty()) {
      int now = q.front(); q.pop();
      rep(i, n) {
        if(s[now][i] == '1') {
          if(c[i] == -1) {
            c[i] = c[now]+1;
            q.push(i);
          }
          else if(abs(c[i]-c[now]) != 1) {
            cout << -1 << endl;
            return 0;
          }
        }
      }
    }
    chmax(ans, *max_element(ALL(c)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = INF;

int main()
{
ll n , k ;
cin >> n >> k ;
vector<ll> h(n+1);
rep(i, n){
  cin >> h[i+1];
}
vector<vector<ll>> dp(n-k+1, vector<ll>(n+1,INF) );
dp[0][0]=0;
rep(i,n){
  rep(j,n-k){
    rep(l,i+1){
      dp[j+1][i+1]=min(dp[j+1][i+1],dp[j][l]+max(0LL,h[i+1]-h[l]));
    }
  }
}

rep(i,n+1){
  ans=min(ans,dp[n-k][i]);
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int
max(int x, int y)
{
	return (x > y ? x : y);
}

int
main(void)
{
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);

	int max_num = max(max(A, B), C);
	int res = max_num * 10 + (A + B + C) - max_num;
	printf("%d\n", res);
	return (0);
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
ll a[200011],b[200011];

int main(){
  cin>>n;
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  ll res=0;
  rep(i,29){
    ll totcnt=0;
    vector<P> c;
    rep(j,n){
      c.push_back(P(b[j]%(1LL<<i),(b[j]>>i)&1));
    }
    sort(all(c));
    vector<ll> sum1;
    sum1.resize(n+1);
    rep(j,n){
      sum1[j+1]=c[j].se;
    }
    sum1[0]=0;
    rep(j,n)sum1[j+1]+=sum1[j];
    rep(j,n){
      ll lo=a[j]%(1LL<<i);
      ll rest=(1<<i)-lo;
      ll nb=(a[j]>>i)&1;
      ll idx=lower_bound(all(c),P(rest,-1))-c.begin();
      { // ari
        ll cnt1=sum1[n]-sum1[idx];
        ll cnt0=n-idx-cnt1;
        if(nb)totcnt+=cnt1;
        else totcnt+=cnt0;
      }
      { // nashi
        ll cnt1=sum1[idx]-sum1[0];
        ll cnt0=idx-cnt1;
        if(nb)totcnt+=cnt0;
        else totcnt+=cnt1;
      }
    }
    if(totcnt%2==1)res|=1LL<<i;
  }
  cout<<res<<endl;
  return 0;
}



Measured memory_bytes: 11236
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			double a = sc.nextDouble();
			double sum = a;

			for(int i = 2;i<=10;i++){
				if(i%2 == 0){
					a = a * 2;
				}else{
					a = a / 3;
				}
				sum += a;
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 27956
package main

import "fmt"

func main() {
	var A,B,K int64
	fmt.Scan(&A,&B,&K)
	if(A>=K) {
		A = A-K
		fmt.Println(A,B)
	} else if(A<K) {
		K = K - A
		A = 0
		if(B>=K) {
			B = B - K
			fmt.Println(A,B)
		} else {
			fmt.Println(0,0)
		}
	}
}

Measured memory_bytes: 512
#include <string>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <math.h>
 
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
	int x,y;
	cin >> x >> y;
    if(y>=x){
      cout << "unsafe" << "\n";
    }else{
      cout << "safe" << "\n";
    }
  
}

Measured memory_bytes: 3608
import Control.Monad
import Data.Graph
import qualified Data.Map as M

main = do
  [n,m]<-map read.words<$>getLine
  xys<-replicateM m $ (\[a,b]->(a,b)).map read.take 2.words<$>getLine
  let graph = buildG (1,n) xys
  print.length $ components graph



Measured memory_bytes: 115068
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
    A[i] = [i+1, A[i]]

A.sort(key=lambda x:x[1])

ans=[]
for i in range(N):
    ans.append(A[i][0])

ans = map(str, ans)
print(' '.join(ans))


Measured memory_bytes: 105988
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.14159265358979;

struct UnionFind{
  vector<int> par;
  
  UnionFind(int N){
    vector<int> a(N);
    par=a;
    for(int i=0;i<N;i++){
      par[i]=i;
    }
  }
  
  int root(int x){
    if(x==par[x]){
      return x;
    }
    return root(par[x]);
  }
  
  void unite(int x,int y){
    if(root(x)==root(y)){
      return;
    }
    par[root(x)]=root(y);
    return;
  }
  
  bool same(int x,int y){
    return root(x)==root(y);
  }
};


int main(){
  ll V,E;
  cin>>V>>E;
  //vector<tuple<ll,ll,ll>> e(E);
  priority_queue<tuple<ll,ll,ll>, vector<tuple<ll,ll,ll>>, greater<tuple<ll,ll,ll>>> q;

  for(int i=0;i<E;i++){
    ll a,b,c;
    cin>>a>>b>>c;
    tuple<ll,ll,ll> e(c,b,a);
    q.push(e);
  }
  UnionFind tree(V);
  ll ans=0;
  while(!q.empty()){
    tuple<ll,ll,ll> e1=q.top();
    int a=get<2>(e1),b=get<1>(e1);
    if(!tree.same(a,b)){
      ans+=get<0>(e1);
      tree.unite(a,b);
    }
    q.pop();
  }
  cout<<ans<<endl;
    
    
}


Measured memory_bytes: 5972
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n-2):
    if (l[i]<l[i+1] and l[i+1]<l[i+2]) or (l[i]>l[i+1] and l[i+1]>l[i+2]):
        ans+=1
print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


int main()
{
	ll n,k;
	cin>>n>>k;
	vector<cpp_int>a(n);
	rep(i,n)cin>>a[i];
	cpp_int cnt1=0,cnt2=0;
	rep(i,n){
		FOR(j,i+1,n){
			if(a[i]>a[j]){
				cnt1++;
			}
		}
		rep(j,n){
			if(a[i]>a[j]){
				cnt2++;
			}
		}
	}
	cpp_int ans=cnt1*k%M+cnt2*k*(k-1)/2%M;
	ans%=M;
	cout<<ans<<endl;
}


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

const int N = 2e5 + 10;
int q[N], n;

struct Node{
	int v, num;
	bool operator < (const Node &A) const {
		if(v == A.v) return num < A.num;
		return v < A.v;
	}
}cha[N], sum[N];

int b_s(int l, int r, int x) {
	while(l < r) {
		int mid = l + r + 1 >> 1;
		if(sum[mid].num <= x) l = mid;
		else r = mid - 1;
	}
	return l;
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &q[i]);
		sum[i] = {q[i] + i, i};
		cha[i] = {i - q[i], i};
	} 
	sort(sum + 1, sum + 1 + n);
	sort(cha + 1, cha + 1 + n);
	
	
	//i > j则，枚举差，找差中比他大的 
	
	long long res = 0;
	int k = 1;
	for(int i = 1; i <= n; i++) {
		int j = i + 1;
		while(j <= n && cha[j].v == cha[i].v) j++;
		j--;
		
		int tk = k;
		while(sum[tk].v < cha[i].v) tk++;
		if(sum[tk].v == cha[i].v) {
			int temp = tk + 1;
			while(sum[temp].v == sum[tk].v) temp++;
			temp--;
			for(int a = i; a <= j; a++) {
				int t = b_s(tk, temp, cha[a].num);
				if(sum[t].num > cha[a].num);
				else res += t - tk + 1; 
			}
			tk = temp + 1;
		}
		i = j;
		k = tk;
	}
	
	printf("%lld\n", res);
}

Measured memory_bytes: 7704
def prime?(n)
  return false if n < 2
  return true  if n == 2 or n == 3
  return false if (n % 2).zero? or (n % 3).zero?
  i, step = 5, 2
  guard = Math.sqrt(n).to_i
  while i <= guard
    return false if (n % i).zero?
    i += step
    step = 6 - step
  end
  true
end

def action(n)
  return n if prime?(n)
  if n.even?
    action(n+1)
  else
    action(n+2)
  end
end

x = gets.chop.to_i

print action(x)

Measured memory_bytes: 1788
#include <stdio.h>
#define DATA 3000

int main(){
    int x, y;
    int i, j;
    int s, tmp;
    int data_1[DATA];
    int data_2[DATA];

    for(i=0; i<DATA; i++){
      scanf("%d %d", &x, &y);
      data_1[i] = x;
      data_2[i] = y;
      if(x == 0 && y == 0){
        break;
      }
    }

    for(s=0; s<i; s++){
      if(data_1[s] > data_2[s]){
          tmp = data_1[s];
          data_1[s] = data_2[s];
          data_2[s] = tmp;
      }
    }

    for(j=0; j<i; j++){
      printf("%d %d\n", data_1[j], data_2[j]);
    }

    return 0;

}


Measured memory_bytes: 1980
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N=1e5 + 7 , MOD = 1e9 + 7;
string s;
int D;
ll mem[N][102][2];
ll solve(int idx , int mod , bool ok){
    if(idx == (int)s.size())
        return (mod == 0);

    int dig = s[idx] -'0';
    if(ok) dig = 9;
    ll &ret = mem[idx][mod][ok];
    if(~ret)
        return ret;
     ret  = 0;
    for(int i = 0 ; i <= dig ; ++i){
        int ok1 = ok;
        if(i < dig){
            ok1 = 1;

        }
        ret+=solve(idx + 1 , (mod + i) % D , ok1 ) % MOD;
    }
    return ret % MOD;

}
main(){
        memset(mem , -1 , sizeof mem);
       cin >> s >> D;
       cout << (solve(0 , 0 , 0) - 1 + MOD) % MOD << endl;



}


Measured memory_bytes: 160384
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

char s[8111];
int n,x,y;
vector<int> vx,vy;
bool ok[30111];
bool check(int s,int t,vector<int>&v)
{
	memset(ok,0,sizeof(ok));
	ok[15000+s]=1;
	for(int i=0;i<(int)v.size();i++)for(int j=0;j<30111;j++)if(ok[j])
	{
		int nj=v[i]-(j-15000)+15000;
		if(nj>=0&&nj<30111)ok[nj]=1;
	}
	return ok[t+15000];
}
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	get2(x,y);
	int cx=0,cy=0,cd=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='F'){if(cd==0)cx++;else cy++;}
		else
		{
			if(cd==0)vy.pb(cy*2);
			else vx.pb(cx*2);
			cd^=1;
		}
	}
	if(check(x,cx,vx)&&check(y,cy,vy))puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	int cnt = 0;
	for (int i = 1; i <= n; i += 2)
	{
		int ch = 0;
		for (int y = 1; y <= i; y++)
		{
			if (i%y == 0)
				ch++;
		}
		if (ch == 8)
			cnt++;
	}
	printf("%d", cnt);
}

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

int main() {
  int n;
  cin >> n;
  ll snk = 1;
  for(int i=1; i<=n; i++) {
    snk *= i;
    snk %= 1000000007;
  }
  cout << snk << endl;
  return 0;
}

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

#define ll long long
using namespace std;
const int N = 3e5 + 5;

int32_t main() {
   int n, m;
   cin >> n >> m;
   int a[n];
   int cnt = 0, total = 0;
   for(int i = 0 ; i < n ; i++) {
       cin >> a[i];total += a[i];}

   for(int i = 0 ; i < n ; i++) {
       if (a[i] * 4 * m >= total ) cnt++;
   }
   if (cnt >= m) cout << "Yes";
   else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
long long f1[3000000], f2[3000000];
long long p(long long a, long long b = mod-2){
    long long ans = 1;
    while(b){
        if(b%2 == 1) ans = ans*a%mod;
        a = a*a%mod;
        b/=2;
    }
    return ans;
}
long long ncr(int a, int b){
    return f1[a]*f2[b]%mod*f2[a-b]%mod;
}
int main(){
    f1[0] = f2[0] = 1;
    for(int i=1;i<3000000;i++){
        f1[i] = f1[i-1]*i%mod;
        f2[i] = p(f1[i]);
    }
    int r1, c1, r2, c2;
    scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
    long long ans = 0;
    for(int i=r1;i<=r2;i++){
        long long res = ((ncr(i+c2+1, i+1) - ncr(i+c1+1, i+1) + mod)%mod + ncr(i+c1, i))%mod;
        ans = (ans + res)%mod;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 47104
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\n'
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    /*
    vector<ll> X(N);
    string t;
    in >> s >> t;
    vector<string> s,t;
    s.resize(N);
    ll N;
    in >> N;
    */
    
    string t;
    in >> t;

    //out << SIZE(t) <<endl;

    REP(i,SIZE(t)){
        if(t[i]=='?'){
            if(t[i-1]=='P'){
                t[i]='D';
            }else if(t[i+1]=='D'){
                t[i]='P';
            }else if(t[i+1]=='?'){
                t[i]='P';
            }else{
                t[i]='D';
            }
        }
    }

    out << t << endl;
    

    
    
}

Measured memory_bytes: 3740
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<iomanip>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in p2(in a){
  return 1LL<<a;
}
const double EPS=1e-10;
vector<vector<double> > s(2,vector<double>(6));
VVI f(2,VI(6));
double clc(double pred, in msk){
  /*
  cout<<pred<<" ";
  forn(i,6)
    cout<<(!!(msk&p2(i)));
  cout<<endl;*/
  double sm=0;
  forn(i,6){
    if(msk&p2(i))
      sm+=pred*s[0][i];
    else
      sm+=(1-pred)*s[1][i];
  }
  return sm;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  forn(z,2){
    forn(i,6){
      cin>>f[z][i];
      s[z][i]=f[z][i]/100.0;
    }
  }
  double bst=0;
  forn(msk,p2(6)){
    double mn=0;
    double mx=1;
    //  choose blue if p*s[0][i]<(1-p)*s[1][i]
    //  p*(s[0][i]+s[1][i])<s[1][i]
    // p<s[1][i]/(s[1][i]+s[0][i]);
    forn(i,6){
      if(f[1][i]==0){
	if(msk&p2(i))
	  mx=-1;
	continue;
      }
      else{
	double pcrit=s[1][i]/(s[1][i]+s[0][i]);
	if(msk&p2(i))
	  mx=min(mx,pcrit);
	else
	  mn=max(mn,pcrit);
      }
    }
    if(mn-EPS<mx){
      bst=max(bst,clc(mn,msk));
      bst=max(bst,clc(mx,msk));
    }
  }
  cout<<setprecision(15);
  cout<<(1-bst)<<endl;
  return 0;
}


Measured memory_bytes: 384
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long long int int64;
typedef vector<int64> VI64;
typedef vector<pair<int64,int64>> VII64;
typedef vector<string> VS;
typedef vector<vector<int64>> VVI;

int main()
{
    IOS;
    int64 T=1;
    //cin>>T;
    while(T--)
    {
        int64 n,i,k,j;
        cin>>n>>k;
        int64 a[n];
        for(i=0;i<n;i++)
            cin>>a[i];
        int64 dp[n];
        dp[0]=0;
        for(i=1;i<n;i++)
        {
            dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
            for(j=2;i-j>=0&&j<=k;j++)
                dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
        }
        cout<<dp[n-1];
    }

    return 0;
}

Measured memory_bytes: 1792
from math import gcd
K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        temp = gcd(i,j)
        for k in range(j,K+1):
            if i==j==k:
                ans+=gcd(temp, k)
            elif len({i,j,k}) == 2:
                ans+=gcd(temp, k)*3
            else:
                ans+=gcd(temp, k)*6
print(ans)

Measured memory_bytes: 9224
#include <iostream>
#include <algorithm>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

using namespace std;

signed main() {
  IOS;
  int a[3],N, i,j, ans=0;
  cin >> a[0] >> a[1] >> a[2] >> N;
  sort(a, a+3);
  for (i = 0; i*a[2] <= N; i++) {
    for (j = 0; j*a[1] <= N-i*a[2]; j++) {
      if ((N - i*a[2] - j*a[1]) % a[0] == 0) {
        ans++;
      }
    }
  }

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


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;
typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define range(v)                v.begin(),v.end()
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2
const int INF = numeric_limits<int>::max();

void ssolve(std::istream& in, std::ostream& out){
    string st1, st2;
    s(st1);
    s(st2);
    int m = st1.size() + 1;
    int n = st2.size() + 1;
    vvi dp(m, vi(n, 0));
    f(i, 0, m){
        f(j, 0, n){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
                continue;
            }
            if (st1[i - 1] == st2[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }else{
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    string ans;
    int i = m - 1;
    int j = n - 1;
    while(dp[i][j]){
        if(dp[i][j] == dp[i - 1][j]){
            i--;
        }else if(dp[i][j] == dp[i][j - 1]){
            j--;
        }else{
            ans += st1[i - 1];
            i--; j--;
        }
    }
    reverse(range(ans));
    p(ans);
    return;
}

class FLCS {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(0);out.tie(0);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    FLCS solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

Measured memory_bytes: 73660
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
sum=0
for i in range(0,len(b)):
    if(b[i]>=a[i]):
        sum=sum+a[i]
        b[i]=b[i]-a[i]
        if(b[i]>=a[i+1]):
            sum=sum+a[i+1]
            a[i+1]=0
        elif(b[i]<a[i+1]):
            sum=sum+b[i]
            a[i+1]=a[i+1]-b[i]
    elif(a[i]>b[i]):
        sum=sum+b[i]
print(sum)
     

Measured memory_bytes: 19648
n = int(input())
li = list(map(int,input().split()))
ans_li=[10 ** 5 + 1] * n

ans_li[0] = li[0]
for i in range(len(li)-1):
    ans_li[i] = min(li[i], ans_li[i])
    ans_li[i+1] = min(li[i], li[i+1])
ans_li[-1] = li[-1]

print(sum(ans_li))

Measured memory_bytes: 3064
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int

#define M_DEBUG 1
#define PI 3.141592653589793
#define MOD 100000007

#define DEBUG 1

int main(void) {

    ll i, n;
    cin >> n;

    vector<ll> a(n);

    ll sum = 0;

    rep (i, 0, n) {
        cin >> a[i];
        sum += a[i];
    }



    ll vsum = 0, mi = sum; 
    rep (i, 0, n) {
        vsum += a[i];
        mi = min(mi, abs(sum - 2 * vsum));
    }

    cout << mi << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll X, Y; cin >> X >> Y;
  int n = 1;
  while(X < Y) {
    X *= 2;
    n++;
  }
  if(X > Y) n--;
  cout << n << endl;
  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

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

V<int> As;
V<V<int>> G;
int dfs(int p, int v) {
   if (G[v].size() == 1) return As[v];
   V<int> rec;
   for (int i = 0; i < G[v].size(); i++) {
      int u = G[v][i];
      if (u == p) continue;
      int res = dfs(v, u);
      if (res == INF) {
         return INF;
      } else {
         rec.push_back(res);
      }
   }
   int B = 2 * As[v] - accumulate(rec.begin(), rec.end(), 0LL);
   if (B > As[v]) return INF;
   int over = 0;
   for (int i = 0; i < rec.size(); i++) {
      over += max(rec[i] - (As[v] - B), 0LL);
   }
   if (over > B) return INF;
   return B;
}

signed main()
{
   int n; cin >> n;
   As.resize(n);
   for (int i = 0; i < n; i++) {
      cin >> As[i];
   }
   G.resize(n);
   for (int i = 0; i < n-1; i++) {
      int a, b; cin >> a >> b; a--; b--;
      G[a].push_back(b);
      G[b].push_back(a);
   }

   if (n == 2) {
      cout << (As[0] == As[1] ? "YES" : "NO") << endl;
      return 0;
   }

   int root = -1;
   for (int i = 0; i < n; i++) {
      if (G[i].size() > 1) {
         root = i; break;
      }
   }

   int res = dfs(-1, root);
   cout << (res == 0 ? "YES" : "NO") << endl;

   return 0;
}


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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// AtCoder Beginner Contest 143
int main(){

    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N)cin >> a[i];
    sort(all(a));

    long long ans = 0;
    rep(i, N)rep(j, i){
        int mi = a[i], ma = a[i] + a[j];
        int tmp = lower_bound(all(a), ma) - a.begin() - i - 1;
        // debug(mi, ma, tmp);
        ans += tmp;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define vll vector<ll>
#define uset unordered_set<string>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n, b, ans = 0;
    cin >> n >> b;
    
    while(n > 0){
        ans += 1;
        n = n/b;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#!/usr/bin/env python3
import sys
import heapq


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n, m = MI()
    a = LI()
    heap = []
    for i in range(n):
        heapq.heappush(heap, a[i] * -1)

    while m > 0:
        min_ = heapq.heappop(heap) * -1
        min_ = (min_ // 2) * -1
        heapq.heappush(heap, min_)
        m -= 1
    print(sum(heap) * -1)


main()


Measured memory_bytes: 92288
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int H,W;
string S[30][30];
int main(){
	cin>>H>>W;
	REP(i,H){
	    REP(j,W){
	        cin>>S[i][j];
	    }
	}
	REP(i,H){
	    REP(j,W){
	        string s=S[i][j];
	        if(s=="snuke"){
	           string ss="A";
	           ss[0]+=j;
	           cout<<ss<<i+1<<endl;
	           break;
	        }
	    }
	}
	return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    if(n >= 30) {
        cout << "Yes";
    }
    else
        cout << "No";
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ll n,cnt=0;
  cin>>n;
  
  for(ll i=1;i<=n;i++)
  {
    ll x;
    cin>>x;
    if((i&1)&(x&1)) cnt++;
  }
  cout<<cnt<<"\n";
}

Measured memory_bytes: 3612
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int n,q,a,b;
	scanf("%d",&n);
	vector<int>v(n);
	for(int i=0;i<n;i++)scanf("%d",&v[i]);
	for(scanf("%d",&q);q--;){
		scanf("%d%d",&a,&b);reverse(v.begin()+a,v.begin()+b);
	}
	for(int i=0;i<n;i++)printf(i<n-1?"%d ":"%d\n",v[i]);
}



Measured memory_bytes: 2724
def count_low_elements(n, p)
	count = 0
	min = n + 1
	(0...n).each do |i|
		if p[i] < min
			count += 1
			min = p[i]
		end
	end
	count
end

n = gets.chomp.to_i
p = gets.chomp.split.map(&:to_i)
puts count_low_elements(n, p)


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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader buff = null;
		buff = new BufferedReader(new InputStreamReader(System.in));

		String[] box = buff.readLine().split(" ");
		int N = Integer.parseInt(box[0]);
		int A = Integer.parseInt(box[1]);
		int B = Integer.parseInt(box[2]);

		int count = 0;
		while(N > 0){
			int total = 0;
			int pre = N;
			while(pre > 0){
				total += pre % 10;
				pre = pre / 10;
				//System.out.println(" / " + pre + " " + total);
			}
			if(total >= A && total <= B){
				//System.out.println(" * " + total + " " + N);
				count += N;
			}
			N--;
		}

		System.out.println(count);
	}

	static long f() {
		long ans = 0;


		return ans;
	}
}

Measured memory_bytes: 20692
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
    int x;
    cin>>x;
    if(x<1200){
        cout<<"ABC"<<endl;
    }else{
        cout<<"ARC"<<endl;
    }
}   



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

int main()
{
    string s;
    int lens;
    const char* END = "-";

    while (1) {
        getline(cin, s);                   // 文字列

        if ((lens = s.length()) == 0) continue;

        // 改行を削除
        if (s.at(lens-1) == '\n') {
            s.resize(lens-1);
        }

        if (s.compare(END) == 0) break;     // 終了

        int num;

        cin >> num;                         // シャッフル回数

        if (num <= 0 || num > 100) continue;
    
        int h;
        string s1;
        string s2;

        for (int i = 0; i < num; i++) {
            cin >> h;                       // 文字列長
            if (h >= 1 && h < lens) {
                s1 = s.substr(0, h);
                s2 = s.substr(h, lens-h);
                s  = s2 + s1;
            }
        }

        cout << s << endl;
    }

    return 0;
}


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

typedef long long LL;
int main()
{
    LL i, j, a, b, ans=0;
    scanf("%lld%lld",&a,&b);
    if(a == b)
        return 0*puts("1");
    for(i=60; i>=0; --i)
    {
        if((b>>i&1)^(a>>i&1))
            break;
        if(a>>i&1) a ^= 1LL<<i;
    }
    for(j=i-1; j>=0; --j)
        if(b>>j&1)
        {
            ans += (1LL<<j+1)-1;
            break;
        }
    ans += ((1LL<<i)-a)<<1;
    if(j != -1 && a <= (1LL<<j+1)-1) ans -= (1LL<<j+1)-a;
    printf("%lld\n",ans+(i!=0));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define __STDC_LIMIT_MACROS
#include <stdint.h>
using namespace std;
#define int             long long
#define endl '\n'	 
bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;
	
	}
	return true;
}

void c_p_c()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 
}
bool how(pair<int,int> a, pair<int, int>b)
{
	return a.second<b.second;
}

int32_t main()

{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//c_p_c();
	int x;
	cin>>x;
	if(360%x==0)
	{
		cout<<360/x<<endl;
	}
	else
	{
		int ans = 0;
		for(int i = 1; i<=1000000; i++)
		{
			if((360*i)%x==0)
			{
				cout<<(360*i)/x<<endl;
				return 0;
			}
		}
	}
}



Measured memory_bytes: 3664
#include <iostream>
using namespace std;
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

typedef vector<int8_t> T;


int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<T, int> cnt;
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        T v(26, 0);
        string s;
        cin >> s;
        for (auto &c : s)
            v[c - 'a']++;
        ans += cnt[v]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16124
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;
const int M = 2e6 + 5;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1LL;
   if(pow < 0) return 0;
   base %= mod;
   while(pow!=0){if(pow&1LL==1LL){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2LL;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;ll c = (a * b)%mod;return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(2e6 + 7)] , inv_fac[(int)(2e6 + 7)];
void precomp_factorial(){fac[0] = 1;for(ll i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(ll i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};

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

   for(int i = 1; i <= 9; i++){
       if(n%i == 0){
           if(n/i < 10){
               cout << "Yes"; return 0;
           }
       }
   }
   cout << "No";

}


Measured memory_bytes: 256
n = int(input())
a = [[] for i in range(n)]

for i in range(n):
    v = list(map(int, input().split()))
    u = v[0] - 1
    for j in v[2:]:
        a[u].append(j-1)

d = [-1] * n
isDiscovered = [False] * n

def bfs(x):
    for i in a[x]:
        if not isDiscovered[i]:
            isDiscovered [i] = True
            d[i] = d[x] + 1

d_ = 0
isDiscovered [0] = True
d[0] = 0
bfs(0)

flag = True
while flag:
    flag = False
    for i in range(n):
        if d[i] is d_ :
            flag = True
            bfs(i)
    d_ += 1

for i in range(n):
    print(i+1, d[i])

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

signed main(void)
{
	string s;
	int n;
	long long cnt;
	map<char, long long> mp;

	cin >> s;
	cnt = 1000000000000000000;
	n = s.size();
	mp['0'] = 0;
	mp['1'] = 0;
	rep(i, n)
	{
		mp[s[i]]++;
	}
	for(auto p : mp)
	{
		cnt = min(cnt, p.second);
	}
	cout << (long long)cnt * 2<< endl;
	return 0;
}


Measured memory_bytes: 512