akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mod 1000000007
#define N 111
using namespace std;
#define LL long long
LL fpow(LL x,int k){
	LL ans=1;
	while (k){
		if (k&1) ans=ans*x%mod;
		x=x*x%mod;
		k>>=1;
	}
	return ans;
} 
vector <int> son[N];
int len[N],siz[N],f[N],g[N],num[N],stk[N],id[N];

void dfs(int x) {
	int ans=1,s=siz[x];
	f[x]=1;g[x]=0;
	for (int i=0;i<son[x].size();i++){
		int u=son[x][i];
		dfs(u);
		g[x]=((LL)g[x]*(f[u]+g[u])+(LL)f[x]*g[u])%mod;
		f[x]=(LL)f[x]*f[u]%mod;
		s-=siz[u];
	}
	g[x]=((LL)g[x]*fpow(2LL,s)%mod+(LL)f[x]*(fpow(2LL,s)-1+mod))%mod;
	f[x]=(LL)f[x]*fpow(2LL,len[x])%mod;
} 
int solve(int l,int r){
	int cnt=0,top=0;
	stk[0]=l-1;
	for (int i=l;i<=r;i++){
		while (top&&num[stk[top]]>=num[i])
		if (num[i]==num[stk[top]]){
			stk[top]=i;break;
		}else if (num[i]>num[stk[top-1]]) {
			int v=++cnt;
			son[v].clear();
			son[v].push_back(id[top]);
			len[id[top]]=num[stk[top]]-num[i];
			siz[id[top]]=i-stk[top-1]-2;
			stk[top]=i;id[top]=v;
			break;
		}else{
			len[id[top]]=num[stk[top]]-num[stk[top-1]];
			siz[id[top]]=i-stk[top-1]-2;
			son[id[top-1]].push_back(id[top]);
			top--;
		}
		if (stk[top]!=i){
			int v=++cnt;
			stk[++top]=i;id[top]=v;
			son[v].clear();
		}
	}
	while (top){
		len[id[top]]=num[stk[top]]-num[stk[top-1]];
		siz[id[top]]=r-stk[top-1]-1;
		if (top>1) son[id[top-1]].push_back(id[top]);
		top--;
	}
	dfs(id[1]);
	return (f[id[1]]+g[id[1]])%mod;
}
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0' || ch>'9'){
		if (ch=='-') f=-1;
		ch=getchar();
	}
	while (ch>='0' && ch<='9'){
		x=x*10+ch-'0';ch=getchar();
	}
	return x*f;
}
int main(){
	int n=read();
	for (int i=1;i<=n;i++) num[i]=read()-1;
	int ans=1;
	for (int i=1;i<=n;i++){
		if (!num[i] || !num[i-1]) ans=ans*2LL%mod;
		if (num[i] && !num[i+1]){
			int l=i;
			while (num[l-1]) l--;
			ans=ans*solve(l,i)%mod; 
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import math
n = int(input())
points = []
for i in range(n):
  x,y = map(int,input().split())
  points.append((x,y))

def distance(p1,p2):
  ans = (p1[0]-p2[0])**2 + (p1[1]-p2[1])**2
  return math.sqrt(ans)

amount = 0
for i in range(len(points)):
  for j in range(len(points)):
    if i == j:
      continue
    amount += distance(points[i],points[j])
print(amount/n)

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

#define ll long long
#define M (1000000000 + 7)

using namespace std;

int main(){
    int n, resposta = 0;

    cin >> n;

    vector<int> value(n);
    vector<int> cost(n);
    vector<int> resp(n);

    for(int i = 0; i < n; ++i) cin >> value[i];
    for(int i = 0; i < n; ++i) cin >> cost[i];

    for(int i = 0; i < n; ++i){
        resp[i] = value[i] - cost[i];
        //cout << resp[i] << endl;
    } 

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

    for(int i = n-1; resp[i] > 0 && i >= 0; --i){
        resposta += resp[i];
        //cout << resposta << endl;
    }
    
    cout << resposta << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    int a[2][n];
    int ans = -1;
    int flag = 0;

    rep(i, 2) {
      rep(j, n) {
        cin >> a[i][j];
      }
    }

    rep(i, n) {
      int flag = i;
      int f = 0;
      int c = 0;
      rep(j, 2) {
        FOR(k, f, n) {
          c += a[j][k];
          if (flag == k) {
            f = flag;
            flag = -1;
            break;
          }
        }
        ans = max(ans, c);
      }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

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

    std::vector<int> A(N);
    int b = 0, c = 0;
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];

        if (A[i] > b)
            b = A[i];
        else if (A[i] > c)
            c = A[i];
    }

    for (int i = 0; i < N; i++)
        std::cout << (A[i] == b ? c : b) << "\n";
}

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

using namespace std;
#define int long long int



signed main()
{
    string s;
    cin >> s;
    int ln = s.length();
    for(int i = 0; i < ln; i++){
        if(s[0] == 'A' && s[1] == 'A' && s[2] == 'A' || s[0] == 'B' && s[1] == 'B' && s[2] == 'B'){
            cout << "No"<< endl;
            break;
        }
        else{
            cout << "Yes"<< endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
int bs_cnt_less(vl& A, const ll X, bool equal) {
    if (equal) return upper_bound(A.begin(), A.end(), X) - A.begin();
    else return lower_bound(A.begin(), A.end(), X) - A.begin();
}

int bs_idx_less(vl& A, const ll X, bool equal) {
    if (equal) return bs_cnt_less(A, X, true) - 1;
    else return bs_cnt_less(A, X, false) - 1;
}

int bs_idx_greater(vl& A, const ll X, bool equal) {
    if (equal) return bs_cnt_less(A, X, false);
    else return bs_cnt_less(A, X, true);
}
#endif 


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

    int A, B, Q; cin >> A >> B >> Q;
    vl S(A + 2); FOR(i, 1, A + 1) cin >> S[i];
    vl T(B + 2); FOR(i, 1, B + 1) cin >> T[i];
    vl X(Q); REP(i, Q) cin >> X[i];

    S[0] = -1e11; S[A + 1] = 1e11;
    T[0] = -1e11; T[B + 1] = 1e11;

    REP(i,Q) {
        vl dist(8);

        ll x = X[i];
        
        // S->T
        int sl = bs_idx_less(S, x, false);
        int tl = bs_idx_less(T, S[sl], true);
        int tr = bs_idx_greater(T, S[sl], true);
        dist[0] = abs(S[sl] - x) + abs(T[tl] - S[sl]);
        dist[1] = abs(S[sl] - x) + abs(T[tr] - S[sl]);

        int sr = bs_idx_greater(S, x, false);
        tl = bs_idx_less(T, S[sr], true);
        tr = bs_idx_greater(T, S[sr], true);

        dist[2] = abs(S[sr] - x) + abs(T[tl] - S[sr]);
        dist[3] = abs(S[sr] - x) + abs(T[tr] - S[sr]);

        // T->S
        tl = bs_idx_less(T, x, false);
        sl = bs_idx_less(S, T[tl], true);
        sr = bs_idx_greater(S, T[tl], true);

        dist[4] = abs(T[tl] - x) + abs(S[sl] - T[tl]);
        dist[5] = abs(T[tl] - x) + abs(S[sr] - T[tl]);

        tr = bs_idx_greater(T, x, false);
        sl = bs_idx_less(S, T[tr], true);
        sr = bs_idx_greater(S, T[tr], true);
        dist[6] = abs(T[tr] - x) + abs(S[sl] - T[tr]);
        dist[7] = abs(T[tr] - x) + abs(S[sr] - T[tr]);

        ll ans = LINF;
      
        REP(i, 8) ans = min(ans, dist[i]);

        cout << ans << endl;
    }

    return 0;
}

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

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

int w,h,m[21][21],sx,sy,gx,gy,dx[]={1,0,-1,0},dy[]={0,1,0,-1};

int f(int w,int h,int m[][21],int x,int y,int t){
	if(t==10)return 99;
	int res=99;
	rep(i,4){
		int cx=x,cy=y,d=0;
		while(1){
			cx+=dx[i];cy+=dy[i];
			if(cx<0||cx>=w||cy<0||cy>=h)break;
			if(m[cy][cx]==3){res=min(res,t+1);break;}
			if(m[cy][cx]==1){
				if(!d)break;
				int m2[21][21];
				rep(j,h)rep(k,w)m2[j][k]=m[j][k];
				m2[cy][cx]=0;
				res=min(res,f(w,h,m2,cx-dx[i],cy-dy[i],t+1));
				break;
			}
			d++;
		}
	}
	return res;
}

int main(){
	while(cin>>w>>h&&w){
		rep(i,h)rep(j,w){
			cin>>m[i][j];
			if(m[i][j]==2){sx=j,sy=i;}
			if(m[i][j]==3){gx=j,gy=i;}
		}
		int ans=f(w,h,m,sx,sy,0);
		cout<<(ans<99?ans:-1)<<endl;
	}
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n;
  cin>>n;
  vvll a(2,vll(n));
  rep(i,2){
    rep(j,n){
      cin>>a[i][j];
    }
  }
  ll ans=0;
  ll cu=a[0][0];
  rep(i,n) cu+=a[1][i];
  ans=cu;
  rep(i,n-1){
    cu-=a[1][i];
    cu+=a[0][i+1];
    ans=max(ans,cu);
  }
  COUT(ans);
}
    


Measured memory_bytes: 256
N = gets.to_i
hs = gets.split.map(&:to_i)
dp = Array.new(N, 0)
dp[1] = (hs[0]-hs[1]).abs
(2...N).each do |i|
    dp[i] = [dp[i-1] + (hs[i-1] - hs[i]).abs, dp[i-2] + (hs[i-2] - hs[i]).abs].min
end
puts dp[N-1]

Measured memory_bytes: 11396
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long lint;
typedef vector<lint> vl;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) REP(i,0,b)
#define maxn 100010

int n;

int main(){
	lint x,y;
	while(cin>>x>>y){
		lint k=x-y;
		if(-1LL<=k&&k<=1LL)puts("Brown");
		else puts("Alice");
	}
	return 0;
}

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

#define exp(n) ((n) * (n))

struct point{
  double x, y;
} p[22] = {};

int main(){
  double s, a, b, c, z;
  int i, j, n = 0;
  while(~scanf("%lf,%lf", &p[n].x, &p[n].y)) n++;
  s = 0.0;
  for(i = 2;i < n;i++){
    a = sqrt(exp(p[i - 1].x - p[0].x) + exp(p[i - 1].y - p[0].y));
    b = sqrt(exp(p[i].x - p[i - 1].x) + exp(p[i].y - p[i - 1].y));
    c = sqrt(exp(p[i].x - p[0].x) +  exp(p[i].y - p[0].y));
    z = (a + b + c) / 2;
    s += sqrt(z * (z - a) * (z - b) * (z -c));
  }
  printf("%.6f\n", s);
  return 0;
}

Measured memory_bytes: 656
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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

const int MOD = 1000000007;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

 int main(){
        string s;
        cin >> s;
        bool flag = true;
        for(int i=0;i<s.size();i++) {
            if(i%2==0) {
                if(!(s[i]=='R' || s[i]=='U' || s[i]=='D') ) {
                    flag = false;
                }
            }else{
                if(!(s[i]=='L' || s[i]=='U' || s[i]=='D') ) {
                    flag = false;
                }
            }
        }
        Yes(flag);
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); cout.tie(NULL);
	
	ll n,m;cin>>n>>m;
	ll a[n];For(i,0,n) cin>>a[i];
	priority_queue<pii> p;
	For(i,0,n) p.push({a[i],1});

	For(i,0,m){
		ll b,c;cin>>b>>c;
		p.push({c,b});
	}
	ll sum=0;
	For(i,0,n){
		sum+=p.top().fi;
		if(p.top().se==1){
			p.pop();
		}else{
			pii x = p.top();
			x.se--;
			p.pop();
			p.push(x);
		}
	}
	cout<<sum<<endl;

	









	
}

Measured memory_bytes: 7024
import math


def main():
    s1 = input()   
    s2 = input()
    
    dp = [[0]*(len(s2)+1) for x in range(len(s1)+1)]
    for x in range(len(s1)):
        dp[x][0] = 0
    for x in range(len(s2)):
        dp[0][x] = 0
    
    for x in range(1,len(s1)+1):
        for y in range(1,len(s2)+1):
            if s1[x-1]==s2[y-1]:
                dp[x][y] = dp[x-1][y-1]+1
            else:
                dp[x][y] = max(dp[x][y-1],dp[x-1][y])
    x = len(s1)
    y = len(s2)
    s = ""
    while x > 0 and y > 0:
        if(s1[x-1]==s2[y-1]):
            s+=s1[x-1]
            x-=1
            y-=1
        elif dp[x-1][y] > dp[x][y-1]:
            x-=1
        else:
            y-=1
    print(s[::-1])
    
main()

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

int main() {
    int N, num, sum = 0;
    cin >> N;
    num = N;
    while(num) {
        int num_temp;
        num_temp = num % 10;
        sum += num_temp;
        num = num / 10;
    }
    if(N % sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
p = [na() for i in range(n)]
d = [[0, 0] for i in range(n)]
for i in range(n):
    d[i][0] = p[i][0] + p[i][1]
    d[i][1] = p[i][0] - p[i][1]

d.sort()

inf = 1 << 60
l = -inf
ans = 0
for i in range(n):
    if l <= d[i][1]:
        ans += 1
        l = d[i][0]

print(ans)

Measured memory_bytes: 41388
N = int(input())
X = [int(_) for _ in input().split()]
Y = sorted([[_, X[_]] for _ in range(N)], key=lambda x: x[1])
Z = [0] * N
a = Y[(N - 1) // 2][1]
b = Y[N // 2][1]
for i in range(N):
    Z[Y[i][0]] = b if i < N // 2 else a
[print(_) for _ in Z]

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

void insertionSort(vector<int> A, int N) {
    for (int i = 0; i < N; i++) {
        int v = A.at(i);
        int j = i-1;
        while (j >= 0 && A.at(j) > v) {
            A.at(j+1) = A.at(j);
            j--;
        }
        A.at(j+1) = v;
        for (int x = 0; x < N; x++) {
            if (x < N-1) {
                cout << A.at(x) << " ";
            } else {
                cout << A.at(x) << endl;
            }
        }
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    insertionSort(A, N);

    return 0;
}



Measured memory_bytes: 3164
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
tmp = 0
output = 0

for i in range(N):
    tmp = A[i] - 1
    output += B[tmp]

    if i == N - 1:
        break

    if A[i + 1] - A[i] == 1:
        output += C[tmp]

print(output)


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    ll n,m;cin>>n>>m;
    vector<pair<ll,ll>> p;
    rep(i,n){
        ll a;cin>>a;
        p.emplace_back(a,1);
    }
    rep(i,m){
        ll b,c;cin>>b>>c;
        p.emplace_back(c,b);
    }
    sort(rall(p));
    ll res = 0;
    ll sub = n;
    for(auto a:p){
        rep(i,a.second){
            res+=a.first;
            sub--;
            if(sub == 0){
                out(res);
                return 0;
            }
        }
    }
}



Measured memory_bytes: 6512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] X = new long[N];
        long[] L = new long[N];
        ArrayList<long[]> arms = new ArrayList<long[]>();
        for (int i=0;i<N;i++) {
            X[i] = sc.nextInt();
            L[i] = sc.nextInt();
            long[] add = {X[i]-L[i], X[i]+L[i]};
            arms.add(add);
        }
        Collections.sort(arms, (o1, o2)->Long.compare(o1[1], o2[1]));
        long used = -3_000_000_000L;
        int cnt = 0;
        for (int i=0;i<N;i++) {
            long before = arms.get(i)[0];
            long after = arms.get(i)[1];
            if (used<=before) {
                used = after;
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 93676
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <map>

typedef long long ll;
const int N = 1e5 + 51;
struct edge {
	int to, next;
} e[N << 1];
int head[N], cnt;
void addedge(int x, int y) {
	e[++cnt] = (edge){y, x[head]}, x[head] = cnt;
	e[++cnt] = (edge){x, y[head]}, y[head] = cnt;
}

ll ans;
void dfs(int x, int p, int d) {
	ans += d;
	for (int i = x[head], nx; i; i = e[i].next)
		if ((nx = e[i].to) != p) dfs(nx, x, d + 1);
}

int p[N];
int f(int x) { return x[p] ? x[p] = f(x[p]) : x; }
void l(int x, int y) {
	if ((x = f(x)) != (y = f(y))) x[p] = y;
}

std::map<ll, int> mp;
int n, sz[N];
ll a[N];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%lld", a + i), i[sz] = 1, mp[a[i]] = i;
	std::sort(a + 1, a + n + 1, std::greater<ll>());
	for (int i = 1; i < n; i++) {
		int x = mp[a[i]], nx;
		ll tmp = a[i] - n + 2 * x[sz];
		if (tmp >= a[i] || !mp.count(tmp)) return puts("-1"), 0;
		nx = mp[tmp];
		nx[sz] += x[sz];
		if (f(x) == f(nx)) return puts("-1"), 0;
		addedge(x, nx);
		l(x, nx);
	}
	dfs(mp[a[1]], 0, 0);
	if (ans != a[1]) return puts("-1"), 0;
	for (int i = 1; i <= cnt; i += 2) printf("%d %d\n", e[i + 1].to, e[i].to);
}

Measured memory_bytes: 15872
import java.util.*;

public class Main {
  public static void main(String[] main){
    Scanner sc = new Scanner(System.in);

    int x = sc.nextInt();
    int y = sc.nextInt();
    int gcd = 1;  /* gcd：最大公約数を１に初期化 */
    int small = 0;
    //x.compareTo(y);

    /* x÷y or y÷x が割り切れるとき, 小さい方を最大公約数として返す */
    if ((x % y == 0) || (y % x == 0)){
      if (x > y || x == y) System.out.println(y);
      else System.out.println(x);
    }
    else{
      if (x > y || x == y){
        x = x % y;
        small = x;
      }
      else{
        y = y % x;
        small = y;
      }

      for (int i = 1; i <= small; i++){
        if ((x % i == 0) && (y % i == 0)){
          gcd = i;
        }
      }
      System.out.println(gcd);
    }
  }
}


Measured memory_bytes: 26380
from sys import stdin
import numpy as np

S = stdin.readline().rstrip().split()[0]

Frag = False
if S[0]==S[1]:
    Frag=True
elif S[1]==S[2]:
    Frag=True
elif S[2]==S[3]:
    Frag=True
if Frag:
    print("Bad")
else:
    print("Good")


Measured memory_bytes: 21536
N,M=map(int,input().split())
A=[];B=[]
for i in range(N):
    Ai=input()
    A.append([Ai[j]=='#' for j in range(N)])
for i in range(M):
    Bi=input()
    B.append([Bi[j]=='#' for j in range(M)])
fans=False
fnext=False
for k in range(N-M+1):
    if fans:
        break
    for l in range(N-M+1):
        if fans:
            break      
        if fnext:
            fnext=False
        for i in range(M):
            if fnext:
                break
            for j in range(M):                    
                if A[k+i][l+j]!=B[i][j]:
                    fnext=True
                    break
                if i==j==M-1:
                    fans=True

print('Yes' if fans else 'No')

Measured memory_bytes: 39152
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

a, b, k = map(int, input().split())

ans = []

for i in range(1, min(a, b) + 1, 1):
    if a % i == 0 and b % i == 0:
        ans.append(i)

print(ans[-k])

Measured memory_bytes: 5120
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        N: i32,
        D: [i32; N],
    };
    let s: i32 = D.iter().sum();
    let mut r = 0;
    for d in D.iter() {
        r += d * (s - d);
    }
    println!("{}", r / 2);
}


Measured memory_bytes: 2148
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl                endl

using namespace std;
const int MOD    = 998244353;
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int x, int y) {                                                             //return x^y in order(log(y))
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
struct trio {
  T first{};
  T second{};
  T third{};
};
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}
int x, y;
int ext_gcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return 0;
  }
  int d = ext_gcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

int inv(int n) {
  ext_gcd(n, MOD, x, y);
  return x;
}
class FKnapsackForAllSubsets {
public:
  static void solve(istream &cin, ostream &cout) {
    int N, S;
    cin >> N >> S;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    map<int, int> check;
    check[0] = bpm(2, N);
    int two  = inv(2);
    rep(i, N) {
      FOR(j, check) {
        if (abs(j.first - A[i]) <= S + 1) {
          check[j.first - A[i]] += j.second * two;
          check[j.first - A[i]] %= MOD;
        }
      }
    }
    cout << mod(check[-S], MOD) << endl;
  }
};


signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  FKnapsackForAllSubsets solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
#include <set> 
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a.at(i);
  }
  set<int> s;
  rep(i,n){
    s.insert(a.at(i));
  }
  if(s.size()==n)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  
  



}


Measured memory_bytes: 10368
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int N, M, X;
  cin >> N >> M >> X;
  int C[N];
  long long A[N][M];
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  long long ans = 1e17;
  for (int i = 0; i < (1 << N); i++) {
    vector<int> R(M, 0);
    long long tmp = 0;
    for (int j = 0; j < N; j++) {
      if ((1 << j) & i) {
        for (int k = 0; k < M; k++) {
          R[k] += A[j][k];
        }
        tmp += C[j];
      }
    }
    bool suc = true;
    for (int j = 0; j < M; j++) {
      if (R[j] < X) suc = false;
    }
    if (suc) ans = min(ans, tmp);
  }
  if (ans == 1e17) cout << -1 << endl;
  else cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 3656
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void resolve() {
    int r,g;
    cin >> r >> g;
    cout << g+ (g - r) << endl;
}

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

Measured memory_bytes: 256
import sys
input=sys.stdin.readline

def main():
    X = input().strip()
    A = []
    for c in X:
        if len(A) > 0 and A[-1] == "S" and c == "T":
            A.pop()
        else:
            A.append(c)
    print(len(A))

if __name__ == '__main__':
    main()


Measured memory_bytes: 5096
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;
using namespace std;

const string YES = "YES";
const string NO = "NO";

void solve(std::string S) {
  ll ans = 0;

  for (char c : S) {
    ans += c == 'o';
  }

  ans += 15 - S.length();
  if (ans >= 8) {
    std::cout << YES << '\n';
  } else {
    std::cout << NO << '\n';
  }
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}

//


Measured memory_bytes: 256
//============================================================================
// Name        : AOJ.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){

	ll a,b,c,k;


	cin>>a>>b>>c>>k;

	if(k%2==0){
		cout<<a-b<<endl;
	}else{
		cout<<b-a<<endl;
	}






	return 0;
}


Measured memory_bytes: 256
N = int(input())
res = N
for i in range(N + 1):
	cc = 0
	t = i
	while t > 0:
		cc += int(t % 6)
		t = int(t / 6)
	t = N - i
	while t > 0:
		cc += int(t % 9)
		t = int(t / 9)
	if res > cc:
		res = cc
print(res)

Measured memory_bytes: 3064
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
        n:usize,m:usize,
        lr:[(Usize1,Usize1);m],
    }
    let mut lmax = 0;
    let mut rmax = n;
    for &(l, r) in lr.iter() {
        lmax = max(lmax, l);
        rmax = min(rmax, r + 1);
    }
    println!("{}", rmax.saturating_sub(lmax));
}


Measured memory_bytes: 4720
let a, b, c = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let p = if a > b then if a > c then b * c else a * b else if b > c then a * c else a * b
let _ = Printf.printf "%d\n" @@ if a mod 2 = 0 || b mod 2 = 0 || c mod 2 = 0 then 0 else p

Measured memory_bytes: 384
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

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

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

	if (((N[0] == N[1]) && (N[1] == N[2]))
		|| ((N[1] == N[2]) && (N[2] == N[3]))) {
		cout << "Yes" << endl;
	}
	else { 
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
LL flag[100010];
int main(){
    LCIN(N);LCIN(M);
    I vec;
    REP(a,N){
        LCIN(B);
        vec.push_back(B);
    }
    REP(a,N){
        flag[a+1] = flag[a]+vec.at(a);
    }
    LL co = 0;
    map<LL,LL> mp;
    for(int a = 0;a <= N;a++){
        mp[flag[a]%M]++;
    }
    for(auto que : mp){
        co += que.second *(que.second-1);
    }
    COUT(co/2);
    return 0;
}


Measured memory_bytes: 5368
N = int(input())
A = input()
B = []
count = 0
for i in range(1, len(A)):
  if A[i] != 'W':
    count += 1
B.append(count)
for i in range(1, len(A)):
  count = B[i - 1]
  if A[i - 1] != 'E':
    count += 1
  if A[i] != 'W':
    count -= 1
  B.append(count)
print(min(B))

Measured memory_bytes: 15520
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%d%c", arr[i], i == n ? '\n' : ' ');}}
void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%lld%c", arr[i], i == n ? '\n' : ' ');}}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
#define DEBUG_Switch 0
int n;
char s[maxn];
int main()
{
#if DEBUG_Switch
    freopen("C:\\code\\input.txt", "r", stdin);
#endif
    //freopen("C:\\code\\output.txt","w",stdout);
    n = readint();
    scanf("%s", s + 1);
    int cntw = 0;
    int cntr = 0;
    repd(i, 1, n)
    {
        if (s[i] == 'W')
        {
            cntw++;
        } else
        {
            cntr++;
        }
    }
    int ans = 0;
    repd(i, 1, cntr)
    {
        if (s[i] == 'W')
        {
            ans++;
        }
    }
    ans = min(ans, cntr);
    ans = min(ans, cntw);
    printf("%d\n", ans );
    return 0;
}




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

int main() {
  int n, t, a, h;
  std::cin >> n >> t >> a;
  
  int min, minnum;
  min = 100000000;
  minnum = 0;
  
  int tdif;
  for (int i = 0; i < n; i++) {
    std::cin >> h;
    tdif = 1000 * t - 6 * h > 1000 * a ? 1000 * t - 6 * h - 1000 * a : 1000 * a - (1000 * t - 6 * h);
    if (tdif < min) {
      min = tdif;
      minnum = i+1;
    }
  }
  std::cout << minnum << '\n';
}

Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int64_t i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> A(N);
  rep(i, N) {
    cin >> A[i];
    A[i]--;
  }

  int64_t prologue = 0;
  int64_t count = 0;
  int64_t now = 0;
  unordered_map<int64_t, int64_t> town;
  for (int64_t i = 0;; ++i) {
    if (town.count(now)) {
      prologue = town[now];
      count -= prologue;
      break;
    }
    count++;
    town[now] = i;
    now = A[now];
  }

  int64_t now2 = 0;
  if (prologue < K) {
    rep(i, prologue) { now2 = A[now2]; }
    K -= prologue;
    K %= count;
    rep(i, K) { now2 = A[now2]; }
  } else {
    rep(i, K) { now2 = A[now2]; }
  }
  cout << now2 + 1 << endl;
  return 0;
}


Measured memory_bytes: 12836
using System;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class program{
  static void Main(string[] args){
    program p = new program();
    p.Run();
  }
  void Run(){
	int N=Readint()[0];
    int[] A = Readint();
    double f=0;
    for(int i=0;i<N;i++)
      f += 1.0/A[i];
    WriteLine((1.0/f).ToString());
  }

  int[] Readint(){
    string[] s = ReadLine().Split();
    int[] res=new int[s.Length];
    Parallel.For(0,s.Length,i=>{
      res[i]=int.Parse(s[i]);
    });
    return res;
  }
}


Measured memory_bytes: 13020
#include <bits//stdc++.h>
using namespace std;
int main(void){
    int a,b,c,i,j,h;
    int movenum[26];
    for(i=0;i<26;i++)
    movenum[i]=0;
    cin>>a;
    string entra,exi;
    cin>>entra>>exi;
    for(i=0;i<a-1;i++){
        b=exi[i]-0x61;
        c=entra[i]-0x61;
        if(i==0)
        movenum[c]=1;
        else
        movenum[c]=(movenum[b]+movenum[c])%1000000007;
    }
    h=exi[a-1]-0x61;
    cout<<movenum[h]<<endl;
    
}



Measured memory_bytes: 3292
n = int(input())
n2 = n
cnt = 0
while n>0:
	cnt += 1
	n = n // 10
if cnt == 1:
	print(n2)
elif cnt == 2:
	print(9)
elif cnt == 3:
	print(9 + (n2-100+1))
elif cnt == 4:
	print(9 + 900)
elif cnt == 5:
	print(9 + 900 + (n2-10000+1))
elif cnt == 6:
	print(9 + 900 + 90000)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl;
using ll=long long;
const ll INF=1LL<<60;



ll modpow(ll a,ll b,ll mod){
  if(b==0)return 1%mod;
  ll u=modpow(a,b/2,mod);
  u=(u*u)%mod;
  if(b%2)u=(a*u)%mod;
  return u;
}

int main(){
  int n,k;
  cin >> n >> k;
  int mod=1E9+7;
  ll pcs[k+1];
  for(int i=1;i<=k;i++)pcs[i]=modpow(k/i,n,mod);
  for(int i=k;i>=1;i--){
    for(int j=2*i;j<=k;j+=i){
      pcs[i]=(pcs[i]-pcs[j]+mod)%mod;
    }
  }
  ll ans=0;
  for(int i=1;i<=k;i++){
    ans+=(pcs[i]*i)%mod;
    ans%=mod;
  }

  cout << ans << endl;
}


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

int main(){
  string S;
  cin >> S;
  int ans=0;
  int L=S.size();
  for(int i=0; i<L/2; i++){
      if(S.at(i)!=S.at(L-1-i)) ans++;
  }
  cout << ans << endl;
}

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

int main(){
  int i,j;ll cnt=0;
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  int c[h][w];
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if((i<b && j<a) || (i>=b && j>=a))c[i][j]=1;
      else c[i][j]=0;
    }
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      cout<<c[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define P pair<ll,ll>
const ll mod = 1e9+7;
const ll INF = 2e12;
const int inf = -1*((1<<31)+1);
 
using namespace std;

struct edge{
	int to;
	int cost;
};

void dijkstra(ll S,vector<vector<ll>> &dist,vector<vector<edge>> &g){
	priority_queue<P,vector<P>,greater<P>> q;
	dist[S][0] = 0;
	q.push(P(0,S));
	//コスト0でSから開始する
	while(!q.empty()){
		P now = q.top();q.pop();
		ll c  = now.first;//(スタート地点からの移動回数)%3
		ll v  = now.second;//今いる頂点
		//if(dist[v][c%3]<c)continue;
		for(int i=0;i<g[v].size();i++){
			edge nextedge = g[v][i];
			if(dist[nextedge.to][(c+1)%3]>dist[v][c%3]+nextedge.cost){
				dist[nextedge.to][(c+1)%3]=dist[v][c%3]+nextedge.cost;
				q.push(P(c+1,nextedge.to));
			}
		}
	}
}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,S,T;
	cin >> N >> M;
	vector<vector<ll>> dist(N,vector<ll>(3,INF));
	//dist[i][j]:= 頂点iにj歩目で行くのにかかる最短コスト
	vector<vector<edge>> g(N);
	rep(i,M){
		int a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back({b,1});

	}
	cin >> S >> T;
	S--;T--;
	dijkstra(S,dist,g);
	cout << (dist[T][0] != INF?dist[T][0]/3:-1) << endl;
}

Measured memory_bytes: 11264
#空リスト作成
num_list = []
line = []
#入力値を全てリストに格納
for num in range(28):
    num_list.append(int(input()))
#リストにない関数をべつのリストに追加する
for num1 in range(1,31):
    if num1 in num_list:
        continue
    else:
        line.append(num1)
#出力
print(min(line))
print(max(line))


Measured memory_bytes: 5596
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

const int maxn = 1e5;

int n;
vector<int> g[maxn];
int size[maxn], deg[maxn];

vector<int> path;
bool fail;

void Dfs1(int u, int p) {
  path.push_back(size[u]);
  int cnt = 0;
  for (int v : g[u]) {
    if (v != p && size[v] >= 0) {
      ++cnt;
      Dfs1(v, u);
    }
  }
  if (cnt >= 2) fail = true;
}

void Exit(void) {
  puts("-1");
  exit(0);
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  if (n == 2) {
    puts("1 2");
    return 0;
  }

  for (int i = 0; i < n; ++i) {
    if (g[i].size() == 1) {
      size[i] = -1;
      int j = g[i][0];
      ++size[j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j : g[i]) {
      if (size[i] >= 0 && size[j] >= 0) {
        ++deg[i];
      }
    }
  }

  int start = -1;
  for (int i = 0; i < n; ++i) {
    if (size[i] >= 0 && deg[i] <= 1) {
      start = i;
      break;
    }
  }
  if (start == -1) throw;
  fail = false;
  path.clear();
  Dfs1(start, -1);
  if (fail) Exit();

  int cnt_cent = 0;
  for (int i = 0; i < n; ++i) {
    cnt_cent += (size[i] >= 0);
  }
  if (path.size() != cnt_cent) Exit();

  if (path[0] >= 1) {
    --path[0];
    path.insert(path.begin(), 0);
  }
  if (path.back() >= 1) {
    --path.back();
    path.push_back(0);
  }
  for (int i = 0, j = (int)path.size() - 1; i < path.size(); ++i, --j) {
    if (path[i] != path[j]) {
      if (path[i] > path[j]) {
        reverse(path.begin(), path.end());
      }
      break;
    }
  }

  int val = 1;
  for (int a : path) {
    for (int i = 0; i < a; ++i) {
      printf("%d ", val + i + 1);
    }
    printf("%d ", val);
    val += a + 1;
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 11896
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n;
int arr[N];
long long l , r;
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , arr + i);
	}
	l = 2;
	r = 2;
	for(int i = n ; i >= 1 ; --i){
		long long cnt = (r / arr[i]) - ((l - 1) / arr[i]);
		if(cnt){
			long long x = (l / arr[i]) * arr[i];
			while(x < l){
				x += arr[i];
			}
			long long y = (r / arr[i]) * arr[i];
			while(y <= r){
				y += arr[i];
			}
			l = x;
			r = y - 1;
			if(l > r){
				printf("-1\n");
				return 0;
			}
		}
		else{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld %lld\n" , l , r);
}

Measured memory_bytes: 640