akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
template<typename T> class segtree {
private:
	int n, sz, h;
	vector<T> node, lazy;
	void eval(int k) {
		if (lazy[k]) {
			node[k] += lazy[k];
			if (k < n) {
				lazy[k * 2] += lazy[k], lazy[k * 2 + 1] += lazy[k];
			}
			lazy[k] = 0;
		}
	}

public:
	segtree(int _sz) {
		sz = _sz;
		h = 0;
		n = 1;
		while (n < sz) n *= 2, h++;
		node.resize(2 * n, numeric_limits<T>::max());
		lazy.resize(2 * n, 0);
		for (int i = 0; i < sz; i++) node[i + n] = 0;
		for (int i = n - 1; i >= 1; i--) node[i] = min(node[2 * i], node[2 * i + 1]);
	}
	void range(int a, int b, T x) {
		a += n, b += n - 1;
		for (int i = h; i > 0; i--) eval(a >> i), eval(b >> i);
		int ta = a, tb = b++;
		while (a < b) {
			if (a & 1) lazy[a++] += x;
			if (b & 1) lazy[--b] += x;
			a >>= 1, b >>= 1;
		}
		while (ta >>= 1, tb >>= 1, ta) {
			if (!lazy[ta]) {
				eval(2 * ta), eval(2 * ta + 1), node[ta] = min(node[2 * ta], node[2 * ta + 1]);
			}
			if (!lazy[tb]) {
				eval(2 * tb), eval(2 * tb + 1), node[tb] = min(node[2 * tb], node[2 * tb + 1]);
			}
		}
	}
	T query(int a, int b) {
		a += n, b += n - 1;
		for (int i = h; i > 0; i--) eval(a >> i), eval(b >> i);
		b++;
		T res1 = numeric_limits<T>::max(), res2 = numeric_limits<T>::max();
		while (a < b) {
			if (a & 1) eval(a), res1 = min(res1, node[a++]);
			if (b & 1) eval(--b), res2 = min(res2, node[b]);
			a >>= 1, b >>= 1;
		}
		return min(res1, res2);
	}
	void print() { for (int i = 0; i < sz; i++) cout << query(i, i + 1) << " "; cout << endl; }
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<vector<pair<int, int> > > L(N + 1);
	int res = 0;
	int l, r, a;
	for (int i = 0; i < M; i++) {
		cin >> l >> r >> a;
		L[r].emplace_back(l, a);
		res += a;
	}
	for (int i = 1; i <= N; i++) {
		sort(L[i].rbegin(), L[i].rend());
	}
	vector<int> dp(N + 2, 0);
	segtree<int> sg(N + 5);
	for (int i = 1; i <= N + 1; i++) {
		//dp[i] = min(dp[i], dp[i - 1]);
		for (auto &j : L[i - 1]) {
			l = j.first;
			a = j.second;
			sg.range(0, l + 1, a);
		}

		dp[i] = sg.query(0, i + 1);
		sg.range(i + 1, i + 2, dp[i]);
		//cerr << dp[i] << " ";
	}
	//cerr << endl;

	cout << res - dp.back() << endl;
}

Measured memory_bytes: 20992
num = [int(x) for x in input().split()]
ans = 0

while((num[0] == num[1] and num[1] == num[2]) == 0):
    ans += 1
    num.sort()
    if num[1] == num[2]:
        num[0] += 2
    else :
        num[0] += 1
        num[1] += 1
    
print(ans)

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

using namespace std;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int l, n;
  scanf("%d %d", &l, &n);
  vector<int> x(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x[i]);
  }
  long long answer = 0;
  for (int rotate = 0; rotate < 2; ++rotate) {
    vector<int> p = x;
    p.push_back(l);
    for (int i = 0; i < n; ++i) {
      p.push_back(l + x[i]);
    }
    vector<long long> sum(n * 2 + 1);
    for (int i = 0; i < n * 2; ++i) {
      sum[i + 1] = sum[i] + 2ll * i * (p[i + 1] - p[i]);
    }
    for (int i = 0; i <= n; ++i) {
      int left = n - i, right = i;
      int left_l = i, left_r = n;
      int right_l = n, right_r = n + i;
      long long result = 0;
      if (left > right) {
        int diff = left - right;
        result += (long long) (p[left_r] - p[left_r - diff]) * (2 * right + 1);
        left_r -= diff;
      }
      if (left < right) {
        int diff = right - left;
        result += (long long) (p[right_l + diff] - p[right_l]) * (2 * left);
        right_l += diff;
      }
      result += (sum[left_r] - sum[left_l]) - (long long) (p[left_r] - p[left_l]) * (2 * left_l - 1);
      result += (long long) (p[right_r] - p[right_l]) * (2 * right_r) - (sum[right_r] - sum[right_l]);
      answer = max(answer, result);
    }
    for (int i = 0; i < n; ++i) {
      x[i] = l - x[i];
    }
    reverse(x.begin(), x.end());
  }
  printf("%lld\n", answer);
  return 0;
}


Measured memory_bytes: 9584
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	string s;
	int t=0;
	cin>>n>>s;
	for(int i=1;i<s.size()-1;i++)
	{
		if(s[i]=='B' && s[i-1]=='A' && s[i+1]=='C')
		t++;
	}
	cout<<t;
	return 0;
 } 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

struct Data{
    int w, s, v;
    Data() = default;
    Data(int w, int s, int v) : w(w), s(s), v(v) {}
    bool operator<(const Data& d) const{
        return w + s < d.w + d.s;
    }
    friend ostream& operator<<(ostream& os, const Data& d){
        return os << d.w << ' ' << d.s << ' ' << d.v << '\n';
    }
    friend istream& operator>>(istream& is, Data& d){
        int x, y, z;
        cin >> x >> y >> z;
        d = Data(x, y, z);
        return is;
    }
};

vector<vector<ll>> dp(1005, vector<ll>(21005, -1));

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

    int n;
    cin >> n;
    vector<Data> input(n);
    for(int i = 0; i < n; ++i)  cin >> input[i];
    sort(input.begin(), input.end());

    dp[0][0] = 0;
    for(int i = 0; i < n; ++i){
        int w = input[i].w, s = input[i].s, v = input[i].v;
        for(int j = 0; j <= 20000; ++j){
            if(dp[i][j] != -1)  chmax(dp[i + 1][j], dp[i][j]);
            if(j - w < 0 || j - w > s)  continue;
            if(dp[i][j - w] != -1)  chmax(dp[i + 1][j], dp[i][j - w] + v);
        }
    }

    ll ans = 0;
    for(int i = 0; i <= 20000; ++i) chmax(ans, dp[n][i]);
    cout << ans << endl;
}

Measured memory_bytes: 169216
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

from collections import deque
from typing import Deque

A.sort()

DL = Deque(A)
DS = Deque(A)

LL = [0 for _ in range(N)]
LS = [0 for _ in range(N)]


if N % 2 == 0:

    for i in range(1, N, 2):
        LS[i] = DS.popleft()
        LL[i] = DL.pop()
    for j in range(0, N, 2):
        LS[j] = DS.popleft()
        LL[j] = DL.pop()

else:
    for i in range(1, N):
        if i % 2 == 1:
            LS[i] = DS.pop()
            LL[i] = DL.popleft()
        else:
            LS[i] = DS.popleft()
            LL[i] = DL.pop()

    LS[0] = DS.pop()
    LL[0] = DL.pop()

ansS = 0
ansL = 0
for i in range(1, N, 2):
    if i == N - 1:
        ansS += abs(LS[i] - LS[i-1])
        ansL += abs(LL[i] - LL[i-1])
    else:
        ansS += abs(LS[i] - LS[i-1])
        ansS += abs(LS[i] - LS[i+1])

        ansL += abs(LL[i] - LL[i-1])
        ansL += abs(LL[i] - LL[i+1])

print(max(ansS, ansL))


Measured memory_bytes: 17868
local mab, mma = math.abs, math.max
local ior = io.input()
local n = ior:read("*n")
local x, y, h = {}, {}, {}
local ref = 1
for i = 1, n do
  x[i], y[i], h[i] = io.read("*n", "*n", "*n")
  if 0 < h[i] then ref = i end
end
local found = false
for cx = 0, 100 do
  for cy = 0, 100 do
    local ch = h[ref] + mab(cx - x[ref]) + mab(cy - y[ref])
    local valid = true
    for i = 1, n do
      if h[i] ~= mma(0, ch - mab(cx - x[i]) - mab(cy - y[i])) then
        valid = false
        break
      end
    end
    if valid then
      found = true
      print(cx .. " " .. cy .." " .. ch)
      break
    end
  end
  if found then break end
end


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

int n,C;
int a[101],b[101],c[101];
int dp[2][105][10005];

int main(void){
	scanf("%d%d",&n,&C);
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
	}
	int now=1,prev=0;
	memset(dp,-1,sizeof(dp));
	dp[0][0][0]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=C;j++){
			for(int k=0;k<=i*100;k++){
				if(dp[prev][j][k]==-1)continue;
				dp[now][j][k]=max(dp[now][j][k],dp[prev][j][k]);
				if(j+c[i]<=C){
					int va=k+a[i];
					int vb=dp[prev][j][k]+b[i];
					dp[now][j+c[i]][min(va,vb)]=max(dp[now][j+c[i]][min(va,vb)],max(va,vb));
					va=k+b[i];
					vb=dp[prev][j][k]+a[i];
					dp[now][j+c[i]][min(va,vb)]=max(dp[now][j+c[i]][min(va,vb)],max(va,vb));
				}
			}
		}
		swap(now,prev);
		memset(dp[now],-1,sizeof(dp[now]));
	}
	int res=0;
	for(int i=0;i<=C;i++){
		for(int j=0;j<=10000;j++){
			res=max(res,min(j,dp[prev][i][j]));
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 11428
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

// auto mod int
const int mod = 1000000007;
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*(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(){
  int n,m;
  cin>>n>>m;
  if(llabs(n-m)>1){
    cout<<0<<endl;
    return(0);
  }
  vector<mint>fact(max(n,m)+1);
  fact[0]=1;
  rep2(i,1,max(n,m)+1){
    fact[i]=fact[i-1]*i;
  }
  mint ans=fact[n]*fact[m];
  if(abs(n-m)==0)ans*=2;
  cout<<ans.x<<endl;
  return(0);
}

Measured memory_bytes: 1024
module Main where
import Data.List

int = read::String -> Int
main = interact $ printer . solver . parser

printer = unlines . (:[]) . show
parser = map int . words

solver :: [Int] -> Int
solver [q,h,s,d,n] = result
  where
    q4 = q * 4
    h2 = h * 2
    sbest = minimum [q4, h2, s]
    result = 
      if sbest * 2 < d 
      then n * sbest 
      else d * (n `div` 2) + sbest * (n `mod` 2)



Measured memory_bytes: 508
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N, T;
    cin >> N >> T;
    vector<int> t(N);
    REP (i, N) cin >> t[i];
    t.push_back(1LL << 31);
    int ans = 0;
    REP (i, N) ans += min(T, t[i + 1] - t[i]);
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 4608
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<time.h>
#define ll long long
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define miin(a,b,c) min((a), min((b), (c)))
#define maax(a,b,c) max((a), max((b), (c)))

int main(){
    int n;
    scanf("%d", &n);
    while(n--){
        int a;
        scanf("%d", &a);
        if(a%2 == 0){
            if((a%3) * (a%5)){
                puts("DENIED");
                return 0;
            }
        }
    }
    puts("APPROVED");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,W;
  cin >> N >> W;
  vector<string> pic(N);
  for(int i = 0; i<N; i++){
    cin >> pic.at(i);
  }
  
  for(int i = -1; i<N+1; i++){
    cout << "#";
    if(i == -1 || i == N) for(int i2 = 0; i2<W; i2++) cout << "#";
    else cout << pic.at(i);
    cout << "#" << endl;
  }
}

Measured memory_bytes: 256
n,a,b = map(int,input().split())

mod = 10**9+7

def comb(n,r):
	u = 1
	d = 1
	for i in range(n-r+1,n+1):
		u = u*i%mod

	for i in range(1,r+1):
		d = d*i%mod
	D = pow(d,mod-2,mod)

	return u*D%mod

ans = pow(2,n,mod)-1-comb(n,a)-comb(n,b)

print(ans%mod)

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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
int main() {
    string s;
    cin >> s;


    //111
    //114 -> 222
    //252 -> 333
    //321 -> 333

    if(s[0]>=s[1]&&s[0]>=s[2]){
        s[1]=s[0];
        s[2]=s[0];
    }else{
        s[0]+=1;
        s[1]=s[0];
        s[2]=s[0];
    }

    PRINT(s);

}



Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<cmath>
#include<ctime>
#include<locale>
//freopen("std.in","r",stdin);freopen("stdout.out","w",stdout);
using namespace std;
int main()
{
    long n,k;
    cin>>n>>k;
    long a=0,b=0,x;
    scanf("%ld",&x);
    a=x;
    b=x;
    for(long i=1;i<n;i++)
    {
        scanf("%ld",&x);
        a=__gcd(a,x);
        b=max(x,b);
    }
    if(k%a==0&&k<=b)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


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

using namespace std;
int mini(int a,int b){
if(a<b)return a;
return b;
}
int minCostdown(int*h,int n,int k){
    int* dp = new int[n];
    dp[0] = 0;
    for(int i = 1;i<n;i++)
        dp[i] = INT_MAX;
    for(int i = 1;i<n;i++){
        for(int j = 1;j<=k;j++){
            if(i-j<0)
                break;
            dp[i] = mini(dp[i],dp[i-j] + abs(h[i]-h[i-j]));
        }
    }
    return dp[n-1];
}
int main()
{
    int n;
    cin>>n;
    int* h = new int[n];
    for(int i = 0;i<n;i++)
        cin>>h[i];
    //cout<<minCost(h,0,n)<<endl;
    cout<<minCostdown(h,n,2)<<endl;
    return 0;
}


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

int main(){
	int n,m;
	int A[101][101],b[101],V[101];
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>A[i][j];
		}
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			V[i]+=A[i][j]*b[j];
		}
	}
	for(int i=0;i<n;i++){
		cout <<V[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int a,b;cin>>a>>b;
    for(int i=1;i<=10000;i++){
        int A = (int)(i*8/100);
        int B = (int)(i/10);
        if(A == a && B == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n;
long long x = 0;
int main()
{
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >>n;
  for (int i = 1; i <= n; ++i)
  {
    for (int j = 1; j <= n; ++j)
    {
      int g = __gcd(i, j);
      for (int k = 1; k <= n; ++k)
      {
        x += __gcd(g, k);
      }
    }
  }
  cout <<x << '\n';
}


Measured memory_bytes: 3640
#include<iostream>
#include<stdio.h>
#include<vector>
#include<ctype.h>
#include<string>
#include<cmath>
using namespace std;

class Dice{
    private:
    int face[7];
    
    public:
    void SetFace(){
        for(int i=1;i<sizeof(face)/sizeof(int);++i){
            cin>>face[i];
        }
    }
    void Up(){
        int buf=face[1];
        face[1]=face[2];
        face[2]=face[6];
        face[6]=face[5];
        face[5]=buf;
    }
    void Down(){
        int buf=face[1];
        face[1]=face[5];
        face[5]=face[6];
        face[6]=face[2];
        face[2]=buf;
    }
    void Right(){
        int buf=face[1];
        face[1]=face[4];
        face[4]=face[6];
        face[6]=face[3];
        face[3]=buf;
    }
    void Left(){
        int buf=face[1];
        face[1]=face[3];
        face[3]=face[6];
        face[6]=face[4];
        face[4]=buf;
    }
    void Rolling(char d){
        if(d=='N'){
            Up();
        }
        else if(d=='S'){
            Down();
        }
        else if(d=='E'){
            Right();
        }
        else if(d=='W'){
            Left();
        }
    }
    void OutPutCurrentFaceNum(){
        cout<<face[1]<<endl;
    }
};
Dice dice;

int main(){
    dice.SetFace();
    string operator0;
    cin>>operator0;
    for(int i=0;i<operator0.size();++i){
        dice.Rolling(operator0[i]);
    }
    dice.OutPutCurrentFaceNum();
    
    return 0;
}



Measured memory_bytes: 3180
#include<stdio.h>
int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(a<c)
    a=c;
  if(b>d)
    b=d;
  printf("%d\n",b-a>0?b-a:0);
  return 0;
}


Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;

int main(){
long long n,k;
long long sum=0;
cin>>n>>k;
while(k<=n+1){
    sum+=(2*n-k+1)*k/2-k*(k-1)/2+1;
    k++;
}
sum%=mod;
cout<<sum<<endl;
return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 15;
const ll INF = 1e15;
const ll MOD = 1e9+7;
ll N,M,W,a,b,c,d,e;
ll A[MAXN][MAXN];
ll B[MAXN];
vi V;
ll ans=INF;

int main(){
    cin>>N>>M>>W;
    for(int i=0;i<N;++i){
        cin>>B[i];
        for(int j=0;j<M;++j)cin>>A[i][j];
    }
    for(int bm=0;bm<(1<<N);++bm){
        int ok=1;
        for(int i=0;i<M;++i){
            ll c=0;
            for(int x=0;x<N;++x)if((1<<x)&bm)c+=A[x][i];
            if(c<W)ok=0;
        }
        if(ok){
            ll w=0;
            for(int i=0;i<N;++i)if((1<<i)&bm)w+=B[i];
            ans=min(ans,w);
        }
    }
    if(ans<INF)cout<<ans;
    else cout<<-1;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll A[20][200005];
ll B[20][200005];
ll N;
int main(){
  cin>>N;
  for(ll j=1;j<=N;j++){
  ll a;cin>>a;
    for(ll i=0;i<20;i++){
    A[i][j]=a%2;a/=2;
    }
  }for(ll i=0;i<20;i++)
    for(ll j=1;j<=N;j++)
      A[i][j]+=A[i][j-1];
  for(ll i=0;i<20;i++){
  ll a=0;
    for(ll j=1;j<=N;j++){
      while(2<=A[i][j]-A[i][a])a++;
      B[i][j]=a;
    }
  }ll ans=0;
  for(ll j=1;j<=N;j++){
  ll M=0;
    for(ll i=0;i<20;i++)
      if(M<B[i][j])M=B[i][j];
    ans+=(j-M);
  }cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 66080
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt();
            var N = line[0];
            var K = line[1];
            var s = consoleReader.String().ToCharArray();
            s[K - 1] += (char)32;
            return new string(s);
        }

        public const int mod = 1000000007;
        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

    #region Console
    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int() => int.Parse(String()); public long Long() => long.Parse(String()); public ulong ULong() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt() => String().Split().Select(int.Parse).ToArray(); public long[] SplitLong() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitULong() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt(int count) { for (int i = 0; i < count; i++) yield return Int(); } public IEnumerable<long> RepeatLong(int count) { for (int i = 0; i < count; i++) yield return Long(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt(int count) { for (int i = 0; i < count; i++) yield return SplitInt(); } }
    #endregion
}

Measured memory_bytes: 11348
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  int *x, *y;
  int n, i;
  double D[4];

  for (i = 0; i < 4; i++) D[i] = 0.0;

  scanf("%d", &n);

  x = (int *)malloc(sizeof(int) * n);
  y = (int *)malloc(sizeof(int) * n);

  for (i = 0; i < n; i++) scanf("%d", &x[i]);
  for (i = 0; i < n; i++) scanf("%d", &y[i]);

  for (i = 0; i < n; i++) {
    D[0] += abs(x[i] - y[i]);
    D[1] += (x[i] - y[i]) * (x[i] - y[i]);
    D[2] += abs((x[i]-y[i]) * (x[i]-y[i]) * (x[i]-y[i]));
    if (D[3] < abs(x[i] - y[i])) D[3] = abs(x[i] - y[i]);
  }
  D[1] = sqrt(D[1]);
  D[2] = cbrt(D[2]);

  for (i = 0; i < 4; i++) {
    printf("%f\n", D[i]);
  }

  free(x);
  free(y);

  return 0;
}

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


int main() {

//変数の宣言

	string str;
	int i;

	cin >> str;

	for(i=0;i<str.size();i++){
		cout << str[str.size()-i-1];
	}
	
	cout <<endl;	
	
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
int N, M;
int ans = 0;


void solver(int from, int to, vector<bool> S, vector<bool> T, vector< vector<bool> > gr);

int main(){
  cin >> N >> M;
  int a,b;
  vector< vector<bool> > gr(9, vector<bool>(9, false));
  for(int i = 0; i< M; i++){
    cin >> a >>  b;
    gr.at(a).at(b) = true;
    gr.at(b).at(a) = true;
  }
  vector<bool> S(9, false);
  vector<bool> T(9, true);
  solver(0, 1, S, T, gr);

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

void solver(int from, int to, vector<bool> S, vector<bool> T, vector< vector<bool> > gr){
  // printf("%d %d\n", from, to);

  S.at(to) = true;
  T.at(to) = false;

  gr.at(from).at(to) = false;
  gr.at(to).at(from) = false;
  for(int i=1;i<N+1; i++){
    if(T.at(i) == true){
      break;
    }else{
      if(i == N){
        ans++;
      }
    }
  }
  for(int i = 1; i< N+1; i++){
    if(gr.at(to).at(i)){
      if(S.at(i) == false){
        solver(to, i, S, T, gr);
      }
      //もし通れるなら行ってみる
    }
  }
}


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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a, b;
    int ans = 0;
    cin >> a >> b;
    if (a == 1)
        ans += 3e5;
    else if (a == 2)
        ans += 2e5;
    else if (a == 3)
        ans += 1e5;
    if (b == 1)
        ans += 3e5;
    else if (b == 2)
        ans += 2e5;
    else if (b == 3)
        ans += 1e5;
    if (a == 1 && b == 1)
        ans += 4e5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
<?php
$s = fgets(STDIN);
$n = strlen($s);
$i = 0;
$j = $n-1;

for(; $i < $n; $i++){
    if($s[$i] == 'A')break;
}
for(; $j >= 0; $j--){
    if($s[$j] == 'Z')break;
}
print $j - $i + 1;

?>

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int k,n; cin>>k>>n;
    int arr[n],ans=0;
    for(int i=0;i<n;i++) cin>>arr[i];
    for(int i=1;i<n;i++) ans=max(ans,arr[i]-arr[i-1]);
    ans=max(ans,arr[0]+k-arr[n-1]);
    cout<<k-ans<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int main(void) {
    string S;
    cin>>S;
    if(S=="AAA"){
      cout<<"No"<<endl;
    }
    else if(S=="BBB"){
      cout<<"No"<<endl;
    }
    else{
      cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC
{
    class ProgramD
    {
        static void Main(string[] args)
        {
            var mod = (long)1e9 + 7;
            var n = long.Parse(Console.ReadLine());
            var list = Console.ReadLine().Split(" ").Select(x => long.Parse(x)).ToList();

            var result = 0L;
            var twoFactor = 1L;
            for (var i = 0; i < 60; i++)
            {
                long even = 0, odd = 0;
                for (var j = 0; j < n; j++)
                {
                    if (((list[j] >> i) & 1) == 1)
                        odd++;
                    else
                        even++;
                }
                var add = (odd * even) % mod * twoFactor % mod;
                result = (result + add) % mod;
                twoFactor = (twoFactor * 2) % mod;
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 67764
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

long long a, b, c;
string s, t;

long long kouyakusuu(long long x, long long y)
{
	if (max(x, y) % min(x, y) == 0)
		return min(x, y);
	else
		return kouyakusuu(min(x, y), max(x, y) % min(x, y));
}

int main()
{
	cin >> a >> b;
	long long e = a * b;
	printf("%lld", e / kouyakusuu(a, b));
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/*
 */

public class ALDS1_9_C
{
    public static void Main(string[] args)
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int[] values = new int[2000000];
        int index = 0;

        var sb = new StringBuilder();
        while (true)
        {
            string[] strs = Console.ReadLine().Split(' ');
            if (strs[0] == "insert")
            {
                Insert(values, index, int.Parse(strs[1]));
                index++;
            }
            else if (strs[0] == "extract")
            {
                if (index == 0)
                {
                    return;
                }
                index--;
                HeapExtractMax(values, index, sb);
            }
            else if (strs[0] == "end")
            {
                break;
            }
        }
        Console.Write(sb.ToString());
    }

    private static void Insert(int[] values, int i, int value)
    {
        values[i] = value;
        while (i > 0 && values[(i + 1) / 2 - 1] < values[i])
        {
            var tmp = values[i];
            values[i] = values[(i + 1) / 2 - 1];
            values[(i + 1) / 2 - 1] = tmp;
            i = (i + 1) / 2 - 1;
        }
    }

    private static void HeapExtractMax(int[] values, int index, StringBuilder sb)
    {
        sb.Append(values[0].ToString());
        sb.AppendLine();
        values[0] = values[index];
        MaxHeapify(values, 0, index);
    }

    private static void MaxHeapify(int[] values, int i, int n)
    {
        int leftId = (i + 1) * 2 - 1;
        int rightId = leftId + 1;
        int largest = i;
        if (leftId < n && values[leftId] > values[i])
        {
            largest = leftId;
        }
        if (rightId < n && values[rightId] > values[largest])
        {
            largest = rightId;
        }
        if (largest != i)
        {
            int tmp = values[i];
            values[i] = values[largest];
            values[largest] = tmp;
            MaxHeapify(values, largest, n);
        }
    }
}



Measured memory_bytes: 35228
#include <bits/stdc++.h>
using ll = long long;

int main() {
    using namespace std;
    int n, k;
    cin >> n >> k;
    int H[n];
    for (int i = 0; i < n; i++) cin >> H[i];
    sort(H, H + n);
    ll ans = 0LL;
    for (int i = 0; i < n - k; i++) ans += H[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
//
// Created on 2020/06/21.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    ll n;
    cin>>n;
    vector<int>kisu;
    while(!(n <= 26)){
        int a = n % 26;
        kisu.push_back(a);
        n /= 26;
        if(a == 0) n --;
    }
    if(n != 0) kisu.push_back(n);
    for (int i = kisu.size() - 1; i >= 0; --i) {
        char o = kisu[i] + 'a' - 1;
        if(kisu[i] == 0){
            o = 'z';
        }
        cout<<o;
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

struct ANS{
	int pay_10,pay_50,pay_100,pay_500,toal;
};

int main(){

	int price,num_10,num_50,num_100,num_500,tmp,pay_sum;
	int ret_10,ret_50,ret_100,ret_500;
	ANS ans;
	bool First = true;

	while(true){
		scanf("%d",&price);
		if(price == 0)break;

		ans.toal = 10000000;

		scanf("%d %d %d %d",&num_10,&num_50,&num_100,&num_500);

		for(int a = 0; a <= num_10; a++){
			for(int b = 0; b <= num_50; b++){
				for(int c = 0; c <= num_100; c++){
					for(int d = 0; d <= num_500; d++){
						if((pay_sum = 10*a+50*b+100*c+500*d) >= price){

							ret_10 = ret_50 = ret_100 = ret_500 = 0;

							pay_sum -= price;
							if(pay_sum >= 500){
								ret_500 = pay_sum/500;
								pay_sum %= 500;
							}
							if(pay_sum >= 100){
								ret_100 = pay_sum/100;
								pay_sum %= 100;
							}
							if(pay_sum >= 50){
								ret_50 = pay_sum/50;
								pay_sum %= 50;
							}
							if(pay_sum >= 10){
								ret_10 = pay_sum/10;
								pay_sum %= 10;
							}

							if((a > 0 && ret_10 > 0)||(b > 0 && ret_50 > 0)||(c > 0 && ret_100 > 0)||(d > 0 && ret_500 > 0)){
								//Do nothing
							}else{
								tmp = num_10 + num_50 + num_100 + num_500 - (a+b+c+d-(ret_10+ret_50+ret_100+ret_500));
								if(tmp < ans.toal){
									ans.toal = tmp;
									ans.pay_10 = a;
									ans.pay_50 = b;
									ans.pay_100 = c;
									ans.pay_500 = d;
								}
							}
						}
					}
				}
			}
		}

		if(!First)printf("\n");

		if(ans.pay_10 > 0)printf("10 %d\n",ans.pay_10);
		if(ans.pay_50 > 0)printf("50 %d\n",ans.pay_50);
		if(ans.pay_100 > 0)printf("100 %d\n",ans.pay_100);
		if(ans.pay_500 > 0)printf("500 %d\n",ans.pay_500);

		First = false;
	}
	return 0;
}

Measured memory_bytes: 2568
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)

int main(){

    fast;
    int T;
    T=1;
    //cin>>T;
    while(T--){
    	int n,i,j;
    	cin>>n;
    	int a[n];
    	multiset<int>m;
    	for(i=0;i<n;i++)
    	{
    		cin>>a[i];
    		m.insert(a[i]);
		}
		int cnt=0;
		for(j=0;j<n;j++)
		{
			int x=a[j];
			m.erase(m.find(x));
			int f=1;
			for(i=1;i*i<=x;i++)
			{
				if(x%i==0)
				{
					if(m.find(i)!=m.end())
					{
						f=0;
						break;
					}
					if(m.find(x/i)!=m.end())
					{
						f=0;
						break;
					}
				}
			}
			m.insert(x);
			if(f)
			{
				cnt++;
			}
			
		}
		cout<<cnt;
		

    }

}

Measured memory_bytes: 13816
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


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

	int kkt; cin >> kkt;
	while (kkt--) {
		ll H, W; cin >> H >> W;
		vector<string> vs(H); for (int i = 0; i < H; i++) cin >> vs[i];
		vector<char> v;
		map<char, int> x_mn, x_mx, y_mn, y_mx;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (vs[i][j] != '.') {
					v.push_back(vs[i][j]);
					if (x_mn.find(vs[i][j]) == x_mn.end()) {
						x_mn[vs[i][j]] = x_mx[vs[i][j]] = i;
						y_mn[vs[i][j]] = y_mx[vs[i][j]] = j;
					}
					else {
						chmin(x_mn[vs[i][j]], i);
						chmax(x_mx[vs[i][j]], i);
						chmin(y_mn[vs[i][j]], j);
						chmax(y_mx[vs[i][j]], j);
					}
				}
			}
		}
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
		bool flag = false;
		do {
			vector<string> vss(H, string(W, '.'));
			for (int i = 0; i < v.size(); i++) {
				for (int j = x_mn[v[i]]; j <= x_mx[v[i]]; j++) {
					for (int k = y_mn[v[i]]; k <= y_mx[v[i]]; k++) {
						vss[j][k] = v[i];
					}
				}
			}
			if (vs == vss) flag = true;
			if (flag) break;
		} while (next_permutation(v.begin(), v.end()));
		if (flag) puts("SAFE");
		else puts("SUSPICIOUS");
	}

	return 0;

}



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

const int ac = 1e6 + 10, mod = 1e9 + 7;
ll X[ac];
ll Y[ac];
ll A[ac], B[ac];
ll UF[ac];

ll f(ll a)
{
	if (UF[a] == a) return a;
	return UF[a] = f(UF[a]);
}

void u(ll a, ll b)
{
	UF[f(a)] = UF[f(b)];
}

bool cmp1(ll a, ll b)
{
	return X[a] < X[b];
}

bool cmp2(ll a, ll b)
{
	return Y[a] < Y[b];
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> X[i] >> Y[i];
	}
	for (int i = 0; i < n; i++)
		A[i] = B[i] = UF[i] = i;
	sort(A, A + n, cmp1);
	sort(B, B + n, cmp2);
	vector<array<ll, 3>> V;
	for (int i = 0; i < n - 1; i++)
	{
		V.push_back({X[A[i + 1]] - X[A[i]], A[i], A[i + 1]});
		V.push_back({Y[B[i + 1]] - Y[B[i]], B[i], B[i + 1]});
	}
	sort(V.begin(), V.end());
	ll s = 0;
	for (auto x : V)
	{
		if (f(x[1]) != f(x[2])) 
		{
			s += x[0];
			u(x[1], x[2]);
		}
	}
	cout << s << '\n';
}


Measured memory_bytes: 21616
a,b,k = map(int,input().split())
for i in range(k):
    if i%2==0:
        # takahashi
        if a%2==1:
            a -= 1
        a //= 2
        b += a
    else:
        if b%2==1:
            b -= 1
        b //= 2
        a += b
print(a,b)


Measured memory_bytes: 2940
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val s = readLine()!!
    val ans = IntArray(s.length)
    var left = 0
    var right = 1
    var lIndex = -1
    while (true) {
        if (right >= s.length) {
            break
        }

        var f = true
        while (right < s.length && !(s[right - 1] == 'L' && s[right] == 'R')) {
            if (f && s[right] == 'L') {
                lIndex = right
                f = false
            }
            right++
        }

        // 処理
//        out.println("$right $left $lIndex")
        val tmp = right - left
        ans[lIndex] = (lIndex - left) / 2 + (right - lIndex + 1) / 2
        ans[lIndex - 1] = (lIndex - left + 1) / 2 + (right - lIndex) / 2

        left = right
        right++
    }
    out.println(ans.joinToString(" "))
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

int main()
{
	ll N,K;
	cin >> K>>N;
	int mini = 10000000;
	int maxi = 0;
	vector<int> v;
	for(int i = 0 ;i<N;i++)
	{
		int temp;
		cin >> temp;
		v.push_back(temp);	
	}
	sort(v.begin(),v.end());
	int ans = v[N-1] - v[0];
	for(int i = 1; i<N;i++)
	{
		
		int temp = v[N-1] - v[i] + (K+v[i-1] - v[N-1]);
		if(temp < ans)
			ans = temp;
	}
	cout << ans<<endl;

}


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

int main() {
  int K,Z=-1;
  cin>>K;
  int A=1,B=0;
  for(int i=0;i<K;i++){
    B+=A*7;
    B%=K;
    if(B==0){
      Z=i+1;
      break;
    }
    A*=10;
    A%=K;
  }
  cout<<Z<<endl;
}



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

#include<stdlib.h>
#include<iostream>
#include<math.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define INF 2000000000
#define Min(a,b) (a<b?a:b)
#define Max(a,b) (a>b?a:b)
#define PI 3.1415926535897932
using namespace std;





int main()
{
IOS;
int a;
cin>>a;
long long ans=a+pow(a,2)+pow(a,3);
cout<<ans;




return 0;
}



Measured memory_bytes: 4040
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;

#define DCRPT_MAX 26

int Alpha;
int Beta; // 0 -> 25
int fCnt;

int F( int g ) {
  return ( Alpha * g + Beta ) % 26;
}

char f( char c ) {
  return F( c - 'a' ) + 'a';
}

string decode( string str, int cnt ) {
  for(int i=0; i<str.size(); i++) {
    for(int j=0; j<cnt; j++) {
      str[i] = f( str[i] );
    }
  }

  return str;
}

string Decrypt( string str, int cnt ) {
  
  for(int i=0; i<str.size(); i++) {
    for(int j=0; j<cnt; j++) {
      if( 'a' <= str[i] && str[i] <= 'z') {
	str[i] = f( str[i] );
      }
    }
  }

  return str;
}

bool affineCipher( vector<string> vec ) {
  
  for( Alpha = 1; Alpha < 26; Alpha ++ ) {
    if( Alpha % 2 == 0 || Alpha % 13 == 0 ) continue;
    for( Beta = 0; Beta < 26; Beta ++ ) {
      for(int i = 1; i < DCRPT_MAX; i ++) {
	for(int j = 0; j < vec.size(); j ++) {
	  string dec = decode( vec[j], i );
	  if( dec == "this" || dec == "that" ) {
	    fCnt = i;
	    return true;
	  }
	}
      }
    }
  }
  
  return false;
}


int main() {
  string cryptogram;
  int tcase;
  
  cin >> tcase; cin.ignore();
  
  for( int i = 0; i < tcase; i ++ ) {
    getline( cin, cryptogram );
    
    vector<string> v;
    stringstream ss( cryptogram );

    while(true) {
      string str;
      ss >> str; if( str == "" ) break;
      if( str.size() == 4 ) {
	v.push_back( str );
      }
    }

    if( affineCipher( v ) ) {
      cout << Decrypt( cryptogram, fCnt ) << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1232
using System;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());

            long[] a = new long[k];
            a[0] = 7;
            for (int i = 1; i < k; ++i) {
                a[i] = (a[i - 1] * 10 + 7) % k;
            }
            for (int i = 0; i < k; ++i) {
                if (a[i] % k == 0) {
                    Console.WriteLine(i + 1);
                    return;
                }
            }
            Console.WriteLine(-1);
            return;
        }
    }
}


Measured memory_bytes: 35204
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int ma = 0;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(S[i][j] == '#') continue;
				var dist = calc(i, j);
				ma = Math.Max(ma, dist);
			}
		}
		Console.WriteLine(ma);
		
	}
	
	bool InRange(int t, int l, int r){
		return l <= t && t < r;
	}
	int[] dx = new int[]{1,0,-1,0};
	int[] dy = new int[]{0,-1,0,1};
	
	int calc(int r, int c){
		
		int[][] min = new int[H][];
		for(int i=0;i<H;i++){
			min[i] = new int[W];
			for(int j=0;j<W;j++){
				min[i][j] = -1;
			}
		}
		
		min[r][c] = 0;
		var q = new Queue<int>();
		q.Enqueue(r * W + c);
		while(q.Count > 0){
			var now = q.Dequeue();
			int y = now / W;
			int x = now % W;
			for(int t=0;t<4;t++){
				int ny = y + dy[t];
				int nx = x + dx[t];
				if(!InRange(ny, 0, H) || !InRange(nx, 0, W)) continue;
				if(S[ny][nx] == '#') continue;
				if(min[ny][nx] == -1){
					min[ny][nx] = min[y][x] + 1;
					q.Enqueue(ny * W + nx);
				}
			}
		}
		
		int ma = 0;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(S[i][j] == '#') continue;
				ma = Math.Max(min[i][j], ma);
			}
		}
		return ma;
		
	}
	
	
	
	int H,W;
	String[] S;
	public Sol(){
		var d = ria();
		H = d[0]; W = d[1];
		S = new String[H];
		for(int i=0;i<H;i++) S[i] = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];
  vi l(n+1), r(n+1);
  rep(i,n){
    l[i+1] = __gcd(l[i],a[i]);
  }
  for(int i = n-1; 0 <= i; i--){
    r[i] = __gcd(r[i+1],a[i]);
  }
  int ans = 0;
  rep(i,n) chmax(ans,__gcd(l[i],r[i+1]));
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 4508
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n;
	cin >> n;
	int h[8][8];
	for (int z = 0; z < n; z++) {
		bool b[14][14];
		int c=0;
		string d;
		for (int i = 0; i < 8; i++) {
			cin >> d;
			for (int j = 0; j < 8; j++) {
				h[i][j] = (int)d[j] - '0';
				b[i + 3][j + 3] = false;
				if (h[i][j] == 1) c++;
			}
		}
		int x, y;
		cin >> x >> y;
		x--; y--;
		int l = x;
		x = y;
		y = l;
		b[x+3][y+3] = true;
		for (int i = 0; i < c; i++) {
			for (int i = 0; i < 8; i++) {
				for (int j = 0; j < 8; j++) {
					if (b[i+3][j+3] == true && h[i][j] == 1) {
						b[i + 3][j + 4] = true; b[i + 3][j + 5] = true; b[i + 3][j + 6] = true;
						b[i + 3][j + 2] = true; b[i + 3][j + 1] = true; b[i + 3][j] = true;
						b[i + 4][j + 3] = true; b[i + 5][j + 3] = true; b[i + 6][j + 3] = true;
						b[i + 2][j + 3] = true; b[i + 1][j + 3] = true; b[i][j + 3] = true;
						h[i][j] = 0; 
					}
				}
			}
		}
		cout << "Data " << z + 1 <<":"<< endl;
		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8; j++) {
				cout << h[i][j];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 3060
#include <iostream>
#include <list>
#include <iterator>
using namespace std;

int main () {
	int n, x;
	string cmd;
	list<int> alist;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> cmd;
		if (cmd == "insert") {
			cin >> x;
			alist.push_front(x);
		}
		else if (cmd == "delete") {
			cin >> x;
			list<int>::iterator ait = alist.begin();
			while(ait != alist.end()) {
				if(*ait == x) {
					alist.erase(ait);
					break;
				}
				else
					ait++;
			}
		}
		else if (cmd == "deleteFirst")
			alist.pop_front();
		else
			alist.pop_back();
		}
	n = alist.size();
	list<int>::iterator ait = alist.begin();
	for (int i = 0; i < n - 1; i++)
		cout << *ait++ << ' ';
	cout << *ait << endl;
	return 0;
}

Measured memory_bytes: 34308