akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>

#define rep(i,p,n) for(int i=p;i<n;i++)
#define lli long long int
#define vi vector<int> 

using namespace std;

void p(int x) {
	cout << x << endl;
}

void pp(string s) {
	cout << s << endl;
}


int main() {
	string s;
	cin >> s;
	rep(i, 0, 4) cout << (s[i]) ;
	cout << " ";
	rep(i, 4, s.length()) cout<<s[i];

	cout << endl;




	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
inline 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()
{
	cout<<min(read(),read())+min(read(),read()); 
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <iomanip>
#include <cmath>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

int main()
{
    // 整数の入力
    ll P,Q,R;
    cin >> P >> Q >> R;

    cout << min(min(P+Q,Q+R),R+P)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#include <string>
#define rep(i,n) for (int i = 0; i< (n); i++)
using namespace std;

int main() {
  int N;

  cin>>N;
  
  
  cout<<N*N<<endl;
  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
count = 0
sum_A = 0

for i in range(N):
    if A[i] < 0:
        count += 1
    A[i] = abs(A[i])
    sum_A += A[i]

if count % 2 == 0:
    print(sum_A)
else:
    print(sum_A - 2*min(A))

Measured memory_bytes: 14412
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; ++i)
    cin >> S[i];
  map<string, int> m;
  for (int i = 0; i < N; ++i)
    ++m[S[i]];
  int a = 0;
  for (auto &i : m)
    a = max(i.second, a);
  for (auto &i : m)
    if (i.second == a)
      cout << i.first << endl;
}


Measured memory_bytes: 27392
# C
from bisect import bisect
import math
x1, y1, x2, y2 = map(int, input().split())
N = int(input())

xL = min(x1, x2)
xR = max(x1, x2)
yL = min(y1, y2)
yR = max(y1, y2)

xyl = []

if x1 < x2 and y1 > y2:
    direction = 'rightdown'
elif x1 > x2 and y1 < y2:
    direction = 'rightdown'
else:
    direction = 'rightup'
    
    
# sort
if direction == 'rightup':
    for _ in range(N):
        x, y = map(int, input().split())
        if xL <= x and x <= xR and yL <= y and y <= yR:
            xyl.append((x, y-yL))
else:
    for _ in range(N):
        x, y = map(int, input().split())
        if xL <= x and x <= xR and yL <= y and y <= yR:
            xyl.append((x, yR-y))

ind = len(xyl)
xyl.sort()

# calculate
dp = [yR-yL+1]*(ind)
for i in range(ind):
    _, y = xyl[i]
    dp[bisect(dp,y)] = y
count_ = bisect(dp,yR-yL)

diff = 5*math.pi - 20
diff2 = 10*math.pi - 20
if count_ == min((xR-xL), (yR-yL)) + 1:
    print(100*((xR-xL) + (yR-yL)) + (count_-1)*diff + diff2)
else:
    print(100*((xR-xL) + (yR-yL)) + count_*diff)

Measured memory_bytes: 31716
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
//树的重建

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
    if ( l >= r ) return;
    int root = pre[pos++];
    int m = distance(in.begin(), find(in.begin(), in.end(), root));
    rec(l, m);
    rec(m + 1, r);
    post.push_back(root);
}

void solve() {
    pos = 0;
    rec(0, pre.size());
    for (int i = 0; i < n; i++) {
        if ( i ) cout << " ";
        cout << post[i];
    }
    cout << endl;
}

int main() {
    int v;
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> v;
        pre.push_back(v);
    }

    for (int i = 0; i < n; i++) {
        cin >> v;
        in.push_back(v);
    }

    solve();
    
    return 0;  
}



Measured memory_bytes: 3172
N, Q = map(int, input().split())
S = str(input())
W = [0] * (N+1)
L = []
R = []
for q in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for n in range(N-1):
    W[n+1] = W[n] + (1 if S[n:n+2] == 'AC' else 0)    

for q in range(Q):
    print(W[R[q]-1]-W[L[q]-1])

Measured memory_bytes: 15808
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
	int n,d;
    cin>>n>>d;
    vector<vector<int>> a(n,vector<int>(d));
    rep(i,n){
        rep(j,d){
            cin>>a[i][j];
        }
    }
    int cnt=0;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            int sum=0;
            for(int k=0;k<d;k++){
                sum+=pow(abs(a[i][k]-a[j][k]),2);
            }
            double b=sqrt(sum);
            if(ceil(b)==floor(b)){
                cnt++;
            }
        }
    }
    cout<<cnt<<endl; 
}


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

using namespace std;


int main(){
	
	//xx = rx - D
	long long r,x,D;
	cin >> r >> D >> x;
	for(int i=1;i<=10;i++){
		
		cout << r*x - D << "\n";
		x = r*x - D;
	}
}

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

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pll = pair<ll, ll>;

#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair


template <typename T>
using vv = vector<vector<T>>;

void solve() {
    int n; cin >> n;
    vector<string> s(n);
    vector<string> rs(n);


    vi c(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i] >> c[i];
        rs[i] = s[i];
        reverse(all(rs[i]));
    }
    multiset<string> used1, used2;

    ll MX = 1e18;
    ll res = MX;
    ll tmp = 0;

    auto bigger = [&](string s1, string s2) -> bool {
        if (s1.size() < s2.size()) return 0;
        for (int i = 0; i < s2.size(); i++)
            if (s1[i] != s2[i]) return 0;
        return 1;
    };

    auto pal = [&](string s) {
        string t = s;
        reverse(all(t));
        return (t == s);
    };

    function<void(string, int)> rec = [&](string need, int side) {
        if (pal(need)) {
            res = min(res, tmp);
            return;
        }
        if (side == 1) {
            if (used1.count(need)) return;
            used1.insert(need);
            for (int i = 0; i < n; i++) {
                tmp += c[i];
                if (bigger(need, rs[i])) {
                    string nneed = need.substr(rs[i].size(), need.size() - rs[i].size());
                    
                    if (pal(nneed)) res = min(res, tmp);

                    else rec(nneed, 1);
                }
                if (bigger(rs[i], need)) {
                    
                        string nneed = rs[i].substr(need.size(), rs[i].size() - need.size());
                    
                        if (pal(nneed)) res = min(res, tmp);
                        else rec(nneed, 2);
                    
                }
                tmp -= c[i];
            }
            used1.erase(used1.find(need));
        } else {
            if (used2.count(need)) return;
            used2.insert(need);
            for (int i = 0; i < n; i++) {
                tmp += c[i];
                if (bigger(need, s[i])) {
                    
                        string nneed = need.substr(s[i].size(), need.size() - s[i].size());
                        
                        if (pal(nneed)) res = min(res, tmp);
                        else rec(nneed, 2);
                    
                }
                if (bigger(s[i], need)) {
                    
                        string nneed = s[i].substr(need.size(), s[i].size() - need.size());
                        
                        if (pal(nneed)) res = min(res, tmp);
                        else rec(nneed, 1);
                    
                }
                tmp -= c[i];
            }
            used2.erase(used2.find(need));
        }
    };

    for (int i = 0; i < n; i++) {
        tmp += c[i];
        rec(s[i], 1);
        tmp -= c[i];
    }

    cout << ((res == MX) ? -1 : res);

}



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define read() freopen("C:\\Users\\Mehedi\\Desktop\\input.txt","r",stdin)
#define write() freopen("C:\\Users\\Mehedi\\Desktop\\output.txt","w",stdout)
#define debug(x) cout<< #x<<" = "<<x<<endl;
#define dbg(x,y) cout<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<endl;
#define optimizar ios_base::sync_with_stdio(0); cin.tie(0)
#define mx 44721
#define mod  1000
void File_IO () {
  #ifndef ONLINE_JUDGE 
  read();write();
  #endif
}
using namespace std;
typedef long long ll ;
int a[55][55],b[55][55];
int main(){
	//File_IO();
	int n;
	cin>>n;
	int arr[n];
	for(int i = 0;i<n;i++)cin>>arr[i];
	int mini = INT_MAX;
	for(int i = 1;i<=100;i++){

		int cnt = 0;
		for(int j = 0;j<n;j++){
			cnt+= (i-arr[j]) *(i-arr[j]);
		}
		mini = min(cnt,mini);
	}
	cout<<mini<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    unsigned long long int a,b,t,x,gcd;
    while(scanf("%llu %llu",&a,&b)!=EOF)
    {
     unsigned long long int lcm,m=a,k=b;
        if(a==0) gcd=a;
        else if(b==0) gcd=b;
        else {
        while(b!=0)
        {
             t=b;
             b=a%b;
             a=t; 
             }
             gcd=a;
                  }
          lcm=m*k/gcd;
          printf("%llu %llu\n",gcd,lcm);
         }
   return 0;
}

Measured memory_bytes: 1740
#include<iostream>

using namespace std;

int main(void)
{
	int a,b;
	
	cin>>a>>b;
	
	if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
	{
		cout<<"Possible\n";
		return 0;
	}
	
	cout<<"Impossible\n";
	return 0;
	
}

Measured memory_bytes: 256
'''
問題：
    英小文字からなる文字列 s が与えられます。
    前から数えて奇数文字目だけ抜き出して作った文字列を出力してください。
    ただし、文字列の先頭の文字を1文字目とします。
'''

'''
制約：
    s の各文字は英小文字
    1 ≦ |s| ≦ 100000
'''

# 標準入力から s を取得する
s = str(input())

i = 1
result = ""
for i in range(len(s) + 1):
    if i % 2 == 0:
        pass
    else:
        result += s[i - 1]

print(result)


Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
// const int N = ;

int k, temp;

void solve() {
    cin >> k;
    temp = 0;
    for(int ans = 1; ans <= (int)1e6; ans++) {
        temp = (temp * 10 + 7) % k;
        if(!temp) {
            cout << ans << '\n';
            return;
        }
    }
    cout << "-1\n";
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 3688
#include<stdio.h>
#include<string.h>
int main()
{
	char s[11];
	char t[11];
	char u[11];
	int x,y;
	scanf("%s %s",&s,&t);
	scanf("%d %d",&x,&y);
	scanf("%s",&u);
	if(strcmp(u,s) == 0){
		printf("%d %d",x-1,y );
}
	else if (strcmp(u,t) == 0) {
		printf("%d %d", x, y - 1);	
}
	return 0;
}

Measured memory_bytes: 1724
#include <stdio.h>

int main()
{   long long n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);
    if(b<a||(a!=b&&n==1)){
        printf("0");
    }else if(a==b){
        printf("1");
    }else
    printf("%lld",(n-2)*(b-a)+1);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <iomanip>

int main(){
  lli w, h, x, y;
  cin >> w >> h >> x >> y;

  long double menseki = w * h * 1.0;
  cout << fixed << setprecision(9) << menseki / 2.0 << ' ';
  
  if(w % 2 == 0 && w / 2 == x && h % 2 == 0 && h / 2 == y)
    cout << 1 << endl;
  else
    cout << 0 << endl;


}


Measured memory_bytes: 256
H, W = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(H)]

A = W+1
identity = -(1<<62)
sqrtA = 500
n_buckets = A // sqrtA + 1
Data = [0] * (n_buckets * sqrtA)
Data[0] = 1<<30
Bucket_min = [0] * n_buckets
Lazy = [identity] * n_buckets

def eval_data(k):
    if Lazy[k] != identity:
        l, r = k*sqrtA, (k+1) * sqrtA
        for i in range(l, r):
            Data[i] = i-Lazy[k]
        Lazy[k] = identity

def update(s, t, x):
    for k in range(s//sqrtA, (t-1)//sqrtA+1):
        l, r = k*sqrtA, (k+1)*sqrtA
        if s <= l and r <= t:
            Bucket_min[k] = l-x
            Lazy[k] = x
        else:
            eval_data(k)
            for i in range(max(l,s), min(r,t)):
                Data[i] = i-x
            Bucket_min[k] = min(Data[l:r])

def get_min(s, t):
    res = 1 << 62
    bl, br = s//sqrtA+1, t//sqrtA
    if bl > br:
        eval_data(br)
        return min(Data[s:t])
    if bl < br:
        res = min(Bucket_min[bl:br])
    ll, rr = bl*sqrtA, br*sqrtA
    if s < ll:
        eval_data(bl-1)
        mi = min(Data[s:ll])
        if res > mi:
            res = mi
    if rr < t:
        eval_data(br)
        mi = min(Data[rr:t])
        if res > mi:
            res = mi
    return res

Ans = []
for i, (a, b) in enumerate(AB, 1):
    update(a, b+1, a-1-get_min(a-1, a))
    ans = get_min(1, W+1)
    Ans.append(ans + i if ans < 1<<25 else -1)
print("\n".join(map(str, Ans)))


Measured memory_bytes: 146000
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	int cnt = 0;
	rep(i, n) {
		if (s[i] == 'R') {
			cnt++;
		}
	}
	Yes((double)n / 2 < cnt);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Read();
            if (S[2] == S[3] && S[4] == S[5])
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main() {
  int h,w; cin >> h >> w;
  vector<vector<char>> table(h,vector<char>(w));

  vector<bool> hd(h,0);//1は残す行
  vector<bool> wd(w,0);//1は残す列
  
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cin >> table[i][j];
      if(table[i][j]=='#'){
        hd[i] = 1;
        wd[j] = 1;
      }
    }
  }
  
  vector<vector<char>> ans(h,vector<char>(w));
  int ansi=0,ansj=0;
  
  for(int i=0; i<h; i++){
    if(hd[i]==1){
      ansj=0;
      for(int j=0; j<w; j++){
        if(wd[j]==1){
          ans[ansi][ansj] = table[i][j];
          ansj++;
        }
      }
      ansi++;
    }
  }
  for(int i=0; i<ansi; i++){
    for(int j=0; j<ansj; j++){
      cout << ans[i][j];
      if(i!=ansi-1 && j==ansj-1) cout << endl;
    }
  }
}  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
vvl G;
ll dfs(int v){
  ll res=1;
  for(auto nv:G[v]){
    res+=dfs(nv);
  }
  return res;
}
    
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  ll n,k;
  cin >> n >> k;
  
  ll cnt1=0,cnt2=0;
  exrep(i,1,n){
    if(i%k==0)cnt1++;
    if(k%2==0 && i%k==k/2)cnt2++;
  }
  ll ans=pow(cnt1,3) +pow(cnt2,3);
  cout << ans << endl;
  
    
  
}


Measured memory_bytes: 12160
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

template <long long mod>
long long mod_pow(long long a, long long b) {
    if (b == 0) return 1;
    long long ret = mod_pow<mod>(a, b / 2);
    ret = ret * ret % mod;
    if (b % 2 == 1) ret = a * ret % mod;
    return ret;
}

const ll MOD = TEN(9) + 7;
int n;
ll a[10000];
map<int, int> fact;

void factorize(int x) {
    for (ll i = 2; i * i <= x; i++) {
        int cur = 0;
        while (x % i == 0) {
            cur++;
            x /= i;
        }
        chmax(fact[i], cur);
    }
    if (x != 1) chmax(fact[x], 1);
}

int main() {
    fastio();

    cin >> n;
    forn(i, n) {
        cin >> a[i];
        factorize(a[i]);
    }

    ll total = 1;
    for (auto p : fact) {
        total = total * mod_pow<MOD>(p.fst, p.snd) % MOD;
    }

    ll ans = 0;
    forn(i, n) {
        ans = (ans + total * mod_pow<MOD>(a[i], MOD - 2) % MOD) % MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 896
//2013-5

#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <time.h>
#define mp make_pair
#define fs first
#define sc second
#define rep(x,n) for(int x = 0;x < n;x ++)
#define Rep(x,n) for(int x = 1;x <= n;x ++)
using namespace std;

char retcol(char c1,char c2){
    if((c1 == 'g' && c2== 'r')||(c1 == 'r' && c2== 'g'))
        return 'b';
    else if((c1 == 'b' && c2 == 'r')||(c1 == 'r' && c2 == 'b'))
        return 'g';
    else
        return 'r';
}

int n;

bool issame(string xx){
    int nu = xx.size();
    rep(i,nu-1)
        if(xx[i]!=xx[i+1])
            return 0;
    return 1;
}

int main(){

    bool tf = 0;
    string str,next;
    while(cin >> str&&str != "0"){
        queue<string> que;
        que.push(str);
        tf = 0;
        n = str.size();
        //この時点で判定
        if(issame(str)){
            printf("0\n");
            continue;
        }
        map<string,int> flag;
        flag.insert(make_pair(str,0));
        //探索
        while(!que.empty()&& tf == 0){
            string str = que.front();
            que.pop();
            if(flag.find(str)==flag.end())
                continue;
            int num = flag.find(str)->second;
            rep(i,n-1){
                if(str[i]!=str[i+1]){
                    next = str;
                    next[i]=retcol(str[i],str[i+1]);
                    next[i+1]=next[i];
                    if(issame(next)){
                        tf = 1;
                        cout << num + 1 << endl;
                        break;
                    }
                    if(flag.find(next)==flag.end()){
                        que.push(next);
                        flag.insert(make_pair(next,num+1));
                    }
                    
                }
            }
        }
        if(tf == 0){
            printf("NA\n");
        }
    }
}

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

int memo[2][200005],p[2]={},ma[2]={};
multiset<int> edge[200005];

void dfs(int now,int phase)
{
	for (auto i = edge[now].begin(); i != edge[now].end(); ++i)
	{
		if (memo[phase][*i]==-1)
		{
			memo[phase][*i]=memo[phase][now]+1;
			if (memo[phase][*i]>ma[phase])
			{
				ma[phase]=memo[phase][*i];
				p[phase]=*i;
			}
			dfs(*i,phase);
		}
	}
}

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a,b;
	for (int i = 0; i < n-1; ++i)
	{
		cin>>a>>b;--a;--b;
		edge[a].insert(b);
		edge[b].insert(a);
	}
	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			memo[i][j]=-1;
		}
	}
	memo[0][0]=0;
	dfs(0,0);
	memo[1][p[0]]=0;
	dfs(p[0],1);
	if (ma[1]%3==1)
	{
		cout<<"Second\n";
	}
	else
	{
		cout<<"First\n";
	}
	return 0;
}


Measured memory_bytes: 42368
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
 
  int N , M ;
  int ans = 0 ;
  cin >> N >> M ;
  vector<int> A(M) ;
  rep(i,M){
    cin >> A.at(i) ;
    ans += A.at(i) ;
  }
  if( ans >= N ) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000;

typedef long long ll;
typedef unsigned long long ull;

ll dp[1010][3][1010];

ll f(ll x, ll n, ll *a) {
  ll re = 0;
  rep(i, n) {
    if (a[i] >= x) re += n;
    else {
      ll key = x - a[i];
      ll le = -1, ri = n, med;
      while (ri - le > 1) {
	med = (ri + le) >> 1;
	if (a[med] >= key) le = med;
	else ri = med;
      }
      re += ri;
    }
  }
  return re;
}

ll g(ll x, ll n, ll *a, ll *r) {
  ll sum = 0;
  rep(i, n) {
    if (a[i] >= x) sum += r[n] + n * a[i];
    else {
      ll key = x - a[i];
      ll le = -1, ri = n, med;
      while (ri - le > 1) {
	med = (ri + le) >> 1;
	if (a[med] >= key) le = med;
	else ri = med;
      }
      sum += r[ri] + ri * a[i];
    }
  }
  return sum;
}


      

int main(void) {
  ll n, m;
  cin >> n >> m;
  ll a[100010];
  rep(i, n) {
    cin >> a[i];
    a[i] = -a[i];
  }

  sort(a, a + n);
  rep(i, n) a[i] = -a[i];

  ll r[100010];
  rep(i, n) r[i + 1] = r[i] + a[i];

  ll s = 0, b = 20000000000, med;
  while (b - s > 1) {
    med = (b + s) >> 1;
    if (f(med, n, a) >=m) s = med;
    else b = med;
  }
  cout << g(s, n, a, r) - s * (f(s, n, a) - m) << endl;

  return 0;
}


Measured memory_bytes: 1792
n, m = map(int, input().split())
students = [list(map(int, input().split())) for _ in range(n)]
checkpoints = [list(map(int, input().split())) for _ in range(m)]

def dist(si, cj):
    return abs(students[si][0] - checkpoints[cj][0]) + abs(students[si][1] - checkpoints[cj][1])

ans = []
for i in range(n):
    ans_i = 0
    for j in range(1, m):
        if dist(i, ans_i) > dist(i, j):
            ans_i = j
    ans.append(ans_i+1)

print(*ans, sep='\n')


Measured memory_bytes: 3064
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	ll t = 0;
	ll ans = 0;
	rep(i,n){
		ll a;
		cin>>a;
		ll tt = (t+a)/2;
		ans += tt;
		// cout<<t<<" "<<a<<" "<<ans<<endl;
		t = (t+a)&1 && a>0;
	}
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 256
import sys
from itertools import permutations
from math import sqrt

def solve():
    input = sys.stdin.readline
    N = int(input())
    coordinate = dict()
    for i in range(N):
        coordinate[i] = tuple(map(int, input().split()))

    total_length = 0
    perm_count = 0
    for p in permutations(range(N)):
        perm_count += 1
        current_id = coordinate[int(p[0])]
        for j in range(1, N):
            next_id = coordinate[int(p[j])]
            total_length += sqrt((current_id[0] - next_id[0]) ** 2 + (current_id[1] - next_id[1]) ** 2)
            current_id = next_id

    print(total_length / perm_count)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;

int main(){
    int n;
    cin  >> n;
    vector<double> vec(n);

    REP(i,n){
        cin >> vec[i];
    }

    SORT(vec);

    REP(i,n-1){
        vec[i+1] = (vec[i]+ vec[i+1])/2;
    
    }
    cout << vec[n-1] <<endl;
}






Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static boolean hasOdd(long[] a) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] % 2 == 1) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }

        int count = 0;
        while (true) {
            if (hasOdd(a)) {
                break;
            }
            count++;
            for (int i = 0; i < n; i++) {
                a[i] /= 2;
            }
        }
        System.out.println(count);
    }

}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string s,t;
vector<int> v[26];
int main(){
    cin>>s>>t;
    int x=0,y;
    long long ans=0;
    for(int i=0;i<s.size();i++)v[s[i]-'a'].push_back(i+1);
    for(int i=0;i<t.size();i++){
        int c=t[i]-'a';
        if(v[c].size()==0){
            cout<<-1;
            return 0;
        }
        if(v[c][v[c].size()-1]<=x){
            y=v[c][0];
            ans+=y+s.size()-x;
        }else{
            y=*upper_bound(v[c].begin(),v[c].end(),x);
            ans+=y-x;
        }x=y;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1216
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
 
 
using namespace std;
 
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
 
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}
#define int long long
#define left left228
#define right right228
#define prev prev228
#define mp make_pair
#define all(v) v.begin(), v.end()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define firn(i, n) for (int i = 1; i < (int)n; ++i)
#define x first
#define y second


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = (int)s.size();
    vector<int> v;
    for (char c : s) {
        if (c == 'T') {
            if (v.empty()) {
                continue;
            } else {
                v.pop_back();
                n -= 2;
            }
        } else {
            v.push_back(1);
        }
    }
    cout << n << '\n';
    return 0;
}

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

using namespace std;
const long long INF = (long long) (1e18)+1;
// 5
// 1 3 4 5 7

int main() {
  int n;
  cin >> n;
  int ans = 0;

  for (int i=1; i<=n; ++i) {
    int temp;
    cin >> temp;
    if (i % 2 == 1 && temp % 2 == 1) {
      ans++;
    }
  }

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

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
const int INF = 1001001001;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define re0 return 0

int npr(int n , int r){//nPr
    r = n - r;
    int sum = 1;
    int i;
    for (i=n;i>=r+1;i--)sum*=i;
    return sum;
}
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 digsum(int n) {//桁和
    int res = 0;
    while(n > 0) {
        //res += n%10;
        //　↑をres++;にすれば桁数
         res++;
        n /= 10;
    }
    return res;
}
bool isPrime(int x){//素数
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
/*bit全探索
for (int bit = 0; bit < (1<<N); ++bit) {
}
if (bit & (1 << i)) {
}
*/


signed main(){ 
    int n; cin >> n;
    n%=10;
    vector<string>d(10);
    d[0]="pon";
    d[1]="pon";
    d[2]="hon";
    d[3]="bon";
    d[4]="hon";
    d[5]="hon";
    d[6]="pon";
    d[7]="hon";
    d[8]="pon";
    d[9]="hon";
    cout << d[n] <<endl;
    re0;
}


Measured memory_bytes: 3596
import math
a,b,x=map(int,input().split())

y=math.degrees(math.atan((2*((a**2)*b-x))/(a**3)))
z=math.degrees(math.atan(a*(b**2)/(2*x)))
if (a**2)*b/2<=x:
  print(y)
else:
  print(z)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
typedef long long int ll;
int a,b,c;
int main(){
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b<<'\n';
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

var M = 1000000000000
var b [100]int

func f(x int) [100]int {
	var a [100]int
	for i := 0; i < 100 && b[i] <= x; i++ {
		a[i] = (x - (b[i] - 1)) % (b[i] * 2)
		if a[i] >= b[i] {
			a[i] = 0
		}
		a[i] += ((x-(b[i]-1))/b[i] + 1) / 2 * b[i]
	}
	return a
}
func main() {
	b[0] = 1
	for i := 1; b[i-1] <= M; i++ {
		b[i] = b[i-1] + b[i-1]
	}
	var A, B int
	_, _ = fmt.Scan(&A, &B)
	var p = f(A - 1)
	var q = f(B)
	var ans = 0
	for i := 0; i < 100; i++ {
		if (q[i]-p[i])%2 == 1 {
			ans += b[i]
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const ll inf = 1000000000000000000ll;
int n, a[maxn];
signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i)
        if (a[i] == 0) {
            cout << "0" << endl;
            return 0;
        }
    ll ans = 1;
    for (int i = 1; i <= n; ++i) {
        if (inf / ans >= a[i]) ans = ans * a[i];
        else {
            cout << "-1" << endl;
            return 0;
        }
        if (ans > inf) {
            cout << "-1" << endl;
            return 0;
        }
    }
    return cout << ans << endl, 0;
}

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

int main()
{
  int x;
  for(int i=0; 1; i++){
    cin >> x;
    if(x == 0)
      break;
    else{
      cout << "Case " << i+1 << ": " << x << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 2980
/*
 * main.c
 *
 *  Created on: 2019/04/06
 *      Author: family
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int t[5] = {0};
int remain[5] = {0};

int main()
{
    int i = 0;
    int tem = 0;
    int ans = 0;
    for(i = 0; i < 5; i++) {
        scanf("%d", &t[i]);
        remain[i] = t[i]%10;
        if(remain[i] != 0) {
            ans += (t[i] - remain[i] + 10);
        } else {
            ans += t[i];
        }
    }

    for(i = 0; i < 5; i++) {
        if((remain[i] != 0) && (tem < (10 - remain[i]))) {
            tem = (10 - remain[i]);
        }
    }
    ans -= tem;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <fstream>
#include <cassert>
using namespace std;

#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define sz(a) int((a).size())
#define rep(i, s, n)  for(int i = s; i <= (n); ++i)
#define rev(i, n, s)  for(int i = (n); i >= s; --i)
#define fore(x, a) for(auto &&x : a)
typedef long long ll;
const int mod = 1000000007;
const int N = 100005;

vector<int> g[N];

int go(int x) {
  int mx = 0;
  vector<int> a;
  fore(y, g[x]) {
    a.emplace_back(go(y));
  }
  sort(a.begin(), a.end(), greater<int>());
  rep(i, 0, sz(a) - 1) {
    mx = max(mx, a[i] + i+1);
  }
  return mx;
}

int main() {
#ifdef loc
  if(!freopen((string(FOLDER) + "inp.txt").c_str(), "r", stdin)) {
    assert(0);
  }
  freopen((string(FOLDER) + "out.txt").c_str(), "w", stdout);
#endif
  boost;
  int n;
  cin >> n;
  rep(i, 2, n) {
    int x;
    cin >> x;
    g[x].emplace_back(i);
  }
  cout << go(1) << endl;
  return 0;
}

Measured memory_bytes: 13568
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    char s, t;
    cin >> s >> t;
    if(s < t) cout << '<' << endl;
    else if(s > t) cout << '>' << endl;
    else cout << '=' << endl;
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    string s; cin >> s;
    int n = s.size();
    sort( ALL( s ) );
    s.erase( unique( ALL( s ) ), s.end() );

    if( n == s.size() ) cout << "yes" << endl;
    else cout << "no" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	for (int n, m; cin >> n >> m&&n;) {
		vector<bool> out(n);
		int imo = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m;) {
				if (!out[(++imo) %= n])
					j++;
			}
			out[imo] = true;
			if (imo == 0)imo = n;
		}
		cout << imo << endl;
	}
	return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  int m = 3*n;
  vint a(m);
  rep(i, m) cin >> a[i];
  vint sum1(m, -inf);
  {
    priority_queue<int, vector<int>, greater<int>> que;
    sum1[n-1] = 0;
    rep(i, n) {
      que.push(a[i]);
      sum1[n-1] += a[i];
    }
    reps(i, n, m) {
      que.push(a[i]);
      sum1[i] = sum1[i-1]+a[i]-que.top();
      que.pop();
    }
  }
  vint sum2(m, -inf);
  {
    reverse(all(a));
    priority_queue<int> que;
    sum2[n-1] = 0;
    rep(i, n) {
      que.push(a[i]);
      sum2[n-1] += a[i];
    }
    reps(i, n, m) {
      que.push(a[i]);
      sum2[i] = sum2[i-1]+a[i]-que.top();
      que.pop();
    }
    reverse(all(a));
    reverse(all(sum2));
  }
  int ans = -inf;
  reps(i, n-1, m-n) {
    if(sum1[i] == -inf || sum2[i+1] == -inf) continue;
    chmax(ans, sum1[i]-sum2[i+1]);
  }
  cout << ans << endl;


  return 0;
}


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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  vi32 a(n), b(n);
  cin >> a >> b;
  rep(i, n) a[i]--, b[i]--;
  vector<vi32> dp(50, vi32(bit32(n), 1e9));
  dp[0][0] = 0;
  rep(s, bit32(n)) rep(i, 50) {
    if (dp[i][s] == 1e9) continue;
    int c = __builtin_popcount(s);
    rep(j, n) {
      if (s & bit32(j)) continue;
      int now = (c % 2 == j % 2) ? a[j] : b[j];
      if (i > now) continue;
      int f = j + __builtin_popcount(s & ((bit32(n) - 1) ^ (bit32(j) - 1)));
      amin(dp[now][s | bit32(j)], dp[i][s] + f - c);
    }
  }
  int ans = 1e9;
  rep(i, 50) amin(ans, dp[i][bit32(n) - 1]);
  if (ans == 1e9) ans = -1;
  cout << ans << endl;
}

Measured memory_bytes: 52736
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
#define pb  push_back
#define rep(var,n)  for(int var=0;var<(n);++var)
#define ALL(c)  (c).begin(),(c).end()
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
 
ll solve(int N, int K, vi& t, vi& d) {
    map<int,vi> stat;
    rep(i,N){
        stat[t[i]].pb(d[i]);
    }
    vi head, tail;
    for (auto p: stat) {
        sort(ALL(p.second));
        head.pb(p.second.back());
        p.second.pop_back();
        tail.insert(tail.end(), ALL(p.second));
    }
    sort(ALL(head), greater<int>());
    sort(ALL(tail), greater<int>());
    int H = head.size(), T = tail.size();
    vll head_acc(H+1), tail_acc(T+1);
    head_acc[0] = tail_acc[0] = 0;
    rep(i,H) head_acc[i+1] = head_acc[i] + head[i];
    rep(i,T) tail_acc[i+1] = tail_acc[i] + tail[i];
 
    ll best = 0;
    for (int kinds=1; kinds<=H; ++kinds) {
        if (IN(K-kinds, 0, T)) {
            ll score = (head_acc[kinds] + tail_acc[K-kinds]) + (ll)kinds*kinds;
            best = max(best, score);
        }
    }
    return best;
}
 
int main() {
    int N, K; scanf("%d%d", &N,&K);
    vi t(N), d(N);
    rep(i,N) scanf("%d%d", &t[i],&d[i]);
    cout << solve(N,K,t,d) << endl;
    return 0;
}

Measured memory_bytes: 13304