akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author SimplyDivine
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            Arrays.sort(a);
            int sum = 0;
            for (int i = n - 1; i >= n - k; i--) {
                sum += a[i];
            }
            out.println(sum);
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream i) {
            br = new BufferedReader(new
                    InputStreamReader(i));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}



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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> a(n);
    REP(i,n)cin >> a[i];
    sort(ALL(a));
    int32 x = 0;
    REP(i,n-1){
        if(abs(a[n-1] - a[i] * 2) < abs(a[n-1] - a[x] * 2)){
            x = i;
        }
    }
    cout << a[n-1] << " " << a[x] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main (void)
{
	int a , b , c;
	scanf("%d %d %d" , &a , &b , &c);
	if(a < b)
	{
		if(b < c)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
	    printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 * 2;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	rep(i, n) cin >> l[i];
	sort(l.begin(), l.end(), greater<int>());
	int out = 0;
	rep(i, k) out += l[i];
	cout << out << endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  for (int i = 0; i < N; i++){
    cin >> S[i];
  }
  sort(S.begin(), S.end());
  for (int i = 0; i < N; i++){
    cout << S[i];
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
 
#define f first
#define s second
#define MAX_N 155
#define INF 1000000000
 
using namespace std;
 
typedef pair<int,int> P;
 
int main(void){
 
  int n,m,k,a,b;
 
  while(cin >> n >> m,n|m){
    vector<P>v[MAX_N];
     
    for(int i=1;i<=n;i++){
      cin >> k;
      for(int j=0;j<k;j++){
    	cin >> a >> b;
   		 v[i].push_back(make_pair(a,b));
      }
    }
 
    int dp[MAX_N][11][80];
 
    for(int i=0;i<MAX_N;i++)
      	for(int j=0;j<11;j++)
  			for(int k=0;k<80;k++)
      			dp[i][j][k]=INF;
 
    for(int i=0;i<11;i++)
      for(int j=0;j<80;j++)
    	dp[0][i][j]=dp[1][i][j]=0;
 
    for(int i=2;i<=n;i++){
      for(int j=0;j<v[i].size();j++){
    	for(int l=m;l>=0;l--){
      		for(int k=0;k<v[i-1].size();k++)
        	dp[i][j][l]=min(dp[i][j][l],dp[i-1][k][l]+(v[i][j].s+v[i-1][k].s)*abs(v[i][j].f-v[i-1][k].f));
      		
      		if(l<m){
        		if(i==2)dp[i][j][l]=0;
        		for(int p=0;p<v[i-2].size();p++)
          			dp[i][j][l]=min(dp[i][j][l],dp[i-2][p][l+1]+(v[i][j].s+v[i-2][p].s)*abs(v[i][j].f-v[i-2][p].f));
      		}
    	}
      }
    }
     
    int ans=INF;
    for(int i=0;i<v[n].size();i++)ans=min(ans,dp[n][i][0]);
    if(m>0)for(int i=0;i<v[n-1].size();i++)ans=min(ans,dp[n-1][i][1]);
 
    cout << ans << endl;
  }
 
  return 0;
}

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

int main(){
    int N, M, a, b;
    int result[50] = {0};

    cin >> N >> M;

    for(int i = 0;i < M;i++){
        cin >> a >> b;
        result[a-1]++;
        result[b-1]++;
    }

    for(int i = 0;i < N;i++){
        cout << result[i] << endl;
    }

  return 0;
}


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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n;
  cin >> n;
  if(n%2==0) cout << n << endl;
  else cout << 2*n << endl;

  return 0;
}


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

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(); it != array.end();++it)
#define repa(n,array) for(auto n :(array))

typedef long long ll ;
typedef vector<int> vi ;
typedef vector<ll> vl ;
//template<class Value>
//using dict = std::map< string, Value >;
typedef map<string,int> dict ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
double eps = 1e-10 ;

template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a = 0,b = 0,num;
  rep(i,4){
    cin >> num;
    a += num;
  }
  rep(i,4){
    cin >> num;
    b += num;
  }
  if(a >= b){
    cout << a << endl;
  }
  else{
    cout << b << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    vector<ll>v;
    map<ll,ll>m;
    for(ll i=0;i<=1000;i++) {v.push_back((i*i*i*i*i));m[(i*i*i*i*i)]=i;}
    sort(v.begin(),v.end());
    ll n;
    cin>>n;
   for(int i=0;i<v.size();i++) {
        auto it = lower_bound(v.begin(),v.end(),abs(v[i]-n));
    //   cout<<v[i]<<" "<<abs(v[i]-n)<<"\n";
        if((*it)==abs(v[i]-n)) {
            
            if(v[i]>n) {
                cout<<max(m[abs(v[i]-n)],m[v[i]])<<" "<<min(m[abs(v[i]-n)],m[v[i]])<<"\n";
            }
            else{
                 cout<<max(m[abs(v[i]-n)],m[v[i]])<<" "<<-min(m[abs(v[i]-n)],m[v[i]])<<"\n";
            }
            return 0;
        }
    }
}

Measured memory_bytes: 3612
#include<stdio.h>
int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
    }else{
    	printf("a == b\n");
    }
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>

int main(){
    int N,M,A,B;
    std::cin >> N >> M >> A >> B;
    if(N>=M){
        if(A>=B){
            std::cout << M+B << std::endl;
        }else{
            std::cout << M+A << std::endl;
        }
    }else{
        if(A>=B){
            std::cout << N+B << std::endl;
        }else{
            std::cout << N+A << std::endl;
        }
    }
    
    
}

Measured memory_bytes: 768
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    import numpy as np
    from itertools import product

    n, m, x = list(map(int, readline().split()))
    a, c = [], []
    for i in range(n):
        c_temp, *a_temp = list(map(int, readline().split()))
        c.append(c_temp)
        a.append(a_temp)

    a = np.array(a)
    ans = INF

    for bit in product(range(2), repeat=n):
        price_total = 0
        learn_total = np.array([0] * m)
        for i in range(n):
            if bit[i] == 1:
                price_total += c[i]
                learn_total += a[i]
        if np.all(learn_total >= x):
            ans = min(ans, price_total)

    if ans == INF:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


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


using namespace std;

typedef long long ll;
const int N=1e7;
bool isprime[N+1];
void sieve()
{
    memset(isprime,true,sizeof(isprime));
    isprime[0]=isprime[1]=false;
    for(ll i=2;i*i<=N;i++)
    {
        if(isprime[i])
        {
            for(ll j=i*i;j<=N;j+=i)
            {
                isprime[j]=false;
            }
        }
    }
}


#define pi 2*acos(0.0)
int main(void)
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    // cout.tie(0);
    sieve();
    vector<ll>v;
    for(ll i=2;i<=N;i++)
    {
        if(isprime[i])
        {
            v.push_back(i);
        }
    }



   int n;
   cin>>n;
   ll arr[n];
   for(int i=0;i<n;i++)
   {
       cin>>arr[i];
   }
   map<int,ll>m;
   for(int j=0;j<n;j++)
   {
       ll x = arr[j];
       for(int i=0;v[i]*v[i]<=x;i++)
       {
           if(x%v[i]==0)
           {
               m[v[i]]++;
               while(x%v[i]==0)
               {
                   x/=v[i];
               }
           }

       }
       if(x>1)
       {
           m[x]++;
       }
   }
   ll ans=0;

   map<int,ll>::iterator it;
   for(it = m.begin();it!=m.end();it++)
   {
       ans = max(ans,it->second);
   }
   if(ans<=1)
   {
       cout<<"pairwise coprime"<<endl;
   }
   else if(ans<n)
   {
       cout<<"setwise coprime"<<endl;
   }
   else
   {
       cout<<"not coprime"<<endl;
   }




}




Measured memory_bytes: 30776
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 1000000007;
const long long int INF = 99999999999999999;




long long int N,M,K,sum=0,res=0;
string str;

int main()
{
    cout << fixed << setprecision(18);
    
    cin>>str;
    IFYes(!(str[0]=='A'&&str[1]=='A'&&str[2]=='A'||str[0]=='B'&&str[1]=='B'&&str[2]=='B'))
    
    
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 2333
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n, m, c;
int main() {
	n = read(), m = read(), c = read();
	rep(i, 1, m) printf("%d ", c);
	if(c == 1000000000) rep(i, 1, n - m) printf("1 "); 
	else rep(i, 1, n - m) printf("%d ", c + 1); 
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main() {
    ll N,M;
    cin >>N>>M;
    map<ll,ll>m;
    rep2(i,N){
        ll p;
        cin>>p;
        m[p]=i;
    }
    UnionFind tree(N+1);


    rep(i,M){
        ll x,y;
        cin>>x>>y;
        tree.unite(x, y);
    }
    ll ans = 0;
    rep2(i,N){
        if(tree.same(i,m[i])){
            ans++;
        }
    }

    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 9884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
const int INF = 1001001001;

int main(){
  int n,m;
  cin >> n >> m;
  vector<tuple<int,int,int>> py(m);
  for(int i=0;i<m;i++){
    int input; cin >> input; get<0>(py.at(i)) = input;
    cin >> input; get<1>(py.at(i)) = input;
    get<2>(py.at(i)) = i;
  } 
  sort(py.begin(),py.end());

  int mem = get<0>(py.at(0));
  int year = 1;
  get<1>(py.at(0)) = year++;
  for(int i=1;i<m;i++){
    if(get<0>(py.at(i)) != mem){
      year = 1;
      mem = get<0>(py.at(i));
    }
    get<1>(py.at(i)) = year++;  
  }
  sort(py.begin(),py.end(),[](const tuple<int,int,int>a, const tuple<int,int,int>b){
    return get<2>(a) < get<2>(b);
  });
  
  for(int i=0;i<m;i++){
    string a = to_string(get<0>(py.at(i)));
    string b = to_string(get<1>(py.at(i)));
    string ans = "";
    for(int j=0;j<6-(int)(a.size());j++){
      ans += '0';
    }
    ans += a;
    for(int j=0;j<6-(int)(b.size());j++){
      ans += '0';
    }
    ans += b;
    cout << ans << endl;
  }
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
int main()
{
    int H, W; cin >> H >> W;
    REP(i, W + 2) cout << '#';
    cout << '\n';
    REP(i, H) {
        cout << '#';
        REP(j, W) {
            char c; cin >> c;
            cout << c;
        }
        cout << "#\n";
    }
    REP(i, W + 2) cout << '#';
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for _ in range(M)]
ans=min(a)+min(b)
for x,y,c in xyc:
  ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)

Measured memory_bytes: 38496
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;

ll N;
vector<pair<ll, ll>> AB;

void input() {
    cin >> N;
    AB.resize(N);
    for (ll i = 0; i < N; i++) {
        cin >> AB[i].first >> AB[i].second;
    }
}

ll solve() {
    sort(AB.begin(), AB.end(), [](auto l, auto r) {
        return l.first + l.second > r.first + r.second;
    });
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        if (i % 2 == 0) {
            ans += AB[i].first;
        } else {
            ans -= AB[i].second;
        }
    }
    return ans;
}


int main() {
    input();
    cout << solve() << endl;
    
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  string s;
  cin >> n >> s;
  ll r=0; 
  ll g=0;
  ll b=0; 
  rep(i,n){
    if(s.at(i)=='R') r++;
    if(s.at(i)=='G') g++;
    if(s.at(i)=='B') b++;
  }
  ll count = 0;
  for(int i = 0; i<n; i++){
    for(int j=i+1; j<n; j++){
      int k = 2*j-i;
      if(k>=n) continue;
      if(s.at(i)!=s.at(j)&&s.at(j)!=s.at(k)&&s.at(k)!=s.at(i)) count++;
    }
  }
  cout << r*g*b-count << endl;
}



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

using namespace std;

int main()
{
    int n,p,cnt;
    cin >> n;
    int arr[n];
    for(int i=0;i<n;i++){ cin >> arr[i]; }
    p=1;
    cnt=0;
    for(int i=0;i<n;i++)
    {
        if(p==arr[i])
        {
            p++;
            cnt++;
        }
    }

    if(p==1){ cout << "-1\n"; }
    else { cout << n-cnt << endl; }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int) 2e5 + 7;

struct tree
{
    int t[N];
    tree()
    {
        for (int i = 0; i < N; i++)
        {
            t[i] = 0;
        }
    }
    void upd(int i, int x)
    {
        while (i < N)
        {
            t[i] = max(t[i], x);
            i += i & (-i);
        }
    }
    int get(int i)
    {
        int sol = 0;
        while (i)
        {
            sol = max(sol, t[i]);
            i -= i & (-i);
        }
        return sol;
    }
};

tree a;
tree b;
int n;
int q;
ll cnt;

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

    cin >> n >> q;
    for (int i = 1; i <= q; i++)
    {
        int tp, x, lo = 1, hi = n, sol = 0;
        cin >> tp >> x;
        if (tp == 1)
        {
            for (int k = (1 << 17); k >= 1; k /= 2)
            {
                if (sol + k < N && b.t[sol + k] < x)
                {
                    sol += k;
                }
            }
            cnt += min(n - 1, sol);
            a.upd(x, sol);
        }
        else
        {
            for (int k = (1 << 17); k >= 1; k /= 2)
            {
                if (sol + k < N && a.t[sol + k] < x)
                {
                    sol += k;
                }
            }
            cnt += min(n - 1, sol);
            b.upd(x, sol);
        }
    }
    cnt += 2 * n - 1;
    ll white = cnt;
    ll green = 2 * n - 3 - q;
    ll black = (ll) n * n - white - green;
    cout << black << "\n";
}


Measured memory_bytes: 5196
import java.util.Scanner;

public class Main{
static int LONGEST=2000000000;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		//System.out.print("Input -> ");
		while(sc.hasNext()){
			long a =sc.nextLong();
			long b =sc.nextInt();
			
			//System.out.println("input="+a+" "+b);
			//System.out.println("LCM="+LCM(a,b)+" "+"GCD="+GCD(a,b));
			System.out.println(GCD(a,b)+" "+LCM(a,b));
			//System.out.print("Next Input -> ");
		}
	}
	
	public static long LCM(long a,long b){
		long max=Math.max(a, b),ans=0;
		long min;
		
		if(max==a){
			min=b;
		}else{
			min=a;
		}
		for(long i=1;i<=LONGEST;i++){
			if((max*i)%min==0){
				ans=max*i;
				 break;
			}
		}
		return ans;
	}
	
	public static long GCD(long a,long b){
		long gcd;
		if(b==0){
			gcd=a;
		}else{
			gcd=GCD(b,a%b);
		}
		return gcd;
	}

}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

int getHourFromSecond(int x) {
	return x / 3600;
}
int getMinuteFromSecond(int x) {
	return (x % 3600) / 60;
}
int getSecond(int x) {
	return x % 60;
}
int main() {
	int x;
	cin >> x;
	cout << getHourFromSecond(x);
	cout << ":";
	cout << getMinuteFromSecond(x);
	cout << ":";
	cout << getSecond(x) << endl;
}


Measured memory_bytes: 3096
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    vector<int> vec(9), perm(9);
    for(int i=0; i<9; i++) {
        cin >> vec[i];
        perm[i] = i + 1;
    }

    int ans = 0;
    do {
        bool ok = true;
        for(int i=0; i<9; i++) {
            if(vec[i] < 0) continue;
            ok &= (vec[i] == perm[i]);
        }

        if(ok) {
            int lhs = perm[0] + perm[2] + perm[5];
            lhs +=  10 * (perm[1] + perm[4]);
            lhs += 100 * perm[3];

            int rhs = 100 * perm[6] + 10 * perm[7] + perm[8];

            if(lhs == rhs) ans++;
        }
    }while(next_permutation(perm.begin(), perm.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
#define MAX 55

int main() {
  int n;
  cin >> n;
  string str[n];
  for (int i = 0; i < n; i++) {
    cin >> str[i];
    sort(str[i].begin(), str[i].end());
  }

  int alpha[MAX][26] = {};
  int len[26] = {};

  for (int i = 0; i < 26; i++) len[i] = 100;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      alpha[i][j] = 0;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < str[i].length(); j++) {
      for (int k = 0; k < 26; k++) {
        if (str[i][j] - 'a' == k) alpha[i][k]++;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int k = 0; k < 26; k++) {
      len[k] = min(len[k], alpha[i][k]);
    }
  }

  string ans = "";
  for (int i = 0; i < 26; i++) {
    if (len[i] == 100) continue;
    for (int j = 0; j < len[i]; j++) {
      ans += char('a' + i);
    }
  }

  cout << ans << endl;
}

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

typedef long long ll;
typedef pair<int, pair<int, int>> piii;
//loop
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//STL
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

const int INF = 1e9;

#define deg_to_rad(deg) ((deg)*M_PI/180.0)



void Main()
{
    ll X;
    cin >> X;

    int ans = 1;
    double x = 1;
    double y = 0;

    if (360 % X == 0)
    {
        cout << 360 / X << endl;
        return;
    }

    while (true)
    {
        if (-0.00001 <= x && x <= 0.00001 && -0.00001 <= y && y <= 0.00001) {
            break;
        }
        x += cos(deg_to_rad(ans * X));
        y += sin(deg_to_rad(ans * X));

        ans++;
    }

    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    return 0;
}


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

using namespace std;


int main()
{
	int x,y;
	cin >> x >> y;
	for(int i = 0; i <= 100; i++){
		for(int j = 0; j <= 100; j++){
			if(i+j == x && 2*i+4*j == y){
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
	return 0;
}


Measured memory_bytes: 3624
n=int(input())
A=sorted(list(map(int,input().split())))
if n==2:
  print(sum(A)/2)
else:
  a=0
  for i in range(n-1):
    a+=(2**i)*(A[i+1])
  print((a+A[0])/(2**(n-1)))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

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

    int x[6];
    int ans = 0;
    for(int i = 1; i<=5; i++){
        cin>>x[i];
        if(x[i] == 0){
            ans = i;
        }
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	while (true)
	{
		cin >> a >> b;
		if (a == 0 && b == 0) break;
		if (a < b) cout << a << " " << b << endl;
		else cout << b << " " << a << endl;
	}
	return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;
using ll = long long ;
const int INF = 1001001001;

int main() {

    ll n ;
    cin >> n;
    
    if(n>=30)
     cout << "Yes" << endl;
    else
     cout << "No" << endl;
    


    return 0 ;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    scanf("%d", &N);
    int X[2000000];
    int X_in[200000];

    for(int i=0; i < N; i++){
        scanf("%d", &X[i]); 
        X_in[i] = X[i];
      
    }
    sort(X, X+N);
    int med_l = X[N/2 - 1];
    int med_r = X[N/2 ];
    
    if(med_l==med_r){
        for(int i =0; i < N; i++) printf("%d\n", med_l);
        return 0;
    }

    for(int i =0; i < N; i++){
        if(X_in[i] <= med_l) printf("%d\n", med_r);
        else printf("%d\n", med_l);
    } 
    return 0;

}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

double D,T,s;

int main()
{
    cin >> D >> T >> s;
    if (D/s<=T)cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001; // > 10^9
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

const ll MAX_V = 1001;

vector<vector<ll> > d(MAX_V, vector<ll>(MAX_V, INFLL)); //距離と隣接行列を兼ねる（ただし対角=0とする）
vector<vector<ll> > pre(MAX_V, vector<ll>(MAX_V, 0)); //iからjへの最短経路でjの前の点
vector<vector<ll> > cost(MAX_V, vector<ll>(MAX_V, INFLL)); //距離と隣接行列を兼ねる（ただし対角=0とする）
ll n; 

void warshall_floyd(bool rep_pre = true) {
    if(rep_pre) {
        for (ll i = 0; i < n; i++) {
            for (ll j = 0; j < n; j++) {
                pre[i][j] = i;
            }
        }
    }
    for (ll k = 0; k < n; k++) {
        for (ll i = 0; i < n; i++) {
            for (ll j = 0; j < n; j++) {
                ll a = d[i][j];
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                if(rep_pre && a != d[i][j]) {
                    pre[i][j] = pre[k][j]; //iからjへの最短経路でjの前の点
                }
            }
        }
    }
}

void get_path(ll s, ll t, ll l) {
    ll ans = 0;
    ll gas = l;
    while (t != s) {
        ll pret = t;
        t = pre[s][t];
        if (gas - cost[pret][t] >= 0) {
            gas -= cost[pret][t];
        } else {
            gas = l;
            ans++;
            gas -= cost[pret][t];
        }
    }
    cout << ans << endl;
}


int main () {

    cin >> n;
    ll m,l; cin >>m>>l;
    rep (i,n) d[i][i] = 0;
    for (ll i = 0; i < m; i++) {
        ll f,t,c; cin >>f>>t>>c;
        f--;
        t--;
        if (c <= l) {
            cost[f][t] = c;
            cost[t][f] = c;
            d[f][t] = c;
            d[t][f] = c;
        } 
    }

    ll q; cin >>q;
    vector<ll> s(q); vector<ll> t(q);
    rep(i,q) cin >> s[i] >> t[i];
    for (ll i = 0; i < q; i++) {
        s[i]--;
        t[i]--;
    }

    warshall_floyd(true);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (d[i][j] <= l && i != j) {
                d[i][j] = 1;
                d[j][i] = 1;
            } else {
                d[i][j] = INFLL;
            }
        }
    }
    rep (i,n) d[i][i] = 0;

    warshall_floyd(true);

    for (ll i = 0; i < q; i++) {
        if (d[s[i]][t[i]] != INFLL) {
            cout << d[s[i]][t[i]]-1 << endl;
        } else {
            cout << -1 << endl;
        } 
    }

    return 0;
}



Measured memory_bytes: 25472
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

bool consist(string &a,string &b){
    if(a.size()<b.size()){return false;}
    for(int i=0;i<=a.size()-b.size();i++){
        bool j=true;
        for(int t=0;t<b.size();t++){
            if(a[i+t]!=b[t]){j=false; break;}
        }
        if(j){return true;}
    }
    return false;
}

ll cov(string &a,string &b){
    for(int i=0;i<a.size();i++){
        bool j=true;
        for(int t=0;i+t<a.size();t++){
            if(t>=b.size()){j=false; break;}
            if(a[i+t]!=b[t]){j=false; break;}
        }
        if(j){return a.size()-i;}
    }
    return 0;
}



int main(){
    ll n;
    while(cin>>n){
        if(n==0){break;}
    vector<string> A(n);
    for(int i=0;i<n;i++){cin>>A[i];}
    vector<string> a;
    for(int i=0;i<n;i++){
        bool j=false;
        for(int t=0;t<n;t++){
            if(i==t){continue;}
            if(consist(A[t],A[i])){j=true; break;}
        }
        if(!j){a.push_back(A[i]);}
    }
    n=a.size();
    vector<vector<ll>> e(n,vector<ll>(n));
    for(int i=0;i<n;i++){
        for(int t=0;t<n;t++){
            e[i][t]=cov(a[i],a[t]);
        }
    }
    vector<vector<ll>> dp(n,vector<ll>(1LL<<n,E));
    for(int i=0;i<n;i++){dp[i][1LL<<i]=a[i].size();}
    for(ll i=1;i<(1LL<<n);i++){
        for(int t=0;t<n;t++){
            if(dp[t][i]==E){continue;}
            for(int h=0;h<n;h++){
                if(i>>h&1){continue;}
                dp[h][i|(1LL<<h)]=min(dp[h][i|(1LL<<h)],dp[t][i]+(ll)a[h].size()-e[t][h]);
            }
        }
    }
    ll ans=E;
    for(int i=0;i<n;i++){
        ans=min(ans,dp[i][(1LL<<n)-1]);
    }
    cout<<ans<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 5008
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
//using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
using pii=pair<ll,ll>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__);


int main(){
    dcl(n,a,b);
    int ok=0,fe=0;
    string s;get(s);
    for(auto c:s){
        if(c=='c')cout<<"No"<<endl;
        else if(c=='a'){
            if(ok<a+b){
                ok++;
                cout<<"Yes"<<endl;
            }else cout<<"No"<<endl;
        }else{
            fe++;
            if(ok<a+b && fe<=b){
                ok++;
                cout<<"Yes"<<endl;
            }else cout<<"No"<<endl;
        }
    }
}


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

int main(){
    int N;
    cin >> N;
    vector<int> V(N);
    vector<int> C(N);
    for(auto& v : V){
        cin >> v;
    }
    for(auto& c : C){
        cin >> c;
    }
    int sum = 0;
    for(int ii=0; ii<N; ii++){
        if(V[ii] > C[ii]){
            sum += V[ii] - C[ii];
        }
    }
    cout << sum << endl;
    return 0;
}


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

using namespace std;

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

    int dis=0;
    int ans=1;
    for(int i=0; i<N; ++i){
        dis += L[i];
        if(dis<=X){
            ans++;
        }
    }
    cout << ans << endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    string s; cin >> s;
    int g=0,p=0;
    REP(i,s.size()){
        if(s[i]=='g')g++;
        else p++;
    }
    cout << (g-p)/2 << endl;
    return 0;
}

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

int main()
{
    int a, b, c; cin >> a >> b >> c;
    
    double s, l, h, rad, PI;
    PI = acos(-1);
    rad = c * PI / 180;
    
    s = (a * b * sin(rad)) / 2;
    l = sqrt(a*a + b*b - (cos(rad))*2*a*b) + a + b;
    h = (2*s)/a;
    cout<<fixed<<setprecision(8);
    cout<<s<<endl<<l<<endl<<h<<endl;
    return 0;
}


Measured memory_bytes: 3508
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <cassert>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 55, inf = 1e9;
const ll INF = 1e18, mod = 1e9 + 7;
const ld PI = 3.1415926535897932384626433832795;

int cnt[MAXN];
ll dp[MAXN], h[MAXN], a[MAXN];
bool vis[MAXN], used[MAXN];

ll Base[4][MAXN][MAXN] = { {}, // Empty matrix
                            {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}, // Identity matrix
                            {{1, 1, 0, 1}, {3, 0, 1, 3}, {2, 0, 1, 2}, {0, 0, 0, 1}}, // Matrix for a given problem
                            {{1, 0, 0, 1}} }; // Vector for calculating the answer

struct Matrix
{
    vector<vector<ll>> Data;
    int n;
    ll res[MAXN];

    Matrix(int n, int x) : n(n), Data(n, vector<ll>(n, 0))
    {
        init(x);
    }

    Matrix operator*(const Matrix &B)const
    {
        Matrix Result(n, 0);
        for (int k = 0; k < n; k++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Result.Data[i][j] = ((ll)Result.Data[i][j] + (ll)Data[i][k] * B.Data[k][j])%mod;
                }
            }
        }
        return Result;
    }

    // Init of matrix
    void init(int x)
    {
        if (x == 0) return ;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                Data[i][j] = Base[x][i][j];
            }
        }
    }

    // Fast exponentation M ^ k
    Matrix pow(ll k)const
    {
        Matrix Result(n, 1), Coef = *this;
        while (k > 0)
        {
            if (k&1) Result = Result * Coef;
            k >>= 1;
            Coef = Coef * Coef;
        }
        return Result;
    }

    // Multiplies matrix with vector
    void calcRes(int x)
    {
        for (int i = 0; i < n; i++)
        {
            res[i] = 0;
            for (int k = 0; k < n; k++)
            {
                res[i] = ((ll)res[i] + (ll)Base[x][0][k] * Data[k][i])%mod;
            }
        }
    }
};

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

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

    int n;
    ll k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        Base[1][i][i] = 1;
        for (int j = 0; j < n; j++) {
            cin >> Base[2][i][j];
        }
    }

    Matrix M(n, 2);
    M = M.pow(k);
    ll res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            res = (res + M.Data[i][j]) % mod;
        }
    }
    cout << res << "\n";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	ll n;
	cin >> n;
	string s;
	while(n) {
		n--;
		s.PB('a' + n % 26);
		n /= 26;
	}
	reverse(ALL(s));
	cout << s << endl;

}





Measured memory_bytes: 3620
import bisect
for e in iter(input,'0'):
 n=int(e)
 c=[sorted(int(input())for _ in[0]*n)]
 c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
 t=f=0
 while 1:
  if not c[t]:break
  x=bisect.bisect(c[t],f)
  f=c[t].pop(x)if x<len(c[t])else 0
  t^=1
 for i in[1,0]:print(len(c[i]))


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

int main(void){
	int a, b, c;
	int count = 0;

	cin >> a >> b >> c;

	for (int i = a; i < b + 1; i++){
		if (c%i == 0) count++;
	}
		
	cout << count << "\n";

	return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    ll ans = 0;
    rep(i, n) {
        if (i % 2 == 0 && a[i] % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define inf (1ll << 60)
using namespace std;

typedef long long i64;
i64 x, y, z, n; /// x->gold y->silver z->bronze
i64 profitst[100010]; /// x gold and i - x bronze
i64 profitdr[100010]; /// z silver and (n - i + 1) - z bronze

struct Elem
{
    i64 a, b, c;
    bool operator< (const Elem & x) const {
        return a - b > x.a - x.b; /// in front i harvest gold and in back silver
    }
} v[100010];

class Get_optim
{
public:
    struct Elem2
    {
        i64 a, b;
        bool operator< (const Elem2 & x) const {
            return a - b < x.a - x.b;
        }
    };
    multiset <Elem2> vals;
    i64 ans1, ans2, n;
    Get_optim(i64 X)
    {
        n = X;
        ans1 = ans2 = 0;
    }
    void add_val(i64 x, i64 y)
    {
        vals.insert((Elem2){ x, y });
        ans1 += x;
        if (vals.size() > n) {
            ans1 -= vals.begin()->a;
            ans2 += vals.begin()->b;
            vals.erase(vals.begin());
        }
    }
    i64 get_ans()
    {
        if (vals.size() < n)
            return -inf;
        return ans1 + ans2;
    }
};

void calc_profit()
{
    Get_optim q(x);
    for (i64 i(1); i <= n; i++) {
        q.add_val(v[i].a, v[i].c);
        profitst[i] = q.get_ans();
    }
    q = Get_optim(y);
    for (i64 i(n); i >= 1; i--) {
        q.add_val(v[i].b, v[i].c);
        profitdr[i] = q.get_ans();
    }
}

int main()
{
    cin >> x >> y >> z;
    n = x + y + z;
    for (i64 i = 1; i <= n; i++)
        cin >> v[i].a >> v[i].b >> v[i].c;

    sort(v + 1, v + n + 1);

    calc_profit();

    i64 ans = 0;

    for (i64 i(1); i < n; i++)
        ans = max(ans, profitst[i] + profitdr[i + 1]);

    cout << ans;
    return 0;
}


Measured memory_bytes: 9984
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

struct card {
    char suit;
    int value;
};

void bubbleSort(card A[], const int N)
{
    int flag = 1;

    for( int i = 0; flag; ++i ){
        flag = 0;

        for( int j = N-1; i < j; --j )
            if( A[j].value < A[j-1].value ){
                swap(A[j], A[j-1]);
                flag = 1;
            }
    }
}

void selectionSort(card A[], const int N)
{
    for( int i = 0; i < N; ++i ){
        int min = i;
      
        //i???????????§A[i]?????????????°???????????????????????±???????
        for( int j = i; j < N; ++j )
            if( A[j].value < A[min].value )
                min = j;
       
        //i??¨min?????°????????°??????
        if( i != min ) swap(A[i], A[min]);
    }
}

int main()
{
    //??\???
    int N;
    scanf("%d%*c", &N);
    card A[N], B[N]; //A:bubbleSort, B:selectionSort
    for( int i = 0; i < N; ++i ){
        scanf("%c%d%*c", &A[i].suit, &A[i].value);
        B[i] = A[i];
    }


    bubbleSort(A, N);
    selectionSort(B, N);


    //????????????????????????????????????
    for( int i = 0; i < N; ++i ){
        if( 0 < i ) printf(" ");
        printf("%c%d", A[i].suit, A[i].value);
    }
    printf("\n");
    printf("Stable\n");

    //?????????????????????????????????
    int flag = 1;
    for( int i = 0; i < N; ++i ){
        if( 0 < i ) printf(" ");
        printf("%c%d", B[i].suit, B[i].value);
        if( !(B[i].suit == A[i].suit && B[i].value == A[i].value) ) flag = 0;
    }
    printf("\n");
    if( flag ) printf("Stable\n");
    else printf("Not stable\n");

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    for(int i = 0;i < n;i++){
        cin >> s[i];
    }
    sort(s.rbegin(),s.rend());
    long long ans = s[0];
    int acs = 1;
    if(n > 2){
        for(int i=0;i < n-2;i++){
            if(i!=0 && i%2 == 0)acs++;
            ans += s[acs];
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3992
N = int(input())
h = list(map(int, input().split()))
ans = 0
x = [0]*N
for i in range(N):
    for _ in range(h[i]-x[i]):
        y = False
        for j in range(i,N):
            if x[j] < h[j]:
                x[j] += 1
                y = True
            else:
                break
        if y:
            ans += 1
print(ans)

Measured memory_bytes: 3064