akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct DSU {
	int* d, n, *sz;
	ll sub;
	DSU(const int& _n) {
		n = _n;
		d = new int[n + 1];
		sz = new int[n + 1];
		for (int i = 0; i <= n; ++i) {
			d[i] = i;
			sz[i] = 1;
		}
		sub = 0;
	}
	int Get(int u) {
		if (u == d[u]) return u;
		return d[u] = Get(d[u]);
	}
	bool Merge(int u, int v) {
		u = Get(u);
		v = Get(v);
		if (u == v) return false;
		d[u] = v;
		sub -= 1LL * sz[v] * (sz[v] - 1) / 2;
		sub -= 1LL * sz[u] * (sz[u] - 1) / 2;
		sz[v] += sz[u];
		sub += 1LL * sz[v] * (sz[v] - 1) / 2;
		return true;
	}
	int GetSize(int u) {
		u = Get(u);
		return sz[u];
	}
};

const int N = 1e5 + 1;
typedef pair<int, int> ii;
ii edge[N];
int n, m;
ll ans[N];

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i)
		scanf("%d%d", &edge[i].first, &edge[i].second);
	reverse(edge + 1, edge + 1 + m);
	ans[1] = 1LL * n * (n - 1) / 2;
	DSU dsu(n);
	for (int i = 2; i <= m; ++i) {
		dsu.Merge(edge[i - 1].first, edge[i - 1].second);
		ans[i] = ans[1] - dsu.sub;
	}
	reverse(ans + 1, ans + 1 + m);
	for (int i = 1; i <= m; ++i)
      printf("%lld\n", ans[i]);
	return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define int long long

using namespace std;

using ll = long long;
const int MAX_V = 100000;
// const int MAX_V = 6;


struct UnionFind {
    vector<int> par;

    explicit UnionFind(int n) : par(n, -1) { }
    // void init(int n) { par.assign(n, -1); }

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

    bool is_same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    bool unite(int x, int y) {
        int root_x = find_root(x);
        int root_y = find_root(y);
        if (root_x == root_y) return false;
        if (par[root_x] > par[root_y]) swap(root_x, root_y); // unite technique
        par[root_x] += par[root_y];
        par[root_y] = root_x;
        return true;
    }

    ll size(int x) {
        return -par[find_root(x)];
    }
};

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

    int n, m;
    cin >> n >> m;

    UnionFind uf(n + 1);
    int a[m], b[m];
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
    }

    ll res[m];
    memset(res, 0, sizeof(res));

    res[m - 1] = n * (n - 1) / 2;
    for (int i = m - 1; i > 0; --i) {
        if (uf.is_same(a[i], b[i])){
            res[i - 1] = res[i];
        } else {
            res[i - 1] = res[i] - 1LL * uf.size(a[i]) * uf.size(b[i]) ;
        }
        uf.unite(a[i], b[i]);
    }

    for (auto r: res) {
        cout << r << '\n';
    }

    return 0;
}


Measured memory_bytes: 4480
import java.util.Scanner;

public class Main {

    private static int n;
    private static boolean[][] graph;
    private static boolean[] visited;

    private static void dfs(int v) {
        visited[v] = true;
        for (int v2 = 0; v2 < n; v2++) {
            if (!graph[v][v2] || visited[v2]) {
                continue;
            }
            dfs(v2);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[m];
        int[] b = new int[m];
        graph = new boolean[n][n];
        visited = new boolean[n];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            graph[a[i] - 1][b[i] - 1] = true;
            graph[b[i] - 1][a[i] - 1] = true;
        }

        int result = 0;
        for (int i = 0; i < m; i++) {
            graph[a[i] - 1][b[i] - 1] = false;
            graph[b[i] - 1][a[i] - 1] = false;
            for (int j = 0; j < n; j++) {
                visited[j] = false;
            }
            dfs(0);

            boolean bridge = false;
            for (int j = 0; j < n; j++) {
                if (!visited[j]) {
                    bridge = true;
                }
            }
            if (bridge) {
                result += 1;
            }
            graph[a[i] - 1][b[i] - 1] = true;
            graph[b[i] - 1][a[i] - 1] = true;
        }
        System.out.println(result);
    }

}


Measured memory_bytes: 25300
implicit none
integer :: x
integer :: b
integer :: a, z

read *,x

if (x <= 3) then
   print '(i0)',1
   stop
endif

a = 0
do b = 2, int(sqrt(real(x)))
   z = b * b
   if (z > x) then
      exit
   endif
   do while (z <= x)
      if (a < z) a = z
      z = z * b
   enddo
enddo

print '(i0)',a
stop
end  

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

using namespace std;
#define rep(i, l, r) for (int i = l; i<r;i++)
#define dec(i, l, r) for (int i = l; i>=r;i--)
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define pb(c) push_back(c)
#define vii vector<pair<int,int>>
#define ii pair<int,int>
#define max(a, b) (((a)<(b))?b:a)
#define min(a, b) ((a>b)?b:a)
#define mp(i, j) make_pair(i,j)
#define ull unsigned long long int
#define ll  long long int
#define pie 3.141592653589793238
#define inf ((ll)1e18)
#define eps 1e-14
#define mod ((int)1e9+7)
#define maxlg 18
#define maxn 400002
#define left(i) ((i)<<1)
#define right(i) (((i)<<1)+1)
int M[2][maxn][20];
ll A[2][maxn];

ll getMin(int id, int i, int j) {
    int k = log2(j - i + 1);
    if (A[id][M[id][i][k]] < A[id][M[id][j - (1 << k) + 1][k]]) {
        return M[id][i][k];
    } else {
        return M[id][j - (1 << k) + 1][k];
    }
}

bool func(ii a, ii b) {
    return A[a.first & 1][getMin(a.first & 1, a.first, a.second)] <
           A[b.first & 1][getMin(b.first & 1, b.first, b.second)];
}

set<ii, bool(*)(ii, ii)> q(func);

bool func2(ii a, ii b) {
     if (a.first<=b.first && a.second>=b.second) {
         return a.first>b.first;
     } else {
         return A[a.first&1][a.first] <A[b.first&1][b.first];
     }
}
set<ii, bool(*)(ii, ii)>remain(func2);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
 #endif
    int N;
    cin >> N;
    int i, j;
    fill(&A[0][0], &A[0][0] + 2 * maxn, inf);
    rep (i, 0, N) {
        cin >> A[i & 1][i];
    }
    //initialize M for the intervals with length 1
    for (i = 0; i < N; i++)
        M[0][i][0] = i, M[1][i][0] = i;
    //compute values from smaller to bigger intervals
    for (j = 1; 1 << j <= N; j++)
        for (i = 0; i + (1 << j) - 1 < N; i++)
            if (A[0][M[0][i][j - 1]] < A[0][M[0][i + (1 << (j - 1))][j - 1]])
                M[0][i][j] = M[0][i][j - 1];
            else
                M[0][i][j] = M[0][i + (1 << (j - 1))][j - 1];

    for (j = 1; 1 << j <= N; j++)
        for (i = 0; i + (1 << j) - 1 < N; i++)
            if (A[1][M[1][i][j - 1]] < A[1][M[1][i + (1 << (j - 1))][j - 1]])
                M[1][i][j] = M[1][i][j - 1];
            else
                M[1][i][j] = M[1][i + (1 << (j - 1))][j - 1];


    q.insert(mp(0, N - 1));
    queue<ii> stack1;
    while (!q.empty()) {
        int l = q.begin()->first;
        int r = q.begin()->second;


        q.erase(q.begin());
        int L = getMin(l & 1, l, r);
        int R = getMin((l & 1) ^ 1, L + 1, r);
         stack1.push(mp(A[L&1][L],A[R&1][R]));
        if (L - 1 >= l)
            q.insert(mp(l, L - 1));
        if (L+1<=R-1)
        q.insert(mp(L+1, R-1));
        if (r >= R + 1)
            q.insert(mp(R + 1, r));
    }
    while (!stack1.empty()) {
        int l =stack1.front().first;
        int r = stack1.front().second;;
        cout <<l<<" "<<r<<" ";
        stack1.pop();
    }

    return 0;
}
























Measured memory_bytes: 42880
#include <bits/stdc++.h>
using namespace std;
using sint = int64_t;

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

template<class T> vector<T> read_vector(sint n) {
	vector<T> vs;
	for (sint i = 0; i < n; ++i) {
		vs.push_back(read<T>());
	}
	return vs;
}

inline void write() {
}

template<class T> void write(T const& t) {
	cout << t;
}

template<class T> void write(vector<T> const& ts) {
	if (ts.size() > 0) {
		cout << ts[0];
	}
	for (size_t i = 1; i < ts.size(); ++i) {
		cout << ' ' << ts[i];
	}
}

template<class T, class... Args> void write(T const& t, Args const&... args) {
	cout << t << ' ';
	write(args...);
}

template<class... Args> void writeln(Args const&... args) {
	write(args...);
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin .exceptions(ios_base::badbit | ios_base::failbit);
	cout.exceptions(ios_base::badbit | ios_base::failbit);
	cin .tie(nullptr);
	cout.tie(nullptr);
	cout.precision(16);
	void run();
	run();
	return 0;
}

void run() {
	auto const N = read<sint>();
	if (N % 2 != 0) {
		writeln(0);
		return;
	}
	sint n = N / 2;

	sint r = 0;
	sint q = 5;
	while (n / q != 0) {
		r += n / q;
		q *= 5;
	}
	writeln(r);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll n;cin>>n;
    vector<vector<ll>> check(26,vector<ll>(n));
    string ans;
    rep(i,n){
        string s;
        cin>>s;

        rep(j,s.size()){
            check[(ll)(s[j]-'a')][i]++;
        }
    }

    rep(i,26){
        ll sum=INF;
        rep(j,n){
            chmin(sum,check[i][j]);
        }
        rep(j,sum){
            ans.push_back((char)('a'+i));
        }
    }

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

Measured memory_bytes: 3588
R = Array.new(200000)

n = gets.to_i

for i in 0..n-1 do
      R[i] = gets.to_i
end

for i in 1..n-1 do

   if i ==1
	  maxv = R[i] - R[i-1]
	  minv = R[i-1]
   end

   if maxv < R[i] -minv
	  maxv = R[i] - minv
   end

   if  R[i] < minv
	  minv = R[i]
   end

end

puts maxv



Measured memory_bytes: 8444
defmodule Main do
  def main do
    [a, b] =
      IO.read(:line)
      |> String.trim
      |> String.split(" ")
    a = String.to_integer(a)
    b = String.to_integer(b)
    IO.puts(Enum.max([a * b, a + b, a - b]))
  end
end


Measured memory_bytes: 30800
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
    @nums = []
  end

  def main
    a, b = gets.split.map(&:to_i)
    s = gets

    if s[0, a] !~ /\d+/
      puts "No"
      return
    end

    if s[a] != '-'
      puts "No"
      return
    end

    if s[a+1, b] !~ /\d+/
      puts "No"
      return
    end

    puts "Yes"

  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2300
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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 (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int> mp;
    rep(i,n) {
        cin >> a[i];
        mp[a[i]]++;
        if(mp.size()>3){
            cout << "No" << endl;
            return 0;
        }
    }
    if(mp.size()==1) {
        if(mp[0]==n) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    if(n%3!=0){
        cout << "No" << endl;
    }else{
        if(mp.size()==3){
            vector<int> key;
            for(auto p : mp){
                key.push_back(p.first);
                if(p.second!=n/3){
                    cout << "No" << endl;
                    return 0;
                }
            }
            if((key[0]^key[1])!=key[2]){
                cout << "No" << endl;
                return 0;
            }
            cout << "Yes" << endl;
        }else if(mp.size()==2){
            for(auto p: mp){
                if(p.first == 0 && p.second==n/3) continue;
                else if(p.first >0 && p.second==n*2/3) continue;
                else{
                    cout << "No" << endl;
                    return 0;
                }
            }
            cout << "Yes" << endl;
        }       
    }
    
    return 0;
}

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

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		int y, m, d;
		cin >> y >> m >> d;
		int ans = 0;
		if (y % 3) {
			if (m % 2)ans += 21 - d + 19 + ((10 - m) / 2) * 39;
			else ans += 20 - d + ((10 - m) / 2) * 39;
		}
		else ans += 21 - d + (10 - m) * 20;
		ans += (999 - y) * 195 + (999 / 3 - y / 3) * 5;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3112
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
char X[3002];
char Y[3002];

void lcs( char *X, char *Y, int m, int n )
{
int L[m+1][n+1];


for (int i=0;i<=m;i++)
{
	for (int j=0;j<=n;j++)
	{
	if (i==0||j==0)
		L[i][j] = 0;
	else if (X[i-1] == Y[j-1])
		L[i][j]=L[i-1][j-1]+1;
	else
		L[i][j]=max(L[i-1][j],L[i][j-1]);
	}
}


int index = L[m][n];

char lcs[index+1];
lcs[index] = '\0';


int i=m,j=n;
while (i>0&&j>0)
{

	if (X[i-1]==Y[j-1])
	{
		lcs[index-1]=X[i-1];
		i--; j--; index--;
	}

	else if (L[i-1][j]>L[i][j-1])
		i--;
	else
		j--;
}


cout << lcs;
}


int main()
{
cin>>X;
cin>>Y;
int m = strlen(X);
int n = strlen(Y);
lcs(X, Y, m, n);
return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int n,a[100],t;

int main(){
	while(cin>>n&&n){
		rep(i,n)cin>>a[i];
		cin>>t;
		int lb=0,ub=n-1;
		int ans=0;
		while(++ans){
			//cout<<ans<<" "<<a[lb]<<" "<<a[ub]<<" "<<a[(lb+ub)/2]<<endl;
			if(a[(lb+ub)/2]==t){cout<<ans<<endl;break;}
			else if(a[(lb+ub)/2]<t)lb=(lb+ub)/2+1;
			else ub=(lb+ub)/2-1;
			if(lb>ub){cout<<ans<<endl;break;}
		}
	}
}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 1000000007;

typedef long long ll; 
typedef pair<int, int> ii; 
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

// Print fn to print array
int gcd(int a, int b){
	if(a%b==0) return b;
	return gcd(b,a%b);
}

int gcd3(int a, int b, int c){
	return gcd(gcd(a,b),c);
}

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

	vector<long long> R(n,0),G(n,0),B(n,0);
	if(s[0]=='R') R[0]++;
	if(s[0]=='G') G[0]++;
	if(s[0]=='B') B[0]++;
	for(int i=1;i<n;i++){
		if(s[i]=='R') R[i]++;
		if(s[i]=='G') G[i]++;
		if(s[i]=='B') B[i]++;

		R[i]+=R[i-1];
		G[i]+=G[i-1];
		B[i]+=B[i-1];
	}

	long long res = 0;
	for(long long i=0;i<n-2;i++){
		for(long long j=i+1;j<n-1;j++){
			if(s[i]==s[j]) continue;
			else if(s[i]!='R'&&s[j]!='R'){
				res+=(R[n-1]-R[j]);
				if(j+(j-i)<n && s[j+(j-i)]=='R') res--;
			}
			else if(s[i]!='G'&&s[j]!='G'){
				res+=(G[n-1]-G[j]);
				if(j+(j-i)<n && s[j+(j-i)]=='G') res--;
			}
			else if(s[i]!='B'&&s[j]!='B'){
				res+=(B[n-1]-B[j]);
				if(j+(j-i)<n && s[j+(j-i)]=='B') res--;
			}
		}
	}	

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3740
/*
			███╗   ███╗ █████╗ ███████╗███╗   ███╗ ██████╗ ██╗   ██╗██████╗ ███████╗ █████╗ ███╗   ███╗██████╗ ██╗   ██╗
			████╗ ████║██╔══██╗╚════██║████╗ ████║██╔═══██╗██║   ██║██╔══██╗╚════██║██╔══██╗████╗ ████║██╔══██╗╚██╗ ██╔╝
			██╔████╔██║███████║    ██╔╝██╔████╔██║██║   ██║██║   ██║██║  ██║    ██╔╝███████║██╔████╔██║██║  ██║ ╚████╔╝
			██║╚██╔╝██║██╔══██║   ██╔╝ ██║╚██╔╝██║██║   ██║██║   ██║██║  ██║   ██╔╝ ██╔══██║██║╚██╔╝██║██║  ██║  ╚██╔╝
			██║ ╚═╝ ██║██║  ██║   ██║  ██║ ╚═╝ ██║╚██████╔╝╚██████╔╝██████╔╝██╗██║  ██║  ██║██║ ╚═╝ ██║██████╔╝   ██║
			╚═╝     ╚═╝╚═╝  ╚═╝   ╚═╝  ╚═╝     ╚═╝ ╚═════╝  ╚═════╝ ╚═════╝ ╚═╝╚═╝  ╚═╝  ╚═╝╚═╝     ╚═╝╚═════╝    ╚═╝

			“Nobody but you have to believe in your dreams to make them a reality.” ― Germany Kent
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define Ma7moud_7amdy                 \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define Open_Sesame Open()
#define pb push_back
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define sz(v) ((int)((v).size()))
#define clr(arr, x) memset(arr, x, sizeof arr)
#define endl "\n"
#define Accepted 0
#define watch(x) cout << #x << " = " << x << endl;
#define un_map unordered_map
#define RT(x) return cout << (x), 0;
#define sc(a) scanf("%d", &a)
#define scll(x) scanf("%I64d", &x)
#define scan(s) scanf("%[^\n]%*c", &s)
#define pr(s) printf("%s", s.c_str()); // print string
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double EPS = -1e-2;
const int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const ll mod = 1000000007;
const int Mx = INT_MAX;
const int Mn = INT_MIN;
const ll MX = LLONG_MAX;
const ll MN = LLONG_MIN;
const int N = 2e5 + 5;
void Open()
{
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
vector<pair<int, pair<int, int>>>v;
main()
{
	Ma7moud_7amdy;
	//Open_Sesame;
	ll n,a,b;
    cin>>n>>a>>b;
    cout<<n/(a+b)*a+min(n%(a+b),a);
	return Accepted;
}


Measured memory_bytes: 256
import bisect
def find_min_fuka_idx(lst, x):
  ok = -1
  ng = len(lst)
  while abs(ok-ng)>1:
    mid = (ok+ng)//2
    if x>=lst[mid]:
      ok = mid
    else:
      ng = mid
  return ng

a,b,q = map(int, input().split())
s = [-10**18]
s_mid = [int(input()) for i in range(a)]
s.extend(s_mid)
s.append(10**18)

t = [-10**18]
t_mid = [int(input()) for i in range(b)]
t.extend(t_mid)
t.append(10**18)

for i in range(q):
  x = int(input())
  si = bisect.bisect_right(s, x)
  tj = bisect.bisect_right(t, x)
  print(min(abs(x-s[si])+abs(s[si]-t[tj]),\
            abs(x-s[si])+abs(s[si]-t[tj-1]),\
           abs(x-t[tj])+abs(t[tj]-s[si]),\
            abs(x-t[tj])+abs(t[tj]-s[si-1]),\
            abs(x-s[si-1])+abs(s[si-1]-t[tj]),\
            abs(x-s[si-1])+abs(s[si-1]-t[tj-1]),\
           abs(x-t[tj-1])+abs(t[tj-1]-s[si]),\
            abs(x-t[tj-1])+abs(t[tj-1]-s[si-1])))


Measured memory_bytes: 13744
now=0
idx=-1
data=[[],[]]
cnt=0
for s in input():
    if s=='F':
        cnt+=1
    elif s=='T':
        if idx==-1:
            now+=cnt
            cnt=0
            idx=1
        elif idx==0:
            data[0].append(cnt)
            cnt=0
            idx=1
        elif idx==1:
            data[1].append(cnt)
            cnt=0
            idx=0
if idx==-1:
    now+=cnt
else:
    data[idx].append(cnt)
def solve(target,move):
    dp={0,}
    for m in move:
        dpc=dp.copy()
        dp=set()
        for k in dpc:
            dp|={k-m,k+m}
    if target in dp:
        return True
    return False
x,y=map(int,input().split())
x-=now
if solve(x,data[0]) and solve(y,data[1]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 4076
fun solve(line: String): String {
    var (a, b, k) = line.split(" ").map(String::toLong)
    if (k > a) {
        k -= a
        a = 0
    } else {
        a -= k
        k = 0
    }
    if (k > b) {
        b = 0
    } else {
        b -= k
    }
    return "$a $b"
}


fun main(args: Array<String>) {
    println(solve(readLine()!!))
}

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

int main(){
    ll j=0;
    string a,b;
    cin >> a;
    for(int i=a.size();i>0;i--){
        b[j++]=a[i-1];
    }
    rep(i,a.size()){
        if(i==a.size()-1) cout << b[i] << endl;
        else cout << b[i];
    }
    return 0;
}



Measured memory_bytes: 3184
#include <iostream>
#include <string>
#include <algorithm>

int main() {
  int N, M;
  std::string S,T;
  std::cin >> N >> M >> S >> T;

  int g = std::__gcd(N,M);
  int n = N/g, m = M/g;

  for (int i = 0; i < g; ++i) {
    if (S[i*n] != T[i*m]) {
      std::cout << "-1" << std::endl;
      return 0;
    }
  }

  std::cout << (long long) N * M / g  << std::endl; // lcm(N,M)
  return 0;
}


Measured memory_bytes: 512
class Ruiseki_lr:
    """左右からの畳み込みをそれぞれ計算する"""
    def __init__(self, array, op, e):
        self.op = op
        self.e = e

        n = len(array)
        self.left = [e] * (n + 1)
        self.right = [e] * (n + 1)
        for i in range(n):
            self.left[i + 1] = self.op(self.left[i], array[i])
        for i in reversed(range(n)):
            self.right[i] = self.op(self.right[i + 1], array[i])

    def get_left(self, p):
        """区間[0, p)の畳み込み結果を返す"""
        return self.left[p]

    def get_right(self, p):
        """区間[p, n)の畳み込み結果を返す"""
        return self.right[p]

    def fold(self, p):
        """p番目を除いた区間[0, n)の畳み込み結果を返す"""
        return self.op(self.left[p], self.right[p + 1])


n = int(input())
a = list(map(int, input().split()))

memo = {}
for i in range(n):
    if a[i] not in memo:
        memo[a[i]] = []
    memo[a[i]].append(i)

ans = [True] * n
used = set([])
for i in range(n):
    if a[i] in used:
        continue
    used.add(a[i])
    num = a[i]
    if len(memo[num]) >= 2:
        for j in memo[num]:
            ans[j] = False
    num += a[i]
    while num <= 10 ** 6:
        if num in memo:
            for j in memo[num]:
                ans[j] = False
        num += a[i]
res = 0
for i in ans:
    if i:
        res += 1
print(res)
    

Measured memory_bytes: 153460
N,M = map(int,input().split())
Data = []
for _ in range(M):
    a,_ = map(int,input().split())
    keys = list(map(int,input().split()))
    pat = 0
    for k in keys:
        pat += 2**(k-1)
    Data.append([a,pat])

DP = [-1]*(2**N) 
DP[0] = 0
for i in range(2**N):
    if DP[i] == -1:
        continue
    for j in range(M):
        cost  = Data[j][0]
        pat   = Data[j][1]
        t = i | pat
        if DP[t] == -1 or DP[t] > DP[i]+cost:
            DP[t] = DP[i]+cost
print(DP[2**N-1])

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

int main() {
  int a;
  cin >> a;
  if(a / 100 == 7) {
    cout << "Yes" << endl;
  } else if((a = a % 100) / 10 == 7) {
    cout << "Yes" << endl;
  } else if(((a = a % 100) % 10) / 1 == 7) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

set<int> s;
void dfs(int n, int k, int l, int t, int a){
  if(l == n + 1) return;
  if(t == k){
    s.insert(a);
    return;
  }
  for(int i = l + 1; i <= n; i++){
    dfs(n, k, i, t + 1, a + (1 << i - 1));
  }
}
int main(){
  cin.tie(0);
 	ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  if(k == 0){
    cout << "0:\n";
    return 0;
  }
  dfs(n, k, 0, 0, 0);
  for(auto it = s.begin(); it != s.end(); it++){
    cout << *it << ":";
    bitset<18> b(*it);
    for(int i = 0; i < 18; i++){
      if(b[i]){
        cout << " " << i;
      }
    }
    cout << "\n";
  }
  return 0;
}



Measured memory_bytes: 5368
import re
import sys
from itertools import product

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    H = il()
    first = H[0]
    count = 1
    for h in H[1:]:
        if first <= h:
            count += 1
            first = h
    return count


if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 12336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int maxn=0x7fffff;
int main(){
	int n,ma=-1,num;
	cin>>n;
	for(int i=1;i<=n;i++){
		int x=0;
		int nn=i;
		while(nn%2==0){
			nn/=2;
			x++;;
		}
		if(x>ma){
			ma=x;
			num=i;
		}
	}
	cout<<num;
	return 0;
}


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

const int N = 100005;

int n;
int a[N];
long long A[N];

bool check(int pos) {
	for (int i = 1; i <= n; ++i) A[i] = a[i];
	for (int i = 1; i < pos; ++i) A[pos] += A[i];
	for (int i = pos + 1; i <= n; ++i) {
		if (A[pos] * 2 < A[i]) return false;
		A[pos] += A[i];
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	sort(a + 1, a + n + 1);

	int l = 1, r = n;
	while(l < r) {
		int mid = ((l + r) >> 1);
		if (check(mid)) r = mid; else l = mid + 1;
	}

	cout << n - l + 1 << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
const long long INF = 1LL << 60;


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {//降順second
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {//降順first
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd


int main() {
	ll n;
	cin >> n;
	vector<ll> h(n);
	rep(i, n)cin >> h[i];
	ll max = 0;
	ll cnt = 0;
	rep(i, n) {
		if (max <= h[i]) {
			max = h[i];
			cnt++;
		}
	}
	cout << cnt;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long MOD = 1e9 + 7;
long long repow(long long x, long long y){
    if(y == 0) return 1;
    long long res = 1;
    while(y > 0){
        if(y & 1) res = res * x % MOD;
        x = x * x % MOD;
        y >>= 1;
    }
    return res;
}
const int MAX = 1000000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = 1;
    finv[0] = 1;
    inv[0] = 1;
    for(int i = 1; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = repow(i, MOD - 2);
        finv[i] = finv[i -1] * inv[i] % MOD;
    }
}
long long COM(long long n, long long k){
    if(k > n || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n - k] % MOD;
}
int main(){
    COMinit();
    int N, K;
    cin >> N >> K;
    int aka = N - K;
    for(int i = 1; i <= K; i++){
        long long ans = COM(aka + 1, i) * COM(K - 1, i - 1) % MOD;
        cout << ans << endl;
    }
}

Measured memory_bytes: 27044
h,w,k=map(int,input().split())
l=[list(input()) for i in range(h)]
ans=[['0' for i in range(w)] for j in range(h)]
n=0;f=0
for i in range(h):
  f=0
  for j in range(w):
    if l[i][j]=='#':
      f=1
      n+=1
      if ans!='0':
        ans[i][j]=str(n)
    else:
      if f==1:
        if ans[i][j]=='0':
          ans[i][j]=str(n)

for i in range(h):
  for j in range(w-2,-1,-1):
    if ans[i][j]=='0':
      ans[i][j]=ans[i][j+1]

check=['0' for i in range(h)]
ans2=['-1' for i in range(h)]
for i in range(h):
  if ans[i][0]!='0':
    check[i]='#'

f2=0;n2=0
for i in range(h):
  if check[i]=='#':
    f2=1
    n2=i
    ans2[i]=str(i)
  else:
    if f2==1:
      if ans2[i]=='-1':
        ans2[i]=n2

for i in range(h-2,-1,-1):
  if ans2[i]=='-1':
    ans2[i]=ans2[i+1]

for i in range(h):
  print(' '.join(ans[int(ans2[i])]))

Measured memory_bytes: 49264
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

#n,*ta = map(int, read().split())
s = input()
n = len(s)
t = "gp"*((n+2)//2)

ans = 0
for i,j in zip(s,t):
    if i != j:
        if i=="g": ans += 1
        else: ans -= 1

print(ans)

Measured memory_bytes: 9020
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  
  if (A >= B+1){
    cout << A*2 - 1 << endl;
  }
  else if (A+1 <= B){
    cout << B*2-1 << endl;
  }
  else {
    cout << A+B << endl;
  }
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int N;
vector<int> h;

int main(void) {
    cin >> N;
    h.resize(N);
    for (int& t : h) {
        cin >> t;
    }
    vector<ll> dp(N + 1, 0);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    for(int i = 2; i < N; ++i) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 1408
#define DivertaPC2019_D
#ifdef DivertaPC2019_D

#pragma comment (linker, "/STACK:256000000")
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

ll N;
ll ans = 0;

int main() {
    cin >> N;

    if (N == 1) {
        write(0);
        return 0;
    }
    else if (N == 2) {
        write(0);
        return 0;
    }

    ll sqrtN = sqrt(N);
    if ((sqrtN + 1) * (sqrtN + 1) == N) {
        sqrtN++;
    }
    else if ((sqrtN - 1) * (sqrtN - 1) == N) {
        sqrtN--;
    }

    ll lim = sqrtN + 1;
    for (ll k = 1; k < lim; ++k) {
        ll n = N - k;
        if (n % k == 0) {
            ll m = n / k;
            if (k % m != 0) {
                if (N % m == k && N / m == k) {
                    ans += m;
                }
            }
        }
    }

    write(ans);
}

#endif

Measured memory_bytes: 256
import sys
import itertools
def solve(x,n,s):
    t=[c for c in itertools.combinations(x,n) if sum(c)==s]
    return len(t)

x=[i for i in range(10)]
for line in sys.stdin.readlines():
    n,s=map(int, line.rstrip().split())
    if s|n==0: break
    print solve(x,n,s)

Measured memory_bytes: 4356
#include<iostream>
#include<string>
#include <bits/stdc++.h>
#include<vector>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
  int n;
  cin >> n;
  if(1<=n && n<=9){
    if(n==2 || n==4 || n==5 || n==7 || n==9){
      cout << "hon" <<endl;
    }else if(n==0 || n==1 || n==6 || n==8){
      cout << "pon" << endl;
    }else{
      cout << "bon" << endl;
    }
  }else if(n>=10 && n<=99){
    n=n%10;
    if(n==2 || n==4 || n==5 || n==7 || n==9){
      cout << "hon" <<endl;
    }else if(n==0 || n==1 || n==6 || n==8){
      cout << "pon" << endl;
    }else{
      cout << "bon" << endl;
    }
  }else{
    n=n%100;
    n=n%10;
    if(n==2 || n==4 || n==5 || n==7 || n==9){
      cout << "hon" <<endl;
    }else if(n==0 || n==1 || n==6 || n==8){
      cout << "pon" << endl;
    }else{
      cout << "bon" << endl;
    }
  }

}


Measured memory_bytes: 3636
# C - Many Requirements
from typing import List, Tuple

N: int
M: int
conditions: Tuple[Tuple[int, int, int, int]]


def rec(seq: List[int]):
    if len(seq) == N + 1:
        return sum(d for a, b, c, d in conditions if seq[b] - seq[a] == c)
    return max(rec(seq + [i]) for i in range(seq[-1], M + 1))


def main():
    global N, M, conditions
    N, M, Q, *ABCD = map(int, open(0).read().split())
    conditions = tuple(zip(*[iter(ABCD)] * 4))
    print(rec([1]))


if __name__ == "__main__":
    main()


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

int main(){
    vector<long long int> luka(87);
    luka[0] = 2;
    luka[1] = 1;
    for(int i=2; i<=86; i++){
        luka[i] = luka[i-1] +luka[i-2];
    }
    int n;
    cin >> n;
    cout << luka[n] << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	n := readInt()
	_ = readInt()

	a := make([]int, n)
	for i := range a {
		a[i] = readInt()
	}

	maxa := make([]int, n)
	maxa[n-1] = a[n-1]
	for i := n - 2; i >= 0; i-- {
		maxa[i] = maxInt(maxa[i+1], a[i])
	}

	maxv := maxa[0] - a[0]
	count := 1
	for i := 1; i < n; i++ {
		d := maxa[i] - a[i]
		if maxv <= d {
			if maxv < d {
				count = 0
			}
			maxv = d
			count++
		}
	}
	println(count)
}


Measured memory_bytes: 3840
import numpy as np
n = int(input())
s = np.array(list(map(int, input())))
res = 0
seen0 = set()
for i, ss in enumerate(s):
    if ss in seen0:
        continue
    seen0.add(ss)
    part = s[i+1:]
    seen1 = set()
    comp_mat = np.full((10, 10), False)
    for j, t in enumerate(part):
        if t in seen1:
            continue
        seen1.add(t)
        part1 = part[j+1:]
        seen2 = set()
        for k, u in enumerate(part1):
            if u in seen2:
                continue
            seen2.add(u)
            comp_mat[t, u] = True
    res += comp_mat.sum()
print(int(res))


Measured memory_bytes: 21668
#include <cstdio>


int main(){
	unsigned n,m;
	unsigned A[100][100];
	unsigned B[100];
	unsigned C[100];

	for(auto &v : C){
			v = 0;
	}

	scanf("%u%u",&n,&m);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf("%u",&A[i][j]);
		}
	}

	for(int i=0;i<m;i++){
			scanf("%u",&B[i]);
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			C[i] += A[i][j]*B[j];
		}
	}

	for(int i=0;i<n;i++){
		printf("%u\n",C[i]);
	}
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;

int main(){
  string s; cin >> s;
  long long head[s.size()+1] = {};
  long long back[s.size()+1] = {};
  int tmp = 0;
  rep(i,s.size()){
    if(s.at(i) == '<') tmp++;
    else tmp = 0;
    head[i+1] = tmp;
  }
  tmp = 0;
  for(int i = s.size()-1; i>=0;i--){
    if(s.at(i) == '>') tmp++;
    else tmp = 0;
    back[i] = tmp;
  }
  long long ans = 0;
  rep(i,s.size()+1){
    ans += max(head[i],back[i]);
    // cout << head[i] << " "<< back[i] << "\n";
  }
  cout << ans << "\n";
}

Measured memory_bytes: 8708
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  vector<string> blue(N);
  for (int i=0; i<N; i++) cin >> blue[i];
  int M; cin >> M;
  vector<string>red(M);
  for (int i=0; i<M; i++) cin >> red[i];
  
  map<string,int>mp;
  for (int i=0; i<N; i++) mp[blue[i]]++;
  for (int i=0; i<M; i++) mp[red[i]]--;
  
  int ans=0;
  for (int i=0; i<N; i++){
    ans = max(ans, mp[blue[i]]);
  }
  cout << ans << endl;
}

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

int main(){
	// sengen
	int n;
	string s;
	int ans = 0;
	// nyuryoku
	cin >> n >> s;
	// keisan
	for(int i=0;i<n-2;i++){
		if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
	}
	// syutsuryoku
	cout << ans;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

const int MAX = 1e5+10;
const ll INF = 1e18;

int N;
ll S[MAX];

ll solve() {
    ll ret = -INF;
    FOR (c, 1, N) {
        ll f = 0;
        REP (n, N/c) {
            f += S[n*c] + S[N-1-n*c];
            if (n*c == N-1 - n*c || n*c == N-1 - (n-1)*c) f = -INF;
            CHMAX(ret, f);
        }
    }
    return ret;
}

int main() {
    cin >> N;
    REP (i, N) cin >> S[i];
    cout << solve() << endl;
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21684
import java.text.DecimalFormat;
import java.util.*;

public class Main {
    public static void main(String[] args)  throws java.io.IOException{
        Scanner sc = new Scanner(System.in);
        while(true) {
            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();
            if(op.equals("?")){
                break;
            }else if (op.equals("+")){
                System.out.println(a + b);
            }else if (op.equals("-")){
                System.out.println(a - b);
            }else if (op.equals("*")) {
                System.out.println(a * b);
            }else if(op.equals("/")) {
                    System.out.println(a / b);
            }
        }
        sc.close();
    }
}

Measured memory_bytes: 17196
n = input()
n = n[-1]

if n[-1] == '2' or n[-1] == '4' or n[-1] == '5' or n[-1] == '7' or n[-1] == '9':
  print('hon')
elif n[-1] == '0' or n[-1] == '1' or n[-1] == '6' or n[-1] == '8':
  print('pon')
else:
  print('bon')

Measured memory_bytes: 9124
#include <iostream>

using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

constexpr ll MOD = 1000000007;

ll powmod(ll a, ll p)
{
	a %= MOD;

	ll result = 1;
	while(p) 
	{
		if(p&1)
			result = (result * a) % MOD;

		a = (a * a) % MOD;
		p >>= 1;
	}
	return result;
}

void solve()
{
	ll n; cin >> n;

	ll total = powmod(10, n);
	ll r = powmod(8, n);
	ll pr = powmod(9, n);

	ll ans = total - pr - pr + r;
	ans %= MOD;
	ans = (ans + MOD) % MOD;
	cout << ans << '\n';
}

int main()
{
#ifndef ONLINE_JUDGE
   freopen("input.txt", "rt", stdin);
   freopen("output.txt", "wt", stdout);
#endif

   	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}



int main() {
  int X;
  cin >> X;
  
  while(X>0){
    if(IsPrime(X)) break;
    else X++;
  }
  
  cout << X << endl;
  
}


Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>

int A[2000000], B[2000000];

void CountingSort(int A[], int B[], int n, int k){
	int i, j;
	int C[k+1];
	for( i = 0; i < k+1; i++ ){ C[i] = 0; }
	for( j = 0; j < n; j++ ){ C[A[j]]++; }
	for( i = 1; i < k+1; i++ ){ C[i] = C[i] + C[i-1]; }
	for( j = n-1; j >= 0; j-- ){
		B[C[A[j]]-1] = A[j];
		C[A[j]]--;
	}
	return;
}

int main(){
	int n, max = INT_MIN, i;
	scanf("%d", &n);
	for( i = 0; i < n; i++ ){
		scanf("%d", &A[i]);
		if( A[i] > max ){ max = A[i]; }
	}
	CountingSort(A, B, n, max);
	printf("%d", B[0]);
	for( i = 1; i < n; i++ ){ printf(" %d", B[i]); }
	printf("\n");
	return 0;
}

Measured memory_bytes: 16264
import math 
import sys
from functools import reduce

N = int(input())
A = list(map(int, input().split()))
A.sort()

def gcd_list(numbers):
  return reduce(math.gcd, numbers)

if gcd_list(A) > 1:
  print("not coprime")
  sys.exit()
  
union = set()
intersection = set()

visited = set()
A_set = set()

flag = False
MAX = 10**6
lim = math.ceil(math.sqrt(MAX))
for a in A:
  #print(visited, a)
  if a in visited: 
    print("setwise coprime")
    sys.exit()
    flag = True 
    break
  b = a
  p = 2
  while p <= lim and b > 1:
    if p in visited: 
      p += 1
      continue
    if b % p == 0:
      q = p
      for q in range(p,MAX+1,p): #pの倍数を全てvisitedへ
        visited.add(q)     
    while b % p == 0:
      b = b // p
    p += 1
  if b > 1:
    q = b
    p = b
    for q in range(p,MAX+1,p): #pの倍数を全てvisitedへ
      visited.add(q) 
      
      

print("pairwise coprime")



"""
def raise_prime(B):
  n = len(B)
  if n == 1:
    
  C = B[0: n//2]
  D = B[n//2:n]
"""


  
  
"""
for a in A:
  p = 2
  while p <= N:
    if p not in visited:
      
      
    
  
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    union.add()
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
"""
  

  
  

Measured memory_bytes: 197696
n = gets.to_i
a = gets.split.map(&:to_i)
sum = a.inject(:+)
t = sum/(n*(n+1)/2)
s = 0
if t*n*(n+1)/2 != sum
    puts "NO"
    exit
end
for i in 0..n-1
    if a[i]-a[i-1]-t > 0 || (a[i]-a[i-1]-t)%n != 0
        puts "NO"
        exit
    end
    s -= (a[i]-a[i-1]-t)/n
end
if t == s
    puts "YES"
else
    puts "NO"
end

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a==1) a = 14;
    if(b==1) b = 14;

    if(a > b) cout << "Alice" << endl;
    else if(b > a) cout << "Bob" << endl;
    else cout << "Draw" << endl;
}

Measured memory_bytes: 3632
n, a, b = map(int, input().split())
if (a-b)%2 == 0:
    print(abs(a-b)//2)
else:
    c, d = max([a, b]), min([a, b])
    if min([d-1, n-c]) == d-1:
        k = d-1
        c = c-k+1
        print(k+abs(c-1)//2)
    else:
        k = n-c
        d = d+k-1
        print(k+abs(n-d)//2)
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int K, X;
  cin >> K >> X;
  if (K * 500 >= X) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

 class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int count = 0 ;
		for(int i = 1 ; i <= n ; i++) {
			String s = Integer.toString(i);
			if(s.length() % 2 != 0) {
				count++;
			}else {
				i = (i*10)-1 ;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 28472