akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N = 25;

vector<pair<int, int> >a[N];

bool Check(int Pos, int Status) {
    bool flag = true;
    for (int i = 0; i < a[Pos].size(); i++) {
        int x = a[Pos][i].first, y = a[Pos][i].second;
        if (y && (Status & (1<<(x-1))) == 0) flag = false;
        if (!y && (Status & (1<<(x-1)))) flag = false;
    }
    return flag;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        for (int j = 0; j < x; j++) {
            int xx, yy;
            scanf("%d%d", &xx, &yy);
            a[i].push_back(make_pair(xx, yy));
        }
    }
    int ans = -1;
    for (int i = 0; i < (1 << n); i++) {
        bool flag = true;
        for (int j = 0; j < n; j++) {
            if (i & (1<<j)) {
                flag = Check(j+1, i);
                if (!flag) break; 
            }
        }
        if (flag) {
            int num = 0, fuck = i;
            while (fuck) {
                if (fuck & 1) num++;
                fuck >>= 1;
            }
            ans = max(ans, num);
           // cout << i << " " << ans << endl;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
using namespace std;
int x[10],y[10];
int n;
int per(int n)
{
    int sum = 1;
    for (int i = 1; i <= n; ++i)
    {
        sum *= i;
    }
    return sum;
}
double dist(int i,int j)
{
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx*dx + dy*dy ,0.5);
}
int main()
{
    cin >> n;
    double sum = 0.0;
    for (int i = 1; i <= n; ++i)
    {
        cin >> x[i] >> y[i];
    }
    vector <int> v(n);
    for (int i = 0; i < n; ++i)
    {
        v[i] = i+1;
    }
    do
    {
        for (int i = 0; i < n-1; ++i)
        {
            sum += dist(v[i],v[i+1]);
        }
    } while (next_permutation(v.begin(), v.end()));
    int d = per(n);
    cout << fixed << setprecision(10) << sum / d << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 20000 + 100;
int N;
int A[Maxn], P[Maxn], B[Maxn];

inline void dfs(int l, int r)
{
	if (l == r || l + 1 == r) return ;
	int mid = (l + r) >> 1;
	A[mid] = (A[l] + A[r]) >> 1;
	dfs(l, mid);
	dfs(mid, r);
}

int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	scanf("%d", &N);
	int x;
	for (int i = 1; i <= N; ++i) scanf("%d", &x), P[x] = i;
	A[1] = 1;
	A[N] = 1000000000 - 30000;
	dfs(1, N);
	for (int i = 1; i <= N; ++i)
		B[i] = P[i] + 1000000000 - 30000 - A[i];
	for (int i = 1; i <= N; ++i) cout<<A[i]<<" ";
	cout<<endl;
	for (int i = 1; i <= N; ++i) cout<<B[i]<<" ";
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
struct edge {
    int to; 
    int weight;
    edge(int t, int w) : to(t),weight(w) {}
};
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Graphi = vector<vi>;
using Graphe = vector<vector<edge> >;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = root(x);
    y = root(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);//mergeテク

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool connected(int x, int y) {
    return root(x) == root(y);
  }

  // データxが含まれる木の大きさを返す
  ll size(int x) {
    return sizes[root(x)];
  }
};

int main(){

    ll n,m; cin >> n >> m;
    vector<pint> node(m);
    rep(i,m){
        int a,b; cin >> a >> b;
        --a;--b;
        node.at(i) = make_pair(a,b);
    } 
    reverse(all(node));
    vector<ll> ans(m);
    ans.at(0) = n*(n-1)/2;
    UnionFind tree(n);
    for(int i = 1; i < m; i++){

        ll x = node.at(i-1).first;
        ll y = node.at(i-1).second;
        if(tree.connected(x,y)) ans.at(i) = ans.at(i-1);
        else ans.at(i) = ans.at(i-1) - tree.size(x)*tree.size(y);
        tree.unite(node.at(i-1).first,node.at(i-1).second);

    }

    reverse(all(ans));
    rep(i,m) cout << ans.at(i) << endl;

    return 0;

}

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

int main() {
  long long X;
  cin >> X;
  long long yokin = 100;
  int year = 0;

  while (yokin < X)  {
    yokin = yokin + yokin / 100;
    year++;
  }
  cout << year << endl;
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    vector<ll> H;
    ll count = 0;
    vector<set<ll>> Roads;
    ll N, M;
    cin >> N >> M;
    H.resize(N);
    Roads.resize(N);
    for(ll i = 0;i < N;i++) cin >> H[i];
    for(ll i = 0;i < M;i++) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        Roads[a].insert(b);
        Roads[b].insert(a);
    }
    for(ll i = 0;i < H.size();i++) {
        bool flag = true;
        for(auto &j: Roads[i]) {
            if(H[j] >= H[i]) {
                flag = false;
            }
        }
        if(flag) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 18004
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n =0;
    n = atoi(s.c_str());
    int ab = n / 100;
    int cd = n % 100;
   
    if ((ab > 0 && ab <= 12)&&(cd >0 && cd <=12)){
        //ab == month
        cout << "AMBIGUOUS" << endl;
    }else if (ab > 0 && ab <= 12){
        // cd == month
        cout << "MMYY" << endl;
    }else if (cd >0 && cd <=12){
        // ab == mon th or cd == month 
        cout << "YYMM" << endl;
    }else {
        cout << "NA"<< endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdint.h>
#include <map>

using namespace std;

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

  multimap<uint32_t, uint32_t> W;

  for (int n=0; n<N; ++n) {
    uint32_t A, B;
    cin >> A >> B;
    W.emplace(B,A);
  }

  bool flag = true;
  uint64_t sum = 0;
  for (auto w : W) {
    sum += w.second;
    if (sum > w.first) {
      flag = false;
      break;
    }
  }

  cout << (flag ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 9600
using System;
using System.Linq;

namespace HelloWorld
{
    class Program
    {
        static void Main()
        {
            var line = Console.In.ReadLine().Split();
            var lgroup = line.GroupBy(x => x).ToArray();

            var freq = lgroup.First(g => g.Count() == lgroup.Max(h => h.Count())).Key;
            var longiv = lgroup.First(g => g.Key.Length == lgroup.Max(h => h.Key.Length)).Key;
            Console.WriteLine("{0} {1}", freq, longiv);
        }
    }
}



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

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int INF = (1 << 30)-1;
using Graph = vector<vector<int> >;

Graph G;
int dp[101010] = {};

int rec(int v) {
  if(dp[v] != -INF) return dp[v];

  int res = 0;
  for(auto nv : G[v]) {
    res = max(res, rec(nv)+1);
  }
  return dp[v] = res;
}

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

  int n, m; cin >> n >> m;
  G.assign(n, vector<int>());
  rep(i, m) {
    int u, v; cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
  }

  rep(i, n) dp[i] = -INF;

  int ans = 0;
  rep(i, n) ans = max(ans, rec(i));
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

struct E{
    int to,cost;
};

int main() {

    int N,M;
    Scd2(N,M);

    int x,y,z;
    vector<vector<E>> e(N);
    vector<vector<E>> eb(N);
    Rep(i,M){
        Scd3(x,y,z);
        x--,y--;
        e[x].push_back({y,z});
        eb[y].push_back({x,z});
    }

    stack<int> s;
    vi isin(N,0);
    s.push(N-1);
    while(s.size()){
        int from = s.top();
        s.pop();
        isin[from] = 1;
        for( E eto : eb[from] ){
            int to = eto.to;
            if( !isin[to]  ){
                s.push(to);
                isin[to]=1;
            }
        }
    }


    vl v(N,-INF*N*10);
    v[0] = 0;

    vi lim(N,0);

    s.push(0);
    while(s.size()){
        int from = s.top();
        s.pop();
        for( E eto : e[from] ){
            int to = eto.to;
            int co = eto.cost;
            if( isin[to] )
            if( v[to] < v[from]+co  ){
                v[to] = v[from]+co;
                s.push(to);
                lim[to]++;
                if( lim[to] > N*2 ) {
                    printf ("inf\n");
                    return 0;
                }
            }
        }
    }

    printf ("%lld\n", v[N-1] );

    return 0;
}





Measured memory_bytes: 768
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define INF 200000000

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

vector<int> G[100000];
int et[200000];
int depth[200000];
int id[100000];

struct ST
{
	vector<pii> data;
	int size;

	ST(int n)
	{
		size = 1;
		while (size < n)size *= 2;

		data.assign(2 * size - 1, make_pair(INF, -1));

		for (int i = 0; i < n; i++)
		{
			data[size - 1 + i] = make_pair(depth[i], et[i]);
		}

		int k = size - 1;
		while (--k >= 0)
		{
			data[k] = min(data[2 * k + 1], data[2 * k + 2]);
		}
	}

	pii find(int s, int t, int k,int l, int r)
	{
		if (r == -1)
		{
			r = size;
		}
		if (t <= l || r <= s)
		{
			return make_pair(INF, -1);
		}
		if (s <= l&&r <= t)
		{
			return data[k];
		}

		return min(find(s, t, 2 * k + 1, l, (l + r) / 2), find(s, t, 2 * k + 2, (l + r) / 2, r));
	}
};

void ET(int n, int p, int& eti, int d)
{
	id[n] = eti;
	et[eti] = n;
	depth[eti] = d;
	eti++;

	for (auto& e : G[n])
	{
		if (e != p)
		{
			ET(e, n, eti, d + 1);
			et[eti] = n;
			depth[eti] = d;
			eti++;
		}
	}
}

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

	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int k;
		cin >> k;

		for (int j = 0; j < k; j++)
		{
			int c;
			cin >> c;
			G[i].emplace_back(c);
		}
	}

	int eti = 0;
	ET(0, -1, eti, 0);

	ST st(eti);

	int q;
	cin >> q;

	for (int i = 0; i < q; i++)
	{
		int u, v;
		cin >> u >> v;

		printf("%d\n", st.find(min(id[u], id[v]), max(id[u], id[v]) + 1, 0, 0, -1).second);
	}

	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<28);
const ll INFL = (1LL<<61);

int main() {
  int n, k; cin >> n >> k;
  int num = (n-2)*(n-1)/2;
  vll ans;
  if ((n==2 && k==1) || k > num) {
    cout << "-1" << endl;
    return 0;
  }

  rep(i,n-1) {
    ans.pb(mp(i+1, n));
  }
  rep(i,n-1) {
    REP(j,i+1,n-1) {
      if (num == k) break;
      ans.pb(mp(i+1, j+1));
      num--;
    }
    if (num == k) break;
  }
  cout << ans.size() << endl;
  rep(i,ans.size()) {
    cout << ans[i].ff << " " << ans[i].ss << endl;
  }
  return 0;
}


Measured memory_bytes: 512
h, w, k = gets.split.map(&:to_i)
field = h.times.map {gets.chomp.chars}

num = 0

(1..h).each do |y_num|
  field.combination(y_num) do |rows|
    tmp = rows.transpose.map(&:join)
    (0..tmp.size).each do |x_num|
      tmp.combination(x_num) do |cols|
        co = 0
        cols.map {co += _1.count("#")}
        num += 1 if co == k
      end
    end
  end
end

puts num

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

const int N = 15;
ll e[N][N];
ll dp[1 << N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, eds;
    cin >> n >> eds;
    forn(i, 0, n) forn(j, 0, n) e[i][j] = 0;
    while (eds--) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        e[a][b] = c;
        e[b][a] = c;
    }
    forn(i, 0, 1 << n) forn(j, 0, n) dp[i][j] = INF;
    dp[1][0] = 0;
    forn(i, 1, n) dp[1][i] = INF;
    for (int mask = 1; mask < (1 << (n - 1)); mask += 2) {
        //cerr << mask << '\n';
        dp[mask][0] = 0;
        for (int m = mask; m; m = (m - 1) & mask) {
            //cerr << m << ' ';
            ll sum = 0;
            vector<pair<int, int>> good;
            forn(i, 0, n) if (m & (1 << i)) forn(j, 0, n) {
                if (mask & (1 << j)) if (!(m & (1 << j))) {
                    sum += e[i][j];
                    if (e[i][j]) good.eb(i, j);
                }
            }
            //cerr << sum << '\n';
            for (auto p : good) {
                int i = p.fs, j = p.sn;
                setmin(dp[mask][j], dp[m][i] + sum - e[i][j]);
            }
        }
    }
    {
        int mask = (1 << n) - 1;
        //cerr << mask << '\n';
        dp[mask][0] = 0;
        for (int m = mask; m; m = (m - 1) & mask) {
            //cerr << m << ' ';
            ll sum = 0;
            forn(i, 0, n) if (m & (1 << i)) forn(j, 0, n) {
                if (mask & (1 << j)) if (!(m & (1 << j)))
                    sum += e[i][j];
            }
            //cerr << sum << '\n';
            forn(i, 0, n) if (m & (1 << i)) forn(j, 0, n) {
                if (mask & (1 << j)) if (!(m & (1 << j))) {
                    if (e[i][j]) setmin(dp[mask][j], dp[m][i] + sum - e[i][j]);
                }
            }

        }
    }
    cout << dp[(1 << n) - 1][n - 1] << '\n';
}


Measured memory_bytes: 4096
a=input()
b=input()
alist=list(a)
blist=list(b)
ans=0
for i in range(len(alist)):
  if(alist==blist):
    ans=1
  kari3=[]
  kari3.extend(alist[-1])
  kari3.extend(alist[:len(alist)-1])
  alist=kari3
  
if(ans==0):
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

void Hoshina(string& str){
	if(str.size() < 7){
	} else {
		for(unsigned int i=0; i<str.size()-6; ++i){
			if(str[i] == 'H' && str[i+1] == 'o' && str[i+2] == 's' && str[i+3] == 'h' && str[i+4] == 'i' && str[i+5] == 'n' && str[i+6] == 'o'){
				str[i+6] = 'a';
			}
		}
	}
	cout << str << endl;
}

int main() {
	int n;
	string str;
	cin >> n;
	cin.ignore();
	for(int i=0; i<n; ++i){
		getline(cin,str);
		Hoshina(str);
	}
	return 0;
}

Measured memory_bytes: 1200
#include  <iostream>
#include  <cstdlib>
#include  <cmath>


int main(void)
{
	int list[101] = {0};  // 0, 1, 2, 3, ... 99, 100

	for(int i = 0; i < 101; i++)
		list[i] = i;

	int X, N;
	std::cin >> X >> N;

	for(int i = 0; i < N; i++){
		int var;
		std::cin >> var;

		list[var] = -1;
	}

	int ans;
	if(list[X] != -1){
		// X自身が答え
		ans = X;
	}
	else{
		if(N < 100){
			// 1 ~ 100 のどこかに答えがある
			int var1 = 0;
			for(int i = X-1; i > 0; i--){
				if(list[i] != -1){
					var1 = i;
					break;
				}
			}

			int var2 = 101;
			for(int i = X+1; i < 101; i++){
				if(list[i] != -1){
					var2 = i;
					break;
				}
			}

			if((X - var1) > (var2 - X))
				ans = var2;
			else
				ans = var1;
		}
		else{
			// 1 ~ 100は全て消えた、なので答えは0か100
			if(X > 101 - X)
				ans = 101;
			else
				ans = 0;
		}
	}

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

	return EXIT_SUCCESS;
}


Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
int main() {
	ll N, K, t = 0, t2 = 0;
	cin >> N >> K;
	vector<int> a(N);
	rep(i, 0, N)cin >> a[i];
	rep(i, 0, N)rep(i2, i + 1, N)if (a[i] > a[i2])t++;
	rep(i, 0, N)rep(i2, 0, N)if (a[i] > a[i2])t2++;
	printf("%lld\n", (t * K % mod + (K - 1) * K / 2 % mod * t2 % mod) % mod);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n, k, i, s = 0;

  scanf("%d %d", &n, &k);

  for (i = 0; i < n; i++) {
    if (i == 0) {
      s = k;
    } else {
      s *= (k - 1);
    }
  }

  printf("%d\n", s);

  return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int k,i,t,j,p,n;
ll f[105][5][2];
string s;
char c[105];
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>s>>k;
	n=(int)s.size();
	for(i=1;i<=n;i++)c[i]=s[i-1];
	f[0][0][1]=1;
	for(i=0;i<n;i++)
	{
		for(t='0';t<='9';t++)
		{
			for(j=0;j<2;j++)
			{
				if(j && t>c[i+1])continue;
				for(p=0;p<=k;p++)
				{
					if(p-(t!='0')<0)continue;
					f[i+1][p][j&(c[i+1]==t)]+=f[i][p-(t!='0')][j];
				}
			}
		}
	}
	cout<<f[n][k][0]+f[n][k][1]<<endl;
	return 0;
}


Measured memory_bytes: 256
#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 <iomanip>
using namespace std;
#define INF 1e15
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;


int main() {
	
	bool check = false;
	int n, m, i, j, k;
	cin >> n >> m;
	vector<ll> score(n, -INF);
	vector<vector<ll>> G(n, vector<ll>(n, -INF));
	vector<bool> c(n, false);

	for (i = 0; i < m; i++) {
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		G[a][b] = c;
	}

	score[0] = 0;

	for (i = 0; i < n; i++) {
		bool update = false;
		for (j = 0; j < n; j++) {
			for (k = 0; k < n; k++) {
				if (G[j][k] != -INF && score[j] != -INF && score[k] < score[j] + G[j][k]) {
					score[k] = score[j] + G[j][k];
					update = true;
				}
			}
		}
		if (!update)break;
	}

	//n-1頂点を通る正の閉路があるかを考える必要がある。
	//ただの閉路検出だけではだめ。
	for (j = 0; j < n; j++) {
		for (k = 0; k < n; k++) {
			if (G[j][k] != -INF && score[j] != -INF && score[k] < score[j] + G[j][k]) {
				score[k] = score[j] + G[j][k];
				c[k] = true;
			}
			if (G[j][k] != -INF && c[j])c[k] = true;
		}
	}
	


	if (c[n-1])cout << "inf" << endl;
	else cout << score[n - 1] << endl;


	return 0;
}

Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        scan.close();
        String[] data = str.split(" ");
        int charge = 0;
        int age = 0;
        int price = 0;
            age = Integer.parseInt(data[0]);
            price = Integer.parseInt(data[1]);
        if ( 6 <= age && age <= 12) {
            charge = price / 2;
        } else if (age > 12 ) {
            charge = price;
        }
        System.out.println(charge);
        }
}

Measured memory_bytes: 21844
#!/usr/bin/python
from collections import defaultdict
import sys,csv,math,heapq
if sys.version_info[0]>=3: raw_input=input
INF=1<<30

def shortestPath(g,s,dist,prev):
	n = len(g)
	dist[s] = 0
	Q=[]
	heapq.heappush(Q,(0,-2,s))
	while Q:
		e=heapq.heappop(Q)
		if prev[e[2]]!=-1: continue
		prev[e[2]]=e[1]
		for f in g[e[2]]:
			if dist[f[2]]>e[0]+f[0]:
				dist[f[2]]=e[0]+f[0]
				heapq.heappush(Q,(e[0]+f[0],f[1],f[2]))

V,E,R=map(int,raw_input().split())
dist=[INF]*V
prev=[-1]*V
G=defaultdict(list)
for _ in range(E):
	s,t,d=map(int,raw_input().split())
	G[s].append([d,s,t])
	G[s].append([d,t,s])
shortestPath(G,R,dist,prev)
for e in dist:
	print('INF' if e==INF else e)

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


int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  vector<pair<long long, long long>> AB(M);
  vector<long long> HH(N);
  for (int i = 0; i < M; i++) {
    cin >> AB.at(i).first >> AB.at(i).second;
    HH.at(AB.at(i).first - 1) = max(HH.at(AB.at(i).first - 1), H.at(AB.at(i).second - 1));
    HH.at(AB.at(i).second - 1) = max(HH.at(AB.at(i).second - 1), H.at(AB.at(i).first - 1));
  }


  int ans = 0;
  for (int i = 0; i < N; i++) {
    if(H.at(i) > HH.at(i)) ans++;
  }

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


Measured memory_bytes: 6424
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long LL;

const int N=2e5+10,mod=1e9+7;;

LL a[N],s[N];

int main()
{
    int n;
    cin>>n;
    LL sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        s[i]=(s[i-1]+a[i])%mod;
    }
    for(int i=1;i<n;i++) sum=(sum+(a[i]*(((s[n]-s[i])%mod+mod))%mod))%mod;
    cout<< sum <<endl;
    return 0;
}

Measured memory_bytes: 6884
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

//const ll MOD = 1000 * 1000 *1000 + 7 ;
const ll MOD = 998244353;
inline void chadd(ll &a, const ll b) { a = (a + b) % MOD;}
inline ll add(const ll a, const ll b){ return (a + b) %  MOD;}
inline void chsub(ll &a, const ll b) { a = (a - b + MOD) % MOD;}
inline ll sub(const ll a, const ll b){ return (a - b + MOD) % MOD; }
inline void chmul(ll &a, const ll b) { a = (a * b) %  MOD;}
inline ll mul(const ll a, const ll b){ return (a * b) %  MOD;}

const int MOD_TABLE_SIZE = 1000000 + 10;
ll inv[MOD_TABLE_SIZE];
ll fac[MOD_TABLE_SIZE];
ll facinv[MOD_TABLE_SIZE];

void mod_table_init() {
  inv[1] = 1;
  for(int i = 2; i < MOD_TABLE_SIZE; i++) {
    inv[i] = MOD - (MOD / i) * inv[(int)MOD % i] % MOD;
  }
  fac[0] = facinv[0] = 1;
  for(int i = 1; i < MOD_TABLE_SIZE; i++) {
    fac[i] = (fac[i-1] * (ll)i) % MOD;
    facinv[i] = (facinv[i-1] * inv[i]) % MOD;
  }
}

inline ll P(int a, int b) {
  if(a<b) return 0LL;
  return fac[a] *  facinv[a-b] % MOD;
}

inline ll C(int a, int b) {
  if(a<b) return 0LL;
  return (fac[a] * facinv[b] % MOD) * facinv[a-b] % MOD;
}

inline ll H(int a, int b) {
  return C(a+b-1,b);
}

int main() {
  mod_table_init();
  int N, M, K; cin>>N>>M>>K;
  vector<ll> beki(N, 1);
  for(int i = 1; i < N; i++) beki[i] = mul(beki[i-1], M-1);
  ll ans = 0;
  for(int i = 0; i <= K; i++) {
    ll tmp = C(N-1, i);
    chmul(tmp, beki[N-i-1]);
    //    cout << N-1 << " " << i << " " << tmp << endl;
    chadd(ans, tmp);
  }
  chmul(ans, M);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 27844
// abc102_b
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
	int	N;
	cin >> N;
	vector<int> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec[i];
	}
	int max = 0;
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			max = std::max(max, abs(vec[i]-vec[j]));
		}
	}
	std::cout << max << endl;
}

Measured memory_bytes: 256
using System;

namespace abc092B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split();
            int D = int.Parse(str[0]);
            int X = int.Parse(str[1]);
            int Ans = 0;
            int m = 0;
            int[] A = new int[N];
            for(int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
                int B = 0;
                while (B <= D)
                {
                    B = 1 + m * A[i];
                    
                    m = m + 1;
                    Ans = Ans + 1;
                }
                m = 0;
                Ans = Ans - 1;
            }
            Console.WriteLine(X + Ans);
        }
    }
}


Measured memory_bytes: 13140
bingo = []
ans = false
flag = Array.new(3).map{Array.new(3, false)}
3.times do
    bingo << gets.chomp.split(" ").map(&:to_i)
end
n = gets.chomp.to_i
n.times do
    b = gets.chomp.to_i
    bingo.each_with_index do |arr, i|
        arr.each_with_index do |e, j|
            if b == e
                flag[i][j] = true
            end
        end
    end
end

if flag[0][0] == true && flag[1][1] == true && flag[2][2] == true
    ans = true
end
if flag[0][2] == true && flag[1][1] == true && flag[2][0] == true
    ans = true
end
flag.each do |i|
    if i.all?{|v| v == true}
        ans = true
    end
end
flag = flag.transpose
flag.each do |i|
    if i.all?{|v| v == true}
        ans = true
    end
end

puts ans ? "Yes" : "No"

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

int main(){
  long long N;
  cin>>N;
  long long *A;
  A = new long long[N];
  for(long long i = 0;i < N;i++){cin>>A[i];}
  sort(A,A+N);
  long long mix = A[0];
  long long tmp = mix;
  while(1){
  	for(long long i = 0;i < N;i++){
    	if((A[i] % mix < mix) && (A[i] % mix != 0))mix = A[i] % mix; 
  	}
    if(tmp == mix)break; else tmp = mix;
  }
  cout<<mix;
  
 return 0; 
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll mo=1000000007;
ll combi(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

int N;
int A[101010];
int num[101010];
vector<int> V;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N+1) {
		cin>>A[i];
		num[A[i]]++;
	}
	FOR(i,N+1) if(num[A[i]]==2) V.push_back(i);
	int a=V[0];
	int b=V[1]-V[0]-1;
	int c=N-V[1];
	for(i=1;i<=N+1;i++) {
		if(i==1) {
			cout<<N<<endl;
			continue;
		}
		ll ret=0;
		// D=0
		ret += combi(N-1,i);
		// D=1
		ret += combi(a+c,i-1);
		ret += (combi(a+c+b,i-1)-combi(a+c,i-1))*2;
		
		// D=2
		ret += combi(N-1,i-2);
		
		cout<<(ret%mo+mo)%mo<<endl;
		
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 11392
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
const int MOD = 1000000007;



int main() {
  ll n, k;
  ll ans = 0;

  cin >> n >> k;
  for (ll i=k; i<=n+1; i++) {
    ll max_n = i*(n-i+1 + n)/2;
    ll min_n = i*(0 + i-1)/2;
    ans += max_n - min_n + 1;

  }
  cout << ans%MOD << endl;
}


Measured memory_bytes: 3196
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}
        static String getStr(){return sc.next();}
        static int getInt(){return sc.nextInt();}
        static Long getLong(){return sc.nextLong();}
        static boolean isNext(){return sc.hasNext();}
        static treeNode[] tree;
  		public static void main(String[] args){
          int N = getInt();
          int Q = getInt();
          tree = new treeNode[N];
          for(int i = 0; i < N; i++){
           	 tree[i] = new treeNode();
          }
          for(int i = 0; i < N-1; i++){
            int mae = getInt() - 1;
            int ato = getInt() - 1;
            tree[mae].addNode(ato);
            tree[ato].addNode(mae);
          }
          for(int i = 0; i < Q; i++){
           	 tree[getInt()-1].setCount(getInt());
          }
          
          String[] output = new String[N];
          bfs();
          //myout("");
          
          for(int i = 0; i < N; i++){
            //myout(tree[i].nodes + " " + tree[i].counter);
            output[i] = String.valueOf(tree[i].sum);
          }
          myout(String.join(" ",output));
          
        }
        //便利メソッド追加枠ここから
  		static void bfs(){
          ArrayDeque<Integer[]> queue = new ArrayDeque<Integer[]>();
          Integer[] first = new Integer[2];
          first[0] = 0;
          first[1] = tree[0].counter;
          queue.addFirst(first);
          tree[0].access = true;
          while(queue.size() > 0){
            Integer[] tmp = queue.pollFirst();
            tree[tmp[0]].addCount(tmp[1]);
            ArrayList<Integer> children = tree[tmp[0]].nodes;
            for(int i = 0; i < children.size(); i++){
              if(!tree[children.get(i)].access){
                tree[children.get(i)].access = true;
                Integer[] addQueue = new Integer[2];
                addQueue[0] = children.get(i);
                addQueue[1] = tmp[1] + tree[children.get(i)].counter;
                queue.addLast(addQueue);
              }
            }
          }
        }
		public static class treeNode{
          ArrayList<Integer> nodes = new ArrayList<Integer>();
          int counter = 0;
          int sum = 0;
          boolean access = false;
          treeNode(){}
          void addNode(int node){
            nodes.add(node);
          }
          void addCount(int count){
            sum += count;
          }
          void setCount(int count){
            this.counter += count;
          }
        }
        //便利メソッド追加枠ここまで
}


Measured memory_bytes: 222260
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;

int d[4] = {1, -1, 4, -4};
map<string, int> memo;

void swap(string &s, int a, int b){
    char temp = s[a];
    s[a] = s[b];
    s[b] = temp;
}

void bfs(){
    queue<pair<string, int>> q;
    q.push(make_pair("01234567", 0));

    pair<string, int> n;
    while(not q.empty()){
        n = q.front(); q.pop();
        rep(i,4){
            int np = n.second + d[i];
            if(n.second == 3 && np == 4) continue;
            if(n.second == 4 && np == 3) continue;
            if(np < 0 || np >= 8) continue;

            string cps = n.first;
            swap(cps, n.second, np);

            if(memo.count(cps) == 0){
                q.push(make_pair(cps, np));
                memo[cps] = memo[n.first] + 1;
            }
        }
    }
}

int main(){
    memo["01234567"] = 0;
    bfs();
    //show(memo.size())
    string input;
    while(cin >> input){
        range(i,1,8){
            string temp;
            cin >> temp;
            input+=temp;
        }

        cout << memo[input] << endl;
    }
}

Measured memory_bytes: 5356
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, s, n) for(int i = s; i < n; i++)
using namespace std;
int main(void) {
    int n, k;
    cin >> n >> k;

    long long cnt1 = 0;
    long long cnt2 = 0;
    reps(i, 1, n+1) {
        if (i % k == 0) {
            cnt2++;
            continue;
        }
        if ((i*2) % k == 0) {
            cnt1++;
            continue;
        }
    }
    cnt1 *= cnt1 * cnt1;
    cnt2 *= cnt2 * cnt2;
    long long cnt = cnt1 + cnt2;

    cout << cnt << endl;

}



Measured memory_bytes: 256
n=gets.to_i
a=gets.split.map &:to_i
a.unshift(0);a<<0
s=0
for i in 0..n
s+=(a[i]-a[i+1]).abs
end
for i in 1..n
p s-(a[i-1]-a[i]).abs-(a[i]-a[i+1]).abs+(a[i-1]-a[i+1]).abs
end

Measured memory_bytes: 18692
import java.util.Scanner;

//Calculation of Expressions
public class Main{

	class R{
		int r, i;
		public R(int r, int i) {
			this.r = r;
			this.i = i;
		}
		R add(R t){
			return new R(r+t.r, i+t.i);
		}
		R sub(R t){
			return new R(r-t.r, i-t.i);
		}
		R mul(R t){
			return new R(r*t.r-i*t.i, r*t.i+i*t.r);
		}
		public String toString() {
			if(r==0&&i==0)return "0";
			if(i==0)return r+"";
			if(r==0)return i+"i";
			if(i>0)return r+"+"+i+"i";
			return r+""+i+"i";
		}
	}
	
	boolean f;
	char[] s;
	int id;
	char get(){
		return s[id++];
	}
	
	void check(R r){
		if(Math.abs(r.r)>10000||Math.abs(r.i)>10000)f = true;
	}
	
	R exp(){
		R res = term();
		while(true){
			char ch = get();
			if(ch=='+'){
				res = res.add(term());
				check(res);
			}
			else if(ch=='-'){
				res = res.sub(term());
				check(res);
			}
			else break;
		}
		return res;
	}
	
	R term(){
		R res = fact();
		check(res);
		char ch = get();
		while(ch=='*'){
			R r = fact();
			check(r);
			res = res.mul(r);
			check(res);
			ch = get();
		}
		id--;
		return res;
	}
	
	R fact(){
		char ch = get();
		if(ch=='(')return exp();
		if(Character.isDigit(ch)){
			int x = 0;
			while(Character.isDigit(ch)){
				x = x*10 + ch-'0';
				check(new R(x, 0));
				ch = get();
			}
			id--;
			return new R(x, 0);
		}
		return new R(0, 1);
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			s = (sc.next()+"$").toCharArray();
			id = 0;
			f = false;
			R res = exp();
			System.out.println(f?"overflow":res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <stdio.h>
using namespace std;


int main(){
    int h,w;
    cin >> h >> w;
    while(h!=0 && w!=0){
        for(int i=0; i<h; i++){
            if(i!=0){
                cout << endl;
            }
            for(int i=0; i<w; i++){
                cout << "#";

            }
        }
        cout << endl;
        cout << endl;
        cin >> h >> w;
        
    }
}
	


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int A,B;cin >> A >> B;
  cout << max(A+B,max(A-B,A*B)) << endl;
  return 0;
}


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

const int M = 2019;

int main() {
    string S; cin >> S;
    int N = S.size();
    int x = 1, now = 0;
    map<int, int> ma;
    ma[0]++;
    for(int i = N - 1; i >= 0; --i) {
        int a = S[i] - '0';
        now = a * x + now;
        now %= M;
        ma[now]++;
        x *= 10, x %= M;
    }
    int64_t ans = 0;
    for(auto &[key, val] : ma) {
        ans += (int64_t)val * (val - 1) / 2;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3768
#include <stdio.h>

int main()
{
  int aparts[4][3][10]={} , b,f,r,v,i,j,k,n;

  scanf("%d",&n);
  for(i=0 ; i < n ; i++)
    {
      scanf("%d %d %d %d",&b,&f,&r,&v);
      aparts[b-1][f-1][r-1] += v;  //n??¶????????±=????????¨?±?????????±????????°????????????????????´????????????
                                   //????????¨?±?????????±????????°??????????????????=????????¨?±??????\?±??????°???????????????= v?????????
    }
  
  for(i=0 ; i<4 ; i++)
    {
      for(j = 0 ; j <3 ; j++)
	{
	  for(k=0 ; k<10 ; k++)
	    {
	      printf(" %d",aparts[i][j][k]);
	    }
	  printf("\n");
	}

      if(i==3)break;
      printf("####################\n");
    }
  
  return 0;

}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int k,h,w;
  cin >> h >> w >> k;
  int c[h][w];
  int b=0;
  rep(i,h){
    string s;
    cin >> s;
    rep(j,w){
      if(s[j]=='#'){
        c[i][j]=1;
        b++;
      }
      else c[i][j]=0;
    }
  }
  int ans=0;
  int u=(1<<h);
  int v=(1<<w);
  //cout << u << v << endl;
  rep(i,u){
    rep(j,v){
      int x=0;
      rep(o,h){
        rep(p,w){
          if(i&(1<<o))continue;
          if(j&(1<<p))continue;
          if(c[o][p]==1)x++;
        }
      }
      if(x==k)ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
using namespace std;

using ll = long long;

typedef pair<int, int> P;

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	ll ans=1;
	for(;y>0;y>>=1){
		if(y&1)(ans*=x)%=mod;
		(x*=x)%=mod;
	}
	return ans;
}

ll facto(ll a){
	if(a==1)
		return 1;
	else return a * facto(a - 1);
}

ll n, k;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
	cin >> n >> k;
	if(k==1)
		cout <<0;
	else
		cout << n - k;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		double dbA = 1.00000 * a;
		int b = scan.nextInt();
		double dbB = 1.00000 * b;
		scan.close();
		//System.out.println("dbA:" + dbA);
		
		int d = a / b;
		int r = a % b;
		double f = dbA / dbB;
		
		System.out.print(d + " " +r + " ");
		System.out.printf("%.5f", f);
		
	}

}

Measured memory_bytes: 17344
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}




int main(void) {

	char b;
	cin >> b;

	if (b == 'T' || b == 'A') {
		cout << (char)('T' + 'A' - b) << endl;
	}
	else {
		cout << (char)('C' + 'G' - b) << endl;
	}



	return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(N)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, left, right):
        """
        [left, right)のsegfuncしたものを得る
        left: index(0-index)
        right: index(0-index)
        """
        res = self.ide_ele
        left += self.num
        right += self.num
        while left < right:
            if left & 1:
                res = self.segfunc(res, self.tree[left])
                left += 1
            if right & 1:
                res = self.segfunc(res, self.tree[right - 1])
            left >>= 1
            right >>= 1
        return res


def segfunc(x, y):
    """
    区間(x,y)に対して行いたい操作の入力
    最小値：min(x,y)
    最大値：max(x,y)
    和：x + y
    積：x * y
    最大公約数：math.gcd(x, y)
    """
    return max(x, y)


ide_ele = -f_inf


def resolve():
    n, c = map(int, input().split())
    XV = [list(map(int, input().split())) for _ in range(n)]

    R = [0]
    prev = 0
    for i in range(n):
        x, v = XV[i]
        R.append(R[-1] + v - (x - prev))
        prev = x
    seg = SegTree(R, segfunc, ide_ele)

    R_r = [0]
    prev_r = 0
    for i in reversed(range(n)):
        x_r, v_r = XV[i]
        x_r = c - x_r
        R_r.append(R_r[-1] + v_r - (x_r - prev_r))
        prev_r = x_r
    seg_r = SegTree(R_r, segfunc, ide_ele)

    res1 = max(R)
    res2 = max(R_r)
    res3 = 0
    for i in range(1, n + 1):
        right = R[i] - XV[i - 1][0]
        idx = n + 1 - i
        left = seg_r.query(0, idx)
        res3 = max(res3, right + left)
    res4 = 0
    for i in range(1, n + 1):
        left_r = R_r[i] - (c - XV[-i][0])
        idx_r = n + 1 - i
        right_r = seg.query(0, idx_r)
        res4 = max(res4, left_r + right_r)
    print(max(res1, res2, res3, res4))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 41460