akhauriyash/Code-Regression huggingface dataset:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

A, B = list(map(int, sys.stdin.readline().split()))
if A < 10 and B < 10:
    print(A * B)
else:
    print(-1)


Measured memory_bytes: 13664
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		int H,W;
		Scanner sc = new Scanner(System.in);
		H = sc.nextInt();
		W = sc.nextInt();
		long c[][] = new long[10][10];
		for (int i=0;i<10;i++) {
			for (int j=0;j<10;j++) {
				c[i][j] = sc.nextLong();
			}
		}
		for (int i=0;i<10;i++) {
			for (int j=0;j<10;j++) {
				for (int k=0;k<10;k++) {
					if (c[j][k]>c[j][i]+c[i][k]) {
						c[j][k]=c[j][i]+c[i][k];
					}
				}
			}
		}
		long result=0;
		for (int i=0;i<H;i++) {
			for (int j=0;j<W;j++) {
				int s= sc.nextInt();
				if (s>-1) {
					result +=c[s][1];
				}
			}
		}
		System.out.println(result);
	}
}

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

#define f(i, q) for(int i = 0; i < q; i++)  

typedef long long ll;

int comp(const void* a, const void* b){
    ll x = *(ll*)a;
    ll y = *(ll*)b;

    return x - y;
}

int main() {
    ll a, b;
    ll ans = 0;
    ll in[1001];
    scanf("%lld %lld", &a, &b);
    for(int i = 0; i < a; i++) {
        scanf("%lld", &in[i]);
    }

    qsort(in, a, sizeof(ll), comp);

    for(int i = 0; i < b; i++) {
        ans += in[i];
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1720
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin>>n;
     
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i]; //n?????\???
     
    for(int i=0;i<n;i++){

        for(int j=i;j>0;j--){
            if(a[j-1]>a[j]) swap(a[j-1],a[j]);
        }
      
        for(int j=0;j<n-1;j++) cout<<a[j]<<" ";
        cout<<a[n-1]<<endl;
    }
     
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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

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

//a=97,z=122

int main(){
    string S;
    cin>>S;
    int last=S.length()-1,countC=0,Cnum;
    for(int i=2;i<last;i++){
        if(S[i]=='C')countC++,Cnum=i;
    }
    rep(i,last+1){
        if(i!=0&&i!=Cnum){
            if(int(S[i])<97){
                cout<<"WA"<<endl;
                return 0;
            }
        }
    }
    if(S[0]=='A'&&countC==1){
        cout<<"AC"<<endl;
    }else{
        cout<<"WA"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,a[100001],x,ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x>n) 
            ans++;
        else a[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0) 
            continue;
        if(a[i]<i) 
            ans+=a[i];
        else if(a[i]>i) 
            ans+=a[i]-i;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pie acos(-1)
#define loop(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x) for(auto &a:x)
#define vi vector<int>
#define vl vector<ll>
#define pii pair<ll,ll>
#define endl "\n"
#define w 3005
ll dp[w][w];
vl a(w);
int n;
ll fun(int l ,int r )
{
    ll &memo=dp[l][r];
    if(memo!=-1)
    return memo;
    if(l>r)
    return 0;
    if((r-l)%2==(n-1)%2)
    return memo=max(a[l]+fun(l+1,r),a[r]+fun(l,r-1));
    else
    return memo=min(-a[l]+fun(l+1,r),-a[r]+fun(l,r-1));
}
void solve()
{
    
    cin>>n;
    
    loop(i,0,n)
    cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<fun(0,n-1);
}
int main() {
	// your code goes here
	io;
	
    solve();
	return 0;
}


Measured memory_bytes: 71040
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debug_() cerr << "AAAAA" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int n, c;
    cin >> n >> c;
    vector<vector<int>> a(c, vector<int>(c));
    for (int i = 0; i < c; i++)
    {
        for (int j = 0; j < c; j++)
        {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> b(n, vector<int>(n));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> b[i][j];
            b[i][j] -= 1;
        }
    }
    vector<vector<ll>> SUM(3, vector<ll>(c, 0));
    for (int i = 0; i < c; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (int k = 0; k < n; k++)
            {
                SUM[(j + k) % 3][i] += a[b[j][k]][i];
            }
        }
    }
    // debug_();

    ll ans = 1001001001001001;
    for (int p = 0; p < c; p++)
    {
        for (int q = 0; q < c; q++)
        {
            if (p == q)
                continue;
            for (int r = 0; r < c; r++)
            {
                if (r == p || r == q)
                    continue;
                ll tmp = SUM[0][p] + SUM[1][q] + SUM[2][r];
                ans = min(ans, tmp);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1280
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

//	for priority queue
//	priority_queue<ipair, vector<ipair>, greater<ipair>>
using ipair = pair<int, pair<int, int>>;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; };
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };

int main()
{
	int a, b;
	cin >> a >> b;

	printf("%d", a*b);
	return 0;
}


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

int main() {
    string S;
    cin >> S;
    auto itr = S.end();
    itr--;
    if(*itr != 's')
        S += 's';
    else
        S += "es";

    cout << S << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define V_MAX 10000
#define E_MAX 100000

#define NIL -1

// Union Find Tree (begin)
int Node[V_MAX];

void init(){
    for(int i = 0; i < V_MAX; i++){
        Node[i] = NIL;
    }
}

int findSet(int x){
    vector<int> V;
    int index = x;
    while(Node[index] != NIL){
        V.push_back(index);
        index = Node[index];
    }
    for(int i = 0; i < V.size(); i++){
        Node[V[i]] = index;
    }
    return index;
}

void unite(int x, int y){
    int root_x = findSet(x);
    int root_y = findSet(y);
    if(root_x != root_y){
        Node[root_x] = root_y;
    }
}

bool same(int x, int y){
    if(findSet(x) == findSet(y)){
        return true;
    }else{
        return false;
    }
}

// Union Find Tree (end)

typedef struct Edge{
    int v1;
    int v2;
    int w;
}Edge;

vector<Edge> Es;

bool edgeSort(Edge a, Edge b){
    return a.w < b.w;
}

int main(void){
    init();

    int V, E;
    scanf("%d %d", &V, &E);

    for(int i = 0; i < E; i++){
        Edge e;
        scanf("%d %d %d", &e.v1, &e.v2, &e.w);
        Es.push_back(e);
    }

    sort(Es.begin(), Es.end(), edgeSort);

    int sum = 0;
    for(int i = 0; i < E; i++){
        if(!same(Es[i].v1, Es[i].v2)){
            sum += Es[i].w;
            unite(Es[i].v1, Es[i].v2);
        }
    }

    printf("%d\n", sum);
}



Measured memory_bytes: 4612
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for(int i=0;i<h;i++)
    cin>>s.at(i);
  int m=0;
  vector<int> my={-1,1,0,0};
  vector<int> mx={0,0,-1,1};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s.at(i).at(j)=='#')
        continue;
      vector<vector<int>> l(h,vector<int>(w,h*w));
      queue<vector<int>> q;
      int ml=0;
      l[i][j]=0;
      q.push({i,j,0});
      while(!q.empty()){
        auto a=q.front();
        q.pop();
        int ay=a.at(0);
        int ax=a.at(1);
        int al=a.at(2);
        for(int p=0;p<4;p++){
          int by=min(max(ay+my.at(p),0),h-1);
          int bx=min(max(ax+mx.at(p),0),w-1);
          if(s.at(by).at(bx)=='.'&&l.at(by).at(bx)>al+1){
            l.at(by).at(bx)=al+1;
            q.push({by,bx,al+1});
            ml=max(ml,al+1);
          }
        }
      }
      m=max(m,ml);
    }
  }
  cout<<m<<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}


ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
  int n;
  cin>>n;
  double ans =(n+1)/2;
  ans= ans /(double)n; 
  printf("%.10lf\n",  ans  );
  
}




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

    #define all(v) v.begin(),v.end()
    #define rall(v) v.rbegin(),v.rend()
    #define trav(i,a) for(auto i: a)
    #define ff first
    #define ss second
    #define eb emplace_back
    #define tc(t) ll t; cin>>t; while(t--)
    #define prec(n) fixed<<setprecission(n)
    #define mst(arr,value) memset(arr,value,sizeof(arr))
    #define mod %MOD
    #define sz(a) a.size()
    
    const long long inf = (long long)1e18;
    const long long MOD = (long long)1e9+7;
    
    #define f(i,n)     for(ll i=0;   i<n;  i++)
    #define fab(i,a,b) for(ll i=a;   i<b;  i++)
    #define fr(i,n)    for(ll i=n-1; i>=0; i--)
    #define fba(i,b,a) for(ll i=b-1; i>=a; i--)

    ll bpw(ll a, ll b) {
        if(b == 0) return 1;
        if(b % 2 == 1) {
            return bpw(a, b - 1) * a mod;
        } else {
            ll b2 = bpw(a, b / 2) mod;
            return b2 * b2 mod;
        }
    }
    ll ncr(ll n, ll r) { 
        ll p = 1, k = 1, m; 
        if (n - r < r) 
            r = n - r; 
        if (r != 0) { 
            while (r) { 
                p *= n; 
                k *= r; 
                m = __gcd(p, k); 
                p /= m; 
                k /= m; 
                n--; 
                r--; 
            } 
        } 
        else
            p = 1;  
        return p; 
    } 

    int main() {
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        cout.tie(NULL);
        ll n, h = 0;
        cin >> n;
        if(n >= 500) {
            h = (n / 500) * 1000;
            n = n - (n / 500) * 500;
        }
        if(n >= 5) {
            h += (n / 5) * 5;
        }
        cout << h;
        return 0;
    }

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 5005;
const int MAXM = 205;
int a[MAXN][MAXM], suf[MAXN][MAXM], c[MAXM];
int n, m, i, j, k, LG[MAXN];
long long tot, ans, d[MAXN];
inline int get()
{
	char c;
	while ((c = getchar()) < 48 || c > 57);
	int res = c - 48;
	while ((c = getchar()) >= 48 && c <= 57)
	res = res * 10 + c - 48;
	return res;
}
int main()
{
	LG[0] = -1;
	for(i = 1; i <= 5000; i ++)
		LG[i] = LG[i >> 1] + 1;
	cin >> n >> m;
	for(i = 2; i <= n; i ++)
		d[i] = get(), d[i] += d[i - 1];
	for(i = 1; i <= n; i ++)
		for(j = 1; j <= m; j ++)
			a[i][j] = get();
	for(i = 1; i <= n; i ++)
	{
		for(j = 1; j <= m; j ++)
			c[j] = 0;
		tot = 0;
		for(j = i; j <= n; j ++)
		{
			for(k = 1; k <= m; k ++)
				if (a[j][k] > c[k]) tot += a[j][k] - c[k], c[k] = a[j][k];
			ans = max(ans, tot - (d[j] - d[i]));
			int tt = 0;
			for(k = 1; k <= m; k ++)
				if (a[i][k] < c[k]) tt ++;
			if (tt == m) break;
		}
	}
	cout << ans << endl;
}

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


/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/

/// Typedef
typedef long long           ll;
typedef unsigned long       ul;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef vector<vi>          vvi;
typedef vector<ll>          vll;
typedef pair<int,int>       pii;
typedef pair<ll,ll>         pll;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define loop(i, y)          for(int i=0; i<int(y); i++)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x); i>=int(y); i--)
#define all(c)              c.begin(), c.end()
#define sz(c)               int(c.size())
#define clr(x, y)           memset(x, y, sizeof(x))
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)
#define slll(x, y, z)       scanf("%lld %lld %lld", &x, &y, &z)
#define MAX                 300005
#define MOD                 1000000009
#define base                1000000007
#define eps                 1e-9
#define INF                 1llu<<61    // 2,305,843,009,213,693,952
#define inf                 1<<29       // 536,870,912
#define PI                  acos(-1.0)  // 3.1415926535897932
// #define INF              0x3f3f3f3f3f3f3f3f
// #define inf              0x3f3f3f3f


int main(){
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int a,p;
    sii(a,p);
    cout<<((a*3)+p)/2<<endl;
    #ifdef VAMP
       printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif

    return 0;
}

Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

N, M = MI()

ans = N * (N - 1) // 2
ans += M * (M - 1) // 2
print(ans)

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N;
    cin >> N;
    vector<pair<ll, ll>> arms;
    Rep (i, N) {
        ll X, L;
        cin >> X >> L;
        arms.push_back({X+L, X-L});
    }

    sort(arms.begin(), arms.end());

    ll ans = 0, now = -2e9;
    Rep (i, N) {
        if (arms[i].second >= now) {
            ans++;
            now = arms[i].first;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

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

//--------------------------

const double PI=3.141592653589;

int main() {

  double r;
  cin >> r;

  cout << 2*r*PI << endl;

  return 0;
}


Measured memory_bytes: 3788
def round_robin(queue_list, t):
    elapsed_time = 0
    while len(queue_list) > 0:
        p, c = queue_list.pop(0)
        if c-t > 0:
            elapsed_time += t
            queue_list.append([p, c-t])
        else:
            elapsed_time += c
            print("{} {}".format(p,elapsed_time))

N, cpu_time = map(int,input().split())
queue_list = []
for i in range(N):
    process,cost = input().split()
    queue_list.append([process, int(cost)])

round_robin(queue_list, cpu_time)


Measured memory_bytes: 12880
S = gets.chomp.chars

nums = Array.new(S.size + 1, -1)

chain = 0

S.each_with_index do |s, idx|
  if s == '<'
    nums[idx] = chain
    nums[idx + 1] = chain + 1
    chain += 1
  else
    chain = 0
  end
end

# p nums
N = S.size
chain = 0

S.reverse.each_with_index do |s, idx|
  if s == '>'
    nums[N - idx] = chain
    nums[N - idx - 1] = [nums[N - idx - 1],  chain + 1].max
    chain += 1
  else
    if S[N - idx - 1] == '>' && nums[N - idx - 1] >= chain
      # nums[N - idx] = chain + 1
    end

    chain = 0
  end
end

# p nums
puts nums.inject(:+)


Measured memory_bytes: 53644
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

vector<ll> num(51),pa(51);

ll cnt(ll n, ll x){
    if(n == 0) return 1;
    else if(x == 1) return 0;
    else if(1 < x && x <= num[n-1]+1) return cnt(n-1,x-1);
    else if(x == num[n-1]+2) return pa[n-1]+1;
    else if(num[n-1]+2 < x && num[n-1]*2+2) return pa[n-1]+1+cnt(n-1,x-2-num[n-1]);
    else return pa[n-1]*2+1;
}

int main(){
    ll n,x; cin >> n >> x;
    num[0] = 1; pa[0] = 1;
    for(int i = 1; i < 51; i++) num[i] = num[i-1] * 2 + 3;
    for(int i = 1; i < 51; i++) pa[i] = pa[i-1] * 2 + 1;
    cout << cnt(n,x) << endl;
    return 0;
}


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

int main(){
    //1llでやれば小さい整数をllにできる
    ll n,wl,ans = 0;
    
    cin >> n >> wl;
    //i番目 まで に重さの合計がx以下となるように選んだ時の、今までの価値の最大値
    ll dp[n+1][wl+1];
    for(int i=0;i < wl+1;i++)
    {
        dp[0][i]=0;
    }

    vector<ll> w(n),v(n);
    
    for(ll i=0ll;i<n;i++)
    {
        cin >> w.at(i) >> v.at(i);
    }//input
    
    for(ll i=0ll;i <= n;i++)//ひとつずつ決めてく
    {
        for(ll x=0ll;x <= wl;x++)
        {
            if(i==0){
                dp[i][x]=0;
                break;
            }
            
            if(x-w.at(i-1)>=0){
                dp[i][x] = max(dp[i-1][x-w.at(i-1)]+v.at(i-1),dp[i-1][x]);
            }//入るなら入れる
            else{
            dp[i][x]=dp[i-1][x];//入れない
            }
            //dp[i][x]は一度しか調べられないのでmaxでdp[i][x]と比べなくてよい
        }
    }
    cout << dp[n][wl] << endl;
}

Measured memory_bytes: 79104
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        while(true){
            //データ受取
            String line = sc.nextLine();

            //終了条件
            if(line.equals("0"))    break;

            int number;
            int sum = 0;

            //一文字ずつ処理
            for(int i = 0;i < line.length();i++){
                number = Character.getNumericValue(line.charAt(i));
                sum += number;
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 26648
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    A = read_ints()
    maximum = 10**18
    if 0 in A:
        return 0
    ans = 1
    for a in A:
        ans *= a
        if ans > maximum:
            return -1
    return ans


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 83644
#include <iostream>

using namespace std;

//int a,b,c;

int main()
{
    int x[3];
    cin >> x[0] >> x[1] >> x[2];
    
    int work;
    for(int i=2;i>0;--i){
        for(int k=0;k<i;++k){
            if(x[k] > x[k+1]){
                work = x[k];
                x[k] = x[k+1];
                x[k+1] = work;
            }
        }
    }
    
    cout << x[0] << " " << x[1] <<" "<<x[2] << endl;
    
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep2(i,start,end) for(ll i = start; i < end; ++i)
#define dwn(i,n) for(int i = n; i >= 0; --i)
#define dwn2(i,start,end) for(ll i = start; i >= end; --i)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f;
const ll mode = 1e9 + 7;


int main(){
	int m,d;
	cin>>m>>d;
	ll sum = 0;
	rep2(j,1,m+1){
		for(int i = 1; i <= d; i++){
			int x = i /10;
			int y = i%10;
			if(x >= 2 && y >= 2 && x*y == j) sum++;
			}
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 12
#define M 1000
#define MAX_A 10000

#define DP_ROW M
#define DP_COL 4096
#define DP_INF (MAX_A * N + 1)

int min(int x, int y) {
    if (x < y) {
        return x;
    } else {
        return y;
    }
}

static unsigned int n, m;
static int as[M];
static unsigned short cs[M]; // if cs[i] has 0x0001, key i can open box 1
static int dp[DP_ROW][DP_COL]; // dp[M][2 ** N]

// assume that row > 0 && col > 0
void print_dp(int row, int col) {
    for (int i = 0; i < row; i++) {
        printf("%010d", dp[i][0]);
        for (int j = 1; j < col; j++) {
            printf(" %010d", dp[i][j]);
        }
        printf("\n");
    }
}

void solve() {
    for (unsigned int i = 0; i < m; i++) {
        unsigned int bits = cs[i];
        for (unsigned int j = 1; j < ((unsigned int) (1 << n)); j++) {
            if (i > 0) {
                dp[i][j] = min(dp[i][j], dp[i-1][j]);
            }
            if (j & bits) {
                if (dp[i][j & (~bits)] + as[i] < dp[i][j]) {
                    dp[i][j] = dp[i][j & (~bits)] + as[i];
                }
            }
        }
    }
}

int main(void) {
    scanf("%d %d", &n, &m);

    // setup prices and cs
    for (unsigned int i = 0; i < m; i++) {
        int l;
        scanf("%d %d", &as[i], &l);
        cs[i] = 0;
        for (int j = 0; j < l; j++) {
            int x;
            scanf("%d", &x);
            cs[i] |= 1 << (x-1);
        }
    }

    // setup dp
    for (int i = 0; i < DP_ROW; i++) {
        dp[i][0] = 0;
        for (int j = 1; j < DP_COL; j++) {
            dp[i][j] = DP_INF;
        }
    }

    solve();
    // print_dp(m, 1 << n);
    // printf("\n");
    printf("%d\n", dp[m-1][(1 << n) - 1] == DP_INF ? -1 : dp[m-1][(1 << n) - 1]);

    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> a[i];
    a[i]--;
  }

  int now = 0;
  for(int i = 0; i < n; ++i)
  {
    now = a[now];
    if(now == 1)
    {
      cout << i + 1;
      return;
    }
  }
  cout << -1;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3916
#include<iostream>
using namespace std;
int main(){
	int a,a1=0,a2=0,a3=0,h;
	for(int i=0;i<10;i++){
		cin >> a ;
		if(a>=a1){a3=a2;a2=a1;a1=a;}
		else if(a>=a2){a3=a2;a2=a;}
		else if(a>=a3){a3=a;}
	}
	h=a1+a2+a3;
	a1=0,a2=0,a3=0,h;
	for(int i=0;i<10;i++){
		cin >> a ;
		if(a>=a1){a3=a2;a2=a1;a1=a;}
		else if(a>=a2){a3=a2;a2=a;}
		else if(a>=a3){a3=a;}
	}
	cout << h << " " << a1+a2+a3 << endl;

	return 0;
}

Measured memory_bytes: 1164
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        long l = lcm(n, m);

        Map<Long, String> sMap = new HashMap<>();
        Map<Long, String> tMap = new HashMap<>();
        for (int i = 0 ; i < n ; i++) {
            sMap.put((long) i * l / n, s.substring(i, i + 1));
        }

        for (int i = 0 ; i < m ; i++) {
            tMap.put((long) i * l / m , t.substring(i, i + 1));
        }

        for (Entry<Long, String> entry : sMap.entrySet()) {
            long num = entry.getKey();
            String ch = entry.getValue();
            if (tMap.containsKey(num)) {
                if (!ch.equals(tMap.get(num))) {
                    l = -1l;
                }
            }

        }

        System.out.println(l);

    }
    static int gcd(int m , int n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    static long lcm(int n , int m) {
        return  (long) n * m / gcd(n, m);
    }

}

Measured memory_bytes: 57020
n = int(input())
A = [int(input()) for _ in range(n)]
f_num = max(A)
A_c = A.copy()
A_c.remove(f_num)
s_num = max(A_c)

for a in A:
    if a == f_num:
        print(s_num)
    else:
        print(f_num)

Measured memory_bytes: 86472
#include <iostream>
using namespace std;
int main(){
  int n,m;//n:カード枚数 m:ゲート数
  cin>>n>>m;
  int s,e,start,end=n,count=0;
  while(count!=m){
    cin>>s>>e;
    if(count==0||s>start)start=s;
    if(e<end)end=e;
    if(end<start){
      end=0;
      start=1;
      break;
    }
    count++;
  }
  cout<<end-start+1;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

// static variable slows down the program!!
//static int swap_cnt=0;

/*
int swap(int *a, int *b){
    int buf=*a;
    *a=*b;
    *b=buf;
    return 1;
}
*/

int bubbleSort(int a[], int n){

    bool flag=true;
    int i=0;    // i is # of elems already in right position

    int sw=0;

    while(flag){
        flag=false;
        for(int j=n-1;j>=i+1;j--){    // start from last index, j is immigrant cadidate, from init(n-1) to limit(i+1) represents max # of swap needed.   
            if(a[j-1]>a[j]){
                swap(a[j-1],a[j]);
                sw++;
                flag=true;
            }
        }
    }

    i++;

    return sw;
}

// insertion sortと違い, 後ろから一個ずつ交換.

int main(){

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

    int sw=bubbleSort(a,n);

    //for(int x:a)cout<<x<<" "; // slows down the program!!
    for(int i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<a[i];
    }
    
    cout<<endl;
    cout<<sw<<endl;


    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n;
    cin >> n;
    string w[n];
    rep(i, n)cin >> w[i];
    rep(i, n - 1){
        nfor(j, i + 1, n){
            if (w[i] == w[j]) {
                No;
                return 0;
            }
        }
    }
    rep(i, n - 1){
        if (w[i][w[i].size() - 1] != w[i + 1][0]) {
            No;
            return 0;
        }
    }
    Yes;
    return 0;
}


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

int main()
{
	int n, k, tot = 0;
	cin >> n >> k;
	for(int i=1;i<=n;i++)
	{
		int tmp;
		cin >> tmp;
		if (tmp >= k)
			tot++;
	}
	cout << tot;

	return 0;
}

Measured memory_bytes: 256
def inputs(): return [int(x) for x in input().split()]
import math
a,b,h,m=inputs()
sita1 = m/2+30*h
sita2 = 6*m
sita = min(abs(sita1-sita2),360-abs(sita1-sita2))
ans =(a**2+b**2-2*a*b*math.cos(sita/180*math.pi))**0.5
print(ans)

Measured memory_bytes: 9508
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
#define _name3(_1,_2,_3,name,...) name
#define _rep1(n) for(ll i=0;i<(n);++i)
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _name3(__VA_ARGS__,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define rrep(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define each(i,a) for(auto &i:a)
#define sum(a) accumulate(range(a),0LL)
#define range(i) (i).begin(),(i).end()
template<class T> inline constexpr bool chmin(T &a,const T &b){ if(a>b){ a=b; return 1; } else return 0; }
template<class T> inline constexpr bool chmax(T &a,const T &b){ if(a<b){ a=b; return 1; } else return 0; }

int main(){
    ll m,n;
    cin>>m>>n;
    vector<pll>a(m);
    each(i, a)cin>>i.first>>i.second;
    vector<pll>b(n);
    each(i, b)cin>>i.first>>i.second;
    ll book[n][m+1]={};
    rep(n){
        ll C=b[i].first,B=b[i].second;
        ll width=0,weight=0,at=0;
        rep(j,m){
            while(at<m&&weight+a[at].first<=C&&width+a[at].second<=B){
                weight+=a[at].first;
                width+=a[at].second;
                at++;
            }
            book[i][j]=at-j;
            weight-=a[j].first;
            width-=a[j].second;
        }
    }
    ll dp[1<<n]={};
    rep(1<<n){
        rep(j,n)if((i>>j)&1^1){
            chmax(dp[i|(1<<j)],dp[i]+book[j][dp[i]]);
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
}



Measured memory_bytes: 29668
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

n,m = map(int, input().split())
#x = []
#for i in range(n):
#    x.append(input().split())
x = [[int(i) for i in input().split()] for i in range(n)] 
p1=[]
p2=[]
p3=[]
p4=[]
p5=[]
p6=[]
p7=[]
p8=[]

for i in range(n):
    p1.append( x[i][0]+x[i][1]+x[i][2])
    p2.append( x[i][0]+x[i][1]-x[i][2])
    p3.append( x[i][0]-x[i][1]+x[i][2])
    p4.append( x[i][0]-x[i][1]-x[i][2])
    p5.append(-x[i][0]+x[i][1]+x[i][2])
    p6.append(-x[i][0]+x[i][1]-x[i][2])
    p7.append(-x[i][0]-x[i][1]+x[i][2])
    p8.append(-x[i][0]-x[i][1]-x[i][2])
p1.sort()
p2.sort()
p3.sort()
p4.sort()
p5.sort()
p6.sort()
p7.sort()
p8.sort()
q = [0,0,0,0,0,0,0,0]
for i in range(m):
    q[0] += p1[i]
    q[1] += p2[i]
    q[2] += p3[i]
    q[3] += p4[i]
    q[4] += p5[i]
    q[5] += p6[i]
    q[6] += p7[i]
    q[7] += p8[i]
for i in range(8):
    q[i] = abs(q[i])
#print(q)   
print(max(q))


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

int main() {
  int h, w;
  cin >> h >> w;
  int c = 0;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == '#') {
        c++;
      }
    }
  }
  cout << (c == h + w - 1 ? "Possible" : "Impossible") << endl;
}


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

int main() {
  bool s[14] = {false};
  bool h[14] = {false};
  bool c[14] = {false};
  bool d[14] = {false};

  int n;
  cin >> n;

  char a;
  int t;
  rep(i,n) {
    cin >> a >> t;
    switch(a) {
      case 'S':
        s[t] = true;
        break;
      case 'H':
        h[t] = true;
        break;
      case 'C':
        c[t] = true;
        break;
      case 'D':
        d[t] = true;
        break;
    }
  }

  rep(i,14) {
    if (i == 0) continue;
    if (s[i] == false) cout << "S " << i << endl;
  }
  rep(i,14) {
    if (i == 0) continue;
    if (h[i] == false) cout << "H " << i << endl;
  }
  rep(i,14) {
    if (i == 0) continue;
    if (c[i] == false) cout << "C " << i << endl;
  }
  rep(i,14) {
    if (i == 0) continue;
    if (d[i] == false) cout << "D " << i << endl;
  }

  return 0;
}



Measured memory_bytes: 3100
import itertools
import math

n = int(input())
town = [[int(i)  for i in input().split()] for j in range(n)]

lis =[i for i in range(n)]
permutations_lis = itertools.permutations(lis)

sum = 0

for one_case in permutations_lis:
    for i in range(n-1):
        sum += math.sqrt((town[one_case[i+1]][0] - town[one_case[i]][0]) ** 2 + (town[one_case[i+1]][1] - town[one_case[i]][1]) ** 2)

print(sum / math.factorial(n))


Measured memory_bytes: 3064
#include <iostream>
#include <utility>
using namespace std;
 
#define N 1000000
#define INF 1000000

typedef pair<char, int> Card;
 

// BubbleSort(C, N)
//   for i = 0 to N-1
//     for j = N-1 downto i+1
//       if C[j].value < C[j-1].value
//         C[j] と C[j-1] を交換
void bubSort(Card cards[], int n){
  for (int i=0; i<n; i++){
    for (int j=n-1; j>=i+1; j--){
      if (cards[j].second < cards[j-1].second){
        Card tmp;
        tmp = cards[j]; cards[j]=cards[j-1]; cards[j-1]=tmp;
      }
    }
  }
}
//SelectionSort(C, N)
//  for i = 0 to N-1
//    minj = i
//    for j = i to N-1
//      if C[j].value < C[minj].value
//        minj = j
//    C[i] と C[minj] を交換
void selSort(Card cards[], int n){
  for (int i=0; i<n; i++){
    int mnj = i;
    Card tmp;
    for (int j=i; j<n; j++){
      if (cards[j].second < cards[mnj].second) mnj = j;
    }
    tmp = cards[i]; cards[i]=cards[mnj]; cards[mnj]=tmp;
  }
}

Card readCard(){
  char s;
  int r;
  Card ret;
  cin >> s;
  ret.first = s;
  cin >> r;
  ret.second = r;
  return ret;
}
void printCard(Card c){
  cout << (char)c.first;
  cout << (int)c.second;
}

int main(void){
  int n,isStbl;
  Card cardsBub[40], cardsSel[40], tmpCard;
  
  cin >> n;
  for (int i=0; i<n; i++){
    cardsBub[i] = cardsSel[i] = readCard();
  }
  bubSort(cardsBub, n);
  selSort(cardsSel, n);
  for (int i=0; i<n; i++){
    printCard(cardsBub[i]);
    cout << (i==n-1?"\n":" ");
  }
  cout << "Stable" << endl;
  isStbl = 1;
  for (int i=0; i<n; i++){
    printCard(cardsSel[i]);
    isStbl &= (cardsSel[i]==cardsBub[i]);
    cout << (i==n-1?"\n":" ");
  }
  cout << (isStbl?"Stable":"Not stable") << endl;
  
  return 0;
}


Measured memory_bytes: 3100
n = int(input())
a = list(map(int, input().split()))

goukei = sum(a)
nagasa = goukei
if nagasa%2 == 1:
  nagasa = nagasa//2 + 1
else:
  nagasa = nagasa//2

leftA = 0
leftB = 0
rightA = 0
rightB = 0
for aa in a:
  leftB = leftA
  leftA += aa
  if leftA > nagasa:
    break

rightA = goukei - leftA
rightB = goukei - leftB
print(min(abs(leftA-rightA), abs(leftB-rightB)))

Measured memory_bytes: 26220
n,m,k=map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a = [0]+a
for i in range(1,n+1):
    a[i] += a[i-1]
b = [0]+b
for i in range(1,m+1):
    b[i] += b[i-1]

ans,j = 0,m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k-a[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)


Measured memory_bytes: 112016
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

class UnionFindTree:
    def __init__(self, n):
        self.nodes = list(range(n+1))
    def find(self, x):
        if self.nodes[x] == x:
            return x
        parent = self.find(self.nodes[x])
        self.nodes[x] = parent
        return parent
    def unite(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b:
            return
        self.nodes[a] = self.nodes[b]
    def is_same(self, a, b):
        return self.find(a) == self.find(b)

N,M,K=LI()
UF=UnionFindTree(N)
NUMF = [0]*(N+1)
for i in range(M):
    f,t = LI()
    UF.unite(f,t)
    NUMF[f] += 1
    NUMF[t] += 1

BLL=[]
for j in range(K):
    f, t = LI()
    BLL.append((f,t))
    BLL.append((t,f))
BLL.sort()
GPS = [0]*(N+1)

for i in range(1, N+1):
    UF.find(i)
    GPS[UF.nodes[i]] += 1

ptr = 0
K2 = 2*K
for i in range(1, N+1):
    res = GPS[UF.find(i)] - 1 - NUMF[i]
    while BLL and ptr < K2 and i == BLL[ptr][0]:
        res -= UF.is_same(BLL[ptr][0], BLL[ptr][1])
        ptr += 1
    print(res, end=" ")
print("")

Measured memory_bytes: 40732
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 1e7+5;
const int INF = 1LL<<30;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int d[100009];
vector<int> dc;
vector<PII> bad;
LL ans[100009];

int main(){
	DRI(n);
	REP(i,n)RI(d[i]);
	int cm=0;
	REP(i,n){
		if(d[i]>cm){
			cm=d[i];
			bad.PB(MP(d[i],i));
		}
		dc.PB(d[i]);
	}
	sort(ALL(dc));
	//dc.resize(unique(ALL(dc))-dc.begin());
	int cp=SZ(dc)-1;
	LL cv=0;LL cc=0;
	for(int i=SZ(bad)-1;i>=0;i--){
		//printf("%d %d\n",bad[i].F,bad[i].S);
		int pv=(i?bad[i-1].F:0);
		cv=cc*(bad[i].F-pv);
		while(cp>=0&&dc[cp]>=pv){
			cv+=dc[cp]-pv;cc++;
			cp--;
		}
		ans[bad[i].S]=cv;
	}
	REP(i,n)printf("%lld\n",ans[i]);
}


Measured memory_bytes: 3700
using System;

namespace ABC_054_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            int A = int.Parse(word[0]);
            int B = int.Parse(word[1]);
            if (A == B)
            {
                Console.WriteLine("Draw");
            }
            else if (A == 1 && B != 1)
            {
                Console.WriteLine("Alice");
            }
            else if (A != 1 && B == 1)
            {
                Console.WriteLine("Bob");
            }
            else if (A > B)
            {
                Console.WriteLine("Alice");
            }
            else if (A < B)
            {
                Console.WriteLine("Bob");
            }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 13140
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let line:Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let n = line[0];
    let m = line[1];

    let S: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let T: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut memo = vec![vec![0u64; m+1]; n+1];
    let MOD = 1000_000_007u64;

    memo[n][m] = 1;
    for i in 0..m {
        memo[n][i] = 1;
    }
    for i in 0..n {
        memo[i][m] = 1;
    }
    for i in (0..n).rev() {
        memo[i][m] = memo[i+1][m];
        let mut tmp = 0u64;
        for j in (0..m).rev() {
            if S[i] == T[j] {
                tmp += memo[i+1][j + 1];
                tmp %= MOD;
            }
            memo[i][j] = (memo[i + 1][j] + tmp) % MOD;
            
            /*
            for k in j..m {
                if S[i] == T[k] {
                    memo[i][j] += memo[i+1][k+1];
                    memo[i][j] %= MOD;
                }
            }
            */
        }
    }

    println!("{}", memo[0][0]);
}


Measured memory_bytes: 45308
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
vector<deque<int>> dq[17];
string s;
int f(deque<int> dq2,int n){
    
    if(dq2.size()==1)return dq2[0];
  dq[n].push_back(dq2);
    deque<int> ret;
    for(int i=0;i<dq2.size();i+=2){
        if(s[abs(dq2[i]-dq2[i+1])-1]=='1')ret.push_back(max(dq2[i+1],dq2[i]));
        else ret.push_back(min(dq2[i],dq2[i+1]));
    }
    return f(ret,n+1);
}
int main(){
    int n;cin>>n;
    cin>>s;
    int p[1<<n];
    rep(i,0,1<<n){
        cin>>p[i];
        p[i]--;
    }
    deque<int> d;
    rep(i,0,1<<n)d.push_back(p[i]);
    int now=0;
    int c=2;
    int ans[1<<(n-1)];
    ans[0]=f(d,0)+1;
    int y=d.front();d.pop_front();
    d.push_back(y);
    ans[1]=f(d,0)+1;
    rep(i,2,1<<(n-1)){
        if(i==c){
            dq[now].clear();
            c*=2;
            now++;
        }
        deque<int> nd=dq[now][i-c/2];
      int yy=nd.front();nd.pop_front();
      nd.push_back(yy);
        ans[i]=f(nd,now)+1;
    }
rep(i,0,2){
    rep(j,0,1<<(n-1))cout<<ans[j]<<endl;
    
}
}


Measured memory_bytes: 192712
a, b, c = map(int, input().split())

if a < b :
    if b < c :
        print(a, b, c)
    elif a < c :
        print(a, c, b)
    else :
        print(c, a, b)
elif b < a :
    if a < c :
        print(b, a, c)
    elif b < c :
        print(b, c, a)
    else :
        print(c, b, a)



Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    ve <ll> arr(n);
    map <ll,ll> pre;
    rep (i,0,n)
    {
        cin>>arr[i];
        pre[i]=pre[i-1]+arr[i];
    }
    ll ans=0;
    rep (i,0,n-1)
    {
        ll val=pre[n-1]-pre[i];
        val%=rem;
        val*=arr[i];
        ans+=val;
        ans%=rem;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 17172