akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int x, y; cin >> x >> y;
	int d = __gcd(x, y);
	int ans = x + y + 1 - d;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define ALL(v) (v).begin(), (v).end()
#define PUTS(x) cout << (x) << endl;
vector<Int> IntsIn(int n) {
    auto v = vector<Int>(0);
    for (int i = 0; i < n; i++) {
        Int a;
        cin >> a;
        v.push_back(a);
    }
    return v;
}

int main() {
    int a, b, m;
    cin >> a >> b >> m;
    auto A = IntsIn(a);
    auto B = IntsIn(b);
    auto ans = 10000000LL;
    rep(i, m) {
        int x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        ans = min(ans, A[x] + B[y] - c);
    }
    sort(ALL(A));
    sort(ALL(B));
    ans = min(ans, A[0] + B[0]);
    PUTS(ans)
}


Measured memory_bytes: 2548
/** Which of the favors of your Lord will you deny ? **/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#ifndef ONLINE_JUDGE
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#else
#define DBG(x)
#define endl "\n"
#endif

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;

#define int long long

void solveTC()
{
    vector<int>v(4);
    cin>>v[0]>>v[1]>>v[2]>>v[3];

    int mx = LLONG_MIN;

    for(int i=0;i<2;i++)
    {
        for(int j=2;j<4;j++)
            mx = max(mx,v[i]*v[j]);
    }

    cout<<mx<<endl;
    DBG(mx);
}


int32_t main()
{
    optimizeIO();

    int tc =1 ;

    while(tc--)
    {
        solveTC();
    }

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}


Measured memory_bytes: 3652
S=list(input())
T=list(input())

dp = [[0]*(len(T)+1) for i in (range(len(S)+1))]

for s in range(len(S)):
    for t in range(len(T)):
        if S[s] == T[t]:
            dp[s+1][t+1] = max(dp[s][t]+1,dp[s][t+1],dp[s+1][t])
        else:
            dp[s+1][t+1] = max(dp[s][t+1],dp[s+1][t])

def checkdpn(x,y):
    if dp[x][y] == dp[x-1][y] + 1 and dp[x][y] == dp[x][y-1] + 1:
        return True
    else:
        return False

x = len(S)
y = len(T)
str = ''

while(True):
    if checkdpn(x,y):
        str = S[x-1] + str
        x -= 1
    else:
        if dp[x][y] == dp[x][y-1] + 1:
            x -= 1
        else:
            y -= 1
    if dp[x][y] == 0:
        break
print(str)

Measured memory_bytes: 113884
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){

    int a,b,h;
    cin >> a >> b >> h;
    P((a+b)*h/2);
    
    return  0;
}


Measured memory_bytes: 256
/*
    Created by Tejas Chaudhari
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef double lf;
typedef bool bl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<lf> vd;
typedef vector<bl> vb;
typedef string st;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define INF (LONG_LONG_MAX / 4)
#define Mod % 1000000007
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

void re_curse() {
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans = 0;
    int i = 0;
    int j = n-1;
    while (i < j) {
        while (s[i] == 'R') {
            ++i;
        }
        while (s[j] == 'W') {
            --j;
        }
        if (i >= j) {
            break;
        }
        s[i] = 'R';
        s[j] = 'W';
        ++ans;
    }
    cout<<ans<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin>>t;
    for (int i = 1; i <= t; ++i) {
        re_curse();
    }
    return 0;
}


Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <functional>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

const int MAX_N = 20000, MAX_M = 16;
const int INF = 1 << 30;
int code_book[MAX_M];
int dp[MAX_N + 1][256];
int y[MAX_N + 1];

int main()
{
    int N, M;
    while(cin >> N >> M && N && M) {
        for(int i = 0; i < M; i++) 
            cin >> code_book[i];
        
        for(int i = 1; i <= N; i++) 
            cin >> y[i];

        for(int i = 0; i <= N; i++) 
            for(int j = 0; j <= 255; j++) 
                dp[i][j] = INF;
        
        dp[0][128] = 0;
        for(int i = 0; i < N; i++) {
            for(int j = 0; j <= 255; j++) {
                for(int k = 0; k < M; k++) {
                    int yn = j + code_book[k];
                    if(yn > 255)
                        yn = 255;
                    else if(yn < 0)
                        yn = 0;
                    dp[i + 1][yn] = min(dp[i + 1][yn], dp[i][j] + (yn - y[i + 1]) * (yn - y[i + 1]));

                }
            }
        }
        
        int ans = INF;
        for(int j = 0; j <= 255; j++)
            ans = min(ans, dp[N][j]);

        cout << ans << endl;
                      
    }
}

Measured memory_bytes: 20000
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
	long n; cin >> n;
	long res = 1;
	for (int i = 2; i <= n; i++)
	{
		res = res * i % mod;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
   
int top, S[1000];
   
void push(int x) {
/* topを加算してからその位置へ挿入 */
  S[++top] = x;
}
   
int pop() {
  top--;
/* topが指していた要素を返す */
  return S[top+1];
}
   
int main() {
  int a, b;
  top = 0;
  char s[100];
   
  while( scanf("%s", s) != EOF ) {
    if ( s[0] == '+' ) {
      a = pop();
      b = pop();
      push(a + b);
    } else if ( s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if ( s[0] == '*' ) {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
   
  printf("%d\n", pop());
   
  return 0;
}


Measured memory_bytes: 2716
N = int(input())
S = [0]*N
sm = 0
A = list(map(int,input().split()))
for i in range(N):
    ai = A[i]
    sm += ai
    S[i] = sm
score = 0
min_score = float("inf")
for i in range(N-1):
    score = abs(S[i]-(S[N-1]-S[i]))
    min_score = min(score,min_score)
print(min_score)



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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

string S, T;

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

    cin >> S;
    cin >> T;

    bool flag = true;

    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) flag = false;
    }

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

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

   


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N, M, Q, D[101010], A[101010], B[101010], E[101010], S[101010], T[101010];
string ans[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> Q;
    rep(i, 0, M) cin >> D[i] >> A[i] >> B[i];
    rep(i, 0, Q) cin >> E[i] >> S[i] >> T[i];

    set<pair<int, int>> gr;
    rep(i, 0, N) gr.insert({ i + 1, i + 1 });

    vector<int> ele, ord;
    rep(i, 0, M) ele.push_back(i);
    sort(all(ele), [&](int a, int b) { return D[a] < D[b]; });
    rep(i, 0, Q) ord.push_back(i);
    sort(all(ord), [&](int a, int b) { return E[a] < E[b]; });

    int elei = 0;
    rep(_i, 0, Q) {
        int i = ord[_i];

        if (S[i] >= T[i]) {
            ans[i] = "Yes";
            continue;
        }

        while (elei < M) {
            int j = ele[elei];
            if (E[i] <= D[j]) break;

            int a = A[j];
            int b = B[j];

            auto itea = gr.lower_bound({ a, -1 });
            auto iteb = gr.lower_bound({ b, -1 });

            int l = itea->second;
            int r = iteb->first;

            iteb++;

            gr.erase(itea, iteb);
            gr.insert({ r, l });
            elei++;

            //printf("%d >> ", D[j]); fore(p, gr) printf("[%d %d] ", p.first, p.second); printf("\n");
        }

        auto itea = gr.lower_bound({ S[i], -1 });
        auto iteb = gr.lower_bound({ T[i], -1 });

        if (itea == iteb) ans[i] = "Yes";
        else ans[i] = "No";
    }

    rep(i, 0, Q) printf("%s\n", ans[i].c_str());
}


Measured memory_bytes: 12908
use std::cmp::min;
use std::io::{BufRead, StdinLock};

fn read(stdin_lock: &mut StdinLock, buf: &mut Vec<u8>, delimiter: u8) -> i32 {
    buf.clear();
    let l = stdin_lock.read_until(delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap()
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let p = read(&mut stdin_lock, &mut buf, b' ');
    let q = read(&mut stdin_lock, &mut buf, b' ');
    let r = read(&mut stdin_lock, &mut buf, b'\n');
    println!("{}", solve(p, q, r));
}

fn solve(p: i32, q: i32, r: i32) -> i32 {
    min(min(p + q, q + r), p + r)
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define wi while
#define vl vector<ll>
#define vi vector<int>
#define map map<char,ll>
#define endl "\n"
const int mxN = 100007;
vector<int>edges[mxN];
int mul(int a,int b)
{
    return (ll) a * b % mod;
}
pii dfs(int v,int par)
{
    int all_white = 1;
    int sth_is_black = 0;
    for(auto u:edges[v])
    {
        if(u != par)
        {
           pii p =  dfs(u,v);
           //p first is the number of ways to color
           // the subtree such that v is black
           int temp = all_white;
           all_white = mul(all_white,p.second);
           sth_is_black = (mul(temp,p.first) + 
            mul(sth_is_black,p.first+p.second))%mod;


        }
    }
    //code
    return make_pair(all_white,(all_white + sth_is_black)%mod);
}

int main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
    
    int n,a,b;
    cin>>n;
    for(int i=1;i<=(n-1);++i)
    {
        cin>>a>>b;
        edges[a].pb(b);
        edges[b].pb(a);
    }
   pii p =  dfs(1, -1);

   int ans = (p.first + p.second ) % mod;

    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 15952
import sys
from collections import Counter

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = [input().rstrip() for _ in range(N)]

C = [Counter(a) for a in A]
#print(A)
#print(C)

tmp = {}

for k, v in C[0].items():
	tmp[k] = v
	for i in range(N):
		tmp[k] = min(tmp[k], C[i][k])

tmp = sorted(tmp.items(), key=lambda x:x[0])
#print(tmp)

ans = ''
for k, v in tmp:
	ans += k * v

print(ans)

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

int main() {
  
  int N=0, A=0;
  
  cin >> N >> A;
  
  int cul = N % 500;
  
  if(cul <= A) {
    
    cout << "Yes" << endl;
    
  } else {
    
    cout << "No" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if(N % 2 == 0){
  	cout << 1.0/2 << endl;
  }else{
  	cout << ((N+1)/2.0)/(double)N << endl;
  } 
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {
	int N,D=0;
	cin >> N >> D;
	cout<<((N-1) / (2 * D + 1)) +1<< endl;

	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int X,Y,Z; cin >>X >>Y >>Z;
  int K; cin >>K;
  vector<ll> A(X); rep(i, X) cin >>A[i];
  vector<ll> B(Y); rep(i, Y) cin >>B[i];
  vector<ll> C(Z); rep(i, Z) cin >>C[i];
  sort(allR(A)); sort(allR(B)); sort(allR(C));
  // A[i],B[j],C[k] を選ぶとして、自分より絶対に美味しい組は
  // (i+1)*(j+1)*(k+1)-1 個ある
  priority_queue<ll> pq;
  for (int i=0; i<X; i++){
    for (int j=0; j<Y; j++){
      if ((i+1)*(j+1) > K) break;
      for (int k=0; k<Z; k++){
        if ((i+1)*(j+1)*(k+1) > K) break;
        pq.push(A[i]+B[j]+C[k]);
      }
    }
  }
  for (int i=0; i<K; i++){
    cout <<pq.top() <<endl;
    pq.pop();
  }
}

Measured memory_bytes: 1532
unittest
{
	assert( [ "5 3", "10 14 19 34 33" ].parse.expand.solve == 202 );
	assert( [ "9 14", "1 3 5 110 24 21 34 5 3" ].parse.expand.solve == 1837 );
	assert( [ "9 73", "67597 52981 5828 66249 75177 64141 40773 79105 16076" ].parse.expand.solve == 8128170 );
	
	assert( [ "5 3", "10 10 10 10 10" ].parse.expand.solve == 60 );		// 追加ケース
	assert( [ "100000 3", "100000".repeat( 100000 ).join( ' ' ) ].parse.expand.solve == 600000 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( nm[ 1 ], as );
}

auto solve( long m, long[] as )
{
	as.sort!( ( x, y ) => y < x );
	
	// m通り以上の握手ができる最大のパワーを二分探索
	auto l = as[ $ - 1 ] * 2;
	auto r = as[ 0 ] * 2;
	while( l < r )
	{
		auto c = ( l + r + 1 ) / 2;
		
		// c以上のパワーの握手が何通りできるか計算
		auto n = 0L;
		auto j = as.length.signed;
		foreach( i, a; as )
		{
			for( ; 0 < j; j-- )
			{
				if( c <= a + as[ j - 1 ] )
				{
					n += j;
					break;
				}
			}
		}
		
		if( m <= n ) l = c;
		else         r = c - 1;
	}
	
	// 累積和表を作成
	auto ts = new long[ 1 + as.length ];
	foreach( i, a; as )
	{
		ts[ i + 1 ] = ts[ i ] + as[ i ];
	}
	
	// 最大幸福度を計算
	auto ans = 0L;
	auto n = 0L;
	auto z = long.max;
	auto j = as.length.signed;
	foreach( i, a; as )
	{
		for( ; 0 < j; j-- )
		{
			if( l <= a + as[ j - 1 ] )
			{
				ans += ( a * j ) + ts[ j ];
				n += j;
				z = min( z, a + as[ j - 1 ] );
				break;
			}
		}
	}
	ans -= z * ( n - m );		// 最小パワーのゲストが複数いるとm通りをオーバーしてしまうので削る
	return ans;
}


Measured memory_bytes: 4668
H, W, K= map(int, input().split())
lst = []
for _ in range(H):
    lst.append(list(str(input())))

ans = 0
for i in range(2**H):
    for j in range(2**W):
        temp =[]
        c = 0
        for h in range(H):
            if (i >> h) & 1:
                temp.append(lst[_])
                for w in range(W):
                    if (j >> w) & 1:
                        if lst[h][w] == '#':
                            c +=1
        if c == K:
            ans += 1
print(ans)

Measured memory_bytes: 68496
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <queue>
#define INF 9999999999
using namespace std;
typedef long long int ll;
int main() {
	ll X, Y;
	cin >> X >> Y;

	if (X % Y == 0) {
		cout << -1 << endl;
		return 0;
	}

	for(int i = 0; ; i++){
		ll Z = X + i;
		if (Z % Y != 0) {
			cout << Z << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n,c=0;
  cin>>n;
  int a[n],b[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  for(int i=0;i<n;i++){
    c+=max(a[i]-b[i],0);
  }
  cout<<c;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    ll N, M, K;
    cin >> N >> M >> K;
    ll res = 0;
    REP(i, M) {
        res += N * N * i * (M - i);
        res %= MOD;
    }
    REP(j, N) {
        res += M * M * j * (N - j);
        res %= MOD;
    }
    cout << res * comb(N * M - 2, K - 2, MOD) % MOD << endl;
    return 0;
}


Measured memory_bytes: 768
n=gets.to_i
d,x=gets.split.map &:to_i
arr=n.times.map{gets.to_i}
res=[]
n.times do |i|
  j=0
  res[i] = 0
  while true
    day=1+arr[i]*j
    break if day>d
    res[i] += 1
    j+=1
  end
end
p res.inject(:+)+x

Measured memory_bytes: 1788
#import collections
# c = collections.Counter()
#import itertools as it
#import math
#import numpy as np
#import sys 
#sys.exit()
 
s = input()
t = input()
#k = int(input())
#a, b  = map(int, input().split())
'''
#  = list(map(int, input().split()))
'''
'''
n = input()
a = [int(input()) for i in range(n)]
'''
'''
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
'''
 
#-------------------------------#
#len(t)==len(s)+1
#print(t[0:-1])
if len(t)==len(s)+1 and 0<len(s)<=10 and t[0:-1]==s:
	print('Yes')
else:
  	print('No')

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

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int w = Integer.parseInt(br.readLine());
        int n = Integer.parseInt(br.readLine());

        int[] array = new int[w];
        for(int i = 0; i < w; i++){
            array[i] = i+1;
        }

        for(int i = 0; i < n; i++){
           String[] input = br.readLine().split(",");
           int a = Integer.parseInt(input[0]);
           int b = Integer.parseInt(input[1]); 
           
           int tmp = array[a-1];
           array[a-1] = array[b-1];
           array[b-1] = tmp;
        }

        for(int i : array){
            System.out.println(i);
        }
    }
}

Measured memory_bytes: 24168
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int n;
    cin >> n;
    int taro = 0;
    int hanako = 0;
    rep(i,n){
        string s,t;//s:太郎,t:花子
        cin >> s >> t;
        if(s == t){
            taro++;
            hanako++;
        }else if(s > t){
            taro += 3;
        }else{
            hanako += 3;
        }
    }
    printf("%d %d\n",taro,hanako);
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


Measured memory_bytes: 3240
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int N, C, K;
vector<double> T;

void solver() {
    sort(T.begin(), T.end());

    int ans = 0;
    int i = 0;
    while (i < N) {
        int angry = T[i++];
        int cap = 1;
        while (i < N && cap++ < C && T[i] - angry <= K) i++;

        ans++;
    }

    cout << ans << endl;
}

int main() {
    cin >> N >> C >> K;
    for (int i = 0; i < N; i++) {
        double tmp;
        cin >> tmp;
        T.push_back(tmp);
    }

    solver();
}


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

int main()
{
  long n, i, j;
  cin >>n;
  long a[n];

  for(i=0;i<n;i++){
    cin >>a[i];
  }
  long max=a[0], min=a[0] ,sum=0;

  for(j=0;j<n;j++){
    if(max < a[j]){
      max = a[j];
    }
    if(min > a[j]){
      min = a[j];
    }
    sum = sum +a[j];
  }

  cout <<min <<" " <<max <<" "<<sum <<endl;

}

Measured memory_bytes: 1240
#include <stdio.h>

int main(void)
{
	int N,M,C;
	scanf("%d%d", &N,&M);
	scanf("%d", &C);
	int b[M];
	int a[M + 1][N + 1];
	int i = 0;
	while (i < M)
	{
		scanf("%d", &b[i]);
		i++;
	}
	i = 0;
	int j;
	int ans[N + 1];
	int count = 0;
	while (i < N)
	{
		j = 0;
		while (j < M)
		{
			scanf("%d", &a[i][j]);
			ans[i] = 0;
			j++;
		}
		i++;
	}
	i = 0;
	while (i < N)
	{
		j = 0;
		while (j < M)
		{
			// printf("%d*%d\n",a[i][j] , b[j]);
			ans[i] += a[i][j] * b[j];
			j++;
		}
		// printf("%d",ans[i]);
		if (ans[i] + C > 0)
			count++;
		i++;
	}
	printf("%d", count);
	return (0);
}

Measured memory_bytes: 128
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("C:\\Users\\BOG\\Desktop\\ICPC\\b1.txt");ofstream out("C:\\Users\\BOG\\Desktop\\ICPC\\b1_out.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int G = 10000001;
int erat[G];

int main(){
    fast;
    memset(erat, 0, sizeof(erat));
    for(int q=2; q<G; q++){
        if(erat[q]) continue;
        for(int w = q; w<G; w+=q) erat[w] = q;
    }
    int a; cin>>a;
    ll e  =0;
    for(int q=1; q<=a; q++){
        int c = q, cnt = 0, pr = -1, o=1;
        for(; c>1; c/=erat[c]){
            if(erat[c]==pr) cnt++;
            else{
                o *= cnt+1;
                cnt = 1;
            }
            pr = erat[c];
        }
        o *= cnt+1;
        e += (1LL*q)*o;
    }
    cout<<e;
}

Measured memory_bytes: 42632
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int n, l;
	cin >> n>> l;
	vector<int> flavs(n);
	int sum = 0;
	vector<int> abss(n);
	for (int i = 0; i < n; ++i) {
		flavs[i] = l + i;
		sum += flavs[i];
		abss[i] = abs(flavs[i]);
	}
	sort(abss.begin(), abss.end());
	for (int i = 0; i < n; ++i) {
		if (abs(flavs[i]) == abss[0]) {
			sum -= flavs[i];
			break;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

class combination{
private:
    vector<mint> fact,inv,finv;
public:
    combination(int N){
        fact = inv = finv = vector<mint>(N+1);
        fact[0] = fact[1] = 1;
        inv[0] = inv[1] = 1;
        finv[0] = finv[1] = 1;
        for(ll i=2;i<=N;i++){
            fact[i] = fact[i-1]*i;
            inv[i] = (mint) mod - inv[mod%i]*(mod/i);
            finv[i] = finv[i-1]*inv[i];
        }
    }
    mint f(int i){
        return fact[i];
    }
    mint comb(int n,int k){
        if(n<k) return 0;
        if(n<0 || k<0) return 0;
        return fact[n]*finv[k]*finv[n-k];
    }
    mint hcomb(int n,int k){
        if(n==0 && k==0) return 1;
        return comb(n+k-1,k);
    }
    mint perm(int n,int k){
        return comb(n,k)*fact[k];
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    vvec<int> g(N);
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    combination C(max(N,K));
    mint ans = K;
    auto dfs = [&](auto&& self,int cur,int par,int d)->void{
        int n = g[cur].size();
        if(d) n--;
        if(!n && cur) return ;
        if(!d) ans *= C.perm(K-1,n);
        else ans *= C.perm(K-2,n);
        for(auto& to:g[cur]) if(to!=par) self(self,to,cur,d+1);
    };
    dfs(dfs,0,-1,0);
    cout << ans << "\n";
}

Measured memory_bytes: 10752
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
	int m,j,r;
	while(1){
		scanf("%d %d %d",&m,&j,&r);
		if(m==-1&&j==-1&&r==-1) return 0;
		if(m==-1||j==-1||m+j<30){
			printf("F\n");
		}else if(m+j>=80){
			printf("A\n");
		}else if(m+j>=65){
			printf("B\n");
		}else if(m+j>=50||r>=50){
			printf("C\n");
		}else{
			printf("D\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    long long int a,b[1000000];
    cin>>a;
    b[0]=2;
    b[1]=1;
    for(int i=2;i<a+2;i++){
        b[i]=b[i-2]+b[i-1];
    }
    cout<<b[a]<<endl;
    
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn eval(a: i64, b: i64, c: i64, ls: &Vec<i64>, assignment: &Vec<i64>) -> i64 {
    (0..3)
        .map(|m| {
            ls.iter()
                .cloned()
                .enumerate()
                .filter(|&(i, _)| assignment[i] == m)
                .fold((0, 0), |(cnt, s), (_, l)| (cnt + 1, s + l))
        })
        .enumerate()
        .map(|(m, (cnt, s))| {
            if cnt == 0 {
                return 1000000;
            }

            let pt = match m {
                0 => a,
                1 => b,
                2 => c,
                _ => unreachable!(),
            };

            (cnt - 1) * 10 + (s - pt).abs()
        })
        .sum()
}

fn solve2(a: i64, b: i64, c: i64, ls: &Vec<i64>, assignment: &mut Vec<i64>) -> i64 {
    if ls.len() == assignment.len() {
        return eval(a, b, c, ls, assignment);
    }

    let mut min_mp = 1000000;
    for i in 0..4 {
        assignment.push(i);
        let mp = solve2(a, b, c, ls, assignment);
        min_mp = min(mp, min_mp);
        assignment.pop();
    }

    min_mp
}

fn solve(a: i64, b: i64, c: i64, ls: &Vec<i64>) -> i64 {
    let mut assignment = vec![];

    solve2(a, b, c, ls, &mut assignment)
}

fn main() {
    let (n, a, b, c) = read_cols!(usize, i64, i64, i64);

    let ls = {
        let mut ls = vec![];
        for _ in 0..n {
            ls.push(read::<i64>());
        }
        ls
    };

    let mp = solve(a, b, c, &ls);
    println!("{}", mp);
}


Measured memory_bytes: 4352
#include <stdio.h>
  
int main()
{
    for (;;) {
        int h, w, x, y;
        scanf("%d %d", &h, &w);
        if (h == 0 & w == 0) {
            return 0;
        }
        for (y = 0; y < h; y++) {
            for (x = 0; x < w; x++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}

Measured memory_bytes: 572
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
ll a, b, c,n, i, j, k,  m, t, arr[200005], ar[200005];
int main() {
    string s;
    cin >> n >> m;
    for (i = 0; i < m; i++)
        cin >> arr[i];
    a = arr[m - 1] - arr[0];
    ll minn = arr[0];
    for (i = 1; i < m; i++) {
        minn = minn > arr[i] - arr[i - 1] ? minn : (arr[i] - arr[i - 1]);
    }
    a=a<a + arr[0] - minn+n-arr[m-1]?a:(a + arr[0] - minn + n - arr[m - 1]);
    cout << a;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

//gcd(0,x)=gcd(x,0)=x, gcd(0,0)=0
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}


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

signed main(){

    int A, B; cin >> A >> B;
    Out(lcm(A, B));

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//DEFINE and TYPEDEF--------------------------------------------------------------
 
#define FORG(i,a,n) for(lld i=a;i<n;i++) //for - general
#define FORZ(i,n) for(lld i=0;i<n;i++) //for - zero
#define FORGI(i,a,n,inc) for(lld i=a;i<n;i+=inc) //for - general incremental
#define FORZI(i,n,inc) for(lld i=0;i<n;i+=inc) //for - zero incremental
#define DEBUG(x) cout<<(#x)<<" is "<<(x)<<endl //to debug values of variables
#define ZINDA cout<<"\nIdhar-ich hai apun!!\n"; //to debug if code reached that point
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
 
#define SORTall(m) sort(m.begin(),m.end());
 
#define st first
#define nd second
#define pb push_back
#define mod 1000000007
 
typedef long long int lld;
typedef unsigned long long int ulld;
 
lld power(lld b, lld e)
{
	if(e==0)
		return 1;
	if(e%2==1)
		return b*power(b*b,(e-1)/2);
	else
		return power(b*b,e/2);
}
 
int nDig(lld n)
{
	return floor(log10(n) + 1);
}

//--------------------------------------------------------------------------------
int main()
{
    SPEEDUP;
 	lld n;
 	cin>>n;

 	lld hi[n];
 	FORZ(i,n) cin>>hi[i];

 	lld csts[n]={0};
 	csts[0]=0;
 	csts[1]=abs(hi[1]-hi[0]);
 	FORG(i,2,n)
 	{
 		if(csts[i-1]+ abs(hi[i]-hi[i-1]) < csts[i-2]+ abs(hi[i]-hi[i-2]))
 			csts[i]=csts[i-1] + abs(hi[i]-hi[i-1]);
 		else csts[i]=csts[i-2] + abs(hi[i]-hi[i-2]);
 	}
 	
 	cout<<csts[n-1];
 	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	string S;
	cin >> S;

	reverse(all(S));

	int i = 0;
	while (S[i] != '\0')
	{
		if (S.substr(i, 5) == "maerd" || S.substr(i, 5) == "esare")
		{
			i += 5;
			continue ;
		}
		if (S.substr(i, 7) == "remaerd")
		{
			i += 7;
			continue ;
		}
		if (S.substr(i, 6) == "resare")
		{
			i += 6;
			continue ;
		}
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
}



Measured memory_bytes: 512
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

a, b = Is()
if a > 8 or b > 8:
    print(':(')
else:
    print('Yay!')

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

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;


    // i is number of pizzas C.
    int i = 0;
    // l is number of pizzas A, m  is number of pizzas B.
    int l = 0, m = 0;
    int cnt = 1;
    int priceP = 0;
    int price = pow(10, 9);

    while(i/2 <= max(x, y)) {
        if (i % 2 == 0) {
            if (x-i/2 > 0) {
                l = x - i/2;
            } else {
                l = 0;
            }
            if (y-i/2 > 0) {
                m = y - i/2;
            } else {
                m = 0;
            }
            priceP = l * a + m * b + i * c;
            price = min(price, priceP);
        }
        i++;
    }
    cout << price << endl;
}

Measured memory_bytes: 256
n,m=map(int, input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int, input().split())))
ab.sort(key=lambda x:x[0])

d=0
money=0
for i in range(n):
    if d+ab[i][1]<=m:
        money+=ab[i][0]*ab[i][1]
        d+=ab[i][1]
    else:
        money+=ab[i][0]*(m-d)
        d+=(m-d)
print(money)

Measured memory_bytes: 29024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using namespace std;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
#define Endl endl
int kai_size = 100001;
vel kai(kai_size, 1);
vel ink(kai_size, 1);

int RE() {
	vel v(3, 2);
	return v.at(4);
}
int ret(int st, vvel &chi) {
	vel lis(0);
	rep(i, chi[st].size()){
		lis.push_back(ret(chi[st][i],chi));
	}
	sor(lis);
	int ans = 0;
	rep(i, chi[st].size()) {
		ans = max(ans, lis[i]) + 1;
	}
	return ans;
}
signed main() {
	int n; cin >> n;
	vel pa(n, -1);
	vvel chi(n);
	rep(i, n - 1) {
		cin >> pa[i + 1];
		pa[i + 1]--;
		chi[pa[i + 1]].push_back(i + 1);
	}
	cout << ret(0, chi) << endl;
	return 0;
}


Measured memory_bytes: 17408
original = gets.chomp.split("")
answer = gets.chomp

flag = false
original.length.times do |i|
    if original.join("") == answer
        flag = true
        break
    end
    original.insert(0, original[original.length - 1])
    original.delete_at(-1)
end

if flag
    puts "Yes"
else
    puts "No"
end


Measured memory_bytes: 1788