akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
int main(void) {
 
int a,b;
 
scanf("%d %d", &a, &b);
 
if(a < b)
printf("a < b\n");
 else if(a > b) 
printf("a > b\n");
 else 
printf("a == b\n");

return 0;
}

Measured memory_bytes: 2596
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

long long all_sum(string &S, int l, int num){
    long long ret = 0;
    if(l>=(int)S.size())return 0;
    ret+=stol(S.substr(l, num))*max(1,(1<<((int) S.size()-l-num-1)))+all_sum(S, l+num, 1);

    num++;
    if(l+num<=(int)S.size()){
        ret+=all_sum(S,l,num);
    }
    //cout << ret << endl;
    return ret;
}

int main(){
    string S;
    cin >> S;
    
    long long ans=all_sum(S, 0, 1);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repr(i, a, b) for(int i = a - 1; i >= b; i--)
#define iter(m) for(auto it = m.begin(); it != m.end(); it++)
#define iterr(m) for(auto it = m.rbegin(); it != m.rend(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
const ll mod = (ll)1e9 + 7;
	
int main(){
	speed;
	int n; cin >> n;
	int ans = 0;
	for(int i = 1; i <= n - 1; i++) {
		for(int j = 1; j <= n - 1; j++) {
			if(j * i >= n) break;
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	ll n, x;
	cin >> n >> x;
	const ll g = __gcd(n, x);
	n /= g;
	x /= g;
	cout << (n - 1) * 3 * g << endl;
	return 0;
}



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

int main() {
    ll h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) cout << 1 << endl;
     else cout << (h*w +1)/2 << endl;
    return 0;
}

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

int main(){
    using namespace std;
    size_t n;
    cin >> n;
    size_t p1, p2;
    cin >> p2 >> p1;
    unsigned long ans{0};
    for(size_t i = 2, p; i < n; ++i){
        cin >> p;
        ans += (p > p1 == p1 > p2);
        p2 = p1;
        p1 = p;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *p;
  struct node *r;
  struct node *l;
  int key;
};
typedef struct node * Node;
Node root;
void insert(int v){
  Node y=NIL;
  Node x=root;
  Node c;
  c=malloc(sizeof(struct node));
  c->key=v;
  c->l=NIL;
  c->r=NIL;
  while(x!=NIL){
    y=x;
    if(c->key < x->key) x=x->l;
    else x=x->r;
  }
    c->p=y;
    if(y==NIL) root=c;
    else if(c->key < y->key) y->l=c;
    else y->r=c;
}
 
void inorder(Node w){
  if(w!=NIL){
    inorder(w->l);
    printf(" %d",w->key);
    inorder(w->r);
  }
}
void preorder(Node w){
  if(w!=NIL){
    printf(" %d",w->key);
    preorder(w->l);
    preorder(w->r);
  }
}
 
int main(){
  int i,k,a;
  char com[20];
 
  scanf("%d",&k);
 
  for(i=0;i<k;i++){
    scanf("%s",com);
 
  if(com[0]=='i'){
    scanf("%d",&a);
    insert(a);
  }
  else if(com[0]=='p'){
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
  }
  }
  return 0;
}



Measured memory_bytes: 25164
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll N,ANS=0;
	vector<ll>V;
	cin>>N;
	rep(i,N){
		ll t;
		cin>>t;
		V.push_back(t);
	}
	rep(i,N){
		if(V[i]%2==0){
			ll count=0;
			for(;;){
				V[i]=V[i]/2;
				ANS++;
				if(V[i]%2!=0)break;
			}
		}
	}
	cout<<ANS<<endl;
}

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

int main(){
  long long A, B, C;
  cin >> A >> B >> C;

  if((A % 2 == 0) || (B % 2 == 0) || (C % 2 == 0)){
    cout << 0 << endl;
    return 0;
  }

  cout << min(A * B, min(B * C, C * A)) << endl;
}


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

long int a,b;
int F(long int a,long int b){
    if(a>=b){
        int cnt=0;
        while(a>0){
            a=a/10;
            cnt++;
        }
        return cnt;
    }
    else return F(b,a);
}

int main(){
  
    long int N;cin>>N;
    int ans=100;
    for(int i=1;i<=sqrt(N);i++){
        if(i*(N/i)==N){
            ans=min(ans,F(i,N/i));
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int gcd(int a, int b)
{
    if (a < b) return gcd(b, a);
    if (b == 0) return a;
    return gcd(b, a % b);
}

void _main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    int ma = 0;
    bool ok = false;
    rep(i, 0, N)
    {
        cin >> A[i];
        chmax(ma, A[i]);
        if (A[i] == K) ok = true;
    }
    int d = A[0];
    rep(i, 1, N)
    {
        d = gcd(d, A[i]);
    }
    if (ok || (K % d == 0 && ma >= K))
    {
        cout << "POSSIBLE" << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
}


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

int main(){
    ll a,b;
    cin >> a;
    if(a%2==0) cout << a << endl;
    else cout << a*2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
int main(){
    int n, k;
    cin >> n >> k;
    int l[100];
    rep(i, n) cin >> l[i];
    sort(l, l + n, greater<int>());
    int res = 0;
    rep(i, k) res += l[i];
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
int main(){
    int N,M;
    cin>>N>>M;
    
    Graph g(N);
    for(int i=0;i<M;++i){
        int A,B;
        cin>>A>>B;
        --A;--B;
        g[A].push_back(B);
        g[B].push_back(A);
    }
    
    vector<int> dist(N,-1);
    queue<int> q;
    
    dist[0]=0;
    q.push(0);
    
    while(!q.empty()){
        int v=q.front();
        q.pop();
        
        for(const int &nv:g[v]){
            if(dist[nv]!=-1)continue;
            
            dist[nv]=v;
            q.push(nv);
        }
    }
    
    bool ok=all_of(dist.cbegin(),dist.cend(),[](const int &x){return x!=-1;});
    
    if(ok){
        cout<<"Yes"<<endl;
        for(int i=1;i<N;++i)cout<<dist[i]+1<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 10152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    bool a = true;
    cin >> S;
    for (int i = 0; i < 3; i++){
        if (S[i] == S[i+1]){
            a = false;
        }
    }
    if (a == true){
        cout << "Good" << endl;
    }
    else{
        cout << "Bad" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define TASK "file"

#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long i64;
typedef long double dbl;
const dbl PI = acos(-1.0L);
const dbl EPS = 1e-12L;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

namespace task {
string s, w;
int k;
i64 r;

int main() {
  cin >> s >> k;
  for (int i = k; i < s.size(); ++i) {
    i64 t = 9;
    for (int j = 1; j < k; ++j) {
      t *= i - j;
    }
    for (int j = 1; j < k; ++j) {
      t /= j;
      t *= 9;
    }
    r += t;
  }
  w = string(s.size(), '0');
  for (int c = 1; c < 10; ++c) {
    w[0] = char('0' + c);
    if (k == 1) {
      r += w <= s;
    } else {
      for (int i = 1; i < s.size(); ++i) {
        for (int x = 1; x < 10; ++x) {
          w[i] = char('0' + x);
          if (k == 2) {
            r += w <= s;
          } else {
            for (int j = i + 1; j < s.size(); ++j) {
              for (int y = 1; y < 10; ++y) {
                w[j] = char('0' + y);
                r += w <= s;
                w[j] = '0';
              }
            }
          }
          w[i] = '0';
        }
      }
    }
    w[0] = '0';
  }
  cout << r << '\n';
  return 0;
}
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(11);
  cout.setf(ios::fixed);
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#elif defined(TASK)
  freopen(TASK".in", "r", stdin);
  freopen(TASK".out", "w", stdout);
#endif
  return task::main();
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <utility>
using namespace std;
#define fol(i,n) for (int i=0;i<n;i++)

int main(){
    string a,b,c;
    cin >>a>>b>>c;
    cout <<"A"<<b.front()<<"C" <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for( auto &i : a ) cin >> i;
	ll sum = 0;
	int r = 0;
	ll ans = 0;
	for( int l = 0; l < n; ++l ){
		while( r < n && ( sum^a[r] ) == ( sum+a[r] ) ){
			sum += a[r];
			++r;
		}
		ans += r-l;
		if( l == r ) ++r;
		else sum -= a[l];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (a, b) = readLongList()
    val aFactors = primeFactor(a).keys
    val bFactors = primeFactor(b).keys
    println((aFactors.intersect(bFactors)).size + 1)
}

/*!
    O(n^(1/2)) // n * n <= Long.MAX_VALUE n <= 10^8 or more
 */
fun primeFactor(n: Long): Map<Long, Long> {
    val factorMap = mutableMapOf<Long, Long>()

    var target = n
    var i = 2L
    while (i * i <= target) {
        while (target % i == 0L) {
            factorMap[i] = factorMap.getOrElse(i) { 0L } + 1L
            target /= i
        }
        i++
    }

    if (target != 1L) { factorMap[target] = 1 }
    return factorMap
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 37928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	ll N;
	cin >> N;
	ll ki=0;
	FOR(i,0,N){
		ll k;cin >> k;
		if(k&1)ki++;
	}
	if(ki&1){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

ll get(vl &B, ll L, ll R) {
  ll res = B[R];
  if (L > 0)
    res -= B[L - 1];
  return res;
}

ll func(vvl &DP, vvl &used, vl &B, ll L, ll R) {
  if (L == R)
    return 0;
  if (used[L][R])
    return DP[L][R];
  used[L][R] = 1;
  ll res = llINF;
  FOR(c, L, R) {
    res = min(res, func(DP, used, B, L, c) + func(DP, used, B, c + 1, R) +
                       get(B, L, R));
  }
  return DP[L][R] = res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N);
  vl B(N);
  REP(i, N) { cin >> A[i]; }
  B[0] = A[0];
  FOR(i, 1, N) B[i] = A[i] + B[i - 1];
  vvl DP = VVL(405, 405, 0);
  vvl used = VVL(405, 405, 0);

  cout << func(DP, used, B, 0, N - 1) << endl;

  return 0;
}


Measured memory_bytes: 3072
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N =  sc.nextInt();
		String s = sc.next();
		int n = 0;

		for(int i = 0;i < s.length() - 1;i++){
			if(s.charAt(i) != s.charAt(i+1)){
				n++;
			}
		}

		System.out.println(n + 1);
	}
}


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... Args> void rd(Args&... args) {((cin >> args), ...);}
template<typename... Args> void wr(Args... args) { ((cout << args << " "), ...); cout<<endl;}

bool check(vector<pii>& s){
    int h=0;
    for(auto it:s){
        if(h+it.F<0) return false;
        h+=it.S;
    }
    return true;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<pii> ls,rs;
    int tot=0;
    forn(i,n){
        string s;
        cin>>s;
        int tsum=0,tmn=0;
        for(auto ch:s){
            tsum+=(ch=='('?1:-1);
            tmn=min(tmn,tsum);
        }
        if(tsum>0) ls.pb({tmn,tsum});
        else rs.pb({tmn-tsum,-tsum});
        tot+=tsum;
    }
    sort(all(ls),greater<pii>());
    sort(all(rs),greater<pii>());
    if(check(ls)&&check(rs)&&tot==0) cout<<"Yes";
    else cout<<"No";
    return 0;
}



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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*{
  }*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

int n;
vector<P> es[101010];

int dist[101010];

int dfs(int v, int p, int d){
  dist[v] = d;
  for(auto e : es[v]) if(p != e.first) {
    dfs(e.first, v, d+e.second);
  }
}

signed main() {
  cin >> n;
  rep(i, 0, n-1){
    int a, b, c;
    cin >> a >> b >> c;
    es[a-1].emplace_back(b-1, c);
    es[b-1].emplace_back(a-1, c);
  }

  int q, k;
  cin >> q >> k;
  vi x(q), y(q);
  rep(i, 0, q) cin >> x[i] >> y[i];

  dfs(k-1, -1, 0);

  rep(i, 0, q){
    int ans = dist[x[i]-1] + dist[y[i]-1];
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
  	cin>>a[i];
  }
  int dp[n];
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
  	dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  }
              cout<<dp[n-1];
}


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

int main(){
    ll a,b,k; cin>>a>>b>>k;
    if(a>=k) cout<<a-k<<" "<<b<<endl;
    else if((a+b)>=k) cout<<0<<" "<<a+b-k<<endl;
    else cout<<0<<" "<<0<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    vvl w(n,vl(n)),v(n,vl(n));
    rep(i,n){
        rep(j,n){
            cin >> w[i][j];
            v[i][j]=w[i][j];
        }
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                chmin(w[i][j],w[i][k]+w[k][j]);
            }
        }
    }
    bool check=false;
    rep(i,n){
        rep(j,n){
            if(w[i][j]!=v[i][j])check=true;
        }
    }
    if(check){
        cout << -1 <<endl;
        return 0;
    }
    ll ans=0;
    rep(i,n){
        rep(j,n){
            bool e=true;
            rep(k,n){
                if(k==i||k==j)continue;
                if(v[i][j]==v[i][k]+v[k][j]){
                    e=false;
                }
            }
            if(e)ans+=v[i][j];
        }
    }
    cout <<ans/2 <<endl;
}

Measured memory_bytes: 1664
n=int(input())
s=list(input())
def func(a,b):
  ans=[a,b] #True:S, False:W
  for i in range(1,n):
    if s[i]=='o':
      if ans[-1]:
        ans.append(ans[-2])
      else:
        ans.append(not ans[-2])
    else:
      if ans[-1]:
        ans.append(not ans[-2])
      else:
        ans.append(ans[-2])
  if ans[0]==ans[-1]:
    flg=False
    if s[0]=='o' and a and ans[1]==ans[-2]:
      flg=True
    elif s[0]=='o' and not a and ans[1]!=ans[-2]:
      flg=True
    elif s[0]=='x' and a and ans[1]!=ans[-2]:
      flg=True
    elif s[0]=='x' and not a and ans[1]==ans[-2]:
      flg=True
    if flg:
      print(''.join(['S' if ansi else 'W' for ansi in ans[:-1]]))
      exit()
func(True,True)
func(True,False)
func(False,True)
func(False,False)
print(-1)


Measured memory_bytes: 6296
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <array>
#include <cmath>

using namespace std;

using ll = long long int;

// GCDを計算します
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
    if (a < b) {
        NumType tmp = a;
        a = b;
        b = tmp; 
    }

    NumType r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

template <class T>
T calcLCM(T a, T b) {
    return a*b/calcGCD(a, b);
}

// 約数を数えます
template <typename NumType>
NumType cntDivisor(const NumType & num) {
    NumType cnt = 0;
    for(NumType i = 1; i * i <= num; ++i) {
        if(num % i == 0) {
            cnt++;
            if(i * i != num) cnt++;
        }
    }

    return cnt;
}

// [beg, end)の範囲を，添え字indexでループするfor文に置換します
#define FOR_RANGE(index, beg, end)     for (ll index = beg; index < N; ++index)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

template<class T>
T min(T a, T b) {
    return (a < b) ? a : b;
}

template<class T>
T max(T a, T b) {
    return (a > b) ? a : b;
}

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


int main() {
    using int_t = int64_t;

    int_t N;
    std::array<int_t, 200000> A;
    
    cin >> N;

    for (int_t i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    std::array<int_t, 200000> B; // ans
    for (int i = 0; i < N; i++) B[i] = 0;

    for (int_t i = N - 1; i >= 0; i--) {
        int_t sum = 0;
        int_t num = i + 1;
        
        for (int_t s = 2 * num; s <= N; s += num) {
            sum += B[s-1];
        }

        if (sum % 2 != A[i]) {
            B[i] = 1;
        }
    }

    int_t numofBox = 0;
    for (int_t i = 0; i < N; i++) { 
        if (B[i] == 1) numofBox++;
    }

    cout << numofBox;
    for(int_t i = 0; i < N; i++) {
        if (B[i] == 1) {
            cout << '\n' << i+1;
        }
    }

    return 0;
}



Measured memory_bytes: 4096
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a <= b) {
			System.out.println(a);
		} else {
			System.out.println(a - 1);
		}
		
	}
}

Measured memory_bytes: 23892
import java.util.*;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		sc.close();
		long R = 0;
		long G = 0;
		long B = 0;
		for(int i = 0; i < N; i++) {
			char ch = S.charAt(i);
			if(ch == 'R')R++;
			else if(ch == 'G')G++;
			else B++;
		}
		long count = 0;
		for(int i = 1; i <= (N - 1) / 2; i++) {
			for(int j = 0; j < N-(i * 2); j++) {
				char ch1 = S.charAt(j);
				char ch2 = S.charAt(j+i);
				char ch3 = S.charAt(j+(i*2));
				if(ch1 != ch2 && ch2 != ch3 && ch1 != ch3)count++;
			}
		}
		System.out.println(R*G*B-count);
	}
}

Measured memory_bytes: 36436
n = int(input())
c, s, f = [], [], []
for i in range(n-1):
  i, j, k = map(int, input().split())
  c.append(i)
  s.append(j)
  f.append(k)

for i in range(n - 1):
  time = s[i] + c[i]
  i += 1
  while i < n - 1:
    if time < s[i]:
      time = s[i] + c[i]
    else:
      time += (f[i] - (time - s[i]) % f[i]) % f[i] + c[i]
    i += 1
  print(time)

print(0)

Measured memory_bytes: 3188
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = set([int(input()) for _ in range(n)])

for i in range(3):
    flag = True
    for j in range(3):
        if not a[i][j] in b:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

for i in range(3):
    flag = True
    for j in range(3):
        if not a[j][i] in b:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

flag = True
for i in range(3):
    if not a[i][i] in b:
        flag = False
if flag:
    print("Yes")
    exit()

flag = True
if a[0][2] in b and a[1][1] in b and a[2][0] in b:
    print("Yes")
else:
    print("No")












Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	map<string,int> m;
	int best = 0;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		m[s]++;
		if(m[s] > best){
			best = m[s];
		}
	}
	vector<string> p;
	for(auto x : m){
		if(x.second == best)
			p.push_back(x.first);
	}
	sort(p.begin(),p.end());
	
	for(auto x : p)
		cout << x << endl;

	return 0;
}



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

typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define REPN(i,a,b) for(int i=a;i<=b;i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)

int main(void){
    #ifdef ccsnoopy
        freopen("D:/Code/in.txt","r",stdin);
    #endif
    int n,k;
    sc(n);sc(k);
    vector< vi > adjList;
    adjList.assign(n, vi());
    int fr, to;
    FOR(i,n-1){
        sc(fr);sc(to);
        fr--;to--;
        adjList[fr].pb(to);
        adjList[to].pb(fr);
    }

    queue<int> q;
    q.push(0);
    int dist[2010];

    if(k%2){
        //try each edge.
        int mxcount = 0;
        FOR(i,n){
            FOR(j,adjList[i].size()){
                if(i > adjList[i][j])continue;
                FOR(z,n)dist[z] = INF;
                dist[i] = 0;
                int nodeb = adjList[i][j];
                dist[nodeb] = 0;
                queue<int> qu;
                qu.push(i);
                qu.push(nodeb);
                int temp = 2;
                while(!qu.empty()){
                    int node = qu.front();
                    qu.pop();
                    FOR(z,adjList[node].size()){
                        int next = adjList[node][z];
                        if(dist[next] > dist[node] + 1){
                            dist[next] = dist[node] + 1;
                            if(dist[next] <= (k-1)/2){
                                temp++;
                            }
                            qu.push(next);
                        }
                    }
                }
                mxcount = max(mxcount, temp);
            }
        }
        cout<<(n-mxcount)<<endl;
    }else{
        //try each vertex.
        int mxcount = 0;
        FOR(i,n){
            FOR(j,n)dist[j] = INF;
            dist[i] = 0;
            int temp = 1;
            queue<int> qu;
            qu.push(i);
            while(!qu.empty()){
                int node = qu.front();
                qu.pop();
                FOR(i,adjList[node].size()){
                    int next = adjList[node][i];
                    if(dist[next] > dist[node] + 1){
                        dist[next] = dist[node] + 1;
                        if(dist[next] <= k/2){
                            temp++;
                        }
                        qu.push(next);
                    }
                }
            }
            mxcount = max(mxcount, temp);
        }
        cout<<(n-mxcount)<<endl;
    }

    return 0;
}




Measured memory_bytes: 512
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	ar := make([]int, n+1)
	for i := 2; i <= n; i++ {
		s := i
		a := 2
		for s != 1 {
			if s%a == 0 {
				s /= a
				ar[a]++
			} else {
				a++
			}
		}
	}
	f(1, n+1, 0, ar)
	fmt.Println(ans)
}

var ans = 0

func f(n, en, sum int, ar []int) {
	if sum > 75 {
		return
	}
	if n == en {
		if sum == 75 {
			ans++
		}
		return
	}
	f(n+1, en, sum, ar)
	for i := 1; i <= ar[n]; i++ {
		if sum == 0 {
			f(n+1, en, i+1, ar)
		} else {
			f(n+1, en, sum*(i+1), ar)
		}
	}
}


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

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

    int max = 0, ans = 0;
    for (int i = 1; i <= N; ++i) {
        int cur = i, cnt = 0;
        while (cur % 2 == 0) {
            cur /= 2;
            ++cnt;
        }

        if (max <= cnt) {
            max = cnt;
            ans = i;
        } 
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (long long i = 0; i < (long long) (n); ++i)
#define pb emplace_back
#define endl '\n'

template<typename T> void _dbg(const char*_s,T _h) { cerr<<_s<<" = "<<_h<<"\n"; }

template<typename T, typename... Ts> void _dbg(const char*_s,T _h,Ts... _t) {
    for(int _b=0;((_b+=*_s=='(')-=*_s==')')!=0||*_s!=',';)cerr<<*_s++;
    cerr<<" = "<<_h<<",";_dbg(_s+1,_t...);
}

#define int long long

#ifdef LOCAL
    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
    #define dbg(...)
#endif

const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, P;
string s;
int pw[N], cnt[N];

bool read() {
    if (!(cin >> n >> P >> s))
        return false;

    return true;
}

void solve(int id = 0) {
    if (P == 2 || P == 5) {
        int ans = 0;

        forn (i, n)
            if ((s[i] - '0') % P == 0)
                ans += i + 1;

        cout << ans << endl;
        return ;
    }

    pw[0] = 1;

    for (int i = 1; i <= n; ++i)
        pw[i] = 10 * pw[i - 1] % P;

    int cur = 0, ans = 0;
    cnt[0] = 1;

    forn (i, n)
        ++cnt[(cur += pw[n - i - 1] * (s[i] - '0')) %= P];

    forn (i, P)
        ans += cnt[i] * (cnt[i] - 1) / 2;

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    //cin >> T;
    T = 1;

    while (read())
        solve(T++);

    return 0;
}



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

using namespace std;

int main(void){
    // Your code here
    int N; string S;
    int i;
    long long r=0,g=0,b=0;
    long long x=0,y=0,z=0;

    cin >> N >> S;

    for(i=0;i<N;i++){
        if(S.at(i)=='R')r++;
        if(S.at(i)=='G')g++;
        if(S.at(i)=='B')b++;   
    }

    long long all = r*g*b;

    for(x=0;x<N-2;x++){
        for(y=x+1;y<N-1;y++){
            z=y*2-x;
            if(z>N-1||S.at(x)==S.at(z)||S.at(y)==S.at(z)||S.at(x)==S.at(y))continue;
            all--;
        }
    }


    cout << all << endl;
}


Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
#include<complex>
using namespace std;
int main(){
	int n,a[100];
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	int ans=1000000000;
	for(int i=-100;i<=100;i++){
		int cnt=0;
		for(int j=0;j<n;j++){
			cnt+=abs(a[j]-i)*abs(a[j]-i);
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

const int N = 1e6+10;
long long int a[N], b[N], c[N];

int main () {
    long long int n;
    cin >> n;
    for(int i = 0 ; i < n-1 ; i++ ) {
        cin >> a[i];
    }
    b[0]=a[0];
    long long int ans = b[0];
    for(int i = 1 ; i < n ; i++ ) {
        if(i==n-1) {
            b[i]=a[i-1];
            ans+=b[i];
            break;
        }
        b[i]=min(a[i],a[i-1]);
        ans+=b[i];
    }
    cout << ans;
}


Measured memory_bytes: 4352
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node
{
    int x;
    int cnt;
};
node a[10];
bool cmp(node k,node w)
{
    return k.cnt<w.cnt;
}
int main()
{
    cin>>a[1].x>>a[2].x>>a[3].x>>a[4].x>>a[5].x;
    for(int i=1;i<=5;i++){
        if(a[i].x%10==0){
            a[i].cnt=0;
        }
        else{
        a[i].cnt=(a[i].x/10)*10+10;
        a[i].cnt-=a[i].x;
        }
    }
    sort(a+1,a+5+1,cmp);
    //cout<<endl;
    //for(int i=1;i<=5;i++) cout<<a[i].x<<endl;
    int sum=0;
    for(int i=1;i<5;i++){
        sum+=a[i].x;
        if(sum%10!=0) sum=(sum/10)*10+10;
    }
    sum+=a[5].x;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
function Main(input) {
  var lines = input.split('\n');
  var N = Number(lines[0]);
  var A = lines[1].split(' ');
  var A_number = [];
  for (var j = 0; j < N - 1; j ++) {
    A_number.push(Number(A[j]));
  }
  A_number.sort(function(a, b) {
    if( a < b ) return -1;
    if( a > b ) return 1;
    return 0;
  });
  var index = 0;
  var count;
  for (var i = 1; i <= N; i ++) {
    count = 0;
    while (A_number[index] == i && index < N) {
      index ++;
      count ++;
    }
    console.log(count);
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 61916
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	var a, b []int

	fmt.Scan(&N)
	for i:=0;i<N;i++ {
		var x int
		fmt.Scan(&x)
		a = append(a, x)
	}

	sort.Sort(sort.IntSlice(a))
	b = append(b, a[0])
	for _, v := range a {
		if b[len(b) - 1] < v {
			b = append(b, v)
		}
	}

	fmt.Print(len(b))
}

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

#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)

#define MOD 1000000007
#define INF 1000000000

using ll = long long int;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    double b;
    ll a,ans = 0; 
    cin >> a >> b;
    
    ans = (a*(int)round(b*100))/100;

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+10;
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
    #define eprintf(...) 42
#endif // LOCAL
using ll = long long;
ll a,b,x;

int main(){
    scanf("%lld %lld",&a,&b);
    x = __gcd(a,b);
    int ans = 1;
    for(ll i = 2 ;i * i<= x;i++){
        if(x % i == 0){
            ans ++ ;
            while(x % i == 0)
            x /= i;
        }
        if(x == 1) break;
    }
    if(x > 1) ++ ans;
    printf("%d\n",ans);
}
/*
    Good Luck
        -Lucina
*/


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

int main()
{
  char b;

  cin >> b;

  if(b == 'A') cout << 'T' << endl;
    if(b == 'T') cout << 'A' << endl;
      if(b == 'C') cout << 'G' << endl;
        if(b == 'G') cout << 'C' << endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  string S;
  cin >> S;
  for (auto &s: S) {
    s -= '0';
  }

  vector<llong> dp(2019, 0);
  dp[S[0]] = 1;
  llong ans = 0;
  for (int i = 1; i < S.size(); ++i) {
    vector<llong> next(2019, 0);
    next[S[i]] = 1;
    for (int j = 0; j < 2019; ++j) {
      next[(10*j + S[i]) % 2019] += dp[j];
    }
    ans += next[0];
    swap(dp, next);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
ll mod = 1000000007;
double pi = 3.14159265358979;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

int main() {
  for (int i = 0; i < 5; i++) {
    int x;
    cin >> x;
    if (x == 0) cout << i + 1 <<endl;
  }
}

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

const int N = 1111111;

#define int long long

int P[N];
bool vis[N];

int n , A , B;

int dn(int x , int y) {
	return (x / y);
}

bool pd(int x) {
	return (n - x) + dn(x , B) >= A;
}

void solve(int l , int r) {
	int it = r;
	for(int i = l;i <= r;++ i) P[i] = it --;
} 

main(void) {
	cin >>n >> A >> B;
	if(A * B < n || A + B > n + 1) {
		puts("-1"); return 0;
	}
	int l = 0 , r = n , res = -1;
	while(l <= r) {
		int mid = (l + r) >> 1;
		if(pd(mid)) {
			l = mid + 1; res = mid;
		}
		else r = mid - 1;
	}
	int it = 0;
	int now = 1;
	while(now <= res) {
		solve(now , min(now + B - 1 , n));
		now += B;
	}
	for(int i = 1;i <= res;++ i) vis[P[i]] = 1;
	now = 1;
	for(int i = res + 1;i <= n;++ i) {
		while(vis[now]) ++ now;
		P[i] = now;
		++ now;
	}
	for(int i = 1;i <= n;++ i) cout << P[i] <<" ";
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define speed ios::sync_with_stdio(false)
#define pb push_back
#define mp make_pair
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define all(x) (x).begin(), (x).end()
#define uint usigned int
typedef vector <ll> vi;
ll MOD = 1e9+7;
//vi v1[200005],v2;
//bool visit[200005]={false};
/*void bfs(ll n){
    queue<ll> q;
    q.push(n);
    visit[n]=true;
    while(!q.empty()){
        ll t=q.front();
        q.pop();
        v2.pb(t);
        for(ll i=0;i<v1[t].size();i++){
            if(visit[v1[t][i]]==false){
                q.push(v1[t][i]);
                visit[v1[t][i]]=true;
            }
        }
    }
}*/
/*void dfs(ll n){
    for(ll i=0;i<v1[n].size();i++)
    {
        ll y=v1[n][i];
        if(visit[y]==0)
        {
            v2.pb(y);
            visit[y]=1;
            dfs(y);
        }
    }
}*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    ll n,i,h,j,x=0,p=0,y=0,sum=0,m=0,ans=1,error=0;
    cin>>n>>m;
    cout<<n-m+1;
    
    
    return 0; 
}



Measured memory_bytes: 256
def main():
    N, A, B = list(map(int, input().split(' ')))
    assert 1 <= A < B <= N
    if (B - A) % 2 == 0:
        print((B - A) // 2)
    else:
        if B - 1 <= N - A:
            print(A + max([0, B - A - 1]) // 2)
        else:
            print(N - B + 1 + max([0, B - A - 1]) // 2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E15;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

 
int main(){fastio
    ll n,k;cin>>n>>k;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=0;
    rep(i,0,n-1){
        rep(j,i+1,n-1){
            if(a[i]>a[j])Add(ans,k);
        }
    }
    sort(a,a+n);
    ll K=mod(k*(k-1)/2);
    rep(i,0,n-1){
        ll p=a+n-upper_bound(a+i,a+n,a[i]);
        Add(ans,p*K);
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}   
int cnt[maxn];

signed main()
{
    showoff;
    int n,ans = 0;
    cin >> n;
    vector<int>v(n+5);
    FOR(i,1,n+1){
        cin >> v[i];
        cnt[v[i]]++;
    }
    FOR(i,1,n+1)ans += (cnt[i]*(cnt[i]-1))/2;
    FOR(i,1,n+1){
        int c = ans-(cnt[v[i]]*(cnt[v[i]]-1))/2;
        int x = cnt[v[i]]-1;
        c += (x*(x-1))/2;
        cout << c << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...#include <bits/stdc++.h>
 

Measured memory_bytes: 4736
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b)
      cout << "a > b" << endl;
    else if (a < b)
      cout << "a < b" << endl;
    else if (a == b)
      cout << "a == b" << endl;    
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
int main() {
       	int n, ans, total, flag = 0;
       	cin >> n;
       	vector<int> arr(n);
       	for(int i = 0; i < n; i++) {
       		cin >> arr[i];
       		if(arr[0] != arr[i]) {
       			flag = 1;
       		}
       	}

       	if(flag) {
       		ans = INT_MAX;
       		for(int i = -100; i <= 100; i++) {
       			total = 0;
       			for(int j = 0; j < n; j++) {
       				total += (arr[j] - i) * (arr[j] - i);
       			}
       			if(total < ans) {
       				ans = total;
       			}
       		}
       	} else {
       		ans = 0;
       	}
       	cout << ans << endl;

       	return 0;
}

Measured memory_bytes: 256
/*
Problem Source : agc-034F
Author : oier_hzy
Time : Nov 24 2019
*/

/*

*/

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

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

const ll oo = 0x3f3f3f3f3f3f3f3f;
const int N = 5001;
int a[N];
ll f[N], g[N];
int n, A, B;

int main() {
	scanf("%d%d%d", &n, &A, &B);
	for(int i = 1; i <= n; ++ i) scanf("%d", a+i);
	
	for(int i = 0; i <= n; ++ i) f[i] = g[i] = +oo;
	f[0] = 0;
	for(int i = 1; i <= n; ++ i) {
		for(int j = 0; j < a[i]; ++ j) {
			cmin(g[j], f[j] + A);
			cmin(g[a[i]], f[j]);
		}
		for(int j = a[i]; j <= n; ++ j)
			cmin(g[j], f[j] + B);
		for(int j = 0; j <= n; ++ j) f[j] = g[j], g[j] = +oo;
	}
	
	ll Ans = +oo;
	for(int i = 0; i <= n; ++ i)
		cmin(Ans, f[i]);
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main() {

	int N;
	scanf("%d",&N);
	
	long long start=0;
	
	for(int i=1;i<=N;i++){
		if( i%3 != 0 && i%5 !=0 ) {
			start += i;
		}
	}
	printf("%lld",start);
		
	
	return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>

#define MOD 1000000007

int main()
{
    int n,bucket[26] = {0},i,j;
    char s[100001];

    scanf("%d %s",&n,s);
    for (i = 0; i < n; i++)
    {
        bucket[s[i] - 'a']++;
    }

    long long ans = 1;

    for (i = 0; i < 26; i++)
    {
        ans *= bucket[i] + 1;
        ans %= MOD;
    }
    
    printf("%lld",ans - 1);
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

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

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> x(n+1);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        x[a] ^= 1;
        x[b] ^= 1;
    }

    rep(i, n){
        if(x[i+1] == 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 1024