akhauriyash/Code-Regression huggingface dataset:
from math import floor, ceil, log

N = int(input())

# O(logN)
def base10to(n, b):
    if n // b > 0:
        return base10to(n // b, b) + str(n % b)
    else:
        return str(n % b)

def calc_base_for_pos_N(N):
    S_base4 = base10to(N, 4) # str

    S_raw = list(map(int, tuple(''.join([digit + '0' for digit in S_base4])[:-1])))[::-1]

    # transformation. takes O(logN)
    position = 0
    while position <= len(S_raw) - 3:
        digit = S_raw[position]
        # -2のところだったら
        if position % 2 == 1:
            position += 1
            continue
        if digit in {0, 1}:
            position += 1
            continue
        elif digit == 2:
            S_raw[position] = 0
            S_raw[position + 1] += 1
            S_raw[position + 2] += 1
        elif digit == 3:
            S_raw[position] = 1
            S_raw[position + 1] += 1
            S_raw[position + 2] += 1
        else: #4
            S_raw[position] = 0
            S_raw[position + 2] += 1
        position += 2

    # postprocessing
    if S_raw[-1] == 2:
        S_raw[-1] = 0
        S_raw += [1, 1]
    elif S_raw[-1] == 3:
        S_raw[-1] = 1
        S_raw += [1, 1]
    elif S_raw[-1] == 4:
        S_raw[-1] = 0
        S_raw += [0, 1]

    S = ''.join([str(digit) for digit in S_raw])[::-1]
    return S

if N >= 0:
    print(calc_base_for_pos_N(N))
else:
    pos_N = abs(N)
    pos_S = list(map(int, list(calc_base_for_pos_N(pos_N))))
    pos_S = pos_S[::-1]
    shifted_S = [0] + pos_S
    pos_S = pos_S + [0]
    assert len(pos_S) == len(shifted_S)
    S_raw = [shifted_S[i] + pos_S[i] for i in range(len(pos_S))]
    position = 0
    while position <= len(S_raw) - 3:
        digit = S_raw[position]
        if digit in {0, 1}:
            position += 1
            continue
        elif digit == 2:
            S_raw[position] = 0
            S_raw[position + 1] += 1
            S_raw[position + 2] += 1
        elif digit == 3:
            S_raw[position] = 1
            S_raw[position + 1] += 1
            S_raw[position + 2] += 1
        else: #4
            S_raw[position] = 0
            S_raw[position + 2] += 1
        position += 1
    # postprocessing
    last_two_digits = S_raw[-2:]
    if last_two_digits == [2, 1]:
        S_raw = S_raw[:-2]
    elif last_two_digits == [3, 1]:
        S_raw[-2:] = [1]
    elif last_two_digits == [1, 2]:
        S_raw[-2:] = [1, 0, 1, 1]
    elif last_two_digits == [2, 2]:
        S_raw[-2:] = [0, 1]
    elif last_two_digits == [3, 2]:
        S_raw[-2:] = [1, 1]
    elif last_two_digits == [4, 1]:
        S_raw[-2:] = [0, 0, 1]
    elif last_two_digits == [4, 2]:
        S_raw = S_raw[:-2]
    S = ''.join([str(digit) for digit in S_raw])[::-1]
    print(S)
    

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

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

void visit(int x, int y) {
	if (x<0 || 11<x || y<0 || 11<y || v[y][x]=='0') return ;
	v[y][x] = '0';
	for (int i=0; i<4; ++i) {
		visit(x+dx[i], y+dy[i]);
	}
}

int main() {
	while (1) {
		for (int i=0; i<12; ++i) {
			if ( ! cin.eof()) {
				cin >> v[i];
			} else {
				return 0;
			}
		}

		int ans = 0;
		for (int y=0; y<12; ++y) {
			for (int x=0; x<12; ++x) {
				if (v[y][x] != '0') {
					visit(x, y);
					++ ans;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1184
#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>
using namespace std;
long long MOD = 1e9 + 7;

vector<bool> check;
string S;

int main() {
	cin >> S;
	check.resize(26, false);
	for (int n = 0; n < S.size(); n++) {
		if (check[S[n] - 'a']) {
			cout << "no" << endl;
			return 0;
		}
		check[S[n] - 'a'] = true;
	}
	cout << "yes" << endl;
	return 0;
}

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

int main() {
  int n, k, x, y, ret;
  cin >> n;
  cin >> k;
  cin >> x;
  cin >> y;
  if (n > k) {
    ret = k * x + (n - k) * y;
  } else {
    ret = n * x;
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main()
{
    char x[4];
    cin >> x;
    sort(x,x+4);
    if(x[0]==x[1] && x[1]!=x[2] && x[2]==x[3]){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    int a, b, c;
    cin >> a >> b >> c;

    if (a + c - 1 >= b - c + 1){
        for(int i = a; i <= b; i++) cout << i << endl;
    }
    else{
        REP(i, c) cout << (a+i) << endl;
        REP(i, c) cout << (b-c+1+i) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

long long int N;
long long int K;
long long int l[51] = {};
long long int ans = 0;

using namespace std;

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> l[i];
	}
	stable_sort(l, l + N+1);
	for (int i = N; i >= N-K+1; i--) {
		ans += l[i];
	}
	cout << ans << endl;
}

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

int main() {
  string S;
  cin >> S;
  if (S == "SUN") {
    cout << 7;
  }
  else if (S == "MON") {
    cout << 6;
  }
  else if (S == "TUE") {
    cout << 5;
  }
  else if (S == "WED") {
    cout << 4;
  }
  else if (S == "THU") {
    cout << 3;
  }
  else if (S == "FRI") {
    cout << 2;
  }
  else {
    cout << 1;
  }
}

Measured memory_bytes: 3636
# coding: utf-8
# Your code here!
#二分探索の実装

N=int(input())
S=[int(i) for i in input().split()]
Q=int(input())
T=[int(i) for i in input().split()] 
C=0
a=0;b=0
for i in T:
    b=len(S)-1
    a=0
    while(a+1<b):
        c=((a+b)//2)
        if(S[c]>=i):
            b=c
        elif(S[c]<i):
            a=c
    if(S[a]==i or S[b]==i):
        C+=1
print(C);



Measured memory_bytes: 16900
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

vector <ll> ans;

int DFS(ll num, int dig){
  ans.push_back(num);
  if (dig == 10) return 0;

  ll now = num % 10;
  if (now > 0){
    DFS(num * 10 + now - 1, dig + 1);
  }
  DFS(num * 10 + now, dig + 1);
  if (now < 9){
    DFS(num * 10 + now + 1, dig + 1);
  }
  return 0;
}

int main(){
  ans.push_back(0);
  for (ll i = 1; i < 10; i++) DFS(i, 1);
  sort(ans.begin(), ans.end());

  int K; cin >> K;
  cout << ans[K] << endl;

  return 0;
}


Measured memory_bytes: 2420
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  s[k - 1] = s[k - 1] - 'A' + 'a';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<tuple>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef unsigned long long int ull;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=1e3;
const int MAXM=2000;
const ll INF=1e18;

struct edge{
    int from,to;
    ll cost;
};

int n,m;
vector<edge> es(MAXM);
vector<ll> d(MAXN,-INF);

int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int from,to,cost;
        cin>>from>>to>>cost;
        from--;to--;
        es[i]=edge{from,to,cost};
    }
   d[0]=0;
    for(int i=0;i<n-1;i++){
        for(int j=0;j<m;j++){
            edge e=es[j];
            if(d[e.from]!=-INF&&d[e.to]<d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
            }
        }
    }
    ll ans=d[n-1];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            edge e=es[j];
            if(d[e.from]!=-INF&&d[e.to]<d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
            }
        }
    }
    if(ans!=d[n-1]) cout<<"inf"<<endl;
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
int main(void){
    int i,win,lose;
    i = win = lose = 0;
    char s[256];
    scanf("%s",s);
    while(1){
        if (s[i] == '\0'){
            break;
        }
        if (s[i] == 'x'){
            lose++;
        }else if (s[i] == 'o'){
            win++;
        }
        i++;
    }
    if (win >= 8 || lose <= 7){
        printf("YES");
    }else{
        printf("NO");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":"\n");return os;}
//------------------------------------------------------------------------------

int main(int argc, char const *argv[]) {
    string s;
    cin>>s;
    string ans="";
    REP(i,s.size()) {
        if(s[i]!='B') {
            ans+=s[i];
        }
        else {
            ans=ans.substr(0,ans.size()-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

ct = []
for _ in range(N):
    ct.append(list(map(int, input().split())))

Cost, Time = ct[0]
for c, t in ct:
    if t <= T and Cost >= c:
        Cost = c
        Time = t

if Time <= T:
    print(Cost)
else:
    print('TLE')

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

typedef pair<int,int> pr;
typedef pair<int,pr > ppr;
const int INF=2<<28;
int main() {
	// your code goes here
	int c,n,m,s,d,a,b,f;
	while(cin >> c >> n >> m >> s >> d && c!=0){
		int longs [101][11]={};
		for(int i=1;i<=100;i++)
			for(int j=0;j<=10;j++)
				longs[i][j]=INF;
		priority_queue<ppr,vector<ppr>,greater<ppr> > p;
		vector<pr> root[101];
		for(int i=0;i<m;i++){
			cin >> a>>b >> f;
			root[a].push_back(pr(b,f));
			root[b].push_back(pr(a,f));
		}
		longs[s][0]=0;
		p.push(ppr(0,pr(0,s)));
		while(!p.empty()){
			int f=p.top().first,point=p.top().second.second,t=p.top().second.first;
			p.pop();
			if(longs[point][t]!=f) continue;
			for(int i=0;i<root[point].size();i++){
				int dir=root[point][i].first;
				if(f+root[point][i].second <= longs[dir][t]){
				longs[dir][t]=f+root[point][i].second;
				p.push(ppr(longs[dir][t],pr(t,dir)));
				}
				if(t+1<=c && f+root[point][i].second/2 <= longs[dir][t+1]){
				longs[dir][t+1]=f+root[point][i].second/2;
				p.push(ppr(longs[dir][t+1],pr(t+1,dir)));
				}
			}
		}
		int minim=INF;
		for(int i=0;i<=c;i++)
		minim=min(minim,longs[d][i]);
		cout << minim<< endl;
	}
	return 0;
}

Measured memory_bytes: 1304
#include<iostream>
#include <string>
using namespace std;
int a[100];
int p,q=0;
int mode=100;
	int main(){
		for(int i=0;i<100;i++){
		cin>>p;
		if(a[p-1]<0){
			a[p-1]=1;}else{a[p-1]++;}}
		while(1){
			for(int ii=0;ii<100;ii++){
				if(a[ii]==mode){cout<<ii+1<<endl;
				q++;
				}}
			if(q>0){break;}else{mode--;}}
    return 0;
	}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define X first
#define Y second
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define D double
#define ll long long
#define REP(i,a) for(int i=0;i<a;i++)
#define REP1(i,a,b) for(int i=a;i<b;i++)
#define REP2(i,a,b) for(int i=a;i<=b;i++)
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define RREP1(i,a,b) for(int i=a;i>b;i--)
#define RREP2(i,a,b) for(int i=a;i>=b;i--)
#define SREP(i,x) for(auto i:x)
#define MS0(x) memset((x),0,sizeof((x)))
#define MS1(x) memset((x),-1,sizeof((x)))
#define MSF(x) memset((x),127,sizeof(x))
#define pb push_back
#define LE(x) (int)((x).size())
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<D,D>
#define im guagua
#define RI(x) x=rit()
#define RII(a,b) a=rit(),b=rit()
#define RIII(a,b,c) a=rit(),b=rit(),c=rit()
#define debug 0
const int INF = 0x7F7F7F7F;
const double EPS = 1e-10 ;
const ll mod7 = 1e9+7;
const ll mod9 = 1e9+9;
using namespace std;
inline ll rit(){
    ll f=0,key=1;
    char c;
    do{
        c=getchar();
        if(c=='-') key=-1;
    }while(c<'0' || c>'9');
    do{
        f=f*10+c-'0';
        c=getchar();
    }while(c>='0' && c<='9');
    return f*key;
}
inline void fprt(D f){
    printf("%.08lf",f);
}
void init(){
}
const int Z = 100005;
int mk[Z];
tuple<int,int,int> tx[Z],ty[Z];
int n;
int x[Z],y[Z],belongx[Z],belongy[Z];
priority_queue<PII,vector<PII>,greater<PII> > pq;
int srt(tuple<int,int,int> ta,tuple<int,int,int> tb){
    return get<0>(ta) < get<0>(tb);
}
int srt2(tuple<int,int,int> ta,tuple<int,int,int> tb){
    return get<1>(ta) < get<1>(tb);
}
void read(){
    RI(n);
    REP(i,n){
        RII(x[i],y[i]);
        ty[i] = tx[i] = mt(x[i],y[i],i);
    }
    sort(tx,tx+n,srt);
    sort(ty,ty+n,srt2);
    REP(i,n){
        belongx[get<2>(tx[i])] = i;
        belongy[get<2>(ty[i])] = i;
    }
}
void solve(){
    PII f;
    int tar;
    ll ans;
    ans=  0;
    pq.push(mp(0,0));
    while(!pq.empty()){
        f = pq.top();
        pq.pop();
        if(mk[f.Y]) continue;
        ans+=f.X;
        mk[f.Y] = 1;
        if(belongx[f.Y] > 0 ){
            tar = get<2>(tx[belongx[f.Y]-1]);
            pq.push(mp(abs(x[f.Y] - x[tar]),tar));
        }
        if(belongx[f.Y] < n-1){
            tar = get<2>(tx[belongx[f.Y]+1]);
            pq.push(mp(abs(x[f.Y] - x[tar]),tar));
        }
        if(belongy[f.Y] > 0 ){
            tar = get<2>(ty[belongy[f.Y]-1]);
            pq.push(mp(abs(y[f.Y] - y[tar]),tar));
        }
        if(belongy[f.Y] < n-1){
            tar = get<2>(ty[belongy[f.Y]+1]);
            pq.push(mp(abs(y[f.Y] - y[tar]),tar));
        }
    }
    cout<<ans<<endl;

}
int main(){
    int nn=1;
    // nn=rit();
    while(nn--){
        // while(cin>>n) 
            init(),read(),solve();
    }
    return 0;
}

Measured memory_bytes: 7796
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int n;
		double ans = 0;
		String str;
		str = bf.readLine();
		n = Integer.parseInt(str);
		if(n % 2 == 0) {
			ans = 0.5;
		} else {
			ans = (double)(n/2 + 1)/n;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 20564
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#define ll                 long long    
#define vi                 vector<ll >
// -------------------Standard Traversal Moves---------------------
// vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
// vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------

#define int                long long                        
#define pb                 push_back                                                     
#define mii                map<ll ,ll >
#define rep(i, a, b)       for(ll  i=a;i<b;i++)
#ifdef LOCAL
#define dbg(args...)       { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
#define dbg(args...)
#endif
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define hell               1000000007
// #define hell               (ll)998244353
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define mp                 make_pair
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define inf                3223372036854775807
#define endl               '\n' 
#define PI                  3.14159265
#define N                  200005
ll n, m, k, a[N];


int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ll tests = 1;
    // cin >> tests;
    rep(test, 1, tests+1)
    {
        cin >> n;
        vi v1, v2;
        rep(i, 0, n)
        {
        	cin >> m >> k;
        	v1.pb(m);
        	v2.pb(k);
        }
        sort(all(v1));
        sort(all(v2));
        if(n%2)
        {
        	cout << v2[n / 2] - v1[n / 2] + 1;
        	return 0;
        }
        else
        {
        	k = v1[n / 2] + v1[n / 2 - 1];
        	k = v2[n / 2] + v2[n / 2 - 1 ] - k;
        	cout << k + 1;
        	return 0;
        }

    }
    return 0;
}

Measured memory_bytes: 6684
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<i64,i64>;
using uset = unordered_set<int>;

int main(){
    int N;
    cin >> N;
    string S,T;
    cin >> S >> T;

    vector<vector<int>> dp(100100, vector<int>(27, 0));
    dp[0][S[0] - 'a'] = 1;
    for(int i = 1; i < N; i++){
        for(char  c = 'a'; c <= 'z'; c++){
            dp[i][c - 'a'] = (dp[i-1][c - 'a'] % 1000000007);
        }
        if(i == N -1) continue;
        ((dp[i][S[i] - 'a'] += dp[i-1][T[i] -'a']) %= 1000000007);
    }

    cout << dp[N - 1][T[N-1] - 'a'] << endl;
}


Measured memory_bytes: 17964
#include<iostream>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s=="hi" or s=="hihi" or s=="hihihi" or s=="hihihihi" or s=="hihihihihi")
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int main(){
    int D; cin >> D;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    rep(i,D){
        rep(j,26){
            cin >> s[i][j];
        }
    }


    vector<int> day(26,0);
    vector<int> contest_no;
    rep(z,D){
        

        // int n_contest=1;
        // int n_score=0;
        // rep(i,26){
        //     if(n_score < c[i] * ((z+1) - day[i])){
        //         n_score= c[i] * ((z+1) - day[i]);
        //         n_contest = i+1;   
        //     }
        // }
        // day[n_contest - 1] = z+1;

        // int contest=1;
        // int score=-1;
        // rep(i,26){
        //     if(score < s[z][i]){
        //         score = s[z][i];
        //         contest = i+1;
        //     }
        // }

        int m_contest=1;
        int m_score=-1e9;
        rep(i,26){
            if(m_score <  s[z][i] + c[i] * ((z+1) - day[i])){
                m_score = s[z][i] + c[i] * ((z+1) - day[i]);
                m_contest = i+1;
            }
        }
        day[m_contest - 1] = z+1;

        contest_no.push_back(m_contest);
    }

    //解の出力
    for(int i:contest_no){
        cout << i << endl;
    }
}


Measured memory_bytes: 3708
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 1000;
int N;
ll a[MAX_N];
ll dp[MAX_N];
vector<int> picked[MAX_N];

int main() {
  std::ios::sync_with_stdio(false);std::cin.tie(0);
  
  cin >> N;
  rep(i, N) cin >> a[i];

  for (int i = 0; i < N; ++i) {
      ll ma = -LLONG_MAX;
      int last_select = -1;
      for (int j = i-2; j >= 0; j -= 2) {
          if (ma < dp[j]) {
              ma = dp[j];
              last_select = j;
          }
      }
      if (ma < 0) {
          dp[i] = a[i];
          picked[i].push_back(i);
      } else {
          dp[i] = a[i] + ma;
          picked[i] = picked[last_select];
          picked[i].push_back(i);
      }
  }

  ll ma = -LLONG_MAX;
  vector<int> selected;
  for (int i = 0; i < N; ++i) {
      if (ma < dp[i]) {
          ma = dp[i];
          selected = picked[i];
      }
  }

  vector<int> ans;
  for (int i = 0; i < selected.size(); ++i) {
      if (i == 0) {
          for (int j = 0; j < selected[i]; ++j) {
              ans.push_back(1);
          }
      } else {
          int interval = selected[i]-selected[i-1]-1;
          while (interval > 1) {
              ans.push_back(3);
              interval -= 2;
          }
          ans.push_back(2);
      }
  }
  int tail = N-selected[_size(selected)-1]-1;
  while (tail > 0) {
      ans.push_back(tail+1);
      --tail;
  }


  cout << ma << endl;
  cout << _size(ans) << endl;
  for (int a : ans) {
      cout << a << endl;
  }


  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template<typename T>
struct Kruskal{
  
  struct edge{
    int from,to;
    T cost;
    int used;
    edge(){}
    edge(int from,int to,T cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  int n;
  vector<int> p,r;
  vector<edge> edges;

  Kruskal(){}
  Kruskal(int n):n(n){}

  void init(int n){
    r.assign(n,1);
    p.resize(n);
    iota(p.begin(),p.end(),0);
  }
  
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }

  bool same(int x,int y){
    return find(x)==find(y);
  }

  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }

  void add_edge(int u,int v,T c){
    edges.emplace_back(u,v,c);
  }
  
  T build(){
    sort(edges.begin(),edges.end());
    init(n);
    T res=0;
    for(auto &e:edges){
      if(!same(e.from,e.to)){
        res+=e.cost;
        unite(e.from,e.to);
        e.used=1;
      }
    }
    return res;
  }
};
//END CUT HERE
int main(){
  int V,E;
  scanf("%d %d",&V,&E);
  Kruskal<int> ksk(V);
  for(int i=0;i<E;i++){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    ksk.add_edge(a,b,c);
  }
  cout<<ksk.build()<<endl;
  return 0;
}

/*
  verified on 2018/10/22
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_A&lang=jp
*/



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

using namespace std;

int main(){
  int A,B,C;
  cin >> A >> B >> C;

  if( (A < C) && (C < B) ){
    cout << "Yes" << endl;
  }
  else if( (B < C) && (C < A)){
   cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
def main():
    h,w,k=map(int, input().split())
    grid = []
    l = [[0]*w for _ in range(h)]
    ten_g = [0]*(h)
    ten_r = [0]*(w)
    for i in range(h):
        s = list(input().rstrip())
        grid.append(s)
    res = 0
    for bi in range(2**(h+w)):
        tmp = 0
        for i in range(h):
            for j in range(w):
                if(bi & 1<<i and bi&(1<<h+j)):
                    if(grid[i][j]=="#"):
                        tmp+=1
        if(tmp == k):
            res+=1


    print(res)
if __name__ == '__main__':
    main()



Measured memory_bytes: 9200
#include<bits/stdc++.h>
#define for_int(i,a,b) for(int i=(a);i<=(b);++i)
#define rep_int(i,a,b) for(int i=(a);i>=(b);--i)
#define for_ll(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep_ll(i,a,b) for(ll i=(a);i>=(b);--i)
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1e6+5
#define quick_pow_mod 1e9+7
#define PII pair<int,int>
using namespace std;
//快读
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (; isdigit(c); c = getchar())
		x = x * 10 + c - 48;
	return x * f;
}
int a[6];
int main() {
	int ans = 0;
	for (int i = 1; i <= 5; ++i) {
		a[i] = read();
		if (a[i] == 0)
			ans = i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){
    int n;
    cin>>n;
    
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    
    int idx=0;
    vector<bool> bb(n, false);
    bb[0]=true;
    
    bool ok=false;
    
    int cnt=0;
    
    int cntloop=0;
    
    while(1){
        
        if(cntloop>n){
            ok=false;
            break;
        }
        
        if(bb[idx]){
            bb[idx]=false;
            idx=a[idx]-1;
            bb[idx]=true;
            cnt++;
        }else{
            ok=false;
            break;
        }
        
        if(bb[idx]&&idx==1){
            ok=true;
            break;
        }
        
        cntloop++;
    }
    
    if(ok){
        cout<<cnt<<endl;
    }else{
        cout<<-1<<endl;
    }
}


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

int main(){
	string s;
	cin >> s;
	if(s == "Sunny"){
		cout << "Cloudy" << endl;
	}else if(s == "Cloudy"){
		cout << "Rainy" << endl;
	}else{
		cout << "Sunny" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

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

const int MAXN = 100005;
const int mod = 1e9 + 7;

int n, ans = 1, a[MAXN], c[MAXN], d[MAXN], f[MAXN], cnt[MAXN];
bool v[MAXN];

inline int Dp(int l, int c)
{
	int t = ((l & 1) && (l ^ 1)) + 1;
	f[0] = 1, f[1] = t;
	for (int i = 2; i <= c; i ++)
		f[i] = (1LL * f[i - 1] * t + 1LL * f[i - 2] * (i - 1) % mod * l) % mod;
	return f[c];
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 1; i <= n; i ++)
		a[i] = Read(), d[a[i]] ++;
	for (int i = 1; i <= n; i ++)
		if (d[a[i]] > 2)
			return puts("0"), 0;
	for (int i = 1; i <= n; i ++)
		if (!d[i])
		{
			int x = i, len = 0;
			while (d[x] < 2)
				v[x] = 1, len ++, x = a[x];
			f[x] = len;
		}
	for (int i = 1; i <= n; i ++)
		if (!v[i])
		{
			int x = i, len = 0;
			bool flg = false;
			while (!v[x])
				v[x] = 1, c[len ++] = x, flg |= f[x], x = a[x];
			if (i ^ x)
				return puts("0"), 0;
			if (!flg)
				cnt[len] ++;
			else
			{
				int sta = 0, lst;
				while (!f[c[sta]])
					sta ++;
				lst = sta;
				for (int j = (sta + 1) % len; j ^ sta; j = (j + 1) % len)
					if (f[c[j]])
					{
						int x = (j - lst + len) % len;
						if (x < f[c[j]])
							return puts("0"), 0;
						if (x > f[c[j]])
							ans = (ans << 1) % mod;
						lst = j;
					}
				int x = (sta - lst + len - 1) % len + 1;
				if (x < f[c[sta]])
					return puts("0"), 0;
				if (x > f[c[sta]])
					ans = (ans << 1) % mod;
			}
		}
	for (int i = 1; i <= n; i ++)
		if (cnt[i])
			ans = 1LL * ans * Dp(i, cnt[i]) % mod;
	return printf("%d\n", ans), 0;
}


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

const int mx = 305;
const int inf = 0x3f3f3f3f;
const int S = mx - 2, T = mx - 1;

struct edge {
  int from, to, cap;
  edge *rev;
  edge(int from, int to, int cap) : from(from), to(to), cap(cap) {}
  void flow(int f) { cap -= f, rev->cap += f; }
};

vector<edge *> adj[mx];

void addEdge(int u, int v, int c) {
  edge *e = new edge(u, v, c);
  edge *rev = new edge(v, u, 0);
  e->rev = rev, rev->rev = e;
  adj[u].push_back(e);
  adj[v].push_back(rev);
}

bool vis[mx], inq[mx];
int bt[mx], mf[mx];
edge *bte[mx];
bool augment(int &flow) {
  fill(vis, vis + mx, false);
  fill(inq, inq + mx, false);
  fill(mf, mf + mx, 0);
  queue<int> q;
  q.push(S);
  mf[S] = inf;
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    inq[p] = false;
    if (vis[p])
      continue;
    vis[p] = true;
    if (p == T)
      break;
    for (edge *e : adj[p]) {
      if (!vis[e->to] && min(e->cap, mf[p]) > mf[e->to]) {
        bt[e->to] = p;
        bte[e->to] = e;
        mf[e->to] = min(e->cap, mf[p]);
        if (!inq[e->to])
          q.push(e->to), inq[e->to] = true;
      }
    }
  }
  if (!vis[T])
    return false;
  int p = T, f = mf[T];
  while (p != S) {
    bte[p]->flow(f);
    p = bt[p];
  }
  flow = f;
  return true;
}

int maxflow() {
  int flow, mflow = 0;
  while (augment(flow))
    mflow += flow;
  return mflow;
}

int main() {
  int x, y, e;
  cin >> x >> y >> e;

  for (int i = 0; i < x; i++)
    addEdge(S, i, 1);
  for (int i = 100; i < 100 + y; i++)
    addEdge(i, T, 1);

  for (int i = 0; i < e; i++) {
    int a, b;
    cin >> a >> b;
    addEdge(a, 100 + b, inf);
  }

  cout << maxflow() << endl;
  return 0;
}


Measured memory_bytes: 4012
#include <iostream>
      #include <string>
      #include <vector>
      #include <algorithm>
      #include <map>
      using namespace std;
      typedef long long ll;
      #define rep(i,n) for (int i=0;i < (int)(n);i++)

      int main(){
        int h,w;
        cin >> h >> w;
        ll ans=1LL << 60;
        for (int i=1;i < w;i++){
           ll s1,s2,s3;
           s1 = (ll)h*i;
           if (h%2 == 0){
             s2 = (h/2)*(ll)(w-i);
             s3 = s2;
           }
           else {
             s2 = (h/2)*ll(w-i);
             s3 = ((h+2-1)/2)*ll(w-i);
           }
           ans=min(ans,max({s1,s2,s3})-min({s1,s2,s3}));
           //printf("s1,s2,s3 = (%lld ,%lld %lld) diff %lld\n",s1,s2,s3,max({s1,s2,s3})-min({s1,s2,s3}));
           if ((w-i)%2 == 0 ){
             s2 = (ll)h*(w-i)/2;
             s3 = s2;
           }
           else if ((w-i) != 1){ 
             //printf("w-i/2 %d\n w-i+2-1/2 %d\n",(w-i)/2,(w-i+2-1)/2);
             s2 = ll(h)*((w-i)/2);
             s3 = ll(h)*((w-i+2-1)/2);
           }
           ans=min(ans,max({s1,s2,s3})-min({s1,s2,s3}));
           //printf("s1,s2,s3 = (%lld ,%lld %lld) diff %lld\n",s1,s2,s3,max({s1,s2,s3})-min({s1,s2,s3}));
        }
        for (int i=1;i < h;i++){
           ll s1,s2,s3;
           s1 = (ll)w*i;
           if (w%2== 0){
             s2 = (w/2)*(ll)(h-i);
             s3 = s2;
           }
           else {
             s2 = (w/2)*ll(h-i);
             s3 = ((w+2-1)/2)*ll(h-i);
           }
           ans=min(ans,max({s1,s2,s3})-min({s1,s2,s3}));
           //printf("s1,s2,s3 = (%lld ,%lld %lld)\n diff %lld\n",s1,s2,s3,max({s1,s2,s3})-min({s1,s2,s3}));
           if ((h-i)%2 == 0 ){
             //printf("h-i %d\n",h-i);
             s2 = (ll)w*((h-i)/2);
             s3 = s2;
           }
           else if ((h-i) != 1 ){ 
             s2 = ll(w)*((h-i)/2);
             s3 = ll(w)*((h-i+2-1)/2);
           }
           ans=min(ans,max({s1,s2,s3})-min({s1,s2,s3}));
           //printf("s1,s2,s3 = (%lld ,%lld %lld)\n diff %lld\n",s1,s2,s3,max({s1,s2,s3})-min({s1,s2,s3}));
        }
        cout << ans << endl;
      }
        
        

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
template<class T> inline bool chmin(T& a, T b){
    if(a>b){a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){
    if(a<b){a=b;return true;}return false;}
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    while(true){
        ll H,W;cin>>H>>W;
        if(H+W==0)break;
        rep(i,H){
            rep(j,W){
                if(i==0 or i==H-1 or j==0 or j==W-1)cout<<"#";
                else cout<<".";
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3100
//
//AtCoder Beginner Contest 130
//B - Bounding
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

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

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> l(n);
    REP(i,n) cin >> l[i];
    
    int ans=1;
    int d = 0;
    REP(i,n){
        d+=l[i];
        if (x>=d) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  typedef function<E(E,E)> H;
  typedef function<E(E,int)> P;
  int n;
  F f;
  G g;
  H h;
  P p;
  T d1;
  E d0;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T d1,E d0,
	      vector<T> v=vector<T>(),P p=[](E a,int b){return a;}):
    f(f),g(g),h(h),d1(d1),d0(d0),p(p){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
    laz.clear();
    laz.resize(2*n-1,d0);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(int len,int k){
    if(laz[k]==d0) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=d0;
  }
  T update(int a,int b,E x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(int a,int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return d1;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(int a,int b){
    return query(a,b,0,0,n);
  }
};
//END CUT HERE
signed main(){
  int n,q;
  cin>>n>>q;
  SegmentTree<Int,Int> ch(n,
			  plus<Int>(),
			  plus<Int>(),
			  plus<Int>(),
			  0,0,vector<Int>(n,0),
			  multiplies<Int>());
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>s>>t;
      cout<<ch.query(s-1,t)<<endl;
    }else{
      cin>>s>>t>>x;
      ch.update(s-1,t,x);
    }
  }
}

/*
verified on 2017/12/01
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G
*/

Measured memory_bytes: 8428
#include<iostream>
#include<cstdio>
using namespace std;
#define int long long
int func(int n, int a, int b){
	if(n==0 && a==0) return 1;
	else if (n==0 || a<0) return 0;
	int ans=0;
	for(int i=b;i<10;i++) ans += func(n-1, a-i, i+1);
	return ans;
}
signed main(){
	int a,b;
	while( scanf("%lld %lld", &a, &b) != EOF ){
		if(a==0&&b==0) break;
		cout << func(a,b,0) <<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

string s;
int N;
ll m, a, r, c, h;
ll D[5];
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

int main()
{
  cin >> N;
  for (int i=0; i < N; i++) {
    cin >> s;
    if(s[0] == 'M')m++;
    if(s[0] == 'A')a++;
    if(s[0] == 'R')r++;
    if(s[0] == 'C')c++;
    if(s[0] == 'H')h++;
  }
  D[0] = m, D[1] = a, D[2]=r, D[3]=c, D[4]=h;
  ll res = 0;
  for (int d=0; d < 10; d++) {
    res += D[P[d]]*D[Q[d]]*D[R[d]];
  }

  cout << res << endl;
}


Measured memory_bytes: 256
a=int(input())
List=sorted(list(map(int,input().split())))
ans=10**1000
for i in range(List[0],List[a-1]+1):
    x=0
    for j in range(a):
        x+=(i-List[j])**2
    if ans>x:
        ans=x
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

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

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll N,goukei=0;
    int K;
    cin >> N >> K;
    vector<int>h(N);

    for(ll i=0;i < N;i++){
        cin >> h.at(i);
    }
    
    sort(h.begin(),h.end());
    reverse(h.begin(),h.end());
    
    for(ll i = 0;i < N;i++){
        if(h.at(i) < K)
            break;
        else
            goukei++;
    }

    cout << goukei << endl;
}

Measured memory_bytes: 3564
N = int(input())
S = [0] * N
T = [0] * N
for i in range(N):
    l = input().split()
    S[i] = l[0]
    T[i] = int(l[1])
X = input()
# print(N, S, T, X)

ans = 0
awake = True
for i in range(N):
    if not awake:
        ans += T[i]
    if S[i] == X:
        awake = False
print(ans)


Measured memory_bytes: 38608
#include "bits/stdc++.h"

using namespace std;

//// Original version
//int dfs(int curr, const vector<vector<int> >& c, bitset<10> passed) {
//    passed.set(curr);
//    int ret = c[curr][1];
//    for (int i = 0; i < 10; ++i) {
//        if (!passed[i] && i != curr && i != 1) {
//            ret = min(ret, dfs(i, c, passed) + c[curr][i]);
//        }
//    }
//    return ret;
//}
//
//void Main() {
//    int H, W;
//    cin >> H >> W;
//    vector<vector<int> > c(10, vector<int>(10, 0));
//    for (int i = 0; i < 10; ++i) {
//        for (int j = 0; j < 10; ++j) {
//            cin >> c[i][j];
//        }
//    }
//    map<int, int> A;
//    for (int i = 0; i < H; ++i) {
//        for (int j = 0; j < W; ++j) {
//            int a;
//            cin >> a;
//            if (a >= 0) {
//                if (A.count(a) == 0) {
//                    A.insert(make_pair(a, 0));
//                }
//                ++A[a];
//            }
//        }
//    }
//
//    vector<int> power(10, 0);
//    power[1] = 0;
//    for (int i = 0; i <= 9; ++i) {
//        bitset<10> passed(0);
//        power[i] = dfs(i, c, passed);
//    }
//
//    int ans = 0;
//    for (auto e : A) {
//        ans += power[e.first] * e.second;
//    }
//    cout << ans << endl;
//}

// Warshall-Floyd version
void Main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int> > c(10, vector<int>(10, 0));
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> c[i][j];
        }
    }

    for (int k = 0; k < 10; ++k) {
        for (int i = 0; i < 10; ++i) {
            for (int j = 0; j < 10; ++j) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < H * W; ++i) {
        int a;
        cin >> a;
        if (a >= 0) {
            ans += c[a][1];
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

using namespace std;

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

int main() {
    int A, B;
    cin >> A >> B;

    if (A >= 13) {
        cout << B << endl;
    } else if (A >= 6) {
        cout << B / 2 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) {
		int  ans = 0;
		String s = scan.next();
		for(int i = 0; i < 4; i++) {
			if(s.charAt(i) == '+') {
				ans++;
			} else {
				ans--;
			}
		}
		System.out.println(ans);
	}

}


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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m, R;
    cin >> n >> m >> R;
    vector<int> r(R);
    vector<vector<int> > g(n, vector<int>(n, Inf));
    rep (i, n) g[i][i] = 0;
    rep (i, R) {
        cin >> r[i];
        r[i]--;
    }
    rep (i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        g[a][b] = g[b][a] = c;
    }
    rep (k, n) {
        rep (i, n) {
            rep (j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
        }
    }
    int res = Inf;
    sort(r.begin(), r.end());
    do {
        int tmp = 0;
        rep (i, R - 1) tmp += g[r[i]][r[i + 1]];
        res = min(res, tmp);
    } while (next_permutation(r.begin(), r.end()));
    cout << res << endl;
    
    return 0;
}



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

int main() {
    string s; cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}


Measured memory_bytes: 3508
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<string>
#include<cmath>
#define MAXN 10005
using namespace std;
int num[10];
int numl[10],numr[10];
bool charge[10];
int main()
{
   int n;
     scanf("%d",&n);
   while(n--){
    for(int i=0;i<10;i++)
    {
      scanf("%d",&num[i]);
      charge[i]=false;
    }
    int left=num[0],right=0,count1=1;
     charge[0]=true;
    for(int j=1;j<10;j++)
    {
       if(!charge[j]&&num[j]>left)
        {
         left=num[j];
         count1++;
         charge[j]=true;
        }
    }
     for(int j=0;j<10;j++)
    {
       if(!charge[j]&&num[j]>right)
        {
         right=num[j];
         count1++;
         charge[j]=true;
        }
    }
    if(count1!=10) printf("NO\n");
    else printf("YES\n");
   }
    return 0;
}

Measured memory_bytes: 3040
def p_f():
    from itertools import product
    L, R = map(int, input().split())
    mod = 10 ** 9 + 7
    # dp[i][j][k][l]: iは桁, jはL<=xか, kはy<=Rか, lは桁数が同じか
    dp = [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(61)]
    dp[60][0][0][0] = 1
    for i in reversed(range(60)):
        # LとRのiビット目を取り出す
        lb = L >> i & 1
        rb = R >> i & 1
        for j, k, l in product(range(2), repeat=3):
            # 前の状態
            pre = dp[i + 1][j][k][l]
            for x, y in product(range(2), repeat=2):
                nj, nk, nl = j, k, l
                if x and (not y):  # xが1でyが0
                    continue
                if (not l) and x != y:
                    continue
                if x and y:
                    nl = 1
                # j: L <= x
                if (not j) and (not x) and lb:
                    continue
                if x and (not lb):
                    nj = 1
                # k: y <= R
                if (not k) and y and (not rb):
                    continue
                if (not y) and rb:
                    nk = 1
                dp[i][nj][nk][nl] += pre

    ans = 0
    for j, k, l in product(range(2), repeat=3):
        ans += dp[0][j][k][l]
        ans %= mod
    print(ans)


if __name__ == '__main__':
    p_f()


Measured memory_bytes: 39792
#include <iostream>
#include <string>

using namespace std;

int main(void) {

  int num = 0;
  int N;
  string S;
  string alphabet = "abcdefghijklmnopqrstuvwxyz";

  cin >> N;
  cin >> S;

  for (int i = 0; i < N; ++i) {
    int tmp = 0;
    string S1 = S.substr(0, i);
    string S2 = S.substr(i, N - i);

    // cout << S1 << endl;
    // cout << S2 << endl;

    for (auto it = alphabet.cbegin(); it != alphabet.cend(); ++it) {
      if (S1.find(*it) != string::npos && S2.find(*it) != string::npos) tmp += 1;
    }
    
    num = max(tmp, num);
  }

  cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 256