akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define INF 1000000000
#define BEAM 100

using namespace std;

class state {
    public:
        int day;
        int previous_score;
        vector<int> previous;
        vector<int> types;

        state() {}

        state(const state& a) : day(a.day), previous_score(a.previous_score), previous(a.previous), types(a.types) {}
};

int _scoring(const vector<int> &c,
        const vector<vector<int>> &s,
        int day,
        int type,
        const vector<int> &previous) {
    int score = s[day][type];

    REP(i, 26) {
        score -= c[i] * (day + 1 - previous[i]);
    }

    return score;
}

int scoring(const vector<int> &c,
        const vector<vector<int>> &s,
        state &this_state) {
    this_state.previous[this_state.types.back()] = this_state.day + 1;
    return this_state.previous_score + _scoring(c, s, this_state.day, this_state.types.back(), this_state.previous);
}

using queue_type = pair<state, int>;
struct CustomCompare
{
    bool operator()(const queue_type &a, const queue_type &b) {
        return a.second < b.second;
    }
};

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

    vector<int> c(26);
    REP(i, 26)
        cin >> c[i];

    vector<vector<int>> s(D, vector<int>(26, 0));
    REP(i, D)
        REP(j, 26)
        cin >> s[i][j];

    vector<state> initial;
    REP(i, 26) {
        state this_state;
        this_state.day = 0;
        this_state.types.push_back(i);
        this_state.types.reserve(D);
        this_state.previous_score = 0;
        this_state.previous = vector<int>(26, 0);
        initial.push_back(this_state);
    }

    priority_queue<queue_type, vector<queue_type>, CustomCompare> q1, q2;
    REP(i, D) {
        if (i == 0) {
            // use initial
            for (auto i : initial) {
                q2.push(make_pair(i, scoring(c, s, i)));
            }
        } else {
            // use queue
            for (int ii = 0; ii < BEAM && !q1.empty(); ++ii) {
                auto i = q1.top();

                REP(j, 26) {
                    state new_state = i.first;
                    new_state.day++;
                    new_state.types.push_back(j);

                    q2.push(make_pair(new_state, scoring(c, s, new_state)));
                    //q2.emplace_back(new_state, scoring(c, s, new_state));
                }

                q1.pop();
            }
        }
        swap(q1, q2);

        q2 = decltype(q2)();
    }

    auto res = q1.top().first;

    for (auto t : res.types)
        cout << t + 1 << endl;

    return 0;
}



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

const int N = 100005, P = 1000000007;
int n, x[N], h[N];

int power(int a, int x) {
	int ans = 1;
	for (; x; x >>= 1, a = 1ll * a * a % P)
		if (x & 1) ans = 1ll * ans * a % P;
	return ans;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", x + i), h[i] = (h[i - 1] + power(i, P - 2)) % P;
	int ans = 0;
	for (int i = 1; i < n; ++i) ans = (ans + 1ll * (x[i + 1] - x[i]) * h[i]) % P;
	for (int i = 1; i < n; ++i) ans = 1ll * ans * i % P;
	printf("%d\n", ans);
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String args[]){
  Scanner sc = new Scanner(System.in);
  int x = sc.nextInt();
  int a = sc.nextInt();
  if(x<a){
    System.out.println(0);
  }else{
    System.out.println(10);
  }
 }
}

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

int main(){
    string s;
    cin >> s;
    if(s=="AAA") cout<<"No"<<endl;
    else if(s=="BBB") cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3588
program handstand2
  implicit none
  integer :: n, i, a, b
  integer(8) :: c(9,9) = 0, x = 0
  read(*,*) n
  do i = 1, n
    a = mod(i,10)
    if (a == 0) cycle
    b = i
    do while (b >= 10)
      b = b/10
    end do
    c(a,b) = c(a,b)+1
  end do
  do a = 1, 9
    do b = 1, 9
      x = x+c(a,b)*c(b,a)
    end do
  end do
  write(*,'(i0)') x
end program handstand2

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] d = new int[N];
        for(int i=0;i<N;i++){
            d[i] = sc.nextInt();
        }
        Arrays.sort(d);
        int ans = 1;
        for(int i=1;i<=N-1;i++){
            if(d[i]!=d[i-1]) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
import sys
# import pdb
input = sys.stdin.readline

N = int(input())    # 夏休みの日数
K = 3      # 活動の種類

acts = []   # ここに各日での活動の幸福度を格納
for _ in range(N):
  acts.append(list(map(int, input().split())))

# acts_chk = [[1 for _ in range(3)] for __ in range(N)]


# 配列の初期化
# i日目に活動pを行ったときの累積幸福度 : dp_list[i][p]
inf = 1e10
dp_list = [[-inf for _ in range(K)] for __ in range(N)]

# 初期値
for i in range(K):
  dp_list[0][i] = acts[0][i]

for day in range(1,N):
  for act in range(K):
    for act_possible in range(K):
      if act == act_possible:
        continue
      dp_list[day][act] = max(dp_list[day][act], dp_list[day-1][act_possible] + acts[day][act])

print(max(dp_list[-1]))


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

using namespace std;

const int MAXN = 5;

int a[MAXN];

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    for (int i = 0; i < 3; i++)
        cin >> a[i];
    sort(a, a + 3);
    cout << abs(a[1] - a[0]) + abs(a[2] - a[1]) << endl;
    return 0;
}


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

int main(void) {
  int N,K;
  scanf("%d %d",&N,&K);

  int x[N+1];
  for(int i=0;i<N;i++) scanf("%d",&x[i]);

  int min=2*abs(x[0])+2*abs(x[N-1]);
  for(int i=0;i<N-K+1;i++) {
    int xl,xr;
    xl = x[i];
    xr = x[i+K-1];
    if(xr<=0) {
      if(abs(xl)<min) min=abs(xl);
    }
    else if(xl>=0) {
      if(xr<min) min=xr;
    }
    else {
      if(abs(xl)<abs(xr)) {
	if(abs(xl)+abs(xr-xl)<min) min=abs(xl)+abs(xr-xl);
      }
      else {
	if(2*xr-xl<min) min=2*xr-xl;
      }
    }
  }
  printf("%d",min);
  return(0);
}
      


Measured memory_bytes: 512
#include<bits/stdc++.h> 
#define inf 1e18
using namespace std;
typedef long long int ll;
int n;
char w[205][205];
vector<int>g[205];
queue<int>q;
int cl[205];
int ans=0;
int main()
{
	scanf("%d",&n);getchar();
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			w[i][j]=getchar();
			if(w[i][j]=='1')g[i].push_back(j);
		}
		getchar();
	}
	for(int i=1;i<=n;i++)
	{
		memset(cl,0,sizeof(cl));
		cl[i]=1;
		q.push(i);
		int flag=1,tmpans=0;;
		while(!q.empty())
		{
			int t=q.front();q.pop();
			tmpans=max(tmpans,cl[t]);
			for(int j=0;j<g[t].size();j++)
			{
				int v=g[t][j];
				if(cl[v]&&abs(cl[v]-cl[t])!=1)
				{
					flag=0;
					break;
				}
				else if(!cl[v])cl[v]=cl[t]+1,q.push(v);
			}
			if(!flag)break;
		}
		if(flag)ans=max(ans,tmpans);
	}
	if(!ans)printf("-1\n");
	else printf("%d\n",ans);
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<limits.h>
#include<queue>
#include<string>
using namespace std;

void maxHeapify(vector<int> &A, int i){
	int l=2*i+1;
	int r=2*i+2;
	int largest;
	int H=A.size();
	
	if ((l<=H-1)&&(A[l]>A[i])){
		largest=l;
	}else{
		largest=i;
	}
	
	if ((r<=H-1)&&(A[r]>A[largest])){
		largest=r;
	}
	if (largest!=i){
		swap(A[i], A[largest]);
		maxHeapify(A,largest);
	}
}

void buildMaxHeap(vector<int> &A){
	int i;
	int H=A.size();
	for (i=(H-2)/2;i>=0;i--){
		maxHeapify(A,i);
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,i;
	cin >> n;
	vector<int> A(n);
	for (i=0;i<n;i++){
		cin >> A[i];
	}
	buildMaxHeap(A);
	for (i=0;i<n;i++){
		cout <<" "<<A[i];
		if (i==n-1) cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N;
	cin >> N;
	LL sum = 0;
	VI count(1e5 + 1, 0);
	for (int n = 0; n < N; n++) {
		int a;
		cin >> a;
		count[a]++;
		sum += a;
	}
	int Q;
	cin >> Q;
	for (int q = 0; q < Q; q++) {
		int b, c;
		cin >> b >> c;
		sum -= b * count[b];
		sum += c * count[b];
		count[c] += count[b];
		count[b] = 0;
		cout << sum << "\n";
	}
	return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <numeric>

inline int read(){
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}

int cnt[1000001];

int main(){
  int n = read(), num = read(), g = num, ex = (n-1)/8;
  cnt[num] = 1;

  for(int i=0;i<ex;i++){
    num = read();
    g = std::gcd(g, num);
    cnt[num]++;
    num = read();
    g = std::gcd(g, num);
    cnt[num]++;
    num = read();
    g = std::gcd(g, num);
    cnt[num]++;
    num = read();
    g = std::gcd(g, num);
    cnt[num]++;
    num = read();
    g = std::gcd(g, num);
    cnt[num]++;
    num = read();
    g = std::gcd(g, num);
    cnt[num]++;
    num = read();
    g = std::gcd(g, num);
    cnt[num]++;
    num = read();
    g = std::gcd(g, num);
    cnt[num]++;
    if(i-cnt[1]>80000&&g==1){
      printf("setwise coprime\n");
      return 0;
    }
  }

  for(int i=0;i<(n-1)%8;i++){
    num = read();
    g = std::gcd(g, num);
    cnt[num]++;
  }

  if(n - cnt[1] > 80000){
    if(g==1) printf("setwise coprime\n");
    else printf("not coprime\n");
    return 0;
  }

  if(g!=1){
    printf("not coprime\n");
    return 0;
  }

  int use[1000001];
  int max_S = 0;
  for(int i=2;i<=1000000;i++){
    if(use[i]==-1) continue;
    int S = 0;
    for(int j=i;j<=1000000;j+=i) {
      S += cnt[j];
      use[j] = -1;
    }
    if(max_S<S) max_S = S;
  }
  if(max_S<2) printf("pairwise coprime\n");
  else printf("setwise coprime\n");
}


Measured memory_bytes: 11404
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a;
    cin >> a;
    cout << a+a*a+a*a*a << '\n';   

    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){

    int a, b, c;

    cin >> a >> b >> c;

    a ^= b;
    b ^= a;
    a ^= b;

    a ^= c;
    c ^= a;
    a ^= c;

    printf("%d %d %d", a, b, c);

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200000 + 10;
//const int maxn = 100 + 10;

int n, pre[maxn], a[maxn];
ll f0[maxn], f1[maxn];
struct qnode{
	int u;
	ll x, y;
	qnode() {}
	qnode(int _u, ll _x, ll _y):u(_u), x(_x), y(_y) {}

	friend bool operator < (qnode a, qnode b) {
		if((ll)a.x * b.y != (ll)a.y * b.x) return 1LL * a.x * b.y < 1LL * a.y * b.x;
		return a.u < b.u;
	}
};
priority_queue<qnode> q;

ll Ans;
int sfa[maxn], used[maxn];

int findfa(int u) { return (sfa[u] == u) ? (u) : (sfa[u] = findfa(sfa[u])); }

int main() {
//	freopen("data.in","r",stdin);
	scanf("%d", &n);
	for(int i = 2;i <= n;i ++) scanf("%d", &pre[i]);
	for(int i = 1;i <= n;i ++) scanf("%d", &a[i]);
	for(int i = 1;i <= n;i ++) {
    f0[i] = f1[i] = 0;
		if(a[i] == 0) f0[i] ++;
		if(a[i] == 1) f1[i] ++;
		if(i != 1) q.push(qnode(i,f0[i],f1[i]));
		sfa[i] = i; used[i] = 0;
	}
	Ans = 0;
	while(!q.empty()) {
		qnode now = q.top(); q.pop();
		int u = now.u, x = now.x, y = now.y;
		if(f0[u] != x || f1[u] != y || used[u] || sfa[u] != u) continue;
		int p = pre[u]; p = findfa(p);
    Ans += (ll) f1[p] * f0[u];
    f0[p] += f0[u]; f1[p] += f1[u];
		if(p != 1) q.push(qnode(p,f0[p],f1[p]));
		sfa[u] = p; used[u] = 1;
	}
	printf("%lld\n", Ans);
	return 0;
}


Measured memory_bytes: 14320
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

    int n,k;
    cin>>n>>k;

    vi v(n);
    fo(i,n) cin>>v[i];
    int s = 0;
    sort(all(v));
    fo(i,k) s += v[i];
    cout<<s;
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3628
n=int(input())
ans=[0]*4
for i in range(n):
  s=input()
  if s=='AC':
    ans[0]+=1
  elif s=='WA':
    ans[1]+=1
  elif s=='TLE':
    ans[2]+=1
  else:
    ans[3]+=1
print("AC x "+str(ans[0]))
print("WA x "+str(ans[1]))
print("TLE x "+str(ans[2]))
print("RE x "+str(ans[3]))


Measured memory_bytes: 9024
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int A, B, K;
  cin >> A >> B >> K;

  FOR(i,A,B+1){
    if(i<A+K||i>B-K){
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <array>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for(const auto &v : vec){
		os << v << ",";
	}
	os << "]";
	return os;
}

typedef long long int lli;
typedef pair<short,short> P;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

struct Rect{
	short x1,x2,y1,y2;
};

class Compare{
	public:
	bool operator()(const Rect &rect1,const Rect &rect2){
		return rect1.y1<rect2.y1;
	}
};

inline short max(short a,short b){
	if(a>b) return a;
	else return b;
}
	
int CalcSize(vector<Rect> &rects){
	int result=0;
	REP(x,0,10010){
		int y=0;
		REP(i,0,rects.size()){
			if(rects[i].x1<=x&&x<rects[i].x2){
				if(rects[i].y2>y) result+=rects[i].y2-max(y,rects[i].y1);
				y=max(y,rects[i].y2);
			}
		}
	}
	return result;
}

int Count(vector<Rect> &rects,vector<vector<bool> > &flag,int x){
	int result=0,y=0;
	REP(i,0,rects.size()){
		if(rects[i].x1<=x&&x<rects[i].x2){
			for(y=max(y,rects[i].y1); y<rects[i].y2; ++y){
				if(!flag[(x-1)%3][y]) ++result;
				if(!flag[(x+1)%3][y]) ++result;
				if(!flag[x%3][y-1]) ++result;
				if(!flag[x%3][y+1]) ++result;
			}
		}
	}
	return result;
}

int CalcLength(vector<Rect> &rects){
	int result=0,index=0;
	vector<vector<bool> > flag(3,vector<bool>(10010));
	REP(x,1,10009){
		if(x-2>=0) fill(flag[(x-2)%3].begin(),flag[(x-2)%3].end(),false);
		int y=0;
		REP(i,0,rects.size()){
			if(rects[i].x1<=x+1&&x+1<rects[i].x2){
				if(rects[i].y2>y) fill_n(flag[(x+1)%3].begin()+max(y,rects[i].y1),rects[i].y2-max(y,rects[i].y1),true);
				y=max(rects[i].y2,y);
			}
		}
		result+=Count(rects,flag,x);
	}
	return result;
}

int main(){
	int N,R;
	while(cin >> N >> R&&!(N==0&&R==0)){
		vector<Rect> rects(N);
		REP(i,0,N){
			int x1,y1,x2,y2;
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			rects[i].x1=x1+4;
			rects[i].y1=y1+4;
			rects[i].x2=x2+4;
			rects[i].y2=y2+4;
		}
		sort(rects.begin(),rects.end(),Compare());
		cout << CalcSize(rects) << endl;
		if(R==2) cout << CalcLength(rects) << endl;
	}
	return 0;
}

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

int main() {
  string s;
  int ans = 0;
  cin >> s;
  for(int i = 0;i < s.size()-1;i++){
    if(s.at(i) != s.at(i+1)) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  int a, b;
  cin >> a >> b;

  int ans;
  if (a == 1 || b == 1) {
    ans = 1;
  } else {
    ans = a * (b / 2);
    if (b % 2 == 1) {
      ans += a - a / 2;
    }
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b,ll p){if(b==0)return 1;ll res=1;a=a%p;while(b>0){if(b&1){res=(res*a)%p;b--;}a=(a*a)%p;b>>=(ll)1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	ll t,n,i,j,k,l,c,f,cnt;
	cin>>n;
	string s;c=0;
	ll num1=0,num2=0,num;
	cin>>s;
	for(i=0;i<n;i++)
	    if(s[i]=='1')
	        c++;
	k=c;
	t=1;
	   for(j=n-1;j>=0;j--)
	   {
	       if(s[j]=='1'){
	       num1+=t;
	       num1%=k+1;}
	       t*=2;
	       t%=k+1;
	   }
	   t=1;
	   for(j=n-1;j>=0&&c>1;j--)
	   {
	       if(s[j]=='1'){
	       num2+=t;
	       num2%=k-1;}
	       t*=2;
	       t%=k-1;
	   }
	for(i=0;i<n;i++)
	{
	    cnt=1;k=c;
	    if(s[i]=='0')
	       num=(num1+power((ll)2,(n-1-i),++k))%k;
	    else{
	        if(k==1){
	            cout<<0<<"\n";continue;}
	        num=(num2-power((ll)2,(n-1-i),--k)+k)%k;
	    }
	   while(num>0)
	   {
	       cnt++;
	       num%=(__builtin_popcount(num));
	   }
	   cout<<cnt<<"\n";
	   
	}
	return 0;
}


Measured memory_bytes: 3772
from itertools import product

n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

cases = product([0, 1], repeat=n)

seen = set()

for case in cases:
    sum_ = 0
    for i in range(n):
        sum_ += case[i] * A[i]
    seen.add(sum_)

for target in M:
    if target in seen:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 5716
#include <iostream>
using namespace std;
string st;
char c[1005];
int t;
int main()
{
	cin>>st;
	for (int i=0;i<st.size();i++)
	{
		if (st[i]=='B')
		{
			c[t]=' ';
			if (t>0) t--;
		}
		else 
		{
			t++;
			c[t]=st[i];
		}
	}
	for (int i=1;i<=t;i++)
	cout<<c[i];
	cout<<endl;	
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/12/27  Problem: AOJ 2170 / Link: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2170  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

struct UnionFind {
	vector<int> data;
	UnionFind(int n) { data.assign(n, -1); }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			//if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	LL root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }

};
// UnionFind uf(n); uf.unionSet(i,j); if(uf.same(x,y))


LL N;

LL ans = 0LL;



int main() {

	int Q;
	while (scanf("%d%d", &N, &Q), N) {

		VI pre(N, 0);
		FOR(i, 0, N - 1) {
			int v; scanf("%d", &v);
			v--;
			pre[i + 1] = v;
		}
		UnionFind uf(N);
		VI mark(N, 0);
		mark[0] = 1;
		vector<PII> qu;
		FOR(i, 0, Q) {
			char c[3]; int v; scanf("%s%d", c, &v);
			PII q;
			q.first = (c[0] == 'Q');
			v--;
			q.second = v;
			if (q.first == 0 && mark[v] == 0)mark[v] = 1,qu.push_back(q);
			else if (q.first == 1)qu.push_back(q);
		}
		FOR(i, 0, N) {
			if (mark[i] == 0)uf.unionSet(pre[i], i);
			//debug(uf.root(i));
		}

		ans = 0;
		Q = SZ(qu);
		FORR(i, Q - 1, 0 - 1) {
			int v = qu[i].second;
			if (qu[i].first == 0) { // delete mark
				uf.unionSet(pre[v], v);
				//debug(uf.root(v));
			}
			else { // sum
				ans += uf.root(v) + 1LL;
			}
		}
		printf("%lld\n", ans);
	}

	return 0;
}

Measured memory_bytes: 5796
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n, c, ans=1<<30; cin >> n >> c;
    vector<vector<int>> d(c, vector<int>(c)), a(3, vector<int>(c, 0));
    //a[i][j] (x+y) % 3 == i, j色のタイル数
    REP(i, c) REP(j, c) cin >> d[i][j];
    REP(i, n) REP(j, n){
        int k; cin >> k;
        ++a[(i+j)%3][k-1];
    }
    REP(i, c) REP(j ,c){
        if(i == j) continue;
        REP(k, c){
            if(i == k) continue;
            if(j == k) continue;
            int cnt = 0;
            REP(l, c) cnt += d[l][i] * a[0][l]; // %=0をi色に
            REP(l, c) cnt += d[l][j] * a[1][l];
            REP(l, c) cnt += d[l][k] * a[2][l];
            ans = min(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
if 0 in a:
  print(0)
  exit()
for aa in a:
  if aa>10**18:
    print(-1)
    exit()
ans=a[0]
for i in range(1,n):
    ans=ans*a[i]
    if ans>10**18:
      print(-1)
      exit()
print(ans)

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

#define R (long long)(1e9 + 7)
#define INF (long long)(1e16L + 5)
#define ll long long
#define grid vector<vector<ll>>

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long d, t, s;
    cin >> d >> t >> s;
    if(s * t >= d)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
ll dp[1<<22]={};
int main(){
  ll n,W,a,b;
  vector<ll> v[2],w[2];
  cin>>n>>W;
  for(ll i=0;i<n;i++){
    cin>>a>>b;
    v[i%2].push_back(a);
    w[i%2].push_back(b);
  }
  vector<P> an[2];
  for(ll cn=0;cn<2;cn++)
    for(ll i=0;i< (1<<v[cn].size());i++){
      ll suw=0,suv=0;
      for(ll j=0;j<v[cn].size();j++){
	if((1&(i>>j))==1){
	  suw+=w[cn][j];
	  suv+=v[cn][j];
	}
      }
      an[cn].push_back(P(suw,suv));
    }
  sort(an[0].begin(),an[0].end());
  ll ma=0;
  for(int i=0;i<an[0].size();i++){
    ma=max(ma,an[0][i].second);
    dp[i]=ma;
  }
  ll ans=0;
  for(int i=0;i<an[1].size();i++){
    ll vv=an[1][i].second;
    ll ww=an[1][i].first;
    ll lb=-1,ub=an[0].size(),mid;
    while(ub-lb>1){
      mid=(ub+lb)/2;
      if(an[0][mid].first+ww<=W)lb=mid;
      else ub=mid;
    }
    if(lb!=-1)ans=max(ans,vv+dp[lb]);
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 44044
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;

int main() {
	int N;
	cin >> N;
	string MARCH = "MARCH", s;
	int l = MARCH.length();
	vector<ll> count(l);
	REP(i, N) {
		cin >> s;
		REP(j, l) {
			if (MARCH[j] == s[0]) {
				count[j]++;
			}
		}
	}

	ll ans = 0;
	REP(i, l) {
		FOR(j, i + 1, l-1) {
			FOR(k, j + 1, l-1) {
				ans += count[i] * count[j] * count[k];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys, copy, itertools,heapq
input = sys.stdin.readline
 
n = int(input())
A = list(map(int,input().split()))
 
suma = sum(A)
a = (suma ** 2)
 
b =0
for i in range(n):
  b += A[i]**2
 
ans = (a-b)//2
 
answer = ans % (10**9 +7)
 
#print(a)
#print(b)
#print(ans)
print(answer)

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

typedef long long ll;


int main(){
    ll N; 
    cin >> N;
    ll a[N];
    ll tmp;
    cin >> a[0];
    for(ll i=1; i<N; i++){
        cin >> tmp;
        a[i] = a[i-1] + tmp;
    }
    ll ans;
    ans = 2000000000;
    for(ll i=1; i<N; i++){
        ans = min(ans, abs(a[N-1]-2*a[i-1]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>

#define MAX_N   (100)
#define MIN_I   (-10000)

static int csmat[MAX_N + 1][MAX_N + 1];

int main() {
  int d, h, max_s, n, s, x, x0, y, y0;

  scanf("%d", &n);

  max_s = MIN_I * MAX_N * MAX_N;

  for (x = 0; x <= n; x++) csmat[0][x] = 0;

  for (y = 1; y <= n; y++) {
    h = 0;
    csmat[y][0] = 0;
    for (x = 1; x <= n; x++) {
      scanf("%d", &d);
      h += d;
      csmat[y][x] = h + csmat[y - 1][x];
      /*printf("(%d,%d)=%d\n", x, y, d);*/
    }

    for (x = 1; x <= n; x++) {
      for (y0 = 0; y0 < y; y0++) {
        for (x0 = 0; x0 < x; x0++) {
          s = csmat[y][x] - csmat[y][x0] - csmat[y0][x] + csmat[y0][x0];
          if (max_s < s) max_s = s;
        }
      }
    }
  }

  printf("%d\n", max_s);
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    cs
    int n,ans=0;cin>>n;
    vector<vector<pair<int,bool>>> v(n);
    rep(i,n) {
        int q;cin>>q;
        while(q--) {
            int t;bool b;
            cin>>t>>b;
            v[i].push_back({t-1,b});
        }
    }
    rep(i,1<<n) {
        int j=i,cnt=0,cur=0;bool bb=1;
        vector<bool> tmp(n);
        while(j) {
            if(j&1) {tmp[cur]=1;cnt++;}
            cur++;j>>=1;
        }
        rep(k,n) {
            if(tmp[k]) {
                for(auto l:v[k]) {
                    if(tmp[l.fi]!=l.se) {bb=0;break;} 
                }
            }
            if(!bb) break;
        }
        if(bb) ans=max(cnt,ans);
    }
    cout<<ans;
}

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

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


    int i = 0;
    int N = s.size();
    string t;
    while (2 * i < N) {
        t += (s.at(2 * i));
        i++;
    }
    cout << t << endl;
}


Measured memory_bytes: 512
use proconio::{input, fastout};

#[fastout]
fn main() {
  input!{
      x : i64
  }
  println!("{}",
            if x < 600 {
                8
            } else if x < 800 {
                7
            } else if x < 1000 {
                6
            } else if x < 1200 {
                5
            } else if x < 1400 {
                4
            } else if x < 1600 {
                3
            } else if x < 1800 {
                2
            } else {
                1
            }        
           );
}


Measured memory_bytes: 2168
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b)
      cout << "a > b" << endl;
    else if (a < b)
      cout << "a < b" << endl;
    else
      cout << "a == b" << endl;    
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 6001001001001001001;
long double EPS = 1e-6;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N),C(N);
    vector<pair<ll,ll>> B,D(200010);
    rep(i,200010){
        D[i].first = 0;
        D[i].second = 0;
    }
    rep(i,N){
        cin >> A[i];
        C[i] = A[i];
    }
    sort(ALL(A));
    B.emplace_back(A[0],1);
    rep(i,N-1){
        if(A[i] == A[i+1]) B.back().second++;
        else B.emplace_back(A[i+1],1);
    }
    rep(i,B.size()){
        D[B[i].first].first = B[i].second * (B[i].second - 1) / 2;
        D[B[i].first].second = B[i].second;
    }
    ll sum = 0;
    rep(i,200010) sum += D[i].first;
    rep(i,N){
        ll a = D[C[i]].second;
        ll d = a * (a-1) / 2 - (a-1) * (a-2) / 2;
        cout << sum - d << endl;
    }
}
    


Measured memory_bytes: 10992
#include <bits/stdc++.h>
using namespace std;
const int nmax=10;
bool graph[nmax][nmax];  


int dsp(int viNodes,int nownode,bool visited[nmax],int N){
  
  visited[nownode]=true;
  
  int ret=0;
  for(int i=0;i<N;i++){
    if(visited[i])continue;
    if(!graph[nownode][i])continue;
    
    if(viNodes==N-1){  
      visited[nownode]=false;
      return 1;
    }
    ret+=dsp(viNodes+1,i,visited,N);
  }
  
  visited[nownode]=false;
  return ret;
}


int main(void)
{
  int i,j;
  int N,M;
  bool visited[nmax]={};
  cin>>N>>M;
  
  for(i=0;i<N;i++)visited[i]=false;
  for(int ai=0;ai<M;ai++){
    cin>>i>>j;
    graph[i-1][j-1]=true;
    graph[j-1][i-1]=true;
  }
  
  cout <<dsp(1,0,visited,N)<< endl;
  return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int a, b, c, d, e, f;
signed main() {
	cin >> a >> b >> c >> d >> e >> f;
	int ans = 0;
	if (a&&d&&e) {
		ans += 3;
		ans += (a - 1) / 2 * 2;
		ans += (d - 1) / 2 * 2;
		ans += (e - 1) / 2 * 2;
	}
	int res = 0;
	res += (a) / 2 * 2;
	res += (d) / 2 * 2;
	res += (e) / 2 * 2;
	cout << max(ans, res) + b << endl;
}

Measured memory_bytes: 256
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

h1,m1,h2,m2,k = ip()
t2 = h2*60 + m2
t1 = h1*60 + m1
print(t2-t1-k)

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

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

  if(N >= M){
    cout << "0" << endl;
    return 0;
  }

  sort(X, X + M);
  int L[M-1];
  for(int i = 0; i < M-1; i++){
    L[i] = X[i+1] - X[i];
  }
  sort(L, L + M -1, greater<int>());
  int uv = 0;
  for(int i = 0; i < N-1; i++){
    uv += L[i];
  }
  cout << X[M-1] - X[0] - uv << endl;
  return 0;
}


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

#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(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    int k;
    cin >> k;
    queue<ll> que;
    rep2(i,1,10) que.push(i);

    ll ans;
    rep(i,k){
        ans=que.front();
        que.pop();
        if(ans%10!=0) que.push(ans*10+ans%10-1);
        que.push(ans*10+ans%10);
        if(ans%10!=9) que.push(ans*10+ans%10+1);
    }

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

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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int N, K;
  cin >> N >> K;

  rep(i, K) {
    int a, b;
    cin >> a >> b;
    cout << min(min(a - 1, N - a), min(b - 1, N - b)) % 3 + 1 << "\n";
  }

  return 0;
}


Measured memory_bytes: 3172
import sys
read = sys.stdin.read
def main():
    n = int(input())
    if n == 1:
        print(1)
        sys.exit()
    # nd:num of div
    r = 0
    for i1 in range(1, n + 1):
        y = n // i1
        r += y * (y + 1) * i1 / 2
    print(int(r))

if __name__ == '__main__':
    main()

Measured memory_bytes: 63316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
int main(){
    int N , D;
    cin >> N >> D;
    vector<vector<int>> x(N, vector<int>(D));
    rep(i,N){
        rep(j,D) cin >> x.at(i).at(j);
    }
    int ans = 0;
    rep(i,N) rep(j,i){// j < i
      int sq = 0;
      rep(k,D){
          int s = x.at(i).at(k)-x.at(j).at(k);
          sq += s * s;

      }
      int s = sqrt(sq) + 0.5;
      if(s * s == sq) 
      ans++;
      }
      cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    final int n = sc.nextInt();
    List<Long> a = new ArrayList<Long>();
    int fe = -1; //最後の偶数の位置
    int count=0;
    for(int i=0;i<n;i++) {
    	a.add(sc.nextLong());
    	if(a.get(i)%2 == 0) {
    		fe = i;
    	}
    }
    sc.close();
    long j = 0;
    for(int i=fe;i>=0;i--) {
    	j = a.get(i);
    	while(j%2==0) {
    		count++;
    		j /= 2;
    		//System.out.print(j+", ");
    	}
    	//System.out.println("");
    }
    System.out.println(count);
    
  }
  
}

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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF 200000000
#define int long long
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
pair<int,char> a[100000],b[100000];
pair<int,char> rr[100000],ll[100000];

void merge(int l, int m,int r){
  int n1=m-l;
  int n2=r-m;
  lp(i,n1) ll[i]=b[l+i];
  lp(i,n2) rr[i]=b[m+i];
  int i=0,j=0;
  ll[n1]=make_pair(INF,' ');
  rr[n2]=make_pair(INF,' ');
  lps(k,l,r){
    if(ll[i].first>rr[j].first){
      b[k]=rr[j];
      j++;
    }
    else{
      b[k]=ll[i];
      i++;
    }
  }
}

void mergesort(int l,int r){
  if(l+1<r){
    int m=(l+r)/2;
    mergesort(l,m);
    mergesort(m,r);
    merge(l,m,r);
  }
  else return ;
}

int partition(int p,int r){
	int x=a[r].first;
	int i=p-1;
	lps(j,p,r){
		if(a[j].first<=x){
			i++;
			swap(a[i],a[j]);
		}
	}
	swap(a[i+1],a[r]);
return i+1;
}

void quicksort(int p,int r){
	if(p<r){
		int q=partition(p,r);
		quicksort(p,q-1);
		quicksort(q+1,r);
	}

}

signed main(){
	int n;
	cin>>n;
	lp(i,n) {
		int y;
		char x;
		cin>>x>>y;
		a[i]=make_pair(y,x);
		b[i]=make_pair(y,x);
	}
	quicksort(0,n-1);
	mergesort(0,n);
	int stat=0;
	lp(i,n){
		if(a[i]!=b[i]) stat=1;
	}
	if(stat==0) cout<<"Stable"<<endl;
	else cout<<"Not stable"<<endl;
	lp(i,n){
		cout<<a[i].second<<" "<<a[i].first<<endl;
	}
	return 0;
}


Measured memory_bytes: 7676
n = int(input())

n -= 1

cnt = 1
num = 26
name = ''
anum = 97

while n >= num:
    name += chr(n%num+anum)
    n = int(n/26)
    n -= 1

name += chr(n%num+anum)

name = name[::-1]

print(name)

Measured memory_bytes: 9188
import java.util.Scanner;

public class Main{
	static int h,w;
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int n= sc.nextInt();
				int m = sc.nextInt();
				int t = sc.nextInt();
				int p = sc.nextInt();
				if(n+m+t+p==0)break;
				h = m;
				w = n;
				int[][] paper = new int[m+1][n+1];
				for(int i=0;i<m;i++)
					for(int k =0;k<n;k++)
						paper[i][k] = 1;

				while(t--!=0) {
					int d = sc.nextInt();
					int c = sc.nextInt();
					if(d==2) {
						int k=h-1+h-1-c-c+1;
						if(h>=2*c) {
							for(int i=h-c-1;i>=h-c-c;i--) {
								for(int j=0;j<w;j++) {
									//  System.out.println(i+" "+j);
									paper[i][j] += paper[k-i][j];
									//System.out.println("paper["+i+"]["+j+"]="+paper[i][j]);
								}
							}
							h-=c;
						}
						else{
							for(int i=h-c-1; i>=0; i--) {
								for(int j=0; j<w; j++) {
									paper[k-i][j]+=paper[i][j];
								}
							}
							int[][] copy=new int [h][w];
							for(int i=h-c; i<h; i++) {
								for(int j=0; j<w; j++) {
									copy[i][j]=paper[i][j];
								}
							}
							for(int i=0; i<c; i++) {
								for(int j=0; j<w; j++) {
									paper[i][j]=copy[h-i-1][j];
								}
							}
							h=c;
						}
						//System.out.println("h="+h);
					}
					else if(d==1) {
						int l=w-1+w-1-c-c+1;
						if(w>=2*c) {
							for(int i=0;i<h;i++) {
								for(int j=w-c-1; j>=w-c-c; j--) {
									paper[i][j] += paper[i][l-j];
									//System.out.println("paper["+i+"]["+j+"]="+paper[i][j]);
								}
							}
							w-=c;
						}
						else {
							for(int i=0; i<h; i++) {
								for(int j=w-c-1; j>=0; j--) {
									paper[i][l-j]+=paper[i][j];
								}
							}
							int[][] copy=new int [h][w];
							for(int i=0; i<h; i++) {
								for(int j=w-c; j<w; j++) {
									copy[i][j]=paper[i][j];
								}
							}
							for(int i=0; i<h; i++) {
								for(int j=0; j<c; j++) {
									paper[i][j]=copy[i][w-j-1];
								}
							}
							w=c;
						}
						//System.out.println("w="+w);
					}
				}
//				for(int i=0; i<h; i++) {
//					for(int j=0; j<w; j++) {
//						System.out.println("paper["+i+"]["+j+"]="+paper[i][j]);
//					}
//				}

				while(p--!=0) {
					int x = sc.nextInt();
					int y = sc.nextInt();
					//System.out.println(h+" "+w);
					System.out.println(paper[h-1-y][w-1-x]);
				}
			}




		}
	}
}


Measured memory_bytes: 44404
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>

using namespace std;

int main(){
  
    double T,X;

    cin >>T >> X;

    cout << T/X<<endl;

  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <utility>
#include <vector>
#include <bitset>
#include <limits>

int main()
{
    std::size_t N, M, X;
    std::cin >> N >> M >> X;

    std::vector<std::pair<std::size_t, std::vector<std::size_t>>> A(N);
    for(auto& a : A)
    {
        std::cin >> a.first;
        a.second.resize(M);
        for(auto& b : a.second)
        {
            std::cin >> b;
        }
    }

    std::size_t answer = std::numeric_limits<std::size_t>::max();

    std::bitset<16> bit = 0;
    while(bit[N] == 0)
    {
        std::size_t C = 0;
        std::vector<std::size_t> rikaido(M, 0);
        for(std::size_t i=0; i<N; ++i)
        {
            if(bit[i] == 1)
            {
                C += A[i].first;
                for(std::size_t j=0; j<M; ++j)
                {
                    rikaido.at(j) += A[i].second.at(j);
                }
            }
        }

        bool ok = true;
        for(const auto& r : rikaido)
        {
            if(r < X)
            {
                ok = false;
                break;
            }
        }

        if(ok)
        {
            answer = std::min(answer, C);
        }
        bit = bit.to_ulong() + 1u;
    }

    if(answer == std::numeric_limits<std::size_t>::max())
    {
        std::cout << "-1" << std::endl;
    }
    else
    {
        std::cout << answer << std::endl;
    }

    return 0;
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

int N, D;
vector<int> A, color;
vector<tuple<long long,int,int>> E;

int find_(int a)
{
	if(a==color[a]) return a;
	return color[a]=find_(color[a]);
}

void union_(int a, int b)
{
	a=find_(a);
	b=find_(b);
	color[a]=color[b]=min(a,b);
}

void solve(int s, int e)
{
	int m=(s+e)>>1, l=s, r=e;
	if(s>=e) return;
	for(int i=s;i<=e;i++) {
		if(i<=m && A[i]-1LL*i*D<A[l]-1LL*l*D) l=i;
		else if(i>m && A[i]+1LL*i*D<A[r]+1LL*r*D) r=i;
	}
	for(int i=s;i<=e;i++) {
		if(i<=m) E.emplace_back(A[i]+A[r]+1LL*(r-i)*D,i,r);
		else E.emplace_back(A[l]+A[i]+1LL*(i-l)*D,l,i);
	}
	solve(s,m);
	solve(m+1,e);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int u, v;
	long long w, ans=0;
	cin>>N>>D;
	A.resize(N); color.resize(N);
	for(int i=0;i<N;i++) cin>>A[color[i]=i];
	solve(0,N-1);
	sort(E.begin(),E.end());
	for(auto e: E) {
		tie(w,u,v)=e;
		if(find_(u)!=find_(v)) {
			union_(u,v);
			ans+=w;
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 69344
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
print(ceil(n/111)*111)


Measured memory_bytes: 63980