akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct BIT{
    vector<ll> bt;
    size_t n,m;
    explicit BIT(size_t n):n(n),m(1){
        while(m<=n) m<<=1u;
        m>>=1u;
        bt.resize(n+1);
    }
    ll sum(ll i){//sum of [1,i](1-index)
        if(!i) return 0;
        ll tmp{};
        for(size_t k=i;k;k-=k&-k) tmp+=bt[k];
        return tmp;
    }
    void ad(ll i,ll x){//add to i(1-index)
        for(size_t k=i;k<=n;k+=k&-k) bt[k]+=x;
    }
    ll lb(ll k){//if sum(i)<k and sum(i) >= k, return i
        ll x=0;
        for(size_t i=m;i>0;i>>=1u){
            if(x+i<=n&&bt[x+i]<k) {
                k-=bt[x+i];
                x+=i;
            }
        }
        return x+1;
    }
};

int n,N;
struct Line{
    double a,b;
};
double solve(vector<Line>&L){
    sort(L.begin(),L.end(),[](const Line&l0,const Line&l1){
        return l0.a<l1.a;
    });
    double l,r,m;
    l=-1e10,r=1e10;
    fr(_,100){
        m=(l+r)/2;
        int s{};
        vector<int> p(n),ip(n);
        iota(p.begin(),p.end(),0);
        sort(p.begin(),p.end(),[&](int i,int j){
            return L[i].a*m+L[i].b<L[j].a*m+L[j].b;
        });
        fr(i,n) ip[p[i]]=i+1;
        BIT b(n);
        fr(i,n){
            s+=b.sum(ip[i]);
            b.ad(ip[i],1);
        }
        if(s>N) r=m;
        else l=m;
    }
    return l;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>n;
    N=(n*(n-1)/2-1)/2;
    double a,b,c;
    vector<Line> LX,LY;
    LX.reserve(n);
    LY.reserve(n);
    fr(i,n){
        cin>>a>>b>>c;
        LX.push_back(Line{-a/b,c/b});
        LY.push_back(Line{-b/a,c/a});
    }
    cout<<fixed<<setprecision(20)<<solve(LX)<<" "<<solve(LY)<<'\n';
}

Measured memory_bytes: 2208
#include <bits/stdc++.h>
using namespace std;
void x(int n){
  if(n==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  exit(0);
}
int main() {
  int a,b,c,d; cin>>a>>b>>c>>d;
  while(1){
    c-=b;
    if(c<=0) x(0);
    a-=d;
    if(a<=0) x(1);
  }
}

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

using namespace std;

typedef pair<int,int> pii;

int n , a[1<<18],ans[1<<18];

void add(pii &ans,int num){
	if(ans.first > ans.second)swap(ans.first,ans.second);
	if(num > ans.first)ans.first = num;
}

int main(){
	cin >> n;
	for (int i = 0; i < (1<<n); ++i)scanf("%d",&a[i]);
	for(int msk = 1; msk < (1 << n);++msk){

		pii tmp = make_pair(a[0],0);
		for(int j = msk ; j > 0; j = (j-1)&msk){
			add(tmp,a[j]);
		}
		ans[msk] = tmp.first+tmp.second;
	}
	for(int i = 1; i < (1<<n);++i)
		ans[i] = max(ans[i],ans[i-1]);

	for(int i = 1; i < (1<<n);++i){
		printf("%d\n", ans[i]);
	}

	return 0;
}



Measured memory_bytes: 5120
#include<cstdio>
#include<vector>
using namespace std;

long n;
vector<int> v;


int main() {
    scanf("%ld", &n);
    while(n > 0) {
        v.emplace_back((n - 1) % 26);
        n = (n - 1) / 26;
    }

    for (int i = v.size() - 1; i >= 0; i--) printf("%c", 'a' + v[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 3184
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rept(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n,int m) {
	int digits = 0;
	while (n != 0) {
		n /= m;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


//入力された文字列が回文か判断してboolを返す
bool is_kaibun(string s) {
	string s_r(s.rbegin(), s.rend());
	return (s == s_r);
}


void yes() {cout << "Yes" << endl;}
void no() {cout << "No" << endl;}


int main() {
	ll a, b, n;
	cin >> n >> a >> b;
	ll ab = a + b;
	ll ans = 0;
	ans += a * (n / ab);
	//cout << ans << endl;

	if (n%ab >=  a)cout << ans + a << endl;
	else cout << ans + (n % ab) << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int N;
  cin >> N;
  ll s = INF, l = -INF;
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    s = min(s, a);
    l = max(l, a);
  }
  cout << l - s << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
int main(){
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    double r;
    double pi=3.14;
    cin>>r;
    double ans=2*r*pi;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3796
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;

int main()
{
	double n,d;
	cin >> n >> d;
	cout << ceil(n/((2*d)+1)) << endl;
}

Measured memory_bytes: 256
a = list(str(input()))
b = list(str(input()))
c = list(str(input()))
n = a.pop(0)
m = 0
while True:
    if n == 'a':
        if len(a) == 0:
            break
        n = a.pop(0)
    elif n == 'b':
        if len(b) == 0:
            break
        n = b.pop(0)
    else:
        if len(c) == 0:
            break
        n = c.pop(0)
print(n.upper())

Measured memory_bytes: 8992
#include <iostream>
#include <ctype.h>
#include <string>

using namespace std;

int main(){

	string data;
	
	getline(cin, data);
	
	for (int i = 0;data[i];i++){

		if (islower(data[i])){
			cout << (char)toupper(data[i]);
		}
		else if (isupper(data[i])){
			cout << (char)tolower(data[i]);
		}
		else{
			cout << data[i];
		}
		
		
	}cout << endl;


	return 0;
}

Measured memory_bytes: 1176
/*
 © 2020-09-19 07:38:49 Franco1010 All Rights Reserved
*/

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;
const lli MOD = 998244353;
struct segtree{
  #define mid (l + r)/2
  #define left(u) (u + 1)
  #define right(u) (u + ((mid - l + 1) << 1))
  struct node{
    lli s;
    node(lli s = 0): s(s) {}
    node operator + (const node & n){
      return node((s + n.s) % MOD);
    }
  };
  vector<node> st;
  int n;
  segtree(int n): n(n), st(2 * n) {}
  void update(int u, int l, int r, int kth, int val){
    if(l == r){
      st[u].s = (st[u].s + val) % MOD;
      return;
    }
    if(kth <= mid) update(left(u), l, mid, kth, val);
    else update(right(u), mid + 1, r, kth, val);
    st[u] = st[left(u)] + st[right(u)];
  }
  lli query(int u, int l, int r, int ll, int rr){
    if(l > r or r < ll or l > rr) return 0;
    if(ll <= l and r <= rr) return st[u].s % MOD;
    return (query(left(u), l, mid, ll, rr) + query(right(u), mid + 1, r, ll, rr)) % MOD;
  }
  lli qq(int l, int r){
    return query(0, 1, n, max(l, 1), min(r, n));
  }
};
int main(){ _
  lli n, k; cin >> n >> k;
  vector<ii> v;
  fore(i, 0, k){
    lli l, r ;cin >> l >> r;
    v.pb({l, r});
  }
  segtree st(n);
  st.update(0, 1, n, 1, 1);
  fore(i, 1, n + 1){
    for(auto j : v){
      st.update(0, 1, n, i, st.qq(i - j.s, i - j.f));
    }
  }
  cout << st.qq(n, n) << ENDL;
  return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    double a = (double) n / 3;
    cout << fixed << setprecision(15) << a*a*a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int n;
    string s;

    cin >> n >> s;

    int result = 0;
    rep(i, n - 2)
    {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
            result++;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
import sys
N = int(input())
lst = [str(input()) for _ in range(N)]
#print(lst)
c = Counter(lst)
for i in c:
    if lst.count(i) > 1:
        print('No')
        sys.exit()

for i in range(len(lst)-1):
    if lst[i][-1] != lst[i+1][0]:
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 9332
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

vector<vector<pair<int,int>>> g(100000);
vector<int> dist(100000,-1);
vector<bool> visited(100000,false);


bool bfs(int i, int d){
  if(visited[i] && d != dist[i]) return false; //到達済み。かつ重みづけが矛盾していたらfalse
  if(visited[i] && d == dist[i]) return true; //到達済み。かつ重みづけが矛盾しないのでtrue
  
  visited[i] = true;//到達済みにする
  dist[i] = d;//到達コストを代入
  rep(j,g[i].size()){//このノードから生えている辺全てを走査
    if(!bfs(g[i][j].first, d + g[i][j].second)) return false;
  }
  
  return true;
}

int main(){
  int n,m; cin >> n >> m;
  rep(i,m){
    int l,r,d; cin >> l >> r >> d;
    l--; r--;
    g[l].push_back({r,d});//lからrへの辺を重みdで張る
    g[r].push_back({l,-1*d});//その逆を重み-dで張る
  }
  
  rep(i,n){//全てのノードを走査
    if(!visited[i]){//まだ訪れていなかったら
      if(!bfs(i,0)){//bfsをする。falseが返ってきたら、このグラフは成り立たない
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 11008
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
 
#define REP(i,n) for ( int i=1; i<=int(n); i++ )  
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
typedef long long LL;
typedef pair<int, int> pii;
typedef long double LD;
const int INF = 0x3f3f3f3f;
 
const int N = 550;
char mp[N][N];
int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++) 
        scanf("%s", mp[i] + 1);
    int res = 0x3f3f3f3f;
    int tmp = 0;
    int sum = 0;
    for(int y = 1; y <= n; y ++) {
        for(int x = 1; x <= n; x ++) {
            if(mp[x][y] == '.') {
                tmp ++;
                break;
            }
        }
        for(int x = 1; x <= n; x ++) 
            sum += mp[x][y] == '#';
    }
    if(sum == 0) return puts("-1") * 0;
    for(int x = 1; x <= n; x ++) {
        bool flag = false;
        int c = 0;
        for(int i = 1; i <= n; i ++) {
            if(mp[i][x] == '#') flag = true;
            c += mp[x][i] == '.';
        }
        if(flag) res = min(res, c + tmp); 
        else res = min(res, c + tmp + 1);
    }
    if(res == 0x3f3f3f3f) puts("-1");
    else printf("%d\n", res);
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
c=[0]*(n+1)
for i in range(m):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
def dfs(v,t):
    c[v]=t
    for i in s[v]:
        if c[i]==t:
            return False
        if c[i]==0 and not dfs(i,-t):
            return False
    else:
        return True
if dfs(1,1):
    q=c.count(1)
    print((n-q)*q-m)
else:
    print((n*(n-1)//2)-m)

Measured memory_bytes: 31152
H,W,K = map(int,input().split())
c = [input() for _ in range(H)]
ans = 0
for i in range(1<<H):
    for j in range(1<<W):
        cnt = 0
        for k in range(H):
            if i >> k & 1: continue
            for l in range(W):
                if j >> l & 1: continue
                if c[k][l] == "#": cnt += 1
        if cnt == K: ans += 1
print(ans)

Measured memory_bytes: 74092
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2e5+10,inf=0x3f3f3f3f;
struct point{
	int x,y;
	bool operator <(const point &rhs) const{
		return x<rhs.x || (x==rhs.x && y<rhs.y);
	}
}a[maxn];
int stk[maxn],top;
const long double pi=acos(-1.0);
int main(){
	int sx=read(),sy=read(),tx=read(),ty=read();
	if(sx>tx) swap(sx,tx),swap(sy,ty);
	int flag=0;
	if(sy>ty) sy=inf-sy+1,ty=inf-ty+1,flag=1;
	int m=read(),n=0;
	while(m--){
		int x=read(),y=read();
		if(flag) y=inf-y+1;
		if(x>=sx && x<=tx && y>=sy && y<=ty) a[++n]=(point){x,y};
	}
	sort(a+1,a+n+1);
	REP(i,1,n){
		int u=a[i].y;
		if(u>stk[top] || top==0) stk[++top]=u;
		else{
			int x=upper_bound(stk+1,stk+top+1,u)-stk;
			stk[x]=u;
		}
	}
	long double ans=(tx-sx+ty-sy)*100.0-20.0*(1-pi/4)*top;
	if(top==min(tx-sx,ty-sy)+1) ans+=pi*5;
	printf("%.15Lf\n",ans);
	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M;
int A[100010];

//最小公倍数、最大公約数
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}

int lcm(int a,int b){
	return a/gcd(a,b)*b;
}

int f(int n){
	int cnt=0;
	while(n%2==0){
		cnt++;
		n/=2;
	}
	return cnt;
}

signed main(){
	cin>>N>>M;
	REP(i,N){
		cin>>A[i];
		A[i]/=2;
	}
	REP(i,N-1){
		if(f(A[i])!=f(A[i+1])){
			cout<<0<<endl;
			return 0;
		}
	}
	int L=A[0];
	for(int i=1;i<N;i++){
		L=lcm(L,A[i]);
		if(L>pow2(10,9)){
			cout<<0<<endl;
			return 0;
		}
	}
	cout<<ceil2(M/L,2)<<endl;
	return 0;
}


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

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> v(n);
    vector<int> c(n);
    for(int &i : v) cin >> i;
    for(int &i : c) cin >> i;
    int ans = 0;
    for(int i = 0; i < n; i++) ans += (v[i] - c[i] > 0) ? v[i] - c[i] : 0;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define int             long long
#define ld              long double
#define fi              first
#define se              second
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#define fo(i,n)         for(i=0; i<n; i++)
#define fo1(i,n)        for(i=1; i<=n; i++)
#define Fo(i,k,n)       for(i=k; k<=n?i<=n:i>=n; k<=n?i++:i--)
#define all(x)          x.begin(), x.end()
#define rall(x)         x.rbegin(), x.rend()
#define sortall(x)      sort(all(x))
#define sortrall(x)     sort(rall(x))
#define clr(x)          memset(x, 0, sizeof(x))
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define pii             pair<int, int>
#define mk(arr,n,type)  type *arr = new type[n];
#define vi              vector<int>
#define si              set<int>
#define usi             unordered_set<int>
#define mii             map<int, int>
#define umii            unordered_map<int, int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int, vi, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define trailzrobits(x) __builtin_ctzll(x)
#define leadzrobits(x)  __builtin_clzll(x)
#define paritybits(x)   __builtin_parityll(x)
#define gcd             __gcd
#define lcm(x, y)       (x * y) / gcd(x, y)
#define mod             1000000007
#define endl            '\n'
#define PI              3.1415926535897932384626
#define inf             1e18
#define sp(x,y)         fixed<<setprecision(y)<<x
void __print(int32_t x) {cout<<x;}
void __print(int x) {cout<<x;}
void __print(ld x) {cout<<x;}
void __print(double x){cout<<x;}
void __print(float x){cout<<x;}
void __print(bool x) {cout<<(x?"true":"false");}
void __print(char x){cout <<'\''<<x<<'\'';}
void __print(const char *x){cout <<'\"' <<x<<'\"';}
void __print(const string &x) {cout<<'\"'<<x<<'\"';}
template<typename T,typename V>     void __print(const pair<T,V> &x) {cout<<'{';__print(x.first);cout<<',';__print(x.second);cout<<'}';}
template<typename T>                void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}void _print() {cout << "]\n";}
template <typename T,typename... V> void _print(T t, V... v) {__print(t);if(sizeof...(v))cout<<", ";_print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_print(x)
#else 
#define dbg(x...)
#endif
int power(int base, int exp){ int res = 1; base %= mod; while(exp > 0){ if(exp & 1) res = (res * base) % mod; base = (base * base) % mod; exp = exp >> 1; } return res; }
int inv(int x){ return power(x, mod - 2) % mod; }
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




const int N = 1e6 + 6, M = N;
int i, j;

void solve(){
    
    int n; cin>>n;
    string s;
    
    while(n>0){
        s+=char('a'+(n-1)%26);
        n=(n-1)/26;
    }
    reverse(all(s));
    cout<<s<<endl;
    
    
}




int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3504
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include<cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include<bitset>

#define REP(i,b,n) for(int i=b;i<(int)n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define FOR(it,o)  for(__typeof((o).begin()) it=(o).begin(); it!=(o).end(); ++it)
#define dbg(x) cout << __LINE__ << ' ' << #x << " = " << (x) << endl


typedef long long ll;

using namespace std;

int solve(vector<int> &v){
    int n = v.size();
    vector<int> sorted = v;
    sort(ALL(sorted));
    map<int, int> m;
    rep(i, n){
        m[sorted[i]] = i%2;
    }
    int cnt = 0;
    rep(i, n){
        if(m[v[i]] != i%2){
            cnt++;
        }
    }
    return cnt/2;
}

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n){
        cin >> v[i];
    }
    cout << solve(v) <<endl;

  return 0;
}


Measured memory_bytes: 5760
import sys
from collections import Counter
from math import gcd
from functools import reduce

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    N_MAX = 10 ** 6

    min_factor = list(range(N_MAX + 1))
    min_factor[2::2] = [2] * (N_MAX // 2)
    for i in range(3, int(N_MAX ** 0.5) + 2, 2):
        if min_factor[i] != i:
            continue
        for j in range(i * i, N_MAX + 1, 2 * i):
            if min_factor[j] > i:
                min_factor[j] = i

    def prime_factorize_fast(n):
        a = Counter()
        while n != 1:
            a[min_factor[n]] += 1
            n //= min_factor[n]

        return a

    primes = Counter()
    for a in A:
        this_prime = prime_factorize_fast(a)
        for p in this_prime.keys():
            primes[p] += 1

    pairwise = True
    for k, v in primes.items():
        if v > 1:
            pairwise = False

    if pairwise:
        print('pairwise coprime')
        return

    g = reduce(gcd, A)
    if g == 1:
        print('setwise coprime')
    else:
        print('not coprime')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 219924
#include <stdio.h>
int main(void) {
    int h = 0;
    int w = 0;
    int isfinish = 0;
    int cou = 0;

    while (isfinish != 1) {
        cou = 0;
        scanf("%d %d", &h, &w);

        if (h == 0 && w == 0) {
            break;
        } else {
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (cou % 2 == 0) {
                        printf("#");
                    } else {
                        printf(".");
                    }
                    cou++;
                }
                printf("\n");
                if (i % 2 == 0) {
                    cou = 1;
                } else {
                    cou = 0;
                }
            }
        }
        printf("\n");
    }

    return 0;
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL<<60);

int main(){

    string s; cin >> s;

    if(s=="Sunny")  cout << "Cloudy" << endl;
    if(s=="Cloudy") cout << "Rainy"  << endl;
    if(s=="Rainy")  cout << "Sunny"  << endl;

    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 3e3 + 5;

ll dp[2][MAXN][2];

void solve(){
	int n, m;
	scanf("%d%d", &n, &m);
	REPN(i, 1, n) {
		dp[0][i][0] = 1;
	}
	dp[0][0][1] = 1;
	REP(i, 0, m) {
		int ind = i & 1;
		REPN(j, 0, n) {
			dp[ind ^ 1][j][0] = dp[ind ^ 1][j][1] = 0;
		}
		REPN(j, 0, n) {
			REP(k, 0, 2) {
				REP(l, 0, 2) {
					if (j > 0) {
						if (j == 1 && k == 0) {
							dp[ind ^ 1][j - l][1] = (dp[ind ^ 1][j - l][1] + dp[ind][j][0]) % MOD;
						} else {
							dp[ind ^ 1][j - l][k] = (dp[ind ^ 1][j - l][k] + dp[ind][j][k]) % MOD;
						}
					}
					if (j < n) {
						dp[ind ^ 1][j + l][k] = (dp[ind ^ 1][j + l][k] + dp[ind][j][k]) % MOD;
					}
				}
			}
		}
	}
	ll ans = 0ll;
	REPN(i, 0, n) {
		ans = (ans + dp[m & 1][i][1]) % MOD;
	}
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

typedef long long ll;
typedef pair<int, int> ii;

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

    char inp[n + 3];
    scanf("%s", inp);

    int cnt = 0;
    for (int l = 0; l < n; l++) {
        int r = l;
        while (r + 1 < n && inp[l] == inp[r + 1])
            r++;
        cnt++;
        l = r;
    }
    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
ll N,M,ans,C,K;
string S,T;
bool found = true;
int main(){
    cin >> N >> M >> C >> K;
    if(N>K){
        ans = K;
    }else if(M+N>K){
        ans = N;
    }else{
        ans = N -(K-M-N);
    }
    cout << ans << endl;
}



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

int main() {
  vector<int>vec(3);
  cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
  
  sort(vec.begin(),vec.end());
  
  cout << vec.at(0) + vec.at(1) << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
 
int main() {
	int n, m;
	string s[105], t[105];
	int max = 0;
	int cnt=0;
	int i, j;

	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	cin >> m;
	for (i = 0; i < m; i++)
	{
		cin >> t[i];
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (s[i] == s[j])
			{
				cnt++;
			}
		}
		for (j = 0; j < m; j++)
		{
			if (s[i] == t[j])
			{
				cnt--;
			}
		}
		if (max < cnt)max = cnt;
		cnt = 0;
	}
	cout << max << endl;
}



/**/
/*#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define PI 3.141592653589793

int main(void) {
	return 0;
}
*/

Measured memory_bytes: 3596
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

long bb[1005][1005];
long sb[1005][1005];
long ww[1005][1005];
long sw[1005][1005];

long count_w( long i0, long j0, long i1, long j1 )
{
    return sw[i1][j1] + sw[i0][j0] - sw[i1][j0] - sw[i0][j1];
}
long count_b( long i0, long j0, long i1, long j1 )
{
    return sb[i1][j1] + sb[i0][j0] - sb[i1][j0] - sb[i0][j1];
}

int main(int argc, char* argv[])
{
    long n,k;
    scanf("%ld%ld", &n, &k);
    
    long i,j;
    for(i=0; i<n; i++) {
        long x, y;
        char str[5]={0};
        scanf("%ld%ld%s", &x, &y, str);
        
        if(str[0]=='B') {
            if((x/k+y/k)%2==0) bb[x%k][y%k]++;
            else               ww[x%k][y%k]++;
        }
        else {
            if((x/k+y/k)%2==0) ww[x%k][y%k]++;
            else               bb[x%k][y%k]++;
        }
    }

    for(i=0; i<=k; i++) {
        sb[0][i]=sw[0][i]=0;
        sb[i][0]=sw[i][0]=0;
    }
    for(i=0; i<k; i++) {
        for(j=0; j<k; j++) {
            sb[i+1][j+1]=sb[i+1][j]+bb[i][j];
            sw[i+1][j+1]=sw[i+1][j]+ww[i][j];
        }
    }
    for(i=0; i<k; i++) {
        for(j=0; j<k; j++) {
            sb[i+1][j+1]+=sb[i][j+1];
            sw[i+1][j+1]+=sw[i][j+1];
        }
    }

    long max=0;
    for(i=0; i<k; i++) {
        for(j=0; j<k; j++) {
            long val = count_w(0,0,i,j) + count_w(i,j,k,k) + count_b(0,j,i,k) + count_b(i,0,k,j);
            if(max <val) {
                max = val;
            }

            val = count_b(0,0,i,j) + count_b(i,j,k,k) + count_w(0,j,i,k) + count_w(i,0,k,j);
            if(max <val) {
                max = val;
            }
        }
    }

    printf("%ld\n", max);

    return 0;
}


Measured memory_bytes: 31744
n = int(input())
a = [0] * n
d = {}
for i in range(n):
    a[i] = int(input())
    d[a[i]] = 0

for i in a:
    d[i] += 1

ans = 0
for k, i in d.items():
    if i % 2 == 1:
        ans += 1

print(ans)


Measured memory_bytes: 56152
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int ans=0;
	for(int i=1;i<n;i++)
	{
		int t=0;
		string a="",b="";
		for(int j=0;j<i;j++)
		a+=s[j];
		for(int j=i;j<s.size();j++)
		b+=s[j];
		int c[26]={};
		for(int j=0;j<a.size();j++)
		c[a[j]-'a']++;
		for(int j=0;j<b.size();j++)
		{
			if(c[b[j]-'a']>0)
			t++;
			c[b[j]-'a']=0;
		}
		if(t>ans)
		ans=t;
	}
	cout<<ans;
 } 

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <sstream>
#include <iterator>
#include <sstream>
#include <iomanip>
#include <istream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
   int a, b, c, d;
   cin >> a >> b >> c >> d;
   if(b < c || a > d) cout << "0" << endl;
   else cout << abs(min(b,d) - max(a,c)) << endl;
}


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

vector<int> solve(int k, int n) {
    if (k == 1 and n == 1) {
        return vector<int>(1, 1);

    } else if (k % 2 == 0) {
        // the last sequence starting with k / 2
        vector<int> a(n, k);
        a[0] = k / 2;
        return a;

    } else {
        // basically the sequence whose all elements are k / 2 + 1
        vector<int> a(n, k / 2 + 1);
        REP (i, n / 2) {
            if (a.back() == 1) {
                a.pop_back();
            } else {
                -- a.back();
                while (a.size() < n) {
                    a.push_back(k);
                }
            }
        }
        return a;
    }
}

int main() {
    int k, n; cin >> k >> n;
    auto a = solve(k, n);
    for (int a_i : a) {
        cout << a_i << ' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3456
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int gcd(long long int a, long long int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

long long int lcm(long long int a, long long int b) {
	return a / gcd(a, b)*b;
}

class Add_Segment_Tree {
	vector<long long int>v;
	vector<long long int>w;
	long long int ret;
	int num;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		v[place] = lcm(Update(place * 2), Update(place * 2 + 1));
		return v[place];
	}
public:
	Add_Segment_Tree(int n) {
		n++;
		num = 1;
		while (num < n * 2)num *= 2;
		v.resize(num, 1);
		w.resize(num, 0);
	}
	void Add(int place, int box, long long int num) {
		place += v.size() / 2;
		v[place] = num;
		w[place] = box;
		place /= 2;
		while (place) {
			v[place] = lcm(v[place * 2], v[place * 2 + 1]);
			w[place] = (v[place] / v[place * 2])%MOD * w[place * 2] + (v[place] / v[place * 2 + 1])%MOD * w[place * 2 + 1];
			w[place] %= MOD;
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int Sum(int a, int b) {
		ret = 1;
		long long int ans = 0;
		b++;
		for (a += num / 2, b += num / 2; a < b; a >>= 1, b >>= 1) {
			if (a & 1) {
				long long int bef = ret;
				ret = lcm(ret, v[a]);
				ans = (ret / bef)%MOD * ans%MOD + (ret / v[a])%MOD * w[a]%MOD;
				ans %= MOD;
				a++;
			}
			if (b & 1) {
				b--;
				long long int bef = ret;
				ret = lcm(ret, v[b]);
				ans = (ret / bef)%MOD * ans%MOD + (ret / v[b])%MOD * w[b]%MOD;
				ans %= MOD;
			}
		}
		cout << ans << endl;
		return ret;
	}
};

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

	cin >> N >> K;
	vector<vector<int>>p(41, vector<int>(N + 1));
	for (int i = 1; i <= N; i++) {
		cin >> p[1][i];
		p[0][i] = i;
	}
	for (int i = 2; i <= 40; i++) {
		for (int j = 1; j <= N; j++) {
			p[i][j] = p[i - 1][p[1][j]];
		}
	}
	vector<int>loop(N + 1, 1);
	vector<int>sum(N + 1, 0);
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= 40; j++) {
			sum[i] += p[j][i];
			if (p[j][i] == i) {
				loop[i] = j;
				break;
			}
		//	cout << i << " " << sum[i] << endl;
		}
	}
	Add_Segment_Tree asg(N + 1);
	for (int i = 0; i <= N; i++)asg.Add(i, sum[i],loop[i]);
	while (K--) {
		cin >> L >> R;
		asg.Sum(L, R);
	}
}



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


int main(){
    string s,t;
    
    cin >> s ;
    cin >> t;
    vector<char> ans(s.size()+t.size());
    for(int i=0;i<t.size();i++){
        ans.at(i)=t.at(i);
    }
    for(int i=0;i<s.size();i++){
        ans.at(t.size()+i)=s.at(i);
    }
    
    for(int i=0;i<s.size()+t.size();i++){
        cout << ans.at(i);
    }
    cout << endl;


}

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

int main(void){
    int N;
    string S;
    cin >> N >> S;
    
    int ans = 0;
    char a;
    for (int i = 0; i < N; i++) {
        if (i == 0)
            a = S[0];
        else {
            if (a != S[i]) {
                ans++;
                a = S[i];
            }
        }
    }
    cout << ans+1 << endl;
}

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

using namespace std;

#define il inline
#define re register int
#define Rep(i, s, e) for (re i = s; i <= e; ++i)
#define Dep(i, s, e) for (re i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)

typedef long long ll;
il ll min(ll x, ll y) {return (x < y) ? x : y;}

const ll INF = 0x3f3f3f3f3f3f3f3f;

const int N = 1010;

il int read() {
	int x = 0; bool f = true; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = false; c = getchar();}
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	return f ? x : -x;
}

int h, n, a[N], b[N], f[10010];
int main() {
	memset(f, INF, sizeof(f));
	h = read(), n = read();
	Rep(i, 1, n) a[i] = read(), b[i] = read();
	f[0] = 0;
	Rep(i, 1, h) {
		Rep(j, 1, n) {
			f[i] = min(f[i], f[max(i - a[j], 0)] + b[j]);
		}
	}
	return printf("%lld", f[h]) & 0;
}

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

bool solve(int A[], int n, int i, int key) {
	if (key == 0) return true;
	if (i >= n) return false;
	return solve(A, n, i + 1, key) || solve(A, n, i + 1, key - A[i]);
}

int main() {
	int n;
	int q;
	int A[20];

	cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i];
	cin >> q;
	
	for (int i = 0; i < q; i++) {
		int key;
		cin >> key;
		if (solve(A, n, 0, key)) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

std::string n, l, s;
int cnt = 0;
bool used[10000];
bool flg = true;

int main(){
	while (std::cin >> n, n != "0000"){
		rep(i, 10000)used[i] = false;
		cnt = 0;
		flg = true;
		while (n != "6174"){
			l = n;
			s = n;
			std::sort(l.begin(), l.end(), std::greater<char>());
			std::sort(s.begin(), s.end());
			if (l.size() < 4)l += std::string("0", 4 - l.size());
			n = std::to_string(std::stoi(l) - std::stoi(s));
			if (used[std::stoi(n)]){
				flg = false;
				break;
			}
			used[std::stoi(n)] = true;
			++cnt;
		}
		if (flg)std::cout << cnt << std::endl;
		else std::cout << "NA" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	int  a, b, c; cin >> a >> b >> c; int d = c - a - b;
	if (d > 0 && 4 * a * b < d * d) { cout << "Yes\n"; }
	else { cout << "No\n"; }
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <iomanip>

using ll = long long int;
using P = std::pair<ll, int>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n;
ll memo[2222][2222];
bool done[2222][2222];
P b[2222];

ll solve(int l, int r){
	if(l>=n || r<0){
		return -INFLL;
	}
	if(done[l][r]){
		return memo[l][r];
	}
	done[l][r] = true;
	if(l<=r){
		memo[l][r] = std::max(memo[l][r],solve(l+1,r)+b[r-l].first*abs(b[r-l].second-l));
		memo[l][r] = std::max(memo[l][r],solve(l,r-1)+b[r-l].first*abs(b[r-l].second-r));
	}
	return memo[l][r];
}

int main(void){
	int i,j;
	ll ans=-INFLL,tmp;
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> b[i].first;
		b[i].second = i;
	}
	sort(b,b+n);
	std::cout << solve(0,n-1) << std::endl;
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  string s;cin>>s;
  cout<<s[0]<<s[1]<<s[2]<<endl;


  return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

class Main {
    private static int rec(int i, int n, int s) {
        if (n == 0) {
            return s == 0 ? 1 : 0;
        } else if (i > 9) {
            return 0;
        } else {
            return rec(i + 1, n, s) + rec(i + 1, n - 1, s - i);
        }
    }

    private static void solve() {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            int n = scanner.nextInt();
            int s = scanner.nextInt();
            if (n == 0 && s == 0) {
                break;
            }
            System.out.println(rec(0, n, s));
        }
    }

    public static void main(String... args) {
        solve();
    }
}

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

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

    int k;
    cin >> k;
    int a = 7;
    for (int i = 1; i <= 2 * k; i++) {
        if (a % k == 0) {
            cout << i << endl;
            return 0;
        }
        a = a * 10 + 7;
        a %= k;
    }
    cout << -1 << endl;
}


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

using namespace std;

#define int long long
const int mod = 1e9 + 7;

int dp[5005][5005];
signed main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int l = s.length();
	dp[0][0] = 1;
	for(int j = 1; j <= n; j++){
		dp[0][j] = (dp[0][j] + dp[1][j - 1] * 2 + dp[0][j - 1]) % mod;
		for(int i = 1; i <= n; i++){
			dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + dp[i + 1][j - 1] * 2) % mod;
		}
	}
	cout << dp[l][n];
}

Measured memory_bytes: 195840
import sys

N,M = map(int, input().split())

L = []
for _ in range(N):
    A,B = map(int, input().split())
    L.append([A,B])

L = sorted(L, key=lambda x: x[0])

sum = 0
for i in range(len(L)):
    l = L[i]
    if l[1]<M:
        M = M - l[1]
        sum = sum + l[0]*l[1]
    else:
        sum = sum + l[0]*M
        print(sum)
        sys.exit()      

print(sum)

Measured memory_bytes: 21960
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=1000000000+7;
        long arr[]=new long[n];
        long sum[]=new long[n];
        for(int i=0;i<n;i++)
            arr[i]=in.nextLong();
        sum[n-1]=0;
        sum[n-2]=arr[n-1];
        for(int i=n-3;i>=0;i--)
            sum[i]=arr[i+1]+sum[i+1];
            
        long ans=0;
        
        for(int i=0;i<n;i++){
            ans=(ans%m)+((arr[i]%m)*(sum[i]%m));
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 63932
s=input()
ok=1
for i in range(0,len(s),2):
    if s[i] not in 'RUD':
        ok = 0
for i in range(1,len(s),2):
    if s[i] not in 'LUD':
        ok = 0
if ok:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	n <- readInt
	print $ last $ takeWhile ( <= n ) $ [ k * k | k <- [ 1 .. ] ]


Measured memory_bytes: 892
import java.util.Scanner;

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

		int[] t = new int[4];

		for (int i = 0; i < 6; i++) {
			t[sc.nextInt() - 1]++;
		}

		for (int i = 0; i < t.length; i++) {
			if (t[i] >= 3) {
				System.out.println("NO");
				sc.close();
				return;
			}
		}
		System.out.println("YES");
		sc.close();
	}

}

Measured memory_bytes: 22100
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

void solve_A(); void solve_B(); void solve_C(); void solve_D();

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    //*
     solve_A();
     //*/
    
    /*
     solve_B();
     //*/
    
    
    /*
     solve_C();
     //*/
    
    /*
    solve_D();
     //*/
	return 0;
}

void solve_A(){
    ll N; cin >> N;
    cout << N/3 << endl;
}

void solve_B(){
    
}

void solve_C(){
    
}

void solve_D(){
    
}


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;
using P = pair<int,int>;

int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  int ai = 0, bi = 0, ci = 0;
  char turn = 'a';
  while (1) {
    if (turn == 'a') {
      if (ai == sa.size()) break;
      turn = sa[ai++];
    }
    else if (turn == 'b') {
      if (bi == sb.size()) break;
      turn = sb[bi++];
    }
    else {
      if (ci == sc.size()) break;
      turn = sc[ci++];
    }
  }
  char win = turn + 'A' - 'a';
  cout << win << endl;
  return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> table(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> table.at(i).at(j);
    }
  }
  
  vector<bool> row(H, false);
  vector<bool> col(W, false);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (table.at(i).at(j) == '#') {
        row.at(i) = true;
        col.at(j) = true;
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
    if (row.at(i))               {
    	for (int j = 0; j < W; j++) {
          if (col.at(j)) {
            cout << table.at(i).at(j);
          }
        }
      cout << endl;
    }
  }   
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct _tree_t {
	int id;
	struct _tree_t *p, *l, *r;
} tree_t;

tree_t* tree_insert(tree_t* root, int id){
	tree_t *y = NULL;
	tree_t *x = root;
	tree_t *z = (tree_t*)malloc(sizeof(tree_t));
	z->id = id;
	z->l = z->r = z->p = NULL;

	while(x != NULL) {
	    y = x;
	    if(z->id < x->id) {
	        x = x->l;
	    } else { 
	        x = x->r;
	    }
	}
	z->p = y;
	if(y == NULL) {
    	root = z;
	} else if(z->id < y->id) {
	    y->l = z;
	} else { 
	    y->r = z;
	}
	
	return root;
}
void print_find(tree_t *tree, int id) {
	if(tree==NULL) {
		printf("no\n");
		return;
	}
	
	if(id == tree->id) {
		printf("yes\n");
		return;
	} else if(id < tree->id) {
		print_find(tree->l, id);
	} else {
		print_find(tree->r, id);
	}
}

void print_preorder(tree_t *tree) {
    printf(" %d", tree->id);
    if(tree->l != NULL) print_preorder(tree->l);
    if(tree->r != NULL) print_preorder(tree->r);
}

void print_inorder(tree_t *tree) {
    if(tree->r == NULL && tree->l == NULL) {
        printf(" %d", tree->id);
    } else if(tree->r == NULL) {
        print_inorder(tree->l);
        printf(" %d", tree->id);
    } else if(tree->l == NULL) {
        printf(" %d", tree->id);
        print_inorder(tree->r);
    } else {
        print_inorder(tree->l);
        printf(" %d", tree->id);
        print_inorder(tree->r);
    }
}
int main(void) {
	int i, n, id;
	char buff[100];
	tree_t *root = NULL;
	scanf("%d\n", &n);
	for(i=0;i<n;i++) {
		scanf("%s %d\n", buff, &id);
		if(buff[0] == 'i') {
			root = tree_insert(root, id);
		} else if(buff[0] == 'f') {
			print_find(root, id);
		} else if(buff[0] == 'p') {
			print_inorder(root);
			printf("\n");
			print_preorder(root);
			printf("\n");
		}
	}
	
	return 0;
}



Measured memory_bytes: 25164