akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
//#include <self/operator>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#define Endl endl
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define quickcin ios_base::sync_with_stdio(false);
const int mod=1e9+7;
const int inf=1039074182;
const ll llinf=1LL*inf*inf;
using namespace std;
template <typename T1,typename T2> inline void chmin(T1 &x,T2 b) {if(b<x) x=b;}
template <typename T1,typename T2> inline void chmax(T1 &x,T2 b) {if(b>x) x=b;}
template <typename T1,typename T2> inline void chadd(T1 &x,T2 b) {x+=b;if(x>=mod) x-=mod;}
template <typename T1,typename T2> inline void chmul(T1 &x,T2 b) {x=1LL*x*b%mod;}
template <typename T1,typename T2> inline void chmod(T1 &x,T2 b) {x%=b,x+=b;if(x>=b) x-=b;}
int n;
int a[2005];
vector <int> vec[2005];
bool block[2005];

inline vector <int> merge(vector <int> a,vector <int> b)
{
	vector <int> res;
	int la=(int)a.size();
	int lb=(int)b.size();
	res.push_back(a[0]);
	for(int i=1,j=0;;)
	{
		if(i==la && j==lb) break;
		if(i==la) res.push_back(b[j++]);
		else if(j==lb) res.push_back(a[i++]);
		else if(a[i]>b[j]) res.push_back(a[i++]);
		else res.push_back(b[j++]);
	}
	return res;
}

//#include <self/operator>
vector <int> dfs(int x)
{
	vector <int> res;
	res.push_back(a[x]);
	block[x]=true;
	for(auto &u:vec[x])
	{
		if(block[u]) continue;
		res=merge(res,dfs(u));
	}
	return res;
}

bool compare(int x,int y)
{
	return a[x]<a[y];
}

void build_graph()
{
	a[n]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i==j) continue;
			if(__gcd(a[i],a[j])!=1) vec[i].push_back(j);
		}
	}
	for(int i=0;i<n;i++)
	{
		vec[i].push_back(n);
		vec[n].push_back(i);
	}
	for(int i=0;i<=n;i++)
	{
		sort(all(vec[i]),compare);
	}
}

void print_graph()
{
	cout<<"--------Graph is below--------"<<endl;
	for(int i=0;i<n;i++)
	{
		for(int &j:vec[i])
		{
			cout<<i<<' '<<j<<endl;
		}
	}
	cout<<"--------Graph is above--------"<<endl;
}

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	build_graph();
	for(auto &x:dfs(n))
	{
		if(x==0) continue;
		cout<<x<<' ';
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 19428
A,B,C,K=map(int,input().split())
ans=0
if K >= A:
    ans+=A
    K-=A
    A=0
else:
    ans=K*1
    K=0
if K >= B:
    K-=B
    B=0
else:
    K=0
if K >= C:
    ans-=C
    K-=C
    C=0
else:
    ans=ans+K*(-1)
    C=0
print(ans)

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

int main() {
  int N, M;
  cin >> N >> M;
  int X[M], D[M - 1];
  for (int i = 0; i < M; i++) {
    cin >> X[i];
  }
  sort(X, X + M);
  for (int i = 0; i < M - 1; i++)
    D[i] = X[i + 1] - X[i];
  sort(D, D + M - 1);
  int ans = 0;
  for (int i = 0; i < M - N; i++)
    ans += D[i];
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

int main()
{
    int n, m, k, ans =  0, tmp;
    cin >> n >> m;

    vector <int> a(m, 0);

    for (int i = 0; i < n; i++){
        cin >> k;
        for (int j = 0; j < k; j++){
            cin >> tmp;
            tmp--;
            a[tmp]++;
        }
    }

    for (int i = 0; i < m; i++){
        if(a[i] == n) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong a[2000100],k;
    cin >> k;
    
    a[1] = 7%k;
    for(llong i=2;i<=k;i++) a[i] = (a[i-1]*10 + 7)%k;
    
    for(llong i=1;i<=k;i++) if(a[i] == 0){
        cout << i << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 11212
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, M, X] = string_to_int(inputs[0])
    A = string_to_int(inputs[1])
    cost_0 = 0
    cost_n = 0
    for a in A:
        if a < X:
            cost_0 += 1
        elif a > X:
            cost_n += 1
    return min([cost_0, cost_n])


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


Measured memory_bytes: 3812
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<59;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;

int main(){
	cin>>n;
	int i=1;
	while(i*i<=n) i++;
	i--;
	cout<<i*i<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
char s[N];
int a[N], op[N], tot[N];

int main() {
    int n, k, cnt = 0, sum = 0; cin >> n >> k;
    scanf("%s", s+1);
    for(int i = 1; i <= n + 1; ++i) {
        if(s[i] != s[i - 1] && i - 1) {
            a[++cnt] = sum;
            op[cnt] = s[i - 1] - '0';
            sum = 0;
        }
        ++sum;
    }
    memset(tot, 0, sizeof(tot));
    for(int i = 1; i <= cnt; ++i) {
        if(!op[i]) tot[i] = tot[i - 1] + 1; else tot[i] = tot[i - 1];
        a[i] += a[i - 1];
    }
    int ans = 0;
    for(int l = 0, r = 1; r <= cnt; ++r) {
        while(l < r && tot[r] - tot[l - 1] > k) ++l;
        ans = max(ans, a[r] - a[l - 1]);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll a[100001];
int n,m,k;
ll dp[100001][301];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n>>m>>k;
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
	}
	for(int i = 0; i < n; i++)
	{
		dp[i][1] = a[i];
	}
	ll sum = a[0];
	for(int j = 2; j <= k; j++)
	{
		deque<ll> dq;
		dp[j-1][j] = sum+ll(j)*a[j-1];
		sum=dp[j-1][j];
		for(int z = 0; z < j; z++)
		{
			while(!dq.empty()&&dp[dq.back()][j-1]<=dp[z][j-1]) dq.pop_back();
			dq.push_back(z);
		}	
		for(int i = j; i < n; i++)
		{
			dp[i][j] = ll(j)*a[i] + dp[dq.front()][j-1];
			while(!dq.empty()&&dp[dq.back()][j-1]<=dp[i][j-1]) dq.pop_back();
			dq.push_back(i);
			while(!dq.empty()&&i-dq.front()>=m) dq.pop_front();
		}
	}
	ll ans = 0;
	for(int i = 0; i < n; i++) ans = max(ans, dp[i][k]);
	cout<<ans<<'\n';
}


Measured memory_bytes: 236160
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
	vs s(h);
	rep(i,h){
		cin >> s[i];
	}
	rep(i,h){
		bool ok = true;
		rep(j,w){
			if(s[i][j] == '#'){
				ok = false;
			}
		}
		if(ok){
			rep(j,w){
				s[i][j] = '*';
			}
		}
	}
	rep(j,w){
		bool ok = true;
		rep(i,h){
			if(s[i][j] == '#'){
				ok = false;
			}
		}
		if(ok){
			rep(i,h){
				s[i][j] = '*';
			}
		}
	}
	rep(i,h){
		bool ok = false;
		rep(j,w){
			if(s[i][j] == '*') continue;
			ok = true;
			cout << s[i][j];
		}
		if(ok){
			cout << "\n";
		}
	}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A , B;
  string op;
  cin >> A >> op >> B;
  if ( op == "+" ) {
    cout << A + B << endl;
  }
  if ( op == "-" ) {
    cout << A - B << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int x1,x2,x3,x4,y1,y2,y3,y4;
  cin>>x1>>y1>>x2>>y2;
  x3=x2+y1-y2;
  y3=y2+x2-x1;
  x4=x3+x1-x2;
  y4=y3+y1-y2;
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
 
typedef long long int lli;
const int SIZE = 200002;
int N;
lli num[SIZE];
lli pSum[SIZE];
 
lli absol(lli x) {
	return x < 0 ? -x : x;
}
 
int main()
{
	lli ans = 10000000000000000L;
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%lld", &num[i]);
		pSum[i] = pSum[i - 1] + num[i];
	}
	for (int i = 1; i < N; i++) {
		lli cand = absol(2 * pSum[i] - pSum[N]);
		if (cand < ans)
			ans = cand;
	}
	printf("%lld\n", ans);
}

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

int main()
{
	int N;
	cin >> N;
	int p[50];
	int cnt = 0;
	for (int i = 0; i < N; ++i)
	{
		cin >> p[i];
		if (p[i] != i+1)
		{
			cnt++;
		}
	}

	if ((cnt == 0)||(cnt == 2))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val xs = readLine()!!.map { it.toString().toInt() }
    for (bits in 0 until (1 shl 3)) {
        val sum = (0 until 3).map { if ((bits shr it) and 1 == 0) xs[it + 1] else -xs[it + 1] }.sum()
        if (xs[0] + sum == 7) {
            val s = (0 until 3).joinToString("") {
                if ((bits shr it) and 1 == 0) "+${xs[it + 1]}" else "-${xs[it + 1]}"
            }
            println("${xs[0]}$s=7")
            break
        }
    }
}


Measured memory_bytes: 33612
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;

int main() {
  vector<vector<int>>c(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>c[i][j];
    }
  }
  int d1=c[0][1]-c[0][0];
  int d2=c[0][2]-c[0][1];
  for(int i=1;i<3;i++){
    if(c[i][1]-c[i][0]!=d1||c[i][2]-c[i][1]!=d2){
      cout<<"No"<<endl;return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;  
}

Measured memory_bytes: 3588
#D in [S_i-X_i,T_i-X_i) → Xiで止まる
import sys
input = sys.stdin.readline

N,Q = map(int,input().split())
q = []

STX = [[int(x) for x in input().split()] for _ in range(N)]
for s,t,x in STX:
  q.append((s-x,1,x)) # xで死ぬ
  q.append((t-x,0,x)) # xで死ななくなる

for i in range(Q):
  d = int(input())
  q.append((d,2,i))
answer = [-1]*Q

se = set() # 引っかかってる場所

q.sort()

min_se = 10**18
flag = False # min_seが正しい

for a,c,b in q:
  if not c:
    se.remove(b)
    if min_se == b:
      flag = False
  elif c&1:
    se.add(b)
    if b < min_se:
      min_se = b
      flag = True
  else:
    if se:
      if not flag:
        min_se = min(se)
        flag = True
      answer[b] = min_se

print('\n'.join(map(str,answer)))


Measured memory_bytes: 142008
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n,m;cin>>n>>m;
    ll l=1,r=n;
    for(int i=0;i<m;i++){
        ll a,b;cin>>a>>b;
        l=max(l,a);
        r=min(r,b);
    }
    cout<<max(0ll,r-l+1)<<"\n";
}


Measured memory_bytes: 3660
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int N;
    LL T;
    cin >> N;
    cin >> T;
    LL ans = 0;
    LL last_x = 0;
    REP(i, N) {
        LL x;
        cin >> x;
        LL y = x - last_x;
        last_x = x;
        if(i != 0) {
            ans += min(y, T);
        }
    }
    ans += T;
    cout << ans << endl;

    return 0;
}



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

int main() {
  int n, m, ans = 0, tmp;
  string s, t;
  cin >> n >> s;

  for (int i = 1; i < n - 1; i++) {
    t = s.substr(i);
    m = t.size();
    tmp = 0;
    set<char> p, q;
    for (int j = 0; j < n - m; j++) p.insert(s[j]);
    for (int j = 0; j < m; j++) q.insert(t[j]);
    for (int j = 0; j < n - m; j++) {
      if (q.count(*begin(p))) tmp++;
      p.erase(*begin(p));
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

queue< int >q[3];
string S;
int idx;
int num;

int main(){
	
	
	
	REP( i, 3 ){
		cin>>S;
		REP( j, S.size() ){
			q[i].push(S[j]-'a');
		}
	}
	
	idx = 0;
	while( 1 ){
		if( q[idx].empty() ) break;
		num = q[idx].front();
		q[idx].pop();
		idx = num;
	}
	
	if( idx == 0 ) puts("A");
	if( idx == 1 ) puts("B");
	if( idx == 2 ) puts("C");
	
	return 0;

}

Measured memory_bytes: 256
N = int(input())

arr = []

for i in range(N):
    arr.append(list(map(int, input().split())))
    
for x in range(101):
    for y in range(101):
        for i in range(N):
            if arr[i][2]:
                H = arr[i][2] + abs(x-arr[i][0]) + abs(y-arr[i][1])
                break
        ok = True
        for i in range(N):
            price = H-abs(x-arr[i][0])-abs(y-arr[i][1])
            if max(price,0) != arr[i][2]:
                ok = False
        if ok :
            print(x,y,H)
            
        


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

ll gcd(ll a, ll b) { //最大公約数
    if (a%b == 0) return b;
    else return gcd(b,a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
    return a*b / gcd(a,b);
}

int main() {
    ll a,b,l,ans,all;
    int c,d;
    cin>>a>>b>>c>>d;
    all=b-a+1;
    a--;
    l=lcm(c,d);
    ans=(b/c+b/d-b/l)-(a/c+a/d-a/l);
    cout<<all-ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<ll>A;
int N;

void solve() {
	ll ecnt = 0;
	ll ocnt = 0;
	for (int i = 0; i < N; i++)if (A[i] > 0)((i % 2 == 1)?ocnt:ecnt) += A[i];

	vector<ll>temp;
	vector<ll>ans;
	puts(max(ecnt,ocnt));
	if (ecnt > ocnt) {
		for (int i = 0; i < N; i++) {
			if (i % 2 == 0) {
				if (A[i] > 0)temp.pb(1);
				else temp.pb(0);
			}
			else temp.pb(0);
		}
	}
	else {
		for (int i = 0; i < N; i++) {
			if (i % 2 == 1) {
				if (A[i] > 0)temp.pb(1);
				else temp.pb(0);
			}
			else temp.pb(0);
		}
	}

	while (temp.size() && temp[0] == 0) {
		ans.pb(1);
		temp.erase(temp.begin());
	}

	while (temp.size() >= 4) {
		if (temp[2])ans.pb(2);
		else ans.pb(3);
		temp.erase(temp.begin()+2);
		temp.erase(temp.begin()+2);
	}


	if (temp.size() == 3) {
		if (temp[2] == 1)ans.pb(2);
		else {
			ans.pb(3);
			ans.pb(2);
		}
	}
	else if (temp.size() == 2) {
		ans.pb(2);
	}
	puts(ans.size());
	fore(x, ans)puts(x);
}

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

	cin >> N;
	A.resize(N);
	ll ma = -inf;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		ma = max(ma, (ll)A[i]);
	}

	if (ma <= 0) {
		puts(ma);
		vector<ll>ans;
		ll cnt = 0;
		while (cnt < N && A[cnt] != ma) {
			ans.pb(1);
			cnt++;
		}
		for (int i = N - cnt; i > 1; i--)ans.pb(i);
		puts(ans.size());
		fore(x, ans)puts(x);
		return 0;
	}

	solve();
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int n; cin>>n;
  // cout<<n<<endl;
  if(n==0) puts("0");
  else{
    vector<int> s(0);
    while(n!=1){
      if(abs(n)%2){
        s.pb(1);
        n-=1;
      }else{
        s.pb(0);
      }
      n/=-2;
    }
    s.pb(1);
    rep(i,s.size())
    cout<<s[s.size()-1-i];
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void printA(int *A, int N);

int main()
{
  int i,j,N,key;
  int A[100];

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

  printA(A,N);
  for(i=1; i<N; i++)
    {
      key = A[i];
      j = i-1;
      while( j >= 0 && A[j] > key )
	{
	  A[j+1] = A[j];
	  j--;
	}
      A[j+1] = key;
      printA(A,N);
    }
  

  return 0;
}


void printA(int *A, int N)
{
  int i;
  for(i=0; i<N-1; i++)
      printf("%d ", A[i]);
  printf("%d\n", A[N-1]);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;


// 二次元累積和
template <typename T> class Accum2D{
public:
  vector<vector<T>> accum;

  Accum2D(vector<vector<T>> &vv){
    int d1 = vv.size(), d2 = vv[0].size();
    accum = vector<vector<T>>(d1+1, vector<T>(d2+1));
    REP(i,d1) REP(j,d2) accum[i+1][j+1] = vv[i][j];
    FORE(i,1,d1) REPE(j,d2) accum[i][j] += accum[i-1][j];
    REPE(i,d1) FORE(j,1,d2) accum[i][j] += accum[i][j-1];
  }

  T sum(int x1, int y1, int x2, int y2){ // [x1,x2), [y1,y2)
    return accum[x2][y2] - accum[x1][y2] - accum[x2][y1] + accum[x1][y1];
  }
};


int main(){
  int N,M,Q;
  while(cin >> N >> M >> Q){
    vector<vector<int>> a(N, vector<int>(N));
    REP(i,M){
      int l,r; cin >> l >> r; --l, --r;
      a[l][r] += 1;
    }

    Accum2D<int> ac(a);

    REP(i,Q){
      int p,q; cin >> p >> q; --p, --q;
      cout << ac.sum(p,p,q+1,q+1) << endl;
    }
  }

  return 0;
}


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




int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i,n){
      cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int Alice = 0;
  int Bob = 0;
  for(int i = 0; i < n; i++){
      if(i %2 == 0){
          Alice += vec.at(i);
      }else{
          Bob += vec.at(i);
      }
  }
  cout << Alice - Bob << endl;



}



Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main()
{
	int K, S;
	cin >> K >> S;

	int ans = 0;
	for (int X = 0; X <= K; X++) {
		for (int Y = 0; Y <= K; Y++) {
			int Z = S - X - Y;
			if (Z >= 0 && Z <= K)
				ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define pb push_back
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define ll long long int
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define deb(x) cout<<#x<<'='<<x<<endl
const double pi = 3.14159265358979323846;

ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}

int val[100001];

void solve()
{

	ll i=0,j=0,k=0,m,n,p,sum=0,cnt=1;
	cin>>n;
	int arr[n];
	for(i=0;i<n;i++)
	cin>>arr[i];
	for(i=0;i<n;i++)
	{
	    val[arr[i]]++;
	    sum+=arr[i];
	}
	int q;
	cin>>q;
	while(q--)
	{
	    int b,c;
	    cin>>b>>c;
	    if(val[b]>0)
	    {
	        val[c]+=val[b];
	        sum+=(c-b)*val[b];
	        val[b]=0;
	    }
	    cout<<sum<<endl;
	}
    
}
int main() {
    fast
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w+", stdout);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

Measured memory_bytes: 4400
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
ll a[100000], n;

int main() {
    cin >> n;
    ll mn = 1L << 60;
    ll mi = 0;
    ll ans = 0;
    ll z = 0;
    rep(i, n) {
        cin >> a[i];
        if (a[i] < 0)mi++;
        else if (a[i] == 0)z++;
        chmin(mn, abs(a[i]));
        ans += abs(a[i]);
    }

    if (mi % 2) {
        if (z) {
            cout << ans << endl;
        } else {
            cout << ans - 2 * mn << endl;
        }
    } else {
        cout << ans << endl;
    }
}



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

using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define endl '\n'
#define int ll

const double PI = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = (int) (1e9) + 7;
const int MX = 777777 + 5;
const int mod = 1777777777;
const double EPS = 1e-10;
const ll MXP = 8999251775770639633;

inline int len(string s){return s.size();}
inline int len(int* A){return (sizeof(A))/sizeof(A[0]);}
template <typename T>inline int len(vector<T> v){return v.size();}
template <typename T>inline int len(set<T> v){return v.size();}
template <typename T,typename S>inline int len(map<T,S> v){return v.size();}

int fac[MX+5];
int power(int x, int y, int p)
{
    int res = 1;

    x = x % p;

    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}

int C(int n, int r, int p)
{
    if (r==0)
        return 1;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

void init(int mod){
    fac[0] = 1;
    for (int i=1 ; i<=MX; i++)
        fac[i] = fac[i-1]*i%mod;
}

int CC(int a, int b){
    int res = 1;
    rep(i,a+1,a-b+1)res *= i,res/=a-i+1;
//    rep(i,1,b+1)res /= i;
    return res;
}

bool equal(double a, double b) {
    return std::fabs(a - b) < std::numeric_limits<double>::epsilon();
}

map<string, int> m;
string trim(string s){
    string res;
    for (int i = 0; i < s.size() && isalpha(s[i]); ++i) {
        res += tolower(s[i]);
    }
    return res;
}

int A[2043];
void _() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(b/a,c);

};

#undef int
int main() {
#if __MINGW32__
    freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Input.txt", "r", stdin);
    freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Output.txt", "w", stdout);

#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		Scanner scan=new Scanner(System.in);
		String s1;
		ArrayList<String> al=new ArrayList<String>();
		int i=0;
		s1=scan.next().toLowerCase();
		while(scan.hasNext()){
			al.add(scan.next());
			if(al.get(i).equals("END_OF_TEXT"))
				break;
			i++;
			
		}
		int s=al.size();
		int c=0;
		for(int m=0;m<s;m++)
		{
			if(al.get(m).toLowerCase().equals(s1))
				c++;
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 18320
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int  n=sc.nextInt();
		int k=sc.nextInt();

String d[]=new String [k];
		for(int i=0;i<k;i++) {
			d[i]=(sc.next());
		}
	
int now=n;
s:while(true)
{
	String nows=String.valueOf(now);
	for(int i=0;i<k;i++) {
		if(nows.contains(d[i])) {
			now++;
			continue s;
		}
	}
	break;
}
System.out.println(now);


		
		
	}
	
	static void readArray(int[] arr,Scanner sc) { 
		for(int i=0;i<arr.length;i++) {
			arr[i]=sc.nextInt();
		}
	}
	
	
	

}


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

int main()
{
    int w, a, b, diff = 0;
    std::cin >> w >> a >> b;
    if(a + w < b) diff = b - (a + w);
    else if(b + w < a) diff = a - (b + w);
    std::cout << diff << std::endl;
}

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

int main(){
	int n;
	int res = 0;
	cin >> n;
	int p[n];
	for(int i = 0; i < n; i++) cin >> p[i];
	for(int i = 1; i < n - 1 ; i++){
		if(p[i] < p[i -1] && p[i] > p[i+1]) res++;
		else if(p[i] < p[i+1] && p[i] > p[i-1]) res++;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
using namespace std;

void jj(int64_t &p, int prime ,int n, int64_t &ans){
    int count = 0;
    while (1)
    {
        if (p % prime == 0)
        {
            p /= prime ;
            count ++ ;
            if (count == n)
            {
                ans *= prime ;
                count = 0 ;
            }
            
        }else
        {
            break ;
        }
        
    }
}


int main(){
    int64_t n,p ;
    cin >> n >> p ;
    if (p == 1)
    {
        cout << 1 << endl ;
        return 0 ;
    }
    if (n == 1)
    {
        cout << p << endl ;
        return 0;
    }
    int64_t ans = 1 ;
    jj(p,2,n,ans) ;
    
    vector<int> prime(1,2) ;
    for (size_t i = 2; i < sqrt(p) + 100; i++)
    {
        bool judge = true ;
        for (size_t j = 0; j < prime.size(); j++)
        {
            if (i % prime.at(j) == 0)
            {
                judge = false ;
                break ;
            }
            
        }
        if (judge == 1)
        {
            prime.push_back(i) ;
            jj(p,i,n,ans) ;
        }
        
    }
    
    
    cout << ans << endl ;
}

Measured memory_bytes: 384
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

import java.io.PrintWriter;
import java.text.DecimalFormat;

public class Main {
	public static void main(String[] args) {
		int i, j, k;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int m = parseInt(sc.next());
		Py[] py0 = new Py[m];
		Py[] py1 = new Py[m];
		for(i = 0; i < m; i++) {
			py0[i] = new Py(parseInt(sc.next()), parseInt(sc.next()));
			py1[i] = py0[i];
		}
		sc.close();
		Arrays.sort(py1, (a, b) -> {if(a.p != b.p) {
			return a.p - b.p;
		} else {
			return a.y - b.y;
		}
		});
		int prep = -1;
		int xx = 0;
		for(i = 0; i < m; i++) {
			if(prep == py1[i].p) {
				xx++;
			} else {
				prep = py1[i].p;
				xx=1;
			}
			py1[i].y = xx;
		}
		DecimalFormat df = new DecimalFormat("000000");
		PrintWriter pw = new PrintWriter(out);
		for(i = 0; i < m; i++) {
			pw.print(df.format(py0[i].p));
			pw.println(df.format(py0[i].y));
		}
		pw.flush();
	}
}
class Py {
	int p;
	int y;
	Py(int p, int y){
		this.p = p;
		this.y = y;
	}
}


Measured memory_bytes: 69332
n = int(input())
x = list(map(int,input().split()))
a = max(x)
b = min(x)
y = 0
ans = 10000000

for i in range (b,a+1): #住民がいる間で
  y = 0 #初期化
  for j in x: #体力の総和を計算
    y = y + (j-i)**2
  if y < ans:
    ans = y

print(ans)


Measured memory_bytes: 3060
while True:
	ans = 0
	n,x = map(int,input().split())
	if x == 0 and n == 0 : break
	for a in range(3,n+1):
		for b in range(2,a):
			for c in range(1,b):
				if a + b + c == x:
					ans+=1
	print(ans)


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */

public class Main {
    public static void main(String[] args) {
        InputStream    inputStream    = System.in;
        OutputStream outputStream = System.out;
        InputReader    in                      = new InputReader(inputStream);
        PrintWriter      out                    = new PrintWriter(outputStream);
        Task                 solver               = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
        	int N = in.nextInt();
        	int tmp;
        	int count = 0;
        	for(int i = 1; i <= N; i+=2) {
        		tmp = 0;
        		for(int j = 1; j <= i; j++) {
        			if(i % j == 0) {
        				tmp++;
        			}
        		}
    			if(tmp == 8) {
    				count++;
    			}
        	}
        	out.println(count);
        }
    }

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

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

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

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

    }
}



Measured memory_bytes: 23380
/* 
 * Project: AtCoder Beginners Contest 145 B - Echo
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/08
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int n;
string s;

void solve() {

    int s_length = s.size();
    if (s.substr(0, s_length/2) == s.substr(s_length/2, s_length))
        printf("Yes\n");
    else
        printf("No\n");

}

int main() {

    scanf("%d", &n);
    cin >> s;

    solve();

}

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

int main(void){
  int memo[101] = {0};
  int n, max = 0;

  while(cin >> n)
    memo[n]++;

  for(int i = 0; i < 101; i++)
    if(max < memo[i])
      max = memo[i];

  for(int i = 0; i < 101; i++)
    if(memo[i] == max)
      cout << i << endl;

  return 0;
}

Measured memory_bytes: 1160
a, b = map(int, input().split())
def gcd(p, q):
    if p < q:
        p, q = q, p
    while q > 0:
        p, q = q, p%q
    return p

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

divisors = make_divisors(gcd(a, b))
ans = []
while divisors:
    key = divisors[0]
    ans.append(key)
    divisors.remove(key)
    notans = []
    for value in divisors:
        if gcd(key, value) != 1:
            notans.append(value)
    for i in notans:
        divisors.remove(i)
            
print(len(ans))


Measured memory_bytes: 3316
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
using namespace std;
#pragma warning(disable : 4996)

bool check(int n) {
	if (n == 1)return false;
	if (n == 2)return true;
	for (int i = 2; i <= sqrt(n) + 1; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	while (true) {
		if (check(n)) {
			cout << n;
			return 0;
		}
		n++;
	}
}

Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n k ->
    let module M = Map.Make (struct type t = int let compare = compare end) in
    let rec loop i map =
        if i = 0 then map else
            let map = Scanf.scanf " %d" (fun a -> 
                M.add a (1 + try M.find a map with _ -> 0) map)
            in
            loop (i - 1) map
    in
    let map = loop n M.empty in
    let arr = Array.of_list (M.bindings map) in
    Array.sort (fun (_, a) (_, b) -> compare b a) arr;
    let rec loop i sum =
        if i >= Array.length arr then sum else
            let (_, a) = arr.(i) in
            loop (i + 1) (sum + a)
    in
    loop k 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 25600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);
            var input2 = Console.ReadLine().Split(' ');
            var homeworkNum = new int[M];
            for (int i = 0; i < M; i++)
            {
                homeworkNum[i] = int.Parse(input2[i]);
            }
            var ans = -1;
            var daySum = 0;
            for (int i = 0; i < homeworkNum.Length; i++)
            {
                daySum += homeworkNum[i];
            }
            ans = daySum;
            if (N < ans)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(N - ans);
            }
        }
    }
}


Measured memory_bytes: 19276
#include<iostream>
#include<cstdio>
using namespace std;
double a, b, c, d, e, f;
double x, y;
int main()
{
	while (cin >> a >> b >> c >> d >> e >> f){
		
		x = (c*e - b*f) / (a*e - d*b) ;
		y=(c*d - f*a) / (b*d - a*e);
		if (x == 0)x = 0;
		if (y == 0)y = 0;
		printf("%.3f %.3f\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;


int main()
{
	int A, B;
	cin >> A >> B;
	if (abs(A - B) % 2 == 1) cout << "IMPOSSIBLE" << endl;
	else cout << (A + B) / 2 << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
   
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        int s,w;cin>>s>>w;
        if(w>=s){
            cout<<"unsafe";
        }
        else{
            cout<<"safe";
        }
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <iomanip>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;

#define mem(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_array(const int A[], int n) {
    REP(i, n) {
        cout << A[i] << " ";
    }
    cout << endl;
}

bool is_prime(int n) {
    if (n == 2) return true;
    for (int i = 2; i < sqrt(n) + 1; ++i) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

int rem[1000001];

inline void solve() {
    int k;
    cin >> k;

    int r = 7;
    rem[r] = 1;
    int res = 1;

    while (true) {
        // cout << rem << endl;
        if (r % k == 0) {
            cout << res << endl;
            return;
        } else {
            r = (r * 10 + 7) % k;
            if (rem[r] == 1) {
                cout << -1 << endl;
                return;
            } else {
                rem[r] = 1;
                res++;
            }
        }
    }
}


int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    int t;
    t = 1;
    // cin >> t;

    for (int _ = 0; _ < t; _++) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 7560
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int O = 0;

string min_str(string S, int K) {
	if(K == 0) return S;
	int N = S.length();
	int occ = 0;
	while(occ < N && S[N-1-occ] == S[N-1]) occ++;
	int occ0 = occ;
	while(K > 1) {
		occ *= 2;
		occ = min(occ, N);
		K--;
		if(occ == N) break;
	}
	if(occ == N) {
		string ret = "";
		for(int i = 0; i < N; i++) ret += S[N-1];
		O = N;
		return ret;
	}
	int r = N-occ;
	string X = S.substr(N-occ0-r, r);
	for(int i = 0; i < occ; i++) X += S[N-1];
	string Xr = X;
	reverse(begin(Xr), end(Xr));
	string Y = X + Xr;
	static vector<int> cand_pos;
	cand_pos = {};
	int max_occ = -1;
	for(int i = 0; i <= N; i++) if(Y[i] == S[N-1] && (i == 0 || Y[i-1] != S[N-1])) {
		int cur_occ = 0;
		while(i+cur_occ < 2*N && S[N-1] == Y[i+cur_occ]) cur_occ++;
		if(O > cur_occ) continue;
		if(max_occ < cur_occ) {
			cand_pos = {};
			max_occ = cur_occ;
		}
		if(max_occ == cur_occ) cand_pos.push_back(i);
		i += cur_occ;
	}
	O = max(O, max_occ);
	if(cand_pos.size() > 2) cand_pos.resize(2);
	string ret = X;
	for(int pos : cand_pos) ret = min(ret, Y.substr(pos, N));
	return ret;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, K;
	string S;
	cin >> N >> K >> S;
	string ans = S;
	char min_char = 'z';
	for(int i = 0; i < N; i++) min_char = min(min_char, S[i]);
	if(S[N-1] == min_char) ans = min(ans, min_str(S, K));
	string Sr = S;
	reverse(begin(Sr), end(Sr));
	string X = S + Sr;
	for(int i = 1; i < N; i++) if(X[i] == min_char && X[i-1] != min_char)
		ans = min(ans, X.substr(i, N));
	for(int i = 0; i < N; i++) if(X[N+i] == min_char && (i == N-1 || X[N+i+1] != min_char)) {
		string Y = X.substr(i+1, N);
		ans = min(ans, min_str(Y, K-1));
		if(O == N) break;
	}
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 384