akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
 
#define fi first
#define se second
#define endl '\n'
#define MOD(n,k) ( (n % k) + k ) % k
#define isOn(S, j) (S & (1 << j) )
#define setBit(S, j) (S | (1 << j ) )
#define LSB(S) (S & (-S))

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

    int h, w, n, a[10005], res[105][105];

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

    int c = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i%2)
                res[i][j] = c;
            else
                res[i][w-j-1] = c;
            
            a[c]--;
            if (a[c] == 0)
                c++;
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++)
            cout << res[i][j] << " ";
        cout << endl;
    }

    return 0;
}  

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int X, Y, Z, K;
ll A[1010], B[1010], C[1010];

struct edge{
    int x, y, z;

    ll culc() const {
        return A[x] + B[y] + C[z];
    }

    bool operator < (const edge& e) const {
         if(culc() != e.culc()) return culc() < e.culc();
         else if(x != e.x) return x < e.x;
         else if(y != e.y) return y < e.y;
         else return z < e.z;
    }
};

void input(){
    cin >> X >> Y >> Z >> K;

    for(int i = 0; i < X; i++){
        cin >> A[i];
    }
    for(int i = 0; i < Y; i++){
        cin >> B[i];
    }
    for(int i = 0; i < X; i++){
        cin >> C[i];
    }
}


void solve(){
    sort(A, A + X);
    sort(B, B + Y);
    sort(C, C + Z);
    X--, Y--, Z--;
    
    priority_queue<edge> q;
    set<edge> st;
    q.push(edge{X, Y, Z});
    st.insert(edge{X, Y, Z});
    for(int i = 0; i < K; i++){
        edge e = q.top();
        q.pop();

        cout << e.culc() << endl;

        if(e.x != 0){
            edge f = {e.x - 1, e.y, e. z};

            if(st.find(f) == st.end()){
                st.insert(f);
                q.push(f);
            }
        }

        if(e.y != 0){
            edge f = {e.x, e.y - 1, e. z};

            if(st.find(f) == st.end()){
            
                st.insert(f);
                q.push(f);
            }        
        }

        if(e.z != 0){
            edge f = {e.x, e.y, e.z - 1};

            if(st.find(f) == st.end()){
                st.insert(f);
                q.push(f);
            }
        }
    }
}

int main(){
    input();
    solve();
    return 0;
}

Measured memory_bytes: 768
#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};

class UnionFind{
public:
    vector<ll> par;
    vector<ll> siz;

    UnionFind(ll k):par(k), siz(k, 1LL){
        rep(i,k) par[i] = i;
    }

    ll root(ll x){
        if(par[x]==x) return x;
        else return par[x] = root(par[x]);
    }

    void unite(ll x, ll y){
        x = root(x);
        y = root(y);
        if(x==y) return;

        if(siz[x]<siz[y]) swap(x, y);
        par[y] = x;
        siz[x] += siz[y];
        return;
    }

    bool same(ll x, ll y){
        return root(x) == root(y);
    }

    ll size(ll x){
        return siz[root(x)];
    }
};

int main(){
	int n, m;
	cin >> n >> m;
	vector<P> a(m);
	rep(i,m) {
		cin >> a[i].first >> a[i].second;
		a[i].first--;
		a[i].second--;
	}
	int ans = 0;
	rep(i,m){
		UnionFind uf(n);
		rep(j,m){
			if(j==i) continue;
			uf.unite(a[j].first, a[j].second);
		}
		if(!uf.same(a[i].first, a[i].second)) ans++;
	}
	cout << ans << endl;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};

int main(){
  int n,k;cin>>n>>k;
  ll dp[2][k+10];
  ll sum[2][k+10];
  for(int i=0;i<k+10;i++)sum[1][i]=sum[0][i]=dp[0][i]=dp[1][i]=0;
  dp[0][0]=1;
  for(int i=1;i<=n;i++){
    // cout<<(i+1)%2<<endl;
    ll hoge;cin>>hoge;
    sum[(i+1)%2][0]=dp[(i+1)%2][0]%MOD;
    for(ll j=1;j<=k;j++){
      sum[(i+1)%2][j]=sum[(i+1)%2][j-1]+dp[(i+1)%2][j];
      sum[(i+1)%2][j]%=MOD;
      //cout<<sum[(i+1)%2][j]<<" ";
    }
    //sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
    // cout<<endl;
    for(ll j=0;j<=k;j++){
      if(j==min(j,hoge))dp[i%2][j]=sum[(i+1)%2][j]%MOD;
      else dp[i%2][j]=(sum[(i+1)%2][j]-sum[(i+1)%2][j-min(hoge,j)-1])%MOD;
      //cout<<dp[(i+1)%2][j]<<" ";
    }
    //cout<<endl;
  }
  cout<<(dp[n%2][k]+MOD)%MOD<<endl;
  return 0;
}

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

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int n0 = 0;
            int n1 = 0;
            for (int i = 0; i < n; ++i) {
                if (in.nextInt() % 2 == 0) ++n0;
                else ++n1;
            }
            if (n1 % 2 == 0) {
                out.println("YES");
            } else {
                out.println("NO");
            }
        }

    }

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

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

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

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

    }
}



Measured memory_bytes: 23472
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        Arrays.sort(h);
        int ans = h[k - 1] - h[0];
        for (int i = 0; i < n; i++) {
            int idx = i + k - 1;
            if (idx >= n)
                break;
            ans = Math.min(h[idx] - h[i], ans);
        }
        System.out.println(ans);
    }

}


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


int main() {
    long long A;
    cin>>A;
    long long counter=1;
    long long a=0;
    long long b[A];
    for(long long i=0; i<A;i++){
    cin>>b[i];}
    sort(b,b+A);
    if(b[0]==0){
    cout<<0<<endl;}
    else{
    for(long long i=0; i<A;i++){
    if(1000000000000000000/counter>=b[i]){
    counter=counter*b[i];}
    else{
    a++;
    break;}}
    if(a==1){
    cout<<-1<<endl;}
    else
    cout<<counter<<endl;}
}

Measured memory_bytes: 4408
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int R,C,s[10][10000];

int main(){
	while(cin>>R>>C){
		if(R+C==0)return 0;
		for(int i=0;i<R;i++)for(int j=0;j<C;j++)cin>>s[i][j];
		int ans=0;
		for(int i=0;i<pow(2,R);i++){
			for(int j=0;j<R;j++){
				if(i%(int)pow(2,j))for(int k=0;k<C;k++)s[j][k]=!s[j][k];
			}
			int a=0;
			for(int j=0;j<C;j++){
				int b=0;
				for(int k=0;k<R;k++)b+=s[k][j];
				a+=max(b,R-b);
			}
			ans=max(ans,a);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1272
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
using namespace std;

const double PI=acos(-1);

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

    vector<int> t(n);
    for(int i = 0; i < n; i++){
        cin >> t[i];
    }
    int sum = accumulate(t.begin(), t.end(), 0);

    int m;
    cin >> m;
    for(int i = 0; i < m; i++){
        int p, x;
        cin >> p >> x;
        cout << sum - (t[p-1] - x) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    X.sort()
    x_next = X[0]
    flag = [X[_] - X[_-1] for _ in range(1,M)]
    flag.sort()
    flag = flag[:M-N:]
    print(sum(flag))


Measured memory_bytes: 13968
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int d;
	cin >> d;
	cout << "Christmas";
	while (25 > d) {
		cout << ' ' << "Eve";
		d++;
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	int mn = 1000;
	int mnd = -1;
	for (int i = 0; i < N; i++) {
		if (mn > A[i]) {
			mn = A[i];
			mnd = i;
		}
	}
	vector<int> X;

	for (int i = 0; i < N; i++) {
		if (mnd != i) {
			X.push_back(i);
			A[i]--;
		}
	}
	X.push_back(mnd);
	A[mnd]--;

	int wh = mnd;

	for (int k = 0; k < K; k++) {

		mn = 1000;
		mnd = -1;
		for (int i = 0; i < N; i++) {
			if (i != wh) {
				if (mn > A[i]) {
					mn = A[i];
					mnd = i;
				}
			}
		}

		for (int i = 0; i < N; i++) {
			if (mnd != i && wh != i) {
				X.push_back(i);
				A[i]--;
			}
		}
		X.push_back(mnd);
		A[mnd]--;

		wh = mnd;

	}

	for (int i = 0; i < N; i++) {
		if (A[i] < 0) {
			cout << -1 << endl;
			return 0;
		}
	}




	cout << X.size() << endl;
	for (int i = 0; i < X.size(); i++) {
		cout << X[i] + 1 << " ";
	}
	cout << endl;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int i=0;i<(n);i++)        //repeat n times
#define REP2(i,s,n) for(int i=(s);i<(n);i++)   //repeat from s to n 
#define REPD(i,n) for(int i=(n);i>=0;i--)      //repeat from n to 0
#define REPD2(i,s,e) for(int i=(s);i>=(e);i--) //repeat from s to e
#define RANGE(i,v) for(auto &i:v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

int main(){
    string S,T;
    cin>>S>>T;

    int cnt = 0;
    REP(i,S.size()){
        if(S[i] != T[i]) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3928
#include <iostream>
#include <stdint.h>
using namespace std;

// modulo integer
// M: modulo number
// * M < 2^31
// * M must be prime if you use division
template <int64_t M>
class mint {
public:
    mint()
        : v(-1)
    {
    }
    mint(int n)
        : v(n % M)
    {
    }

    int64_t get() const { return v; }

    mint& operator+=(const mint& r)
    {
        v = (v + r.v) % M;
        return *this;
    }
    mint& operator-=(const mint& r)
    {
        v = (v - r.v + M) % M;
        return *this;
    }
    mint& operator*=(const mint& r)
    {
        v = (v * r.v) % M;
        return *this;
    }
    mint& operator/=(const mint& r)
    {
        return (*this) *= r.inv();
    }

    mint pow(int r) const
    {
        mint k = *this, ret = 1;
        while (r > 0) {
            if (r % 2 != 0)
                ret *= k;
            r /= 2;
            k *= k;
        }
        return ret;
    }

    mint inv() const
    {
        return pow(M - 2);
    }

private:
    int64_t v;
};

template <int64_t M>
inline mint<M> operator+(mint<M> l, const mint<M>& r)
{
    return l += r;
}

template <int64_t M>
inline mint<M> operator-(mint<M> l, const mint<M>& r)
{
    return l -= r;
}

template <int64_t M>
inline mint<M> operator*(mint<M> l, const mint<M>& r)
{
    return l *= r;
}

template <int64_t M>
inline mint<M> operator/(mint<M> l, const mint<M>& r)
{
    return l /= r;
}

template <int64_t M>
inline ostream& operator<<(ostream& os, const mint<M>& r)
{
    return os << r.get();
}

typedef mint<1000000007> MINT;

int main()
{
    int n, m;
    cin >> n >> m;
    if (n < m)
        swap(n, m);

    if (n - m >= 2) {
        cout << 0 << endl;
        return 0;
    }

    MINT v = 1;
    for (int i = 0; i < n; i++) {
        v *= MINT(n - i);
    }
    for (int i = 0; i < m; i++) {
        v *= MINT(m - i);
    }

    if (n == m) {
        v *= MINT(2);
    }

    cout << v << endl;

    return 0;
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

lint imos[2010][2010];
bool done[2010][2010];

void init(void){
    rep(i, 2010){
        rep(j, 2010){
            imos[i][j] = 0;
            done[i][j] = false;
        }
    }
}

void compress(vector<lint> &v, map<lint, lint> &zip, vector<lint> &unzip){
    SORT(v);
    v.erase(unique(v.begin(), v.end()), v.end());
    unzip.resize(v.size());
    rep(i, v.size()){
        zip[v[i]] = i;
        unzip[i] = v[i];
    }
    return;
}

void bfs(int sy, int sx, int maxY, int maxX){
    done[sy][sx] = true;
    queue<P> que;
    que.push({sy, sx});
    while(!que.empty()){
        P p = que.front();
        que.pop();
        done[p.first][p.second] = true;
        rep(i, 4){
            int ny = p.first + dy[i], nx = p.second + dx[i];
            if(0 <= ny && ny < maxY && 0 <= nx && nx < maxX && !done[ny][nx] && imos[ny][nx] == 0){
                done[ny][nx] = true;
                que.push({ny, nx});
            }
        }
    }
    return;
}

int main(){
    int w, h;
    while(cin >> w >> h, w){
        init();
        int n;
        cin >> n;
        vector<lint> x1(n), x2(n), y1(n), y2(n), x, y;
        rep(i, n){
            cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
            x.push_back(x1[i]);
            x.push_back(x2[i]);
            y.push_back(y1[i]);
            y.push_back(y2[i]);
        }
        x.push_back(0);
        x.push_back(w);
        y.push_back(0);
        y.push_back(h);
        map<lint, lint> zipx, zipy;
        vector<lint> unzipx, unzipy;
        compress(x, zipx, unzipx);
        compress(y, zipy, unzipy);
        rep(i, n){
            ++imos[zipy[y1[i]]][zipx[x1[i]]];
            --imos[zipy[y1[i]]][zipx[x2[i]]];
            --imos[zipy[y2[i]]][zipx[x1[i]]];
            ++imos[zipy[y2[i]]][zipx[x2[i]]];
        }
        rep(i, 2010){
            REP(j, 1, 2010){
                imos[i][j] += imos[i][j-1];
            }
        }
        rep(j, 2010){
            REP(i, 1, 2010){
                imos[i][j] += imos[i-1][j];
            }
        }
        lint ans = 0;
        rep(i, unzipy.size()-1){
            rep(j, unzipx.size()-1){
                if(!done[i][j] && imos[i][j] == 0){
                    ++ans;
                    bfs(i, j, unzipy.size()-1, unzipx.size()-1);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 38744
using System;
public class Lesson{
    public static void Main(){
        // Here your code !
        
        string[] in_str = Console.ReadLine().Split(' ');
        int a = int.Parse(in_str[0]);
        int b = int.Parse(in_str[1]);
        int c = int.Parse(in_str[2]);
        
        if(a<b & b<c){
            System.Console.WriteLine("Yes");
        } else {
            System.Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 8848
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 1> { using type = vector<T>; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int D;
  ll G;
  while (cin >> D >> G) {
    vector<int> p(D), c(D);
    for (int i = 0; i < D; i++) cin >> p[i] >> c[i];
    ll res = 1ll << 60;
    for (int m = 0; m < (1 << D); m++) {
      ll rest = G, cost = 0;
      for (int i = 0; i < D; i++) {
        if ((m >> i) & 1) {
          int score = 100 * (i + 1);
          rest -= 1ll * score * p[i];
          rest -= c[i];
          cost += p[i];
        }
      }
      for (int i = D - 1; i >= 0 && rest > 0; i--) {
        if (!((m >> i) & 1)) {
          int score = 100 * (i + 1);
          ll need = min((rest + score - 1) / score, (ll)p[i]);
          rest -= need * score;
          cost += need;
        }
      }
      if (rest <= 0) {
        res = min(res, cost);
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAX=105;
const int INF=0x3f3f3f3f;
int n,b[MAX][26];
char s[MAX][MAX];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%s",s[i]);
    for(int i=0;i<n;i++){
        int len=strlen(s[i]);
        for(int j=0;j<len;j++) b[i][s[i][j]-'a']++;
    }
    for(int i=0;i<26;i++){
        int t=INF;
        for(int j=0;j<n;j++) t=min(t,b[j][i]);
        for(int j=0;j<t;j++) printf("%c",i+'a');
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
set<LP> G;
set<LP> s;
ll ans[10];
int main(){
    ll h,w,n; cin >> h >> w >> n;
    REP(i,n){
        ll a,b; cin >>a >> b; 
        G.insert(make_pair(a,b));
        REP(i,3){
            REP(j,3){
                ll x = a+i-1;
                ll y = b+j-1;
                if(x>1&& x < h && y > 1&& y < w){
                    s.insert(make_pair(x,y));
                }
            }
        }
    }
    auto it = s.begin();
    while(it!=s.end()){
        ll cx = it->first;
        ll cy = it->second;
        ll tmp = 0;
        REP(i,3){
            REP(j,3){
                ll x = cx +i -1;
                ll y = cy +j -1;
                LP p(x,y);
                auto f = G.find(p);
                if(f != G.end())  tmp++;
            }
        }
        ans[tmp]++;
        it++;
    }
    ll b = 0;
    FOR(i,1,10){
        b+=ans[i];
    }
    ans[0] = (h-2)*(w-2) - b;
    REP(i,10){
        cout << ans[i] << endl;
    }



}

Measured memory_bytes: 62720
#include<bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
#define ff first
#define se second
#define MAX 1000001
#define MAXN 100005
#define mod 1000000007 
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,d,ans;
    cin>>a>>b>>c>>d;
    ans=(a-c)*(b-d);
    cout<<ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>
#include <stack>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

int main(){
  int in;
  stack<int> s;

  while(scanf("%d", &in) != EOF){
    if(in == 0){
      printf("%d\n",s.top());
      s.pop();
    }
    else s.push(in);
  }

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std;
int N,K,A[2<<17];
main()
{
	cin>>K>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	int ans=0;
	for(int i=0;i<N;i++)
	{
		if(i<N-1)ans=max(ans,A[i+1]-A[i]);
		else ans=max(ans,K+A[0]-A[i]);
	}
	cout<<K-ans<<endl;
}


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

int main () {
  int n, m, ans;
  cin >> n >> m;
  vector<int> l(m);
  vector<int> r(m);
  int L = 1, R = n;
  rep(i,m) {
    cin >> l.at(i) >> r.at(i);
    L = max(L,l.at(i));
    R = min(R,r.at(i));
  }
  ans = R - L + 1;
  ans = max(ans,0);
  cout << ans;
}


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

int main(){

    int w,h,n;

    cin >> w >> h >> n;

    int x[n],y[n];

    for(int i=0; i<n; i++){
      cin >> x[i] >> y[i];
    }

    int px = x[0],py = y[0];

    int ans = 0,minnum,dirx,diry;

    for(int i=1; i<n; i++){
      //cout << px << " " << x[i] << " " << py << " " << y[i] << endl;
      if( (py >= y[i] && px <= x[i]) || (py <= y[i] && px >= x[i]) ){
        dirx = px - x[i];
        dirx = dirx > 0 ? dirx : -dirx;
        diry = py - y[i];
        diry = diry > 0 ? diry : -diry;
        //cout << "before " << ans << endl;
        ans += dirx + diry;
        //cout << "after "  << ans << endl;
        px = x[i];
        py = y[i];
      }
      else{
        dirx = px - x[i];
        dirx = dirx > 0 ? dirx : -dirx;
        diry = py - y[i];
        diry = diry > 0 ? diry : -diry;
        minnum = min(dirx,diry);
        //cout << "before " << ans << endl;
        ans += minnum + (dirx - minnum) + (diry - minnum);
        //cout << "after "  << ans << endl;
        px = x[i];
        py = y[i];
      }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3108
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}

pair<long long, int> D[100050];

pair<int, int> edge[100050];

vector<int> G[100050];

int n, size[100050], tot;

long long dis[100050];

inline void dfs(int u, int fa) {
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v != fa) {
      dis[v] = dis[u] + 1;
      dfs(v, u);
    }
  }
}

int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    long long d = read();
    D[i] = {d, i};
    size[i] = 1;
  }
  sort(D + 1, D + n + 1);
  reverse(D + 1, D + n + 1);
  for (int i = 1; i < n; i++) {
    long long delta = D[i].first - n + 2 * size[i];
    int l = 1, r = n + 1, pos = 0;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (D[mid].first <= delta) {
        r = mid - 1;
        pos = mid;
      } else
        l = mid + 1;
    }
    if (D[pos].first != delta) {
      puts("-1");
      return 0;
    }
    int u = D[i].second, v = D[pos].second;
    G[u].push_back(v);
    G[v].push_back(u);
    edge[++tot] = {u, v};
    size[pos] += size[i];
  }
  dfs(D[n].second, 0);
  long long sum = 0;
  for (int i = 1; i <= n; i++) sum += dis[i];
  if (sum == D[n].first) {
    for (int i = 1; i <= tot; i++)
      cout << edge[i].first << " " << edge[i].second << endl;
  } else
    puts("-1");//__wfx fuck you
  return 0;
}


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

//-----------------------------------LIBRARY OF INPUT-----------------------------------
void reader(int *x) {
	int k = getchar(); *x = k - '0';
	while (true) {
		k = getchar();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}

#pragma warning(disable:4996)
int n, m, q, dist[110000], mark[110000], u[210000], v[210000];
vector<pair<int, int>>x[110000], y[110000], z[110000]; bool used[210000];
bool isgood(int f) {
	for (int i = 0; i < z[f].size(); i++) {
		if (mark[z[f][i].first] == 0 && used[z[f][i].second] == false)return true;
	}
	return false;
}
int main() {
	reader(&n); reader(&m); reader(&q); queue<int>Q;
	for (int i = 0; i < m; i++) {
		int a = 0, b = 0;
		reader(&a);
		reader(&b);
		u[i + 1] = a; v[i + 1] = b;
		x[a].push_back(make_pair(b, i + 1)); x[b].push_back(make_pair(a, i + 1));
	}
	Q.push(1); for (int i = 1; i <= n; i++)dist[i] = 999999; dist[1] = 0;
	while (!Q.empty()) {
		int a1 = Q.front(); Q.pop();
		for (int i = 0; i < x[a1].size(); i++) {
			if (dist[x[a1][i].first] > dist[a1] + 1) { dist[x[a1][i].first] = dist[a1] + 1; Q.push(x[a1][i].first); }
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < x[i].size(); j++) {
			if (dist[i] < dist[x[i][j].first]) { y[i].push_back(x[i][j]); }
			if (dist[i] > dist[x[i][j].first]) { z[i].push_back(x[i][j]); }
		}
	}
	int cnt = 0;
	for (int i = 0; i < q; i++) {
		int a = 0;
		reader(&a);
		used[a] = true;
		int E1 = u[a], E2 = v[a];
		if (dist[E1] == dist[E2]) { cnt += 0; }
		else {
			int a1 = 0; if (dist[E1] < dist[E2])a1 = E2; else a1 = E1;
			if (isgood(a1) == false && mark[a1] == 0) {
				queue<int>Q; Q.push(a1); cnt++; mark[a1] = 1;
				while (!Q.empty()) {
					int a2 = Q.front(); Q.pop();
					for (int j = 0; j < y[a2].size(); j++) {
						if (mark[y[a2][j].first] == 0 && isgood(y[a2][j].first) == false) {
							mark[y[a2][j].first] = 1; Q.push(y[a2][j].first); cnt++;
						}
					}
				}
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 25616
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	int[][] inv;



	boolean isok(int i, int j) {

		return i >= 0 && i < 10 && j >= 0 && j < 10;

	}



	void setTrans(int d[], int p) { // only for size == 100

		int i = p / 10;

		int j = p % 10;

		Arrays.fill(d, 0);

		int[] di = { 0, 0, 0, 1, -1 };

		int[] dj = { 0, 1, -1, 0, 0 };

		for (int z = 0; z < 5; z++) {

			int ni = i + di[z];

			int nj = j + dj[z];

			if (!isok(ni, nj))

				continue;

			d[10 * ni + nj] = 1;

		}

	}



	void add(int[] to, int[] from) { // only for size==100

		for (int i = 0; i < to.length; i++) {

			to[i] = from[i] ^ to[i];

		}

	}



	void swap(int[] a, int[] b) {

		int piv;

		for (int i = 0; i < 100; i++) {

			piv = a[i];

			a[i] = b[i];

			b[i] = piv;

		}

	}



	void init() { // set inv[][]

		inv = new int[100][100];

		int[][] trans = new int[100][100];

		for (int i = 0; i < 100; i++) {

			setTrans(trans[i], i);



			inv[i][i] = 1;

		}

		for (int i = 0; i < 100; i++) {

			if (trans[i][i] == 0) {

				for (int j = i + 1; j < 100; j++) {

					if (trans[j][i] == 1) {

						swap(trans[i], trans[j]);

						swap(inv[i], inv[j]);

						break;

					}

				}

			}

			for (int j = i + 1; j < 100; j++) {

				if (trans[j][i] == 1) {

					add(trans[j], trans[i]); // ツ湘」ツ三ツ角ツ行ツ療アツ可サ

					add(inv[j], inv[i]);

				}

			}

		}

		for (int i = 0; i < 100; i++) {

			if (trans[99 - i][99 - i] == 0) {

				for (int j = i + 1; j < 100; j++) {

					if (trans[99 - j][99 - i] == 1) {

						swap(trans[99 - i], trans[99 - j]);

						swap(inv[99 - i], inv[99 - j]);

						break;

					}

				}

			}

			for (int j = i + 1; j < 100; j++) {

				if (trans[99 - j][99 - i] == 1) {

					add(trans[99 - j], trans[99 - i]); // ツ妥篠角ツ行ツ療アツ可サ

					add(inv[99 - j], inv[99 - i]);

				}

			}

		}

	}



	int[] ans(int in[]) {

		int[] ret = new int[100];

		for (int i = 0; i < 100; i++) {

			for (int j = 0; j < 100; j++) {

				ret[i] ^= inv[i][j] * in[j];

			}

		}

		return ret;

	}



	void run() {

		int n = sc.nextInt();

		init();

		for (int z = 0; z < n; z++) {

			int in[] = new int[100];

			for (int i = 0; i < 100; i++) {

				in[i] = sc.nextInt();

			}

			int ans[] = ans(in);

			for (int i = 0; i < 10; i++) {

				for (int j = 0; j < 10; j++) {

					if (j != 0) {

						System.out.print(" ");

					}

					System.out.print(ans[i * 10 + j]);

				}

				System.out.println();

			}

		}



	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

int main()
{
    int x[3];
    rep(i, 0, 3) cin >> x[i];
    sort(x, x + 3);
    cout << x[0] << " " << x[1] << " " << x[2] << endl;
}



Measured memory_bytes: 3140
w,h,n = list(map(int,input().split()))
minX = 0
maxX = w
minY = 0
maxY = h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        minX = max(minX, x)
    elif a == 2:
        maxX = min(maxX, x)
    elif a == 3:
        minY = max(minY, y)
    elif a == 4:
        maxY = min(maxY, y)

print(max(0, maxX-minX)*max(0, maxY-minY))


Measured memory_bytes: 9044
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,c;
int w[50][50];
int w2[3][50];
int s[3][300000];
int t[3];
int ans[3];
int flag[100];
int x;


int check(int x,int y)
{
    int tans=0;
    for (int i=0; i<t[x]; ++i)
        tans+=w[s[x][i]][y];
    return tans;
}

int dfs(int now)
{
    if (now==3) return 0;
    int ans=2000000000;
    for (int i=1; i<=c; ++i)
        if (flag[i]==0)
        {
            flag[i]=1;
            ans=min(ans,w2[now][i]+dfs(now+1));
            flag[i]=0;
        }
    return ans;
}
int main()
{
    cin>>n>>c;
    for (int i=1; i<=c; ++i)
        for (int j=1; j<=c; ++j)
            scanf("%d",&w[i][j]);
    for (int i=1; i<=n; ++i)
        for (int j=1; j<=n; ++j)
        {
            scanf("%d",&x);
            s[(i+j)%3][t[(i+j)%3]++]=x;
        }
    for (int i=0; i<3; ++i)
    {
        for (int j=1; j<=c; ++j)
            w2[i][j]=check(i,j);
    }
    cout<<dfs(0)<<endl;
    return 0;
}


Measured memory_bytes: 1280
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    h::Int,w::Int,k::Int=parseMap(split(readline()))
    c::Vector{String}=[readline() for i in 1:h]
    ans::Int=0
    for i in 0:(1<<(h+w))-1
        pat=Vector{Int}()
        for j in 0:h+w-1
            if i & (1<<j) == 0
                # jは0-startだがJuliaの配列は1-indexedなので
                push!(pat,j+1)
            end
        end
        cnt::Int=0
        for j in 1:h
            for k in 1:w
                if !(j in pat) && !(h+k in pat) && c[j][k]=='#'
                    cnt+=1
                end
            end
        end
        if cnt==k
            ans+=1
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 173408
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

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

  vi A(N);

  for (int i = 0; i < N; i++) cin >> A[i];

  ll B = 0;
  for (int i = 0; i <= N - 1; i++) {
    if (i % 2 == 0) B += A[i];
    else B -= A[i];
  }

  vi ans(N);
  ans[0] = B;

  for (int i = 1; i < N; i++) {
    ans[i] = A[i - 1] * 2 - ans[i - 1];
  }

  for (int i = 0; i < N; i++) {
    cout << ans[i];
    if (i == N - 1) cout << endl;
    else cout << ' ';
  }
}


Measured memory_bytes: 2944
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>

using namespace std;
using LL = long long;

class Solution {
private:
	void insertBasis(LL num, array<LL, 64>& basis) {
		for (int d = 63; d >= 0; --d) {
			const LL bit = 1LL << d;
			if (num & bit) {
				if (basis[d]) {
					num ^= basis[d];
				} else {
					basis[d] = num;
					break;
				}
			}
		}
	}
public:
	/* time: O(n), space: O(1), where n = |A| */
	LL xorSum3(const vector<LL>& A) {
		LL oddBits = 0;
		for (LL num : A)
			oddBits ^= num;
		LL evenBits = ~oddBits;

		array<LL, 64> basis = {};
		for (LL num : A)
			insertBasis(num & evenBits, basis);

		LL maxEvenBits = 0;
		for (int d = 63; d >= 0; --d)
			maxEvenBits = max(maxEvenBits, maxEvenBits ^ basis[d]);
		return maxEvenBits * 2 + oddBits;
	}
};

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

	vector<LL> A(n);
	for (int i = 0; i < n; ++i)
		cin >> A[i];

	Solution sol;
	LL ans = sol.xorSum3(A);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(2**20)

class Node():
    def __init__(self,parent,left,right):
        self.parent = parent
        self.left = left
        self.right = right

def get_all_height(T: dict, H: dict, u: int):
    #深さ優先探索で各地点をめぐりながらHに高さ情報をセットしていく
    h_left = 0
    h_right = 0
    if T[u].left is not None:
        h_left = get_all_height(T,H,T[u].left) + 1
    if T[u].right is not None:
        h_right = get_all_height(T,H,T[u].right) + 1

    ret = max(h_left,h_right)
    H[u] = ret
    return ret

def get_all_depth(T, D:dict, u:int, p:int):
    D[u] = p
    if T[u].left is not None:
        get_all_depth(T,D,T[u].left,p+1)
    if T[u].right is not None:
        get_all_depth(T,D,T[u].right,p+1)

def ret_sibling(T,u):
    parent = T[u].parent
    if parent == None:
        return -1
    if T[parent].left == u:
        ret = T[parent].right
    else:
        ret = T[parent].left

    if ret == None:
        return -1

    return ret

def ret_degree(T,u):
    ret = 0
    if T[u].left != None:
        ret += 1
    if T[u].right != None:
        ret += 1
    return ret

#データを読み込む
n = int(input())
T = {key: Node(None,None,None) for key in range(n)}
for _ in range(n):
    tmp = list(map(int,input().split()))

    if tmp[1] != -1:
        T[tmp[0]].left = tmp[1]
        T[tmp[1]].parent = tmp[0]
    if tmp[2] != -1:
        T[tmp[0]].right = tmp[2]
        T[tmp[2]].parent = tmp[0]

#根の探索
for i in range(n):
    if T[i].parent is None:
        ROOT = i
        break
else:
    raise ValueError("ROOTが存在しないなんておかしい")

#深さと高さの探索
D = {}
get_all_depth(T,D,i,0)
H = {}
get_all_height(T,H,ROOT)

def print_for_a_node(u):
    if T[u].parent is None:
        parent = -1
    else:
        parent = T[u].parent

    sib = ret_sibling(T,u)
    deg = ret_degree(T,u)
    node_type = 'internal node' if deg != 0 else 'leaf'
    if parent == -1:
        node_type = 'root'

    print(f'node {u}: parent = {parent}, sibling = {sib}, degree = {deg}, depth = {D[u]}, height = {H[u]}, {node_type}')

for node in range(n):
    print_for_a_node(node)



Measured memory_bytes: 5640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int A[6];
  RREP(i,5) cin>>A[i];
  RREP(i,5){
    if(A[i]==0){
      cout<<i<<endl;
      return 0;
    }
  }
}

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

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

int main(void) {
  int r, c;
  cin >> r >> c;

  int tmp, totalRow, totalCols[c+1]={0};
  rep(i, r) {
    totalRow = 0;
    rep(j, c) {
      cin >> tmp;
      cout << tmp << " ";
      totalRow += tmp;
      totalCols[j] += tmp;
    }
    cout << totalRow << endl;
    totalCols[c] += totalRow;
  }

  rep(i, c) cout << totalCols[i] << " ";
  cout << totalCols[c] << endl;

}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, min = INT_MAX, max = INT_MIN;
	cin >> n;
	for(int i = 0; i < n; i++) {
		int num;
		cin >> num;
		if(num < min) min = num;
		if(num > max) max = num;
	}
	cout << max - min << endl;

	return 0;
}

Measured memory_bytes: 256
n,*a=gets.split.map &:to_i
l=(1..n).map{gets.to_i}
m=9000
for x in 0...4**n
    s=[q=0,0,0]
    x.to_s(4).rjust(n,"0").split("").each_with_index{|e,i|e<'3'&&(s[e.to_i]+=l[i])>l[i]&&q+=10}
    (0..2).each{|i|q+=(a[i]-s[i]).abs}
    m=[m,q].min if s.all?{|i|i>0}
end
p m

Measured memory_bytes: 1916
#include <bits/stdc++.h>
 
 
using namespace std;
typedef long long ll;
 
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
int T;
const int maxN = 2e3+8;
const ll INF = 1e15+7;
const int MOD = 1e9+7;
int n;
int k;
int a[maxN];


int main() {
	int n,k;
	scanf("%d %d",&n,&k); 
	ll cnt = 0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	ll ans = 0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(a[i] > a[j])
			{
				cnt++;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		int tmp = 0;
		for(int j=1;j<=n;j++)
		{
			if(a[j] < a[i] && i != j)
			{
				tmp++;
			}
		}
		ans += (ll)k*(k-1)/2%MOD * tmp % MOD;
		ans %= MOD;
	}
	ans += cnt*k%MOD;
	ans %= MOD;
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
        public static void main (String[] args){
                Scanner sc = new Scanner(System.in);
                //連続泊数
                int N = sc.nextInt();
                //区切り泊数
                int K = sc.nextInt();
                //初期一泊価格
                int X = sc.nextInt();
                //後期一泊価格
                int Y = sc.nextInt();
                int ans;
                if(N <= K){
                        ans = N * X;
                }else{
                        ans = K * X + (N - K) * Y;
                }
                System.out.println(ans);
        }
}

Measured memory_bytes: 9552
#include <cstdio>
#include <iostream>
#include <cmath>

using namespace std;

int main(void)
{  
  int a, b;
  int num, count;
  while (scanf ("%d %d", &a, &b) != EOF){
    num = a + b;
    count = 0;
    while (num != 0){
      num = num / 10;
      count++;
    }
    printf("%d\n", count);
  }

  return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>

#define INF 100000000
#define MAX_N 1000000

typedef struct {
	int num;
	int max;
	int last;
} FIELD;

int isPrime[ MAX_N + 1 ] = { 0, 0, 1 }, corner[ 1998 ] = { 2 }, coord[ 1000001 ], m;
FIELD field[ 1002 ][ 1001 ];
const int dx[ 7 ] = { 1, 0, -1 , 0, -1, 0, 1 }, dy[ 7 ] = { 0, -1, 0, 1, 1, 1, 1 };

void dfs( int, int );

int main( void ) {
	int i, j, add, x, y, d, cnt, n;

	for ( i = 3; i <= MAX_N; i += 2 )
		isPrime[ i ] = 1;

	for ( i = 3; i * i <= MAX_N; i += 2 )
		if ( isPrime[ i ] )
			for ( j = i * 2; j <= MAX_N; j += i )
				isPrime[ j ] = 0;

	add = 1;
	for ( i = 1; i < 1998; i++ ) {
		corner[ i ] = corner[ i - 1 ] + add;
		add += i & 1;
	}

	x = y = 500;
	d = cnt = 0;
	for ( i = 1; i <= 1000000; i++ ) {
		coord[ i ] = x * 1001 + y;
		field[ x ][ y ].num = i;

		if ( i == corner[ cnt ] ) {
			d = d + 1 & 3;
			cnt++;
		}

		x += dx[ d ];
		y += dy[ d ];
	}

	for ( x = 1002; x--; field[ x ][ 1000 ].num = INF ) ;
	for ( y = 1001; y--; field[ 0 ][ y ].num = field[ 1001 ][ y ].num = INF ) ;

	for ( ; scanf( "%d %d", &m, &n ), m; printf( "%d %d\n", field[ x ][ y ].max, field[ x ][ y ].last ) ) {
		for ( i = m + 1; --i; field[ x = coord[ i ] / 1001 ][ y = coord[ i ] % 1001 ].max = INF, field[ x ][ y ].last = 0 ) ;

		dfs( x = coord[ n ] / 1001, y = coord[ n ] % 1001 );
	}

	return 0;
}

void dfs( int x, int y ) {
	int i;

	field[ x ][ y ].max = 0;
	for ( i = 4; i < 7; i++ ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];

		if ( field[ nx ][ ny ].num <= m ) {
			if ( field[ nx ][ ny ].max == INF )
				dfs( nx, ny );

			if ( field[ x ][ y ].max < field[ nx ][ ny ].max ) {
				field[ x ][ y ].max = field[ nx ][ ny ].max;
				field[ x ][ y ].last = field[ nx ][ ny ].last;
			} else if ( field[ x ][ y ].max == field[ nx ][ ny ].max )
				if ( field[ x ][ y ].last < field[ nx ][ ny ].last )
					field[ x ][ y ].last = field[ nx ][ ny ].last;
		}
	}

	if ( isPrime[ field[ x ][ y ].num ] ) {
		if ( !field[ x ][ y ].max )
			field[ x ][ y ].last = field[ x ][ y ].num;

		field[ x ][ y ].max++;
	}
}

Measured memory_bytes: 20264
def main():
    n = input()
    hon = ['2', '4', '5', '7', '9']
    pon = ['0', '1', '6', '8']
    bon = ['3']
    if n[len(n)-1] in hon:
        print('hon')
    elif n[len(n)-1] in pon:
        print('pon')
    else:
        print('bon')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9124
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def prime_factor(n):
    ret = {}
    p = 2
    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p
        p += 1

    if n != 1: ret[n] = 1

    return ret


a, b = map(int, input().split())
g = gcd(a, b)

print( len(prime_factor(g)) + 1)


Measured memory_bytes: 38512
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local S = read.l():totable()
local Q = read.nl()
local rev = false
local front = 0
local back = #S+1
for i=1,Q do
    local q = read.l()
    if q == "1" then
        rev = not rev
    else
        local t, f, c = q:split()
        local ins_front = f == '1'
        if rev then
            ins_front = not ins_front
        end
        if ins_front then
            S[front] = c
            front = front - 1
        else
            S[back] = c
            back = back + 1
        end
    end
end
local ans = {}
for i=front+1,back-1 do
    table.insert(ans, S[i])
end
if rev then
    print(string.reverse(table.concat(ans, "")))
else
    print(table.concat(ans, ""))
end

Measured memory_bytes: 50560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		sc.close();
		
		String ab = a + b;
		int num = Integer.valueOf(ab);
		
		for (int i = 1; i * i <= num; i++) {
			if (i * i == num) {
				System.out.println("Yes");
				return;
			}
		}
		
		System.out.println("No");
	}
}




Measured memory_bytes: 26952
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 15
using namespace std;
typedef long long ll;
bool sqr[16005];
int n,d,x[maxn][15];
bool dis(int p,int q){
  int res = 0;
  for(int i = 1;i <= d;i++){
    res += (x[p][i] - x[q][i]) * (x[p][i] - x[q][i]);
  }
  return sqr[res];
}
int main(){
  for(int i = 0;i * i <= 16000;i++){
    sqr[i * i] = true;
  }
  scanf("%d%d",&n,&d);
  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= d;j++){
      scanf("%d",&x[i][j]);
    }
  }
  int ans = 0;
  for(int i = 1;i <= n;i++){
    for(int j = i + 1;j <= n;j++){
      ans += dis(i,j);
    }
  }
  printf("%d\n",ans);
  return 0;
}


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

int main() {
   int A, B, C, X;
   cin >> A >> B >> C >> X;
   int count = 0;

   for (int i = 0; i <= A; i++) {
       for (int j = 0; j <= B; j++) {
           for (int k = 0; k <= C; k++) {

               if (500 * i + 100 * j + 50 * k == X) {
                   count++;
               }
           }
       }
   }

   cout << count << endl;

}

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

int main(){
  int n;
  cin >> n;
  int h[n];
  int count = 0;
  int ans = 0; 
  for(int i=0; i<n; i++){
    cin >> h[i];
    if(i>0){
      if(h[i-1]>=h[i]) count += 1;
      else count = 0;
    }
    ans = max(ans,count);
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 640