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

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,s,n) for(int i=s;i<n;i++)
#define GRGR(dx,dy) for(int i=0,dir[6]={0,-1,0,1,0,0},dx,dy;dx=dir[i],dy=dir[i+1],i<4;i++)
typedef pair<int,int> P;
struct T {int x1,y1,x2,y2;};
int w,h,n;
int vw,vh;
set<int> vx;
set<int> vy;
T t[1002];
bool bd[3000][3000];

void debug(){
  REP(j,vh){
    REP(i,vw)cout<<bd[i][j]<<" ";
    cout<<endl;
  }
}

int r2v(set<int> vs,int r){
  return distance(vs.begin(),vs.find(r));
}

void paint(int i,int j){
  queue<P> que;
  que.push(P(i,j));
  bd[i][j]=0;
  while(!que.empty()){
    P p=que.front();que.pop();
    int px=p.first, py=p.second;
    GRGR(dx,dy){
      if(px+dx<0||vw<=px+dx||py+dy<0||vh<=py+dy){
        continue;
      }
      if(bd[px+dx][py+dy]){
        que.push(P(px+dx,py+dy));
        bd[px+dx][py+dy]=0;
      }
    }
  }
}

int main(){
  while(cin>>w>>h,w){
    cin>>n;
    vx.clear();
    vy.clear();
    vx.insert(0);
    vx.insert(w);
    vy.insert(0);
    vy.insert(h);
    int x1,y1,x2,y2;
    REP(i,n){
      cin>>x1>>y1>>x2>>y2;
      vx.insert(x1);
      vy.insert(y1);
      vx.insert(x2);
      vy.insert(y2);
      t[i]={x1,y1,x2,y2};
    }
    vw=vx.size()-1;
    vh=vy.size()-1;
    REP(i,vw)REP(j,vh)bd[i][j]=1;
    REP(i,n){
      x1=r2v(vx,t[i].x1);
      y1=r2v(vy,t[i].y1);
      x2=r2v(vx,t[i].x2);
      y2=r2v(vy,t[i].y2);
      FOR(i,x1,x2)FOR(j,y1,y2)bd[i][j]=0;
    }
    //debug();
    int ans=0;
    REP(i,vw)REP(j,vh){
      if(bd[i][j]){
        paint(i,j);
        ans++;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 4716
s = input()[::-1]
gogun = ["maerd","remaerd","esare","resare"]
while (len(s)>0):
    if len(s) >= 5 and (s[:5] == gogun[0] or s[:5] == gogun[2]):
        s = s[5:]
    elif len(s) >= 6 and s[:6] == gogun[3]:
        s = s[6:]
    elif len(s) >= 7 and s[:7] == gogun[1]:
        s = s[7:]
    else:
        print("NO")
        break
else:
    print("YES")


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,j;
  cin >> n;
  vector<int> a(n),b(n);
  for(int i = 0;i<n;i++){
    cin >> a.at(i);
    j = a.at(i);
    b.at(j-1) = i+1;
  }
  for(int i = 0;i<n;i++){
    cout << b.at(i) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
void Yes(bool c) { if (c)print("Yes"); else print("No"); };
void YES(bool c) { if (c)print("YES"); else print("NO"); };

void solve() {
    int A,B,C,X;
    cin >> A >> B>> C >> X;
    X /= 50;
    ll ans = 0;
    rep(i,A+1){
        rep(j,B+1){
            rep(k,C+1){
                if(i*10 + j*2 + k*1 == X) {
                    ans++;
                }
            }
        }
    }
    print(ans);
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>

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

int main() {
	string S;
	cin >> S;
	if (!S.compare("Sunny"))cout << "Cloudy";
	else if (!S.compare("Cloudy")) cout << "Rainy";
	else cout << "Sunny";



	return 0;
}



Measured memory_bytes: 256
A,B,K = [int(x) for x in input().split()]
cnt = 0
while(cnt<K):
    if(A%2==1):
        A-=1
    B+=A//2
    A//=2
    cnt+=1
    if(cnt>=K):break
    if(B%2==1):
        B-=1
    A+=B//2
    B//=2
    cnt+=1
    
print(A,B)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<double>p(N);
  for(int i=0;i<N;i++)
    cin>>p.at(i);
  vector<vector<double>>dp(1+N,vector<double>(1+N,0));
  dp[0][0]=1;
  for(int i=1;i<=N;i++)
    dp[i][0]=dp[i-1][0]*(1-p.at(i-1));
  for(int i=1;i<=N;i++){
  for(int j=1;j<=N;j++){
  if(j<=i)
    dp[i][j]=p[i-1]*dp[i-1][j-1]+(1-p[i-1])*dp[i-1][j];
    else
      dp[i][j]=0;
  
  }
  }double ans=0;
  for(int k=(N+1)/2;k<=N;k++)
    ans+=dp[N][k];
  cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
const int mod = 1000000007;
const int modx = 998244353;
#define ll long long
#define readi(x) scanf("%d", &x)
#define reads(x) scanf("%s", x)
#define readl(x) scanf("%I64d", &x)
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)
#define rep2(i, a, b) for (i = b; i >= a; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bpc(x) __builtin_popcount(x)
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pdd pair<double, double>
#define pic pair<int, char>
#define ddouble long double
#define PI 3.1415926535
#define endl "\n"
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define prod(x, y) ((x % mod) * (y % mod)) % mod
#define add(x, y) ((x % mod) + (y % mod)) % mod
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define pqs priority_queue<int, vector<int>, greater<int>>
#define pqb priority_queue<int>
#define mii map<int, int>
#define mll map<ll, ll>
using namespace std;
//using namespace __gnu_pbds;
/*ll power(ll x, ll y)
{
    ll r = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            r = (r*x) % mod;

        y = y>>1;
        x = (x*x) % mod;
    }
    return r;
}*/
const int N = 1e5 + 5;
int dp[N] = {}, n, a[N];
int rec(int k)
{
    if (dp[k])
        return dp[k];
    int i;
    rep(i, n)
    {
        if (k - a[i] >= 0 && rec(k - a[i]) == 2)
            return dp[k] = 1;
    }
    return dp[k] = 2;
}
void thunder()
{
    int i, j, k;
    cin >> n >> k;
    rep(i, n) cin >> a[i];
    dp[0] = 2;
    if (rec(k) == 1)
        cout << "First" << endl;
    else
        cout << "Second" << endl;
    return;
}
int main()
{
    /*#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif*/
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll q = 1;
    //cin >> t;
    while (q--)
        thunder();
}


Measured memory_bytes: 7116
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(int argc, char const *argv[]) {
  int W, a, b;
  cin >> W >> a >> b;
  if (b > a + W) {
    cout << b - a - W << endl;
  } else if (b + W < a) {
    cout << a - b - W << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
from collections import deque

def bfs(num):
    if visited[num]==0:
        visited[num]=C.pop(-1)
        for item in way[num]:
            d.append(item)
    return

N=int(input())

ans=[-1]*N
way=[[]for i in range(N)]
visited=[0]*N

for _ in range(N-1):
    a,b=map(int,input().split())
    way[a-1].append(b-1)
    way[b-1].append(a-1)

C=list(map(int,input().split()))
C.sort()
#print(C)


d=deque([0])

while d:
    temp=d.popleft()
    if visited[temp]==0:
        bfs(temp)

ans=0
for i in range(N):
    for item in way[i]:
        ans+=min(visited[i],visited[item])

print(ans//2)
print(*visited)
    


Measured memory_bytes: 6388
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  sort(begin(a), end(a));
  V<> b(n), c(n);
  if (n & 1) {
    for (int i = 0; i < n / 2; ++i) b[2 * i + 1] = a[i];
    b[n - 1] = a[n / 2];
    for (int i = n + 1 >> 1; i < n; ++i) b[2 * (i - (n + 1 >> 1))] = a[i];
    sort(rbegin(a), rend(a));
    for (int i = 0; i < n / 2; ++i) c[2 * i + 1] = a[i];
    c[n - 1] = a[n / 2];
    for (int i = n + 1 >> 1; i < n; ++i) c[2 * (i - (n + 1 >> 1))] = a[i];
  } else {
    for (int i = 0; i < n >> 1; ++i) b[2 * i + 1] = a[i];
    for (int i = n >> 1; i < n; ++i) b[2 * (i - n / 2)] = a[i];
  }
  lint res = 0;
  for (int i = 0; i < n - 1; ++i) res += abs(b[i + 1] - b[i]);
  lint res2 = 0;
  for (int i = 0; i < n - 1; ++i) res2 += abs(c[i + 1] - c[i]);
  cout << max(res, res2) << '\n';
}

Measured memory_bytes: 1536
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VI p(n);
    REP(i,0,n) cin >> p[i];
    int cnt = 0;
    REP(i,0,n) if (p[i] != i + 1) ++cnt;
    if (cnt <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int player = sc.nextInt();
        int[][] n = new int[player][3];
        int[][] flag = new int[player][3];

        int[] score = new int[player];
        int cnt = 0;
        int buf = 0;
        for(int i = 0;i < player;i++){
            for(int j = 0;j < 3;j++){
                n[i][j] = sc.nextInt();
                flag[i][j] = 1;
            }
        }
        for(int i = 0;i < player;i++){
            for(int j = 0;j < 3;j++){
                for(int k = i+1;k < player;k++){
                    if(n[i][j] == n[k][j]){
                        flag[i][j] = 0;
                        flag[k][j] = 0;
                    }
                }
            }
        }
        for(int i = 0;i < player;i++){
            for(int j = 0;j < 3;j++){
            //  System.out.print(flag[i][j]+":");
                n[i][j] = n[i][j] * flag[i][j];
            }
            //System.out.println();
        }

        for(int i = 0;i < player;i++){
            for(int j = 0;j < 3;j++){
                score[i] = score[i]+n[i][j];
            }
        }
        for(int i = 0;i < player;i++){
            System.out.println(score[i]);
        }


    }
}

Measured memory_bytes: 28900
#include<bits/stdc++.h>
using namespace std;
int n,a[2005],ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;++i)
	 cin>>a[i];
	sort(a,a+n);
	for(int i=1;i<n;++i)
	{
		int it=0;
		for(int j=i+1;j<n;++j)
		{
			while(it<i&&a[it]+a[i]<=a[j]) ++it;
			ans+=i-it;
		}
	}
	cout<<ans;
	return 0;
}

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

typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

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

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n;
int main(){
    cin>>n;
    vector<int> b(n-1);
    rep(i,n-1)cin>>b.at(i);
    vector<int>a(n);
    a.at(0)=b.at(0);
    a.at(n-1)=b.at(n-2);
    rep2(i,1,n-2)a.at(i)=min(b.at(i),b.at(i-1));
    ll ans=0;
    rep(i,n)ans+=a.at(i);
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long
ll a[400000],sum[2000000],sz[4000000];
map<ll,ll>d,vs;
vector<ll> v[40];
queue<ll>q;

int main()
{
    IO;
    ll i, j, n, m,mm=1e6, k=1, t, ans=0,l=0, g, p;
    string s1,s2;
    cin>>s1>>s2;
    s1+=s2[s2.size()-1];
    if(s1==s2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3648
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;
ll n;

ll cal(ll k, ll a, ll b, ll c) {
	if (k > n) return 0;
	ll res=0;
	if (a > 0 && b > 0 && c > 0) res += 1;
	res += cal(k * 10 + 3, a + 1, b, c);
	res += cal(k * 10 + 5, a, b + 1, c);
	res += cal(k * 10 + 7, a, b, c + 1);
	return res;
}


signed main() {
	cin >> n;
	ll ans = cal(0, 0, 0, 0);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> a(n+1,0);
    rep(i,n){
        if(s[i] =='A' && s[i+1] == 'C'){
            a[i+1]+=1;
        }
    }
    rep(i,n){
        a[i+1] = a[i] + a[i+1];
    }
    // rep(i,n){
    //     cout << a[i] << endl;
    // }
    rep(i,q){
        int x,y;
        cin >> x >> y;
        if(x==1){
            cout << a[y-1] << endl;
        }else{
            cout << a[y-1] - a[x-1] << endl; 
        }
    }


    return 0;
}

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

struct Node {
  int v, cost;
  bool operator>(const Node &n) const {
    return cost > n.cost;
  }
};

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

  vector<vector<int>> g(n, vector<int>(n, -1));
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int v, c;
      cin >> v >> c;
      g[u][v] = c;
    }
  }

  vector<int> dists(n, -1);
  priority_queue<Node, vector<Node>, greater<Node>> q;
  q.push({0, 0});
  while (!q.empty()) {
    Node node = q.top();
    q.pop();

    if (dists[node.v] != -1) {
      continue;
    }
    dists[node.v] = node.cost;

    for (int i = 0; i < n; i++) {
      if (g[node.v][i] != -1) {
	q.push({i, node.cost + g[node.v][i]});
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << i << ' ' << dists[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;

void solve();

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

void solve() {
    int n,h;
    cin >> n >> h;
    int a[n],b[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    int HSum = 0;
    int ama = 0;
    sort(b,b+n);
    sort(a,a+n);
    for(int i = n-1; i >= 0; i--) {
        if(a[n-1] > b[i]) break;
        h -= b[i];
        ama++;
        if(h <= 0) break;
    }
    if(h > 0) {
        ama += h / a[n-1];
        h -= (h / a[n-1]) * a[n-1];

        if(h > 0) ama++;
    }

    cout << ama << endl;
}

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

using namespace std;

int main() {
  int W,H;
  cin >> H >> W;
  char field[60][60];
  int count = 0;
  int dx[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
  int dy[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
  // 入力
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      scanf(" %c",&field[x][y]);
    }
  }

  // 解く
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if(field[x][y] == '.') {
        count = 0;
        for (int i = 0; i < 8; i++) {
          if (x + dx[i] >= 0 && y + dy[i] >= 0 && x + dx[i] < W && y + dy[i] < H ) {
            if(field[x + dx[i]][y + dy[i]] == '#') {
              count++;
            }
          }
        }
        field[x][y] = '0' + count;
      }
    }
  }

  // 出力
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      printf("%c",field[x][y]);
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>

//     MLE,TLE魔
//↓↓↓↓↓↓↓↓↓↓↓↓
#define int long long
//↑↑↑↑↑↑↑↑↑↑↑↑
//     MLE,TLE魔
#define endre getchar();getchar();return 0
#define moder 1000000007
#define inf 5000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
struct edge { int to, cost; };
int dx[5] = { 0,1,0,-1 }, dy[5] = { 1,0,-1,0 };
map<int, int>factor(int x) {
	map<int, int>res;
	for (int i = 2; i*i <= x; i++) {
		while (x%i == 0) {
			x /= i;
			res[i]++;
		}
	}
	if (x != 1)res[x]++;
	return res;
}
/*--------Library Zone!--------*/


int n, a[100005], b[100005];
int t[100005];
signed main() {
	cin >> n;
	REP(i, n + 1) {
		cin >> a[i];
	}
	REP(i, n + 1) {
		cin >> b[i];
	}
	int ans = 1;
	REP(i, n + 1) {
		if (a[i] != a[i - 1] && a[i] > b[i]) {
			cout << 0 << endl;
			endre;
		}
		if (b[i] != b[i + 1] && b[i] > a[i]) {
			cout << 0 << endl;
			endre;
		}
		if (a[i] != a[i - 1] || b[i] != b[i + 1])continue;
		ans *= min(a[i], b[i]);
		ans %= moder;
	}
	cout << ans << endl;
	endre;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
 
template<class T>
struct BellmanFord {
private:
    struct Edge {
        int from, to;
        T cost;
    };
    
    int n;
    vector<vector<int>> graph;
    vector<bool> used;
    vector<Edge> edges;
    vector<int> prev;
    
    void dfs(int v) {
        if (used[v]) return;
        used[v] = true;
        for(auto u : graph[v]) {
            dfs(u);
        }
    }
    
public:
    const T inf = numeric_limits<T>::max() / 2 - 1;
    vector<T> dist;
    vector<int> path;
    
    BellmanFord(){};
    BellmanFord(int _n) {
        n = _n;
        graph.resize(n);
        used.resize(n);
        dist.resize(n);
        prev.resize(n);
    }
    
    void add_edge(int from, int to, T cost) {
        edges.push_back((Edge){from, to, cost});
        graph[from].push_back(to);
    }
    
    bool get_distance(int from, int to = -1) {
        vector<bool> reach(n, true);
        for(int i = 0; i < n; i++) {
            fill(used.begin(), used.end(), false);
            dfs(i);
            if (to != -1) reach[i] = used[to];
        }
        fill(dist.begin(), dist.end(), inf);
        fill(prev.begin(), prev.end(), -1);
        dist[from] = 0;
        for(int i = 0; i < n; i++) {
            bool update = false;
            for(auto e : edges) {
                if ((!reach[e.from]) || (!reach[e.to]) || (dist[e.from] == inf)) continue;
                if (dist[e.to] > (dist[e.from] + e.cost)) {
                    dist[e.to] = dist[e.from] + e.cost;
                    prev[e.to] = e.from;
                    update = true;
                }
            }
            if (!update) break;
            if (i == (n - 1)) {
                return false;
            }
        }
        return true;
    }
    
    void get_path(int to) {
        path = vector<int>(0);
        for (; to != -1; to = prev[to]) {
            path.push_back(to);
        }
        reverse(path.begin(), path.end());
    }
};
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m, p;
    cin >> n >> m >> p;
    BellmanFord<ll> bf(n);
    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        bf.add_edge(a, b, p - c);
    }
    if (!bf.get_distance(0, n - 1)) {
        cout << -1 << endl;
    }
    else {
        ll ans = max(0LL, -bf.dist[n - 1]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int s=0,op=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') op=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*op;
}
int  main(){
	string s;cin>>s;
	cout<<s[0]<<s.size()-2<<s[s.size()-1];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=100010;
ll n,x,a[maxn],q[maxn],h[maxn],ans;
int main(){
	cin>>n;ll x;
	for(int i=1;i<=n;i++){
		cin>>x;
		a[x]=i;
	}
	for(int i=1;i<=n;i++){
		q[i]=i-1;h[i]=i+1;
	}
	for(int i=1;i<=n;i++){
		ll x=q[a[i]],y=q[x];
		ll z=h[a[i]],p=h[z];
		if(x!=0){
			ans+=(x-y)*(z-a[i])*i;
		} 
		if(z!=n+1){
			ans+=(a[i]-x)*(p-z)*i;
		}
		h[x]=z;
		q[z]=x;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
N,K = map(int,input().split())
S = input()
S = list(S)
if S[K-1] == 'A':
    S[K-1] = 'a'
    
if S[K-1] == 'B':
    S[K-1] = 'b'
    
if S[K-1] == 'C':
    S[K-1] = 'c'

S = ''.join(S)
print(S)
    

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000000;

ll n;
ll ans=0;
int main(){
  cin >> n;
  if(n%2 != 1){
    rep(i, 28){
      ll k = pow(5,i)*2;
      ans += n/k;
    }
  }
  cout << ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,j) for(int i=0;i<j;i++)
#define REP(i,j,z) for(int i=j;i<z;i++)
int main()
{
	ll N;
	ll i=1;
	ll ans=0;
	cin>>N;
	N--;
	cout<<N*(N+1)/2<<endl;	
}


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

using ld = long double;

constexpr ld eps = 1e-10;
constexpr ld pi = std::acos(-1.0);

using point = std::complex<long double>;

class line {
public:
    line()
        : a(point(0, 0)), b(point(0, 0))
    {}
    line(point a_, point b_)
        : a(a_), b(b_)
    {}

    point a, b;
};

class circle {
public:
    circle()
        : p(point(0, 0)), r(0)
    {}
    circle(point p_, long double r_)
        : p(p_), r(r_)
    {}

    point p;
    long double r;
};

long double dot(point a, point b) {
    return std::real(std::conj(a) * b);
}

point proj(line l, point p) {
    long double t = dot(p - l.a, l.a - l.b) / std::norm(l.a - l.b);
    return l.a + t * (l.a - l.b);
}

std::vector<line> tangent_cp(circle c, point p) {
    std::vector<line> res;
    point v = c.p - p;
    ld d = std::abs(v), len = std::sqrt(std::norm(v) - c.r * c.r);
    if(std::isnan(len)) {
        return res;
    }
    point v1 = v * point(len / d, c.r / d);
    point v2 = v * point(len / d, -c.r / d);
    res.push_back(line(p, p + v1));
    if(len < eps) {
        return res;
    }
    res.push_back(line(p, p + v2));
    return res;
}

ld get_angle(point p) {
    ld res = arg(p);
    if(res < 0) {
        res += 2 * pi;
    }
    return res;
}

int main() {
    ld x, y, theta, w;
    cin >> x >> y >> theta >> w;
    point p(x, y);
    ld r_ang = get_angle(p);
    theta = theta / 180 * pi;
    w = w / 180 * pi;
    bool clockwise = false;
    {
        ld ang = theta - r_ang;
        if(ang > 0 && ang <= pi || ang < 0 && ang <= -pi) {
            clockwise = true;
        }
    }

    ld lb = 0, ub = w * abs(p);
    for(int i = 0; i < 60; ++i) {
        ld v = (lb + ub) / 2;
        circle c(point(0, 0), v / w);
        auto ls = tangent_cp(c, p);
        bool ok = false;
        for(auto& l : ls) {
            auto pp = proj(l, point(0, 0));
            ld t1 = abs(p - pp) / v;
            ld ang = get_angle(pp);
            if(clockwise) {
                ld check = r_ang - ang;
                if(check < 0) {
                    check += 2 * pi;
                }
                if(check > pi) {
                    continue;
                }
                ang = theta - ang;
            } else {
                ld check = ang - r_ang;
                if(check < 0) {
                    check += 2 * pi;
                }
                if(check > pi) {
                    continue;
                }
                ang = ang - theta;
            }
            if(ang < 0) {
                ang += 2 * pi;
            }
            ld t2 = ang / w;
            if(t2 >= t1) {
                ok = true;
            }
        }
        if(ok) {
            ub = v;
        } else {
            lb = v;
        }
    }
    cout << fixed << setprecision(10) << lb << endl;
}


Measured memory_bytes: 3336
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))


#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321

int N,M,K,T;
vector<int> E[100]; bool vis[100];
int ans = 0;

void dfs(int x, int c){
	if( c == N ){
		ans++; return;
	}
	vis[x] = true;
	for(auto e : E[x])if(!vis[e]){
		dfs(e,c+1);
	}
	vis[x] = false;
}

int main(void){
	geti(N,M);
	rep(i,M){
		int a,b; geti(a,b); E[a].pb(b); E[b].pb(a);
	}

	dfs(1,1);
	cout << ans;

}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')

typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int a, b;
    cin >> a >> b;
    cout << 6 - a - b << "\n";
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    ll max_a = 0;
    rep(i,n){
        cin >> a[i];
        max_a = max(max_a, a[i]);
    }

    unordered_map<ll,ll> ump;
    rep(i,n){
        ump.emplace(a[i], min(max_a - a[i], a[i]));
    }
    auto itr = max_element(ump.begin(), ump.end(),
    [&](const auto &a, const auto &b) -> bool{
        return a.second < b.second;
    });
    // sort(ump.begin(), ump.end());
    cout << max_a << " " << (*itr).first << endl;
    return 0;
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
int fir[100001],nex[200001],to[200001];
int n,m,p,q,N,M,ans[100001];
bool vis[100001];
void add(int p,int q)
{
	nex[++M]=fir[p];fir[p]=M;to[M]=q;
	nex[++M]=fir[q];fir[q]=M;to[M]=p;
}
void find(int now)
{
	for(int i=fir[now];i;i=nex[i])
	if(!vis[to[i]])
	{
		ans[++N]=to[i];
		vis[to[i]]=1;
		find(to[i]);
		return;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d%d",&p,&q),add(p,q);
	vis[1]=1;ans[N=1]=1;
	find(1);int g=N;find(1);
	printf("%d\n",N);
	for(int i=N;i>g;i--)
		printf("%d ",ans[i]);
	for(int i=1;i<=g;i++)
		printf("%d ",ans[i]);
	return 0;
} 

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007

using namespace std;
int soma[1000];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int aux;
        scanf("%d",&aux);
        soma[i] = soma[i-1] + aux; 
    }
    int menor = mod;
    for(int i=1;i<n;i++){
        menor = min(menor, abs(soma[n] - 2*soma[i]));
    }
    printf("%d\n",menor);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	
	if(a%3==0 || b%3==0 ||(a+b)%3==0){
		printf("Possible\n");
	} else{
		printf("Impossible\n");
	}

return 0;
}

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

int main()
{
    int64_t A,B,K;
    cin >>A >>B>>K;
    if(A>K)
    {
        cout << A-K <<" "<< B <<endl;
        return 0;
    }
    if(A+B<K)
    {
        cout << 0 <<" "<< 0 << endl;
        return 0;
    }
        cout << 0 <<" "<< B+A-K <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int A,B;

int main(){
	cin>>A>>B;
	cout<<A/B+A%B<<endl;
}


Measured memory_bytes: 3096
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;


void bf(string &s) {
  int count = 0;
  for(int i = 0; i <s.size(); i++)
  {
    for(int j = i + 1; j <= s.size(); j++)
    {
      string str = s.substr(i, j - i);
      ll num = stoi(str);
      if(num % 2019 == 0 && num != 0) {
        count++;
        cout << "can " + str << endl;
      }
    }
  }
  cout << count << endl;
}

int main()
{
  string s;
  cin >> s;
  int base = 2019;
  int result = 0;
  reverse(s.begin(), s.end());
  v memo(base, 0);
  int d = 1;
  int num = 0;
  memo[0] = 1;
  for(int i = 0; i < s.size(); i++) {
    num = num + d * (s[i] - '0');
    num %= base;
    memo[num]++;
    d = (d * 10) % base;
  }
  for(int i = 0; i < base; i++)
  {
    if(memo[i] > 0) {
      result += (memo[i] * (memo[i] - 1)) / 2;
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 3696
# AOJ 1101 A Simple Offline Text Editor

class TextEditor
  def initialize(text)
    @text = text
    @cursor = 0
  end

  def to_s
    text_before_cursor + "^" + text_after_cursor
  end

  def inspect
    %Q|#<TextEditor:0x#{"%x".%(object_id)} "#{to_s}">|
  end

  def forward_char
    @cursor += 1 if @cursor < @text.length
    self
  end

  def forward_word
    if @cursor < @text.length
      m = /^ +/.match(text_after_cursor)
      @cursor += m[0].length if m
    end

    if @cursor < @text.length
      m = /^[^ ]+/.match(text_after_cursor)
      @cursor += m[0].length if m
    end

    self
  end

  def backward_char
    @cursor -= 1 if @cursor > 0
    self
  end

  def backward_word
    if @cursor > 0
      last_blank_pos = text_before_cursor.sub(/\s+$/, "").rindex(" ")
      if last_blank_pos
        @cursor = last_blank_pos + 1
      else
        @cursor = 0
      end
    end

    self
  end

  def insert(text)
    @text = text_before_cursor + text + text_after_cursor
    @cursor += text.length

    self
  end

  def delete_char
    unless @cursor == @text.length
      @text = text_before_cursor + text_after_cursor[1..-1]
    end

    self
  end

  def delete_word
    if @cursor < @text.length
      @text = text_before_cursor +
        text_after_cursor.sub(/ *[^ ]+/, "")
    end

    self
  end

  private
  def text_before_cursor
    if @cursor.zero?
      ""
    else
      @text[0..(@cursor - 1)]
    end
  end

  def text_after_cursor
    if @cursor == @text.length
      ""
    else
      @text[@cursor..-1]
    end
  end
end

n_texts = gets.to_i
n_texts.times do
  t = TextEditor.new(gets.chomp)

  n_commands = gets.to_i
  n_commands.times do
    command, argument = gets.chomp.split(" ", 2)
    argument.sub!(/^ +/, "")

    case command
    when "forward"
      case argument
      when "char"
        t.forward_char
      when "word"
        t.forward_word
      end
    when "backward"
      case argument
      when "char"
        t.backward_char
      when "word"
        t.backward_word
      end
    when "insert"
      m = /^"(.*)"/.match(argument)
      t.insert m[1] if m
    when "delete"
      case argument
      when "char"
        t.delete_char
      when "word"
        t.delete_word
      end
    end
  end

  puts t.to_s
end

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

#define gap " "
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ok cout<<"ok"<<endl
#define dbg(x) cout<<(#x)<<" is "<<x<<endl
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int N=100009;
int ar[1000];
int main()
{
  //fastio; 
  int n,k,i,r,sum=0;
  scanf("%d %d",&n,&k);

  for(i=0; i<n; i++)
  {
  	scanf("%d",&ar[i]);
  }

  sort(ar,ar+n);

  for(i=n-1,r=1; r<=k; r++,i--)
  {
     sum+=ar[i];
  }
  printf("%d\n",sum);
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

bool vcomp(vector<int>& a, vector<int>& b)
{
  if (a.size() != b.size())
    return false;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != b[i])
      return false;
  }
  return true;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  string s, t;
  cin >> s;
  cin >> t;
  vector<vector<int>> vs(26);
  vector<vector<int>> vt(26);
  int n = s.size();
  for (int i = 0; i < n; i++) {
    vs[(int)(s[i] - 'a')].push_back(i);
    vt[(int)(t[i] - 'a')].push_back(i);
  }
  int ans = true;
  for (int i = 0; i < 26; i++) {
    if (vs[i].size()) {
      char c = s[vs[i][0]];
      dumpv(c, vs[i]);
      c = t[vs[i][0]];
      int j = c - 'a';
      dumpv(c, vt[j]);
      if (!vcomp(vs[i], vt[j])) {
        ans = false;
        break;
      }
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

struct BIT {
    BIT(int n) : b(n + 1), n(n) {}
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) b[k] += v;
    }
    int sum(int k) {
        int s = 0;
        for (; k > 0; k -= k & -k) s += b[k];
        return s;
    }
    vector<int> b;
    int n;
};

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

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }

    int t[2] = {};

    BIT bt(2000);
    for (int i = n - 1; i >= 0; i--) {
        bt.add(a[i], 1);
        t[0] += bt.sum(a[i]);
    }

    sort(a.begin(), a.end());
    int i1, p = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] != p) {
            i1 = i;
            p = a[i];
        }
        t[1] += i1;
    }

    cout << ((ll)k * t[0] + (ll)k * (k - 1) / 2 % P * t[1]) % P << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#define MOD(x) (x + 1000000007) % (1000000007)

using namespace std;

template <class t>
using vec = vector<t>;
using ll = long long;

const int MAX = numeric_limits<int>::max();

template <class t>
ostream &operator<<(ostream &out, vec<t> &v)
{
    for (auto &e : v)
        out << e << " ";
    out << "\n";
    return out;
}

template <class t>
istream &operator>>(istream &in, vec<t> &v)
{
    for (auto &e : v)
        in >> e;
    return in;
}

int n;
vec<vec<ll>> a;
vec<ll> dp, pre;

void find(ll used, vec<int> &not_used, ll group_mask, int index)
{
    if (index == not_used.size())
    {
        dp[used | group_mask] = max(dp[used | group_mask], dp[used] + pre[group_mask]);
        return; 
    }
    find(used, not_used, group_mask, index + 1);
    find(used, not_used, group_mask | (1 << not_used[index]), index + 1);
}

int main()
{
    cin >> n;
    a = vec<vec<ll>>(n, vec<ll>(n));
    cin >> a;
    dp = vec<ll>(1 << n);
    pre = vec<ll>(1 << n);
    for (ll mask = 0; mask < (1 << n); mask++)
        for (int i = 0; i < n; i++)
            if (mask & (1 << i))
                for (int j = i + 1; j < n; j++)
                    if (mask & (1 << j))
                        pre[mask] += a[i][j];
    for (ll mask = 0; mask < (1 << n); mask++)
    {
        vec<int> not_used;
        for (int i = 0; i < n; i++)
            if (!(mask & (1 << i))) not_used.push_back(i);
        find(mask, not_used, 0, 0);
    }
    cout << dp[(1 << n) - 1];
    return 0;
}

Measured memory_bytes: 4316
#include<stdio.h>

int main(){
  int n=0;
  int i=0;
  int a=0;
  int b=0;
  int c=0;
  int max=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d %d",&a,&b,&c);
    max=a;
    if(max<b){
      max=b;
    }
    if(max<c){
      max=c;
    }

    if(max==a){
      if( (a*a) == ((b*b)+(c*c)) ){
	printf("YES\n");
      }
      else{
	printf("NO\n");
      }
    }
    else if(max==b){
     if( (b*b) == ((a*a)+(c*c)) ){
       printf("YES\n");
     }
      else{
	printf("NO\n");
      }
    }
    else{
      if( (c*c) == ((a*a)+(b*b)) ){
	printf("YES\n");
      }
      else{
	printf("NO\n");
      }
    }
  }

  return 0;

}

Measured memory_bytes: 0
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a,b;
	cin>>a>>b;
	if(a >= 10 || b >= 10){
		cout<<-1;
	}	
	else{
		cout<<a*b;
	}
	return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
typedef vector<edge> edges;
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///
vi all, odd, v;
int allt[1000005], oddt[1000005];

int main()
{
	v.push_back(0);
	FOR(i, 1, 1000) v.push_back(v[i - 1] + i);
	all.push_back(0);
	FOR(i,1, v.size())
	{
		all.push_back(all[i - 1] + v[i]);
		if (all[i] & 1) odd.push_back(all[i]);
		if (all[i] > 1000000) break;
	}
	int n;
	fill(ALL(allt), INF); fill(ALL(oddt), INF);
	allt[0] = oddt[0] = 0;
	REP(i, 1000001)REP(j, all.size())
	{
		int t = i + all[j];
		if (t >= 1000001) break;
		allt[t] = min(allt[i] + 1, allt[t]);
	}

	REP(i, 1000001)REP(j, odd.size())
	{
		int t = i + odd[j];
		if (t >= 1000001) break;
		oddt[t] = min(oddt[i] + 1, oddt[t]);
	}
	while (cin >> n, n)
	{
		cout << allt[n] << " " << oddt[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 9040
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        AB[] ab = new AB[N];
        PriorityQueue<Integer> queue = new PriorityQueue<>(
                Comparator.reverseOrder());
        for (int i = 0; i < N; i++) {
            ab[i] = new AB(sc.nextInt(), sc.nextInt());
        }
        // 振込が早い順にソート 昇順
        Arrays.sort(ab, (a, b) -> a.a - b.a);
        int ans = 0;
        int ptr = 0;
        // A日後に報酬B
        // 受けたことのある仕事はできない
        // 一番報酬が高い ∧ 日数が担保されてる
        // PriorityQueue add=offer
        for (int Mi = 1; Mi <= M; Mi++) {
//            for (int Ni = ptr; Ni < N; Ni++) {
//                if (ab[Ni].a <= Mi) {
            while(ptr < N && ab[ptr].a <= Mi) {
                    queue.add(ab[ptr].b);
                    ptr++;
                }
            
            if (queue.isEmpty())
                continue;
            ans += queue.poll();
        }

        // System.out.println(queue);

        // for (int i = 1; i <= M; i++) {
        // //ptrはどの配列まで検査したか
        // //ptrが件数よりも小さい &&
        // while (ptr < N && ab[ptr].a <= i) {
        // queue.add(ab[ptr].b);
        // ptr++;
        // System.out.println("i :"+i+", ab: "+ab[ptr].b+", ptr: " +ptr);
        // }
        // if (queue.isEmpty()) continue;
        // ans += queue.poll();
        // }

        System.out.println(ans);
    }

    static class AB {
        int a, b;

        AB(int a, int b) {
            this.a = a;
            this.b = b;
        }
    }
}

Measured memory_bytes: 90732
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 170, task b, 2020/06/14
//ms,
/*
*/

int main(void){
  int x, y;
  cin >>x >>y;
  for(int i=0;i<=x;i++){
    if(2*i+4*(x-i)==y) goto EXIST;
  }

  cout <<"No"<<endl;
  return 0;

  EXIST:
    cout <<"Yes"<<endl;
  return 0;
}
/*
*/


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

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

  string s, t;
  cin >> s >> t;

  vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, 0));

  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
      }

      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
    }
  }

  string ans = "";
  int i = (int)s.size();
  int j = (int)t.size();
  while (i > 0 && j > 0) {
    if (dp[i][j] == dp[i - 1][j]) {
      --i;
    } else if (dp[i][j] == dp[i][j - 1]) {
      --j;
    } else {
      ans = s[i - 1] + ans;
      --i;
      --j;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 35584