akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

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

#define v vector
#define ALL(x) x.begin(),x.end()
#define rALL(x) x.rbegin(),x.rend()
#define endl '\n'
#define F first
#define S second
#define DEBUG

template<typename T> void DBG(const char* name, T&& H) {
	cerr << name << " = " << H << ')' << endl;
}

template<typename T, typename... Args> void DBG(const char* names, T&& H, Args&&... args) {
	const char* NEXT = strchr(names+1, ',');
	cerr.write(names, NEXT-names) << " = " << H << " |";
	DBG(NEXT+1, args...);
}

#ifdef DEBUG
	#define dbg(...) cerr << __FUNCTION__ << ' ' <<__LINE__ << " : (", DBG(#__VA_ARGS__, __VA_ARGS__)
#else
	#define dbg(...)
#endif

using ll = long long;
using ld = long double;

const long long mod = 998244353;
const long double PI = acos(-1.0);
const long long INF = 1e18;
const int maxN = 2e5+1;

void Solve() {
	int K;
	cin >> K;
	vector<int> seven(1e6+100);
	seven[0] = 0;
	seven[1] = 7 % K;
	for(int i = 2; i < seven.size(); i ++) {
		seven[i] = (seven[i-1] * 10) % K;
	}
	for(int i = 2; i < seven.size(); i ++) {
		seven[i] = (seven[i]+seven[i-1]) % K;
	}
	int idx = -1;
	for(int i = 1; i <= seven.size()-1; i ++) {
		if(seven[i] == 0) {
			idx = i;
			break;
		}
	} 
	cout << idx << endl;
}

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

	int tt = 1;
	while(tt --) {
		Solve();
	}
	
	return 0;
}

Measured memory_bytes: 7148
N = int(input())
A = list(map(int, input().split()))

money = 1000
ticket = 0
for i in range(N - 1):
    # buy
    if A[i] < A[i + 1]:
        ticket += money // A[i]
        money -= (money // A[i]) * A[i]
    elif A[i] == A[i + 1]:
        pass
    # sell
    else:
        money += A[i] * ticket
        ticket = 0

money += A[-1] * ticket

print(money)


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 repi(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 bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
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) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
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 power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int N; cin >> N;
  vstr S(N); cin >> S;
  vi32 ans(26, 1e9);
  rep(i, N) {
    vi32 cnt(26);
    rep(j, S[i].size()) {
      cnt[S[i][j] - 'a']++;
    }
    rep(j, 26) amin(ans[j], cnt[j]);
  }
  rep(i, 26) if (ans[i] != 1e9) cout << string(ans[i], 'a' + i);
  cout << '\n';
}


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

bool is_leap_year(int y);
int get_leap_years(int* ly_list, int y_bgn, int y_end);

int main()
{
    int leap_years_list[1000]; //A.D. 0 - A.D. 3000 の間に閏年は高々1000個しかない

    bool first_set = true; //一つ目のセットの前にだけは改行を入れてはいけないので

    while (true) {
        int year_begin, year_end;

        //読み込み
        scanf("%d %d", &year_begin, &year_end);

        //終了判定
        if (year_begin == 0 && year_end == 0) {
            break;
        }

        //閏年を計算する
        int leap_years_count = get_leap_years(leap_years_list, year_begin, year_end);

        //セットとセットの間には空行を入れる
        if (first_set) {
            first_set = false;
        } else {
            putchar('\n'); //putcharは一文字だけ出力する関数です
        }

        //閏年を出力
        if (leap_years_count == 0) {
            puts("NA"); //putsは与えられた文字列を出力した後改行する関数です
        } else {
            for (int i = 0; i < leap_years_count; i++) {
                printf("%d\n", leap_years_list[i]);
            }
        }
        
    }
}

bool is_leap_year(int y)
{
    if (y % 400 == 0) {
        return true; 
    } else if (y % 100 == 0) {
        return false;
    } else {
        return y % 4 == 0;
    }
}

int get_leap_years(int* ly_list, int y_bgn, int y_end)
{
    int count = 0;
    for ( int ly = y_bgn; ly <= y_end; ly ++ ) {
        if ( is_leap_year ( ly ) == true ) {
            ly_list[count] = ly;
            count ++;
        }
    }
    return count;
}

Measured memory_bytes: 1048
N, W = list(map(int, input().split()))

weight = []
value = []

for i in range(N):
    w, v = list(map(int, input().split()))
    weight.append(w)
    value.append(v)


dp = []

for i in range(N+1):
    dp.append([])
    for j in range(W+1):
        dp[i].append(0)


# max value = dp[何個まで見たか][現在の重さ]
for i in range(N):
    for j in range(W+1):
        if (j+weight[i]) <= W:
            dp[i+1][j+weight[i]] = max(dp[i][j+weight[i]], dp[i][j] + value[i])

        dp[i+1][j] = max(dp[i][j],dp[i+1][j])

print(dp[N][W])


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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n;
vector<int> a, b;
vector<int> per;

int position(vector<int> per, vector<int>& v){
	int res = 0;
	do{
		if (per == v) return res;
		else res++;
	} while(next_permutation(per.begin(), per.end()));
	return res;
}

int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	a.resize(n); b.resize(n); per.resize(n);
	for(int i=1; i<=n; i++) per[i-1] = i;
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++) cin >> b[i];
	cout << abs(position(per, a) - position(per, b)) << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		int n = in.nextInt();
		int q = in.nextInt();
		STRMQ rmq = new STRMQ(n);
		while (q-- > 0) {
			int com = in.nextInt();
			if (com == 0) {
				rmq.set(in.nextInt(), in.nextInt());
			} else {
				out.println(rmq.min(in.nextInt(), in.nextInt()+1));
			}
		}
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		dump((end-start) + "ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

class STRMQ {

	public static final long INF = (1<<31)-1;
	public final int length;
	private final int reviceLen;
	private final int internalLen;
	private long[] data;

	public STRMQ(int n) {
		this.length = n;
		this.reviceLen = Integer.highestOneBit(Math.max(length-1,1))<<1;
		this.internalLen = 2*reviceLen - 1;
		this.data = new long[internalLen];
		for (int i=0; i<internalLen; i++) data[i] = INF;
	}

	public void set(int idx, int val) {
		idx += reviceLen-1;
		data[idx] = val;
		while (idx > 0) {
			idx = (idx - 1) / 2;
			data[idx] = Math.min(data[idx*2+1], data[idx*2+2]);
		}
	}

	public long get(int idx) {
		return data[idx + reviceLen - 1];
	}

	// [begin, end)
	public long min(int begin, int end) {
		return min(begin, end, 0, 0, reviceLen);
	}

	private long min(int begin, int end, int idx, int l, int r) {
		if (r <= begin || end <= l) return INF;
		if (begin <= l && r <= end) return data[idx];

		long vl = min(begin, end, idx*2+1, l, (l+r)/2);
		long vr = min(begin, end, idx*2+2, (l+r)/2, r);
		return Math.min(vl, vr);
	}

	public String toString() {
		long[] val = new long[length];
		for (int i=0; i<length; i++) val[i] = data[i + reviceLen - 1];
		return Arrays.toString(val);
	}
}

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

int main(){
    int N;
    vector<int> A(N),B(N),C(N);
    cin >> N;
    for(int i;i<N;i++) cin >> A.at(i);
    for(int i;i<N;i++) cin >> B.at(i);
    for(int i;i<N-1;i++) cin >> C.at(i);
    
    int sat = accumulate(B.begin(),B.end(),0);
    for(int i;i<N-1;i++){
        if(A.at(i)+1 == A.at(i+1)){
            sat += C.at(A.at(i)-1);
        }
    }
    cout << sat << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

int main(){
	int n;
	int a[3];
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	if((a[2] * a[2]) == (a[1] * a[1] ) + (a[0] * a[0]))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = ll(1e18)+1;
const ll MOD = 1000000007;  // 1e9 + 7

// Check if "the count of value which lower than limit" is lower than k
bool check(vector<ll>& a, ll limit, ll k) {
  ll n = a.size();
  ll cnt = 0; // the count of pairs which are lower than m
  rep(i, n) {
    ll x = a[i];
    if (x > 0) { // positve
      int l = -1, r = n;
      // search in [l, r)
      while (r-l > 1) {
        int m = (l+r)/2;
        if (a[m]*x < limit) {
          l = m;
        } else {
          r = m;
        }
      }
      // Here, a[l]*x < limit, limit <= a[l+1]*x
      cnt += l + 1; // [0, l] is lower value
    } else if (x == 0) {
      if (limit > 0) {
        cnt += n;
      }
    } else { // negative
      int l = -1, r = n;
      // search in (l, r]
      while (r-l > 1) {
        int m = (l+r)/2;
        if (a[m]*x < limit) {
          r = m;
        } else {
          l = m;
        }
      }
      // Here, a[l]*x >= limit, limit > a[l+1]*x
      cnt += n - r; // [r, n) is lower value
    }
  }
  // minus self
  rep(i, n) {
    if (a[i] * a[i] < limit) { --cnt; }
  }
  cnt /= 2;

  return cnt < k;
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  sort(all(a));
  ll l = -INF;
  ll r = INF;
  // Search the result in [l, r)
  while (r - l > 1) {
    ll m = (r+l)/2;
    if (check(a, m, k)) { // ok
      l = m;
    } else {
      r = m;
    }
  }
  cout << l << endl;
}


Measured memory_bytes: 1920
#include<cstdio>
#include<algorithm>
using namespace std;

const int NMAX = 111111;
bool chk[NMAX];
int cnt[NMAX];

int main(){
    int n,m; scanf("%d%d",&n,&m);
    chk[1] = true;
    for(int i=1;i<=n;i++) cnt[i]=1;
    for(int i=0;i<m;i++){
        int x,y; scanf("%d%d",&x,&y);
        if(chk[x]) chk[y] = true;
        cnt[x]--; cnt[y]++;
        if(!cnt[x]) chk[x] = false;
    }
    int ans = 0;
    for(int i=1;i<=n;i++) if(chk[i]&&cnt[i]) ans++;
    printf("%d",ans);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>  
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N =  100010;  
const int mod = 1e9 + 7;
#define FI first
#define SE second
typedef pair<int, int>pii;

int hs[N];
int num[N];
ll mul[N];
ll Pow(ll a, int x)
{
	ll ret = 1;
	if (a == 1)
		return 1;
	while (x)
	{
		if (x&1)
			ret = ret*a%mod;
		a *= a;
		a %= mod;
		x >>= 1;
	}
	return ret;
}
ll C(int n, int m)
{
	return mul[n]*Pow(mul[m], mod - 2)%mod * Pow(mul[n-m], mod - 2)%mod;
}
int main()  
{  
  // freopen("in.txt","r",stdin);
   int num[3];
   while (~scanf("%d%d%d", num, num + 1, num + 2))
   {
   	sort(num, num + 3);
   	printf("%d\n" ,num[0] + num[1]);
   }
   return 0;  
}  

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int N;
    int result;
	scanf("%d", &N);
    if (N < 10) {
        result = N;
    } else if (N < 100) {
        result = 10-1;
    } else if (N < 1000) {
        result = 10-1 + N-99;
    } else if (N < 10000) {
        result = 10-1 + 1000-100;
    } else if (N < 100000) {
        result = 10-1 + 1000-100 + N-9999;
    } else {
        result = 10-1 + 1000-100 + 100000-10000;
    }
    printf("%d\n", result);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
	int  i,j,r,c,sum,a[101][101];
	scanf("%d%d",&r,&c);
	for(i=0;i<r;i++){
		for(j=0;j<c;j++)scanf("%d",&a[i][j]);
	}
	for(i=0;i<r;i++){
		sum=0;
		for(j=0;j<c;j++)sum+=a[i][j];
		a[i][c]=sum;
	}
	for(i=0;i<=c;i++){
		sum=0;
		for(j=0;j<r;j++)sum+=a[j][i];
		a[r][i]=sum;
	}
	for(i=0;i<=r;i++){
		for(j=0;j<=c;j++){
			if(j)printf(" ");
			printf("%d",a[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
 
    int V[N], C[N], ans=0, i;
 
    for (i=0; i<N; i++){
        cin >> V[i];
    }
    for (i=0; i<N; i++){
        cin >> C[i];
    }
 
    for (i=0; i<N; i++){
        if (V[i] >= C[i]){
            ans+=(V[i] - C[i]);
        }
    }
 
 
    cout << ans;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    char a,b;
    cin >> a >> b;
    if(a > b)
    {
        cout << ">";
    }
    else if(a == b)
    {
        cout << "=";
    }
    else
    {
        cout << "<";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>
#define rep(i,n) for(int i = 0; i < (n); i++) 
using namespace std;

int main() {
	int r;
	cin >> r;
	cout << pow(r,2) << endl;
	

	return 0;
}


Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 99999999999999999
#define MOD 1000000007 

void func()
{
    ll a[6];
    ll ans=0;
    loop(i,1,6){
        cin>>a[i];
        if(a[i]==0){
            ans=i;
        }
    }
    cout<<ans<<"\n";
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)(v).size())
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1);



int main(void) {
    ll a, b, c;
    cin >> a >> b >> c;
    ll count = 0;
    while (1) {
        if (a % 2 == 1) break;
        if (b % 2 == 1) break;
        if (c % 2 == 1) break;
        ll na, nb, nc;
        na = (b + c) / 2;
        nb = (a + c) / 2;
        nc = (b + a) / 2;
        if (na == a && nb == b && nc == c) {
            cout << -1 << endl;
            return 0;
        }
        a = na;
        b = nb;
        c = nc;
        count++;
    }
    cout << count << endl;
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int n=700;
  if (S.at(0)=='o') n+=100;
  if (S.at(1)=='o') n+=100;
  if (S.at(2)=='o') n+=100;
  cout << n << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct edge
{
	int v,w,nxt;
}e[500005];
int n,m,h[100005],t;
int f[305][305][305],mod=1e9+7,ans;
void add(int u,int v,int w)
{
	e[++t].v=v;
	e[t].w=w;
	e[t].nxt=h[u];
	h[u]=t;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int l,r,x;
		scanf("%d%d%d",&l,&r,&x);
		add(r,l,x);
	}
	f[1][0][0]=3;
	for(int i=1;i<=n;i++)
	{
		for(int j=h[i];j;j=e[j].nxt)
		{
			int v=e[j].v,w=e[j].w;
			for(int k=0;k<i;k++)
				for(int l=0;l<=max(k-1,0);l++)
				{
					if(w==1&&k>=v) f[i][k][l]=0;
					if(w==2&&(k<v||l>=v)) f[i][k][l]=0;
					if(w==3&&l<v) f[i][k][l]=0; 
				}
		}
		for(int j=0;j<i;j++)
			for(int k=0;k<=max(j-1,0);k++)
			{
				f[i+1][j][k]=(f[i+1][j][k]+f[i][j][k])%mod;
				f[i+1][i][k]=(f[i+1][i][k]+f[i][j][k])%mod;
				f[i+1][i][j]=(f[i+1][i][j]+f[i][j][k])%mod;
			}
	}
	for(int i=0;i<n;i++)
		for(int j=0;j<=max(i-1,0);j++)
			ans=(ans+f[n][i][j])%mod;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 110848
# -*- coding: utf-8 -*-
"""
https://abc058.contest.atcoder.jp/tasks/arc071_a

"""
import sys
from sys import stdin
from collections import Counter
input = stdin.readline


def solve(S, n):
    freq = [[0]*n for _ in range(26)]

    for x, s in enumerate(S):
        c = Counter(s).most_common()
        for ch, f in c:
            y = ord(ch) - ord('a')
            freq[y][x] = f

    chars = []
    for i, ch in enumerate('abcdefghijklmnopqrstuvwxyz'):
        f = min(freq[i])
        for _ in range(f):
            chars.append(ch)
    return chars


def main(args):
    S = []
    n = int(input())
    for _ in range(n):
        s = list(input().strip())
        S.append(s)
    ans = solve(S, n)
    print(*ans, sep='')


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3316
#include <stdio.h>

int g(double x1,double y1,double x2, double y2, double xp, double yp){
  double v1x, v1y, v2x, v2y;
  v1x = x2-x1;
  v1y = y2-y1;
  v2x = xp-x1;
  v2y = yp-y1;
  return v1x*v2y-v2x*v1y;

}
int main(){
  double x1,y1,x2,y2,x3,y3;
  double xp,yp;
  int f1,f2,f3;
  char tmp[64];
  
  while(fgets(tmp, 64, stdin)!=NULL){
	sscanf(tmp, "%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp);
	f1 = g(x1,y1,x2,y2,xp,yp);
	f2 = g(x2,y2,x3,y3,xp,yp);
	f3 = g(x3,y3,x1,y1,xp,yp);
	//printf("%d %d %d\n",f1,f2,f3);
	if((f1>0 && f2>0 && f3>0)||(f1<0 && f2<0 && f3<0))
	  printf("YES\n");
	else
	  printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 624
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    int n, k; cin >> n >> k;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    
    map<long long, int> s[2];
    int cur = 0, prev = 1;
    for (int L = 0; L < n; L++) {
        long long sum = 0;
        for (int R = L; R < n; R++) {
            sum += a[R];
            s[prev][sum]++;
        }
    }

    long long ans = 0;
    for (int i = 50; i >= 0; i--) {
        auto it = s[prev].lower_bound(1LL<<i);
        if (it == s[prev].end()) continue;
        s[cur].clear();
        int count = 0;
        for (auto it1 = it; it1 != s[prev].end(); it1++) count += it1->second;
        // if (k <= distance(it, s[prev].end())) {
        if (k <= count) {
            ans += 1LL << i;
            while (it != s[prev].end()) {
                s[cur][it->first - (1LL<<i)] = it->second;
                it++;
            }
        } else {
            for (auto e : s[prev]) {
                if (e.first >= 1LL<<i) {
                    s[cur][e.first - (1LL<<i)] += e.second;
                } else
                    s[cur][e.first] += e.second;
            }
        }
        swap(prev, cur);
    }
    cout << ans << endl;
}


Measured memory_bytes: 38656
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define M_PI 3.1415926
int A[100005]={};
int cnt[100005]={};
int num[100005]={};
bool cmp(int a,int b){
    return a>b;
}
int main()
{
    int a;
    while(cin>>a){
int n=1;
for(int i=0;i<a;i++){
    cin>>A[i];
    cnt[A[i]]++;
}
int ans=0;
int flag=0;
for(int i=0;i<=100000;i++){
    if(cnt[i]==1)
        ans++;
    if(cnt[i]>1){
            ans++;
        num[n++]=cnt[i]-1;
    flag=1;
    }
}
int l=1,r=n;
if(flag)
    r--;
for(int i=1;i<=r;i++){
    while(num[i]>=3){
    num[i]-=2;
    }
}
sort(num+1,num+1+n,cmp);
while(1){
        if(l>=r){
            bk;
        }
    int tmp=min(num[l],num[r]);
    num[l]-=tmp;
    num[r]-=tmp;
    if(num[l]==0)
        l++;
    if(num[r]==0)
        r--;
    if(l>=r){
        bk;
    }
    sort(num+l,num+r+1,cmp);
}
for(int i=1;i<=n;i++){
    ans-=num[i];
}
cout<<max(1,ans)<<endl;
    }


    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

#define N 100
#define M 1000

int g[N][N];
int a[M],b[M],c[M];
int n,m;

// calculates the distances of the shortest paths
// when graph g is an undirected graph
// if g is directed, fix the line 15
void warshall_floyd(void){
    int i,j,k;
    rep(i,n)rep(j,n)
        if(i!=j)g[i][j]=inf;
    rep(i,m)g[a[i]-1][b[i]-1]=g[b[i]-1][a[i]-1]=c[i];
    rep(k,n)rep(i,n)rep(j,n)
        if(g[i][j]>g[i][k]+g[k][j])
            g[i][j]=g[i][k]+g[k][j];
}

void run(){
    cin>>n>>m;
    rep(i,m){
        cin>>a[i]>>b[i]>>c[i];
    }
    warshall_floyd();
    int ans=0;
    rep(i,m){
        bool f=true;
        rep(j,n){
            rep(k,n){
                if(g[j][a[i]-1]+c[i]+g[b[i]-1][k]==g[j][k]){
                    f=false;
                    break;
                }
            }
        }
        ans+=f;
    }
    cout<<ans<<endl;
}

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

int main() {
  int N;
  cin >> N;
  int ans{};
  for (int i{1}; N >= i; i *= 100) {
    ans += min(i*10-1, N) - (i - 1);
  }

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


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>

#define TASK "Yet Another Palindrome Partitioning"

using namespace std;

const int maxn = 2e5 + 1;
string s;
int n,f[(1<<26)],x;

void OpenFile()
{
    //freopen(TASK".INP","r",stdin);
    //freopen(TASK".OUT","w",stdout);
}

void Enter()
{
    cin >> s;
}

void Init()
{

}

void Solve()
{
    fill(f+1,f+(1<<26),s.size());
    for (auto c : s) {
        x ^= 1 << (c - 'a');
        for (int i=0;i<26;++i)
            f[x] = min(f[x],f[x^(1<<i)]+1);
    }
    if (f[x] == 0) f[x] = 1;
    cout << f[x];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //OpenFile();

    Enter();
    Init();
    Solve();
}


Measured memory_bytes: 262804
#include <iostream>

using namespace std;

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

  int ans = N;
  for (int i = 0; i <= N; ++i) {
    int ans_i = 0;
    // i を 6 のべき乗のみで引き出す
    int div = i;
    do {
      ans_i += div % 6;
      div /= 6;
    } while (div != 0);

    // N - i を 9 のべき乗のみで引き出す
    div = N-i;
    do {
      ans_i += div % 9;
      div /= 9;
    } while (div != 0);

    ans = min(ans, ans_i);
  }

  cout << ans << endl;
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
int main(){
	ll n, k;
	cin>>n>>k;
	if(2 * k - 1 > n) { cout<<"-1\n"; return 0; }
	map<ll,ll>used;
	vector<tuple<ll,ll,ll>>ans;
	ll one=k+n-1,two=k+n,third=one+two;
	while(third >= k + 2 * n){
		used[one]=1, ans.pb({one,two,third});
		one -= 2, ++ two, -- third;
	}
	third = (k+n-1) + (k+n) + 1;
	one += 2;
	if(one ^ k) one = k;
	else one = k+1;
	two = k + 2 * n - 1;
	while(third < k + 3 * n){
		if(used[one]) ++ one;
		assert(!used[one]);
		ans.pb({one,two,third});
		-- two, ++ third, ++ one;
	}
	assert(siz(ans)==n);
	for(auto i:ans)assert(get<0>(i)+get<1>(i)<=get<2>(i));
	for(auto i:ans)cout<<get<0>(i)<<' '<<get<1>(i)<<' '<<get<2>(i)<<'\n';
}


Measured memory_bytes: 11820
def main():
  while True:
    n, m = map(int,input().split())
    if not n:
      break
    
    lst = [0] * m
  
    for i in range(n):
      lst = [i + j for i, j in zip(lst, map(int,input().split()))]
  
    lst = list(zip(lst,[i for i in range(1,m + 1)]))
    lst = sorted(lst,key=lambda t:-t[0])
    
    print(" ".join(list(map(str,[t[1] for t in lst]))))
  
main()


Measured memory_bytes: 5624
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

#define cin_desync()                                                           \
    do {                                                                       \
        ios_base::sync_with_stdio(false);                                      \
        cin.tie(0);                                                            \
    } while (0)

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

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

int main() {
    ll N, M;
    cin >> N >> M;

    string S, T;
    cin >> S >> T;

    ll lcm = N * M / __gcd(N, M);
    ll s1 = lcm / N, s2 = lcm / M;

    ll clash = s1 * s2 / __gcd(s1, s2);
    for (ll c = 0; c < lcm; c += clash) {
        ll si = c / s1;
        ll sj = c / s2;

        if (S[si] != T[sj]) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << lcm << endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>


int main() {
	int N;
	std::cin>>N;
	std::vector<int> a_vec(N);
	std::vector<int> b_vec(N);
	std::vector<int> c_vec(N);
	for (int i = 0; i < N * 3; ++i) {
		int h;
		std::cin >> h;
		if (i % 3 == 0) {
			a_vec[i/3] = h;
		} else if (i % 3 == 1) {
			b_vec[i/3] = h;
		} else {
			c_vec[i/3] = h;
		}
	}
	std::vector<int> vec_1(N);
	std::vector<int> vec_2(N);
	std::vector<int> vec_3(N);
	int result = 0;
	vec_1[0] = a_vec[0];
	vec_2[0] = b_vec[0];
	vec_3[0] = c_vec[0];

	for (int i = 1; i < N; ++i) {
		vec_1[i] = a_vec[i] + std::max(vec_2[i-1], vec_3[i-1]);
		vec_2[i] = b_vec[i] + std::max(vec_1[i-1], vec_3[i-1]);
		vec_3[i] = c_vec[i] + std::max(vec_1[i-1], vec_2[i-1]);
	}
	result = std::max(vec_1[N-1], std::max(vec_2[N-1], vec_3[N-1]));
	printf("%d\n", result);
	return 0;
}


Measured memory_bytes: 2560
using System;
using System.Linq;

namespace _166_b
{
    internal class TrickOrTreat
    {
        private static void Main(string[] args)
        {
            var nk = Console.ReadLine()?.Split(" ").Select(int.Parse).ToArray();
            if (nk == null) return;

            var n = nk[0];
            var k = nk[1];

            var sunuke = new int[n];
            for (var i = 0; i < n; i++)
            {
                sunuke[i] = 0;
            }

            for (var i = 0; i < k; i++)
            {
                var d = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());
                var a = Console.ReadLine()?.Split(" ").Select(int.Parse).ToArray();
                if (a == null) return;

                for (var j = 0; j < d; j++)
                {
                    sunuke[a[j] - 1]++;
                }
            }

            var zeroSunuke = 0;
            for (var i = 0; i < n; i++)
            {
                if (sunuke[i] == 0)
                {
                    zeroSunuke++;
                }
            }

            Console.WriteLine(zeroSunuke);
        }
    }
}

Measured memory_bytes: 28424
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int x,y;
    scanf("%d%d",&x,&y);


    ll ans = 0;

rep(i,1){
    if(x==y){
        ;
        break;
    }
    if(x==-y){
        ans++;
        break;
    }
    if(abs(x)<abs(y)){
        if(x<0){
            ans++;
        }
        ans += abs(y) - abs(x);
        if(y<0)ans++;
        break;
    }
    if(abs(x)>abs(y)){
        if(x>0)ans++;
        ans += abs(x) - abs(y);
        if(y>0){
            ans++;
        }
        break;
    }
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b,ans;
vector<int> path[10];
bool reached[10];
void dfs(int x){
  reached[x] = true;
  int c = 0;
  for(int i=0;i<n;++i)
    if(reached[i]) c++;
  if(c==n){
    ans++;
    return;
  }
  for(auto &i:path[x]){
    if(reached[i]) continue;
    dfs(i);
    reached[i] = false;
  }
}

int main()
{
  cin >> n >> m;
  for(int i=0; i<m; i++){
    cin >> a >> b;
    a--;
    b--;
    path[a].push_back(b);
    path[b].push_back(a);
  }
  
  ans = 0;
  for(int i=0;i<n;++i) reached[i]=false;
  dfs(0);
  cout << ans << "\n";
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    ll n,a,b;cin >>n>>a>>b;
    ll d=b-a;
    ll ans;
    if(d%2==0)ans=d/2;
    else {
        ans=d/2;
        ans+=min(n-b+1,a);
    }
    cout <<ans <<endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1000;
const char END = '\n';

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

	ll Ans = 0, sub = 1;
	ll A, B;
	cin >> A >> B;
	A = A - 1;
	while (1) {
		if (sub >= B)
			break;
		sub += A;
		Ans++;
	}

	cout << Ans;
	cout << END;
	return 0;
}

Measured memory_bytes: 256
// Charan Sriramula
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
 
const ll lg=22;
const ll N=1e6+5;
const ll M=5e8;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;
 
#define is(n) scanf("%d",&n)
#define io(n) printf("%d\n",n)
#define ls(n) scanf("%lld",&n)
#define lo(n) printf("%lld\n",n)
 
#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
 
inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

ll n,k,a[N];

bool F(ll cur)
{
    ll cnt=0;
    vector<ll> v;
    for(ll i=0;i<n;i++)
    {
        ll div=a[i]%cur;
        if(div==0||div==cur){continue;}
        v.pb(div);
    }
    sort(all(v));
    ll low=0,high=v.size()-1;
    while(low<high)
    {
        ll lowsteps=v[low];
        ll highsteps=cur-v[high];
        if(lowsteps==highsteps)
        {
            v[low]=0;
            v[high]=cur;
            low++;
            high--;
            cnt+=lowsteps;
        }
        else if(lowsteps<highsteps)
        {
            v[low]=0;
            v[high]+=lowsteps;
            low++;
            cnt+=lowsteps;
        }
        else
        {
            v[high]=0;
            v[low]-=highsteps;
            high--;
            cnt+=highsteps;
        }
        if(cnt>k){return false;}
    }
    for(ll i=0;i<v.size();i++)
    {
        if(v[i]==0||v[i]==cur){continue;}
        return false;
    }
    return true;
}

int main()
{
    cin>>n>>k;
    ll maxi=0,sum=0;
    for(ll i=0;i<n;i++){cin>>a[i];sum+=a[i];}
    for(ll i=1;i<=sqrt(sum);i++)
    {
        if(sum%i){continue;}
        ll pos=F(i);
        ll qpos=F(sum/i);
        if(pos){maxi=max(maxi,i);}
        if(qpos){maxi=max(maxi,sum/i);}
    }
    cout<<maxi<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
    string s;
    int ans=0,now=0;
    cin >> s;
   
    string t = "ATCG";
    
    for(int i=0;i<s.size();i++){
        bool flag = false;
        for(int j=0;j<t.size();j++){
            if(s[i] == t[j]) flag = true;
        }

        if(!flag) now=0;
        else
        {
            now++;
            if(now>ans){
                ans = now;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
h,w,d = gets.chomp.split(' ').map(&:to_i)
px = Array.new(h + 1,0)
py = Array.new(w + 1,0)
(0...h).each do |i|
  num_list = gets.chomp.split(' ').map(&:to_i)
  (0...w).each do |j|
    px[num_list[j]] = i
    py[num_list[j]] = j
  end
end

q = gets.to_i
mp = Array.new(h * w + 1,0)
(d + 1..h * w).each do |i|
  mp[i] = mp[i - d] + (px[i - d] - px[i]).abs + (py[i - d] - py[i]).abs
end

(0...q).each do |i|
  l,r = gets.chomp.split(' ').map(&:to_i)
  puts mp[r] - mp[l]
end

Measured memory_bytes: 5500
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int r=0,l=s.length();
  for(int i=l-1;i>0;--i){
    if(s[i]<'9'){
      s[i]='9';
      for(int j=i-1;j>=0;--j){
        if(s[j]=='0')s[j]='9';
        else{
          if(s[j]!='x')s[j]--;
          break;
        }
      }
    }
    for(int j=0;s[j]=='0'||s[j]=='x';++j)s[j]='x';
  }
  for(auto c:s)if(c!='x')r+=c-'0';
  cout<<r;
  return 0;
}

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

const int N = 100005;
int n, l, a[N];
int main () {
	cin >> n >> l;
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	int k = -1;
	for (int i = 1; i < n; ++i) {
		if (a[i] + a[i + 1] >= l) {k = i; break;}
	}
	if (k == -1) return puts("Impossible"), 0;
	puts("Possible");
	for (int i = 1; i < k; ++i) printf("%d\n", i);
	for (int i = n - 1; i > k; --i) printf("%d\n", i);
	printf("%d\n", k);
	return 0;
}

Measured memory_bytes: 1152
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
int main(void){
	int N=0;
	cin>>N;
	vector<int>v(N);
	for(int i=0;i<N;i++){
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	double ans=v[0];
	for(int i=1;i<N;i++){
		ans+=v[i];
		ans/=2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
long long int pow(int a){
	long long int p=1;
	for(int i=0;i<a;i++){
		p=p*27;
	}
	return p;
}
int main(){
	char s[6000]={};
	scanf("%s",s);
	long long int g[6000]={};
	int k;
	scanf("%d",&k);
	int q;
	for(int i=0;true;i++){
		if(s[i]==0){
			q=i;
			break;
		}
		g[i]=s[i]-'a'+1;
	}
	long long int a[5*q]={};
	int p=0;
	for(int i=0;i<q;i++){
		long long int u=0;
		for(int j=0;j<5;j++){
			u+=g[i+j]*pow(4-j);
			a[p]=u;
			p++;
		}
	}
	std::sort(a,a+5*q);
	q=1;
	for(int i=1;true;i++){
		if(a[i]!=a[i-1])q++;
		if(q==k){
			char t[5]={};
			for(int j=4;j>=0;j--){
				t[j]=a[i]%27;
				if(t[j]!=0)t[j]=t[j]+'a'-1;
				a[i]=a[i]/27;
			}
			printf("%s\n",t);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 384
$n = gets.to_i
INF = 1 << 30
$m = Array.new($n){ Array.new }
$n.times do
  l = gets.split.map(&:to_i)
  (1..l[1]).each{ |i| $m[l[0]] << l[2*i,2] }
end

def dijkstra(x)
  cost = Array.new($n, INF)
  cost[x] = 0
  used = Array.new($n)
  while true
    m = INF
    $n.times{ |i| m = cost[i] if !used[i] && m > cost[i] }
    break if m == INF 
    $n.times do |i|
      if m == cost[i]
        used[i] = true
        $m[i].each do |r|
          u, w = r
          cost[u] = cost[i] + w if cost[u] > cost[i] + w 
        end
      end
    end
  end
  cost
end
ret = dijkstra(0)
ret.each_index{ |i| puts "#{i} #{ret[i]}" }

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

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

int main()
{
    long s=0;
    int k;
    cin >> k;
    for (int i = 1; i < k + 1; i++)
    {
        for (int j = 1; j < k + 1; j++)
        {
            for (int l = 1; l < k + 1; l++)
            {
                s += gcd(i, gcd(j, l));
            }
        }
    }
    cout << s;
}


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

string s;

void input() {
	cin >> s;
}

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

	input();
	if (s.length() == 2) {
		cout << s << "\n";
	}
	else {
		reverse(s.begin(), s.end());
		cout << s << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
#define repd(i,a,b) for (int i=a;i<int(b);i++)
#define rep(i,n) repd(i,0,n)
#define VARNAME(v) #v
using P = pair<int,int>;


int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int BEAM = 870;
  int d;vector<int> c(26);cin>>d;rep(i,26)cin>>c[i];
  vector<array<int, 26>> s(d);
  rep(i,d)rep(j,26)cin>>s[i][j];
  vector<int> curs = {0};
  vector<array<int, 26>> curl(1);
  vector<vector<int>> cura(1);
  rep(i,d){
    int len = int(curs.size()) * 26, ind = 0;
    vector<P> nxs(len);
    vector<array<int, 26>> nxl(len);
    vector<vector<int>> nxa(len);
    rep(j, curs.size()){
      rep(t, 26){
        int score = curs[j];
        array<int, 26> last = curl[j];
        vector<int> ans = cura[j];
        score += s[i][t];
        last[t] = i+1;
        rep(k,26)score -= c[k]*(i+1 - last[k]);
        ans.emplace_back(t);
        nxs[ind] = P(score, ind);
        nxl[ind] = last;
        nxa[ind] = ans;
        ind++;
      }
    }
    sort(nxs.rbegin(), nxs.rend());
    len = min(len, BEAM);
    curs.resize(len);curl.resize(len);cura.resize(len);
    rep(j,len){
      curs[j] = nxs[j].first;
      curl[j] = nxl[nxs[j].second];
      cura[j] = nxa[nxs[j].second];
    }
    if(i % 73 == 0)BEAM -= 80;
  }
  int ans = 0;
  rep(i,min(int(curs.size()), BEAM)){
    if(curs[ans] < curs[i])ans = i;
  }

  for(auto x : cura[ans]){
    cout << x+1 << endl;
  }
}


Measured memory_bytes: 24092