akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    vector<ll> a(n);
    for (int i = 0 ; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    ll mx = a[0];
    for (int i = 0; i < n; i++) {
        ans += max(0LL, mx - a[i]);
        mx = max(mx, a[i]);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4832
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=998244353;
char s1[100],s2[100];
int main()
{
	scs(s1+1);
	getchar();scs(s2+1);
	int n=strlen(s1+1),m=strlen(s2+1);
	if(m!=n+1){
		pf("No\n");return 0;
	}int biaoji=0;
	rep(i,1,n)if(s1[i]!=s2[i])biaoji=1;
	if(biaoji==0)pf("Yes\n");
	else pf("No\n");
}


Measured memory_bytes: 3688
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(20);
    
    //入力を受け取る
    int n;cin >> n;
    vector<pair<int,int> > arr(n);
    for(int i = 0;i < n;i++){
        cin >> arr[i].second;
    }
    for(int i = 0;i < n;i++){
        cin >> arr[i].first;
    }
    //B側でソートする
    sort(arr.begin(),arr.end());
    //A_p1<=A_p2<=...<=A_pnとなるように順列Pを構成する
    vector<pair<int,int> > A(n);
    for(int i = 0;i < n;i++){
        A[i] = make_pair(arr[i].second,i);
    }
    sort(A.begin(),A.end());
    for(int i = 0;i < n;i++){
        if(A[i].first > arr[i].first){
            cout << "No" << '\n';
            return 0;
        }
    }
    vector<int> p(n);
    for(int i = 0;i < n;i++)p[i] = A[i].second;
    //順列pのサイクルを数える
    vector<int> used(n,0);
    int cycle = 0;
    for(int i = 0;i < n;i++){
        if(!used[i]){
            cycle++;
            int j = i;
            while(!used[j]){
                used[j] = 1;
                j = p[j];
            }
        }
    }
    if(cycle >= 2){
        cout << "Yes" << '\n';
        return 0;
    }
    //サイクルが1個だったとき、B_i>=P_i+1を満たすiがあるか？
    for(int i = 0;i < n-1;i++){
        if(arr[i].first >= arr[p[i+1]].second){
            cout << "Yes" << '\n';
            return 0;
        }
    }
    cout << "No" << '\n';
    return 0;
}


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

using lint = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, a, b;
	cin >> n >> a >> b;
	int mintrip = min(n*a, b);
	cout << mintrip << '\n';
}



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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

const ld eps = 1e-9, pi = acos(-1.0);

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

    ld a, b, c;
    cin >> a >> b >> c;
    ld S = 0.5 * a * b * sin(2 * pi * c / 360.0);
    cout << fixed << setprecision(10) << 0.5 * a * b * sin(2 * pi * c / 360.0) << endl;
    cout << fixed << setprecision(10) << a + b + sqrt(a * a + b * b - 2 * a * b * cos(2 * pi * c / 360.0)) << endl;
    cout << fixed << setprecision(10) << 2 * S / a << endl;
}



Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int a, b;
  cin >> a >> b;

  int sum = a * b; 

  if (sum % 2 == 0)
  {
    cout << "Even" << endl;
  }
  else
  {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 3632
#include<iostream>
int R,C,s[10000][10],f[10],N,i,j,n,m;void rec(int k){if(k<R){f[k]=0;rec(k+1);f[k]=1;rec(k+1);}else{for(n=i=0;i<C;i++,n+=m>R-m?m:R-m){for(m=j=0;j<R;j++)m+=s[i][j]^f[j];}N=N>n?N:n;}}main(){for(;std::cin>>R>>C,R|C;rec(0),printf("%d\n",N))for(j=R;j-->0;)for(i=C;i-->0;)std::cin>>s[i][j];}

Measured memory_bytes: 1256
#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(){
  string s;
  cin >> s;
  int cnt_g = 0;
  int cnt_p = 0;

  int cnt_win = 0;
  int cnt_lose = 0;
  for(int i = 0;i < s.size();i++){
    if(s[i] == 'p'){
      if(cnt_p + 1 <= cnt_g){
        cnt_p++;
      }
      else{
        cnt_lose++;
        cnt_g++;
      }
    }
    else if(s[i] == 'g'){
      if(cnt_p + 1 <= cnt_g){
        cnt_p++;
        cnt_win++;
      }
      else cnt_g++;
    }
  }

  cout << cnt_win - cnt_lose << endl;
}

Measured memory_bytes: 512
n = int(input())
mod = 10**9+7
if (n==1):
    print(0)
elif (n==2):
    print(2)
else:
    ans = 1
    no1 = 1
    no2 = 1
    for i in range(n):
        ans *= 10
        ans %= mod
        no1 *= 9
        no1 %= mod
        no2 *= 8
        no2 %= mod
    print((ans-2*no1+no2)%mod)

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 998244353;
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {
	int n;
	cin >> n;
	int k;
	cin >> k;
	vector<P> s(k);
	rep(i, k) cin >> s[i].first >> s[i].second;
	vector<int> dp(2*n+5);
	dp[1] = 1;
	dp[2] = -1;
	for (int i = 1; i <= n; i++) {
		dp[i] += dp[i - 1];
		dp[i] %= mod;
		rep(j, k) {
			dp[i + s[j].first] += dp[i];
			dp[i + s[j].second+1] -= dp[i];
			dp[i + s[j].first] %= mod;
			dp[i + s[j].second + 1] += mod;
			dp[i + s[j].second + 1] %= mod;
		}
	}


	cout << dp[n] << endl;
}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
#include <stdio.h>
# define M_PI  3.14159265358979323846
using namespace std;

typedef long long ll;
const int N = 1e2 + 9, M = 9e2 + 9, OO = 0x3f3f3f3f;
const double EPS = 0.00000000001;
const int mod = 1000000000+7;

int n, x, l[N], d, cnt = 1;

int main(){
	//freopen ("i.in","r",stdin);
	//freopen ("no.out","w",stdout);

	scanf("%d%d", &n, &x);
	for(int i = 0 ; i < n ; ++i) scanf("%d", l+i);
	for(int i = 0 ; i < n ; ++i){
		d = d + l[i];
		if(d <= x) ++cnt;
	}

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

	return 0;
}


Measured memory_bytes: 256
n, x, y = map(int, input().split())

res_dict = {}
for i in range(1, n+1):
    for j in range(i+1, n+1):
        tmp = min(j-i, abs(x-i)+abs(y-j)+1)
        if not tmp in res_dict.keys():
            res_dict[tmp] = 1
        else:
            res_dict[tmp] += 1

for i in range(1, n):
    if i in res_dict.keys():
        print(res_dict[i])
    else:
        print(0)


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

typedef vector<int> vi;
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
#define x first
#define y second
#define point pair<int,int>
#define len(s)   (int)s.length()
#define sz(v)    (int)v.size()
#define all(a)   a.begin(),a.end()
#define clr(x, val)	memset((x), (val), sizeof(x))

//you don't know math, unless you can do math!
int dp[100009];
vector<int> a;
int n;

int solve(int i){
    int &ret= dp[i];
    if(i == n - 1){
        return ret = 0;
    }

    if(i == n - 2){
        return ret = abs(a[i] - a[i+1]);
    }

    if(ret != -1)
        return ret;

    int c1 = solve(i+1) + abs(a[i] - a[i+1]);
    int c2 = solve(i+2) + abs(a[i] - a[i+2]);

    return ret = min(c1, c2);
}

int main() {
    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);

    cin>>n;
    a = vector<int> (n);

    loop(i, n) cin>>a[i];
    clr(dp, -1);

    cout<<solve(0);

}



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
using Graph = vector<vector<ll>>;
#define all(x) (x).begin(), (x).end() //string の sort とかはこれ
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

const ll MOD = 1000000007;
const ll INF = 1e18; //1*10^18
const double PI = 3.14159265;

int ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
//最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//最小公倍数

ll powll(ll a, ll n)
{ //O(log n)
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a;
    }
    a = a * a;
    n >>= 1; //(n & 1)=(n % 2 !=0)
  }
  return res;
}

ll modpow(ll a, ll n, ll mod) //O(log n)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1; //(n>>=1)=(n/2)
  }
  return res;
}

int ReturnDigit(ll num)
{
  string number = to_string(num);
  return number.length();
}

const ll MAX = 1e6;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() //MODは素数じゃないとだよ！！
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind
{
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N)
  { //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x)
  { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y)
  {                   // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry)
      return;     //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

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

int main()
{
  // COMinit();
  // srand((unsigned int)time(NULL));//--> rand()
  ll i, j, k, l, ans = 0;
  string s;
  cin >> s;

  if (s[1] == 'B')
  {
    cout << "ARC";
  }
  else
  {
    cout << "ABC";
  }

  // cout << ans << endl;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

int main() {
    string s;cin >> s;
    int n = s.size();
    ll ans = 0;
    int a_cnt = 0; // ブロック内の今まで出たAの数
    REP(i,n) {
        if (s[i] == 'A') a_cnt++;
        else if (i < n-1 && s[i] == 'B' && s[i+1] == 'C') {
            ans += a_cnt;
            i++;
        }
        else {
            a_cnt=0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  ll n,m;
  cin >> n >> m;
  ll h[n+5];
  rep(i,n) cin >> h[i+1];
  vector<vector<ll>> path;
  rep(i,n+5){
    vector<ll> tmp;
    tmp.push_back(0);
    path.push_back(tmp);
  }
  
  ll num1,num2;
  rep(i,m){
    cin >> num1 >> num2;
    path[num1].push_back(num2);
    path[num2].push_back(num1);
  }
  int res=0;
  rep(i,n){
    if(path[i+1].size()==1){
      res++;
      continue;
    }
    for(int j=1;j<path[i+1].size();j++){
      if(h[path[i+1][j]]>=h[i+1]) break;
      if(j==path[i+1].size()-1) res++;
    }
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 11736
#include<bits/stdc++.h>
using namespace std;
#define int long long int
 
signed main()
 {
     int n;
     cin>>n;
     int arr[n];
     for(int i=0;i<n;i++)
     {
         cin>>arr[i];
     }
     pair<int,int> dp[n][n];
     for(int i=0;i<n;i++)
     {
         dp[i][i].first=arr[i];
         dp[i][i].second=0;
     }
     for(int k=1;k<n;k++)
     {
         for(int i=0;i<n;i++)
         {
             int j=i+k;
             if(j>=n) break;
             int a1=dp[i][j-1].second+arr[j];
             int a2=dp[i+1][j].second+arr[i];
             dp[i][j].first=max(a1,a2);
             if(a1>a2)
             {
                 dp[i][j].second=dp[i][j-1].first;
             }
             else
             {
                 dp[i][j].second=dp[i+1][j].first;
             }
             
         }
     }
     cout<<dp[0][n-1].first-dp[0][n-1].second<<"\n";
 }

Measured memory_bytes: 140928
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int[] A;
        public void Run()
        {
            A = Input.ReadIntArray();

            bool flag = (A[0] != 2) && (A[1] != 2);
            Console.WriteLine(flag ? "Yes" : "No");
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

using namespace std;

int main() {
    int n, taroScore, hanakoScore;
    taroScore = hanakoScore = 0;
    cin >> n;

    string taroStr, hanakoStr;
    for (int i = 0; i < n; i++) {
        cin >> taroStr >> hanakoStr;

        if (taroStr > hanakoStr) {
            taroScore += 3;
        }
        else if (taroStr == hanakoStr) {
            taroScore += 1;
            hanakoScore += 1;
        }
        else if (taroStr < hanakoStr) {
            hanakoScore += 3;
        }
    }

    cout << taroScore << ' ' << hanakoScore << endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 40;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s; cin >> s;
  int n = s.size();
  int t = INF;
  rep(i, n-1) {
    if(s[i] != s[i+1]) chmin(t, max(i+1, n-i-1));
  }
  if(t != INF) cout << t << endl;
  else cout << n << endl;
}


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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N;
VL A, sum, rsum;

int main() {
    cin >> N;
    sum.resize(N + 2);
    rsum.resize(N + 2);
    A.emplace_back(0);
    REP(i, N) { A.emplace_back(IN()); }
    A.emplace_back(0);
    REP(i, N) {
        sum[i + 1] = sum[i] + abs(A[i] - A[i + 1]);
        rsum[N - i] = rsum[N - i + 1] + abs(A[N - i] - A[N - i + 1]);
    }
    FOR(i, 1, N + 1) {
        cout << sum[i - 1] + rsum[i + 1] + abs(A[i + 1] - A[i - 1]) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
constexpr int MAXN = 1e5 + 5;
constexpr long long M = 998244353;
constexpr double EPS = 1e-7;
using namespace std;
template <typename T> inline void read(T &x) {
    int f = 1; x = 0;
    char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}
struct segTree {
    using Node = segTree *;
    Node lson, rson;
    int l, r;
    long long mul;
}Tree[MAXN << 1];
int n;
int main() {
    //freopen("test.in", "r", stdin);
    vector<int> vec{999, 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};
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    //sort (vec.begin(), vec.end());
    cin >> n;
    cout << vec[n] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	
  string s,t;
  cin>>s>>t;
  char c=t[t.length()-1];
  if(s+c == t){
    cout<<"Yes\n";
  }
  else
    cout<<"No\n";
  
  return 0;

}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll gcd(ll a2,ll b2){
	ll t;
	while(b2!=0){
		t=a2%b2;
		a2=b2;
		b2=t;
	}
	return a2;
}


int main() {

	ll x,y;
	cin>>x>>y;

	if(y<0&&x>0)cout<<1+labs(x-labs(y))<<endl;
	else if(y>0&&x<0)cout<<1+labs(labs(x)-y)<<endl;
	else if(x<=y)cout<<labs(labs(y)-labs(x))<<endl;
	else if(x>y&&x!=0&&y!=0)cout<<2+labs(labs(y)-labs(x))<<endl;
	else cout<<1+labs(labs(y)-labs(x))<<endl;

	return 0;
}


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

int main() {
  int N, a, b, c, d;

  cin >> N;

  a = N / 1000;
  b = N % 1000 / 100;
  c = N % 100 / 10;
  d = N % 10;

  if ((a == b && b == c) || (b == c && c == d)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>

using namespace std;

int w, h, n;

bool adj(int a, int b) {
    if (0 <= a && a <= w - 2 &&
        0 <= b && b <= w - 2) {
        return a == b;
    }

    if (w <= a && a <= w + h - 3 &&
        w - 2 <= b && b <= w - 2 + h - 3) {
        return a - w == b - (w - 2);
    }

    if (w + h - 1 <= a &&
        w - 2 + h - 3 <= b) {
        return a - (w + h - 1) == b - (w - 2 + h - 3);
    }
    return false;
}

int main() {
    while (cin >> w >> h >> n) {
        int a = 0, b = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int p;
            cin >> p;
            if (p) b++; else a++;
            ans += adj(a, b);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3116
def move(dice, order):
  if order == "E":
    temp = dice[0]
    dice[0] = dice[3]
    dice[3] = dice[5]
    dice[5] = dice[2]
    dice[2] = temp
  elif order == "N":
    temp = dice[0]
    dice[0] = dice[1]
    dice[1] = dice[5]
    dice[5] = dice[4]
    dice[4] = temp
  elif order == "S":
    temp = dice[0]
    dice[0] = dice[4]
    dice[4] = dice[5]
    dice[5] = dice[1]
    dice[1] = temp
  elif order == "W":
    temp = dice[0]
    dice[0] = dice[2]
    dice[2] = dice[5]
    dice[5] = dice[3]
    dice[3] = temp
  else:
    pass
  return dice

def roll(dice):
  temp = dice[1]
  dice[1] = dice[2]
  dice[2] = dice[4]
  dice[4] = dice[3]
  dice[3] = temp
  return dice

def judge(dice1, dice2):
  flag = True
  for i in range(6):
    if dice1[i] != dice2[i]:
      flag = False
      break
  return flag

def aresame(dice1, dice2):
  mvdice = dice2
  cnt = 0
  
  while True:
    mvdice = move(mvdice, "E")
    cnt += 1
    if dice1[0] == mvdice[0]:
      rolldice = mvdice
      cntroll = 0
      while True:
        rolldice = roll(rolldice)
        cntroll += 1
        if judge(dice1, rolldice) == True:
          return True
        if cntroll == 4:
          break
    if cnt == 4:
      break

  mvdice = dice2
  cnt = 0
    
  while True:
    mvdice = move(mvdice, "N")
    cnt += 1
    if dice1[0] == mvdice[0]:
      rolldice = mvdice
      cntroll = 0
      while True:
        rolldice = roll(rolldice)
        cntroll += 1
        if judge(dice1, rolldice) == True:
          return True
        if cntroll == 4:
          break
    if cnt == 4:
      break

  return False


import sys

n = int(input())
saikoro = [[] for i in range(n)]
for i in range(n):
  saikoro[i] = list(map(int, input().split()))

for i in range(n):
  for j in range(i+1, n):
    if aresame(saikoro[i], saikoro[j]) == True:
      print("No")
      sys.exit()
      
print("Yes")




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

const ll M = 1000000007;
int n;
ll dp[2000010], s[2000010];

int main(){
	scanf("%d", &n);
	for(int i = 2 * n + 5; i >= 1; i--){
		if(i > n) dp[i] = 1;
		else if(i == n) dp[i] = n;
		else dp[i] = (1LL * (n - 1) * (n - 1) + dp[i + 1] + s[i + 3] - s[i + n + 2] + M) % M;
		s[i] = (s[i + 1] + dp[i]) % M;
	}
	printf("%lld\n", dp[1]);
}

Measured memory_bytes: 31488
IDENTIFICATION DIVISION.
PROGRAM-ID. 172B.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP     PIC X(200000).
*>
WORKING-STORAGE SECTION.
01 S       PIC X(200001).
01 T       PIC X(200001).
01 I          PIC 9(06) COMP.
01 CNT        PIC 9(06) COMP.
01 OUT        PIC ZZZZZ9.
*>
PROCEDURE DIVISION.
  OPEN INPUT STDIO.
  READ STDIO.     
  MOVE INP TO S.
  READ STDIO.     
  MOVE INP TO T.
  CLOSE STDIO.
*>
  MOVE ZERO TO CNT.
  PERFORM VARYING I FROM 1 BY 1 UNTIL S(I:1) = ' '
    IF (S(I:1) NOT = T(I:1)) 
      ADD 1 TO CNT
    END-IF
  END-PERFORM.  
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


Measured memory_bytes: 4396
def partition(n,a,p,r):
  x = a[r]
  i = p - 1
  
  for j in range(p,r):
    if x >= a[j]:
      i += 1
      a[i],a[j] = a[j],a[i]
      
  a[i+1],a[r] = a[r],a[i+1]
  
  for k in range(i+1):
    print(a[k],end=" ")
    
  print("[{}]".format(x),end=" ")
  
  for k in range(i+2,r):
    print(a[k],end=" ")
    
  print(a[r])

n = int(input())
a = list(map(int,input().split()))
partition(n,a,0,len(a)-1)

Measured memory_bytes: 18416
from sys import stdin
import numpy as np

N = int(stdin.readline().rstrip().split()[0])
A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]

def G(_a, _b):
  if _a>=_b:
    a, b = _a, _b
  else:
    a, b = _b, _a
  
  while True:
    c = a%b
    if c == 0:
      break
    a,b = b,c
  
  return b

L = np.array(list(set(A)))
mini = np.min(L)
yaku = [1]
i=2
r_mini = np.sqrt(mini)
while i<=r_mini:
  if mini%i==0:
    yaku.append(i)
  i+=1
yaku2 = list(map(lambda x: int(mini/x), yaku))
yaku = yaku[::-1]
yaku2.extend(yaku)
for y in yaku2:
  if np.sum(L%y)==0:
    ans = y
    break

print(ans)

Measured memory_bytes: 23384
<?php
  	fscanf(STDIN,"%d",$k);
  	fscanf(STDIN,"%d %d",$a,$b);

  	//$list = explode(" ",trim(fgets(STDIN)));
	
	for($i=$a;$i<=$b;$i++){
      if($i%$k==0){
        echo "OK\n";
        exit;
      }
    }
      
      echo "NG\n";

Measured memory_bytes: 16108
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)

void recursive_debug(string) { cerr << endl; }

template<class H,class... T>
void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}

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

template<class T>
ostream& operator<<(ostream &ost, const vector<T> &v) {
    ost << "[";
    for(T t : v) ost << t << ",";
    ost << "]";
    return ost;
}

struct State {
    ll score;
    vector<int> last;
    vector<int> types;
    bool operator<(const State& rhs) const {
        return (score < rhs.score);
    }
    bool operator>(const State& rhs) const {
        return (score > rhs.score);
    }
};


int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int D, M = 26;
    cin >> D;
    vector<ll> c(M);
    rep(m,M) cin >> c[m];
    vector<vector<ll>> s(D, vector<ll>(26));
    rep(d,D) rep(m,M) cin >> s[d][m];

    set<State> cur_states = {{0, vector<int>(M, -1), {}}};
    size_t SIZE = 830;

    rep(d,D) {
        set<State> nxt_states;
        for (auto &cur_itr : cur_states) {
            State state = cur_itr;
            rep(m,M) {
                State nxt_state;
                nxt_state.score = state.score + s[d][m];
                nxt_state.last = state.last;
                nxt_state.last[m] = d;
                nxt_state.types = state.types;
                nxt_state.types.push_back(m);

                rep(i,M) {
                    nxt_state.score -= c[i] * (d - nxt_state.last[i]);
                }
                nxt_states.insert(nxt_state);
                if (nxt_states.size() > SIZE) {
                    nxt_states.erase(nxt_states.begin());
                }
            }
        }

        cur_states = std::move(nxt_states);
    }

    for (int t : cur_states.begin()->types) {
        cout << t+1 << endl;
    }
    // debug(cur_states[0].score);

    return 0;
}


Measured memory_bytes: 6804
nom,dis = gets.split(" ").map!{|i| i.to_i}
yoko=Array.new(nom)
tate=Array.new(nom)

for i in 0..nom-1
  yoko[i],tate[i]= gets.split.map!{|i| i.to_i}
end
kazu=0
for j in 0..nom-1
  if dis**2>=(yoko[j]**2+tate[j]**2)
    kazu+=1
  end
end
puts kazu


Measured memory_bytes: 17508
import sys
input = sys.stdin.readline

weight = [0]*110
value = [0]*110
dp = [[0]*100010 for i in range(110)]

N, W = map(int, input().split())
for i in range(N):
  weight[i], value[i] = map(int, input().split())

# dp roop
for i in range(N):
  sum_w = 0
  while sum_w <= W:
    if sum_w >= weight[i]:
      dp[i+1][sum_w] = max(dp[i][sum_w - weight[i]] + value[i], dp[i][sum_w])
    else:
      dp[i+1][sum_w] = dp[i][sum_w]
    sum_w += 1
print(dp[N][W])    

Measured memory_bytes: 120856
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 15;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int K = 12;
const int KM = 1 << (K - 1);
ll dat[1 << K];

void update(int A) {
	dat[A] = min(dat[A * 2], dat[A * 2 + 1]);
	if (A != 1) update(A >> 1);
}

void add(int A, ll B) {
	int C = A + KM;
	dat[C] = B;
	update(C >> 1);
}

ll check(int L, int R, int A, int l, int r) {
	if (L <= l && r <= R) return dat[A];
	if (r <= L || R <= l) return 1ll << 60;
	return min(check(L, R, A * 2, l, (l + r) >> 1), check(L, R, A * 2 + 1, (l + r) >> 1, r));
}

ll query(int L, int R) {
	return check(L, R, 1, 0, KM);
}

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

	fread_unlocked(cn, 1, cm, stdin);
	int N = getint(), K = getint(), Q = getint();
	ll A[2002];
	int LR[2002];
	rep1(i, N) {
		A[i] = ((ll)getint() << 11) + i;
		dat[KM + i] = A[i];
	}
	for (int i = KM - 1; i > 0; i--) {
		dat[i] = min(dat[i * 2], dat[i * 2 + 1]);
	}
	rep(i, N + 2) LR[i] = -1;

	priority_queue<int> q;
	int kotae = 1e9;
	int saishou = 2e9;
	sort(A + 1, A + N + 1);
	const int m = (1 << 11) - 1;

	for (int i = N; i >= 1; i--) {
		int a = A[i] >> 11;
		int k = A[i] & m;

		int l = (LR[k - 1] == -1) ? k : LR[k - 1];
		int r = (LR[k + 1] == -1) ? k : LR[k + 1];
		LR[l] = r;
		LR[r] = l;

		int kosuu = min(K - 1, r - k) + min(K - 1, k - l) + 1;
		int abureta = max(0, kosuu - K + 1);

		rep(i, abureta) {
			ll tmp = query(l, r + 1);
			q.push(tmp >> 11);
			add(tmp & m, 1ll << 60);
		}

		while (q.size() >= Q) {
			int tmp = q.top();
			chmin(saishou, tmp);
			q.pop();
		}
		chmin(kotae, saishou - a);
	}

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string s,p;
  cin>>s>>p;
  if(s[0]==p[2] && s[1]==p[1] && s[2]==p[0]){
    cout<<"YES"<<"\n";
  }
  else{
    cout<<"NO"<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

typedef pair<int,int> pii;

vector<pii>sp;

int dx[12]={-1,0,1,2,2,2,1,0,-1,-2,-2,-2};
int dy[12]={-2,-2,-2,-1,0,1,2,2,2,1,0,-1};

int n;

bool dfs(int x,int y,int t){

	if(t>=0 && (abs(x-sp[t].first)>1 || abs(y-sp[t].second)>1))return false;
	if(t==n-1)return true;

	for(int i=0;i<12;i++){
		int nx=x+dx[i],ny=y+dy[i];
		if(nx<0 || ny<0 || 9<nx || 9<ny)continue;
		if(dfs(nx,ny,t+1))return true;
	}
	return false;
}

int main(void){

	int x,y;
	while(cin >> x >> y,x|y){
		cin >> n;
		sp.resize(n);
		for(int i=0;i<n;i++)cin >> sp[i].first >> sp[i].second;
		if(dfs(x,y,-1))cout << "OK" << endl;
		else cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
import java.util.Scanner;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();

        int sum = 0;

        for (int i = 0; i < A && i < K; i++) {
            sum++;
        }
        for (int i = (A + B); i < K; i++) {
            sum--;
        }
        System.out.println(sum);
        sc.close();
    }
}

Measured memory_bytes: 35732
import java.util.Scanner;

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

		int cnt = 0;
		for (int i = 0; i < 6; i++) {
			for (int j = 1; j <= N; j++) {
				if (j <= N && j < Math.pow(10,(2*i+1)) && j >= Math.pow(10,(2*i))) {
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 21844
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    ll a;
    const ll MOD=1e9+7;
    modint(ll a_=0){
        a=a_%MOD;
        if(a<0) a+=MOD;
    }
    modint inv()const{
        ll n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y;
        y.a=a+x.a;
        if(y.a>MOD) y.a-=MOD;
        return y;
    }
    modint operator-(const modint& x){
        modint y;
        y.a=a-x.a;
        if(y.a<0) y.a+=MOD;
        return y;
    }
    modint operator*(const modint& x){
        modint y(a*x.a);
        return y;
    }
    modint operator/(const modint& x){
        return *this * x.inv();
    }
    modint& operator+=(const modint& x){
        *this=*this+x;
        return *this;
    }
    modint& operator-=(const modint& x){
        *this=*this-x;
        return *this;
    }
    modint& operator*=(const modint& x){
        *this=*this*x;
        return *this;
    }
    modint& operator/=(const modint& x){
        *this=*this/x;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    ll a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(ll a,ll b){
    modint n(1),A(a);
    while(b){
        if(b&1) n*=A;
        A*=A;
        b>>=1;
    }
    return n;
}

class FSmallProducts {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,k,m;
        in>>n>>k;
        m=(int)sqrt(n);
        vector<modint> c(2*m),s(2*m+1),ns(2*m+1);
        fr(i,m) c[i]=1,c[i+m]=n/(m-i)-n/(m-i+1);
        if(n/m==m) c[m]-=1;
        s[0]=1;
        fr(_,k){
            ifr(i,2*m) ns[i]=ns[i+1]+(s[0]-s[2*m-i])*c[i];
            s.swap(ns);
        }
        out<<s[0]<<endl;
    }
};

int main() {
    FSmallProducts solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

using ll = long long;
ll modinv(ll a, ll m) {
	assert(m > 0);
	if (m == 1) return 0;
	a %= m;
	if (a < 0) a += m;
	assert(a != 0);
	if (a == 1) return 1;
	return m - modinv(m, a) * m / a;
}

template <int MOD_> struct modnum {
private:
	int v;
public:
	static const int MOD = MOD_;

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int () const { return v; }
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum operator ~ () const {
		modnum res;
		res.v = modinv(v, MOD);
		return res;
	}

	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= (~o);
	}

	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

using num = modnum<int(1e9)+7>;

num powmod(num a, ll n){
	if(n == 0) return num(1);
	if(n & 1) return a * powmod(a, n-1);
	return powmod(a*a, n/2);
}

const int MAXN = 1100000;

num fact[MAXN];
num ifact[MAXN];
num p3[MAXN];
num p2[MAXN];
num pn1[MAXN];

void init(){
	fact[0] = ifact[0] = p3[0] = p2[0] = pn1[0] = 1;
	for(int i = 1; i < MAXN; i++){
		fact[i] = fact[i-1] * i;
		ifact[i] = ifact[i-1] / i;
		p3[i] = p3[i-1] * 3;
		p2[i] = p2[i-1] * 2;
		pn1[i] = pn1[i-1] * (-1);
	}
}

int main(){
	init();
	ll n;
	cin >> n;
	num probsum = 0;
	num ans = 0;
	for(ll k = 0; k < n; k++){
		num prob = fact[n] * ifact[n-k] * ifact[k] * (p2[n-k] - pn1[n-k]) / p3[n];
		probsum += prob;
		num ev = num(1) / num(n-k) / num(n) / 3;
		ans += prob * ev;
	}
	assert(probsum == 1);
	cout << int(ans) << endl;
}

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

int main(int argc, const char * argv[]) {
    int N, D;
    cin >> N;
    cin >> D;

    float *v = new float [N * D];
    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++){
            cin >> v[i * D + j];
        }
    }
    
    int count = 0;
    for (int i = 0; i < N-1; i++) {
        for (int j = i + 1; j < N; j++) {
            float dist = 0.0f;
            for (int k = 0; k < D; k++){
                int id0 = i * D;
                int id1 = j * D;
                dist += pow(v[id0+k] - v[id1+k], 2.0);
            }
            dist = sqrt(dist);
            
            if (ceil(dist) == floor(dist)) {
                count++;
            }
        }
    }
    
    cout << count << endl;
    
    delete[] v;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

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

int main()
{
	llong x1 = read(),v1 = read(),x2 = read(),v2 = read(),t = read();
	if(v1<=v2) {puts("NO");}
	else if((v1-v2)*t>=abs(x1-x2)) {puts("YES");}
	else {puts("NO");}
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep(i,sz(s)) {
    if(s[i]-'0') ans++;
  }
  cout << ans << endl;
  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[] a = new int[]{sc.nextInt(), sc.nextInt(), sc.nextInt()};
        int count = 0;
        for (int i = a[0]; i <= a[1]; i++) {
            if (a[2] % i == 0) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 26164
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    long long w,h;
    cin>>w>>h;
    long long p[w],q[h];
    long long ans=0;
    
    for(int i=0;i<w;i++){
        cin>>p[i];
        ans+=p[i];
    }
    for(int i=0;i<h;i++){
        cin>>q[i];
        ans+=q[i];
    }

    sort(p,p+w);
    sort(q,q+h);

    

    for(int i=0;i<h;i++){
        long long cnt;
        cnt=p+w - upper_bound(p,p+w,q[i]);
        ans += cnt * q[i];
        
    }
    for(int i=0;i<w;i++){
        long long cnt;
        cnt=q+h - lower_bound(q,q+h,p[i]);
        ans += cnt * p[i];
    }

    cout<<ans<<endl;
    
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <functional> 
#include <vector>
#include <cstring>

using namespace std;

int main(){

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

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

    sort(a.begin(),a.end());
    a.push_back(200001);

    int mrk=0,i;
    vector<int> shu;
    for(i=1;i<n+1;i++){
        if(a[i-1] < a[i]){
            shu.push_back(i-mrk);
            mrk = i;
        }
    }
  
  	sort(shu.begin(),shu.end());
  	

    if(shu.size() <= k){
        cout << "0";
      	return 0;
    }

    int cnt=0;
    for(int l=0;l<shu.size()-k;l++){
        cnt += shu[l];
    }

    cout << cnt;

    return 0;
}

Measured memory_bytes: 2800
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/21/20 20:55:02
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  vector<int> A(n); for (auto& a:A) cin>>a;
  int X = accumulate(A.begin(), A.end(), 0, [](int a, int b) {return a^b;});
  for (auto a:A) {
    cout << (X^a) << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3984
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int fa[100010];
inline int findfa(int x)
{
	if(fa[x]!=x)fa[x]=findfa(fa[x]);
	return fa[x];
}
struct node
{
	int x,y;
}a[100010];
int len;
inline void ins(int x,int y){len++;a[len].x=x,a[len].y=y;}
int main()
{
    //freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	long long m;
	int n=read();scanf("%lld",&m);int q=read();bool bk=true;
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=q;i++)
	{
		int x=read()+1,y=read()+1,id=read();
		if(!id)
		{
			int fx=findfa(x),fy=findfa(y);
			if(fx!=fy)fa[fx]=fy;
		}
		else ins(x,y),bk=false;
	}
	bool pd=true;
	for(int i=1;i<=len;i++)
	{
		int fx=findfa(a[i].x),fy=findfa(a[i].y);
		if(fx==fy){pd=false;break;}
	}
	int cnt=0;
	for(int i=1;i<=n;i++)if(findfa(i)==i)cnt++;
	long long uf=1LL*cnt*(cnt-1)/2-cnt+n;
	if((m<n && bk==false) || m>uf)pd=false;
	if(pd==false)puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%i",&n);
    int rem,div,t;
    
    t = n % 10;
    if (t==2 || t==4 || t==5 || t==7 || t==9)
    {
    	printf("hon\n");
    }
    else if (t==3)
    {
    	printf("bon\n");
    }
    else
    {
    	printf("pon\n");
    }
    return 0;
}

Measured memory_bytes: 3764