akhauriyash/Code-Regression huggingface dataset:
/**
 *      purpose : AGC 17 A
 *      author  : kyomukyomupurin
 *      created : 2018-11-05 17:21:41
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

const int MAX = 2e5;
const int MOD = 1e9 + 7;
int64 fac[MAX] = {}; int64 inv[MAX] = {}; int64 finv[MAX] = {};

void make_table(){
    fac[0] = 1; fac[1] = 1;
    finv[0] = 1; 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;
    }
}

int64 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;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, P; cin >> N >> P;
    int A[N] = {};
    for (int i = 0; i < N; ++i) cin >> A[i];

    int64 odd = 0; int64 even = 0;
    for (int i = 0; i < N; ++i){
        if (A[i] % 2 == 0) ++even;
        else ++odd;
    }
    make_table();
    int64 sumodd = 0;
    int64 sumeven = pow(2, even);

    if (P == 0){
        for (int i = 0; i <= odd; i += 2){
            sumodd += com(odd, i);
        }
    }
    else if (P == 1){
        for (int i = 1; i <= odd; i += 2){
            sumodd += com(odd, i);
        }
    }
    print(sumeven * sumodd);
    
    return 0;
}

Measured memory_bytes: 4992
#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))

using namespace std;

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

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; 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; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
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) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) 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> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
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() {
  map<string, int> ma;
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  ma[s] = a;
  ma[t] = b;
  string key;
  cin >> key;
  ma[key]--;
  cout << ma[s] << " " << ma[t] << endl;
}


Measured memory_bytes: 256
h,w = (int(i) for i in input().split())
#print(h,w)
s = [[i for i in input()] for j in range(h)]
#print(s)

mylist=[[0 for j in range(w)] for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            if i-1 >= 0 and j-1 >= 0:
                mylist[i-1][j-1]+=1
            if i-1 >= 0:
                mylist[i-1][j]+=1
            if i-1 >= 0 and j+1 <= w-1:
                mylist[i-1][j+1]+=1
            if j-1 >= 0:
                mylist[i][j-1]+=1
            if j+1 <= w-1:
                mylist[i][j+1]+=1
            if i+1 <= h-1 and j-1 >= 0:
                mylist[i+1][j-1]+=1
            if i+1 <= h-1:
                mylist[i+1][j]+=1
            if i+1 <= h-1 and j+1 <= w-1:
                mylist[i+1][j+1]+=1

for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            mylist[i][j]='#'
            
for i in range(h):
  for j in range(w):
    print(mylist[i][j], end="")
  print('')

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

int main() {
	int n, m;
	while (1) {
		cin >> n >> m;
		if (n == 0 && m == 0)
			break;
		vector<int> price;
		for (int i = 0; i<n; i++) {
			int x;
			cin >> x;
			if (x < m)
				price.push_back(x);
		}

		int max = 0;
		for (int i = 0; i<price.size(); i++) {
			for (int j = i + 1; j<price.size(); j++) {
				int sum = price[i] + price[j];
				if (sum <= m && sum >= max) {
					max = sum;
				}
			}
		}
		if (max != 0)
			cout << max << endl;
		else cout << "NONE" << endl;
	}
	return 0;
}

Measured memory_bytes: 3016
import queue
k=int(input())
q=queue.Queue()
for i in range(1,10):
  q.put(i)
c=0
while c<k:
  a=q.get()
  c+=1
  if c==k:
    print(a)
  if (a%10)!=0:
    q.put(10*a+a%10-1)
  q.put(10*a+a%10)
  if (a%10)!=9:
    q.put(10*a+a%10+1)

Measured memory_bytes: 12452
# include <iostream>
# include <string>
# include <cstdlib>
using namespace std;


int main () {
    int N;
    cin >> N;
    int t[N], x[N], y[N];
    for ( int i = 0; i < N; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }
    
    string ans = "Yes";
    for ( int i = 0; i < N; i++){
        int dt, dx, dy;
        if ( i == 0) {
            dt = t[0];
            dx = abs(x[0]);
            dy = abs(y[0]);
        } else {
            dt = t[i] - t[i-1];
            dx = abs(x[i] - x[i-1]);
            dy = abs(y[i] - y[i-1]);
            
        }
        
        if ( dt < dx + dy || (dt - dx - dy) % 2 == 1) {
            ans = "No";
            break;
        }
    }
    
    cout << ans;
}

Measured memory_bytes: 1408
n = int(input())
array = [int(x) for x in input().split()]
array.append(0)

tmp = array[0]
cnt = []
cnt_tmp = 0
for i in array:
    if tmp == i:
        cnt_tmp += 1
    else:
        cnt.append(cnt_tmp)
        tmp = i
        cnt_tmp = 1

res = 0
for i in cnt:
    if i != 1:
        if i %2:
            res += i//2
        else:
            res += i//2
print(res)


Measured memory_bytes: 3060
k = int(input())

ans = [[] for _ in range(10)]
ans[0] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]

for i in range(9):
    for num in ans[i]:
        if num[-1] == "0":
            ans[i + 1].append(num + "0")
            ans[i + 1].append(num + "1")
        elif num[-1] == "1":
            ans[i + 1].append(num + "0")
            ans[i + 1].append(num + "1")
            ans[i + 1].append(num + "2")
        elif num[-1] == "2":
            ans[i + 1].append(num + "1")
            ans[i + 1].append(num + "2")
            ans[i + 1].append(num + "3")
        elif num[-1] == "3":
            ans[i + 1].append(num + "2")
            ans[i + 1].append(num + "3")
            ans[i + 1].append(num + "4")
        elif num[-1] == "4":
            ans[i + 1].append(num + "3")
            ans[i + 1].append(num + "4")
            ans[i + 1].append(num + "5")
        elif num[-1] == "5":
            ans[i + 1].append(num + "4")
            ans[i + 1].append(num + "5")
            ans[i + 1].append(num + "6")
        elif num[-1] == "6":
            ans[i + 1].append(num + "5")
            ans[i + 1].append(num + "6")
            ans[i + 1].append(num + "7")
        elif num[-1] == "7":
            ans[i + 1].append(num + "6")
            ans[i + 1].append(num + "7")
            ans[i + 1].append(num + "8")
        elif num[-1] == "8":
            ans[i + 1].append(num + "7")
            ans[i + 1].append(num + "8")
            ans[i + 1].append(num + "9")
        elif num[-1] == "9":
            ans[i + 1].append(num + "8")
            ans[i + 1].append(num + "9")

for j in range(10):
    l = len(ans[j])
    if k <= l:
        print(ans[j][k - 1])
        break
    elif k > l:
        k -= l

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

int main() 
{ 
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s){
        cout<<a-1<<" "<<b;
        return 0;
    }
    cout<<a<<" "<<b-1;
	return 0; 
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

const ll MOD = 1e9 + 7;
map<ll, ll> m;

void f(int n) {
    for(ll i = 2; i * i <= n; i++) {
        if(n % i != 0) continue;

        while(n % i == 0) {
            m[i]++;
            n /= i;
        }
    }
    if(n != 1) m[n]++;
    
    return;
}

int main() {
    ll n;
    cin >> n;

    for(int i = n; i >= 1; i--) {
        f(i);
    }

    ll ans = 1;
    for(auto p : m) {
        ans *= p.second + 1;
        //cout << p.second << endl;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int m,a,b,c;
    while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    {if(a>b)
    {m=a;a=b;b=m;}
    if(b>c)
    {m=b;b=c;c=m;}
     if(a>b)
    {m=a;a=b;b=m;}
    printf("%d\n",c-a);}
    return 0;
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 
#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 10000000009

typedef long long ll;
int n,m;

int main(int argc, char const *argv[])
{
    cin >> n >> m;
    priority_queue<ll> q[8];
    REP(i, n) {
            ll x,y,z; cin >> x >> y >> z;
            q[0].push(x+y+z);
            q[1].push(-x+y+z);
            q[2].push(x-y+z);
            q[3].push(x+y-z);
            q[4].push(-x-y+z);
            q[5].push(-x+y-z);
            q[6].push(x-y-z);
            q[7].push(-x-y-z);
    }
    ll s[8];
    REP(i,8) {
        s[i] = 0;
    }
    REP(i, m) {
        REP(j,8) {
            ll x = q[j].top();q[j].pop();
            s[j] += x;
        }
    }
    ll res = -1;
    REP(i,8){
        res = max(res, s[i]);
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    vector<int> a(n);
    int s = 0, t = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s += a[i];
        t += a[i] * a[i];
    }

    int x = s / n;
    int r = 1 << 30;
    for (int i = -1; i <= 1; i++) {
        int y = x + i;
        int b = t - 2 * s * y + n * y * y;
        r = min(r, b);
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
string S1, S2;
int f() {
	for (int n = min<int>(S1.length(), S2.length()); n >= 1; --n) {
		vector<int> a1(26), a2(26);
		set<vector<int>> s1;
		for (int i = 0; i < n; ++i) {
			++a1[S1[i] - 'a'];
			++a2[S2[i] - 'a'];
		}
		s1.insert(a1);
		for (int i = n; i < S1.length(); ++i) {
			--a1[S1[i - n] - 'a'];
			++a1[S1[i] - 'a'];
			s1.insert(a1);
		}
		if (s1.count(a2)) {
			return n;
		}
		for (int i = n; i < S2.length(); ++i) {
			--a2[S2[i - n] - 'a'];
			++a2[S2[i] - 'a'];
			if (s1.count(a2)) {
				return n;
			}
		}
	}
	return 0;
}
int main() {
	cin >> S1 >> S2;
	cout << f() << endl;
}


Measured memory_bytes: 3884
#arc083c

a,b,c,d,e,f=map(int,input().split())
x=1
y=-1
for i in range(0,f+1,100*a):
 for j in range(0,f+1-i,100*b):
  s=min(f-i-j,(i+j)*e//100)
  if i+j==0:
   continue
  for k in range(0,s+1,c):
   for l in range(0,s+1-k,d):
    if y/x<(k+l)/(i+j):
     x=i+j
     y=k+l
print(x+y,y)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  string s,hs;
  cin >> s;
  for(int i = 0; i < (s.length() + 1)/2; i++){
    hs += s.at(i*2);
  }
  cout << hs << endl;
  return 0;
}


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

int main() {
	long long N, K, INF = 1145141919810;
	cin >> N >> K;
	vector<vector<long long> > VV(N);
	for (int i = 0; i < N; i++) {
		int T, D;
		cin >> T >> D;
		T--;
		VV[T].push_back(D);
	}
	for (auto &V : VV) {
		sort(V.begin(), V.end(), greater<long long>());
		if (V.empty()) V.push_back(-INF);
	}
	sort(VV.begin(), VV.end(), [&](vector<long long> a, vector<long long> b) {return a[0] > b[0]; });
	long long Count = 0, ans;
	priority_queue<long long> Q;
	for (int i = 0; i < K; i++) {
		Count += VV[i][0];
		for (int j = 1; j < VV[i].size(); j++) Q.push(VV[i][j]);
	}
	for (int i = K; i < N; i++) {
		for (int j = 0; j < VV[i].size(); j++) Q.push(VV[i][j]);
	}
	ans = Count + K * K;
	for (long long i = K - 1; i >= 1; i--) {
		long long v = VV[i][0];
		long long w = Q.top();
		if (v < w) {
			Q.pop();
			Count += w;
			Q.push(v);
			Count -= v;
		}
		ans = max(ans, Count + i * i);
	}
	cout << ans;
}

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

//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long

using namespace std;

const int NN = 1e6 + 7;
const int N = 2e5 + 7;
const int M = 20;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;

void solve1()
{
	long double n;
	cin >> n;
	cout << setprecision(20) << n * n * n / 27;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> vll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll N; cin >> N;
  ll A[N], B[N];
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];

  vector<ll> pos, neg;
  rep(i, N){
    if(A[i] - B[i] >= 0) pos.push_back(A[i] - B[i]);
    else neg.push_back(A[i] - B[i]);
  }
  sort(pos.begin(), pos.end(), greater<ll>());
  ll ans = neg.size();
  ll sum = 0;
  for(ll n : neg) sum += n;
  for(ll p : pos){
    if(sum >= 0) break;
    sum += p;
    ans++;
  }
  cout << (sum < 0 ? -1 : ans) << endl;
  return 0;
}


Measured memory_bytes: 2808
import sys
input = sys.stdin.readline
 
h,w,m = list(map(int,input().split()))

R = [0]*h
C = [0]*w
G = {}

for _ in range(m):
  a,b = list(map(int,input().split()))
  a,b = a-1, b-1
  R[a] += 1
  C[b] += 1
  G[(a,b)] = 1
  
hhh = max(R)
ccc = max(C)
hei,wei = [],[]

for i in range(h):
  if R[i]==hhh:
    hei.append(i)
    
for i in range(w):
  if C[i]==ccc:
    wei.append(i)
  
  
best = 0
for i in hei:
  for j in wei:
    cor = 0
    if (i,j) in G:
      cor = 1
    best = max(best,R[i]+C[j] - cor)
    if cor==0:
      break
  if cor==0:
      break
      
print(best)

Measured memory_bytes: 165760
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle {
    int f[N2], space, MD;
};

Puzzle state;
int limit;
int path[LIMIT];


int getAllMD(Puzzle pz) {
    int sum = 0;
    for (int i = 0; i != N2; ++i) {
        if ( pz.f[i] == N2 ) continue;
        sum += MDT[i][pz.f[i] - 1];
    }
    return sum;
}

bool isSolve(Puzzle s) {
    for (int i = 0; i != N2; ++i) {
        if ( s.f[i] != i + 1 ) return false;
    }
    return true;
}

bool dfs(int depth, int prev) {
    if ( state.MD == 0 ) return true;
    if ( state.MD + depth > limit ) return false;

    Puzzle tmp;
    int sx = state.space / N;
    int sy = state.space % N;

    for (int r = 0; r != 4; ++r) {
        int tx = sx + dx[r];
        int ty = sy + dy[r];
        if ( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
        if ( max(r, prev) - min (r, prev) == 2 ) continue;
        tmp = state;
        state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
        state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
        swap(state.f[sx * N + sy], state.f[tx * N + ty]);
        state.space = tx * N + ty;
        if ( dfs(depth + 1, r) ) {
            path[depth] = r;
            return true;
        }
        state = tmp;
    }
    return false;
}

string iterative_deepening(Puzzle in) {
    in.MD = getAllMD(in);

    for (limit = in.MD; limit <= LIMIT; ++limit) {
        state = in;
        if ( dfs(0, -100) ) {
            string ans;
            for (int i = 0; i != limit; ++i) {
                ans += dir[path[i]];
            }
            return ans;
        }
    }
    return "unsolvable";
}

int main()
{
    for (int i = 0; i != N2; ++i) {
        for (int j = 0; j != N2; ++j) {
            MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
        }
    }

    Puzzle in;
    for (int i = 0; i != N2; ++i) {
        cin >> in.f[i];
        if ( in.f[i] == 0 ) {
            in.f[i] = N2;
            in.space = i;
        }
    }
    string ans = iterative_deepening(in);
    cout << ans.size() << endl;
    return 0;
}


Measured memory_bytes: 3208
n=int(input())
bfr=[[[0]*10 for i in range(3) ]for i in range(4)]
for i in range(n):
    b,f,r,v=map(int,input().split())
    bfr[b-1][f-1][r-1]+=v
for i in range(len(bfr)):
    for f in bfr[i]:
        print(' ',end='')
        print(*f)
    if i != len(bfr)-1:
        print('#'*20)




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

int main()
{
    int n;
    cin >> n;
    int cnt[4] = {0};
    rep(i, n){
        string s;
        cin >> s;
        if(s[0]=='A') cnt[0]++;
        if(s[0]=='W') cnt[1]++;
        if(s[0]=='T') cnt[2]++;
        if(s[0]=='R') cnt[3]++;
    }
    cout << "AC x " << cnt[0] << endl;
    cout << "WA x " << cnt[1] << endl;
    cout << "TLE x " << cnt[2] << endl;
    cout << "RE x " << cnt[3] << endl;
    
    return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

const int MAX = 100000;
const int SQ = 316;
int cnt[MAX];
int ans[MAX];

struct Q {
    int l, r;
    bool operator<(const Q& q) const {
        if (l/SQ != q.l/SQ) return l < q.l;
        return q.r < r;
    }
};

Q qs[MAX * 3];

vector<int> factor[MAX];

void add(int x, int c) {
    for (int f : factor[x]) if (cnt[f]++ == 0) ans[f] += c;
}
void del(int x, int c) {
    for (int f : factor[x]) if (--cnt[f] == 0) ans[f] -= c;
}


int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &qs[i].l, &qs[i].r);
        qs[i].r++;
    }
    sort(qs, qs + n);
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j*j <= i; j++) {
            if (i % j == 0) {
                factor[i].push_back(j-1);
                if (j*j != i) factor[i].push_back(i/j-1);
            }
        }
    }
    for (int l = 0, r = 0, i = 0; i < n; i++) {
        while (l > qs[i].l) { l--; add(l, n-i); }
        while (r < qs[i].r) { add(r, n-i); r++; }
        while (l < qs[i].l) { del(l, n-i); l++; }
        while (r > qs[i].r) { r--; del(r, n-i); }
    }
    for (int i = 0; i < m; i++) {
        printf("%d\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 13568
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <numeric>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<size_t> idx(N);
  std::iota(idx.begin(), idx.end(), 0);

  std::vector<int> a(N), w(N);
  for (auto& ai: a) scanf("%d", &ai);
  for (auto& wi: w) scanf("%d", &wi);

  int res = 1e9;
  do {
    int cur = 0;
    for (size_t i = 0; i < N; ++i) {
      size_t ii = idx[i];
      size_t jj = idx[(i+1)%N];
      if (a[ii] == 0 && a[jj] == 1) {
        cur += w[ii];
      } else if (a[ii] == 1 && a[jj] == 0) {
        cur += w[ii];
      }
    }
    res = std::min(res, cur);
  } while (std::next_permutation(idx.begin(), idx.end()));
  printf("%d\n", res);
}



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

mod = 10**9+7

def pwmod(x, y):
    res = 1
    for i in range(y):
        res = res * x % mod
    return res

ans = pwmod(10, N) - pwmod(9, N) - pwmod(9, N) + pwmod(8, N)
ans = ans % mod

print(ans)


Measured memory_bytes: 9168
using System;

public class Program
{
	public static void Main(string[] args)
	{
		var ss = new StreamScanner();
		//---------------------------------

		//var y = ss.Next<int>();
		var n = ss.Next<int>();
		int[] array = ss.Next<int>(n);

		for (int i = n-1; i >= 0; i--)
		{
			Console.Write("{0}", array[i]);
			if (i != 0)
			{
				Console.Write(" ");
			}
		}
		Console.WriteLine("");
		/*
		//????????????int, double, string?????????????????£????????????
		int i = ss.Next<int>();
		double d = ss.Next<double>();
		string s = ss.Next<string>();

		//?????°???????????????????????¨?????????????????????????????????????????????????´???????
		int[] array = ss.Next<int>(10);
		*/
		//---------------------------------
	}

	public static void Write()
	{
		Console.Write("hello world!");
	}

	public static bool Check(int num)
	{
		int checknum = num;
		if (num % 3 == 0)
		{
			return true;
		}

		while (checknum != 0)
		{
			if (checknum % 10 == 3)
			{
				return true;
			}

			checknum = checknum / 10;

		}
		return false;
	}
}




public class StreamScanner
{
	private readonly char[] _c = { ' ' };
	private int _index = -1;
	private string[] _input = new string[0];
	private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

	public T Next<T>()
	{
		if (_index == _input.Length - 1)
		{
			_index = -1;
			while (true)
			{
				string rl = _sr.ReadLine();
				if (rl == null)
				{
					if (typeof(T).IsClass) return default(T);
					return (T)typeof(T).GetField("MinValue").GetValue(null);
				}
				if (rl != "")
				{
					_input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
					break;
				}
			}
		}
		return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
	}

	public T[] Next<T>(int x)
	{
		var ret = new T[x];
		for (var i = 0; i < x; ++i) ret[i] = Next<T>();
		return ret;
	}

	public T[][] Next<T>(int x, int y)
	{
		var ret = new T[y][];
		for (var i = 0; i < y; ++i) ret[i] = Next<T>(x);
		return ret;
	}
}

Measured memory_bytes: 9812
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=2e4+10,oo=0x3f3f3f3f,MOD=998244353;
const double PI = acos(-1);

void solve(){
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    ll red[a],green[b];
    vll ans;
    loop(a,i,0)
        cin>>red[i];
    loop(b,i,0)
        cin>>green[i];
    sort(all(red,a),greater<ll>());
    sort(all(green,b),greater<ll>());
    loop(x,i,0)
        ans.pb(red[i]);
    loop(y,i,0)
        ans.pb(green[i]);
    loop(c,i,0){
        ll z;cin>>z;
        ans.pb(z);
    }
    ll res=0;
    sort(allv(ans),greater<ll>());
    loop(x+y,i,0)
        res+=ans[i];
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();
}

Measured memory_bytes: 8880
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;

char m;
int n, flag[4], vis, i, k;

int main()
{
	while(cin >> n)
	{
		getchar();
		vis = 0;
		for(i = 0; i < 4; i++)  flag[i] = 0;
		for(i = 0; i < n; i++)
		{
			scanf("%c",&m);
			if(m == 'P') flag[0]++;
			if(m == 'W') flag[1]++;
			if(m == 'G') flag[2]++;
			if(m == 'Y') flag[3]++;
			getchar();
		}
		for(i = 0; i < 4; i++)
			if(flag[i] == 0) vis++;
		k = 4 - vis;
		if(k == 1) cout << "One" << endl;
		if(k == 2) cout << "Two" << endl;
		if(k == 3) cout << "Three" << endl;
		if(k == 4) cout << "Four" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;

const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int main(){
	int n;
	
	cin >> n;
	
	
	if (n/10 == 9 || n%10 == 9) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
def popular_vote():
    # 入力
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    # 総投票数
    total_vote = sum(A)
    # 総投票数の(1/4*M)以上をカウント
    count = 0
    for i in range(N):
        if A[i] >= total_vote/(4*M):
            count += 1
    if count >= M:
        return 'Yes'
    else:
        return 'No' 

result = popular_vote()
print(result)

Measured memory_bytes: 9156
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<pair<int,int>> vip;

#define ZOOM ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)






void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif




int main(int argc,char* argv[])
{
    ZOOM

    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll> p(a),q(b),r(c);
    rep(i,a) cin>>p[i];
    rep(i,b) cin>>q[i];
    rep(i,c) cin>>r[i];
    r.pb(-1);

    sort(all(p),greater<ll>()),sort(all(q),greater<ll>()),sort(all(r),greater<ll>());

    ll sum = 0;
    vector<ll> tp;
    for(ll i=0;i<x;++i)
        tp.pb(p[i]);
    for(ll i=0;i<y;++i)
        tp.pb(q[i]);
    sort(all(tp));
    for(int i=0;i<min(x+y,c);++i)
    {
        if(tp[i]<r[i])
        {
            tp[i]=r[i];
        }
        else
            break;
    }
    for(int i=0;i<x+y;++i)
        sum+=tp[i];
    cout<<sum;

    return 0;
}



Measured memory_bytes: 5744
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



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

	string s;
	cin>>s;
	if (s[1]=='B') s[1]='R'; else s[1]='B';
	cout<<s<<'\n';
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define kws 1e9+7
#define lli long long int
using namespace std;
vector<vector<int> > gr;
int siz[200005],par[200005];
long long int fac[200005],invfac[200005],dp[200005],ans[200005];
lli MOD=kws;
lli modpow(lli x,lli y)
{
	lli ans=1;
	lli m=MOD;
	while(y>0)
	{
		if(y%2==1)
		{
			ans*=x;
			ans%=m;
		}
		y/=2;
		x=x*x;
		x%=m;
	}
	return ans%m;
}
long long int dpf(int p)
{
	if(siz[p]==1)
	return  dp[p]=1;
	dp[p]=fac[siz[p]-1];
	for(auto x: gr[p])
	{
		if(par[p]==x)
		continue;
		dp[p]*=dpf(x);
		dp[p]%=MOD;
		dp[p]*=invfac[siz[x]];
		dp[p]%=MOD;
	}
	return dp[p];
}
int dfs(int u,int p)
{
	siz[u]=1;
	par[u]=p;
	for(auto x: gr[u])
	{
		if(x==p)
		continue;
		siz[u]+=dfs(x,u);
	}
	return siz[u];
}
int root(int u)
{
	//rerooting method: First change size of parent
	//then dp of parent then size of child then dp of child
	//And then in the end reverse it.
	int p=par[u];
	if(p!=-1)
	{
		int orgsizp=siz[p];
		siz[p]-=siz[u];
		dp[p]*=invfac[orgsizp-1];
		dp[p]%=MOD;
		dp[p]*=fac[siz[u]];
		dp[p]%=MOD;
		dp[p]*=fac[siz[p]-1];
		dp[p]%=MOD;
		dp[p]*=modpow(dp[u],MOD-2);
		dp[p]%=MOD;
		int orgsizu=siz[u];
		siz[u]+=siz[p];
		dp[u]*=invfac[orgsizu-1];
		dp[u]%=MOD;
					
		dp[u]*=invfac[siz[p]];
		dp[u]%=MOD;
		dp[u]*=fac[siz[u]-1];
		dp[u]%=MOD;
		dp[u]*=dp[p];
		dp[u]%=MOD;
		ans[u]=dp[u];
	}
	for(auto x: gr[u])
	{
		if(x==par[u])
		continue;
		root(x);
	}
	if(p==-1)
	return 0;
	swap(u,p);
	int orgsizp=siz[p];
		siz[p]-=siz[u];
		dp[p]*=invfac[orgsizp-1];
		dp[p]%=MOD;
		dp[p]*=fac[siz[u]];
		dp[p]%=MOD;
		dp[p]*=fac[siz[p]-1];
		dp[p]%=MOD;
		dp[p]*=modpow(dp[u],MOD-2);
		dp[p]%=MOD;
		int orgsizu=siz[u];
		siz[u]+=siz[p];
		dp[u]*=invfac[orgsizu-1];
		dp[u]%=MOD;
		dp[u]*=invfac[siz[p]];
		dp[u]%=MOD;
		dp[u]*=fac[siz[u]-1];
		dp[u]%=MOD;
		dp[u]*=dp[p];
		dp[u]%=MOD;
}
int main()
{
	int n;
	cin>>n;
	fac[0]=1;
	memset(dp,-1,sizeof(dp));
	invfac[0]=1;
	for(int i=1;i<=n+1;i++)
	{
		fac[i]=(fac[i-1]*i)%((lli)MOD);
		invfac[i]=modpow(fac[i],MOD-2);
	}
	gr=vector<vector<int> >(n+1);
	for(int i=1;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		gr[x].push_back(y);
		gr[y].push_back(x);
	}
	dfs(1,-1);
	ans[1]=dpf(1);
	root(1);
	ans[0]=0;
	for(int i=1;i<=n;i++)
	cout<<ans[i]<<"\n";
}


Measured memory_bytes: 21748
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            //0 と 1 のみから成る 3 桁の番号 s が与えられます。1 が何個含まれるかを求めてください。
            var s = cin.Read;

            WriteLine(s.Count(x => x == '1'));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 26652
//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>
#include<limits>

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(){
  ll n,a,b;
  cin>>n>>a>>b;
  
  ll ans=(n/(a+b))*a;
  if(a>=n%(a+b)) ans+=n%(a+b);
  else ans+=a;
  cout<<ans<<endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int check(int X){
  if(X==1)
    return 300000;
  else if(X==2)
    return 200000;
  else if(X==3)
    return 100000;
  else
    return 0;
}

int main() {
  int X,Y;
  cin>>X>>Y;
  int sum=check(X)+check(Y);
  if(X==1&&Y==1)
    sum+=400000;
  cout<<sum<<endl;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
v = input().split()

if len(set(v)) == 1:
    print(n // 2)
else:
    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])
    c1m = c1.most_common()
    c2m = c2.most_common()

    if c1m[0][0] == c2m[0][0]:
        print(min(n - c1m[0][1] - c2m[1][1], n - c1m[1][1] - c2m[0][1]))
    else:
        print(n - c1m[0][1] - c2m[0][1])

Measured memory_bytes: 30780
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005


int main() {
    int h, w, m;
    cin >> h >> w >> m;
    int a[h] = {}, b[w] = {};
    set<P> se;
    rep(i,m){
        int x, y;
        cin >> x >> y;
        x--, y--;
        a[x]++;
        b[y]++;
        se.insert(P(x,y));
    }
    int ma = 0;
    rep(i,h){
        ma = max(ma,a[i]);
    }
    vector<int> v;
    int ans = 0;
    rep(i,h){
        if(a[i] == ma) v.push_back(i);
    }
    ans += ma;
    ma = 0;
    rep(i,w){
        ma = max(ma,b[i]);
    }
    vector<int> u;
    rep(i,w){
        if(b[i] == ma) u.push_back(i);
    }
    ans += ma;

    int flag = 1;
    rep(i,v.size()){
        rep(j,u.size()){
            int x = v[i];
            int y = u[j];
            if(se.find(P(x,y))==se.end()){
                flag = 0;
                break;
            }
        }
        if(flag == 0)break;
    }
    ans -= flag;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 23856
n,x=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*n
for i in range(n):
  a[i]=abs(l[i]-x)
a.sort()
from fractions import gcd
from functools import reduce
def gcdl(list):
  return reduce(gcd,list)
print(gcdl(a))

Measured memory_bytes: 14224
#include<iostream>
#include<cstdio>

using namespace std;

string a,s;
 
void f(int p,int q,string b)
{
	if(p==4)
	{
		if(q==7)s=b+"=7";
		return;
	}
	f(p+1,q+a[p]-'0',b+"+"+a[p]);
	f(p+1,q-a[p]+'0',b+"-"+a[p]);
}
 
int main()
{
	string b;
	cin>>a;b=a[0];
	f(1,a[0]-'0',b);
	cout<<s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    long N,A[100009];
    cin>>N;
    for(long i=1;i<=N;i++)
        cin>>A[i];
    long i=1,C=0;
    while(i!=2 && C<=N)
    {
        i=A[i];
        C++;
    }
    if(i!=2)
        cout<<-1;
    else
        cout<<C;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    ll min_num = inf;
    ll n_count = 0;
    rep(i, n) {
        if (a[i] < 0) {
            n_count++;
            a[i] *= -1;
        }
        min_num = min(min_num, abs(a[i]));
    }
    ll sum = accumulate(all(a), 0ll);
    if (n_count % 2 == 0) {
        cout << sum << endl;
    } else {
        cout << sum - min_num * 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;

typedef pair<ll, ll> pll;
typedef pair<int, int> pi;

typedef vector<pll> vpl;
typedef vector<pi> vpi;

typedef queue<ll> ql;
typedef queue<int> qi;

template <class T>
void printv(vector<T> vc) {
    for (auto e: vc) cout << e << " ";
    cout << endl;
}

template <class T>
void printvv(vector<T> vvc) { 
    for (auto vc: vvc) {
        for (auto e: vc) cout << e << " ";
        cout << endl;
    }
}

template <class T>
void printvp(vector<pair<T, T> > vp) {
    for (auto pT: vp) cout << pT.first << " " << pT.second << endl;
}

vpl L;

inline ll rec(int i, ll x, ll p) {
    if (i == 0) return p + 1;
    if (x <= 1) return p;

    if (x == L[i].second) return L[i].first + p;

    ll y = (L[i].second + 1) / 2;
    if (x < y) return rec(i - 1, x - 1, p);

    p += L[i - 1].first + 1;
    if (x == y) return p;

    return rec(i - 1, x - y, p);
}

int main() {
    L.resize(51);
    ll n, x; cin >> n >> x;

    L[0] = pll(1, 1);

    for (int i = 1; i <= n; ++i) {
        ll p = L[i - 1].first * 2 + 1;
        ll h = L[i - 1].second * 2 + 3;
        L[i] = pll(p, h);
    }

    cout << rec(n, x, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[30005],n,tot;
int main(){
	scanf("%d",&n);
	if (n==3) return puts("2 5 63"),0;
	for (int i=1;i<=30000;i++)
		if (i%2==0||i%3==0)
			a[++tot]=i;
	for (;;){
		random_shuffle(a+1,a+(n==3?100:tot)+1);
		int have2=0,have3=0,sum=0;
		for (int j=1;j<=n;j++){
			sum=(sum+a[j])%6;
			if (a[j]%2) have2=1;
			if (a[j]%3) have3=1;
		}
		if (!sum&&have2&&have3){
			for (int j=1;j<=n;j++)
				printf("%d ",a[j]);
			puts("");
			exit(0);
		}
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define W while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007
#define mp make_pair

  int main()
  {
    ll x;
    cin>>x;
    ll count=0,d=100;
    while(d<x)
    {
        d=d+d/100;
    count++;
    }
    cout<<count;
     }

Measured memory_bytes: 3608
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

typedef pair<int, int> Coor;
typedef pair<Coor, int> Pair;

int w, h;
int n;
vector<int> xs;
vector<int> ys;
vector<Pair> diff;
map<int, int> xtox;
map<int, int> ytoy;
int xfrom;
int xto;
int yfrom;
int yto;

short field[4001][4001];

char count(int x, int y) {
    char ret = 0;
    queue<Coor> q;

    q.push(Coor(x, y));
    while (!q.empty()) {
        Coor c = q.front(); q.pop();
        x = c.first;
        y = c.second;

        if (x < xfrom || xto <= x || y < yfrom || yto <= y) continue;
        if (field[y][x]) continue;

        field[y][x] = 1;
        ret = 1;
        q.push(Coor(x-1, y));
        q.push(Coor(x+1, y));
        q.push(Coor(x, y-1));
        q.push(Coor(x, y+1));
    }
    return ret;
}

int main() {
    int ans;

    while (1) {
        xs.clear();
        ys.clear();
        diff.clear();
        xtox.clear();
        ytoy.clear();
        memset(field, 0, sizeof(field));

        scanf("%d %d", &w, &h);
        if (w == 0 && h == 0) exit(0);

        scanf("%d", &n);
        xs.push_back(0);
        xs.push_back(w-1);
        ys.push_back(0);
        ys.push_back(h-1);
        for (int i=0; i<n; i++) {
            int x1, x2;
            int y1, y2;
    
            scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
            xs.push_back(x1-1);
            xs.push_back(x1);
            xs.push_back(x2);
            xs.push_back(x2+1);
            ys.push_back(y1-1);
            ys.push_back(y1);
            ys.push_back(y2);
            ys.push_back(y2+1);
            diff.push_back(Pair(Coor(x1, y1), 1));
            diff.push_back(Pair(Coor(x1, y2), -1));
            diff.push_back(Pair(Coor(x2, y1), -1));
            diff.push_back(Pair(Coor(x2, y2), 1));
        }
    
        sort(xs.begin(), xs.end());
        sort(ys.begin(), ys.end());
        xs.erase(unique(xs.begin(), xs.end()), xs.end());
        ys.erase(unique(ys.begin(), ys.end()), ys.end());
    
        for (int i=0; i<xs.size(); i++) {
            xtox[xs[i]] = i;
        }
    
        for (int i=0; i<ys.size(); i++) {
            ytoy[ys[i]] = i;
        }
    
        for (int i=0; i<diff.size(); i++) {
            Pair p = diff[i];
            int x = p.first.first;
            int y = p.first.second;
            int add = p.second;
    
            field[ytoy[y]][xtox[x]] += add;
        }
    
        yfrom = ytoy[0];
        yto   = ytoy[h-1];
        xfrom = xtox[0];
        xto   = xtox[w-1];
        h = ys.size();
        w = xs.size();
        for (int i=0; i<h; i++) {
            for (int j=1; j<w; j++) {
                field[i][j] += field[i][j-1];
            }
        }
    
        for (int i=1; i<h; i++) {
            for (int j=0; j<w; j++) {
                field[i][j] += field[i-1][j];
            }
        }
    
        ans = 0;
        for (int i=yfrom; i<yto; i++) {
            for (int j=xfrom; j<xto; j++) {
                if (count(j, i)) ans++;
            }
        }

        printf("%d\n", ans);
    }
}

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

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

    vector<int> X(N);
    for(int i=0; i<N; i++){
        cin>>X[i];
    }

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

    int ans = 1e9;
    for(int i=X[0]; i<=X[N-1]; i++){
        int dis = 0;
        
        for(int j=0; j<N; j++){
            dis += (X[j]-i)*(X[j]-i);
        }

        ans = min(dis, ans);
    }

    cout<<ans<<endl;

    return 0;
}

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

int main()
{
    string s="MARCH";
    long c[5] = {0};
    long n;
    cin >> n;
    for(int i=0; i<n; i++){
        string t;
        cin >> t;
        for(int j=0; j<5; j++){
            if(t[0] == s[j]){
                c[j]++;
            }
        }
    }
    long ans = 0;
    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            for(int k=j+1; k<5; k++){
                ans += c[i]*c[j]*c[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int N, C;
    cin >> N >> C;

    vector<vector<int>> D(C, vector<int>(C));
    rep(i, C) {
        rep(j, C) cin >> D[i][j];
    }

    vector<vector<int>> c(N, vector<int>(N));
    rep(i, N) {
        rep(j, N) {
            cin >> c[i][j];
            c[i][j]--;
        }
    }
    
    vector<vector<int>> sum(3, vector<int>(C, INF));
    rep(x, 3) {
        rep(k, C) {
            int res = 0;
            rep(i, N) {
                rep(j, N) {
                    if ((i + j) % 3 != x) continue;
                    int before = c[i][j];
                    res += D[before][k];
                }
            }
            sum[x][k] = res;
        }
    }

    int ans = INF;
    rep(i, C) {
        rep(j, C) {
            rep(k, C) {
                if (i != j && j != k && i != k) {
                    ans = min(ans, sum[0][i] + sum[1][j] + sum[2][k]);
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1280