akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int N; cin>>N;
  vector<int> x(N, 0);
  vector<int> y(N, 0);
  vector<int> h(N, 0);
  int aa = 0;
  for (int i=0; i<N; i++) {
    cin>>x[i]>>y[i]>>h[i];
    if (h[i]>0) aa=i;
  }
  int height;
  for (int i=0; i<=100; i++) {
    for (int j=0; j<=100; j++) {
      height = h[aa] + abs(x[aa]-i) + abs(y[aa]-j);
      for (int k=0; k<N; k++) {
        if (max(height-(int)abs(x[k]-i)-(int)abs(y[k]-j), 0) != h[k]) {
          break;
        }
        if (k==N-1) {
          cout << i << " " << j << " " << height << endl;
          return;
        }
      }
    }
  }
}

int main()
{
  solve();
  return 0;
}


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

int main() {
  int a, b, ans;
  char op;
  while(true) {
    scanf("%d %c %d", &a, &op, &b);
    if(op == '?') break;
    else if(op == '+') ans = a + b;
    else if(op == '-') ans = a - b;
    else if(op == '*') ans = a * b;
    else ans = a / b;
    printf("%d\n", ans);
  }
}


Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using pint = pair<int,int>;

int N, M;
vector<vector<bool> > G;
vector<int> deg;

bool ok = true;
vector<bool> seen;
vector<pint> res;
void rec(int v, int p) {
    seen[v] = true;
    for (int nv = 0; nv < N; ++nv) {
        if (seen[nv]) continue;
        if (G[v][nv]) continue;
        rec(nv, v);
    }
    if (deg[v] & 1) {
        if (p == -1) ok = false;
        else {
            res.push_back(pint(v, p));
            ++deg[v]; ++deg[p];
            G[v][p] = 1; G[p][v] = 1;
        }
    }
}

vector<int> temp;
vector<vector<int> > comp;
void rec2(int v) {
    seen[v] = true;
    for (int nv = 0; nv < N; ++nv) {
        if (nv == v) continue;
        if (seen[nv]) continue;
        if (!G[v][nv]) continue;
        rec2(nv);
    }
    temp.push_back(v);
}

void solve() {
    ok = true;
    seen.assign(N, 0);
    res.clear();
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue;
        rec(v, -1);
    }
    
    // cannot
    if (!ok) {
        cout << -1 << endl;
        return;
    }
    
    // decomposition
    seen.assign(N, 0);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue;
        temp.clear();
        rec2(v);
        comp.push_back(temp);
    }

    // reconstruct
    if (comp.size() == 2) {
        if (comp[0].size() > comp[1].size()) swap(comp[0], comp[1]);
        if (comp[0].size() == 1) {
            int t = comp[0][0];
            int u = -1, v = -1;
            for (int i = 0; i < comp[1].size(); ++i) {
                for (int j = i + 1; j < comp[1].size(); ++j) {
                    int cu = comp[1][i], cv = comp[1][j];
                    if (!G[cu][cv]) u = cu, v = cv;
                }
            }
            if (u == -1) {
                if (res.size() == 0) {
                    cout << -1 << endl;
                    return;
                }
                u = res.back().first;
                v = res.back().second;
                res.pop_back();
            }
            else {
                res.push_back(pint(u, v));
            }
            res.push_back(pint(t, u));
            res.push_back(pint(t, v));
        }
        else {
            for (int it = 0; it < 2; ++it) {
                for (int it2 = 0; it2 < 2; ++it2) {
                    res.push_back(pint(comp[0][it], comp[1][it2]));
                }
            }
        }
    }
    else if (comp.size() > 2) {
        for (int i = 0; i < comp.size(); ++i) {
            int j = (i + 1) % comp.size();
            res.push_back(pint(comp[i][0], comp[j][0]));
        }
    }
    
    // output
    cout << res.size() << endl;
    for (auto &p : res) {
        if (p.first > p.second) swap(p.first, p.second);
        cout << p.first + 1 << " " << p.second + 1 << endl;
    }
}

int main() {
    cin >> N >> M;
    G.assign(N, vector<bool>(N, 0));
    deg.assign(N, 0);
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        G[a][b] = G[b][a] = 1;
        deg[a]++; deg[b]++;
    }
    solve();
}


Measured memory_bytes: 3184
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        long N = scan.nextLong();
        long A = scan.nextLong();
        long B = scan.nextLong();

        long a = N-A;
        long b = B-1;
        long ans = Math.min(a, b);

        if((A+B)%2 == 0){
            ans = Math.min((A+B)/2-A, ans);
        }else{
            long c = (B-A-1)/2+A;
            long d = (N-(A+(N-B+1)))/2+(N-B+1);
            long e = Math.min(c, d);
            ans = Math.min(e, ans);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 24148
#include<stdio.h>
#include <string.h>
#include<math.h>
#include<iostream>
using namespace std;

int main()
{
    int N, D;
    char c[3];
    int count = 0;
    int max = 0;


    cin >> c[0] >> c[1] >> c[2];

    for (int i = 0; i < 3; i++) {
        if (c[i] == 'S')
            count = 0;
        else {
            count++;
            if (count > max)
                max = count;
        }

    }

    cout << max << endl;


    return 0;
}

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

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
#define tmp template<class t>

tmp void chmax(t&a,t b){if(a<b)a=b;}
tmp void chmin(t&a,t b){if(a>b)a=b;}

tmp using vc=vector<t>;
tmp using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fs<<","<<p.sc<<"}";
}

tmp ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

constexpr ll ten(int n){
	return n==0?1:ten(n-1)*10;
}

tmp void mkuni(vc<t>&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

ll read(){ll i;cin>>i;return i;}

using ld=long double;
using cm=complex<ld>;
#define x real()
#define y imag()
const ld eps=1e-8;
int sgn(ld a){return a<-eps?-1:(a>eps?1:0);}
auto cmcmp=[](const cm&a,const cm&b){
	if(sgn(a.x-b.x))return a.x<b.x;
	else return sgn(a.y-b.y)<0;
};

struct ln{
	cm a,b;
	cm dir(){return b-a;}
};
ld dot(cm a,cm b){return a.x*b.x+a.y*b.y;}
ld crs(cm a,cm b){return a.x*b.y-a.y*b.x;}
int ccw(cm a,cm b){return sgn(crs(a,b));}
int ccw(cm a,cm b,cm c){return ccw(b-a,c-a);}
int ccw(ln a,cm b){return ccw(a.a,a.b,b);}

//(-2)[a,-1](0)[b,1](2)
int bet(cm a,cm b,cm c){
	cm d=b-a;
	ld e=dot(d,c-a);
	if(sgn(e)<=0)return sgn(e)-1;
	return sgn(e-norm(d))+1;
}

ld tri2(cm a,cm b,cm c){
	return crs(b-a,c-a);
}

ld area2(const vc<cm>&a){
	int n=a.size();
	ld b=0;
	rep(i,n)
		b+=crs(a[i],a[(i+1)%n]);
	return b;
}

struct cr{
	cm c;
	ld r;
};

//0-apart,1-coinside,2-a<b,3-a<=b,4-a>b,5-a>=b,6-a touch b,7-a cross b
int intcc(cr a,cr b){
	ld c=abs(a.c-b.c);
	if(sgn(c)==0&&sgn(a.r-b.r)==0)return 1;
	int d=sgn(c+a.r-b.r);
	if(d<=0)return d+3;
	int e=sgn(c+b.r-a.r);
	if(e<=0)return e+5;
	int f=sgn(a.r+b.r-c);
	if(f>=0)return f+6;
	return 0;
}

cm readcm(){
	ld a,b;
	cin>>a>>b;
	return cm(a,b);
}

ld readld(){
	ld a;
	cin>>a;
	return a;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(1);
	
	int n=read();
	rep(_,n){
		cr a{readcm(),readld()};
		cr b{readcm(),readld()};
		int c=intcc(a,b);
		if(c==0)
			cout<<0<<endl;
		else if(c==1)
			assert(false);
		else if(c==2)
			cout<<-2<<endl;
		else if(c==4)
			cout<<2<<endl;
		else
			cout<<1<<endl;
	}
}



Measured memory_bytes: 3320
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(int i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define fill(a) memset(a,0,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    ll n,m;
    cin>>n>>m;
    ll sum=0,a;
    rep(i,0,m)
    {
        cin>>a;
        sum+=a;
    }
    if(sum<=n)
        cout<<n-sum<<endl;
    else
        cout<<-1<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100000+5
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(int &f){
	f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
int n,m,q;
int p[55];
int a[55],b[55],c[55],d[55];
int ans=0;
void make(int pos,int tot,int last){
    if(pos==tot+1){
        int cnt=0;
        for(int i=1;i<=q;i++){
            if(p[b[i]]-p[a[i]]==c[i]){
                cnt+=d[i];
            }
        }
        ans=max(ans,cnt);
        return ;
    }
    for(int i=last;i<=m;i++){
        p[pos]=i;
        make(pos+1,tot,i);
        p[pos]=0;
    }
}
int main()
{
    read(n),read(m),read(q);
    for(int i=1;i<=q;i++){
        read(a[i]),read(b[i]),read(c[i]),read(d[i]);
    }
//    if(n<=8 && m<=8){
        for(int i=1;i<=m;i++){
        	p[1]=i;
            make(2,n,i);
        }
        cout<<ans<<endl;
        return 0;
//    }
    
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int>V;
	int h;
	for (int i = 0; i < N; ++i) {
		cin >> h;
		V.push_back(h);
	}
	sort(V.begin(), V.end());
	int M = INF;
	for (int i = 0; i < N - K + 1; ++i) {
		M = min(M,V[i + K-1] - V[i]);
	}
	cout << M << endl;
	return 0;
}

Measured memory_bytes: 892
n, m = list(map(int, input().split()))


connections = dict()
answer = 'IMPOSSIBLE'


def add_to_set(a, b):
    if a in connections:
        connections[a].add(b)
    else:
        connections[a] = set([b])

    if b in connections:
        connections[b].add(a)
    else:
        connections[b] = set([a])


for i in range(m):
    a, b = list(map(int, input().split()))
    add_to_set(a, b)

island_1 = connections.get(1)
island_N = connections.get(n)


for e in island_1:
    if island_N and e in island_N:
        answer = 'POSSIBLE'

print(answer)

Measured memory_bytes: 77580
#include <bits/stdc++.h>
using namespace std;
long long solve(int arr[], int n, int k) {
	long long dp[n];
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		long long ans = INT_MAX;
		for (int j = 1; j <= k; j++) {
			if (i - j >= 0) {
				ans = min(ans, abs(arr[i] - arr[i - j]) + dp[i - j]);
			}
		}
		dp[i] = ans;
	}
	return dp[n - 1];
}
int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif
	int n, k;
	cin >> n >> k;
	int arr[100000];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	cout << solve(arr, n, k);

	return 0;
}

Measured memory_bytes: 4812
s = input()
if len(s) == 2:
    if s[0] == s[1]:
        print(1, 2)
    else:
        print(-1, -1)
else:
    for i in range(len(s)-2):
        if len(set(s[i:i+3])) < 3:
            print(i+1, i+3)
            exit()
    print(-1, -1)

Measured memory_bytes: 3188
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n,m;
int ar[200005];

int xs[200005];

int dp[2000005];
int main(){
  cin>>n;
  int sum=0;
  REP(i,n-1) scanf("%d",&ar[i]),sum+=ar[i];
  sum-=ar[0]+ar[1];

  const int MX=1000002;
  int s=1000000;
  REP(i,MX) dp[s+i]=i;
  REPN(i,n-1,2){
    int p=ar[i];
    REP(j,p) dp[s-1-j]=dp[s+j+1];
    s-=p;
  }
  cin>>m;
  REP(i,m){
    int x;
    scanf("%d",&x);

    int res;
    if(x>=MX){
      res=x-sum;
    }else{
      res=dp[s+x];
    }
    res+=ar[0]-ar[1];
    printf("%d\n",res);
  }
  return 0;
}





Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
////////////////////////////////////////////////////////////////////
int main()
{
    string S; cin >> S;
    ll ans=0;

    for(int bit=0; bit < (1<<S.size()-1); ++bit){
        ll num=S[0]-'0';
        //cout << "before num= " << num << endl;
        for(int i=0; i<S.size()-1; ++i){
            if(bit & (1<<i)){
                ans+=num;
                num=0;
            }
            num = num*10 + (S[i+1]-'0');
            //cout << "after num= " << num << endl;
        }
        ans+=num;
        //cout << "ans= " << ans << endl;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int N,i,j,s;
    cin>>N;
    int d[N];
    s=0;
    for(i=0;i<N;i++)
        cin>>d[i];
    for(i=0;i<N;i++){
        for(j=i+1;j<N;j++)
            s=s+d[i]*d[j];
    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 256
N = gets.strip.to_i
p = gets.strip.split.map(&:to_i)

c=0
p.each_with_index do |a,i|
    if a!=(i+1)
        c+=1
    end
end

if c==2 || c==0
    puts 'YES'
else
    puts 'NO'
end

Measured memory_bytes: 1788
import heapq
nk = input()
allp = input()
nklis = nk.split(" ")
plis = allp.split(" ")
plis = [int(n) for n in plis]
n = int(nklis[0])
k = int(nklis[1])
print(sum(heapq.nsmallest(k, plis)))

Measured memory_bytes: 9196
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const int MAX = 100000;
static const int NIL = -1;
using namespace std;


int main() {

    string s[3]; cin >> s[0] >> s[1] >> s[2];
    queue<char> q[3];
    char turn = 'a';
    rep(i,s[0].size()) q[0].push(s[0][i]);
    rep(i,s[1].size()) q[1].push(s[1][i]);
    rep(i,s[2].size()) q[2].push(s[2][i]);

    while(1){
        if(turn == 'a' && q[0].empty()) {
            cout << 'A';
            return 0;
        }else if(turn == 'b' && q[1].empty()){
            cout << 'B';
            return 0;
        }else if(turn == 'c' && q[2].empty()){
            cout << 'C';
            return 0;
        }
        if(turn == 'a'){
            turn = q[0].front();
            q[0].pop();
        }else if(turn == 'b'){
            turn = q[1].front();
            q[1].pop();
        }else {
            turn = q[2].front();
            q[2].pop();
        }
    }

    return 0;
}


Measured memory_bytes: 3584
/*...................bismillahir rahmanir rahim.....................*/
#include<bits/stdc++.h>
 
#define m_p make_pair
#define PB push_back
#define FF first
#define SS second
#define PII pair<int,int>
#define PSS pair<string,string>
#define MX 1000007
#define MOD 1000000007
#define SI(a)({ ;scanf("%d",&a);a;})
#define SC(a)({ ;scanf("%c",&a);a;})
#define SL(a)({ ;scanf("%lld",&a);a;})
#define SD(a)({ ;scanf("%lf",&a);a;})
#define FI freopen("input.txt","r+",stdin);
#define FO freopen("output.txt","w+",stdout);
using namespace std;
 
typedef long long LL; 
 
/*............start.............*/

void solve()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22) cout<<"bust\n";
    else cout<<"win\n";
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int q=1;
    // cin>>q;
    for(int kase=1;kase<=q;kase++)
    {
        //cout<<"Case "<<kase<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
using System;

namespace ChokudaiScanner
{
    class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();

            int N = cin.NextInt();
            int[] X = cin.ArrayInt(N);
            int sum = 0;

            for(int i = 0; i < N; i++)
            {
                sum += X[i];
            }
            sum /= N;
            int sumA = sum + 1;
            int sumB = sum - 1;
            long[] hp = new long[3];

            for(int i = 0; i < N; i++)
            {
                hp[0] += (X[i] - sum) * (X[i] - sum);
                hp[1] += (X[i] - sumA) * (X[i] - sumA);
                hp[2] += (X[i] - sumB) * (X[i] - sumB);
            }
            Array.Sort(hp);

            Console.WriteLine(hp[0]);
        }
    }
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayNext(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Next();
            }
            return Array;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}



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

int main() {
	int N,t;
	cin >> N >> t;
	long long arr[N];
	long long sum=0;
	for (int i=0; i<N; i++){
		cin>>arr[i];
	}
	for (int i=1; i<N; i++){
		int add = t<(arr[i]-arr[i-1]) ? t : (arr[i]-arr[i-1]);
		sum+=add;
	}
	sum += t;
	
	cout << sum << "\n";
}

Measured memory_bytes: 1792
N=int(input())
A=[0]*N
B=list(map(int,input().split()))
for i in range(N):
  if i==0:
    A[i]=B[i]
  elif i==N-1:
    A[i]=B[i-1]
  else:
    A[i]=min(B[i-1],B[i])
print(sum(A))

Measured memory_bytes: 3064
/***
*	?????§?????????
****/

#include <iostream>
#include <vector>
using namespace std;

int main(void)
{
	int  n;
	cin >> n ;
	vector<int> fxR(n);
	
	for(int t=0; t< n; t++){
		cin >> fxR[t];
	}
	
	int maxR = fxR[1] - fxR[0];
	int minR = fxR[0];
	
	for(int j =1; j<n ; j++){	//n???????????????????????°??????????¢????
		if( maxR < (fxR[j]-minR)){
			maxR = fxR[j]-minR;
		}
		if( minR > fxR[j]){
			minR = fxR[j];
		}
	}
	
	cout << maxR << endl;//?????§???????????¨?????????

	return 0;
}

Measured memory_bytes: 1796
import math

n ,p = map(int, input().split())

p_part_list = {}


for i in range(2,int(math.sqrt(p)) +1):
  if p % i == 0:
    while (p % i == 0):
      if i not in p_part_list:
        p_part_list[i] = 1
        p = p // i
      else:
        p_part_list[i] += 1
        p = p // i
      
if p > 1:
  p_part_list[p] = 1
  
max_num = 1
#print(p_part_list)

for num in p_part_list:
  if p_part_list[num] >= n:	# N個の整数にその数を最低１個割り振れるかチェック
   # if max_num < num ** int(p_part_list[num]/n): #均等に割り振れれば、振り振る（１個以上可）
    max_num *= num ** int(p_part_list[num]/n)
    
print(max_num)




Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

bool kaibun(ll a){
  string s=to_string(a);
  ll n=s.size();
    bool ok=true;
    for(ll i=0;i<n/2;i++)if(s[i]!=s[n-1-i])ok=0;
    if(ok)return 1;
    else return 0;
}

int main(){

  ll a,b;
  cin >> a >> b;

  ll ans=0;
  for(ll i=a;i<=b;i++)if(kaibun(i))ans++;

  cout << ans << endl;

}

Measured memory_bytes: 3768
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N, P;
  cin >> N >> P;
  if (N == 1) {
    cout << P << endl;
    return 0;
  }
  int s = sqrt(P) + 1;
  vector<bool> sieve(s, true);
  map<int, int> m;
  for (int i = 2; i != s; ++i) {
    if (!sieve[i]) {
      continue;
    }
    while (P % i == 0) {
      ++m[i];
      P /= i;
    }
    if (P == 1) break;
    for (int j = 2 * i; j < s; j += i) sieve[j] = false;
  }

  int ans = accumulate(begin(m), end(m), 1, [&](int a, auto p) {
    int n = p.second / N;
    while (n--) a *= p.first;
    return a;
  });
  cout << ans << endl;
}


Measured memory_bytes: 3728
from itertools import accumulate
n,k=map(int,input().split())
x=list(map(int,input().split()))
x_pos=list(filter(lambda x: x>=0,x))
x_neg=list(filter(lambda x:x<0,x))
x_neg=list(map(lambda x: -x , x_neg))
x_pos.sort()
x_neg.sort()
#print(x)
#print(x_pos)
#print(x_neg)
ans=float('inf')
if k<=len(x_pos):
    ans=min(ans,x_pos[k-1])
if k<=len(x_neg):
    ans=min(ans,x_neg[k-1])
for i in range(len(x_pos)):
    if k-2-i<len(x_neg) and k-2-i>=0:
        ans=min(ans,2*x_pos[i]+x_neg[k-2-i],2*x_neg[k-2-i]+x_pos[i])
print(ans)




Measured memory_bytes: 14452
#include <bits/stdc++.h>
#define ref(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef pair<int,int> P;

int h,w,k,a[200001],b[200001];
int x1,x2,yy1,y2;

queue<P> q;

int main()
{
    cin>>h>>w>>k>>x1>>yy1>>x2>>y2;
    vector<vector<int>> dp,us;
    vector<int>v(w+1);
    ref(i,h+1) dp.push_back(v);
    us=dp;
    ref(i,h)ref(j,w) {
        char h;
        cin>>h;
        if(h=='@')us[i][j]=1;}

        q.push(make_pair(x1,yy1));
        while(q.size()){
                P p=q.front();
                q.pop();
                int f=p.first,r=p.second;
 //cout<<f<<" "<<r<<endl;
                if(f==x2&&r==y2) break;
            ref(i,min(k,h-p.first))
                if(!dp[i+f][r]&&!us[i+f][r]) {
                    dp[i+f][r]=dp[f][r]+1;
                q.push(make_pair(f+i,r));}
                else if(dp[i+f][r]>dp[f][r]&&!us[i+f][r]) continue;
                else break;
            ref(i,min(k,p.first-1))
                if(!dp[f-i][r]&&!us[f-i][r]) {
                    dp[f-i][r]=dp[f][r]+1;
                q.push(make_pair(f-i,r));}
                else if(dp[f-i][r]>dp[f][r]&&!us[f-i][r]) continue;
                else break;
            ref(i,min(k,w-r))
                if(!dp[f][i+r]&&!us[f][r+i]) {
                    dp[f][r+i]=dp[f][r]+1;
                q.push(make_pair(f,r+i));}
                else if(dp[f][r+i]>dp[f][r]&&!us[f][r+i]) continue;
                else break;
            ref(i,min(k,r-1))
                if(!dp[f][r-i]&&!us[f][r-i]) {
                    dp[f][r-i]=dp[f][r]+1;
                q.push(make_pair(f,r-i));}
                else if(dp[f][r-i]>dp[f][r]&&!us[f][r-i]) continue;
                else break;

        }
    if(dp[x2][y2])cout<<dp[x2][y2];
    else cout<<-1;


    return 0;

}

Measured memory_bytes: 22752
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define ff first
#define ss second
#define MAXN  100005
#define endl "\n"
using namespace std;
vector<int>v,w;
ll dp[102][MAXN];
ll n,ww;
ll rec(int i,int we){
    if(i==n)
        return 0;
    if(dp[i][we]!=-1)
        return dp[i][we];
    ll ans=rec(i+1,we);
    if(we+w[i]<=ww){
        ans=max(ans,v[i]+rec(i+1,we+w[i]));
    }
    //cout<<i<<" "<<we<<" "<<ans<<endl;
    return dp[i][we]=ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    memset(dp,-1,sizeof(dp));
    cin>>n>>ww;
    for(ll i=0;i<n;i++){
        cin>>a>>b;
        w.pb(a);
        v.pb(b);
    }
    ll ans=rec(0,0);
    cout<<ans;



    return 0;
}



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

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

    int N = s.size();

    static int opt[1 << 26];
    for (int mask = 0; mask < (1 << 26); mask++) opt[mask] = 1 << 28;

    opt[0] = 0;
    static int dp[300000];
    int mask = 0;
    for (int i = 0; i < N; i++) {
        mask ^= 1 << (s[i] - 'a');
        dp[i + 1] = opt[mask] + 1;
        for (int j = 0; j < 26; j++) {
            dp[i + 1] = min(dp[i + 1], opt[mask ^ (1 << j)] + 1);
        }

        opt[mask] = min(opt[mask], dp[i + 1]);
    }
    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 263556
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n,a,b;cin >> n >> a >> b;
    int x[n];
    rep(i,n)cin >> x[i];
    vector<int> dist(n-1);
    rep(i,n-1)dist[i] = x[i+1] - x[i];
    int ret = 0;
    rep(i,n-1){
        ret += min(dist[i]*a,b);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 4808
#include <stdio.h>
#include <algorithm>
#define NUM  105
#define SIZE 100005

  long long int dp[NUM][SIZE], v[SIZE];
  int w[SIZE];

  int main(void) {
        int n,W;

        scanf("%d %d",&n,&W);
        for(int i=1; i<=n; i++) scanf("%d %lld",&w[i],&v[i]);

        for(int i=1; i<=n; i++) {
                for(int j=1; j<=W; j++) {
                        if(j<w[i]) dp[i][j] = dp[i-1][j];
                        else dp[i][j] = std::max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
                }
        }
        printf("%lld",dp[n][W]);
        return 0;
  }







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

void solve()
{
    long long n,i, x, y, zmin=2e9, zmax=-2e9, wmin=2e9, wmax=-2e9;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>x>>y;
        zmax = max(zmax, x+y);
        zmin = min(zmin, x+y);
        wmax = max(wmax, x-y);
        wmin = min(wmin, x-y);
    }
    cout<<max(zmax-zmin, wmax-wmin)<<endl;
}
int main() {
    int t=1;
    //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3632
#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() {
  ll N;
  cin >> N;
  vector<ll> as(N);
  rep(i, N) {
    cin >> as[i];
  }

  map<ll, ll> m;
  rep(i, N) {
    int a = as[i];
    if (m.count(a)) {
      m[a]++;
    } else {
      m[a] = 1;
    }
  }

  auto c = [&](ll num) {
    return num*(num-1)/2;
  };

  ll all = 0;
  for (auto i = m.begin(); i != m.end(); ++i) {
    ll value = i -> second;
    all += c(value);
  }

  map<ll, ll> ans;
  for (auto it = m.begin(); it != m.end(); ++it) {
    ll key = it ->first;
    ll value = it -> second;
    ll num = all - (c(value)-c(value-1));
    ans[key] = num;
  }

  rep(i, N) {
    int a = as[i];
    cout << ans[a] << endl;
  }

  return 0;
}


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

using namespace std;

#define INF 1001000100010001000
//#define INF 1010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    string st;
    cin >> st;
    
    vvi dp(2, vi(2019, 0));

    int ans = 0;
    rep(i, st.size()) {
        rep(j, 2019) {
            dp[!(i&1)][(j * 10 + (st[i] - '0')) % 2019] = dp[i&1][j];
        }
        dp[!(i&1)][(st[i] - '0')]++;
        ans += dp[!(i&1)][0];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3736
n = int(input())
cnt = n
ans = n

for i in range(n+1) :
    tmp = i
    cnt = 0
    while tmp > 0 :
        cnt += tmp % 6
        tmp = tmp // 6
    tmp = n - i
    while tmp > 0 :
        cnt += tmp % 9
        tmp = tmp // 9 
    ans = min(ans, cnt)

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <chrono>
#include <regex>
using namespace std;
#define len(_x) (sizeof((_x)) / sizeof(_x)[0])
#define ll long long
#define fastIO  ios_base::sync_with_stdio(false); cin.tie(0); 
#define Ichar(_x) char _x=_getchar_nolock();
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>=a && (x)<=b	
#define incE(a,b,x)(x)>=a && (x)<=b	
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
//#define DEBUG


ll modo(ll a)
{
	return a % (int)(1e9+7);
}

int main()
{
	ll n, k;
	std::cin >> n >>k;
	ll s = 0;
	for (ll i = k+1; i <=n; ++i)
	{
		ll t = n / i;
		ll temp = n - (t*i + k);
		s += (i - k)*t +  (temp<0?-1:temp) +1 - (k == 0);
	}
	std::cout << s;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;


int main(){
   IOS;
 //    #ifndef ONLINE_JUDGE
 //        freopen("in.txt",  "r",  stdin);
 //        freopen("out.txt", "w", stdout);
 //    #endif
   
   long int n;
   cin>>n;

   long int sum = 0;

   for(long int i = 1; i <= n; i++){
    if(i % 3 == 0)
      continue;
    if(i % 5 == 0)
      continue;
    sum += i;
   }

   cout<<sum;
   return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

char in[100050];
int ans[100050];
int main() {
	int N, i, j, k;
	scanf("%d %s", &N, in);

	for (i = 0; i < 2; i++) {
		for (j = 0; j < 2; j++) {
			ans[0] = i, ans[1] = j;
			for (k = 2; k < N; k++) ans[k] = (int)(in[k - 1] == 'x') ^ ans[k - 2] ^ ans[k - 1];
			for (k = 0; k < N; k++) {
				int n1 = (k + N - 1) % N, n2 = k, n3 = (k + 1) % N;
				if (ans[n1] ^ ans[n2] ^ ans[n3] ^ (int)(in[n2] == 'x')) break;
			}
			if (k >= N) {
				for (k = 0; k < N; k++) {
					if (ans[k]) printf("W");
					else printf("S");
				}
				return !printf("\n");
			}
		}
	}
	return !printf("-1\n");
}

Measured memory_bytes: 768
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	fmt.Println((float64((N + 1) / 2)) / float64(N))
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


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

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

	deque<int> b;
	for(int i = 0; i < n; ++i) {
		( i % 2 == n % 2 ) ? b.push_back( a[i] ) : b.push_front( a[i] );
	}

	for(int i = 0; i < n; ++i)
		i != n-1 ? cout << b[i] << " " : cout << b[i] << endl;

	return 0;
}

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

int temp[10][10] = {}, N, M;

int foo(int n,int coun,int bb[]){//cout<<coun<<" "<<n<<endl;
    if(coun == N)return 1;
    int tee[10][10], ans =0, aa[10]={},C=0;
    for(int i = 1; i <= coun;i++){aa[bb[i]]=1;}
  for(int i = 1; i <= N; i++){
    if(aa[i]==1)continue;
    //tee[n][i]=1;
    bb[coun+1]=i;
    if(temp[n][i])ans += foo(i,coun+1,bb);
    
    //tee[n][i]=0;
    
  }
  //if(ans==0)return 0;
  return ans;
}

int main(){
  int a, b, te[10][10]={}, bb[10] = {};
  cin>>N>>M;
  te[1][1] = 1;bb[1]=1;
  for(int i = 0; i < M; i++){
    cin>>a>>b;
    temp[a][b]=1;
    temp[b][a]=1;
  }

  cout<<foo(1,1,bb)<<endl;

  return 0;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
ll t[1252],a[1252];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%lld%lld",t+i,a+i);
  ll x=t[0],y=a[0];
  FOR(i,1,n){
    ll o=t[i],p=a[i];
    ll ro = (x+o-1)/o;
    ll nx = o*ro;
    ll ny = p*ro;
    if(ny>=y){
      x=nx;
      y=ny;
    }else{
      ro = (y+p-1)/p;
      x=o*ro;
      y=p*ro;
    }
  }
  printf("%lld\n",x+y);
  return 0;
}


Measured memory_bytes: 256
N = int(input())
nums = list(map(int, input().split()))
cnt = 0
cntlst = []
for i in range(0,N):
    taisyouN = nums[i]
    while taisyouN %2 == 0:
        taisyouN = taisyouN/2
        cnt = cnt+1
    cntlst.append(cnt)
    cnt = 0
print(sum(cntlst))

Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int l,r,d;
    cin >> l >> r >> d;
    if(l%d!=0 && r%d!=0) cout << (r-l)/d << endl;
    else cout << (r-l)/d+1 << endl;

    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t x){
	if(was_output)cout << " ";
	was_output = true;
	cout << x;
}

void outendl(){
	was_output = false;
	cout << endl;
}

int main(){
	int n;
	cin>>n;
	vector<ll> line(n);
	foreach(i, line)cin>>i;
	vector<ll> sum(n+1, 0);
	rep(i, n)sum[i+1]=sum[i]+line[i];
	ll ans = INFLL;
	for(int i=2;i<n-1;++i){
		vector<pll> left, right;
		ll l = sum[i];
		ll r = sum[n]-l;
		int p = lower_bound(all(sum), l/2) - sum.begin();
		ll a = sum[p];
		ll b = sum[i]-sum[p];
		if(a>b)swap(a, b);
		left.push_back(pll(a, b));
		a = sum[p-1];
		b = sum[i] - sum[p-1];
		if(a>b)swap(a, b);
		left.push_back(pll(a, b));
		p = lower_bound(all(sum), l+r/2)-sum.begin();

		a = sum[p] - sum[i];
		b = sum[n] - sum[p];
		if(a>b)swap(a, b);
		right.push_back(pll(a, b));
		a = sum[p-1] - sum[i];
		b = sum[n] - sum[p-1];
		if(a>b)swap(a, b);
		right.push_back(pll(a, b));
		foreach(j, left){
			foreach(k, right){
				ll nmin = min(j.first, k.first);
				ll nmax = max(j.second, k.second);
				chmin(ans, nmax-nmin);
			}
		}
	}

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




Measured memory_bytes: 3328
N = int(input())
towns = list(map(int, input().split()))
yusyas = list(map(int, input().split()))

ans = 0
restmons = towns[0]
for i, mons in enumerate(yusyas):
    if restmons > mons:  # 前の勇者がとり逃したほうがキャパを超える
        ans += mons
        restmons = towns[i + 1]
    else:
        if restmons + towns[i + 1] > mons:  # 次の町は狩り残す
            ans += mons
            restmons = restmons - mons + towns[i + 1]
        else:  # 次を空にする
            ans += restmons + towns[i + 1]
            restmons = 0
    # print((i, ans, restmons))

print(ans)


Measured memory_bytes: 18624
// 线段树维护DP
// f[i]: 从前i个数中选，满足条件的数有多少个。
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;

const int N = 600010;

int n, k, tr[N << 2];
int a[N];

void update(int p, int l, int r, int pos, int v)
{
    if (l == r)
    {
        tr[p] = v;
        return;
    }

    int mid = l + r >> 1;
    if (pos <= mid) update(p << 1, l, mid, pos, v);
    if (pos > mid) update(p << 1 | 1, mid + 1, r, pos, v);

    tr[p] = max(tr[p << 1], tr[p << 1 | 1]);
}

int query(int p, int l, int r, int L, int R)
{
    if (L <= l && R >= r)
        return tr[p];
    
    int mid = l + r >> 1;
    int res = 0;

    if (L <= mid) res = max(res, query(p << 1, l, mid, L, R));
    if (R > mid) res = max(res, query(p << 1 | 1, mid + 1, r, L, R));

    return res;
}

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

    for (int i = 1; i <= n; i ++ )
        scanf("%d", &a[i]);
    
    int ans = 0;

    for (int i = 1; i <= n; i ++ )
    {
        int res = query(1, 0, N, max(a[i] - k, 0), a[i] + k) + 1;
        ans = max(ans, res);
        update(1, 0, N, a[i], res);
    }

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

Measured memory_bytes: 9140
import itertools
import math


def calcDistanceIsInt(p1, p2):
    sum = 0
    for i in range(len(p1)):
        sum += math.pow(abs(p1[i] - p2[i]), 2)

    sq = math.sqrt(abs(sum))
    if sq.is_integer():
        return True
    else:
        return False


nd = list(map(int, input().split()))
n, d = nd[0], nd[1]

points = []
for i in range(n):
    point = list(map(int, input().split()))
    points.append(point)

# print(points)
# print(list(itertools.combinations(points, 2)))

int_count = 0
for i in list(itertools.combinations(points, 2)):
    # print(i[0], i[1])
    # print(calcDistanceIsInt(i[0], i[1]))
    if calcDistanceIsInt(i[0], i[1]):
        int_count += 1
print(int_count)


Measured memory_bytes: 38256
#include <iostream>

int main()
{
  int x[5];
  std::cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
  for (int i=0; i<5; i++) {
    if (x[i]==0) {
      std::cout << i+1 << std::endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3516
#include<iostream>
#include<vector>
#include<iomanip>

using namespace std;

int main(){

    int N;
    cin >> N;

    vector<double> A(N);

    for(int i=0;i<A.size();i++){
        cin >> A[i];
    }

    double sum = 0.;
    for(int i=0;i<A.size();i++){
        
        sum += 1/A[i];

    }

    cout << setprecision(10) << 1/sum << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
const int NUM = 7;
int main(){
	int a,b,c,l[10],s,cnt;
	while(cin >> a >> b >> c){
		memset(l,0,sizeof(l));
		s = a + b;
		++l[--a];
		++l[--b];
		++l[--c];
		cnt = 0;
		for(int i = 0;i < 10;++i){
			if(!l[i]){
				if(s + i + 1 <= 20) ++cnt;
			}
		}
		cnt *= 10;
		if((double)(cnt / NUM) >= 5.0) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#define N 45

int fibonacci(int);
int fib[N];

int main(){
    int n;

    scanf("%d", &n);
    printf("%d\n", fibonacci(n));
    return 0;
}

int fibonacci(int n){
    int i;

    fib[0] = 1;
    fib[1] = 1;
    for(i = 2; i <= n; i++){
        fib[i] = fib[i-1] + fib[i-2];
    }

    return fib[n];
}

Measured memory_bytes: 596