akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
#define ll long long

vector<vector<ll>> e_input;
vector<vector<ll>> e;
map<vector<ll>, ll> ie;
ll max_color = -1;

void dfs(ll par, ll i, ll color_par) {
  ll color = 0;
  for(ll j=0; j<e[i].size(); ++j) {
    if (e[i][j]==par) continue;
    if (color==color_par) {++color;}
    vector<ll> _e = {i, e[i][j]};
    sort(_e.begin(), _e.end());
    ie[_e] = color;
    dfs(i, e[i][j], color);
    ++color;
  }
  max_color = max(max_color, color-1);

}

int main(){
  ll N;
  cin >> N;
  e.resize(N);
  for(ll i=0; i<N-1; ++i){
    ll a,b;
    cin >> a >> b;

    vector<ll> e_inp = {a-1, b-1};
    sort(e_inp.begin(), e_inp.end());
    e_input.push_back(e_inp);

    e[a-1].emplace_back(b-1);
    e[b-1].emplace_back(a-1);
  }
  
  dfs(-1, 0, -1);

  cout << max_color+1 << endl;
  for(ll i=0; i<e_input.size(); ++i){
    cout << ie[e_input[i]]+1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 25012
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
    int n,m,c,cnt; cin >> n>>m>>c;
    cnt=0;
    for(int i=min(n,m);i>0;i--){
        //cout<<"i:" <<i<<" n%i: "<< n%i<<" m%i :"<<m%i<<endl;
        if(((n%i)==0) && ((m%i)==0)){
            //cout<<i<<endl;
            cnt++;
        }
        if(cnt==c){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}

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

#define ll long long
const int MOD = 1e9+7;
ll mod(ll x) {
	return (x%MOD + MOD) %MOD;
}
ll mul(ll a,ll b) {
	return mod(mod(a) * mod(b));
}

int main() {
	int n;
	cin >> n;
	vector<ll> v(n);
	ll sum = 0;
	for (int i = 0; i < n; ++i)
	{
		/* code */
		ll tmp;
		cin >> v[i];
		v[i] += sum;
		sum = v[i];
	}
	ll result = 2 * MOD;
	for(int i = 0;i < n-1;i++)
		result = min(result,abs(sum- 2*v[i]));
	cout << result << endl;
	return 0;
}

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

# 列から確認
ans = []
for i in range(H):
    row = mat[i]
    if all(['.' == r for r in row]):
        continue
    ans.append(row)

columns = [''.join([a[w] for a in ans]) for w in range(W)]
tmp = len(ans)
columns = [c for c in columns if '.' * tmp != c]

ans = [''.join([c[i] for c in columns]) for i in range(len(columns[0]))]
print('\n'.join(ans))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



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

	//数字の文字列をint型に一文字ずつ変換するラムダ式
	auto strTOint = [&](char c){
		return c - '0';
	};

	vector<int> a(s.size());
		REP(i,s.size()){
		a[i] = strTOint(s[i]);
	}
  int divx, y;
  REP(i,s.size()){
    divx += a[i];
  }

  y = atoi(s.c_str());

  if(y%divx == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  // cout << divx << y << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

void solve();
static int P, Q, R;

void solve() {
  int ans = min(P + Q, min(Q + R, R + P));
  cout << ans << endl;
}

int main() {
  cin >> P >> Q >> R;
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 999999999ll
#define MIN -999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(x) cout<<x<<endl
int main() {
  cout << fixed << setprecision(16);
  ll n;
  cin>>n;
  ll z=(ll)sqrt(n);
  ll x,y;
  Pool(i,1,z+1){
    if(n%i==0){
      x=i;
      y=n/i;
      break;
    }
  }
  cout<<x+y-2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
// #define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(12);const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=3e5+5;
int a[N];
int c[N];
int32_t main(){
    int n;
    cin>>n;
    forn(i,n){
        cin>>a[i];
        c[a[i]]++;
    }
    multiset<int,greater<int>> s;
    forn(i,n+1)if(c[i])s.insert(c[i]);
    int sum=n;
    for(int k=1;k<=n;++k){
        while(!s.empty()&&(*s.begin()>sum/k)){
            int v=*s.begin();
            s.erase(s.begin());
            if(v>1)s.insert(v-1);
            sum--;
        }
        cout<<(sum/k)<<'\n';
    }
    return 0;
}

Measured memory_bytes: 19072
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    N = II()
    K = II()
    X = LMIIS()
    ans = 0
    for x in X:
        ans += min(x,K-x)*2
    print(ans)
    
main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
//#define int long long

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

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

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

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    LL n, k;
    cin >> n >> k;
/*
    if(n < k/2 + k%2){
        cout << 0 << endl;
        return 0;
    }
*/
    LL ans = 0;
    if(k % 2 == 1){
        LL cnt = 0;
        REP(i, n){
            if((i+1) % k == 0) cnt++;
        }
        ans = cnt * cnt * cnt;
        cout << ans << endl;
        return 0;
    }else{
        LL cnt = 0;
        REP(i, n){
            if((i+1) % k == 0) cnt++;
        }

        ans = cnt * cnt * cnt;

        LL ans2 = 1;
        LL cnt2 = 0;
        REP(i, k/2 - 1){
            if((i+1) % k == k/2) cnt2++;
        }

        LL cnt3 = 0;
        for(int i = k/2; i <= n; i++){
            if(i % k == k/2) cnt3++;
        }

        ans2 = cnt3 * cnt3 * cnt3;
        REP(i, cnt2) ans2 += cnt3 * cnt3;

        cout << ans + ans2 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

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

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

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

  int count = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == count) ++count;
  }

  int ans = (n - (count - 1));
  if (ans != n)
    cout << ans << endl;
  else
    cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 1152
import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import java.lang.Math.*;

public class Main {

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	public void run() throws Exception {
		FastIO file = new FastIO();
		int n = file.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) a[i] = file.nextInt();
		int cur = 0;
		int ans = 0;
		for (int i = 1; i < n; i++) {
			if (a[i] <= a[i-1]) {
				cur++;
				ans = Math.max(cur, ans);
			}
			else {
				cur = 0;
			}
		}
		System.out.println(ans);
	}

	public static class FastIO {
		BufferedReader br;
		StringTokenizer st;

		public FastIO() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static long pow(long n, long p, long mod) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n % mod;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2, mod);
			return (temp * temp) % mod;
		} else {
			long temp = pow(n, (p - 1) / 2, mod);
			temp = (temp * temp) % mod;
			return (temp * n) % mod;

		}
	}

	public static long pow(long n, long p) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2);
			return (temp * temp);
		} else {
			long temp = pow(n, (p - 1) / 2);
			temp = (temp * temp);
			return (temp * n);

		}
	}

	public static long gcd(long x, long y) {
		if (x == 0)
			return y;
		else
			return gcd(y % x, x);
	}

	public static boolean isPrime(int n) {
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;

		if (n % 2 == 0 || n % 3 == 0)
			return false;

		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}
}


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

struct Node {
    int index = -1;
    int depth = -1;
    int parent = -1;
    vector<int> child;
};

int get_depth(Node *node, int index) {
    if (node[index].parent < 0) {
        return 0;
    } else if (node[index].depth > 0){
        return node[index].depth;
    }else {
        int d = get_depth(node, node[index].parent) + 1;
        for (auto& i : node[node[index].parent].child) {
            node[i].depth = d;
        }
        return node[index].depth;
    }
}

int main() {
    int n;
    cin >> n;
    Node a[n];
    
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        a[x].index = x;
        for (int j = 0; j < y; ++j) {
            int b;
            cin >> b;
            a[x].child.push_back(b);
            a[b].parent = x;
        }
    }
    
    for (auto& i : a) {
        string child = "";
        for (auto& j : i.child) {
            string c = child == "" ? "" : ", ";
            child += c + to_string(j);
        }
        cout << "node " << i.index << ": ";
        cout << "parent = " << i.parent << ", ";
        cout << "depth = " << get_depth(a, i.index) << ", ";
        cout << (i.parent < 0 ? "root" : (i.child.size() < 1 ? "leaf" : "internal node")) << ", ";
        cout << "[" << child << "]" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 8272
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pii;

int N;
vector<int> X, Y;
pii L[2010], R[2010];
int board[4010][4010];

int findi(int cur, vector<int> &V) {
    return lower_bound(V.begin(), V.end(), cur) - V.begin();
}

int main() {
    scanf("%d", &N);
    for(int i=0; i<N; i++) {
        scanf("%lld%lld", &L[i].first, &L[i].second);
        scanf("%lld%lld", &R[i].first, &R[i].second);
        X.push_back(L[i].first), X.push_back(R[i].first);
        Y.push_back(L[i].second),Y.push_back(R[i].second);
    }
    sort(X.begin(), X.end()); sort(Y.begin(), Y.end());
    X.erase(unique(X.begin(), X.end()), X.end());
    Y.erase(unique(Y.begin(), Y.end()), Y.end());

    for(int i=0; i<N; i++) {
        int sx = findi(L[i].first, X);
        int sy = findi(L[i].second, Y);
        int tx = findi(R[i].first, X);
        int ty = findi(R[i].second, Y);
        board[sx][sy]++;
        board[sx][ty]--;
        board[tx][sy]--;
        board[tx][ty]++;
    }

    for(int i=0; i<4010; i++) {
        for(int j=1; j<4010; j++) {
            board[i][j] += board[i][j-1];
        }
    }

    for(int j=0; j<4010; j++) {
        for(int i=1; i<4010; i++) {
            board[i][j] += board[i-1][j];
        }
    }

    ll ans = 0;
    for(int i=0; i<4010; i++) {
        for(int j=0; j<4010; j++) {
            if(board[i][j]) {
                ll H = Y[j+1] - Y[j];
                ll W = X[i+1] - X[i];
                ans += H * W;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 65680
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.begin(), c.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
#define Sort(a) sort(Range(a));
#define DeSort(a) sort(RevRange(a));

using namespace std;
using ll = long long;

int main(void){
    Cin(string, a);
    Cin(string, b);
    Cin(string, c);
    cout << char(a[0] - 32) << char(b[0] - 32) << char(c[0] - 32) << "\n";
    //Cout(() ? "Yes" : "No");
    //Cout(() ? "YES" : "NO");
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

const int N=5005;
const int M=205;

int n,m,w[N][M],lef[N],rig[N],tot;
LL dis[N],tmp[N],s[N];
struct data{int x,l,r,c;}op[N*M*2];

int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

bool cmp(data a,data b)
{
	return a.x<b.x;
}

int main()
{
	n=read();m=read();
	for (int i=2;i<=n;i++) dis[i]=dis[i-1]+(LL)read();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			w[i][j]=read();
	for (int j=1;j<=m;j++)
	{
		for (int i=1;i<=n;i++)
		{
			lef[i]=i-1;
			while (lef[i]&&w[lef[i]][j]<w[i][j]) lef[i]=lef[lef[i]];
		}
		for (int i=n;i>=1;i--)
		{
			rig[i]=i+1;
			while (rig[i]<=n&&w[rig[i]][j]<=w[i][j]) rig[i]=rig[rig[i]];
		}
		for (int i=1;i<=n;i++)
		{
			op[++tot].x=lef[i]+1;op[tot].l=i;op[tot].r=rig[i]-1;op[tot].c=w[i][j];
			op[++tot].x=i+1;op[tot].l=i;op[tot].r=rig[i]-1;op[tot].c=-w[i][j];
		}
	}
	sort(op+1,op+tot+1,cmp);
	LL ans=0;int now=1;
	for (int i=1;i<=n;i++)
	{
		memset(tmp,0,sizeof(tmp));
		while (now<=tot&&op[now].x==i) tmp[op[now].l]+=op[now].c,tmp[op[now].r+1]-=op[now].c,now++;
		for (int j=1;j<=n;j++) tmp[j]+=tmp[j-1],s[j]+=tmp[j],ans=j<i?ans:max(ans,s[j]-dis[j]+dis[i]);
	}
	printf("%lld",ans);
	return 0;
}

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

int main() {
    int N, i, a[100000], b[100000];
    cin >> N;
    for (i = 0; i < N; i++) cin >> a[i] >> b[i];

    long long c = 0, n;
    for (i = N-1; i >= 0; i--) {
        n = (c+a[i]) % b[i];
        if (n > 0) c += b[i]-n;
    }

    cout << c << endl;
    return 0;
}

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

 
int main() {
   vector<char> s(4);
   rep(i,4)cin>>s[i];

   sort(s.begin(),s.end());
   if(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2])cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys
#sys.setrecursionlimit(n)
import heapq
from collections import defaultdict, deque
import itertools

import itertools
from heapq import heappop, heappush
N, M, R = map(int, input().split())

r = [int(i) for i in input().split()]
mp = defaultdict(lambda:defaultdict(list))
for _ in range(M):
    a, b, c= map(int, input().split())
    mp[a][b] = c
    mp[b][a] = c

v = [[float('inf')] * (N + 1) for _ in [0] * (N + 1)]
def dijkstra(start):
    q = []
    global v
    heapq.heappush(q, (0, start))
    vv = v[start]
    vv[start] = 0
    while(q):
        vc, vs = heapq.heappop(q)
        for i in mp[vs]:
            vsc = mp[vs][i]
            cost = vv[i]
            newcost = vsc + vc
            if cost > newcost:
                vv[i] = newcost
                heapq.heappush(q, (newcost, i))

for i in r:
    dijkstra(i)

ans = float('inf')
for i in itertools.permutations(r):
    t_ans = 0
    for j in range(R - 1):
        t_ans += v[i[j]][i[j + 1]]
    if ans > t_ans:
        ans = t_ans
print(ans)


Measured memory_bytes: 7008
#include <stdio.h>
#include <stdlib.h>

int main(int argv, char *argc[]){
    
    int num;
    int *array;
    int x;
    
    scanf("%d", &num);
    
    array = malloc(sizeof(int)*num);
    
    for(x=num; 0<x;x--){
        scanf("%d", &array[x-1]);
    }
    
    for(x=0; num-1>x; x++){
        printf("%d ", array[x]);
    }
    
    printf("%d\n", array[num-1]);
    free(array);
    return 0;
}

Measured memory_bytes: 596
import sys
from pprint import pprint

N, M, X = map(int, sys.stdin.readline().split())

books = []
for _ in range(N):
    tmp = list(map(int, sys.stdin.readline().split()))
    books.append(tmp)

ans = float("inf")
for i in range(1 << N):
    cost = 0
    scores = [0] * M
    for j in range(N):
        if i & (1 << j):
            cost += books[j][0]
            for k, score in enumerate(books[j][1:]):
                scores[k] += score
    for score in scores:
        if score < X:
            break
    else:
        ans = min(ans, cost)
            
print(-1 if ans == float("inf") else ans)

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

int main() {

	int n, m, c; cin >> n >> m >> c;
	vector<int> b(m);
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	vector<vector<int>> a(n, vector<int>(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int tmp = c;
		for (int j = 0; j < m; j++) {
			tmp += a[i][j] * b[j];
		}
		if (0 < tmp) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3584
n = int(input())
a = list(map(int, input().split()))
c1_list = [0]*60
for i in range(n):
  b = format(a[i], '060b')

  for j in range(len(b)):
    if b[j] == "1":
      c1_list[j] += 1
count = 0
for i in range(60):
  count = (count + c1_list[i]*(n-c1_list[i])*2**(59-i)) % 1000000007
print(count)

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n;
ll a[maxn];
vector<pair<int,int>> v;

void add(int x, int y) {
  v.push_back({x+1,y+1});
  //a[y] += a[x];
}

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


  cin>>n;
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  int j=0;
  for (int i=1; i<n; i++) {
    if (abs(a[i]) > abs(a[j])) j = i;
  }


  if (a[j] >= 0) {
    if (j!=0) {
      add(j, 0);
      add(j, 0);
    }
    for (int i=1; i<n; i++) {
      add(i-1, i);
      add(i-1, i);
    }
  } else {
    if (j!=n-1) {
      add(j, n-1);
      add(j, n-1);
    }
    for (int i=n-2; i>=0; i--) {
      add(i+1, i);
      add(i+1, i);
    }
  }

  cout<<v.size()<<endl;
  for (auto p: v) cout<<p.first<<" "<<p.second<<"\n";


  assert(int(v.size()) <= n*2);
  
  // for (int i=0; i<n; i++) {
  //   cerr<<a[i]<<" ";
  //   if (i) assert(a[i]>=a[i-1]);
  // }
  // cerr<<endl;  

  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 256
/*-----------------------------------------------,
|  __                                       __   |
| |  |--.-----.---.-.----.----.-----.-----.|  |_ |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _||
| |_____|_____|___._|____|____|_____|   __||____||
|                                   |__|         |
`-----------------------------------------------*/
#include<algorithm>
#include<array>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long ll; typedef long double ld ;using namespace std;
#define INF 1000000000000
#define MOD 10000007
#define ALL(name) (name).begin(),(name).end()
#define REP(counter, limit) for (long long counter = 0; counter < limit; counter++)
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){ios::sync_with_stdio(0);cin.tie(nullptr); /*cout<<fixed<<setprecision(20);*/};}setupios;
int main() {

  int n,x;
  cin>>n>>x;
  vector<int> a(n);
  REP(i,n)cin>>a[i];
  sort(ALL(a));
  int ans=0;
  bool tr=false;
  REP(i,n){
    if(a[i] > x){
      tr=true;
      break;
    }else{
      x-=a[i];
      ans++;
    }
  }
  if(!tr and x != 0)ans--;
  cout<<ans<<endl;

}


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

typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define precise(x) cout<<fixed<<setprecision(12)<<x
#define test cout<<"#";

const ll INF = 1e18L + 5;

ll ans[3001][3001];
ll solve(vector<ll> &v, ll s, ll e, ll n)
{
	if(s>e)
		return 0;
	if(ans[s][e]!=-1)
		return ans[s][e];
	ll r = n-(s+e)-1;
	if(r%2 != 0)
		return ans[s][e] = min(solve(v, s+1, e, n), solve(v, s, e-1, n));
	else
		return ans[s][e] = max(solve(v, s+1, e, n)+v[s-1], solve(v, s, e-1, n)+v[e-1]);	
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	vector<ll> v(n);
	ll sum = 0;
	for(ll x = 0; x < n; x++)
	{
		cin>>v[x];
		sum+=v[x];
	}
	memset(ans, -1, sizeof(ans));
	ll x = solve(v, 1, n, n);
	ll y = sum-x;
	cout<<x-y;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    constexpr int Z = 26;
    string s,t;
    cin >> s >> t;
    vector<vector<int>> vvs(Z,vector<int>());

    REP(i,s.size()) {
        vvs[s[i] - 'a'].emplace_back(i+1);
    }
    // sentinel
    REP(i,Z) {
        vvs[i].emplace_back(-1);
    }

    bool imp = false;
    ll ans = 0;
    vector<int> tc(Z,0);
    ll loop = 0;
    int c = -1;
    
    REP(i,t.size()) {
        int tp = t[i] - 'a'; 

        if (vvs[tp].size() == 1) {
            imp = true;
            break;
        }

        while(vvs[tp][tc[tp]] < c && vvs[tp][tc[tp]] != -1) tc[tp]++;
        if (vvs[tp][tc[tp]] == -1) {
            loop++;
            // reset
            tc = vector<int>(Z,0);
            c = vvs[tp][tc[tp]];
            tc[tp]++;
            
        } else {
            c = vvs[tp][tc[tp]];
            tc[tp]++;
        }
    }
    //cerr << loop << endl;
    ans = loop * s.size() + c;

    if (imp) {
        cout << "-1" << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, h[114514];
	cin>>n>>k;
	REP(i, n){
		cin>>h[i];
	}
	sort(h, h+n);
	int ans=1e9;
	REP(i, n-k+1){
		CHMIN(ans, h[i+k-1]-h[i]);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 640
program flip_and_rectangles
  implicit none
  integer :: h, w, a(2000,2000), g(2000,2000), x, i, j
  integer :: stack(2000), left(2000), m, p, t, wid, hei
  character(2000) :: s
  a = 0
  g = 0
  stack = 0
  left = 0
  read(*,*) h, w
  do i = 1, h
    read(*,*) s
    s = trim(adjustl(s))
    do j = 1, w
      if (s(j:j).eq."#") a(i,j) = 1
    end do
  end do
  do i = 1, h-1
    do j = 1, w-1
      g(i,j) = 1-mod(sum(a(i:i+1,j:j+1)),2)
    end do
  end do
  do j = 1, w-1
    do i = 2, h-1
      if (g(i,j).eq.1) g(i,j) = g(i,j)+g(i-1,j)
    end do
  end do
  x = max(h,w)
  do i = 1, h-1
    stack(1:w) = 0
    left(1:w) = 0
    p = 1
    m = 0
    do j = 1, w-1
      t = p
      do while (p.gt.1.and.stack(p-1).ge.g(i,j))
        p = p-1
        wid = j-left(p)
        hei = stack(p)
        m = max(m,(wid+1)*(hei+1))
      end do
      if (p.eq.t) left(p) = j
      stack(p) = g(i,j)
      p = p+1
    end do
    do while (p.gt.1)
      p = p-1
      wid = w-left(p)
      hei = stack(p)
      m = max(m,(wid+1)*(hei+1))
    end do
    x = max(m,x)
  end do
  write(*,'(i0)') x
  stop
end program flip_and_rectangles

Measured memory_bytes: 31488
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


# globals
inf = float('inf')
N = 0
S = ""


def set_inputs():
    global N, S
    N = get_int()
    S = get_str()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    s = "".join(itertools.dropwhile(lambda c: c == ".", S))
    black = []
    white = []
    count = 0
    prev = "#"
    for c in s:
        if c == prev:
            count += 1
        else:
            if prev == "#":
                black.append(count)
            else:
                white.append(count)
            prev = c
            count = 1
    if prev == ".":
        white.append(count)
    t = len(black)
    forward = list(itertools.accumulate([0] + black))
    backward = list(itertools.accumulate([0] + white[::-1]))
    print(min([forward[i] + backward[t-i] for i in range(t+1)]))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 19448
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
 
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define setpr(x) cout << setprecision((x))
#define PI atan(1)*4
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mk(a , b) { min((a) , (b)) , max((a) , (b)) }
#define flush cout.flush()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endc "\n"
#define MOD 1000000007
#define meme(x) memset((x), 0, sizeof((x)))
#define memo(x) memset((x),-1, sizeof((x)))
 
using namespace std;

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

// #define int ll

ll egcd(ll a, ll b, ll &x, ll &y){
    if (a == 0LL){  
        x = 0LL;  
        y = 1LL;  
        return b;  
    }
    ll xx, yy;
    ll val = egcd(b % a, a, xx, yy);  
    x = yy - (b / a) * xx;  
    y = xx;  
    return val;
}

ll gcd(ll a, ll b){
    while(true){
        if(a>b)
            swap(a,b);
        if (a == 0) 
            return b; 
        ll p = b % a  , q = a;
        a = p;
        b = q;
    }
}
 
ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}

//  ==========      //\\       //||     ||====//||
//      ||         //  \\        ||     ||   // ||
//      ||        //====\\       ||     ||  //  ||
//      ||       //      \\      ||     || //   ||
//  ==========  //        \\  ========  ||//====|| 
//  code

vector<ll> a;
vector< vector<ll > > dp;

ll rec(int left, int right){
    if(left >= right)
        return 0;

    if(dp[left][right] > -1)
        return dp[left][right];

    ll cost = 0LL;
    for(int i = left; i <= right; i++){
        cost += a[i];
    }

    ll ans = LLONG_MAX;
    for(int i = left; i < right; i++){
        ans = min(ans, cost + rec(left, i) + rec(i + 1, right));
    }
    return dp[left][right] = ans;
}

void solve(){
    int n,i,j,k,l,p;
    cin >> n;
    a.resize(n);
    dp.resize(n, vector<ll>(n, -1));

    for(auto &i : a)
        cin >> i;
    cout << rec(0, n - 1) << endc;
}

int32_t main(){
    init;
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4496
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,p;
    string s,t;
    cin>>s>>t;
    for(i=0;i<t.size();i++){
        cout<<t[i];
    }
    for(i=0;i<s.size();i++){
        cout<<s[i];
    }
}


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

cb = []
for i in A:
    cb += [[i,1]]
for _ in range(M):
    b, c = map(int, input().split())
    cb += [[c, b]]
cb.sort(reverse = True)
#print (cb)

ans = 0
i = 0
j = 0
while i <= N:
    a = min(N-i, cb[j][1])
    ans += cb[j][0] * a
    j += 1
    i += a
    #print (ans)
    if i == N:
        print (ans)
        i += 1


Measured memory_bytes: 34952
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <bitset>
#include "math.h"
using namespace std;

int main() {
    
    typedef pair<long long, long long> P;
    
    int N, M;
    
    cin >> N >> M;
    
    priority_queue<P, vector<P>, greater<P> > que;
    long long a, b;
    for (int j = 0; j < N; j++) {
        cin >> a >> b;
        que.push(P(a,b));
    }
    
    long long res = 0;
    
    while (M > 0) {
        P p = que.top(); que.pop();
        if (p.second < M) {
            res += p.first * p.second;
            M -= p.second;
        } else {
            res += p.first * M;
            M = 0;
        }
    }

    cout << res << endl;
    
    
    return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        ll N, K, Q; cin >> N >> K >> Q;
        vector<ll> A(N); cin >> A;
        vector<ll> B = A;
        sort(all(B));
        B.erase(unique(B.begin(), B.end()), B.end());
        ll ans = INFL;

        for(ll mini : B) {
            ll cnt = 0;
            vector<ll> vv;
            rep(l, N) {
                while(l < N and A[l] < mini) l++;
                ll r = l;
                while(r < N and A[r] >= mini) r++;
                if(r - l + 1 >= K) {
                    cnt += r - l - K + 1;
                    vector<ll> v;
                    repeat(j, l, r) v.push_back(A[j]);
                    sort(all(v));
                    rep(j, r - l -  K + 1) vv.push_back(v[j]);
                }
                l = r;
            }
            //cerr << i << " ~ :" <<  cnt << " : " << mx << " - " << mini << endl;
            if(cnt >= Q) {
                sort(all(vv));
                ll mx = vv[Q - 1];
                assert(mx >= mini);
                if(vv[0] == mini) set_min<ll>(ans, mx - mini);
            }
        }
        assert(ans != INFL);
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,ans=0,min=0,min_=0;cin>>n;
  lvector v(n,0),w(n,0);rep(i,n) cin>>v[i];
  min=v[0];w[0]=v[0];
  for(ll i=1;i<n;++i) {
    min_=v[i];
    if(min_<min) min=min_;
    w[i]=min;
  }
  rep(i,n) if(v[i]<=w[i]) ans++;
  print(ans);
  return 0;
}

Measured memory_bytes: 3456
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import System.IO
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete

rate :: [(Int,Int,Int)] -> String
rate [] = "no guest"
rate ds = show $ ok_len * 100 `div` len
  where
    len = length ds
    ok_len = length $ filter (\(_,m,m') -> mod (m'-m) 60 <= 8) ds

main = do
    n <- getInt
    unless (n==0) $ do
        ds <- map (apply3 (,,) . map readInt . wordsBy (`elem`": ")) <$> replicateM n getLine
        putStrLn $ ("lunch "++) $ rate $ filter (\(h,m,m') -> 11 <= h && h < 15) ds
        putStrLn $ ("dinner "++) $ rate $ filter (\(h,m,m') -> 18 <= h && h < 21) ds
        putStrLn $ ("midnight "++) $ rate $ filter (\(h,m,m') -> 21 <= h || h < 2) ds
        main


Measured memory_bytes: 4380
#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{
	int N=0;
	scanf("%d",&N);
	int K[N]={0},P[N]={0};
	for(int i=0;i<N;i++)
	{
		scanf("%d %d",&K[i],&P[i]);
	}
	for(int i=0;i<N;i++)
	{
		if(K[i]%P[i]==0)
		{
			printf("%d\n",P[i]);
		}
		else
		{
			printf("%d\n",K[i]%P[i]);
		}
	}
	return 0;
}


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

const int M=2e5+5;
const int MO=1e9+7;
int a[M];

int main()
{
	int n; scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",a+i);
	int sum=a[0],ans=0;
	for(int i=1;i<n;i++)
	{
		ans=(ans+1LL*a[i]*sum%MO)%MO;
		sum=(sum+a[i])%MO;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4604
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll dp[60][100010];
int main(){
	ll n;cin>>n;
	vector<ll> v;
	rep(i,8){
		v.pb(pow(6,i));
	}
	FOR(i,1,7){
	  v.pb(pow(9,i));
	}

	dp[0][0]=1;
	rep(i,50){
		rep(j,100010){
			rep(k,v.size()){
				if(j+v[k]<=n){
					dp[i+1][j+v[k]]=(dp[i+1][j+v[k]]||dp[i][j]);
				}
			}
		}
	}

	rep(i,60){
		if(dp[i][n]){
			cout<<i<<endl;
			return 0;
		}
	}
  return 0;
}

Measured memory_bytes: 40448
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in range(N):
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[index] += 1

co = 1
for i in range(len(n)):
  co = co * n[i]
co -= 1

print(co % 1000000007)


Measured memory_bytes: 3188
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using dl = long double;
int main()
{
    int a[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }

    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int temp;
        cin>>temp;
        for(int k=0;k<3;k++){
            for(int x=0;x<3;x++){
                if(a[k][x]==temp){
                    a[k][x]=0;
                }
            }
        }
    }
    int flag =0;
    //check each row and column
    for(int i=0;i<3;i++){
        if(a[i][0]==0&&a[i][1]==0&&a[i][2]==0){
            flag=1;
        }
        if(a[0][i]==0&&a[1][i]==0&&a[2][i]==0){
            flag=1;
        }
    }
// check diag
if(a[0][0]==0&&a[1][1]==0&&a[2][2]==0)flag =1;
if(a[1][1]==0&&a[0][2]==0&&a[2][0]==0)flag =1;

if(flag==1)cout<<"Yes";
else cout<<"No";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_ ; ++i)
#define drep(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_ ; --i)
#define Sys_fault() exit(998244353)
#define clear(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = (x << 3) + (x << 1) + (ch - 0x30);
		ch = getchar();
	}
	return flag * x;
}

#define Maxn (100009)
int n, a[Maxn], k;
LL prefix_sum[Maxn], jump_sum[Maxn];
int main() {
#ifdef Qrsikno
	freopen("l.in","r",stdin);
	freopen("l.out","w",stdout);
#endif
	n = read(), k = read();
	rep(i, 1, n) a[i] = read(), prefix_sum[i] = prefix_sum[i - 1] + a[i];
	rep(i, 1, n) jump_sum[i] = jump_sum[i - 1] + max(0ll, 1ll * a[i]);
	LL ans = 0;
	rep(i, 1, n - k + 1) {
		LL tmp = (i != 0) * jump_sum[i - 1] + jump_sum[n] - jump_sum[i + k - 1];
		if(prefix_sum[i + k - 1] - prefix_sum[i - 1] >= 0)
			tmp += prefix_sum[i + k - 1] - prefix_sum[i - 1]; 
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int n,k; string s; cin >> n >> k >> s;
    s[k-1]=tolower(s[k-1]);
    out(s);

    return 0;
}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

int prime[10000];
ll mod = 1e9 + 7;

void factfact(int n) {
  int i, j;
  ll ans = 1;

  for (i = 2; i <= n; i++) {
    prime[i] = 1;
  }
  for (i = 2; i <= n; i++) {
    if (prime[i]) {
      for (j = i * 2; j <= n; j += i) {
        prime[j] = 0;
      }
    }
  }
  for (i = 2; i <= n; i++) {
    if (prime[i]) {
      prime[i] = 0;
      for (j = i; j <= n; j *= i) {
        prime[i] += n / j;
      }
      // printf("%d^%d\n", i, prime[i]);
      ans *= prime[i] + 1;
      ans %= mod;
    }
  }
  // printf("\n");
  cout << ans << endl;
}

int main(void) {
  // factfact(12);
  int N;
  cin >> N;
  factfact(N);
  return 0;
}


Measured memory_bytes: 256
N = int(input())
XY = []
for i in range(N):
    XY.append(list(map(int,input().split())))

if N!=1:
    pqs = []
    for i in range(N):
        for j in range(i+1,N):
            X1 = XY[i][0]
            Y1 = XY[i][1]
            X2 = XY[j][0]
            Y2 = XY[j][1]
            pqs.append(str(X1-X2)+","+str(Y1-Y2))
            pqs.append(str(X2-X1)+","+str(Y2-Y1))

    from collections import Counter
    C = dict(Counter(pqs))
    out = N - max(C.values())
    print(out)
else:
    print(1)

Measured memory_bytes: 39920
s = input().rstrip().split(' ')
L = int(s[0])
R = int(s[1])
cnt = 2020
 
for i in range(L, R):
    for r in range(i+1, R+1):
        ans = (i*r) % 2019 
        if ans < cnt:
            cnt = ans
            if cnt == 0:
        	    break
    if cnt == 0:
      break
 
print(cnt)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt(),B=sc.nextInt();
		System.out.println(A!=B?Math.max(A, B)+Math.max(A, B)-1:A+B);
	}
}


Measured memory_bytes: 22996