akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;


int main()
{
    int N, M;
    cin >> N >> M;
    
    vector<pair<int,int>> war(M);
    for( int i = 0; i < M; ++i ){
        int a, b;
        cin >> a >> b;
        war[i] = make_pair( b, a );
    }


    sort( war.begin(), war.end() );
    int ans = 1;
    int removedBridge = war[0].first-1;
    
    for( int i = 1; i < M; ++i ){
        if( war[i].second <= removedBridge ) continue;
        else{
            removedBridge = war[i].first-1;
            ++ans;
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> P;
const int MAX_V=100000;
vector<int> G[MAX_V];
int ord[MAX_V];
bool inS[MAX_V];
stack<int> roots,S;
vector<vi> cc;
vector<P> bs;
int cnt;
int N,M;
void vis(int v,int p){
	ord[v]=++cnt;
	S.push(v);
	inS[v]=1;
	roots.push(v);
	for(int u:G[v]){
		if(ord[u]==0){
			vis(u,v);
		}else if(u!=p&&inS[u]){
			while(ord[roots.top()]>ord[u]) roots.pop();
		}
	}
	if(v==roots.top()){
		bs.pb(P(p,v));
		vector<int> vc;
		while(true){
			int w=S.top();S.pop();
			inS[w]=0;
			vc.pb(w);
			if(v==w) break;
		}
		roots.pop();
		cc.pb(vc);
	}
}
void bridge(){
	rep(i,N) if(ord[i]==0){
		vis(i,-1);
		bs.pop_back();
	}
}
int main(){
	cin>>N>>M;
	rep(i,M){
		int a,b;
		cin>>a>>b;
		G[a].pb(b);
		G[b].pb(a);
	}
	bridge();
	for(P& p:bs) if(p.fs>p.sc) swap(p.fs,p.sc);
	sort(all(bs));
	for(P p:bs){
		cout<<p.fs<<" "<<p.sc<<endl;
	}
}

Measured memory_bytes: 5316
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#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 ALL(a) (a).begin(), (a).end()

bool used[200000];
vector<int> G[200000];
vector<pii> ds;

void dfs(int v, int d) {
    used[v] = true;

    bool term = true;
    for (auto u : G[v]) {
        if (!used[u]) {
            term = false;
            dfs(u, d + 1);
        }
    }
    if (term) ds.push_back({d, v});
}

int main() {
    int N, a, b;
    cin >> N;
    REP(i, N - 1) {
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }
    dfs(0, 0);
    sort(ALL(ds));
    int s = ds[ds.size() - 1].second;
    ds = vector<pii>();
    REP(i, N) used[i] = false;
    dfs(s, 0);
    sort(ALL(ds));
    s = ds[ds.size() - 1].first;
    if (s % 3 == 1) cout << "Second" << endl;
    else cout << "First" << endl;
    return 0;
}

Measured memory_bytes: 23936
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>

using namespace std;

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

int str_int(string v){
	int a=0;
	REP(i, v.size()){
		if(v[0]=='-'){
			if(!i)continue;
			else a = a*10 - (v[i]-'0');
		}
		else a = a*10 + (v[i]-'0');
	}
	return a;
}

int main(){
	int n, a, b, fx;
	string ins, sta;
	int ans, head, tail;
	while(1){
		cin >> n;
		if(!n) break;
		head = 2000000000;
		tail = -2000000000;
		b = 2000000001;
		fx = 0;
		sta = "ambiguous";
		REP(i,n){
			cin >> ins;
			if(!fx){
				if(ins[0] == 'x'){
					fx = 1;
					if(i%2==0){
						if(b-1<head)head = b-1;
						b = head;
					}
					else if(i%2==1){
						if(b+1>tail) tail = b+1;
						b = tail;
					}
				}
				else{
					fx=0;
					a = str_int(ins);
					if(i%2==0&&a>=b) sta = "none";
					if(i%2==1&&a<=b) sta = "none";
					b = a;
				}
			}
			else{
				if(ins[0] == 'x'){
					fx=1;
					sta = "none";
				}
				else{
					fx=0;
					a = str_int(ins);
					if(i%2==0&&a>=tail) tail = a+1;
					if(i%2==1&&a<=head) head = a-1;
					b = a;
				}
			}
			//cout << head << "~" << tail  << ":" << sta << endl;
		}
		//cout << head << " " << tail << " ";
		if(sta == "none") cout << sta << endl;
		else{
			if(head == tail) cout << head << endl;
			else if(head < tail) cout << "none" << endl;
			else cout << sta << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1216
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  string s;
  cin >> s;
  Pr(s[2] == s[3] && s[4] == s[5]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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; }
#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<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

int main(){
  string s;cin>>s;
  if(s=="Sunny")cout<<"Cloudy"<<endl;
  else if(s=="Cloudy")cout<<"Rainy"<<endl;
  else cout<<"Sunny"<<endl;
}


Measured memory_bytes: 256
N, X = map(int, input().split())
L = list(map(int,input().split()))
a = 0
count = 1
for i in range(N) :
    a += L[i]
    if a <= X :
        count += 1
        if i == N-1 :
            print(count)
    else :
        print(count)
        break

Measured memory_bytes: 3060
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        Console.WriteLine("CODEFESTIVAL2016".Zip(Reader.String(), (a, b) => a != b).Count(b => b));
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    static string[] Split(string s) { return s.Split(separator, op); }
    static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 2776
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define fo(n) for(int i = 0;i < int(n);i++)
#define foo(a,b) for(int i = int(a);i <= int(b);i++)
#define mk make_pair
#define pb push_back
#define MAXN (int)1e6
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define fastio ios_base:: sync_with_stdio(false)
#define inf (int)1e9

int main(){

	
	fastio;
	int n;
	cin >> n;

	vi arr(n);
	fo(n) cin >> arr[i];

	vi sum(n);

	sum[0] = arr[0];
	for(int i = 1;i < n;i++) sum[i] = sum[i-1] + arr[i];

	int ans = inf;

	for(int i = 0;i < n-1;i++){
		int s1 = sum[i];
		int s2 = sum[n-1]-sum[i];

		ans = min(ans, abs(s1-s2));
	}

	cout << ans << endl;

	return 0;
 }	

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

int main(){
    int n,m=0,cnt=0;
    cin>>n;

    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a.at(i);
        if(a.at(i)>=m){
            m=a.at(i);
            cnt=i;
        }
    }

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

    for(int i=0; i<n; i++){
        if(i==cnt) cout<<a.at(n-2)<<endl;
        else cout<<a.at(n-1)<<endl;
    }


}


Measured memory_bytes: 2432
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		V[] vs = new V[N];
		for (int i = 0; i < N; i++) {
			vs[i] = new V(i);
		}
		for (int i = 0; i < M; i++) {
			int s = sc.nextInt() - 1;
			int t = sc.nextInt() - 1;
			vs[s].add(t);
			vs[t].add(s);
		}
		int Q = sc.nextInt();
		int v[] = new int[Q];
		int d[] = new int[Q];
		int c[] = new int[Q];
		for (int i = 0; i < Q; i++) {
			v[i] = sc.nextInt() - 1;
			d[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		dist = new int[N];
		Arrays.fill(dist, -1);
		for (int i = Q - 1; i >= 0; i--) {
			color(vs, v[i], d[i], c[i]);
		}
		Arrays.stream(vs).forEach(u -> System.out.println(u.col));
	}
	static int dist[];
	private static void color(V[] vs, int s, int d, int c) {
		if (dist[s] >= d) {
			return;
		}
		Queue<Integer> que = new LinkedList<>();
		que.add(s);
		dist[s] = d;
		while(que.isEmpty() == false) {
			int u = que.poll();
			if (vs[u].col == 0) { 
				vs[u].col = c;
			}
			if (dist[u] == 0) {
				continue;
			}
			for (int v: vs[u]) {
				if (dist[v] >= dist[u] - 1) {
					continue;
				}
				que.add(v);
				dist[v] = dist[u] - 1;
			}
		}
	}
	static class V extends ArrayList<Integer>{
		int id;
		int col = 0;
		V(int _id) {
			id = _id;
		}
	}
}


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

int main() {
  int n;
  cin >> n;
  vector<long long> cd(n);
  for (int i = 0; i < n; i++) cin >> cd[i];

  long long p = 0, c = 0;
  for (int i = 0; i < n; i++) {
    c += cd[i];
    if (cd[i] == 0 || i+1 == n) {
      p += c / 2;
      c = 0;
    }
  }
  cout << p << endl;
  return 0;
}


Measured memory_bytes: 1152
import java.util.*;
import java.io.PrintWriter;
public class Main{
	static long mod=1000000007;
	static long[] fact;
	static long[] inv;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int r1=sc.nextInt();
		int c1=sc.nextInt();
		int r2=sc.nextInt();
		int c2=sc.nextInt();
		long ans=0;
		fact=new long[c2+r2+2];
		fact[1]=1;
		for(int i=2; i<=c2+r2+1; i++){
			fact[i]=(fact[i-1]*i)%mod;
		}
		inv=new long[c2+r2+2];
		inv[c2+r2+1]=pow(fact[c2+r2+1],mod-2);
		for(int i=c2+r2; i>=0; i--){
			inv[i]=(inv[i+1]*(i+1))%mod;
		}
		for(int i=c1; i<=c2; i++){
			ans+=comb(i+r2+1,i+1)-comb(i+r1,i+1)+mod;
			ans%=mod;
		}
		System.out.println(ans);
	}
	static long comb(int t,int y){
		long re=1;
		re*=fact[t];
		re*=inv[y];
		re%=mod;
		re*=inv[t-y];
		return re%mod;
	}
	
	static long pow(long p,long q){
		long res=1;
		while(q>0){
			if((q & 1)==1){
				res*=p;
				res%=mod;
			}
			q>>=1;
			p*=p;
			p%=mod;
		}
		return res;
	}
}


Measured memory_bytes: 53588
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

#define N 51
ll n,x;
ll ans=0;
ll mai[N];
ll pat[N];
void dfs(ll pos,ll level){
    if(level==0){
        if(pos>=x)return;
        pos++;
        ans++;
        return;
    }
    
    pos++;
    if(pos>=x)return;
    if(pos+mai[level-1]>=x){
        dfs(pos,level-1);
        return;
    }
    pos+=mai[level-1];
    ans+=pat[level-1];
    if(pos>=x)return;
    pos++;
    ans++;
    if(pos>=x)return;
    if(pos+mai[level-1]>=x){
        dfs(pos,level-1);
        return;
    }
    pos+=mai[level-1];
    ans+=pat[level-1];
    return;
}
int main(){fastio
    cin>>n>>x;
    mai[0]=1;
    pat[0]=1;
    rep(i,1,N-1){
        mai[i]=mai[i-1]*2+3;
        pat[i]=pat[i-1]*2+1;
    }
    dfs(0,n);
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import sys
from itertools import combinations
#DEBUG = True
DEBUG = False
if DEBUG:
    f=open("202007_1st/C_input.txt")
else:
    f=sys.stdin
WHITE='.'
BLACK='#'
def count_black(H_index,W_index):
    count_tmp=0
    for _ in range(H):
        if _ in H_index:
            continue
        for __ in range(W):
            if __ in W_index:
                continue
            if S[_][__]==BLACK:
                count_tmp+=1
    return count_tmp
ans=0
H,W,K=map(int,f.readline().split())
S=[f.readline().strip() for _ in range(H)]
H_indices=[_ for _ in range(0,H)]
W_indices=[_ for _ in range(0,W)]
combi_list_H=[[-1]]
combi_list_W=[[-1]]
for _ in range(1,H):
    combi_list_H.extend(list(combinations(H_indices,_)))
for _ in range(1,W):
    combi_list_W.extend(list(combinations(W_indices,_)))
for _ in combi_list_H:
    for __ in combi_list_W:
        if count_black(_,__)==K:
            ans+=1
print(ans)
f.close()

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

signed main() {
#ifdef LOCAL
  assert(freopen("d.in", "r", stdin));
#endif
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> p(n + 1);
  vector<int> pos(n + 1);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    --p[i];
    pos[p[i]] = i;
  }
  p[n] = pos[n] = n;
  vector<ll> d(n + 1);
  for (int i = 0; i < n + 1; ++i) {
    d[i] = 1e18;
    ll cost = 0;
    for (int j = i - 1; j >= 0; --j) {
      if (pos[j] < pos[i]) {
        d[i] = min(d[i], d[j] + cost);
        cost += a;
      } else {
        cost += b;
      }
    }
    d[i] = min(d[i], cost);
  }
  cout << d[n] << '\n';
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
typedef long long int lli;
typedef pair<lli, lli> pii;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli solve(string s, int n, int k)
{
	lli c1 = 1;
	lli c2 = 1;
	for(lli i=1; i<n; i++)
	{
		if(s[0] == s[i])
			c1++;
		else
			break;			
	}
	for(lli i=n-2; i>=0; i--)
	{
		if(s[n-1] == s[i])
			c2++;
		else
			break;			
	}
//	cout<<c1<<" "<<c2<<"\n";
	lli ans = c1/2 + c2/2;
	lli count = 0;
	for(lli i=c1; i<(n-c2); i++)
	{
		if(s[i] != s[i-1])
			continue;
		else
		{
			s[i] = '.';
			count++;
		}
	}
	ans = count*k + ans*k;
	return ans;
}
int main()
{
	fastio;
	string s;
	lli k;
	cin>>s>>k;
	lli n = s.length();
	unordered_map<char, bool> mp;
	for(lli i=0; i<n; i++)
		mp[s[i]] = true;
	lli c = mp.size();
	if(n == 1)
	{
		cout<<k/2<<"\n";
	}
	else if(c == 1)
	{
		if(n%2 == 0)
			cout<<k * (n/2)<<"\n";
		else
			cout<<((k*n)/2)<<"\n";
	}
	else if(s[0] != s[n-1])
	{
		lli count = 0;
		for(lli i=1; i<n; i++)
		{
			if(s[i] != s[i-1])
				continue;
			else
			{
				s[i] = '.';
				count++;
			}
		}
		cout<<k*count<<"\n";
	}
	else
	{
		lli c1 = 1;
		lli c2 = 1;
		for(lli i=1; i<n; i++)
		{
			if(s[0] == s[i])
				c1++;
			else
				break;			
		}
		for(lli i=n-2; i>=0; i--)
		{
			if(s[n-1] == s[i])
				c2++;
			else
				break;			
		}
		if(c1%2 == 0 && c2%2 == 0) // even even
		{
			lli ans = 0;
			ans += c1/2 + c2/2;
			lli count = 0;
			for(lli i=c1; i<(n-c2); i++)
			{
				if(s[i] != s[i-1])
					continue;
				else
				{
					s[i] = '.';
					count++;
				}
			}
			ans += count*k + ans*k;
			cout<<ans<<"\n";
		}
		else if(c1%2 == 0 && c2%2 == 1) // even odd 
		{
			reverse(s.begin(), s.end());
			cout<<solve(s, n, k)<<"\n";
		}
		else if(c1%2 == 1 && c2%2 == 0) // odd even
		{
			cout<<solve(s, n, k)<<"\n";
		} 
		else
		{
			s[0] = '.';
			lli count = 0;
			for(lli i=1; i<n; i++)
			{
				if(s[i] != s[i-1])
					continue;
				else
				{
					s[i] = '.';
					count++;
				}
			}
			lli ans = k*count + k-1;
			cout<<ans<<"\n";
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
typedef long long LL;
int main()
{
	int a[1005];
	int N;
	cin >> N;
	for (int i = 0;i < N;i++)
		cin >> a[i];
	int cnt = 0;
	for (int i = 0;i < N;i += 2)
	{
		if (a[i] % 2 == 1)
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3160
#!/usr/bin/env python3
# coding: UTF-8
import math

def dist1(data1, data2):
    leng = 0
    for a, b in zip(data1, data2):
        leng += abs(a-b)

    return leng

def dist2(data1, data2):
    leng = 0
    for a,b in zip(data1, data2):
        leng += abs(a-b)**2.0
    
    return (math.sqrt(leng))

def distn(data1, data2, n):
    leng = 0
    for a,b in zip(data1, data2):
        leng += abs(a-b) ** n

    return (pow(leng, 1/n))

def distlm(data1, data2):
    leng = 0
    for a,b in zip(data1, data2):
        ab = abs(a-b)
        leng = leng if leng > ab else ab
    return leng

leng = input()
datax =list(map(float, input().split()))
datay =list(map(float, input().split()))

print ( distn(datax, datay, 1))
print ( distn(datax, datay, 2))
print ( distn(datax, datay, 3))
print ( distlm(datax, datay))




Measured memory_bytes: 5708
package main

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

func dummy() {
	math.Abs(1.0)
}

/************I/O***********/

var (
	// ReadString returns a WORD string.
	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))
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

// ReadInt returns an integer.
func readInt() int {
	return int(readInt64())
}

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

// ReadIntSlice returns an integer slice that has n integers.
func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

// ReadFloat64 returns an float64.
func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func readRuneSlice() []rune {
	return []rune(readString())
}

/*********math********/
func mod(val int, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func minInt(val ...int) int {
	res := val[0]
	for i := 1; i < len(val); i++ {
		if res > val[i] {
			res = val[i]
		}
	}
	return res
}
func maxInt(val ...int) int {
	res := val[0]
	for i := 1; i < len(val); i++ {
		if res < val[i] {
			res = val[i]
		}
	}
	return res
}

const MOD = 1000000007

func c(a int, b int) int {
	if a < 0 || b < 0 {
		return 0
	}

	res := 1
	for i := 0; i < b; i++ {
		res *= a - i
	}
	for i := 0; i < b; i++ {
		res = res / (i + 1)
	}
	return res
}

func main() {

	N := readInt()
	a := make([]int, N)
	b := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = readInt()
		b[i] = a[i]
	}
	sort.Ints(a)

	max := a[N-1]
	next_max := a[N-2]

	for i := 0; i < N; i++ {
		if b[i] == max {
			fmt.Println(next_max)
		} else {
			fmt.Println(max)
		}

	}

}


Measured memory_bytes: 7680
<?php
/*
    Problem URL : http://arc075.contest.atcoder.jp/tasks/arc075_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

ini_set('error_reporting', E_ALL & ~E_NOTICE);

$arr = array();

fscanf(STDIN, "%d", $N);

for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d", $arr[$i]);
}

sort($arr);
$ans = array_sum($arr);
// echo $ans . PHP_EOL;
// exit;

if ($ans % 10 != 0) {
    echo $ans . PHP_EOL;
    exit;
} 

for ($i = 0; $i < $N; $i++) {
    for ($j = $i; $j < $N; $j++) {
        $tmp = $ans - $arr[$j];
        if ($tmp % 10 != 0) {
            echo $tmp . PHP_EOL;
            exit;
        }
    }
    $ans -= $arr[$i];
}

echo $ans . PHP_EOL;


Measured memory_bytes: 4856
a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))

n = int(input())
b = []
for _ in range(n):
    _b = int(input())
    b.append(_b)
    for i in range(3):
        for j in range(3):
            if a[i][j] == _b:
                a[i][j] = 0

if a[0][0] == a[1][0] == a[2][0] == 0 or a[0][1] == a[1][1] == a[2][1] == 0 or a[0][2] == a[1][2] == a[2][2] == 0 or a[0][0] == a[1][1] == a[2][2] == 0 or a[0][2] == a[1][1] == a[2][0] == 0 or a[0][0] == a[0][1] == a[0][2] == 0 or a[1][0] == a[1][1] == a[1][2] == 0 or a[2][0] == a[2][1] == a[2][2] == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
using System;

namespace abc99_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int Number = int.Parse(Console.ReadLine());
            if (Number < 1000)
            {
                Console.WriteLine("ABC");
            }
            else
            {
                Console.WriteLine("ABD");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)

int main(){
  int n;cin>>n;
  int m;cin>>m;
  int a,minx=1e4;
  fol(i,n){
    cin>>a;
    m-=a;
    minx=min(a,minx);
  }
  cout << n+(m/minx)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const ll INF = 1e18L + 5;
const int siz = 1e5 + 5;
vector <ll> edges[siz];
vector <ll> in_degree(siz);
int dist[siz];
bool vis[siz];
void solve();
ll mod = 1e9+7;
void solve()
{
	int h, w;
	cin >> h >> w;
	char block[h][w];
	
	for(int i= 0; i<h; i++)
			cin >> block[i];
			
	int dp[h][w];

	memset(dp, 0, sizeof dp);
	dp[0][0] = 1;
		
	for(int i = 0; i<h; i++)
	{
		for(int j = 0; j<w; j++)
		{
			if(i-1>=0 && block[i][j] == '.')
				dp[i][j] = (dp[i-1][j] + dp[i][j])%mod;
			if(j-1>=0 && block[i][j] == '.')
				dp[i][j] = (dp[i][j-1] + dp[i][j])%mod;
		}
	}
	cout << dp[h-1][w-1] << endl;
	
}

int main()
{
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		ll t = 1;
	//	cin >> t
		while(t--)
		{
			solve();
		}
	return 0;
}
	


Measured memory_bytes: 8320
A,B,C,X = [int(input()) for i in range(4)]
ans = 0
for i_500 in range(A+1):
    for i_100 in range(B+1):
        resid = X - i_500 * 500 - i_100 * 100
        if resid >= 0:
            q,mod = divmod(resid,50)
            if C >= q and mod == 0:
                ans += 1

print(ans)

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

int main(){
  int N, M, X; cin >> N >> M >> X;
  vector<int> A(M);
  int S = 0;
  
  for(int i=0; i<M; i++){
    cin >> A[i];
  }
  
  for(int i=0; i<M; i++){
    if(A[i] > X){
      S++;
    }
  }
  
  cout << min(S, M-S) << endl;
}


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

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int lcm(int a, int b) { return a * (b / gcd(a, b)); }

class DSemiCommonMultiple {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, M;
        cin >> N >> M;
        vector<int> a(N);
        REP(i, N) {
            cin >> a[i];
            a[i] /= 2;
        }

        int num = 0;
        int c = a[0];
        while (c % 2 == 0) {
            c /= 2;
            num++;
        }
        REP(i, N) {
            int tmp = 0;
            int c = a[i];
            while (c % 2 == 0) {
                c /= 2;
                tmp++;
            }
            if (num != tmp) {
                cout << 0 << endl;
                return;
            }
        }

        int l = a[0];
        REP(i, N) {
            l = lcm(l, a[i]);
            if (l > M) {
                cout << 0 << endl;
                return;
            }
        }

        cout << (M + l) / (2 * l) << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DSemiCommonMultiple solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i,a,b)  for(int i=(a);i<(b);i++)
#define REP(i,n)    FOR(i,0,n)
#define ALL(a)      a.begin(),a.end()
#define vi          vector<int>
#define vvi         vector<vi>
#define P           pair<int,int>
 
int main(){
    int a,b,c,d;
    {
        string s;cin>>s;
        a=s[0]-'0';
        b=s[1]-'0';
        c=s[2]-'0';
        d=s[3]-'0';
    }
    if      (a+b+c+d==7)printf("%d+%d+%d+%d=7",a,b,c,d);
    else if (a+b+c-d==7)printf("%d+%d+%d-%d=7",a,b,c,d);
    else if (a+b-c+d==7)printf("%d+%d-%d+%d=7",a,b,c,d);
    else if (a+b-c-d==7)printf("%d+%d-%d-%d=7",a,b,c,d);
    else if (a-b+c+d==7)printf("%d-%d+%d+%d=7",a,b,c,d);
    else if (a-b+c-d==7)printf("%d-%d+%d-%d=7",a,b,c,d);
    else if (a-b-c+d==7)printf("%d-%d-%d+%d=7",a,b,c,d);
    else if (a-b-c-d==7)printf("%d-%d-%d-%d=7",a,b,c,d);
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 256
a,b,c,x,y = map(int, input().split())

ans = 0
if a > 2*c and x > 0: # aの価格がcの2倍以上ならx枚のピザをc円のピザで満たす
  ans += x*2*c
  y -= x
  x = 0
if b > 2*c and y > 0: # bの価格がcの2倍以上ならy枚のピザをc円のピザで満たす
  ans += y*2*c
  x -= y
  y = 0
if a+b >= 2*c and x > 0 and y > 0: # a+bの価格がcの2倍以上ならmin(x,y)枚のピザをc円のピザで満たす
  ans += 2*c*min(x,y)
  if x < y:
    y -= x
    x = 0
  elif y < x:
    x -= y
    y = 0
  else:
    x,y = 0,0
# 残りは普通に計算
if x > 0: ans += x*a
if y > 0: ans += y*b
print(ans)

Measured memory_bytes: 9208
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=924844033,root=5;
int power(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return ret;
}
struct NTTsolver
{
	int w[600111];
	void ntt(int a[],int n,int f)
	{
		for(int i=0,j=0;i<n;i++)
		{
			if(i<j)swap(a[i],a[j]);
			for(int t=n>>1;(j^=t)<t;t>>=1);
		}
		for(int l=1;l<n;l<<=1)
		{
			int l2=l<<1;
			int wn=power(root,(mod-1)/l2),w;
			if(f==-1)wn=power(wn,mod-2);
			for(int i=0;i<n;i+=l2)
			{
				w=1;
				for(int j=0;j<l;j++)
				{
					int tmp=1ll*a[i+l+j]*w%mod;
					a[i+l+j]=(a[i+j]-tmp+mod)%mod;
					a[i+j]=(a[i+j]+tmp)%mod;
					w=1ll*w*wn%mod;
				}
			}
		}
		if(f==-1)
		{
			int rev=power(n,mod-2);
			for(int i=0;i<n;i++)a[i]=1ll*a[i]*rev%mod;
		}
	}
	int a[600111],b[600111],c[600111];
	void mult(int _a[],int _b[],int _c[],int n,int m)
	{
		int l;
		for(l=1;l<n+m;l<<=1);
		for(int i=0;i<l;i++)a[i]=(i<=n?_a[i]:0);
		for(int i=0;i<l;i++)b[i]=(i<=m?_b[i]:0);
		for(int i=0;i<l;i++)_c[i]=0;
		ntt(a,l,1);ntt(b,l,1);
		for(int i=0;i<l;i++)c[i]=1ll*a[i]*b[i]%mod;
		ntt(c,l,-1);
		for(int i=0;i<=n+m;i++)_c[i]=c[i];
	}
}m1;

vector<int> g[200111];
int f[200111],invf[200111];
int n,sz[200111],a[200111],b[200111],c[600111];

void dfs(int x,int f=0)
{
	sz[x]=1;
	for(int i=0;i<(int)g[x].size();i++)
		if(g[x][i]!=f)
		{
			dfs(g[x][i],x);
			sz[x]+=sz[g[x][i]];
		}
}
int main()
{
	f[0]=invf[0]=1;
	for(int i=1;i<200111;i++)
	{
		f[i]=1ll*i*f[i-1]%mod;
		invf[i]=power(f[i],mod-2);
	}
	
	get1(n);
	for(int i=1,u,v;i<n;i++)
	{
		get2(u,v);
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1);
	for(int i=2;i<=n;i++)
	{
		a[sz[i]]++;
		a[n-sz[i]]++;
	}
	
	for(int i=1;i<=n;i++)a[i]=1ll*a[i]*f[i]%mod;
	for(int i=0;i<=n;i++)b[i]=invf[n-i];
	m1.mult(a,b,c,n,n);
	for(int i=1;i<=n;i++)
	{
		int t=c[i+n];
		t=1ll*t*invf[i]%mod;
		t=(1ll*n*f[n]%mod*invf[i]%mod*invf[n-i]%mod-t+mod)%mod;
		printendl(t);
	}
	return 0;
}

Measured memory_bytes: 41728
#include <stdio.h>
int GetPoint(void)
{
	int i, curr, sum=0;
	for(i=0; i<5; i++)
	{
		scanf("%d", &curr);
		sum += curr;
	}
	return sum;
}

int main(void)
{
	int i, n, curr, max, min;
	while(1)
	{
		scanf("%d", &n);
		if(n==0)break;

		curr=GetPoint();
		max=curr; min=curr;
		for(i=1; i<n; i++)
		{
			curr=GetPoint();
			     if(curr > max)max = curr;
			else if(curr < min)min = curr;
		}
		printf("%d %d\n", max, min); 
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

vector <int> pre, in, ans;

void rec(int lp, int rp, int li, int ri) {
    int root = pre[lp];
    int i = 0;
    while(in[li+i] != root) i++;
    if (i != 0) rec(lp+1, lp+i, li, li+i-1);
    if (li + i != ri) rec(lp+i+1, rp, li+i+1, ri);

    ans.pb(root);
}

void solve(void){
    int N;
    cin >> N;
    pre.resize(N), in.resize(N);
    rep(N, i) cin >> pre[i];
    rep(N, i) cin >> in[i];
    rec(0, N-1, 0, N-1);
    rep(N, i) {
        if (i < N-1) printf("%d ", ans[i]);
        else printf("%d\n", ans[i]);
    }
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}



Measured memory_bytes: 3252
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=acos(-1.0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
vector<complex<long double>> fft(vector<complex<long double>> a,int bo){
    int n=a.size();
    int h=0;
    while((1<<h)<n)h++;
    rep(i,0,n){
        ll j=0;
        rep(k,0,h)j|=((i>>k)&1)<<(h-1-k);
        if(i<j)swap(a[i],a[j]);
    }
    for(ll i=1;i<n;i*=2){
        rep(j,0,i){
            complex<long double> w=polar(1.0,(-(2*pi)/(2*i))*j*bo);
            for(ll k=0;k<n;k+=i*2){
                complex<long double> s=a[j+k];
                complex<long double> t=a[j+k+i]*w;
                a[j+k]=s+t;
                a[j+k+i]=s-t;
            }
        }
    }
    if(bo==-1)rep(i,0,n)a[i]/=n;
    return a;
}
vector<complex<long double>> fft(vector<long double> a,int bo){
    vector<complex<long double>> b(a.size());
    rep(i,0,a.size())b[i]=complex<long double>(a[i],0);
    return fft(b,bo);
}
vector<long double> convolve(vector<long double> a,vector<long double> b){
    int s=a.size()+b.size()-1;
    int t=1;
    while(t<s)t*=2;
    a.resize(t);
    b.resize(t);
    vector<complex<long double>> A=fft(a,1);
    vector<complex<long double>> B=fft(b,1);
    rep(i,0,t)A[i]*=B[i];
    A=fft(A,-1);
    rep(i,0,s)a[i]=A[i].real();
    return a;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,m;cin>>n>>m;
    vector<long double> a(100001),b(100001);
    ll cn[100001];
    fill(cn,cn+100001,0);
    rep(i,0,n){
        int t;cin>>t;
        cn[t]++;
       
    }
    rep(i,0,100001){
        a[i]=(long double)cn[i];
        b[i]=(long double)cn[i];
    }
    vector<long double> anss=convolve(a,b);
    ll ans[anss.size()];
    rep(i,0,anss.size())ans[i]=(ll)(anss[i]+0.4);
    ll sum=0;
    ll cnt=0;
    //cout<<anss.size()<<endl;
    rrep(i,anss.size()-1,0){
        if(cnt+ans[i]>m){
            sum+=i*(m-cnt);
            break;
        }
        else{
            sum+=i*ans[i];
            cnt+=ans[i];
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 43072
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
int main(){
	int n=read();
	int ans=0;
	while(n) ans+=n%10,n/=10;
	if(ans==1) cout<<10<<endl;
	else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 06.07.2020 09:43:03       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long cnt = n / i;
    ans += cnt * (cnt + 1) / 2 * i;
  }
  cout << ans << '\n';
  return 0;
}


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

int tmp[200010] = {};
int imo[200010] = {};

int main(){
    int n, m;
    cin >> n >> m;

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

    int num = 0;
    int ans = 0;
    for(int i = 1;i <= n;i++){
        num += tmp[i];
        imo[i] = num;
        if(imo[i] == m){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
import java.lang.Long.min
import java.lang.Math.sqrt

fun main (args:Array<String>){
    val N = readLine()!!.toLong()
    var minResult = (N - 1)
    val sqrtN = sqrt(N.toDouble()).toInt()
    for (i in 1..sqrtN) {
        if (N % i == 0L) {
            val j = N / i
            minResult = min(minResult, ((i - 1) + (j - 1)))
        }
    }
    println(minResult)
}


Measured memory_bytes: 34532
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n,k;
    for(;;){
        scanf("%d%d",&n,&k);
        if(n==0&&k==0)break;
        int ma=0,now=0;
        vector<int> ins(n);
        for(int i=0;i<n;i++)scanf("%d",&ins[i]);
        for(int i=0;i<k;i++)now+=ins[i];
        for(int i=k;i<n;i++){
            now+=ins[i]-ins[i-k];
            ma=max(ma,now);
        }
        printf("%d\n",ma);
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int A[200010],B[200010],num[200010];
int N,M,W,C,E,G,K;
int ans=1,ans2,Max=0,Min=INF;
string S,T;
vector<int> V;
set<int> U;
map<int,int> H;
bool F,Q[200010];

vector<int> D;
void DecompositPrime(int n){
	int a=2;
	while(n>=a*a){
		if(n%a==0){
			//printf("%d ",a);
			D.push_back(a);
			n/=a;
		}
		else{
			a++;
		}
	}
	D.push_back(n);
}

signed main(){
	cin>>N>>M;
	if(N==1){
		cout<<M<<endl;
		return 0;
	}
	if(M==1){
		cout<<1<<endl;
		return 0;
	}
	DecompositPrime(M);
	for(int i=0;i<D.size();i++){
		H[D[i]]++;
		DEB(D[i])END
	}
	for(auto x:H){
		if(x.second>=N){
			ans*=(int)std::pow(x.first,(x.second/N));
			DEB(ans)END
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//One implementation to rule them all?
#define db              double
#define ll              long long int
#define ld                long long double
//#define int           long long int
#define ull             unsigned long long
#define fi              first
#define se              second
#define rep(i,a,n)      for(int i=a;i<n;i++)
#define repr(i,n,b)     for(int i=n;i>=b;i--)
#define endl            '\n'
#define mem(a,b)        memset(a, b, sizeof a)
#define mkp             make_pair
#define pb              push_back
#define max3(a,b,c)     max(a,max(b,c))
#define min3(a,b,c)     min(a,min(b,c))
#define w(t)            int t; cin>>t; while(t--)
#define all(a)          a.begin(), a.end()
#define sz(a)           int((a).size())
#define debug(x)        cerr << #x << " = " << x << endl;
//Bitwise 
#define isOn(S, j)      (S & (1<<j))
#define setBit(S, j)    (S |= (1<<j))
#define clearBit(S, j)  (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S)       (S & (-S))
#define setAll(S, n)    (S = (1<<n)-1)
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
//Can use tuples in C++17
using namespace std;
typedef vector < int > vii;
typedef vector < ll > vll;
typedef vector < vii > vvi;
typedef pair < int,int > pii;
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
const db PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
db eps       =          0.000001;
ll mod       =          998244353;   //(1e9+7)
void print(vector <int> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}
void printll(vector <ll> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}

ll ncr(ll n, ll r)
{
    r=min(r,n-r);
    ll A[r],i,j,B[r];
    iota(A,A+r,n-r+1);  
    iota(B,B+r,1);     

    ll g;
    for(i=0;i<r;i++)
    for(j=0;j<r;j++)
    {
        if(B[i]==1)
            break;
        g=__gcd(B[i], A[j] );
        A[j]/=g;
        B[i]/=g;
    }
    ll ans=1;
    for(i=0;i<r;i++)
        ans=(ans*A[i]%mod);
    return ans;
}
const int SIZE=1e5+5;
bool judgePermutation(int a[], int n){
    static int used[SIZE+1];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(int i = 0; i < n; i++) used[a[i]] = 1;
    for(int i = 1; i <= n; i++) {
        if(!used[i]) return 0;
    }
    return 1;
}

int main(){ 
//CONDITION && cout << "YES" || cout << "NO"; cout << '\n';
//////////////////////////////////////////////////////////////////////
//  ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
//  cout.tie(NULL);
//  cerr.tie(NULL);
//For fast IO
///////////////////////////////////////////////////////////////////// 
//  std::cout.unsetf ( std::ios::floatfield );  // floatfield not set
//  std::cout.precision(10);
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
	db l;
	cin>>l;
	l=l/3;
	l=l*l*l;
	printf("%0.10lf\n",l);
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
l = gets.split.map(&:to_i)
l.sort!
ans = 0
for i in 0..(n-3)
  for j in (i+1) .. (n-2)
    for k in (j+1) .. (n-1)
      if l[i] != l[j] && l[j] != l[k] && l[k] != l[i] && l[k] < l[i]+l[j]
        ans += 1
      end
    end
  end
end
puts ans

Measured memory_bytes: 14408
S=input()
N=len(S)
count=0
if N%2==0:
    for i in range(0,N//2):
        if S[2*i]=="L" or S[2*i+1]=="R":
            count=1
else:
    for i in range(0,N//2):
        if S[2*i]=="L" or S[2*i+1]=="R":
            count=1
    if S[N-1]=="L":
            count=1
if count==1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<string, int, int> T;

int N;
vector<P> XI;
vector<P> ans;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) {
        int X; cin >> X;
        XI.pb(P(X, i));
    }
    sort(XI.begin(), XI.end());
    int a = XI[(N-1)/2].first;
    int b = XI[N/2].first;
    rep(i, N) {
        int j = XI[i].second;
        if (i<N/2) ans.pb(P(j, b));
        else ans.pb(P(j, a));
    }
    sort(ans.begin(), ans.end());
    rep(i, N) cout << ans[i].second << endl;
}

Measured memory_bytes: 12140
N, M = map(int, input().split())

a = []
b = []
c = []
d = []

for _ in range(N):
    _a, _b = map(int, input().split())
    a.append(_a)
    b.append(_b)

for _ in range(M):
    _c, _d = map(int, input().split())
    c.append(_c)
    d.append(_d)

for i in range(N):
    maxIdx = 0
    for j in range(M):
        d1 = abs(a[i] - c[j]) + abs(b[i] - d[j])
        d2 = abs(a[i] - c[maxIdx]) + abs(b[i] - d[maxIdx])
        if d1 < d2:
            maxIdx = j

    print(maxIdx + 1)

Measured memory_bytes: 3188