akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

// 2部グラフの判定
// 使い方：colorを-1で初期化してください．
// 注意：連結かどうかに気をつけてください．
// 参考：https://qiita.com/drken/items/a803d4fc4a727e02f7ba#4-3-%E4%BA%8C%E9%83%A8%E3%82%B0%E3%83%A9%E3%83%95%E5%88%A4%E5%AE%9A
vector<ll> color;
bool is_2bu_graph(vector< vector<ll> >& G, ll now, ll col) {
    color[now] = col;
    for(auto g : G[now]) {
        if(color[g] != -1) {
            if(color[g] == col) return false;
            else continue;
        } else {
            if(!is_2bu_graph(G, g, 1-col)) return false;
        }
    }
    return true;
}

int main(){
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, 0, n) cin >> s[i];
    color.resize(n, -1);
    vector< vector<ll> > G(n), d(n, vector<ll> (n, 1e18));
    rep(i, 0, n) {
        rep(j, 0, n) {
            if(s[i][j] == '1') {
                G[i].push_back(j);
                d[i][j] = 1;
            }
        }
    }
    if(!is_2bu_graph(G, 0, 0)) {
        cout << -1 << endl;
        return 0;
    }
    rep(i, 0, n) d[i][i] = 0;
    rep(i, 0, n){
        rep(j, 0, n){
            rep(k, 0, n){
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
    ll ans = 0;
    rep(i, 0, n){
        rep(j, 0, n) ans = max(ans, d[i][j]);
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 4272
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


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

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;

void mymain(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> arr;
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        arr.pb(mp(a,b));
    }
    sort(all(arr));
    int ans=0,j=0;
    /*for(pair<int,int> p : arr){
        cout << p.F <<" "<< p.S <<endl;
    }
    cout <<endl;
    */
    priority_queue<int> q;
    for(int i=m-1;i>=0;i--){
        int l=m-i;
        //cout << l <<endl;
        while( j<n && arr[j].F<=l ){
            //deb(arr[j].S);
            q.push(arr[j].S);
            j++;
        }
        //deb(q.top());
       // cout << i <<" "<<l<<" "<<q.top() <<endl;
        if(!q.empty()){
                ans+=q.top();
        q.pop();
        }

    }
    cout << ans <<endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t;
t=1;
///cin>>t;
for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}


Measured memory_bytes: 3568
import math

N = int(input())

Y = math.floor(math.sqrt(2*N))
j = min(1,Y - 3)
while True:
    if (j-1)*j < 2 * N <= (j+1)*j:
        break
    j += 1

a = (j+1)*j//2
for i in range(1,j+1):
    if i != a-N:
        print(i)

Measured memory_bytes: 3408
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

template<class T>bool chmax(T &a, const T &b) {
   if (a < b) {
      a = b;
      return 1;
   }
   return 0;
}
template<class T>bool chmin(T &a, const T &b) {
   if (a > b) {
      a = b;
      return 1;
   }
   return 0;
}

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool dp[101000];
int X;

int main()
{
   cout << fixed << setprecision(10);
   cin >> X;
   dp[0] = 1;
   dp[105] = 1;
   REP(i, X) {
      dp[i + 100] += dp[i];
      dp[i + 101] += dp[i];
      dp[i + 102] += dp[i];
      dp[i + 103] += dp[i];
      dp[i + 104] += dp[i];
      dp[i + 105] += dp[i];
   }
   REP(i, X) {
      eprintf("%d,%d\n", i, dp[i]);
   }
   cout << (dp[X] ? 1 : 0) << endl;
   return 0;
}



Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b) + sum([c[a[i] - 1] for i in range(n - 1) if a[i] + 1 == a[i + 1]])
print(ans)

Measured memory_bytes: 38576
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String[] a = sc.nextLine().split("");
        String[] b = sc.nextLine().split("");
        String answer = "";
        for(int i = 0;i<a.length;i++){
            answer = answer + a[i];
            if(a.length>b.length && i == a.length-1){
                break;
            }
            answer = answer + b[i];
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
long long x;
long long ans;
int main(){
    cin >> x;
    ans = 0;
    ans += 2LL * (x / 11);
    x %= 11;
    if(x > 0){
        if(x <= 6){
            ++ans;
        }
        else{
            ans += 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

class UnionFind {
    vector<int> par;
    int n;

public:
    UnionFind(int n) : par(n, -1) {}

    int find(int x) {
        if (par[x] < 0) return x;
        return par[x] = find(par[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

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

    int n, m, k, l;
    cin >> n >> m;
    vector <int> lan[100005];
    for (int i = 0; i < n; i++) {
        cin >> k;
        for (int j = 0; j < k; j++) {
            cin >> l;
            lan[l].push_back(i);
        }
    }

    UnionFind uf(100005);

    for (int i = 1; i <= m; i++) {
        if (lan[i].size() < 2) continue;
        for (int j = 1; j < lan[i].size(); j++) {
            uf.unite(lan[i][j-1], lan[i][j]);
        }
    }

    for (int i = 1; i < n; i++) {
        if (!(uf.same(i, i-1))) {
            cout << "NO" << "\n";
            return 0;
        }
    }

    cout << "YES" << "\n";
    return 0;
}

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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP(A,B) make_pair(A,B)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

const ll MX=1e18;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    ll ans=1;
    bool ng=0;
    rep(i,0,n){
        ll tmp;
        cin >> tmp;
        if(tmp==0){
            cout << 0 ENDL;
            return 0;
        }
        if(ng || (MX+1)/ans < tmp || ans*tmp > MX){
            ng=1;
        }
        ans*=tmp;
    }
    if(ng) cout << -1 ENDL;
    else cout << ans ENDL;
    return 0;
}

Measured memory_bytes: 6020
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
using namespace std;


int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    int count = 0;
    int result = 0;
    for(int i = 0; i < s.size(); i++){
      switch(s.at(i)){
        case 'A':
        case 'C':
        case 'T':
        case 'G':
          count++;
          break;
        default:
          count = 0;
      }
      result = max(result, count);
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
a,b,mix,n_a,n_b=input().rstrip().split()
a=int(a)
b=int(b)
mix=int(mix)
n_a=int(n_a)
n_b=int(n_b)
x=[n_a,n_b]
fee=a*n_a+b*n_b
fee_a=2*mix*max(x)
fee_mix=0
if n_a>=n_b:
    fee_mix=n_b*2*mix+(n_a-n_b)*a
else:
    fee_mix=n_a*2*mix+(n_b-n_a)*b
print(min(fee,fee_a,fee_mix))

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

int main()
{
    string s = "", ss;
    int H, W;
    cin >> H >> W;
    W += 2;
    for(int i = 1; i <= W; i++){
        s += "#";
    }
    cout << s << "\n";
    while(H--){
        cin >> ss;
        cout << "#" << ss << "#" << "\n";
    }
    cout << s << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,sum=0;
  cin>>n;
  for(ll i=1;i<=n;i++){
    if(i%3==0 || i%5==0){
      continue;
    }
    sum+=i;  
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h> 
#include<cmath>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define nax 3e5+2
using namespace std;

int main() 
{ 	
	string s;
	cin>>s;
	if(s[2] == s[3] && s[4] == s[5]){
		cout<<"Yes";
	}
	else
		cout<<"No";
	
	return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

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

int main(){
    int  x,a,b;
    cin >> x >> a >> b;
    if(abs(x-a) > abs(x-b)){
        cout << "B" << endl;
    }else{
        cout << "A" << endl;
    }

    return 0;
}

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

const int nax = 1e5+5;
vector<int> v[nax];
int dist[nax];
int in_degree[nax];
bool visited[nax];


void dfs(int a){
    assert(!visited[a]);
    visited[a]=true; 
    for(int b:v[a]){
        dist[b]= max(dist[b],dist[a]+1);
        --in_degree[b];
        if(in_degree[b]==0){
            dfs(b);
        } 
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        ++in_degree[y];
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(!visited[i] && in_degree[i]==0){
            dfs(i);
        }
    }
    for(int i=1;i<=n;i++){
        cnt=max(cnt,dist[i]);
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 14568
n,k = map(int,input().split())

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

print(len(str(Base_10_to_n(n, k))))

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
		int N;
	cin >> N;
	vec(B)
	fx(N-1) {
		vecp(B)
	}
	B.insert(B.begin(), B.at(0));
	ll ans = 0;
	fx(N-1) {
		ans += min(B.at(x), B.at(x + 1));
	}
	ce(ans+B.at(N-1))
    return 0;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Problem solver = new Problem();
        solver.solve(0, in, out);
        out.close();
    }

    static class Problem {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int[] players = new int[N];
            for (int i = 0; i < N; i++)
                players[i] = in.nextInt();

            if(N == 0) {
                out.println(0);
                return;
            }

            if(N == 1) {
                out.println(players[0]);
                return;
            }

            Arrays.sort(players);
            long maxComfort = players[players.length - 1];
          	int i = players.length - 2;
            N -= 2;
            while (N > 0) {
                maxComfort += 2 * players[i];
                N -= 2;
                i--;
            }

            if(N == -1) {
                maxComfort -= players[i + 1];
            }

            out.println(maxComfort);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 55692
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

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

	Int N;
	cin >> N;

	vector<Int> b(N - 1);
	for (Int i = 0; i < N-1; i++) {
		cin >> b[i];
	}

	vector<Int> a(N);
	a[0] = b[0];
	a[N - 1] = b[N - 2];

	for (Int i = 0; i < N-2; i++) {
		if (b[i + 1] >= b[i]) {
			a[i + 1] = b[i];
		}
		else {
			a[i + 1] = b[i + 1];
		}
	}

	Int ans = 0;
	for (Int i = 0; i < N; i++) {
		ans += a[i];
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	    int resultCount = 0;
	    while (true) {
		    String[] line = br.readLine().split(" ");

		    int n = Integer.parseInt(line[0]);
		    int x = Integer.parseInt(line[1]);

		    if (n == 0 && x == 0) break;

		    for (int i = 1; i <= n; i++) {
		    	for (int j = i + 1; j <= n; j++) {
		    		for (int k = j + 1; k <= n; k++) {

		    			if (i + j + k == x) {
		    				resultCount++;
		    			}
		    		}
		    	}
		    }
		    System.out.println(resultCount);
		    resultCount= 0;
	    }
	}
}

Measured memory_bytes: 25128
//============================================================================
// Name        : abc101.cpp
// Author      : sep
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>

using namespace std;

inline void main101A() {

	int n = 0;
	int i;
	string s;

	cin >> s;

	for (i = 0; i < s.length(); i++)
		if (s[i] == '-') {
			--n;
		} else {
			++n;
		}

	cout << n;

}

inline void main101B() {

	long long int n;
	int i;
	long long int temp;
	long long int sum = 0;

	cin >> n;
	temp = n;

	for (i = 0; temp > 0; i++) {
		sum += temp % 10;
		temp /= 10;
	}

	if (n % sum == 0) {
		cout << "Yes";
	} else {
		cout << "No";
	}

}

inline void main101C() {

}

inline void main101D() {

}

int main() {

#ifdef TEST
	struct timespec startTime, endTime;
	while (1) {
		clock_gettime(CLOCK_REALTIME, &startTime);
#endif

		main101B();

#ifdef TEST
		cout << flush;
		cerr << flush;
		cerr << endl << "Elapsed Time:";
		clock_gettime(CLOCK_REALTIME, &endTime);
		if (endTime.tv_nsec < startTime.tv_nsec) {
			cerr << endTime.tv_sec - startTime.tv_sec - 1 << "."
					<< endTime.tv_nsec + 1000000000 - startTime.tv_nsec << "s"
					<< endl;
		} else {
			cerr << endTime.tv_sec - startTime.tv_sec << "."
					<< endTime.tv_nsec - startTime.tv_nsec << "s" << endl;
		}

		cerr << endl;
	}
#endif

	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;

fn func(x:i32) -> i32 {
    if x/10 == 0 {return x;}
    x%10 + func(x/10)
}

fn main() {
    let n:i32 = read();

    println!("{}", if n%func(n)==0 {"Yes"} else {"No"});

}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  ll n;
  cin >> n;
  vector<ll>v(n);
  rep(i,n)cin >> v[i];
  map<ll,ll>m;
  rep(i,n){
    m[(i + 1) - v[i]]++;
    v[i] += (i + 1);
  }
  ll ans = 0;
  rep(i,n)ans += m[v[i]];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 27544
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int a, b, c, d, e, na, nb, nc;
    while (cin >> a >> b >> c >> d >> e, a) {
        cin >> na >> nb >> nc;
        int mn = 1 << 30;
        for (int i = 0; i <= na + nb + nc; ++i) {
            int ct1, ct2, ct3, ct4, ct5, ct6;
            ct1 = min(max(0, i), na);
            ct4 = min(max(0, na - i), na);
            ct2 = min(max(0, i - na), nb);
            ct5 = min(max(0, na + nb - i), nb);
            ct3 = min(max(0, i - na - nb), nc);
            ct6 = min(max(0, na + nb + nc - i), nc);
            mn = min(mn, min(ct4 * a + ct5 * b + ct6 * c, max(ct4 + ct5 + ct6, d) * e) + ct1 * a + ct2 * b + ct3 * c);
        }
        cout << mn << endl;
    }
    return 0;
}

Measured memory_bytes: 3108
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

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


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n, long long m, long long v, long long p, std::vector<long long> a){
    sort(a.begin(), a.end(), greater<i64>());
    i64 ans = 0;

    auto f = [&](i64 idx){
        i64 border = a[idx] + m;
        i64 cnt_sum = 0;
        i64 ignore_cnt = 0;
        for(i64 i = 0; i < n; ++i){
            if(idx == i){
                cnt_sum += m;
                continue;
            }
            if(ignore_cnt < p - 1){
                ++ignore_cnt;
                cnt_sum += m;
                continue;
            }
            if(a[i] > border)
                return false;
            i64 cnt = max(0LL, min(border - a[i], m));
            cnt_sum += cnt;
        }
        return cnt_sum >= m * v;
    };

    i64 ok = -1, ng = n;
    while(abs(ng - ok) > 1){
        i64 mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    };
    cout << ok + 1 << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long V;
    scanf("%lld",&V);
    long long P;
    scanf("%lld",&P);
    std::vector<long long> A(N);
    for(i64 i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, V, P, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
//-------------
//include
//-------------
#include <map>
#include <list>
#include <cmath>
#include <vector>
#include <string>
#include <cctype>
#include <random>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
//-------------
//typedef
//-------------
typedef long long LL;
typedef  vector<int> VI;
typedef  pair<int, int> PII;
typedef  vector<int, int> VII;
typedef  map<string, int> MSI;
//-------------
//utillty
//-------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MK make_pair
#define PB push_back
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//-------------
//repetition
//-------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//-------------
//debug
//-------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumpl(x) REP(i,SZ(x))cerr<<i<<x<<"="<<x[i]<<endl;
const int MOD = 1000000007;
int main()
{
	int RGB,num;
	cin >> num;
	RGB += num * 100;
	cin >> num;
	RGB += num * 10;
	cin >> num;
	RGB += num * 1;
	RGB % 4 == 0 ? cout << "YES" << endl : cout << "NO" << endl;
#ifdef _DEBUG
	while(1);
#endif
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int year, month, day, sum;

int print(void);

int main(void)
{
    while(scanf("%d %d %d", &year, &month, &day) != EOF) {
    sum = 10000 * year+ 100 * month + day;
    print();
    }
    return 0;
}

int print(void)
{
    if (sum < 18680907) {
        printf("pre-meiji\n");
    } else if (sum < 19120730) {
        printf("meiji %d %d %d\n", year - 1867, month, day);
    } else if (sum < 19261225) {
        printf("taisho %d %d %d\n", year - 1911, month, day);
    } else if (sum < 19890108) {
        printf("showa %d %d %d\n", year - 1925, month, day);
    } else {
        printf("heisei %d %d %d\n", year - 1988, month, day);
    }
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int k,a,b;
  cin>>k>>a>>b;
  
  int lo=a/k;
  if(a%k) lo++;
  
  lo*=k;
  
  puts((lo>=a && lo<=b)?"OK":"NG");
  
  return 0;
  
}

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


int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (a >= k) cout << k << endl;
	else if(a + b >= k){
		cout << a << endl;
	}
	else {
		cout << a - k + a + b << endl;
	}
}


Measured memory_bytes: 3492
import math


def is_prime(num):
    if num == 2:
        return True
    elif num % 2 == 0:
        return False

    for i in range(3, int(math.floor(math.sqrt(num))) + 1):
        if num % i == 0:
            return False
    return True


def solve():
    count = 0
    for _ in range(int(input())):
        if is_prime(int(input())):
            count += 1
    print(count)


if __name__ == "__main__":
    """
    1 <= n <= 10000
    x <= 10^8
    """
    solve()



Measured memory_bytes: 5696
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define srt(a) sort(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int> 
#define vplli vector <pair <lli,lli> >
#define vpulli vector <pair <ulli,ulli> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pair <int,int>> >
#define vvb vector <vector <bool> >
#define fr(i,n) for (int i = 0; i < (n); i++)
#define frbig(i,n) for (lli i = 0; i < (n); i++)
#define fra(i,a,n) for (lli i = a; i < (n); i++)
#define run(c,s) for(auto c:s) 
#define read(n) int n; cin >> n;
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;
const lli MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    read(n);read2(a,b);
    if(a/n==b/n && a%n>0 && b%n>0) cout << "NG";
    else cout << "OK";
    return 0;
}


Measured memory_bytes: 3608
import sys

d = {i:0 for i in range(1,101)}
for i in map(int, sys.stdin):
    d[i] += 1
s = sorted(d.items(), key=lambda x: x[1], reverse=True)
m = s[0][1]
for i in s:
    if i[1] < m:
        break
    print(i[0])

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

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

  int N; cin >> N;
  int X = -1;
  for (int i = 0; i <= N; i++) {
    int t = i * 1.08;
    if (t == N) X = i;
  }

  if (X == -1) {
    cout << ":(" << '\n';
  } else {
    cout << X << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(a,b) for(int i = a;i < b; i++)
using namespace std;

void troca(int i, int j, char * vet){
	char aux;
	aux = vet[i];
	vet[i] = vet[j];
	vet[j] = aux;
}

int main() {
	int x, res=0,sim1=0, sim2=0, parei, para=0;
	char aux[212345];
	scanf(" %d", &x);
	scanf(" %[^\n]", aux);
	rep(0,x) {
		if(aux[i] == 'W') sim1=1;
		if(aux[i] == 'R') sim2=1;
	}
	if (sim1 and sim2){
		parei = x-1;	
		for (int i = 0;i <= x;i++) {
			// printf("I = %d\n", i);
			para=0;
			if (aux[i] == 'W'){		
				for (int j = parei;j >= i;j--) {
					// printf("J = %d\n", j);
					if (aux[j] == 'R'){
						parei = j-1;
						troca(i,j,aux);
						res++;para=1;
						break;
					}
				}
				if (!para) {
					break;
				}
			}
		}
	}
	// printf("%s\n", aux);
	printf("%d\n", res);
	
	return 0;
}


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

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

  int p[22];
  for (int i = 0; i < N; i++) cin >> p[i];

  int cnt = 0;

  for (int i = 0; i < N - 2; i++) {
    if (p[i] < p[i + 1] && p[i + 1] < p[i + 2]) cnt++;
    if (p[i + 2] < p[i + 1] && p[i + 1] < p[i]) cnt++;
  }
  cout << cnt << endl;
}


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

int main(){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    int x[N], y[M];
    for (int i=0; i<N; i++) {
        cin >> x[i];
    }
    for (int i=0; i<M; i++) {
        cin >> y[i];
    }

    sort(x, x+N);
    sort(y, y+M);

    if (x[N-1] < y[0]) {
        if (x[N-1] < Y && X < y[0]) {
            cout << "No War" << endl;
            return 0;
        }
    }

    cout << "War" << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = tuple(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()

diff = [x[i + 1] - x[i] for i in range(len(x) - 1)]
diff.sort()

diff_sum = 0

for i in range(len(diff) - (n - 1)):
    diff_sum += diff[i]

print(diff_sum)


Measured memory_bytes: 13968
#include <bits/stdc++.h>
using namespace std;
int l[100010];
int r[100010];

int main (int argc, char const* argv[])
{
	priority_queue <long long> dec;
	priority_queue <long long, vector <long long>, greater <long long> > inc;
	
	long long add_dec = 0;
	long long add_inc = 0;
	
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d %d", &l[i], &r[i]);
	}	 
	
	long long c = 0;
	dec.push(l[1]);
	inc.push(l[1]);
	for(int i = 2; i <= n; i++) {
		add_dec -= r[i] - l[i];
		add_inc += r[i-1] - l[i-1];
		long long opt1 = dec.top() + add_dec;
		long long opt2 = inc.top() + add_inc;
		if(l[i] <= opt1) {
			dec.pop();
			inc.push(opt1 - add_inc);
			dec.push(l[i] - add_dec);
			dec.push(l[i] - add_dec);
			c += abs(l[i] - opt1);
		} else if (opt2 <= l[i]) {
			inc.pop();
			dec.push(opt2 - add_dec);
			inc.push(l[i] - add_inc);
			inc.push(l[i] - add_inc);
			c += abs(l[i] - opt2);
		} else {
			dec.push(l[i] - add_dec);
			inc.push(l[i] - add_inc);
		}
	}
	printf("%lld\n", c);
	return 0;
}

Measured memory_bytes: 2804
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cmath>
using namespace std;


const int MAX_N = 6;
const int INF = 1<<24;
const double EPS = 1e-5;

bool equals(double a, double b) {
  return fabs(a-b) <= EPS;
}

double r;
int s;
int w[MAX_N];


int sum(int a, int b) {
  int res = 0;
  for(int i = a; i < b; ++i) {
    res += w[i];
  }
  return res;
}
/*
pair<double, double> rec(double x, int a, int b) {
  if(b-a == 1) {
    return make_pair(x, x);
  }
  pair<double, double> res, p;
  res = make_pair(-INF, INF);
  for(int i = a+1; i < b; ++i) {
    int su = sum(a, b);
    int u = sum(a, i);
    int v = sum(i, b);
    p = rec(x-(double)v/su, a, i);
    res.first = max(res.first, p.first);
    p = rec(x+(double)u/su, i, b);
    res.second = min(res.second, p.second);
  }
  return res;
}
*/
double calc() {
  int t[MAX_N];
  for(int i = 1; i <= s-1; ++i) {
    t[i-1] = i;
  }

  double pos[MAX_N];
  int g[MAX_N];
  double res = -INF;

  do {
    int cnt = 1;
    fill(pos, pos+s, 0.0);
    fill(g, g+s, 0);
    for(int k = 0; k < s-1; ++k) {
      int a, b;
      int sa, sb;
      for(a = t[k]-1; a >= 0 && g[a] == g[t[k]-1]; --a); ++a;
      for(b = t[k]; b < s && g[b] == g[t[k]]; ++b);
      sa = sum(a, t[k]);
      sb = sum(t[k], b);
      for(int i = a; i < t[k]; ++i) {
	pos[i] -= (double)sb/(sa+sb);
	g[i] = cnt;
      }
      ++cnt;
      for(int i = t[k]; i < b; ++i) {
	pos[i] += (double)sa/(sa+sb);
	g[i] = cnt;
      }
      ++cnt;
    }
    double minv, maxv;
    minv = INF;
    maxv = -INF;
    for(int i = 0; i < s; ++i) {
      minv = min(minv, pos[i]);
      maxv = max(maxv, pos[i]);
    }
    double newv = maxv - minv;
    if(!equals(newv, r) && newv < r) res = max(res, newv);

  } while(next_permutation(t, t+s-1));

  return res;
}

double solve() {
  sort(w, w+s);
  double res = -INF;
  do {
    //    pair<double, double> p = rec(0.0, 0, s);
    //    double newV = p.second - p.first;
    double newV = calc();
    res = max(res, newV);
  } while(next_permutation(w, w+s));
  return res == -INF ? -1 : res;
}

int main() {
  int T;
  cin >> T;
  for(int tc = 1; tc <= T; ++tc) {
    cin >> r;
    cin >> s;
    for(int i = 0; i < s; ++i) {
      cin >> w[i];
    }
    double res = solve();
    if(res == -1) printf("%d\n", -1);
    else printf("%.16f\n", res);
  }
  return 0;
}

Measured memory_bytes: 984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    ll n,k;cin>>n>>k;
    vector<ll> h(n);
    rep(i,n)cin>>h[i];
    sort(h.begin(),h.end());
    ll sum=0;
    rep(i,n-k)sum+=h[i];
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1792
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#define IFD(...)
#ifndef NDEBUG
#define NDEBUG
#endif
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <boost/hana/functional/fix.hpp>
using boost::hana::fix;
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, b, a) for (int i = (b); i >= (a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    i64 a, b;
    cin >> a >> b;
    cout << a * b / gcd(a, b) << endl;

    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>

//AOJ0075
#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

int main(void){

int bg,cnt=0;
double tj, sc;
char k;

	while(!cin.eof()){
		cin >> bg >> k >> tj >> k >> sc;
		if(cin.eof()) break;
		if(tj/(sc*sc) >= 25){
			cout << bg << endl;
			cnt++;
		}
	}
	if(cnt==0) cout << "該当なし" << endl;
	return 0;
	
}

Measured memory_bytes: 1232
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
#include <ios>     
#include <iomanip> 
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;



llong gcd(llong a, llong b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}

//ここまで共通

llong INF = 20000000000;

int N, K;
llong X[100100];
llong Y[100100];
int x = 0, y = 0;
int main() {
	cin >> N >> K;

	llong tmp;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		if (tmp > 0) {
			X[x] = tmp;
			x++;
		}

		else if (tmp < 0) {
			Y[y] = -tmp;
			y++;
		}

		else {
			K--;
		}
	}

	sort(X, X + x);
	sort(Y, Y + y);

	for (int i = x; i <= K; i++) {
		X[i] = INF;
	}

	for (int i = y; i <= K; i++) {
		Y[i] = INF;
	}


	if (K == 0) cout << 0;
	else {
		llong ans = min(X[K - 1], Y[K - 1]);
		for (int i = 1; i <= K - 1; i++) {
			ans = min({ ans, X[K - 1 - i] + 2 * Y[i - 1], X[K - 1 - i] * 2 + Y[i - 1] });
		}

		cout << ans;
	}
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int N, M;
vector<vector<int>> G;
int dp[100000];

int dfs(int s){
    if(dp[s] != -1) return dp[s];

    int ret = 0;
    for(int t : G[s]){
        dp[t] = dfs(t);
        ret = max(ret, dp[t]+1);
    }
    dp[s] = ret;
    return ret;
}

int main(){
    cin >> N >> M;
    G.resize(N);
    for(int j=0; j<M; j++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
    }

    fill_n(dp, N, -1);

    for(int i=0; i<N; i++)
        dfs(i);


    int ans = 0;
    for(int i=0; i<N; i++)
        ans = max(ans, dp[i]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"

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

  IN(N);

  int A[N];
  REP(i, N) {
    cin >> A[i];
    A[i] -= i+1;
  }
  sort(A, A+N);
  ll ans = 0,
      median = A[N/2];

  REP(i, N)
    ans += (ll)abs(A[i] - median);

  OUT(ans);

  return 0;
}


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





int main(){
  int a,b,c;
  int x,y;
  cin>>a>>b>>c>>x>>y;
  if(a>b){swap(a,b);}
  if(a>c){swap(a,c);}
  x=min(x,y);
  int ans=a+x-50;
  cout<<ans<<endl;
  
  
  return 0;
}



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

int main() {
    int N;
    cin >> N;
    char C[N];
    for (int i = 0; i < N; i++)
        cin >> C[i];
    
    int head_idx = 0;
    int tail_idx = N-1;
    int cnt = 0;
    for (;head_idx < tail_idx; head_idx++, tail_idx--) {
        while (C[head_idx] != 'W' && head_idx < N)
            head_idx++;
        while (C[tail_idx] != 'R' && tail_idx >= 0)
            tail_idx--;

        if (head_idx < tail_idx)
            cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
int N, M, Q;
vector<int> A, B, C, D;
ll ans = 0;

ll calc(vector<int> x){
  ll res = 0;
  rep(q,Q){
    if(x[B[q]-1] - x[A[q]-1] == C[q]){
      res += D[q];
      //cout << D[q] << endl;
    }
  }
  return res;
}

void dfs(vector<int> x){
  if(sz(x)==N){
    //cout << 'Y' << endl;
    ans = max(ans, calc(x));
    return;
  }
  //cout << sz(x) << endl;
  int i = x[sz(x)-1];
  //cout << i << endl;
  //i++;
  for(; i<=M; i++){
    //cout << i << endl;
    vector<int> aa = x; aa.pb(i);
    dfs(aa);
  }
}

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


  rep(q,Q){
    int a, b, c, d; cin >> a >> b >> c >> d;
    A.pb(a);
    B.pb(b);
    C.pb(c);
    D.pb(d);
  }


  for(int i=1; i<=M; i++){
    vector<int> x = {i};
    dfs(x);
  }

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


Measured memory_bytes: 3604
#include <cstdio>
#include <set>
#include <utility>
using namespace std;

int main(){
	int n;
	double r, x, y;
	scanf("%d%lf", &n, &r);
	
	set<pair<int,int> > st;
	for(int i = 0; i < n; ++i){
		scanf("%lf%lf", &x, &y);
		st.insert( make_pair((x + 1e6) / r, (y + 1e6) / r));
	}
	
	set<pair<int,int> >::iterator it, it2;
	int ans = 0;
	for(it = st.begin(); it != st.end(); st.erase(it++)){
		++ans;
		for(int i = -1; i <= 1; ++i)
		for(int j = -1; j <= 1; ++j){
			if( i == 0 && j == 0 ) continue;

			it2 = st.find( make_pair(it->first + i, it->second + j) );
			if( it2 != st.end() ){
				st.erase(it2);
			}
		}
	}
	
	printf("%d\n", ans);
}

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int a,b,c;

main() {
    cin >> a >> b >> c;
    ct(a*b/2)
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>

int n,m,a[101];

int main() {
	std::cin >> n >> m;
	int tot = 0;
	for(int i = 1;i <= n;i++) std::scanf("%d",a + i), tot += a[i];
	int res = 0;
	for(int i = 1;i <= n;i++) {
		if(a[i] * 4 * m >= tot) res++;
	}
	if(res >= m) std::puts("Yes");
	else std::puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    ll A, B, C;
    cin >> A >> B >> C;
    swap(A, B);
    swap(A, C);
    cout << A << " " << B << " " << C << endl;
    return 0;
}

Measured memory_bytes: 256
# 解答

N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

for i in range(N):
  P[i] -= 1  

visit = [False for _ in range(N)]
loops = []

for i in range(N):
  if visit[i]:
    continue
  now = i
  loop = [C[now]]
  visit[now] = True
  while not visit[P[now]]:
    now = P[now]
    loop.append(C[now])
    visit[now] = True
  loops.append(loop)

ans = -float("inf")
for loop in loops:
  n = len(loop)
  r = K%n
  m = K//n
  if r==0:
    r = n
    m -= 1
  suml = sum(loop)
  if K > n and suml <= 0:
    r = n
    m = 0
  cumsum = [0] + loop + loop[:r-1]
  for i in range(n+r-1):
    cumsum[i+1] = cumsum[i] + cumsum[i+1]
  maxC = -float("inf")
  for i in range(n):
    for j in range(i+1, i+r+1):
      maxC = max(maxC, cumsum[j]-cumsum[i])
  ans = max(ans, maxC + suml*m)
print(ans)

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

void solve()
{
  int ans=0;

  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];

  REP(i,n) {
    while (a[i]%2==0) {
      a[i]/=2;
      ans++;
    }
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 384