akhauriyash/Code-Regression huggingface dataset:
x, n = map(int, input().split())
p = list(map(int, input().split()))

i = 0
ans = None if p else x

while(ans is None):
    xu, xd = x+i, x-i
    if xu not in p:
        ans = xu
    if xd not in p:
        ans = xd
    i=i+1

print(ans)


Measured memory_bytes: 9180
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out


N, K = map(int, input().split())

x = Base_10_to_n(N, K)

print(len(str(x)))


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;


int dp[101010];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin >> N;
    fill(dp, dp+N, inf);
    dp[0] = 0;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    rep(i, N) {
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
///#pragma GCC optimize("Ofast")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
///#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
///#include<ext/pb_ds/assoc_container.hpp>
///#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
///using namespace __gnu_pbds;
///template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll N = 10001;
const ll MOD = 1000000007;
const ll INF = LLONG_MAX;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rev(a) reverse(all(a))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl
#define space ' '
#define nl '\n'
#define PI acos(-1)

#define coutv(v) for(auto it:v)cout<<it<<space;cout<<nl;
#define cinv(v) for(auto &it:v)cin>>it;


int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int tc=1,cs=0;
    ///cin>>tc;
    while(tc--)
    {
        double r;
        cin>>r;
        cout<<fixed<<setprecision(6)<<2*PI*r<<nl;
    }
}


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

using namespace std;

using matrix = vector<vector<long>>;

const long M = 1e9 + 7;

void add_self(long& a, long b) {
    a += b;
    if (a >= M) a -= M;
}

long mul(long a, long b) {
    return a * b % M;
}

matrix mat_add(const matrix& m1, const matrix& m2) {
    int N = m1.size();
    auto res = m1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            add_self(res[i][j], m2[i][j]);
        }
    }
    return res;
}

matrix mat_mul(const matrix& m1, const matrix& m2) {
    int N = m1.size();
    auto res = m1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            long sum = 0;
            for (int k = 0; k < N; k++) {
                add_self(sum, mul(m1[i][k], m2[k][j]));
            }
            res[i][j] = sum;
        }
    }
    return res;
}

matrix mat_pow(const matrix& m, long N) {
    if (N == 1) return m;
    auto res = m;
    auto m1 = m;
    --N;
    while (N) {
        if (N & 1) res = mat_mul(res, m1);
        N /= 2;
        m1 = mat_mul(m1, m1);
    }
    return res;
}

long sum_all(const matrix& m) {
    long res = 0;
    int N = m.size();
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            add_self(res, m[i][j]);
        }
    }
    return res;
}

int main(int argc, char *argv[])
{
    long N, K;
    cin >> N >> K;
    matrix g(N, vector<long>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> g[i][j];
        }
    }
    // auto res = mat_pow(g, K);
    // for (int i = 0; i < N; i++) {
    //     for (int j = 0; j < N; j++) {
    //         cout << res[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    cout << sum_all(mat_pow(g, K)) << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
string a, s="None";
int i, c[130];
int main() {
	cin>>a;
	for(i=0; a[i]; i++) c[a[i]]++;
	for(i='z'; i>='a'; i--) if(!c[i]) s=i;
	cout<<s;
	return 0;
}

Measured memory_bytes: 512
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  let exprs = content
    .trim()
    .split('\n')
    .slice(1)
    .map(line => line.split(' '));
  
  // s is sorted
  const dict = new Dict();
  for (const [op, arg] of exprs) {
    switch(op) {
      case 'insert': {
        dict.add(arg);
        break;
      }
      case 'find': {
        const found = dict.find(arg);
        console.log(found ? 'yes' : 'no');
      }
    }
  }
});


class Dict {
  constructor() {
    this.hashTable = [];
  }

  add(str) {
    const key = this.getKeyFor(str);
    if (!this.hashTable[key]) {
      this.hashTable[key] = [];
    }

    this.hashTable[key].push(str);
  }

  find(str) {
    const key = this.getKeyFor(str);
    return this.hashTable[key] && this.hashTable[key].includes(str);
  }

  getKeyFor(str) {
    let sum = 0;
    let p = 1;
    for (const s of str) {
      sum += p * this.getKeyForChar(s);
      p *= 5;
    }

    return sum;
  }

  getKeyForChar(char) {
    switch(char) {
      case 'A': return 1;
      case 'C': return 2;
      case 'G': return 3;
      case 'T': return 4;
    }
  }
}


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

int dp[330];
int s,d,m;
int k[110],w[110][55],p[110][55],f[110];

int main(){
  
  while(cin >> s >> d >> m){
    for(int i=0;i<s;i++){
      cin >> k[i];
      for(int j=0;j<k[i];j++)cin >> w[i][j] >> p[i][j];
    }
    for(int i=0;i<d;i++)cin >> f[i];

    for(int i=0;i<=m;i++)dp[i] = -1;
    
    dp[0] = 0;

    for(int i=0;i<d;i++){
      for(int x=0;x<k[f[i]];x++){
	int v = p[f[i]][x], c = w[f[i]][x];
	for(int j=m-v;j>=0;j--){
	  if(dp[j]>=0)dp[j+v] = max(dp[j+v],dp[j]+c);
	}
      }
    }
	
    int ans = 0;
    for(int i=1;i<=m;i++)
      if(dp[i] > dp[ans])ans = i;
    cout << dp[ans] << " " << ans << endl;
  }
}

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

int main() {
  long long N;
  cin >> N;
  vector<long long> time(5);
  for (int i = 0; i < 5; i++) cin >> time.at(i);
  sort(time.begin(), time.end());
  cout << 4 + (N + time.at(0) - 1) / time.at(0) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int n,q,h,s,d;
  long long price,m;
  scanf("%d %d %d %d %d",&q,&h,&s,&d,&n);
  m=4*q;
  h=2*h;
  if (m>h) {
    m=h;
  }
  if (m>s) {
    m=s;
  }
  if (2*m<=d) {
    price=m*n;
  } else {
    price=d*((long long)n/2)+(n%2)*m;
  }
  printf("%lld\n",price);
  return 0;
}

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

typedef long long ll;

#define rep(var,n) for(int var=0;var<(n);++var)

template<class T>
std::istream &operator >> (std::istream &in, std::vector<T> &tgt){
  T input; in >> input;
  tgt.push_back(input);
  return in;
}

template<class T>
std::ostream &operator << (std::ostream &out, std::vector<T> &tgt){
  for(int i=0;i<tgt.size();i++)
    out << tgt.at(i) << " ";
  return out;
}

int main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n; cin >> n;
  vector<int> a; rep(i,n) cin >> a;

  vector<int> ans(n,0);
  rep(i,n){
    if(i%2==0) ans[0] += a[i];
    else ans[0] -= a[i];
  }
  ans[n-1] = (a[n-1]-ans[0]/2)*2;
  for(int i=n-2;i>0;i--) ans[i] = (a[i]-ans[i+1]/2)*2;

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

Measured memory_bytes: 2296
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

// #define DEBUG

const ll mod = 1e9 + 7;
ll mypow(ll x, ll y, ll m = mod)
{
    ll ans = 1;
    ll q = x;
    while (y > 0)
    {
        if (y % 2 == 1)
        {
            ans *= q;
            ans %= m;
        }
        q = q * q;
        q %= m;
        y = y / 2;
    }
    return ans%m;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    ll n, k;
    cin >> n >> k;
    cout << mypow(k, n) << endl;
    return 0;
}


Measured memory_bytes: 3104
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())


a, b, c, d = inpl()
 
i = math.ceil(a / d)
j = math.ceil(c / b)
if i >= j:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 75068
#include <stdio.h>
#include <stdlib.h>

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  int N,K;
  scanf("%d%d",&N,&K);

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

  int ans = 1e9;
  for(int i = 0;i+K-1 < N;i++){
    ans = min(ans,min(abs(x[i])+abs(x[i]-x[i+K-1]),abs(x[i+K-1])+abs(x[i+K-1]-x[i])));
  }

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

  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n;
int main() {
    cin >> n;
    if (n & 1) {
        n -= 1;
        n /= 2;
        cout << n * (n + 1) << endl;
    } else {
        n /= 2;
        cout << n * n << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    cout.precision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    return 0;
}
map<char, int> scor; 
void solve() { 
	int n, k;
	cin>>n>>k;
	cin>>scor['s'];
	cin>>scor['p'];
	cin>>scor['r'];
	string s;
	cin>>s;
	int ans=0;
	for (int i = 0; i < (int) s.size(); ++i) {
		if (i - k >= 0 and s[i - k] == s[i]) {
			s[i] = '#';
			continue;
		}
		ans+=scor[s[i]];
	}
	cout<<ans;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int sw = 1;
	int cnt = 0;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		if (sw == s[i] - '0') cnt++;
		else {
			v.push_back(cnt);
			cnt = 1;
			sw = 1 - sw;
		}
	}
	if (cnt != 0) v.push_back(cnt);
	if (v.size() % 2 == 0)v.push_back(0);
	vector<ll> sum(v.size() + 1);
	rep(i,v.size()) {
		sum[i + 1] = sum[i] + v[i];
	}
	int w = 2 * k + 1;
	ll ans = 0;
	for (int i = 0; i < sum.size(); i += 2) {
		int r = min(i + w, (int) sum.size() - 1);
		ans = max(ans, sum[r] - sum[i]);
	}
	cout << ans << endl;
}

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


Measured memory_bytes: 4648
import numpy as np
import math as m
import collections

def main(**kwargs):
    front = collections.deque()
    back = collections.deque()
    now = "f"

    for q in qs:
        if q[0] == "1":
            if now == "b":
                now = "f"
            else:
                now = "b"

    if now == "f":
        now = "f"

        for q in qs:
            if q[0] == "1":
                if now == "b":
                    now = "f"
                else:
                    now = "b"
            else:
                if (q[1] == "1" and now == "f") or (q[1] == "2" and now == "b"):
                    front.appendleft(q[2])
                else:
                    back.append(q[2])

        res = "".join(front) + s + "".join(back)
    else:
        now = "f"

        for q in qs:
            if q[0] == "1":
                if now == "b":
                    now = "f"
                else:
                    now = "b"
            else:
                if (q[1] == "1" and now == "f") or (q[1] == "2" and now == "b"):
                    front.append(q[2])
                else:
                    back.appendleft(q[2])
        res = "".join(back) + s[::-1] + "".join(front)
        
    return res

if __name__ == "__main__":
    cin = np.array(input().split(" "))
    s, *_ = cin
    cin = np.array(input().split(" ")).astype("int")
    n, *_ = cin

    qs = []

    for i in range(n):
        cin = np.array(input().split(" "))
        qs.append(list(cin))
    
    cout = main(s=s, n=n, qs=qs)
    print(cout)


Measured memory_bytes: 102964
N = int(input())
from collections import  defaultdict
items = defaultdict(list)
for i in range(N):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        x-=1
        items[i].append([x, y])

ans = 0
for bit in range(2 ** N):
    tmp = [False] * N
    cnt = 0
    for k in range(N):
        if bit & (1 << k):
            tmp[k] = True
            cnt += 1
    # print(tmp)
    check = True
    for k in range(N):
        if tmp[k]:
            res = items[k]
            for r in res:
                x = r[0]
                y = r[1]
                if y == 1:
                    if tmp[x]:
                        continue
                    else:
                        check = False
                else:
                    if tmp[x]:
                        check = False
                    else:
                        continue
    if check:
        ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 44252
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    private static final long MOD = 1000000007;

    private void solve() {
        int n = sc.nextInt();
        int k = sc.nextInt();

        long start = 0;
        long end = 0;
        long ans = 0;
        for (int i = 0; i <= n; i++) {
            start = (start + i) % MOD;
            end = (end + n - i) % MOD;
            if (i >= k - 1) {
                ans = (ans + end - start + 1 + MOD) % MOD;
            }
        }

        out.println(ans);
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}


Measured memory_bytes: 32864
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;

const long long MOD = (long long)1e9 + 7;

int n;
double x;
string u;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(20);
	cin >> n;
	double ans = 0.0;
	for (int i = 0; i < n; i++) {
		cin >> x >> u;
		if (u[0] == 'J') {
			ans += x;
		}
		else {
			ans += x * 380000.0;
		}
	}
	cout << ans << "\n";
	//system("pause");
	return 0;
}

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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;


signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> s(m), t(m);
    vector<vector<int>> edges(n);
    for(int i = 0; i < m; ++i){
        cin >> s[i] >> t[i];
        edges[--s[i]].emplace_back(--t[i]);
    }
    vector<double> dp(n, 0);
    for(int i = n - 2; i >= 0; --i){
        for(auto& x : edges[i])
            dp[i] += (dp[x] + 1) / edges[i].size();
    }

    vector<double> memo(dp);

    for(int i = 0; i < m; ++i){
        int a = s[i], b = t[i];
        if(edges[a].size() == 1)
            continue;

        double p = dp[a];
        p *= edges[a].size();
        p -= dp[b] + 1;
        p /= edges[a].size() - 1;
        memo[a] = min(memo[a], p);
    }

    double ans = dp[0];

    for(int k = 0; k < n; ++k){
        auto per = dp;
        per[k] = memo[k];
        for(int i = k - 1; i >= 0; --i){
            per[i] = 0;
            for(auto& x : edges[i])
                per[i] += (per[x] + 1) / edges[i].size();
        }
        ans = min(ans, per[0]);
    }

    printf("%.20lf\n", ans);
}


Measured memory_bytes: 2816
def read():
    S = input().strip()
    return S,


def solve(S):
    harf = len(S) // 2
    count = 0
    for i in range(harf):
        if S[i] != S[len(S) - 1 - i]:
            count += 1
    return count


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


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

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

	for (int i = 0; i < N; i++) {
		vector<int> v(3);
		cin >> v.at(0) >> v.at(1) >> v.at(2);

		sort(v.begin(), v.end());
		int& a = v.at(0),
			& b = v.at(1),
			& c = v.at(2);
		a *= a;
		b *= b;
		c *= c;
		if (a + b == c) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define INF LLONG_MAX

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  ll n;
  cin >> n;
  
  vector<ll> a(n,0);
  for(ll i=0;i<n;i++){
    cin >> a[i];
    a[i] -= i+1;
  }
  sort(a.begin(), a.end());
  ll b = a[n/2];
  ll ans = 0;
  for(ll i=0;i<n;i++){
    ans += abs(a[i]-b);
  }
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 4868
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2005;
int n,m,Q,i,j,a[N][N],f1[N][N],f2[N][N];
char s[N][N];
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
void write(int x){if (x>9) write(x/10);putchar(x%10+48);}
int ask(int a[N][N],int xa,int ya,int xb,int yb){
	return a[xb][yb]-a[xa-1][yb]-a[xb][ya-1]+a[xa-1][ya-1];
}
int main(){
	n=read();m=read();Q=read();
	for (i=1;i<=n;i++) scanf("%s",s[i]+1);
	for (i=1;i<=n;i++) for (j=1;j<=m;j++)
		a[i][j]=a[i][j-1]+a[i-1][j]-a[i-1][j-1]+(s[i][j]-=48);
	for (i=1;i<n;i++) for (j=1;j<=m;j++)
		f1[i][j]=f1[i][j-1]+f1[i-1][j]-
			f1[i-1][j-1]+(s[i][j]&&s[i+1][j]);
	for (i=1;i<=n;i++) for (j=1;j<m;j++)
		f2[i][j]=f2[i][j-1]+f2[i-1][j]-
			f2[i-1][j-1]+(s[i][j]&&s[i][j+1]);
	for (;Q--;){
		int xa=read(),ya=read(),xb=read(),yb=read();
		int ans=ask(a,xa,ya,xb,yb)-
			ask(f1,xa,ya,xb-1,yb)-ask(f2,xa,ya,xb,yb-1);
		write(ans);putchar('\n');
	}
}

Measured memory_bytes: 52736
def cP(x):
    if x%2==0 or x%3==0 or x%5==0 :
        return 0
    for i in range(7,int(x**0.5+1),2):
        if x%i==0:
            return 0
    return 1


x = int(input())
if x==2 or x==3 or x==5 :
    print(x)
    exit()

if x%2==0 :
    x+=1

while 1:
    if cP(x) :
        break
    #print(x)
    x+=2

print(x)



Measured memory_bytes: 9116
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten53 300005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

//stack<char> stk;
//set<ll> sll;
//set<pair<ll,ll>> spll;
//map<string,ll> mp;
//map<ll,ll> mp;
//deque<ll> deq;
//vector<ll> vll;
ll num[ten5],num2[ten5];
ll b1[2],b2[2];
//priority_queue<pair<ll,ll>> pq;          //decreasing

int main(void)
{
    ll m,n,i,j,k=0,m1,m2;
    string s;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>m;
        if(i&1==1)
        {
            num[m]++;
            if(num[m]>b1[0])
            {
                b1[0]=num[m];
                m1=m;
            }
            else if(num[m]>b1[1])
                b1[1]=num[m];
        }
        else
        {
            num2[m]++;
            if(num2[m]>b2[0])
            {
                b2[0]=num2[m];
                m2=m;
            }
            else if(num2[m]>b2[1])
                b2[1]=num2[m];
        }
    }
    if(m1!=m2)
        cout<<n-b1[0]-b2[0];
    else
        cout<<(b1[1]>=b2[1]?n-b1[1]-b2[0]:n-b1[0]-b2[1]);
    return 0;
}





Measured memory_bytes: 5184
N, K = map(int, input().split())
L = list(map(int, input().split()))

def sum_n(n):
  return n * (n + 1) // 2

sum_list = [0 for _ in range(N)]
for i in range(N):
  sum_list[i] = sum_n(L[i]) / L[i]

st = 0
ed = K - 1
tmp = sum(sum_list[:ed+1])
ans = tmp
for i in range(N - K):
  ed += 1
  tmp = tmp - sum_list[st] + sum_list[ed]
  ans = max(ans, tmp)
  st += 1

print(ans)

Measured memory_bytes: 24804
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll T=1000000000000000000;
ll a[100005];
int main(){
	int n;cin>>n;
	ll mul=1;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]==0){
			cout<<0<<'\n';
			return 0;
		}
	}
	for(int i=1;i<=n;++i){
		ll x=a[i];
		if(T<x)return puts("-1")*0;
		else{
			if(x==0){
				cout<<0<<'\n';
				return 0;
			}
			T/=x;
			mul*=x;
		}
	}
	cout<<mul<<'\n';
}


Measured memory_bytes: 4324
import java.io.IOException;
import java.util.NavigableSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			NavigableSet<Integer> taro = new TreeSet<Integer>();
			NavigableSet<Integer> hanako = new TreeSet<Integer>();
			for (int i = 0; i < n; i++)
				taro.add(scanner.nextInt());
			for (int i = 1; i <= n * 2; i++)
				if (!taro.contains(i))
					hanako.add(i);

			boolean flag = true;
			int a = 0;
			while (!taro.isEmpty() && !hanako.isEmpty()) {
				if (flag)
					a = taro.pollFirst();
				else
					a = hanako.pollFirst();
				while (!taro.isEmpty() && !hanako.isEmpty()) {
					if (flag) {
						if (hanako.higher(a) == null) {
							break;
						} else {
							a = hanako.higher(a);
							hanako.remove(a);
							flag = false;
						}
					} else {
						if (taro.higher(a) == null)
							break;
						else {
							a = taro.higher(a);
							taro.remove(a);
							flag = true;
						}

					}

				}
			}
			System.out.println(hanako.size());
			System.out.println(taro.size());
		}
	}
}

Measured memory_bytes: 20628
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int cnt = 0;
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];
    sort(l.begin(), l.end());
    for(int i = 0; i < n - 2; i++)
    {
        int k = i + 2;
        for(int j = i + 1; j < n; j++)
        {
            while(k < n && l[i] + l[j] > l[k]) k++;
            if(k > j) cnt += k - j - 1;
        }
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vii vector<ii>
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define pin(n) in(n.first) >> n.second
#define vin(a, n) for (ll i=0; i<n; ++i) in(a[i])
#define viin(a, n) for (ll i=0; i<n; ++i) in2(a[i].first, a[i].second);
#define out(n) cout << n
#define outs(n) out(n) << ' '
#define outn(n) out(n) << '\n'
#define out2(n, m) cout << n << ' ' << m
#define out2s(n, m) out2(n, m) << ' '
#define out2n(n, m) out2(n, m) << '\n'
#define pout(n) out2(n.first, n.second)
#define pouts(n) pout(n) << ' '
#define poutn(n) pout(n) << '\n'
#define vout(a) for (auto i : a) outs(i)
#define viout(a) for (auto i : a) out2n(i.first, i.second)
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pp(a, b) emplace_back(make_pair(a, b))
#define fori(i, n) for (ll i=0; i<n; ++i)
#define foris(i, a, b) for (ll i=a; i<b; ++i)
#define ford(i, n) for (ll i=n-1; i>=0; --i)
#define fords(i, a, b) for (ll i=a; i>=b; --i)
#define forr(i, a) for (auto &i : a)
const int mod = (int)(1e9) + 7;
//endregion


int main() {
    io();
    int n, k, mini = 1000000005;
    in2(n, k);
    vi arr(n);
    vin(arr, n);
    qsort(arr);
    fori (i, n-k+1) mini = min(mini, arr[i+k-1]-arr[i]);
    out(mini);
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<stdbool.h>
#define int long long
#define elif else if
#define mod 1000000007

int maxx(int a, int b)
{
	return (a>b)?a:b;
}
int main(void)
{
	int n;
	scanf("%lld",&n);
	int arr[n][3];
	for(int i = 0;i<n;i++)
	{
		scanf("%lld %lld %lld",&arr[i][0],&arr[i][1],&arr[i][2]);
	}

	int dp[n][3],ans;
	memset(dp,0,sizeof(dp));
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];
	for(int i = 1;i<n;i++)
	{
		dp[i][0] = arr[i][0] + maxx(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = arr[i][1] + maxx(dp[i-1][0],dp[i-1][2]);
		dp[i][2] = arr[i][2] + maxx(dp[i-1][1],dp[i-1][0]);
	}
	// ans = maxx
	ans = maxx(dp[n-1][0],maxx(dp[n-1][1],dp[n-1][2]));
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4864
' Imports System.Collections.Generic
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim A, B, K As Long
        Dim arr() As String
        arr = Split(Console.ReadLine())
        A = arr(0) : B = arr(1) : K = arr(2)
        Console.WriteLine(CStr(A - Math.Min(A, K)) & " " & CStr(B - Math.Min(B, K - Math.min(A, K))))
        Return
    End Sub
End Class


Measured memory_bytes: 28384
a,b,c,d=map(int,input().split())
a=min(4*a,2*b,c)
N=int(input())
if 2*a<=d:
  print(N*a)
else:
  if N%2==0:
    print(N//2*d)
  else:
    print(N//2*d+a)

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

pair<string, int> cipher(const string& s, int pos = 0);

pair<string, int> letter(const string& s, int pos) {
  if (s[pos] == '+') {
    string res;
    tie(res, pos) = letter(s, pos+1);
    if (res == "?") {
      return make_pair(res, pos);
    } else if (res == "Z") {
      res[0] = 'A';
      return make_pair(res, pos);
    } else {
      ++res[0];
      return make_pair(res, pos);
    }
  } else if (s[pos] == '-') {
    string res;
    tie(res, pos) = letter(s, pos+1);
    if (res == "?") {
      return make_pair(res, pos);
    } else if (res == "A") {
      res[0] = 'Z';
      return make_pair(res, pos);
    } else {
      --res[0];
      return make_pair(res, pos);
    }
  } else {
    return make_pair(s.substr(pos, 1), pos+1);
  }
}

pair<string, int> string_p(const string& s, int pos) {
  if (s[pos] == '[') {
    string res;
    tie(res, pos) = cipher(s, pos+1);
    reverse(begin(res),end(res));
    return make_pair(res, pos+1);
  } else {
    return letter(s, pos);
  }
}

pair<string, int> cipher(const string& s, int pos) {
  string res;
  string str;
  do {
    tie(str, pos) = string_p(s, pos);
    res += str;
  } while(pos < s.size() && s[pos] != ']');
  return make_pair(res, pos);
}

string convert(const string& s) {
  auto p = cipher(s).first;
  replace(begin(p),end(p),'?','A');
  return p;
}

int main() {
  while(1){
    string s;
    cin>>s;
    if (s == ".") break;
    cout << convert(s) << endl;
  }
  return 0;
}

Measured memory_bytes: 3164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node
{
    unsigned int key;
    struct node *next;
    struct node *prev;
};

typedef struct node *NodePointer;

NodePointer nil;

NodePointer listSearch(int key)
{
    /* your code */
    NodePointer i;
    for (i = nil->next; i != nil && i->key != key; i = i->next)
    {
    }
    return i;
}

void init()
{
    nil = malloc(sizeof(struct node));
    nil->next = nil;
    nil->prev = nil;
}

void printList()
{
    NodePointer cur = nil->next;
    int isf = 1;
    while (1)
    {
        if (cur == nil)
            break;
        if (isf == 0)
            printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
        isf = 0;
    }
    printf("\n");
}

void deleteNode(NodePointer t)
{
    /* your code */
    if (t == nil)
        return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst()
{
    NodePointer t = nil->next;
    if (t == nil)
        return;
    deleteNode(t);
}

void deleteLast()
{
    /* your code */
    NodePointer t = nil->prev;
    if (t == nil)
        return;
    deleteNode(t);
}

void delete (int key)
{
    /* your code */
    NodePointer t;
    t = listSearch(key);
    deleteNode(t);
}

void insert(int key)
{
    NodePointer x;
    x = malloc(sizeof(struct node));
    x->key = key;
    /*your code*/
    x = (struct node *)malloc(sizeof(struct node));

    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main()
{
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++)
    {
        scanf("%s%d", com, &key);
        if (com[0] == 'i')
        {
            insert(key);
            np++;
            size++;
        }
        else if (com[0] == 'd')
        {
            if (strlen(com) > 6)
            {
                if (com[6] == 'F')
                    deleteFirst();
                else if (com[6] == 'L')
                    deleteLast();
            }
            else
            {
                delete (key);
                nd++;
            }
            size--;
        }
    }

    printList();
    return 0;
}



Measured memory_bytes: 32964
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

struct ST {
  int D, P;
  static bool hi(const ST& l, const ST& r) { return l.P > r.P; }
};


int N, M;
ST st[10000];

bool input() {
  int i;

  scanf("%d %d", &N, &M);
  if (!N && !M) return false;

  for (i = 0; i < N; i++) {
    scanf("%d %d", &st[i].D, &st[i].P);
  }

  return true;
}

int main() {
  int i, sum;

  while (input()) {
    sum = 0;
    sort(st, st + N, ST::hi);
    for (i = 0; i < N; i++) {
      if (st[i].D < M) {
        M -= st[i].D;
        st[i].D = 0;
      } else {
        st[i].D -= M;
        M = 0;
      }
      sum += st[i].D * st[i].P;
    }
    printf("%d\n", sum);

  }

  return 0;
}

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

int main(void)
{
	double a, b, h, m,ans;
	scanf("%lf %lf %lf %lf",&a,&b,&h,&m);
	h += m / 60;
	h = h * M_PI / 6;
	m = m * M_PI / 30;
	
	h=fabs(h - m);

	
	ans = sqrt(a*a+b*b-2*a*b*cos(h));

	printf("%.16f",ans);

	return 0;
}

Measured memory_bytes: 2600
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){

  int N, M, R;cin >> N >> M >> R;
  
  vector <int> r(R);
  for (int i = 0; i < R; i++){
    cin >> r[i]; r[i]--;
  }
  sort(r.begin(), r.end());

  ll dist[N][N];
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      if(i != j) dist[i][j] = nmax;
      else dist[i][j] = 0;
    }
  }
  
  for (int i = 0; i < M; i++){
    int A, B, C; cin >> A >> B >> C;
    A--; B--;
    dist[A][B] = C;
    dist[B][A] = C;
  }
  
  for (int k = 0; k < N; k++){
    for (int i = 0; i < N; i++){
      for (int j = 0; j < N; j++){
        if (dist[i][j] > dist[i][k] + dist[k][j]){
          dist[i][j] = dist[i][k] + dist[k][j];
        }
      }
    }
  }

  ll ans = nmax;
  do{
    ll sum = 0;
    for (int i = 0; i < R - 1; i++){
      sum += dist[r[i]][r[i + 1]];
    }

    if (ans > sum){
      ans = sum;
    }

  } while (next_permutation(r.begin(), r.end()));
  
  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;
int main(){
    int N; cin >> N;
    vector<int> v;
    int a;
    for(int i = 0; i < N; i++){
        cin >> a;
        v.push_back(a);
    }
    
    for(int i = 1; i <= N-1; i++){
        cout << v[0];
        for(int j = 1; j < N; j++){
            cout << " " << v[j];
        }
        cout << endl;
        int j = i-1;
        int w = v[i];
        while(j >= 0 && v[j] > w){
            v[j + 1] = v[j];
            j--;
            v[j + 1] = w;
        }
        
    }
    cout << v[0];
    for(int i = 1; i < N; i++){
        cout << " " << v[i];
    }
    cout << endl;
    return 0;
}
    

Measured memory_bytes: 3148
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor, pow
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
S = ""
K = 0


def set_inputs():
    global S, K
    S = get_str()
    K = get_int()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    x = next(itertools.dropwhile(lambda i: i < len(S) and S[i] == "1", itertools.count(0)))
    if K - 1 < x:
        print("1")
        return
    print(S[x])
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()


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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")   */


//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 2e6 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 2e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

int t[N], dp[N];
vp a;
map <int, int> mp;

int bin (int x, int i) {
    int l = i, r = a.size();
    while (r - l > 1) {
        int m = (r + l) >> 1ll;
        if (a[m].ff < x) l = m;
        else r = m;
    }
    return l;
}

void upd (int v, int l, int r, int pos, int x) {
    if (r - l == 1) {
        t[v] = x;
        return;
    }
    else {
        int m = (r + l) >> 1;
        if (m <= pos) upd(v * 2 + 2, m, r, pos, x);
        else upd(v * 2 + 1, l, m, pos, x);
        t[v] = max(t[v * 2 + 1], t[v * 2 + 2]);
    }
}

int ask (int v, int l, int r, int tl, int tr) {
    if (l >= tr || r <= tl) return -1;
    if (tl <= l && r <= tr) {
        return t[v];
    }
    int m = (r + l) >> 1;
    return max(ask(v * 2 + 1, l, m, tl, tr), ask(v * 2 + 2, m, r, tl, tr));
}


signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    dp[n] = 1;
    for (int i = 0; i < n; i++) {
        int x, d;
        cin >> x >> d;
        a.pb({x, d});
    }
    sort(a.begin(), a.end());
    vi b;
    for (auto to : a) b.pb(to.ff + to.ss), b.pb(to.ff);
    int kol = 0;
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    for (auto to : b) {
        mp[to] = kol++;
    }
    for (int i = n - 1; i >= 0; i--) {
        int x = mp[a[i].ff + a[i].ss];
        int pos = bin(x, i);
        a[i].ff = mp[a[i].ff];
        if (pos == i) {
           upd(0, 0, n, pos, pos);
           dp[i] = (dp[i + 1] * 2) % mod;
        }
        else {
           int x1 = ask(0, 0, n, i + 1, pos + 1);
           upd(0, 0, n, i, x1);
           dp[i] = (dp[i + 1] + dp[x1 + 1]) % mod;
        }
    }
    cout << dp[0];
}


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

/*
code credits : ਜ਼ੈਲਦਾਰ
dashan jot singh
*/
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define inf LLONG_MAX
#define p pair<ll,ll>
ll n,m;
std::vector<ll> graph[100010];
ll dp[100010];
ll solve(ll i){
	if(graph[i].size()==0){
		return 0;
	}
	if(dp[i]!=-1){
		return dp[i];
	}
	ll xx=INT_MIN;
	for(auto x:graph[i]){
		xx=max(xx,1+solve(x));
	}
	dp[i]=xx;
	return dp[i];
}
int main(){
	fast;
	cin>>n>>m;
	for(ll i=0;i<m;i++){
		ll u,v;
		cin>>u>>v;
		graph[u].pb(v);
	}
	memset(dp,-1,sizeof(dp));
	ll ans=INT_MIN;
	for(ll i=1;i<=n;i++){
		ans=max(ans,solve(i));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
int main(){
	char c[200010],s[200010];
	int len;
	cin>>c+1>>s+1;
	len=strlen(c+1);
	int cnt=0,i,j;
	for(i=1;i<=len;i++){
		if(c[i]!=s[i])cnt++;
	}
	cout<<cnt;
}

Measured memory_bytes: 4008
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <memory.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <queue>
#include <stack>
#include <cstdio>
#include <bitset>
 
using namespace std;
 
#define nfs ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f first
#define s second
#define m_p make_pair
#define pb push_back
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define ll long long
#define ull unsigned long long
#define ld long double
#define ef else if
#define loc(x) (x).begin(),(x).end() 
#define locR(x) (x).rbegin(),(x).rend()
#define no puts("NO")
#define yes puts("YES")
#define ex puts("-1")
#define en puts("")
#define _ cout  
#define __ <<
#define outV(v) for(int i = 0 ; i < v.size() ; i++)cout << v[i] << ' ';
#define outA(x,l,r) for(int i = l ; i < r ; i++)cout << x[i] << ' ';
 
const ld EPS = 1e-18;
const double DEPS = 1e-9;
const ld PI = 3.141592653589793238;
const ull MOD = 1e9 + 7;
const int N = (int)(5e5) + 1;
 
 
ll gcd(ll fx, ll fy)
{
	if (!fy) return fx;
	return gcd(fy, fx % fy);
}
 
inline void fill(int* ar, int sz, int val)
{
	for (int i = 0; i < sz; i++)
	{
		ar[i] = val;
	}
}
 
int n, a[N], b[N], c[N], dp[N][3];
 
int main()
{
	cin >> n;
	
	for (int i = 0; i < n; i++)
	{
		scanf("%d", a + i);
		scanf("%d", b + i);
		scanf("%d", c + i);
	}
 
	memset(dp, -1, sizeof(dp));
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
 
	for (int i = 1; i <= n; i++)
	{
		dp[i][0] = max(dp[i][0], dp[i - 1][1] + a[i]);
		dp[i][0] = max(dp[i][0], dp[i - 1][2] + a[i]);
		dp[i][1] = max(dp[i][1], dp[i - 1][0] + b[i]);
		dp[i][1] = max(dp[i][1], dp[i - 1][2] + b[i]);
		dp[i][2] = max(dp[i][2], dp[i - 1][0] + c[i]);
		dp[i][2] = max(dp[i][2], dp[i - 1][1] + c[i]);
	}
 
	cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
}

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

int main() {

    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n+1);
    rep(i, n){
        cin >> a[i];
        b[a[i]]++;
    }

    ll res = 0;
    rep(i, n+1){
        res += (b[i] * (b[i]-1)) / 2;
    }
    
    rep(i, n){
        ll tmp1 = (b[a[i]] * (b[a[i]]-1)) / 2;
        ll tmp2 = ((b[a[i]]-1) * (b[a[i]]-2)) / 2;
        cout << res - tmp1 + tmp2 << endl;
    }

    return 0;
}

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

int main() {
  
  int N, K; cin >> N >> K; double ans = 0.0;
  
  for (int i = 1; i < N + 1; i++) {
    
    int tmp = i; int count = 0;
    
    while (true) {
      if (K <= tmp) break;
      tmp *= 2; count++;
    }
    
    int denominator = N * int(pow(2, count));
    
    ans += 1.0 / double(denominator);
    
  }
  
  cout << fixed << setprecision(10);
  
  cout << ans << endl;
  
}

Measured memory_bytes: 4124
package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"sort"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	type pair struct{ l, r,k int }

	tree := make([]int,5e5+10)
	add := func(i int, val int) {
		for ; i <= 5e5+5; i += i & -i {
			tree[i] += val
		}
	}
	sum := func(i int) (res int) {
		for ; i > 0; i &= i - 1 {
			res += tree[i]
		}
		return
	}
	query := func(l, r int) int { return sum(r) - sum(l-1) } // [l,r]

	var n,q int
	Fscan(in, &n,&q)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])

	}
	qs := make([]pair, q)
	for i := range qs {
		Fscan(in, &qs[i].l, &qs[i].r)
		qs[i].k = i
	}
	sort.Slice(qs, func(i, j int) bool { return qs[i].r < qs[j].r })
	it := 1
	vis := make([]int, 5e5+10)
	ans := make([]int,q )
	for _, q := range qs {
		for ;it<=q.r;it++ {
			if vis[a[it]] >0{
				add(vis[a[it]],-1)
			}
			vis[a[it]]=it
			add(it,1)
		}
		it = q.r+1
		ans[q.k]=query(q.l,q.r)
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 40648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

ll H, W;
vector<string> board;

bool is_symmetry(vector<string>& board) {
    for (ll h = 0; h < (H + 1) / 2; h++) {
        for (ll w = 0; w < W; w++) {
            ll g = H - 1 - h;
            ll v = W - 1 - w;

            if (board[h][w] != board[g][v]) {
                return false;
            }
        }
    }

    return true;
}

bool is_symmetric(ll h1, ll h2) {
    string s1 = board[h1], s2 = board[h2];
    vector<bool> used(W, false);
    for (ll w1 = 0; w1 < W; w1++) {
        for (ll w2 = w1 + 1; w2 < W; w2++) {
            if (!used[w1] && !used[w2] && s1[w1] == s2[w2] && s1[w2] == s2[w1]) {
                used[w1] = used[w2] = true;
                break;
            }
        }
    }
    
    ll unused = 0;
    for (auto u : used) {
        if (!u) {
            unused++;
        }
    }

    return unused < 2;
}

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

    cin >> H >> W;
    for (ll h = 0; h < H; h++) {
        string s;
        cin >> s;
        board.push_back(s);
    }

    vector<vector<ll> > alphabets(H, vector<ll>(26, 0));
    for (ll h = 0; h < H; h++) {
        for (auto s : board[h]) {
            alphabets[h][s - 'a']++;
        }
    }

    vector<bool> used(H, false);

    for (ll h1 = 0; h1 < H; h1++) {
        for (ll h2 = h1 + 1; h2 < H; h2++) {
            if (!used[h1] && !used[h2] && alphabets[h1] == alphabets[h2]) {
                if (is_symmetric(h1, h2)) {
                    used[h1] = used[h2] = true;
                    break;
                }
            }
        }
    }

    ll unused = 0;
    for (auto u : used) {
        if (!u) {
            unused++;
        }
    }

    if (unused >= 2) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    char name[4];
    gets(name);

    char name2[4] = "ABC";
    if((strcmp(name2,name)) == 0)
        printf("ARC\n");
    else
        printf("ABC\n");

    return 0;
}


Measured memory_bytes: 1532