akhauriyash/Code-Regression huggingface dataset:
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repb(i,n) for(ll i=(n-1);i>=0;i--)
#define all(a) a.begin(),a.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

int main(){
    ll n; cin >> n;
    auto dp = v<>(n+1,0);
    rep(i,n){
        dp[i+1] = dp[i]+i+1;
    }
    
    auto it = lower_bound(all(dp),n);
    while(n!=0){
        cout << it-dp.begin() << endl;
        n-=(it-dp.begin());
        it = lower_bound(all(dp),n);
    }

    return 0;
}

Measured memory_bytes: 78336
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;
int main() {
	char x, y;
	cin >> x >> y;
	if (x > 'F' || y > 'F')
		return 0;
	if (x < y) cout << "<" << endl;
	else if (x == y) cout << "=" << endl;
	else cout << ">" << endl;


	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    char s1[11],s2[11],s3[11];
    cin>>s1>>s2>>s3;
    cout<<(char)(s1[0]-'a'+'A')<<(char)(s2[0]-'a'+'A')<<(char)(s3[0]-'a'+'A')<<endl;
    return 0;
}

Measured memory_bytes: 256
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let nm = readInts()
    let (n, m) = (nm[0], nm[1])
    var aryAns = [Int](repeating: -1, count: n)
    var aryS = [Int]()
    var aryC = [Int]()
    
    for _ in 0..<m {
        let sc = readInts()
        aryS.append(sc[0])
        aryC.append(sc[1])
    }
    
    var ans = String()
    if m == 0 {
        if n == 1 {
            print(0)
            return
        }
        else {
            for i in 0..<n {
                ans += i == 0 ? "1": "0"
            }
            print(ans)
            return
        }
    }
    
    for i in 0..<m {
        if aryAns[aryS[i]-1] != -1 && aryAns[aryS[i]-1] != aryC[i]{
            print(-1)
            return
        }
        aryAns[aryS[i]-1] = aryC[i]
    }
    if aryAns[0] == 0 && aryAns.count != 1{
        print(-1)
        return
    }
    
    for i in 0..<n {
        if i == 0 && aryAns.count != 1 && aryAns[i] == -1{
            ans += "1"
            continue
        }
        ans += aryAns[i] == -1 ? "0": String(aryAns[i])
    }
    print(ans)
}

main()





Measured memory_bytes: 13648
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int K, N; cin>>N>>K;
  cout << N-K+1	<< endl;
  return 0;
}


Measured memory_bytes: 256
/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();
    
    int n = Integer.parseInt(br.readLine());
    char[] seq = br.readLine().toCharArray();
    char[] seq2 = new char[n];
    for (int i=0; i<n; i++) {
      seq2[i] = seq[i+n];
    }
    long sum = 0;
    for (int i=0; i<(1<<n); i++) {
      StringBuilder front = new StringBuilder();
      StringBuilder back = new StringBuilder();
      for (int j=0; j<n; j++) {
        if ((i&(1<<j))>0) {
          front.append(seq[j]);
        } else {
          back.append(seq[j]);
        }
      }
      front.reverse();
      back.reverse();
      char[] s1 = back.toString().toCharArray();
      char[] s2 = front.toString().toCharArray();
      int s1Index = 0;
      int s2Index = 0;
      Long[][] dp = new Long[s1.length+1][s2.length+1];
      long nWays = solve(seq2, s1, s2, s1Index, s2Index, dp);
      sum += nWays;
    }
    System.out.println(sum);
  }
  static long solve(char[] seq2, char[] s1, char[] s2, int s1Index, int s2Index, Long[][] dp) {
    if (s1Index==s1.length && s2Index==s2.length) {
      return 1L;
    }
    if (dp[s1Index][s2Index]!=null) {
      return dp[s1Index][s2Index];
    }
    long sum = 0;
    int cIndex = s1Index + s2Index;
    if (s1Index<s1.length && seq2[cIndex]==s1[s1Index]) {
      sum += solve(seq2, s1, s2, s1Index+1, s2Index, dp);
    }
    if (s2Index<s2.length && seq2[cIndex]==s2[s2Index]) {
      sum += solve(seq2, s1, s2, s1Index, s2Index+1, dp);
    }
    return dp[s1Index][s2Index] = sum;
  }
}


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

int n,m;
void chk(int i){
    if(i>=n&&!(m%i)){printf("%d",m/i);exit(0);}
}
int main(){
    scanf("%d%d",&n,&m);
    int s=sqrt(m);
    for(int i=1;i<=s;i++)chk(i);
    for(int i=s;i;i--)chk(m/i);
    return 0;
}

Measured memory_bytes: 256
package main

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

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}

type pair struct {
	name  string
	point int
	rank1 int
	rank2 int
}

func comparePoint(a, b pair) bool {
	if a.name == b.name {
		return a.point > b.point
	}
	return a.name < b.name
}

func swap(shops *[]pair, i, j int) {
	s := (*shops)[i]
	(*shops)[i] = (*shops)[j]
	(*shops)[j] = s
}

func main() {
	n := nextInt()
	shops := []pair{}

	// 初期化
	for i := 0; i < n; i++ {
		s := pair{nextString(), nextInt(), i + 1, -1}
		shops = append(shops, s)
	}

	// 順位付け
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if !comparePoint(shops[i], shops[j]) {
				swap(&shops, i, j)
			}
		}
	}
	for i := 0; i < n; i++ {
		shops[i].rank2 = i + 1
	}

	for i := 0; i < n; i++ {
		fmt.Println(shops[i].rank1)
	}
}


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

        int x,y;
        int ans = 0;
        cin>>x>>y;
        for(int i=0;i<=x;i++){
            for(int j=0;j<=x;j++){
                if(i+j==x){
                    if(i*4+j*2==y){
                        ans = 1;
                        break;
                    }
                }
            }
        }
        if(ans){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
ll rui(ll a,ll b){
    ll res=1;
    ll x=a;
    while(b){
        if(b&1){
            res=res*x%inf;
        }
        x=x*x%inf;
        b/=2;
    }
    return res;
}
signed main(){
    ll n,x;cin>>n>>x;
    vector<ll>s(n);
    rep(i,n)cin>>s[i];
    vector<vector<ll> >dp(n+1,vector<ll>(x+1));
    sort(rall(s));
    ll p=1;
    REP(i,1,n+1){
        p=p*i%inf;
    }
    vector<ll>inv(x+1);
    rep(i,x+1){
        inv[i]=rui(i,inf-2);
    }
    dp[0][x]=p;
    rep(i,n){
        rep(j,x+1){
            ll b=dp[i][j]*inv[n-i]%inf;
            if(i<n-1)dp[i+1][j]=(dp[i+1][j]+b*(n-i-1)%inf)%inf;
            dp[i+1][j%s[i]]=(dp[i+1][j%s[i]]+b)%inf;
            //cout<<dp[i][j]<<' ';
        }
        //cout<<endl;
    }
    ll ans=0;
    rep(i,min(s[n-1],x+1)){
        ans=(ans+i*dp[n][i]%inf)%inf;

    }
    cout<<ans<<endl;
}

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

int main() {
    string s;
    cin >> s;
    if (s == "ARC")cout << "ABC" << endl;
    else cout << "ARC" << endl;
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<pair<int,int> >g[20];
int ret;
int now;
int dim;
void dfs(int a,int b,int c){
	if(a&&g[a].size()==1)return ;
	ret+=c*2;
	now+=c;
	dim=max(dim,now);
	for(int i=0;i<g[a].size();i++)if(g[a][i].first!=b)dfs(g[a][i].first,a,g[a][i].second);
	now-=c;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		ret=now=dim=0;
		for(int i=0;i<20;i++)g[i].clear();
		for(int i=0;i<a-1;i++){
			int b,c,d;
			scanf("%d%d%d",&b,&c,&d);
			b--;c--;
			g[b].push_back(make_pair(c,d));
			g[c].push_back(make_pair(b,d));
		}
		dfs(0,-1,0);
		printf("%d\n",ret-dim);
	}
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N, Q = map(int, input().split())

AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a, b in AB:
  graph[a].append(b)
  graph[b].append(a)

value = [0] * (N+1)
for p, x in PX:
  value[p] += x

def dfs(v, parent):  
  for i in graph[v]:
    if i == parent:
      continue
    value[i] += value[v]
    dfs(i, v)

dfs(1, 0)    
ans = ' '.join(map(str, value[1:]))
print(ans)

Measured memory_bytes: 285864
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define int long long
#define elif else if
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string
int sum(int a){
  int b=0;
  while(a){
      b+=a%10;
      a/=10;
  }
  return b;
}
signed main(){
  int N,M,O,P=0,c=0,c2=0,crash=0,nowtab=0;
  double D,D2;
  char C;
  str S,T,U;
  cin>>N>>M>>O;
  rep(0,N){
    if(sum(i+1)>=M&&sum(i+1)<=O){
      c+=i+1;
    }
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
from sys import stdin

data = [stdin.readline().rstrip().split() for _ in range(2)]
N = [int(n) for n in data[0]]
A = [int(n) for n in data[1]]
n = N[0]

l = dict()
for i in range(n):
    l[i+1] = A[i]
ans = []
for k, v in sorted(l.items(), key=lambda x: x[1]):
    ans.append(str(k))
print(' '.join(map(str, ans)))

Measured memory_bytes: 37420
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <iostream>
#include <forward_list>
using namespace std;

#define SCAN_INT(i) scanf("%d", i)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define PRINT_INT(i) printf("%d\n", i)
#define PRINT_TWO_INT(i, j) printf("%d %d\n", i, j)
#define PRINT_THREE_INT(i, j, k) printf("%d %d %d\n", i, j, k)

int main()
{
    int a, e, dam, k;
    SCAN_INT(&a);
    SCAN_INT(&dam);
    SCAN_INT(&dam);
    SCAN_INT(&dam);
    SCAN_INT(&e);
    SCAN_INT(&k);

    if (e - a <= k)
        printf("Yay!");
    else
        printf(":(");
    return 0;
}

Measured memory_bytes: 256
//made by Sert
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 34;
const int N = (int)1e6 + 34;

typedef long long ll;

void solve() {
    int n;
    scanf("%d", &n);
    vector<int> a(n), nx(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    nx[n - 1] = n;
    for (int i = n - 2; i >= 0; i--) {
        nx[i] = (a[i + 1] == 0 ? nx[i + 1] : i + 1);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int sum = a[i];
        int xr = a[i];
        int cur = i;
        while (sum == xr) {
            cur = nx[cur];
            if (cur == n) break;
            sum += a[cur];
            xr ^= a[cur];
        }
        ans += cur - i;
    }
    cout << ans << "\n";
}

int main() {
#ifdef SERT
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    solve();
    solve();
    //solve();
    //solve();
#endif
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include<vector>
using namespace std;
typedef long long ll;
//#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i =0;i<n;++i)
//#define mod (ll)(1e9+7)
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S,T;
    cin >> S >> T;
    int x = S.length();
    int f = 0;
    if(S==T) {
        f=1;
    }else{
      for(int i = 1;i<x;i++){
          if(T.substr(x-i,i)==S.substr(0,i)&&T.substr(0,x-i)==S.substr(i,x-i)){
              f = 1;
              break;
          }
      }
    }
    if(f==1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <ctime>
#include <list>
using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
typedef pair<int,int> PI;
#ifndef M_PI
const double M_PI=acos(-1);
#endif
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int((a).size()))
#define F first
#define S second
int dx[]={0,1,0,-1,0,0},dy[]={1,0,-1,0,0,0};
int dz[]={0,0,0,0,1,-1};

int n;
double sx[30],sy[30],sz[30];

double dist(double x,double y,double z,int id){
  double tx=x-sx[id];
  double ty=y-sy[id];
  double tz=z-sz[id];
  return sqrt(tx*tx+ty*ty+tz*tz);
}

double rad(double x,double y,double z){
  double ret=dist(x,y,z,n-1);
  rep(i,n-1)ret=max(ret,dist(x,y,z,i));
  return ret;
}

typedef struct _node{
  double x,y,z,r;
  int wh;
  _node(double x,double y,double z,int wh):
    x(x),y(y),z(z),wh(wh),r(rad(x,y,z)){};

  bool operator<(const _node& rn)const{
    if(rn.wh!=wh)return rn.wh<wh;
    return rn.r<r;
  }
}node;

int tx[]={1,1,1,1,-1,-1,-1,-1};
int ty[]={1,1,-1,-1,1,1,-1,-1};
int tz[]={1,-1,1,-1,1,-1,1,-1};
double len[1000];

void solve(){
  rep(i,n)cin>>sx[i]>>sy[i]>>sz[i];
  len[0]=100;
  for(int i=1;i<1000;++i)
    len[i]=len[i-1]/2;
  double ans=10000;
  priority_queue<node> q;
  q.push(node(50,50,50,0));
  int cu=0;
  int bwh=-1;
  while(!q.empty()){
    node cur=q.top();
    q.pop();
    if(cu==1000 && cur.wh==bwh)continue;
    if(cu==1000)cu=0,bwh=cur.wh;
    ++cu;
    double rr=len[cur.wh];    
    if(ans<cur.r-rr*sqrt(3)*2+EPS)continue;
    ans=min(ans,cur.r);
    if(cur.wh>25)continue;
    node best(cur);
    bool ok=false;
    rep(i,0){
      double dx=rr*(rand()%200)/200;
      double dy=rr*(rand()%200)/200;
      double dz=rr*(rand()%200)/200;
      double tr=rad(cur.x+dx,cur.y+dy,cur.z+dz);
      if(tr+EPS<ans){
        ok=true;
        best=node(cur.x+dx,cur.y+dy,cur.z+dz,cur.wh+1);
      }
      ans=min(ans,tr);
    }
    if(ok)q.push(best);
    //printf("%.5f %.5f %.5f %.5f %.7f %d\n",cur.x,cur.y,cur.z,cur.r,ans,cur.wh);

    rep(i,8)
      q.push(node(cur.x+rr*tx[i],cur.y+rr*ty[i],cur.z+rr*tz[i],cur.wh+1));
  }

  printf("%.5f\n",ans);
}

main(){
  srand(time(NULL));
  while(cin>>n,n)
    solve();
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] ten;
        int n = sc.nextInt();
 
        ten = new int[n];
        for(int i=0;i<n;i++){
            ten[i] = sc.nextInt();
        }
        for(int i=n-1;i>=0;i--){
            System.out.print(ten[i]);
            if(i != 0){
                System.out.print(" ");
            }
        }
        System.out.print("\n");
    }
}


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

int main() {
  int N;
  scanf("%d", &N);
  int a[N];
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
  }

  int b[N+1];
  b[0] = abs(a[0]);
  b[N] = abs(a[N-1]); // ?

  long long gloss = b[0]+b[N];

  for (int i = 0; i < N-1; ++i) {
    b[i+1] = abs(a[i+1]-a[i]);
    gloss += b[i+1];
  }

  for (int i = 0; i < N; ++i){
    long long sum = gloss;
    sum -= b[i] + b[i+1];
    if(i==0) sum += abs(a[1]);
    else if(i==N-1) sum += abs(a[N-2]);
    else sum += abs(a[i+1]-a[i-1]);
    cout << sum << endl;
  }

  // cout << abs(a[])






}



Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<algorithm>
#define Number 200000
using namespace std;

int main(){
  int n,p;
  vector<int> prime_table;
  vector<int> num_table(Number,1);
  num_table[0]=num_table[1]=0;
  for(int i=2;i<Number;i++){
    if(num_table[i]){
      prime_table.push_back(i);
      for(int j=i+i;j<Number;j+=i){
	num_table[j]=0;
      }
    }
  }
  while(cin>>n>>p,n+p>-1){
    vector<int> num;
    vector<int>::iterator it=upper_bound(prime_table.begin(),prime_table.end(),n);
    int index=distance(prime_table.begin(),it);
    p--;
    for(int i=index;i<index+100;i++){
      for(int j=index;j<=i;j++){
	num.push_back(prime_table[i]+prime_table[j]);
      }
    }
    sort(num.begin(),num.end());
    cout<<num[p]<<endl;
  }
  return 0;
}

Measured memory_bytes: 2064
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
count = C
ans = 0
for _ in range(N):
    A = list(map(int, input().split()))
    for i in range(M):
        count += A[i] * B[i]
    if count > 0:
        ans += 1
    count = C
print(ans)


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

const int MAX_N = 1e+5 + 5;

int N, M;
vector<int> g[MAX_N];
bool is_used[MAX_N], is_ok[MAX_N];
vector<int> ans;
int parent[MAX_N];

void dfs(int u) {
    if (is_used[u]) return;
    is_used[u] = true;
    for (int i = 0; i < g[u].size(); i++) {
        dfs(g[u][i]);
    }
    ans.push_back(u);
}

void tsort() {
    for (int i = 0; i < N; i++) dfs(i);
    reverse(ans.begin(), ans.end());
}

int main() {
    int A, B;
    cin >> N >> M;
    for (int i = 0; i < N + M - 1; i++) {
        cin >> A >> B;
        A--, B--;
        g[A].push_back(B);
    }
    tsort();
    reverse(ans.begin(), ans.end());
    map<int, bool> MP;
    for (int i = 0; i < ans.size(); i++) {
        MP[ans[i]] = true;
        for (int j = 0; j < g[ans[i]].size(); j++) {
            int now_u = g[ans[i]][j];
            if (MP[now_u] && !is_ok[now_u]) {
                parent[now_u] = ans[i];
                is_ok[now_u] = true;
            }
        }
    }
    parent[ans[ans.size() - 1]] = -1;
    for (int i = 0; i < N; i++) {
        cout << parent[i] + 1 << endl;
    }
    return 0;
}

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type / Class / Struct Definitions:
using ll = long long;
using ull = unsigned long long;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    string s;
    int q;
    bool rev = false;
    cin >> s >> q;
    list<char> l;
    rep(i, s.size()) {
        l.push_back(s[i]);
    }
    rep(i, q) {
        int t;
        cin >> t;
        if(t == 1) {
            rev = !rev;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if(f == 1) {
                if(rev) {
                    l.push_back(c);
                } else {
                    l.push_front(c);
                }
            } else {
                if(rev) {
                    l.push_front(c);
                } else {
                    l.push_back(c);
                }
            }
        }
        //list
        /*
        for(auto itr = l.begin(); itr != l.end(); ++itr) {
            cout << *itr;
        }
        cout << endl;
        */
    }
    //list
    if(rev) {
        auto en = l.end();
        en--;
        for(auto itr = en; itr != l.begin(); --itr) {
            cout << *itr;
        }
        cout << *l.begin();
    } else {
        for(auto itr = l.begin(); itr != l.end(); ++itr) {
            cout << *itr;
        }
    }
    cout << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 9984
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  std::cin >> S;

  const std::string itoc = "abcdefghijklmnopqrstuvwxyz";
  std::unordered_map<char, i64> ctoi;
  for (const char& c : itoc) {
    ctoi.insert(std::make_pair(c, ctoi.size()));
  }
  const auto char_less = [&ctoi](const char& x, const char& y) { return ctoi[x] < ctoi[y]; };

  if (S.size() < 26) {
    std::set<char, std::function<bool(char, char)>> unappeared(itoc.begin(), itoc.end(), char_less);
    for (const char& S_i : S) {
      unappeared.erase(S_i);
    }
    std::cout << S << *unappeared.begin() << std::endl;
  } else {
    std::set<char, std::function<bool(char, char)>> appeared(char_less);
    i64 i;
    for (i = 25; i >= 0; --i) {
      if (!appeared.empty() && char_less(S[i], *appeared.rbegin())) break;
      appeared.insert(S[i]);
    }
    if (i < 0) {
      std::cout << -1 << std::endl;
    } else {
      const char S_i = S[i];
      S.resize(i);
      std::cout << S << *std::upper_bound(appeared.begin(), appeared.end(), S_i, char_less) << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y, int m) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y, int m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int h, w, n;
vector<int> vec[200010];
int ma = 1;

signed main() {
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		vec[x].push_back(y);
	}
	for (int i = 1; i <= h; i++)sort(all(vec[i])), vec[i].push_back(w + 1);
	for (int i = 1; i < h; i++) {
		if (!vec[i + 1].empty() && vec[i + 1][0] <= ma) {
			cout << i << endl;
			return 0;
		}
		if (!(upper_bound(all(vec[i + 1]), ma + 1) - lower_bound(all(vec[i + 1]), ma + 1)))ma++;
	}
	cout << h << endl;
}

Measured memory_bytes: 12800
#include <iostream>
using namespace std;
typedef long long ll;
ll dp[100005];
int B[100005];
int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    int a;
    cin >> a;
    B[a] = 1;
  }
  dp[0] = 1;
  for (int i=1; i<=N; i++) {
    if (!B[i]) {
      dp[i] = dp[i-1];
      if (i > 1) dp[i] += dp[i-2];
      dp[i] %= 1000000007LL;
    }
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll solve(ll C, const vector<pair<ll,ll>>& v){
  int N = v.size();
  ll ret = 0;
  vector<ll> dp(N, 0);

  ll sum = 0, mxdp = 0;
  rep(i,N){
    sum += v[i].second;
    ret = max(ret, sum - v[i].first);
    dp[i] = mxdp = max(mxdp, sum - (2*v[i].first));
  }

  sum = 0;
  for(int i=N-1; i>=0; i--){
    sum += v[i].second;
    ll dist = C - v[i].first;
    ll best = ((i<=0)?0:dp[i-1]) + sum - dist;
    ret = max(ret, best);
  }

  return ret;
}

int main(){
  int N;
  ll C;
  cin >> N >> C;
  vector<pair<ll,ll>> v,w;
  rep(i,N){
    ll a, b;
    cin >> a >> b;
    v.emplace_back(a,b);
    w.emplace_back(C-a,b);
  }
  reverse(ALLOF(w));
  
  ll ret = 0;
  ret = max(ret, solve(C, v));
  ret = max(ret, solve(C, w));

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 4708
#include <math.h>  /* M_PI */
#include <stdio.h>
int main (void){
	double r, s, l;
	scanf("%lf" ,&r);
	s=M_PI*r*r;
	l=M_PI*(r+r);
	printf("%8f\t%8f\n" ,s,l);

	return  0;
}

Measured memory_bytes: 652
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node{
    int key;
    Node *next,*prev;
};

Node *nil;

Node* listSearch(int key){
    Node *cur = nil ->next;         //从头结点后面的元素开始访问
    while (cur != nil && cur ->key != key){
        cur = cur -> next;
    }
    return cur;
}


void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(true){
        if(cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur ->next;
    }
    printf("\n");
}


void deleteNode(Node *t){
    if(t == nil) return;
    t->prev->next = t-> next;
    t->next->prev = t-> prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}


void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    Node* X = (Node*)malloc(sizeof(Node));
    X->key = key;
    X->next = nil->next;
    nil->next->prev = X;
    nil->next = X;
    X->prev = nil;
}


int main(){
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d",&n);
    init();
    for(i = 0; i<n; i++){
        scanf("%s%d",com,&key);
        if(com[0]=='i') {insert(key); np++; size++;}
        else if(com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F') deleteFirst();
                else if(com[6] =='L') deleteLast();
            }else{
                deleteKey(key); nd++;
            }
            size--;
        }
    }

    printList();
    return 0;
}




Measured memory_bytes: 33968
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

ll get_ans(map<pair<ll,ll>,ll>&m,ll a,ll b){
	ll cnt=0;
	for(ll i=a;i<=34;i++){
		for(ll j=b;j<=34;j++){
			if(m.find({i,j})!=m.end()){
				cnt+=m[{i,j}];
			}
		}
	}
	return cnt;
}

void update_v(vector<pair<ll,ll> >&v,ll idx,ll val){
	ll a=0,b=0,cnt=0;
//	cout<<val<<endl;
	while(val>0 && val%2==0){
		cnt++;
		val/=2;
	}
	
	a=cnt;
	while(val>0 && val%5==0){
		b++;
		val/=5;
	}
	
	v[idx]={a-9,b-9};
//	cout<<v[idx].ff<<" "<<v[idx].ss<<endl;
	return ;
}

int main(){
	io;
	ll n;
	cin>>n;
	vector<pair<ll,ll> >v(n);
	long double k=1e9;
	ll ans=0;
	map<pair<ll,ll>,ll >m;
	for(ll i=0;i<n;i++){
		long double val;
		cin>>val;
		ll t=llround(val*k);
	//	cout<<val<<" "<<t<<endl;
		update_v(v,i,t);
		m[{v[i].ff,v[i].ss}]++;
	}
	

	map<pair<ll,ll> ,ll>::iterator it1;
	map<pair<ll,ll> ,ll>::iterator it2;

	for(it1=m.begin();it1!=m.end();it1++){
		for(it2=m.begin();it2!=m.end();it2++){
			pair<pair<ll,ll>,ll> p1=*it1,p2=*it2;
			if(p1<p2){
				if(p1.ff.ff+p2.ff.ff>=0 && p1.ff.ss+p2.ff.ss>=0){
					ans+=p2.ss*p1.ss;
				}
			}else if(p1==p2){
			if(p1.ff.ff+p2.ff.ff>=0 && p1.ff.ss+p2.ff.ss>=0){
					ans+=((p1.ss*(p2.ss-1))/2);
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6348
a = [i*i for i in range(400)]
n,d = map(int,input().split())
x = []
for _ in range(n):
    x.append(list(map(int,input().split())))
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        s = 0
        for k in range(d):
            s += (x[i][k]-x[j][k])**2
        if s in a:
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ff(i,n) for(i=0;i<n;i++)
#define ll long long int
#define pb push_back
#define mp make_pair
ll bg=998244353;
void updateBIT(ll BITree[], ll n, ll index, ll val) 
{ 
    index = index + 1; 
    while (index <= n) 
    { 
        BITree[index] += val; 
        index += index & (-index); 
    } 
} 
ll *constructBITree(ll arr[], ll n) 
{ 
    ll *BITree = new ll[n+1]; 
    for (ll i=1; i<=n; i++) 
        BITree[i] = 0; 
    for (ll i=0; i<n; i++) 
        updateBIT(BITree, n, i, arr[i]); 
    return BITree; 
} 
ll getSum(ll BITree[], ll index)  
{
	ll sum =0;
    index = index + 1; 
    while (index>0) 
    { 
        sum += BITree[index]; 
        index -= index & (-index); 
    } 
    return sum; 
} 
void update(ll BITree[], ll l, ll r, ll n, ll val) 
{ 
    updateBIT(BITree, n, l, val); 
    updateBIT(BITree, n, r+1, -val); 
} 
ll gcd(ll n1, ll n2) {
    if (n2 != 0)
        return gcd(n2, n1 % n2);
    else
        return n1;
}
ll pp(string str) 
{ 
    ll l = 0; 
    ll h = str.length() - 1; 
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        { 
            return 0; 
        } 
    } 
	return 1; 
}
int main()
{
    ll t;
    t=1;
    while(t--)
    {
    	ll i,j,n,q,k=0,a=0,ans=bg;
    	string f;
    	cin>>f;
    	n=f.length();
		vector<pair<ll,ll> >vec;
    	if(f[n-1]=='1' || f[0]=='0' || f[n-2] == '0')
		  cout<<"-1";
		else
		{
		    ll l=0,r=n-2;
			while(l<=r)
			{
			     	if(f[l]!=f[r])
			     	{
			     	     cout<<"-1";
						 return 0; 	
					}
					l++;
					r--;
			}
			ll c=0,maxi=-1;
			for(i=0;i<=n/2-1;i++)
			{
			    if(f[i]=='0')
				   c++;
				else
				{
				   if(maxi!=-1)
				    vec.pb(mp(i+1,maxi+1));
				   for(j=1;j<=c;j++)
				   	vec.pb(mp(i+1,i+1-j));
				   maxi = i;	    	
				   c=0; 	
				}   	
			}
			vec.pb(mp(n,maxi+1));
			for(i=n-1;i>maxi+1;i--)
			  vec.pb(mp(n,i));
			ff(i,n-1)
			   cout<<vec[i].first<<" "<<vec[i].second<<endl;  	
		}  			    
    }
    return 0;
}

Measured memory_bytes: 3312
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        try {
            int N = Integer.parseInt(br.readLine());
 
            int x;
 
            for(int i = 1; i <= N; i++)
            {
                if(i%3 == 0){
                    System.out.printf(" %d",i);
                }else{
                    x = i;
                    do{
                        if(x%10 == 3){
                            System.out.printf(" %d",i);
                            break;
                        }
                        x /=10;
                    }while(x != 0);
                }
            }
            System.out.printf("\n");
 
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 36932
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[N], ans[N], sum;

inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}
 
inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i], sum ^= a[i];
   //cout << sum << endl;
   for (int i = 1; i <= n; i ++) cout << (a[i] ^ sum) << ' ';
   //exit (0);
}               
 
signed main () {                                       
   //#ifdef QWERTY
   //   freopen("input", "r", stdin);
   //#endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                   

Measured memory_bytes: 4376
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

c1 = input()
c2 = input()
c3 = input()

print(c1[0]+c2[1]+c3[2])







Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std;
  
 
int main(){
  std::vector<int> v;
  for(int i=0;i<3;i+=1){
       int x;
       cin >> x;
          v.push_back(x);
  }
  sort(v.begin(),v.end());
  cout << v[0]+v[1] << endl;
     
}

Measured memory_bytes: 3596
from collections import Counter


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


n, k = map(int, input().split())
aaa = list(map(int, input().split()))
MOD = 10 ** 9 + 7
bit = Bit(2001)
single = 0
for a in reversed(aaa):
    single += bit.sum(a)
    bit.add(a + 1, 1)
ans = single * k % MOD
coef = k * (k - 1) // 2 % MOD
cnt = Counter(aaa)
before = 0
for a, c in sorted(cnt.items()):
    ans = (ans + c * before * coef) % MOD
    before += c
print(ans)


Measured memory_bytes: 3564
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){
  int n;
  cin >> n;
  
  int ans1 = 0;
  int ans2 = 0;
  
  for (int i = 0; i < n; i++){
    string s1, s2;
    cin >> s1 >> s2;
    
    if(s1 > s2){
      ans1 += 3;
    } else if (s1 < s2){
      ans2 += 3;
    } else {
      ans1 += 1;
      ans2 += 1;
    }
  }
  cout << ans1 << " "<< ans2 << endl;
  
  return 0;
}  



Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

const int mod = 1000000007;
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*(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;
  }
};
void solve(){
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	mint ans;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			if(a[i]>a[j]) ans += k*(k+1)/2;
			else if(a[i]<a[j]) ans += k*(k-1)/2;
		}
	}
	cout << ans.x << endl;
}

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

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

int main(){
    int n; cin >> n;
    vector<int> b(n-1); rep(i,n-1) cin >> b[i];
    int ans = b[0];
    rep(i,n-2) ans += min(b[i],b[i+1]);
    ans += b[n-2];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0;i < N;i++)
#define pb push_back

vector<int>E[10005];
int N;
bool flag[10005] = {0};
vector<int>out;

void dfs(int v) {
  flag[v] = true;
  Rep(i,E[v].size()) {
    int nv = E[v][i];
    if(!flag[nv])dfs(nv);
  }
  out.pb(v);
}

int main()
{
  int M,s,t;
  cin >> N >> M;
  while(M--) {
    cin >> s >> t;
    E[s].pb(t);
  }
  Rep(i,N) {
    if(!flag[i])dfs(i);
  }
  reverse(out.begin(),out.end());
  Rep(i,N)cout << out[i] << endl;
  return 0;
}

Measured memory_bytes: 3904
import sys
from itertools import combinations

input = sys.stdin.readline


class UnionFind:
    """Union Find class.

    "Path compression" and "Union by rank" are used.

    References:
        <https://en.wikipedia.org/wiki/Disjoint-set_data_structure>
    """

    def __init__(self, N):
        self.N = N
        self.__make_set()

    def __make_set(self):
        self._parent = list(range(self.N + 1))
        self._rank = [0] * (self.N + 1)
        self._size = [1] * (self.N + 1)

    def find(self, x):
        if self._parent[x] != x:
            self._parent[x] = self.find(self._parent[x])
        return self._parent[x]

    def union(self, x, y):
        x_root = self.find(x)
        y_root = self.find(y)

        if x_root == y_root:
            return

        x_rank = self._rank[x_root]
        y_rank = self._rank[y_root]
        if x_rank > y_rank:
            self._parent[y_root] = x_root
            self._size[x_root] += self._size[y_root]
        elif x_rank < y_rank:
            self._parent[x_root] = y_root
            self._size[y_root] += self._size[x_root]
        else:
            self._parent[y_root] = x_root
            self._rank[x_root] += 1
            self._size[x_root] += self._size[y_root]

    def same_set(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self._size[self.find(x)]


def main():
    N, M = map(int, input().split())
    A = [0] * M
    B = [0] * M
    for i in range(M):
        A[i], B[i] = map(int, input().split())

    uf = UnionFind(N)
    ans = [0] * M
    ans[-1] = N * (N - 1) // 2
    for i in reversed(range(M - 1)):
        a, b = A[i + 1], B[i + 1]
        if uf.same_set(a, b):
            ans[i] = ans[i + 1]
        else:
            ans[i] = ans[i + 1] - uf.size(a) * uf.size(b)
        uf.union(a, b)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


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

using namespace std;

int main() {

    int n;
    cin >> n;
    std::vector<int> v(n);

    for(int i = 0 ; i < n; i++)cin >> v[i];

    sort(v.begin(), v.end());
    
    long long ans = 0LL;

    for(int j = n - 1; j >= 2; j--){
        for(int i = j - 1; i >= 1; i--){

            if(v[j] - v[i] >= v[i])break;

            int need = v[j] - v[i];
            int where = upper_bound(v.begin(), v.end(), need) - v.begin();
            ans += i - where;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
  int W, H, X, Y;
  std::cin >> W >> H >> X >> Y;

  // flip/mirror to make x<=W/2, y<=H/2, y/x<=H/W
  double w = double(W);
  double h = double(H);
  double x = double(X);
  double y = double(Y);

  int has_multi_cut = 2 * X == W && 2 * Y == H ? 1 : 0;
  std::cout << std::fixed << w * h / 2 << " " << has_multi_cut << std::endl;

  return 0;
}


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

int sod(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

  cout << ((N % sod(N) == 0) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const n = parseInt(input[0].split(" ")[0]);
    const m = parseInt(input[0].split(" ")[1]);
    let abs = Array(n+1).fill(0).map(_ => [])
    for (let i = 1; i < input.length; i++) {
        let [a, b] = input[i].split(" ").map(el => parseInt(el))
        abs[a].push(b)
        abs[b].push(a)
    }
    let dp = {}
    dp[1] = 1
    let q = [1]
    let seen = new Set()
    while (q.length > 0) {
        let id = q.shift()
        for (let key of abs[id]) {
            if (!seen.has(key)) {
                dp[key] = id
                q.push(key)
                seen.add(key)
            }
        }
    }
    if (n !== Object.keys(dp).length) {
        console.log('No')
        return
    }
    console.log('Yes')
    for (let i = 2; i <= n; i++) {
        console.log(dp[i])
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 124508
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int r,g;
    cin >> r;
    cin >> g;

    cout << g * 2 - r << endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define mx 205
#define inf 2e9
#define nitro ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int main()
{
    nitro ;
    string s,t;
    cin>>s;
    for(int i=0;i<s.length();i++)
        s[i] = 'x';
    cout<<s<<endl;
}


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

int main()
{
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;

  if (L > R)
  {
    cout << "Left" << endl;
  }
  else if (L == R)
  {
    cout << "Balanced" << endl;
  }
  else
  {
    cout << "Right" << endl;
  }
}


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

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)

template<class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}

void _main() {
        int a,b,c; cin >>a>>b>>c;
        if (a+b+c>=22)cout<<"bust";
        else cout <<"win";
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 3620