akhauriyash/Code-Regression huggingface dataset:
///  author:Kissheart  ///
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
double x;
char y[5];
double ans=0;
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lf%s",&x,y);
        if(!strcmp(y,"BTC"))
            ans+=x*380000.0;
        else
            ans+=x*1.0;
    }
    printf("%.10lf\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
signed main()
{
    speed
    int n,d;cin>>n>>d;
    int q=(2*d+1);
    if((n%q)==0){cout<<(n/q);}
    else
    {
        cout<<(n/q)+1;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
static const ll LL_MAX = (ll)1 << 55;

int main()
{
	ll n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);

	ll ans = 0;
	ll x[100001] = {};
	scanf("%lld", &x[1]);
	repe(i, 2, n) {
		scanf("%lld", &x[i]);
		ans += min((x[i] - x[i - 1])*a, b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,unsafe-math-optimizations")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
#include <assert.h>
#include <immintrin.h>
#include <emmintrin.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;
#ifdef ONLINE_JUDGE
#define assert(...) /* nothing */
#endif
#define DEBUG_CAT
#ifdef DEBUG_CAT
#define dbg(...)   printf( __VA_ARGS__ )
#else 
#define dbg(...)   /****nothing****/
#endif
//int rint();char rch();long long rlong();
const int mn=1e5+4;
vector<int> inp[mn];
bitset<mn> b;
bitset<mn> predp;
bool pre(int x, int p) {
  bool ans=b[x];
  int id=0;
  for (auto &y:inp[x]) {
    if (y==p) continue;
    //printf("p:%d id:%d x:%d y:%d\n",p,id,x,y);
    ans=pre(y,x)||ans;
    ++id;
  }
  //printf("p:%d x:%d ans:%d\n",p,x,ans);
  return predp[x]=ans;
}
vi g[mn];
int nume=0;
void makeg(int x, int p) {
  if (predp[x]==0) return;
  for (auto &y:inp[x]) {
    if (y==p) continue;
    if (predp[y]==0) continue;
    g[x].PB(y); g[y].PB(x);
    nume++;
    makeg(y,x);
  }
}
bitset<mn> c;
int dpe[mn],dpi[mn];
int dfs1(int x, int p) { // end MUST exclude bottom vertex
	int bonus=(c[x]?1:-1);
	int ans=1;
	for (auto &y:g[x]) {
		if (y==p) continue;
		int cand=dfs1(y,x)+bonus+1;
		chkmax(ans,cand);
	}
	//printf("x:%d dpe:%d\n",x,ans);
	return dpe[x]=ans;
}
int dfs2(int x, int p) { // start MUST include bottom vertex
	int bonus=(c[x]?1:-1);
	int ans=bonus+1;
	for (auto &y:g[x]) {
		if (y==p) continue;
		int cand=dfs2(y,x)+bonus+1;
		chkmax(ans,cand);
	}
	//printf("x:%d dpi:%d\n",x,ans);
	return dpi[x]=ans;
}
int final=0;
void peek(int x, int p) {
	int bonus=c[x]?1:-1;
	int be=-INF,bi=-INF;
	int ans=0;
	for (auto &y:g[x]) {
		if (y==p) continue;
		chkmax(ans,dpe[y]+bi+bonus);
		chkmax(ans,dpi[y]+be+bonus);
		chkmax(be,dpe[y]);
		chkmax(bi,dpi[y]);
	}
	chkmax(ans,bi);
	chkmax(ans,be+bonus);
	chkmax(final,ans);
	for (auto &y:g[x]) if (y!=p) peek(y,x);
}

int main()
{
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; cin>>n;
  for (int i=1;i<n;i++) {
    int x,y; cin>>x>>y;
    //printf("x:%d y:%d\n",x,y);
    inp[x].PB(y); inp[y].PB(x);
  }
  string s; cin>>s;
  for (int x=1;x<=n;x++) {
    b[x]=(s[x-1]=='W');
    //printf("x:%d %d\n",x,(int)b[x]);
  }
  int initx=-1;
  for (int x=1;x<=n;x++) {
    if (b[x]) {initx=x; break;}
  }
  if (initx==-1) {
    printf("0\n"); return 0;
  }
  pre(initx,-1);
  makeg(initx,-1);
  for (int x=1;x<=n;x++) c[x]=(g[x].size()&1)^b[x];
  dfs1(initx,-1); dfs2(initx,-1);
  peek(initx,-1);
  int ans=nume*2+c.count()-(final);
  printf("%d\n",ans);
}


Measured memory_bytes: 21456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.nextLine();
		int num = N.length();
		int H = 0;

		for (int i = 0; i < num; i++) {
			H += N.charAt(i) - '0';
		}

		if (Integer.parseInt(N) % H == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;
const int MAX = 12;

int main(){

  int n, m, x;
  cin >> n >> m >> x;
  vector<int> price(n);
  vector<vector<int>> value(n, vector<int>(m));
  vector<int> sum_value(m);
  int min_price = INFI;

  rep(i,n){
    cin >> price[i];
    rep(j,m) cin >> value[i][j];
  }
  int bit_max = 1<<n;
  for (int i = 1; i <= bit_max; i++){
    int sum_price = 0;
    fill(sum_value.begin(), sum_value.end(), 0);
    for (int j = 0; j < n; j++){
      if(1<<j & i){
        sum_price += price[j];
        for(int k = 0; k < m; k++) sum_value[k] += value[j][k];
      }
    }
    auto itr = min_element(sum_value.begin(), sum_value.end());
    if (*itr >= x) min_price = min(min_price, sum_price);
  }

  if (min_price != INFI) cout << min_price << endl;
  else cout << -1 << endl;

  return 0;
}

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


int main()
{
	int N;
	cin>>N;
	string S;
	cin>>S;
	int cnt_r=0;
	string ans="";
	rep(i,N)
	{
		if(S[i]==')')
		{
			if(cnt_r<=0)
			{
				ans+='(';
			}
			else
			{
				cnt_r--;
			}
		}
		else
		{
			cnt_r++;
		}	
	}
	ans+=S;
	rep(i,cnt_r)
	{
		ans+=')';
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3560
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

Graph g;
vector<long long> depth;
void dfs(int u, int p) {
    for (auto &e: g[u]) if (e.first != p) {
        dfs(e.first, u);
        chmax(depth[u], depth[e.first] + e.second);
    }
}
vector<long long> height;
void dfs2(int u, int p, int d_par) {
    vector<pair<long long, int>> d_child;
    d_child.emplace_back(0, -1);        // sentinel
    for (auto &e: g[u]) {
        long long dv = (e.first == p ? d_par : depth[e.first]) + e.second;
        d_child.emplace_back(dv, e.first);
    }
    sort(d_child.rbegin(), d_child.rend());
    height[u] = d_child[0].first;
    for (auto &e: g[u]) if (e.first != p) {
        long long nd_par = d_child[d_child[0].second == e.first].first;
        dfs2(e.first, u, nd_par);
    }
}

int main() {
    int n; cin >> n;
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int s, t; cin >> s >> t; s--, t--;
        g[s].emplace_back(t, 1);
        g[t].emplace_back(s, 1);
    }
    depth.resize(n);
    dfs(0, -1);
    height.resize(n);
    dfs2(0, -1, 0);
    for (auto h: height) cout << (n - 1) * 2 - h << endl;
    return 0;
}


Measured memory_bytes: 33036
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }
    
    vector<int>dirX={-1,0,1};
    vector<int>dirY={-1,0,1};


    void solve(){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll x,y;
        ll maxi=-1e18;
        maxi=max({maxi,a*c,b*d,a*d,b*c});
        cout<<maxi;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
        //    cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

Measured memory_bytes: 3652
#include <iostream>

using namespace std;
int m,d,i,j,nr;
bool ok;
int main()
{
    cin>>m>>d;
    for(i=1;i<=m;i++)
    {
        ok=false;
        for(j=22;j<=d;j++)
        {
            if((j%10)*(j/10)==i && j%10>=2)
            {
                nr++;
            }
        }
    }
    cout<<nr;
    return 0;
}


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

using namespace std;

int main()
{
    int n; cin >> n;
    
    int cnt = 0; 
    for(int i = 0; i < n; i++)
    {
        int x, y; cin >> x >> y;
        if(x != y)
        {
            cnt = 0;
            continue;
        }
        else
        {
            cnt++;
            if(cnt >= 3)
            {
                cout << "Yes";
                return 0;
            }
        }
    }

    cout << "No";
    return 0;
}

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

int main(){
    long long n,k,res,mx=0,ans=1;
    cin>>n>>k;
    res=k;
    for(long long i=2;i*i<=k;i++){
        if(k%i==0){
            int c=0;
            while(res%i==0){
                res/=i;
                c++;
            }
            ans*=pow(i,c/n);
        }
    }
    
    if(res!=1){
        ans*=pow(res,1/n);
    }
    cout<<ans;
    
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;
constexpr ll mod = 1000000007;

ll N, M;
ll A[1010], B[1010];

int main()
{
  scanf( "%lld%lld", &N, &M );
  rep( i, N )
    scanf( "%lld", A+i );
  rep( i, M )
    scanf( "%lld", B+i );
  
  std::sort( A, A+N );
  std::sort( B, B+M );

  ll prod = 1;

  for( ll i = N*M; i > 0; --i )
  {
    ll p = std::lower_bound( A, A+N, i )-A;
    ll q = std::lower_bound( B, B+M, i )-B;

    if( A[p] == i && B[q] == i )
    {
      if( (p+1 < N && A[p+1] == A[p]) || (q+1 < M && B[q+1] == B[q]) )
        prod = 0;
    }
    else if( A[p] == i )
      prod = (prod*(M-q)) % mod;
    else if( B[q] == i )
      prod = (prod*(N-p)) % mod;
    else
      prod = (prod*((N-p)*(M-q)-(N*M-i))) % mod;
  }

  printf( "%lld\n", prod%mod );

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;


int n;

string *color;

queue<int> q;

int *ans;

vector<int> g[1000000];


void bfs(int x){
  color[x] = "gray";
  q.push(x);


  while(q.size() != 0){
    int u = q.front();
    q.pop();

    for(int i = 0; i < g[u].size(); i++){
      int v = g[u][i];
      if(color[v] == "white"){
        color[v] = "gray";
        q.push(v);
      }
    }

    color[u] = "black";
    ans[u] = x;


  }
  return;
}


int main(){

  cin >> n;

  color = new string[n];

  ans = new int[n];

  int m;

  cin >> m;


  int a, b;


  for(int i = 0; i < m; i++){
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }


  for(int i = 0; i < n; i++){
    color[i] = "white";
  }


  for(int j = 0; j < n; j++){
    if(color[j] == "white"){
      bfs(j);
    }
  }

  int q;

  cin >> q;

  for(int i = 0; i < q; i++){
    cin >> a >> b;
    if(ans[a] == ans[b]){
      cout << "yes" << endl;
    }
    else{
      cout << "no" << endl;
    }
  }

  return 0;
}



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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    ll a, v; cin >> a >> v;
    ll b, w; cin >> b >> w;
    ll t; cin >> t;

    ll dist = abs(a-b);
    ll vel = v - w;
    if(t*vel >= dist){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<P> p(m);
    
    rep(i,m) cin >>p[i].first >>p[i].second;

    rep(x,1000){
        int keta = 1;
        int nx = x/10;
        vector<int> d(1,x%10);
        while(nx){
            keta++;
            d.push_back(nx%10);
            nx/=10;
        }
        if(keta != n) continue;
        bool ok =true;
        reverse(d.begin(), d.end());
        rep(i,m){
            if(d[p[i].first-1] != p[i].second) ok =false;
        }
        if(ok){
            cout << x << endl;
            return 0;
        }
        }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cassert>
#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jiglypuff
#define ld long double
#define itn int
#define pir pair<int, int> 
#define all(x) (x).begin(), (x).end()
using namespace std;

lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x1, ld y1, ld x2, ld y2)
{
	return ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
	return (a * (a + 1LL)) / 2;
}
char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] = { 0, 0, 1, -1, 1, -1, 1, -1 };


const int N = 1e6 + 30;
const lli mod = 1e9 + 7;
const ld pi = acos(-1);
const int T = 238;
const ld e = 74e-9;

lli bp(lli a, lli b = -2LL)
{
	lli ret = 1;
	while (b)
	{
		if (b & 1) ret *= a, ret %= mod;
		a *= a;
		a %= mod;
		b >>= 1;
	}
	return ret;
}

int x, y, a, b, c;
int a1[N], b1[N], c1[N];
vector <lli> pat;
lli ans;
int main()
{
	fastio;
	cin >> x >> y >> a >> b >> c;
	for (int i = 0; i < a; i++)
	{
		cin >> a1[i];
	}
	sort(a1, a1 + a);
	reverse(a1, a1 + a);
	for (int i = 0; i < x; i++)
	{
		pat.push_back(a1[i]);
	}
	for (int i = 0; i < b; i++)
	{
		cin >> b1[i];
	}
	sort(b1, b1 + b);
	reverse(b1, b1 + b);
	for (int i = 0; i < y; i++)
	{
		pat.push_back(b1[i]);
	}
	for (int i = 0; i < c; i++)
	{
		cin >> c1[i];
		pat.push_back(c1[i]);
	}
	sort(all(pat));
	reverse(all(pat));
	for (int i = 0; i < x + y; i++)
	{
		ans += pat[i];
	}
	cout << ans << endl;
	return 0;
}


/*
  __
*(><)*
  \/ /
  ||/
--||
  ||
  /\
 /  \
/    \
*/


Measured memory_bytes: 14960
import java.util.Scanner;

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

            for (int i = s.length() - 1 - 1; i >= 0; i--) {
                String sub = s.substring(0, i);
                if (isEven(sub)) {
                    System.out.println(sub.length());
                    return;
                }
            }

            System.out.println(-1);
        }
    }

    private static boolean isEven(String s) {
        if (s.length() % 2 == 1) {
            return false;
        }

        int l = s.length() / 2;
        for (int i = 0; i < l; i++) {
            if (s.charAt(i) != s.charAt(l + i)) {
                return false;
            }
        }

        return true;
    }
}


Measured memory_bytes: 21716
N = int(input())
a = list(map(int, input().split()))
Alice_score = 0
Bob_score = 0

a.sort(reverse = True)

for i in range(len(a)):
    if i % 2 == 0:
        Alice_score += a[i]
    else:
        Bob_score += a[i]

print(Alice_score - Bob_score)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
const int INF = 2e9;
int main(){
    int N;
    cin >> N;
    int cnt = 0;
    bool zero = false;
    ll res = 0;
    ll m = INF;
    rep(i,N){
        ll a;
        cin >> a;
        if(a < 0)cnt++;
        if(a == 0)zero = true;
        res += abs(a);
        m = min(m,abs(a));
    }
    if(zero || cnt%2 == 0){
        cout << res << endl;
    }else{
        cout << res -2*m << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;
const int MOD = 1e9+7;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//C++17以上
template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int a;cin >> a;
    string s;cin >> s;
    cout << (a>=3200?s:"red") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>                                                       
                                                                          
using namespace std;                                                      
                                                                          
void judgment(int x,int y);                                               
                                                                          
int main (void) {                                                         
  int a, b;                                                               
  cin >> a >> b;                                                          
  judgment(a,b);                                                          
}                                                                         
                                                                          
void judgment(int x, int y) {                                             
  if (x < y) {                                                            
    cout << "a < b" << endl;                                              
  } else if (x > y) {                                                     
    cout << "a > b" << endl;                                              
  } else {                                                                
    cout << "a == b" << endl;                                             
  }                                                                       
                                                                          
}                                                                         
                                      

Measured memory_bytes: 3096
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------

int main(void) {
  ll s;
  cin >> s;
  if(s==1e18){
    cout << 0 << " " << 0 << " "
         << 1000000000 << " " << 0 << " "
         << 0 << " " << 1000000000
         << "\n";
    return 0;
  }
  cout << 0 << " " << 0 << " "
       << 1000000000 << " " << 1 << " "
       << 1000000000-(s%1000000000) << " " << s/1000000000+1
       << "\n";

}


Measured memory_bytes: 3656
import java.util.*;
import java.io.*;

public class Main {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader() throws FileNotFoundException {
            // reader = new BufferedReader(new FileReader("count.in"));
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }

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

        public int nextInt() { // reads in the next int
            return Integer.parseInt(next());
        }

        public long nextLong() { // reads in the next long
            return Long.parseLong(next());
        }

        public double nextDouble() { // reads in the next double
            return Double.parseDouble(next());
        }

        public int[] nextIntArr(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) arr[i] = nextInt();
            return arr;
        }

        public long[] nextLongArr(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) arr[i] = nextLong();
            return arr;
        }

        public double[] nextDoubleArr(int size) {
            double[] arr = new double[size];
            for (int i = 0; i < size; i++) arr[i] = nextDouble();
            return arr;
        }

    }

    public static void main(String[] args) throws IOException, FileNotFoundException {
        InputReader in = new InputReader();
        PrintWriter pw = new PrintWriter(System.out);

        int n = in.nextInt();
        int[] pts = in.nextIntArr(n);
        int[] dp = new int[n];

        dp[1] = Math.abs(pts[1] - pts[0]);
        for (int i = 2; i < dp.length; i++) {
            int oneback = dp[i - 2] + Math.abs(pts[i] - pts[i - 2]);
            int twoback = dp[i - 1] + Math.abs(pts[i] - pts[i - 1]);
            dp[i] = Math.min(oneback, twoback);
        }
        // System.out.println(Arrays.toString(dp));

        pw.println(dp[n - 1]);

        pw.close();
    }
}


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

using namespace std;
typedef long long int ll;
#define debug(val) "[ " << #val " : " << (val) << " ]\n"
#define space " "
#define space " "
#define vi vector<int>
#define PI atan(1)*4
#define pb push_back
#define ff first
#define ss second
#define PI atan(1)*4

const ll INF = (ll)1e18 ; 
void solve() {
	int n , W ; 
	cin >> n >> W ; 
	vector<ll> dp(100000 + 3 , INF) ; 
	int sz = (int)dp.size() ; 
	for(int i=0;i<n;i++){
		ll val , w ; 
		cin >> w >>val;
		dp[0] = 0 ;
		for(int j =sz-1;j>=val ;j--){
			dp[j] = min(dp[j] , w + dp[j - val]) ;
		}
		
	}
	ll res = 0 ; 
	for(int i=0;i<sz;i++){
		if(dp[i] <= W) res = i ; 
	}	
	cout << res <<endl; 
   
}
int main() {
#ifdef _DEBUG // place in cmake-build-debug folder
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int q = 1;
    //cin >> q;
    for (int i = 1; i <= q; i++) {
        // cout << "Case #" << i << ": ";
        solve();
    }
}


Measured memory_bytes: 4000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int d = sc.nextInt();
		int n = sc.nextInt();
		
		if (d == 0) {
			
			System.out.println((n == 100) ? 101 : n);
			
		} else if (d == 1) {
			
			System.out.println((n == 100) ? 101 * 100 : n * 100);
			
		} else {
			
			System.out.println((n == 100) ? 101 * 10000 : n * 10000);
			
		}
		
	}

}


Measured memory_bytes: 22868
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:1048576")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef tuple <int, int, int> t3;

int IT_MAX = 1 << 12;
const ll MOD = 1000000009;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<(n);i++)

ll in[55];
int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%lld", &in[i]);

	ll ans = 0;
	while (1) {
		ll s = 0;
		for (i = 1; i <= N; i++) {
			if (in[i] < N) continue;
			ll t = in[i] / N;
			in[i] = in[i] % N;
			in[i] -= t;
			ans += t;
			s += t;
		}
		if (s == 0) break;
		for (i = 1; i <= N; i++) in[i] += s;
	}
	return !printf("%lld\n", ans);
}

Measured memory_bytes: 256
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(l[int(input()) - 1])

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

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

  int maxE=1;
  for (int i=2;i<=X;i++) {
    for (int j=i*i;j<=X;j*=i) {
      maxE = std::max(maxE,j);
    }
  }

  std::cout << maxE << '\n';
  return 0;
}


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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define ll long long
#define ld long double
#define sz(s) ((int)s.size())
#define all(s) s.begin(), s.end()

using namespace std;

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

int n;
int x;
map <int, int> mp;
vector <int> v;

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &x);
        mp[x]++;
        if(mp[x] == 2) {
            mp[x] = 0;
            v.pb(x);
        }
    }
    sort(all(v));
    reverse(all(v));
    if(sz(v) < 2) puts("0");
    else cout << v[0] * 1ll * v[1] << endl;
}


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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N = 100005;
ll b[N], perm[N], l[N], r[N];
ll suff[N];
ll pref[N];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	ll n = 100000, x = 100000; 
	cin >> n >> x;
	ll sm = 0;
	for(int i = 1; i <= n; i++){
		b[i] = rand() % (x+1);
		l[i] = rand() % (x/2);
		r[i] = l[i] + rand() % (x / 2);
		cin >> b[i] >> l[i] >> r[i];
		perm[i] = i;
		sm += b[i];
	}
	sort(perm + 1, perm + n + 1, [&](int i, int j){return (x - b[i]) * (ll) r[i] + l[i] * (ll) b[i] > (x - b[j]) * (ll) r[j] + l[j] * (ll) b[j];});
	for(int i = 1; i <= n; i++){
		int ind = perm[i];
		pref[i] = pref[i - 1] + (x - b[ind]) * (ll) r[ind];
	}

	for(int i = n; i >= 1; i--){
		int ind = perm[i];
		suff[i] = suff[i + 1] + l[ind] * (ll) b[ind];
	}
	ll lo = 0, hi = sm;
	while(lo < hi){
		ll mid = (lo + hi) >> 1;
		ll num = mid / x;
		ll rem = mid % x;
		bool ok = false;
		if(num >= n) ok = true;
		else{
			for(int i = 1; i <= n; i++){
				int ind = perm[i];
				ll here = (rem <= b[ind] ? l[ind] : r[ind]) * (rem - b[ind]);
				if(i > num){
					here += pref[num];
					here -= suff[num + 1];
					here += b[ind] * (ll) l[ind];
				} else{
					here += pref[num + 1];
					here -= r[ind] * (ll) (x - b[ind]);
					here -= suff[num + 2];
				}
				if(here >= 0) ok = true;
			}
		}
		if(ok) hi = mid;
		else lo = mid + 1;
	}
	// trace(sm);
	cout << lo;
}

Measured memory_bytes: 8364
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main() {
    val a = readI()
    println(a + a * a + a * a * a)
}


Measured memory_bytes: 34400
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    string s;
    scan(s);
    int n = s.length.to!int;
    auto a = new int[](n + 1);

    foreach (i ; 0 .. n) {
        a[i + 1] = a[i] ^ (1 << (s[i] - 'a'));
    }

    debug {
        writeln(a);
    }

    auto opt = new int[](n + 1);
    auto dp = new int[](1<<26);
    dp[] = n;
    dp[0] = 0;

    foreach (i ; 1 .. n + 1) {
        int mn = dp[a[i]];

        foreach (j ; 0 .. 26) {
            mn = min(mn, dp[a[i] ^ (1<<j)]);
        }

        opt[i] = mn + 1;
        dp[a[i]] = min(dp[a[i]], opt[i]);

        debug {
            writeln(opt);
        }
    }

    writeln(opt[n]);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 268344
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
 
int main(){
    int n,W,H;
 
    while(cin >> n ,n){
	cin >> W >> H;
 
	bool field[H][W];
	memset(field,false,sizeof(field));
 
	int x,y;
	for(int i = 0 ; i < n ; i++){
	    cin >> x >> y;
	    x--; y--;
	    field[y][x] = true;
	}
 
	int S,T;
	cin >> S >> T;
 
	int ans = 0;
	for(int i = 0 ; i <= H-T ; i++){
	    for(int j = 0 ; j <= W-S ; j++){
		int cnt = 0;
		for(int k = i ; k < i+T ; k++){
		    for(int l = j ; l < j+S ; l++){
			if(field[k][l]) cnt++;
		    }
		} 
		ans = max(ans,cnt);
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;

    int idx_a, idx_z;
    int len = s.length();
    bool a = false, z = false;
    for (int i = 0; i < len; i++) {
        if (s[i] == 'A' && !a) {
            idx_a = i;
            a = true;
        }
        if (s[len-i-1] == 'Z' && !z) {
            idx_z = len-i-1;
            z = true;
        }
        if (a && z) break;
    }

    cout << (idx_z - idx_a + 1) << endl;
}


Measured memory_bytes: 640
#include <iostream>
//#include <string>

/*struct pair {
	int x;
	int y;
};*/


int main() {
	long long int n, k;
	std::cin >> n >> k;
	
	n %= k;
	long long min = 3000000000000000000;
	while (true) {
		n -= k;
		if (n < 0) {
			n *= -1;
		}
		if (min == n) {
			break;
		}
		if (min > n) {
			min = n;
		}
	}
	std::cout << min << std::endl;
	/*int ans;
	if (n % k == 0) {
		std::cout << 0 << std::endl;
		return 0;
	}
	while (true) {
		n %= k;
		if (n == 0) {
			ans = k;
			break;
		}
		k %= n;
		if (k == 0) {
			ans = n;
			break;
		}
	}
	std::cout << ans << std::endl;*/
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, 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;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  ll N, x; cin >> N >> x;
  vector<ll> a(N); rep(i, N) cin >> a[i];
  ll ans = 0;
  if (a[0] > x) {
    ans += a[0] - x;
    a[0] = x;
  }
  for (int i = 0; i + 1 < N; ++i){
    if (a[i] + a[i + 1] > x) {
      ll diff = a[i] + a[i + 1] - x;
      ans += diff;
      a[i + 1] -= diff;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> xl(n);
  for(int i = 0;i < n;i++){
    int x,l;
    cin >> x >> l;
    xl[i] = make_pair(x+l,x-l);
  }

  sort(xl.begin(),xl.end());

  int cnt = 1;
  int now = xl[0].first;
  for(auto p:xl){
    if(now <= p.second){
      cnt++;
      now = p.first;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  cout << s[0] << (int)s.size()-2 << s.back() << endl;
  return 0;
}


Measured memory_bytes: 256
<?php

while($line = fgets(STDIN)){
	$n = intval($line);
	if($n == 0){
		break;
	}
	
	$arr = array();
	$max = array();
	for($i = 0; $i < $n; $i++){
		$x = intval(fgets(STDIN));
		$arr[$i] = 0;
		$max[$i] = -1000000;
		for($j = 0; $j <= $i; $j++){
			$arr[$j] += $x;
			if($max[$j] < $arr[$j]){
				$max[$j] = $arr[$j];
			}
		}
	}
	
	echo max($max)."\n";
}

Measured memory_bytes: 16384
import fractions

argN = int(input())
argA = list(map(int,input().split()))

aryL = [0] * argN
aryR = [0] * argN
aryL[0] = argA[0]
aryR[argN-1] = argA[argN-1]

for i in range(1,argN):
  aryL[i] = fractions.gcd(aryL[i-1],argA[i])
  aryR[argN-1-i] = fractions.gcd(aryR[argN-i],argA[argN-1-i])

maxGcd = 0
for i in range(argN):
  if i == 0:
    wkGcd = aryR[1]
  elif i == argN - 1:
    wkGcd = aryL[argN - 2]
  else:
    wkGcd = fractions.gcd(aryL[i-1],aryR[i+1])
  if maxGcd < wkGcd:
    maxGcd = wkGcd

print(maxGcd)
  

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

int main() {
    int64_t X;
    cin >> X;

    int64_t A = 100;
    for (int i = 1;; ++i) {
        A = A + A * 0.01;

        if (X <= A) {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 3620
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
int n;
char s[200005];
bool flag[200005];
ll ans,num;
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	s[0]='W';
	for(int i=1;i<=2*n;i++)
	{
		if((s[i]==s[i-1]&&flag[i-1]==0)||(s[i]!=s[i-1]&&flag[i-1]==1))flag[i]=1;
		else flag[i]=0;
	}
	ans=1;
	for(int i=1;i<=2*n;i++)
	{
		if(flag[i]==1)
		{
			if(num==0)
			{
				printf("0\n");
				return 0;
			}
			ans=ans*num%MOD;
			num--;
		}
		else num++;
	}
	if(num!=0)
	{
		printf("0\n");
		return 0;
	}
	for(int i=1;i<=n;i++)ans=ans*i%MOD;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ll A, B, M; cin >> A >> B >> M;
    ll *a = new ll[A], *b = new ll[B];
    ll ma = 999999, mb = 999999;
    for (int i = 0; i < A; i++) {
        cin >> a[i];
        ma = min(ma, a[i]);
    }
    for (int i = 0; i < B; i++) {
        cin >> b[i];
        mb = min(mb, b[i]);
    }

    ll *x = new ll[M], *y = new ll[M], *c = new ll[M];
    for (int i = 0; i < M; i++)
        cin >> x[i] >> y[i] >> c[i];

    ll ans = 9999999999;

    for (int i = 0; i < M; i++) {
        ans = min(ans, a[x[i]-1] + b[y[i]-1] - c[i]);
    }

    cout << min(ans, ma+mb) << endl;
    return 0;
}

Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n;
int arr[N];
int pre[N];
int ans;
int power(int a , int b){
	int res = 1;
	while(b){
		if(b & 1){
			res = (1LL * res * a) % mod;
		}
		a = (1LL * a * a) % mod;
		b >>= 1;
	}
	return res;
}
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , arr + i);
	}
	for(int i = 1 ; i <= n ; ++i){
		pre[i] = (pre[i - 1] + power(i , mod - 2)) % mod;
	}
	for(int i = 1 ; i <= n ; ++i){
		ans = (ans + 1LL * arr[i] * pre[i]) % mod;
		ans = (ans + 1LL * arr[i] * pre[n - i + 1]) % mod;
		ans = (ans + 1LL * arr[i] * (mod - 1LL)) % mod;
	}
	for(int i = 1 ; i <= n ; ++i){
		ans = (1LL * ans * i) % mod;
	}
	printf("%d\n" , ans);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,k,a[2010],b[2010],xd,ans;
const ll mod=1e9+7;
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    for(ll i=1;i<=n;++i)
		cin>>a[i];
	for(ll i=1;i<=n;++i)
		for(ll j=i+1;j<=n;++j)
			xd=(xd+(a[i]>a[j]))%mod;
	sort(a+1,a+n+1);
	for(ll i=1;i<=n;++i)
	{
		ll sum=1;
		while(a[i]==a[i+1]&&i<=n)++i,++sum;
		ans+=(sum*(i-sum)%mod*(((k-1)*k/2)%mod))%mod;
		ans%=mod;
	}
	cout<<(ans+xd*k%mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 256
/******************************************
*    AUTHOR:         CHIRAG AGARWAL       *
*    INSTITUITION:   BITS PILANI, PILANI  *
******************************************/
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL; 
typedef long double LD;
const int MAX=2003;

string s[MAX];
int arr[MAX][MAX];
int cnt[MAX][MAX][3];
int pre[MAX][MAX][3];

int eval(int a,int b,int c,int d,int k)
{
	return (pre[a-1][b-1][k]+pre[c][d][k]-pre[c][b-1][k]-pre[a-1][d][k]);
}

int main() 
{
	int n,m,q;
	scanf("%d %d %d",&n,&m,&q);
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		for(int j=1;j<=m;j++)
		{
			if(s[i][j-1]=='0')
			{
				arr[i][j]=0;
			}
			else
			{
				arr[i][j]=1;
			}
		}
	}	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(arr[i][j]==1)
			{
				//printf("cma\n");
				cnt[i][j][0]++;
				if(arr[i-1][j]==1)
				{
					cnt[i][j][1]++;
				}
				if(arr[i][j-1]==1)
				{
					cnt[i][j][2]++;
				}
			}	
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			for(int k=0;k<3;k++)
			{
				cnt[i][j][k]+=cnt[i][j-1][k];
			}	
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			for(int k=0;k<3;k++)
			{
				pre[i][j][k]=pre[i-1][j][k]+cnt[i][j][k];
			}	
		}
	}
	for(int i=1;i<=q;i++)
	{
		int a,b,c,d;
		scanf("%d %d %d %d",&a,&b,&c,&d);
		int v1=eval(a,b,c,d,0);
		int v2=eval(a,b,c,d,1);
		printf("%d\n",v1-v2-eval(a,b,c,d,2)+eval(a,b,c,b,2)+eval(a,b,a,d,1));
	}
	return 0;
}

Measured memory_bytes: 115584
// ABC162D - RGB Triplets

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

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

	long long int R = 0, G = 0, B = 0;
	for (int i = 0; i < N; i++) {
		switch (S[i]) {
			case 'R':
				R++;
				break;
			case 'G':
				G++;
				break;
			case 'B':
				B++;
				break;
			default:
				break;
		}
	}

	long long int ans = R * G * B;

	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int k = 2 * j - i;
			if ((k < N)
			  &&(S[i] != S[j])
			  &&(S[i] != S[k])
			  &&(S[j] != S[k])) {
				ans--;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	cout << fixed << setprecision(20) << pow(n/3.0, 3) << endl;
}



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

int main(){
    long double n;
    cin>>n;
    vector<long double>a(n);
    
    for(int i=0;i<n;i++){
       cin>>a.at(i);
    }
    sort(a.begin(),a.end());
    for(int i=1;i<n;i++){
        a.at(i)=(a.at(i)+a.at(i-1))/2;
    }
    cout<<fixed<<setprecision(10)<<a.at(n-1)<<endl;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	static int h, w;
	static char[][] s;
	static int[][] gragh;
	static int[] dx = {1, -1, 0, 0};
	static int[] dy = {0, 0, 1, -1};
	static final int INF = Integer.MAX_VALUE;

	static class Pair {
		int x, y;
		Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		h = sc.nextInt();
		w = sc.nextInt();
		s = new char[h][w + 1];
		for(int i = 0 ; i < h ; i++) s[i] = sc.next().toCharArray();
		int black = 0;
		int white = 0;
		for(int i = 0 ; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				if(s[i][j] == '#') black++;
				else white++;
			}
		}
		int dist = bfs();

		int ans = white - (dist + 1);
//		for(int i = 0 ; i < h ; i++) {
//			for(int j = 0 ; j < w ; j++) {
//				System.out.print(s[i][j]);
//			}
//			System.out.println();
//		}
//		System.out.println();
//		for(int i = 0 ; i < h ; i++) {
//			for(int j = 0 ; j < w ; j++) {
//				if(s[i][j] == '.') {
//					s[i][j] = '#';
//					ans++;
//				}
//			}
//		}
		if(ans < 0) System.out.println(-1);
		else System.out.println(ans);
	}

	public static int bfs() {
		Queue<Pair> que = new LinkedList<>();
		gragh = new int[h][w];
		for(int i = 0 ; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				gragh[i][j] = INF;
			}
		}
		que.add(new Pair(0, 0));
		gragh[0][0] = 0;
		while(que.size() != 0) {
			Pair p = que.poll();
			if(p.x == h - 1 && p.y == w - 1) break;
			for(int i = 0 ; i < 4 ; i++) {
				int nx = p.x + dx[i];
				int ny = p.y + dy[i];
				if(0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != '#' && gragh[nx][ny] == INF) {
					que.add(new Pair(nx, ny));
					gragh[nx][ny] = gragh[p.x][p.y] + 1;
					s[nx][ny] = (char)('0' + gragh[p.x][p.y] + 1);
				}
			}
		}
		return gragh[h - 1][w - 1];
	}

}


Measured memory_bytes: 23764