akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#define EPS 1e-9

using namespace std;

class L;

class P{
public:
	double x,y;
	P(){x=0;y=0;}
	P(double x, double y){this->x=x;this->y=y;}
	P reflect(L l);
};
class L{
public:
	P p1,p2;
	L(){}
	L(P p1, P p2){this->p1=p1;this->p2=p2;}
	L reflect(L l);
};

P P::reflect(L l){
	double dx = (l.p2.x - l.p1.x), dy = (l.p2.y - l.p1.y);
	double a = dx * dx + dy *dy, b = dx * (l.p1.x - x) + dy * (l.p1.y - y);
	double t = -b / a;
	double tx = l.p1.x + dx * t, ty = l.p1.y + dy * t;
	this->x = 2*tx-x;
	this->y = 2*ty-y;
	return *this;
}
L L::reflect(L l){
	this->p1.reflect(l);
	this->p2.reflect(l);
	return *this;
}


int isIntersect(L l1, L l2){
	if (((l1.p1.x - l1.p2.x) * (l2.p1.y - l1.p1.y) + (l1.p1.y - l1.p2.y) * (l1.p1.x - l2.p1.x)) * 
		((l1.p1.x - l1.p2.x) * (l2.p2.y - l1.p1.y) + (l1.p1.y - l1.p2.y) * (l1.p1.x - l2.p2.x)) < 0){
		if (((l2.p1.x - l2.p2.x) * (l1.p1.y - l2.p1.y) + (l2.p1.y - l2.p2.y) * (l2.p1.x - l1.p1.x)) * 
			((l2.p1.x - l2.p2.x) * (l1.p2.y - l2.p1.y) + (l2.p1.y - l2.p2.y) * (l2.p1.x - l1.p2.x)) < 0	){
			return 1;
		}
	}
	return 0;
}

P getIntersect(L l1, L l2){
	double S1 = ((l2.p2.x - l2.p1.x) * (l1.p1.y - l2.p1.y) - (l2.p2.y - l2.p1.y) * (l1.p1.x - l2.p1.x)) / 2;
	double S2 = ((l2.p2.x - l2.p1.x) * (l2.p1.y - l1.p2.y) - (l2.p2.y - l2.p1.y) * (l2.p1.x - l1.p2.x)) / 2;
	return P(l1.p1.x + (l1.p2.x - l1.p1.x) * S1 / (S1 + S2 + EPS), l1.p1.y + (l1.p2.y - l1.p1.y) * S1 / (S1 + S2 + EPS));
}


L mir[6][6];
P start, tgoal;
int n;
double ans;
void check(vector <int> ref){
	int i,j;
	P goal = tgoal;
	for(i=0;i<int(ref.size());i++){
		for(j=0;j<n;j++){
			mir[i+1][j] = mir[i][j];
			if(ref[i]!=j) mir[i+1][j].reflect(mir[i][ref[i]]);
		}
		goal.reflect(mir[i][ref[i]]);
	}
	P cur = start;
	P is;
	for(i=0;i<=int(ref.size());i++){
		L laser = L(cur, goal);
		if(i != int(ref.size())){
			if(!isIntersect(laser, mir[i][ref[i]])){
				return;
			}
			is = getIntersect(laser, mir[i][ref[i]]);
		}else is = goal;
		laser.p2 = is;
		for(j=0;j<n;j++){
			if((i == int(ref.size()) || ref[i]!= j) &&
			   (!i || ref[i-1]!= j) &&
			    isIntersect(laser, mir[i][j])){
				return;
			}
		}
		
		cur = is;
	}
	ans = min(ans, (goal.x-start.x)*(goal.x-start.x)+(goal.y-start.y)*(goal.y-start.y));
}

void solve(vector<int> ref){
	int i;

	check(ref);
	if(ref.size()<5){
		for(i=0;i<n;i++){
			if(ref.size() && ref[ref.size()-1] == i) continue;
			ref.push_back(i);
			solve(ref);
			ref.pop_back();
		}
	}
}

main(){
	int i,x1,y1,x2,y2;
	vector<int> ref;

	while(cin>>n,n){
		ans = 1e9;
		for(i=0;i<n;i++){
			cin>>x1>>y1>>x2>>y2;
			mir[0][i] = L(P(x1,y1),P(x2,y2));
		}
		cin>>tgoal.x>>tgoal.y>>start.x>>start.y;
		
		ref.clear();
		solve(ref);
		cout << sqrt(ans) << endl;
	}
}

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

int main(){
    string n;
    cin>>n;
    for(int i=0;n.size()>i;i++){
    if(n.at(i)=='1'){
    n.at(i)='9';}else if(n.at(i)=='9'){n.at(i)='1';
    }
    }
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        int[] a = new int[n];
        
        for(int i = 0; i < n; i++) a[i] = sc.nextInt();
        
        List<Pair<Integer,Integer>> list = new ArrayList<>();
        
        for(int i = 0; i < n; i++){
            list.add(new Pair<>(a[i], i));
        }
        
        list.sort((x,y) -> x.getKey() - y.getKey());
        
        for(int i = 0; i < n; i++){
            System.out.print((list.get(i).getValue() + 1) + " ");
        }
    }
}


class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {
 
    public Pair(K key, V value) {
        super(key, value);
    }
 
    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

vector<string> g;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int r, c;
    cin >> r >> c;
    int cx, cy, dx, dy;
    cin >> cy >> cx >> dy >> dx;

    g.resize(r);
    cx--;
    cy--;
    dx--;
    dy--;
    for(int i = 0; i < r; i++) {
        cin >> g[i];
    }

    deque<pair<int,int>> q;
    vector<vector<int>> dist(r, vector<int>(c, (int)1e9));
    vector<vector<bool>> vis(r, vector<bool>(c, false));
    q.push_back(mp(cy,cx));

    pii delta[4] = {{-1, 0},{1, 0}, {0, 1}, {0, -1}};
    dist[cy][cx] = 0;
    while(!q.empty()) {
        pair<int,int> p = q.front();
        q.pop_front();
        int y = p.first;
        int x = p.second;
        int d = dist[y][x];
        if(vis[y][x]) continue;
        vis[y][x] = true;
        trav(v, delta) {
            int nr = v.first + y;
            int nc = v.second + x;
            if(nr < 0 || nc < 0 || nr >= r || nc >= c) continue;
            if(!vis[nr][nc] && g[nr][nc] != '#') {
                if (d < dist[nr][nc]) {
                    dist[nr][nc] = d;
                    q.push_front(mp(nr, nc));
                }
            }
        }
        for(int dely = -2; dely <= 2; dely++) {
            for(int delx = -2; delx <= 2; delx++) {
                int nr = y + dely;
                int nc = delx + x;
                if(nr < 0 || nc < 0 || nr >= r || nc >= c) {
                    continue;
                }
                if(vis[nr][nc] || g[nr][nc] == '#') continue;
                if(d + 1 < dist[nr][nc]) {
                    dist[nr][nc] = d + 1;
                    q.push_back(mp(nr,nc));
                }
            }
        }

    }
    cout << (dist[dy][dx] == (int)1e9 ? -1 : dist[dy][dx]) << endl;

    return 0;
}


Measured memory_bytes: 8868
/* Arpit Pandey*/ 

#include <bits/stdc++.h>
#include <stdlib.h>
#include <stdint.h>
using namespace std;
 
#define int long long
#define pb push_back
#define in insert
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
#define test(x) int x;cin>>x; while(x-->0)
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;
void fast_io()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("error.txt", "w", stderr);
	freopen("output.txt", "w", stdout);
#endif
}

void sol()
{
	int n; cin>>n;
	int x[n],y[n];
	for(int i=0;i<n;i++)
	{
		cin>>x[i]>>y[i];
	}
	int m1=-1e9,m2=1e9;
	for(int i=0;i<n;i++)
	{
		m1=max(m1,x[i]+y[i]);
		m2=min(m2,x[i]+y[i]);
	}
	int ans1=abs(m1-m2);
	m1=-1e9;m2=1e9;
	for(int i=0;i<n;i++)
	{
		m1=max(m1,x[i]-y[i]);
		m2=min(m2,x[i]-y[i]);
	}
	int ans2=abs(m1-m2);
	cout<<max(ans1,ans2);



}
int32_t main()
{
	fast_io();
	//test(t)
	sol();
	//cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	//cerr << sizeof(dp)*(1e-6) << " megabytes\n";
	return 0;
}


Measured memory_bytes: 6768
N=int(input())
X=list(map(int,input().split(" ")))
P=min(X)
L=max(X)
sum1=0
for i in range(N):
  sum1+=(X[i]-P)*(X[i]-P)
while P!=L:
  sum2=0
  for i in range(N):
    sum2+=(X[i]-P-1)*(X[i]-P-1)
  if sum2<sum1:
    sum1=sum2
  P+=1
print(sum1)

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll Y, M;
    string S;
    cin >> S;
    Y = stoll(S.substr(0, 4));
    M = stoll(S.substr(5, 2));
    if(Y >= 2019 && M >= 5) cout << "TBD";
    else cout << "Heisei";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3560
#include <iostream>
#include <list>

int main()
{
    std::list<int> List;

    int q, m, x, d;
    auto itr = List.end();

    std::cin >> q;
    for (int i = 0; i < q; i++)
    {
        std::cin >> m;
        if (m == 0)
        {
            std::cin >> x;
            itr = List.insert(itr, x);
        }
        else if (m == 1)
        {
            std::cin >> d;
            itr = next(itr, d);
        }
        else if (m == 2)
        {
            itr = List.erase(itr);
        }

        // std::cout << m << " " << x << " " << d << std::endl;
        // for (auto &x : List)
        // {
        //     std::cout << x;
        // }
        // std::cout << " " << *itr << std::endl;
    }

    for (auto &x : List)
    {
        std::cout << x << std::endl;
    }

    return 0;
}


Measured memory_bytes: 18600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    set<string> st;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 19124
#include<iostream>
#include<iomanip>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;

int main(){
    int D , T , S;
    cin >> D >> T >> S;

    if( (S * T) >= D){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" <<endl;
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a=N/10/10;
  int b=N/10-a*10;
  int c=N-a*100-b*10;
  if(a==7||b==7||c==7)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}



Measured memory_bytes: 3636
n = int(input())
bt = 0
bx = 0
by = 0
flag = True
for i in range(n):
    t,x,y = map(int,input().split())
    elp = t-bt
    ex = x-bx
    ey = y-by
    nes = ex + ey
    elp -=  nes
    if elp >= 0:
        if elp %2 == 0:
            continue
        else:
            flag = False
            break
    else:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 3060
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

template<class T>
class sg_tree : public vector<T>{
private:
    lli n;
    T default_value;
    void _query(lli a,lli b,T x,lli k,lli l,lli r){
        if(r <= a || b <= l) return;
        if(a <= l && r <= b) (*this)[k] = x;
        else {
            _query(a,b,x,k*2+1,l,(l+r)/2);
            _query(a,b,x,k*2+2,(l+r)/2,r);
            return;
        }
    }
public:
    sg_tree():vector<T>(){

    }
    sg_tree(lli n,T d = -1):vector<T>(n*4,d){
		this->n = 1;
        while(n > this->n) this->n <<= 1;
        this->default_value = d;
    }
    T update(lli i){
        i += n - 1;
        T ret = (*this)[i];
        while(i > 0){
            i = (i - 1) / 2;
            ret = max(ret,(*this)[i]);
        }
        return ret;
    }
    void query(lli a,lli b,lli x){
        _query(a,b,x,0,0,n);
    }
    T func(T a,T b){
        return min(a,b);
    }
};

lli n,q;
lli c,s,t,x;
lli k = 0;
vll b;

sg_tree<lli> sg;

int main(){
    cin >> n >> q;
    sg = sg_tree<lli> (n);
    for(lli i = 0;i < q;i++){
        cin >> c;
        if(c){
            cin >> x;
            lli t;
            if((t = sg.update(x)) < 0) cout << 2147483647 << endl;
            else cout << b[t] << endl;
        }else{
            cin >> s >> t >> x;
            b.push_back(x);
            sg.query(s,t+1,k);
            k++;
            
        }
    }
}

Measured memory_bytes: 7020
#include "bits/stdc++.h"
using namespace std;

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	string S;
	cin >> S;

	vector<int> res(S.size());
	//for (int i = 0; i < S.size(); i++)
	//	res[i] = 1;

	int rCount = 0, lCount = 0;
	for (int i = 0; i < S.size()-1; i++)
	{
		if (S[i] == 'R' && S[i + 1] == 'R')
		{
			res[i] = 0;
			rCount++;
		}

		if (S[i] == 'R' && S[i + 1] == 'L')
		{
			res[i] = rCount / 2 + 1;
			res[i + 1] = rCount / 2 + rCount % 2 + 1;
			rCount = 0;
		}
	}

	for (int i = S.size()-1; i > 0; i--)
	{
		if (S[i-1] == 'L' && S[i] == 'L')
		{
			res[i] += 0;
			lCount++;
		}

		if (S[i-1] == 'R' && S[i] == 'L')
		{
			res[i - 1] += lCount / 2 + lCount % 2;
			res[i] += lCount / 2;
			lCount = 0;
		}

	}

	for (int i = 0; i < res.size(); i++)
	{
		if (i > 0)
			cout << " ";
		cout << res[i];
	}
	return 0;
}

Measured memory_bytes: 1104
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define mod 998244353
#define maxn 10010
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int quick_pow(int x,int p)
{
    int an=1;
    int po=x;
    while(p)
    {
        if(p&1)  an=1ll*an*po%mod;
        po=1ll*po*po%mod;
        p>>=1;
    }
    return an;
}
int a,b,n;
char s[maxn],t[maxn];
int fac[maxn],inv[maxn];
int f[maxn];
int res;
int C(int x,int y)
{
    return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main()
{
    scanf("%s",s+1);
    scanf("%s",t+1);
    n=strlen(s+1);
    fac[0]=1;
    for(int i=1;i<=n;i++)  fac[i]=1ll*fac[i-1]*i%mod;
    inv[n]=quick_pow(fac[n],mod-2);
    for(int i=n-1;i>=0;i--)  inv[i]=1ll*inv[i+1]*(i+1)%mod;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='1'&&t[i]=='1')  a++;
        else if(s[i]=='1')        b++;
    }
    for(int i=0;i<=b;i++)  f[i]=1ll*fac[i]*fac[i]%mod;
    res=1ll*f[b]*fac[a]%mod*fac[a]%mod*C(a+b,a)%mod;
    for(int i=1;i<=a;i++)
    {
        f[0]=0;
        for(int j=1;j<=b;j++)
        {
            f[j]=(1ll*f[j]*i%mod*j%mod+1ll*f[j-1]*j%mod*j%mod)%mod;
        }
        res=(res+1ll*f[b]*fac[a-i]%mod*fac[a-i]%mod*C(a,a-i)%mod*C(a+b,a-i)%mod)%mod;
    }
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
Q=int(input())

NumList=[0]*(10**5+1)

AllSum=sum(A)

for a in A:
  NumList[a]+=1

for i in range(Q):
  B,C=map(int,input().split())
  AllSum=AllSum + (C-B)*NumList[B]
  NumList[C]+=NumList[B]
  NumList[B]=0
  
  print(AllSum)

Measured memory_bytes: 84724
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;



int main(){

	int a,b,c,d,e;

	scanf("%d\n%d\n%d\n%d\n%d",&a,&b,&c,&d,&e);

	printf("%d\n",min(a,min(b,c))+min(d,e)-50);

    return 0;
}

Measured memory_bytes: 2680
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::vector<std::vector<int>> g(n);
	for(int i = 0; i < n; i++) {
		std::string s; cin >> s;

		for(int j = 0; j <= i; j++) {
			if(s[j] == '0') continue;
			if(i == j) {
				printf("-1\n");
				return 0;
			}
			
			g[i].push_back(j);
			g[j].push_back(i);
		}
	}

	int cur = 0;
	std::vector<int> vid(n, -1);
	for(int i = 0; i < n; i++) {
		if(vid[i] != -1) continue;

		vid[i] = cur;
		std::queue<int> qu({i});
		while(!qu.empty()) {
			auto v = qu.front(); qu.pop();

			for(auto e: g[v]) {
				if(vid[e] != -1) continue;

				vid[e] = cur;
				qu.push(e);
			}
		}
		cur++;

		qu.push(i);
		std::vector<int> bi(n, -1); bi[i] = 0;
		while(!qu.empty()) {
			auto v = qu.front(); qu.pop();

			for(auto e: g[v]) {
				if(bi[e] != -1) {
					if((bi[v] % 2) == (bi[e] % 2)) {
						printf("-1\n");
						return 0;
					}
					continue;
				}

				bi[e] = 1 - bi[v];
				qu.push(e);
			}
		}
	}

	std::vector<int> ans(cur, 0);
	for(int i = 0; i < n; i++) {
		std::set<int> st({1});
		std::queue<int> qu({i});
		std::vector<int> comp(n, -1); comp[i] = 1;
		while(!qu.empty()) {
			auto v = qu.front(); qu.pop();
			
			for(auto e: g[v]) {
				if(comp[e] != -1) continue;
				
				comp[e] = comp[v] + 1;
				st.insert(comp[e]);
				qu.push(e);
			}
		}
		
		ans[vid[i]] = std::max(ans[vid[i]], (int)st.size());
	}
	int tmp = 0;
	for(auto v: ans) tmp += v;
	printf("%d\n", tmp);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>

using namespace std;

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

  int a=-1,b=-1,c=-1;

  for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
                if((n-i-j >= 0) && (10000*i + 5000*j + 1000*(n-i-j) == y)){
                        a = i;
                        b = j;
                        c = n -i -j;
                }
        }
  }

  if(a == -1){
        cout << "-1 -1 -1" << endl;
  }else{
        cout << a << " " << b << " " << c << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.next().split("");
        int start = 0;
        int end = 0;
        for (int i = 0; i < s.length; i++) {
            if (!"A".equals(s[i])) {
                continue;
            }
            start = i;
            break;
        }
        for (int i = s.length - 1; i >= 0; i--) {
            if (!"Z".equals(s[i])) {
                continue;
            }
            end = i;
            break;
        }
        System.out.println(end - start + 1);
    }

}


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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s; cin >> s;
    if(s=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main()
{
  int N;
  
  cin >> N;
  
  if(N < 1200)
    cout << "ABC" << endl;
  else if(N < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 100001
vector<vector<int> > arr(max1);


int main(){	
	long long int n;
	cin>>n;
	long long int len=0;
	int k=0;
	while(len<n){
		k++;
		len+=(long long)pow(26,k);
		
	}
	//cout<<k<<endl;
	len-=(long long)pow(26,k);
	n-=len;
	int pos=0;
	string ans="";
	//cout<<len<<endl;
	//cout<<k<<" "<<n<<endl;
	for (int i = 0; i <k ; ++i)
	{
		for (int j = 0; j < 26; ++j)
		{
			if(n<=(j+1)*(long long)pow(26,k-i-1) && n >(j)*(long long)pow(26,k-i-1) ){
				ans+='a'+j;
				n-=(j)*(long long)pow(26,k-i-1);
				break;
			}
		}
		//cout<<ans<<" "<<n<<endl;
	}
	cout<<ans<<endl;




}

Measured memory_bytes: 5468
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int K;
  cin >> K;
  vector<int>  A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << A[K-1] << endl;
}


Measured memory_bytes: 256
def get_input():
    N, M =  list(map(int, input().split()))
    routes = {}
    for i in range(M):
        a, b =  list(map(int, input().split()))
        a_idx = a - 1
        b_idx = b - 1
        if a_idx in routes:
            routes[a_idx].append(b_idx)
        else:
            routes[a_idx] = [b_idx]
        
        if b_idx in routes:
            routes[b_idx].append(a_idx)
        else:
            routes[b_idx] = [a_idx]

    return N, M, routes

def write_result(marks, N):
    flag = True
    output_str = ''
    for i in range(1, N):
        if i not in marks:
            flag = False
            break
        output_str += f'{marks[i]+1}\n'
    if flag:
        print('Yes')    
        print(output_str)
    else:
        print('No')

import numpy


marks = {0:0}

N, M, routes = get_input()
mark = {0:0}
start_nodes = [0]
while start_nodes:
    next_nodes = []
    for i in start_nodes:
        for n in routes[i]:
            if n in marks:
                continue
            marks[n] = i
            next_nodes.append(n)
    start_nodes = next_nodes   
write_result(marks, N)

Measured memory_bytes: 66676
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
h = []
m.times do
  h << gets.split.map(&:to_i)
end
i = 0
h.sort_by{|u, v| -v}.each do |x, y|
  break if a[i] >= y
  x.times do
    a[i] = y
    i += 1
    break if i >= n
    break if a[i] >= y
  end
  break if i >= n
end
puts a.inject(:+)

Measured memory_bytes: 21776
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, m);
    vc<int> d(m);
    vc<ll> c(m);
    For(i, m){
        cin >> d[i] >> c[i];
    }
    
    ll sum = 0;
    For(i, m) sum += d[i] * c[i];
    // Cout(sum);
    
    ll ans = 0;
    For(i, m) ans += c[i];
    Cout(ans-1 + ((sum-1)/9));
}



Measured memory_bytes: 2560
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  map<int, int> m;
  for (long long i = 2; i * i <= N; ++i) {
    while (N % i == 0) {
      N /= i;
      ++m[i];
    }
  }
  if (N != 1) ++m[N];
  int cnt = 0;
  for (auto& p : m) {
    for (int i = 1; p.second >= i; ++i) {
      p.second -= i;
      ++cnt;
    }
  }
  cout << cnt << endl;
}


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

using namespace std;

int main(){

  long long int W,H,N;
  cin>>W>>H>>N;

  long long int ans_w_min=0, ans_w_max=W;
  long long int ans_h_min=0, ans_h_max=H;
  
  int ans=0;

  for(int i=0; i<N; i++){
    long long int x, y, a;
    cin>>x>>y>>a;

    if(a==1){
      ans_w_min=max(ans_w_min, x);
    }else if(a==2){
      ans_w_max=min(ans_w_max, x);
    }else if(a==3){
      ans_h_min=max(ans_h_min, y);
    }else if(a==4){
      ans_h_max=min(ans_h_max, y);
    }

    if(ans_w_min>=ans_w_max or ans_h_min>= ans_h_max){
      break;
    }
  }
  
  if(ans_w_min>=ans_w_max or ans_h_min>= ans_h_max){
      cout<<0<<endl;
  }else {
    ans=(ans_w_max-ans_w_min)*(ans_h_max-ans_h_min);
    cout<<ans<<endl;
  }

}


Measured memory_bytes: 3584
#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--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int n, k;
    cin >> n >> k;
    
    COMinit();

    for(int i = 1; i <= k; i++){
        cout << (COM(n-k+1,i) * COM(k-1, i-1))%MOD<< endl;
    }

    return 0;
}


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=(int)sqrt((double)n);++i){
        ans=max(ans,i*i);
    }
    printf("%d\n",ans);
    return 0;
}



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



int main(){
	int n,d;
	while(cin >> n >> d && n){
		vector<int> ms[n];
		int tot[100] = {};
		int l = 0;
		for(int i = 0 ; i < n ; i++){
			int k;
			cin >> k;
			l += k;
			while(k--){
				int t;
				cin >> t;
				ms[i].push_back(t);
				tot[i] += t;
			}

		}
		for(int i = 0 ; i < l ; i++){
			pair<int,int> idx = {1e9,-1};
			for(int j = 0 ; j < n ; j++){
				if( ms[j].size() ){
					int s = ms[j].back();
					int mi=1e9,mx=-1e9;
					for(int k = 0 ; k < n ; k++){
						int v = k == j ? tot[j] - s : tot[k];
						mi = min(mi,v);
						mx = max(mx,v);
					}
					idx = min(idx,make_pair(mx-mi,j));
				}
			}
			//cout << idx.first << " " << idx.second << endl;
			if( idx.first > d ){
				cout << "No" << endl;

				goto ex;
			}
			tot[idx.second] -= ms[idx.second].back();
			ms[idx.second].pop_back();
		}
		cout << "Yes" << endl;
		ex:;
	}
}

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

using ll = long long int;
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M) % M;
}

Int f (Int x) {
    Int ret = 0;
    while (x > 0) {
        Int b = __builtin_popcount(x);
        x %= b;
        ret++;
    }
    return ret;
}

int main() {
    Int n;
    string s;
    cin >> n >> s;
    Int cnt = 0;
    for (Int i = 0; i < (Int)n; i++) {
        if (s[i] == '1') cnt++;
    }
    Int x = 0, y = 0;
    for (Int i = 0; i < n; i++) {
        if (s[i] == '1') {
            if (cnt - 1 > 0) {  
                x += RepeatSquaring(2, n - 1 - i, cnt - 1);
                x %= (cnt - 1);
            }
            if (cnt + 1 <= n) {
                y += RepeatSquaring(2, n - 1 - i, cnt + 1);
                y %= (cnt + 1);
            }
        }
    }
    for (Int i = 0; i < n; i++) {
        if (s[i] == '0') {
            Int tmp = y;
            Int add = RepeatSquaring(2, n - 1 - i, cnt + 1);
            tmp = (add + tmp) % (cnt + 1);
            // print("aaa");
            // print(y);
            // print((num + (1<<((n - 1) - i))) % (cnt + 1));
            print(f(tmp) + 1);
        } else {
            if (cnt == 1) {
                print(0);
            } else {
                Int tmp = x;
                Int sub = RepeatSquaring(2, n - 1 - i, cnt - 1);
                tmp = (tmp - sub + (cnt - 1)) % (cnt - 1);
                print(f(tmp) + 1);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double pi = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

int main(){
    int N,M;
    cin >> N >> M;
    vector<priority_queue<int,vector<int>,greater<int>>> p(N+1);
    vector<map<int,int>> m(N+1);
    vector<pair<int,int>> query(M);
    for(int i = 0; i < M ;i++){
        int pre,y;
        cin >> pre >> y;
        query[i] = make_pair(pre,y);
        p[pre].push(y);
    }
    for(int i = 1; i <= N;i++){
        if(p[i].empty()) continue;
        int k = p[i].size();
        for(int count = 1; count <= k; count++){
            m[i][p[i].top()] = count;
            p[i].pop();
        }
    }
    for(auto pa : query)
        printf("%06d%06d\n",pa.first,m[pa.first][pa.second]);
    return 0;
}

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

long long n;
vector<long long> p;

long long solve();

int main() {
  cin >> n;
  p.resize(n);
  for(int i = 0; i < n; ++i) cin >> p[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0, now = 1e9;
  for(int i = 0; i < n; ++i)
    if(now > p[i]) {
      ++res;
      now = p[i];
    }
  return res;
}

Measured memory_bytes: 1792
import math
import itertools

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

def get_dist(a, b):
    return math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)

ans = 0
n = 0
for p in itertools.permutations(xy, N):
    d = 0
    for i in range(len(p)-1):
        d += get_dist(p[i], p[i+1])
    ans += d
    n += 1

print(ans / n)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int a[2010];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int ans = 0;
	sort(a,a+n);
	for(int i=1;i<n;i++)
	{
		int k = 0;
		for(int j = i+1;j<n;j++)
		{
			while(k<i&&a[i]+a[k]<=a[j])k++;
			ans+=i-k; 
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int N = 100;

int main(){
  int i, j, n, u, k, v;
  int A[N][N];

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    for(j = 0;j < n; j++){
      A[i][j] = 0;
    }
  }

  for(i = 0; i < n; i++){
    scanf("%d", &u);
    scanf("%d", &k);
    //u--;
    
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      //v--;
      A[u-1][v-1] = 1;
    }
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(j != 0){
	printf(" ");
      }
      
      printf("%d" , A[i][j]);
    }
    
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2044
sx, sy, tx, ty = map(int,raw_input().split())
a = tx - sx
b = ty - sy
S = 'R' * a + 'U' * b + 'L' * a + 'D' * b
S += 'D' + 'R' * (a+1) + 'U' * (b+1) + 'L' + 'U' + 'L' * (a+1) + 'D' * (b+1) + 'R'
print S


Measured memory_bytes: 2692
Option Strict On
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim K As Integer = NextInt()
        Dim S As Integer = NextInt()

        Dim ans As Integer = 0

        For x As Integer = 0 To K
            For y As Integer = 0 To K
                Dim z As Integer = S - x - y

                If 0 <= z AndAlso z <= K Then
                    ans += 1
                End If
            Next
        Next

        WriteLine(ans)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


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

int main(){
  int a[10];
  rep(i,5){
    cin>>a[i];
    if(a[i]==0){
      cout<<i+1;
      return 0;
    }
  }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int p[10]={0,2,5,5,4,5,6,3,7,6},a[10],n,m,f[10002],v[10];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&a[i]);
		v[a[i]]=1;
	}
	memset(f,-1,sizeof(f));
	f[0]=0;
	for(int i=1;i<=m;i++)
		for(int j=p[a[i]];j<=n;j++)
			f[j]=max(f[j],f[j-p[a[i]]]+1);
  	int tmp=f[n];
	for(int i=1;i<=tmp;i++)
		for(int j=9;j>=1;j--)
			if(v[j]&&p[j]<=n&&f[n-p[j]]==f[n]-1)
			{
				printf("%d",j);
				n-=p[j];
				break;
			}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;

#define loop(i,first,end) for(int i=(first);i<(end);i++)
#define uint unsigned int
#define ull unsigned long long
#define ll long long
#define vint vector<int>
#define vuint vector<unsigned int>
#define vull vector<ull>
#define vll vector<ll>
#define init(type,var) type var;cin>>var;
#define vinit(vtype,var,n) vtype var(n);loop(i,0,n)cin>>var[i];

const ull MOD = 1000000007ULL;
const ull INF = (ull)(-1LL);

int main(void){
	int a, b, c;
	cin >> a >> b >> c;
	a -= b;
	c -= a;
	if (c < 0)c = 0;

	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
using namespace std;

int H;
vector<int> v;

int main() {
  cin >> H;
  v.resize(H + 1);
  rep1(i, H) {
    cin >> v[i];
  }
  rep1(i, H) {
    cout << "node " << i << ": ";
    cout << "key = " << v[i] << ", ";
    if (i != 1) cout << "parent key = " << v[i / 2] << ", ";
    if (2 * i <= H) cout << "left key = " << v[2 * i] << ", ";
    if (2 * i + 1 <= H) cout << "right key = " << v[2 * i + 1] << ", ";
    cout << endl;
  }
  return 0;
}



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

int INF = 1e9;

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

  int c1 = A * X + B * Y;
  int c2 = (X > Y) ? A * (X - Y) + 2 * C * Y : B * (Y - X) + 2 * C * X;
  int c3 = (X > Y) ? 2 * C * X : 2 * C * Y;
  cout << min({c1, c2, c3}) << endl;
}

Measured memory_bytes: 256
-- bubble sort
iter :: [Int] -> (Bool,Int,[Int])
iter []     = (False,0,[])
iter (x:[]) = (False,0,(x:[]))
iter (x0:x1:xs) =
  let (f,n,x) = if x0 > x1
                then iter (x0:xs)
                else iter (x1:xs)
  in
    if x0 > x1
    then (True,n+1,x1:x)
    else (f,   n  ,x0:x)

ans n x = 
  let (f,n',x') = iter x
  in 
    if f
    then ans (n'+n) x'
    else (n'+n,x')

ans' (0:_) = []
ans' (n:x) =
  let d = take n x
      r = drop n x
  in
    (ans 0 d):(ans' r)

main = do
  c <- getContents
  let i = map read $ lines c :: [Int]
      o = ans' i
  mapM_ (\(n,_) -> print n) o

Measured memory_bytes: 5464
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = x / 500;
        int b = (x % 500) / 5;
        System.out.println(1000*a + 5*b);
    }
}

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

using namespace std;
const int N=1e5+10;

int n, x, a[N];

int main() {
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>x;
		a[x]=i;
	}
	for(int i=1; i<=n; i++) {
		cout<<a[i];
		if (i==n) cout<<endl;
		else cout<<' ';
	}
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = pow(10, 9) + 7;
//const int mod = 998244353;
//const int mod = ;
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N, K;
  cin >> N >> K;
  vector<int> V(N);
  for (int i = 0; i < N; i++)
  {
    cin >> V.at(i);
  }
  
  int ans = -INF;
  for (int a = 0; a <= K; a++)
  {
    for (int b = 0; b <= K; b++)
    {
      if (a + b > K) break;
      int aa = min(a, N);
      int bb = min(b, N - aa);
      int cd = min(K / 2, K - a - b);
      
      vector<int> hv;
      for (int i = 0; i < aa; i++)
      {
        hv.push_back(V.at(i));
      }
      for (int i = 0; i < bb; i++)
      {
        hv.push_back(V.at(N - i - 1));
      }
      
      sort(hv.begin(), hv.end(), greater<int>());
      //cout << hv.size() << " " << a << " " << b << " " << cd << endl;
      //cout << cd << " " << hv.size() << " ";
      cd = min((int)cd, (int)hv.size());
      
      int val = 0;
      for (int i = 0; i < hv.size() - cd; i++)
      {
        val += hv.at(i);
      }
      chmax(ans, val);
      
      cd = max((int)0, cd - 1);
      //cout << cd << endl;
      
      val = 0;
      for (int i = 0; i < hv.size() - cd; i++)
      {
        val += hv.at(i);
      }
      chmax(ans, val);
      //cout << a << " " << b << " " << cd << " " << val << endl;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 384
N,A,B = map(int,input().split())
sum = 0
array = []
for i in range(1,N+1):
    array.append(list(str(i)))

for i in range(N):
    value = 0
    for j in range(len(array[i])):
        value += int(array[i][j])
    if A <= value <= B:
        sum += int(''.join(array[i]))
print(sum)        



Measured memory_bytes: 4340
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH RANJAN******************************************************
***********************************************************************************************/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i,n) for(int i=0;i<(int)n;i++)
#define frs(i,a,b) for(int i = a;i<b;i++)
#define meme(a,b,c) memset(a,b,sizeof(c)); //works only for 0 and -1
int main(){
  fast();
  int n;
  cin>>n;
  vector<ll> v(n);
  fr(i,n)cin>>v[i];
  int ans = 0;
  sort(v.begin(),v.end());
  fr(i,n-2)
    frs(j,i+1,n-1)
    	frs(k,j+1,n){
  if(v[i]!=v[j]&&v[j]!=v[k]&&v[k]!=v[i]&&v[i]+v[j]>v[k])ans++;
  }
  cout<<ans;
 return 0;
  
}




Measured memory_bytes: 3656
while 1:
    n=int(input())
    if n==0:break
    ap=0
    bp=0
    for i in range(n):
        a,b=map(int,input().split())
        if a>b:
            ap+=a+b
        elif a<b:
            bp+=a+b
        elif a==b:
            ap+=a
            bp+=b
    print(ap,bp)


Measured memory_bytes: 5612
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
#define rep(i,m) for(int i=0;i<(n);i++)
using namespace std;
const int MAX = 100005;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main(){
  ll n; cin >> n;
  ll b[n];
  rep(i,n-1) cin >> b[i];
  ll a[n];
  a[0] = b[0];
  for(int i=1;i<n-1;i++){
    a[i] = min(b[i-1],b[i]);
  }
  ll ans = 0;
  a[n-1] = b[n-2];
  rep(i,n){
    ans += a[i];
  }
  cout << ans;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;


immutable long MOD = 10^^9+7;


void main() {
    auto N = readln.chomp.to!int;
    auto cnt = new long[](10^^3+1);
    fill(cnt, 0);
    foreach (i; 2..N+1) {
        int j = 2;
        while (j * j <= i) {
            while (i % j == 0) {
                i /= j;
                cnt[j]++;
            }
            j++;
        }
        if (i > 1)
            cnt[i]++;
    }

    long ans = 1;
    foreach (i; 2..N+1) {
        ans = (ans * (cnt[i]+1)) % MOD;
    }
    ans.writeln;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 1e9+7
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PI 4*atan(1)

using namespace std;

int main()
{
   ll a,b,c; cin >> a >> b >> c;
   ll d = a/b;
   if (a%b != 0) d++;
   cout << c*d;
}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main(void)
{
	int w,h,x,y,r;
	cin >> w >> h >> x >> y >> r;
	if(x+r<=w&&x-r>=0&&y+r<=h&&y-r>=0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
#define FOR(i, m, n) for(int i = m;i < n;i++)
int MAX_N = 100000;
#define REP(i, n) for(int i = 0;i < n;i++)
int MAX_W = 100000;
int chnage(int X){
  if( X == 9){
    return 1;
  }else{
    return 9;
  }
}
int main(){
  int N;cin >> N;
  REP(i,9){
    if(111* i < N && N <= 111 * (i+1)){
      cout << 111 * (i+1) << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main() {
    int n;
    cin >> n;
    vector<int> a(n+1), b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];

    ll ans = 0;

    for(int i = 0; i < n; i++){
        ans += min(a[i], b[i]);
        b[i] = max(0, b[i]-a[i]);
        ans += min(a[i+1], b[i]);
        a[i+1] = max(0, a[i+1] - b[i]);
    }
    cout << ans << endl;
}


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

int main() {
  int64_t N, A, B;
  int64_t count=0;
  
  cin >> N >> A >> B;
  
  int64_t sub=N/(A+B);
  
  count=N-sub*(A+B);
  
  count =sub*A + min(count,A);
  
  cout << count;
  
  return 0;
}


Measured memory_bytes: 256
// D - Ki
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

// void abprn(vvi &vv, int n){
// 	for(int i=0; i<n; i++){
// 		cout<<i<<") "; for(auto e:vv[i]) cout<<e<<",\t"; cout<<"\n";
// 	}
// }

void dfs(vvi &ab, vi &ans, int cur, int pre){
	for(int nxt:ab[cur]){
		if(nxt==pre) continue;
		ans[nxt] += ans[cur];
		dfs(ab,ans,nxt,cur);
	}
}

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

	vvi ab(n);
	for(int i=0; i<n-1; i++){
		int a,b; cin>>a>>b;
		ab[--a].push_back(--b);
		ab[b].push_back(a);
	}

	vi ans(n);
	for(int i=0; i<q; i++){
		int p,x; cin>>p>>x;
		ans[--p] += x;
	}
	// abprn(ab, n);//
	// for(int i=0; i<n; i++) cout<< ans[i] <<(i<n-1?" ":"\n");//

	dfs(ab,ans,0,-1);

	for(int i=0; i<n; i++) cout<< ans[i] <<(i<n-1?" ":"\n");
}

Measured memory_bytes: 29696
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

double A;
double B;
ll A2;
ll B2;
ll N;

double t0;
ll t1;
ll t11;
ll t2;
ll maxV=0;
int main(){
    cin >> A;
    cin >> B;
    cin >> N;
    A2 = A;
    B2 = B;

    t0 = A/B;
    t1 = t0 * N;
    t2 = N/B;
    t2 = t2 * A;
    maxV = max(maxV,t1 - t2);

    if(N<B){
        cout << maxV << endl;        
    }else{
        N = B -1;
        t0 = A/B;
        t1 = t0 * N;
        t2 = N/B;
        t2 = t2 * A;
        maxV = max(maxV,t1 - t2);
        cout << maxV << endl;        
    }
}

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

static const int Max = 200000;

int main() {
	int R[Max], n;

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

	int maxv = (R[1]-R[0]);
	int minv = R[0];
	
	for (int i = 1; i<n; i++) {
		if (maxv < (R[i] - minv)) {
			maxv = (R[i] - minv);
		}
		if (minv > R[i]) {
			minv = R[i];
		}
	}

	cout << maxv << endl;

}


Measured memory_bytes: 3888
N = int(input())
S = input()
R = set()
G = set()
B = set()
for i in range(N):
  if S[i] == 'R':
    R.add(i)
  elif S[i] == 'G':
    G.add(i)
  else:
    B.add(i)

# print(R,G,B)
x = 0
for i in R:
  for j in G:
    if (i - j) % 2 == 0 and (i + j) // 2 in B:
      x -= 1
    if 2 * j - i in B:
      x -= 1
    if 2 * i - j in B:
      x -= 1
    # print(i,j,x)
x += len(R) * len(B) * len(G)
print(x)


Measured memory_bytes: 9380