akhauriyash/Code-Regression huggingface dataset:
def main():
    INF = 100 * 40 + 1
    MX = 4000

    N, Ma, Mb = map(int, input().split())

    dp = [[INF] * (MX * 2 + 1) for _ in range(2)]
    i, j = 0, 1
    for _ in range(N):
        ai, bi, ci = map(int, input().split())
        x = Ma * bi - Mb * ai  # Σai:Σbi=Ma:Mb<->Ma*Σbi-Mb*Σai=0

        for k in range(-MX, MX + 1):
            dp[j][k] = dp[i][k]
        dp[j][x] = min(dp[j][x], ci)

        for k in range(-MX + x, MX + 1):
            dp[j][k] = min(
                dp[j][k],
                dp[i][k - x] + ci
            )
        i, j = j, i

    res = dp[i][0]
    print(-1 if res == INF else res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    B=list(map(int,input().split()))
    ans=[]
    for i in range(n):
        for j in range(len(B)-1,-1,-1):
            if B[j]==j+1:
                ans.append(B.pop(j))
                break
        else:
            print(-1)
            break
    else:
        print('\n'.join(map(str,ans[::-1])))

if __name__=='__main__':
    main()

Measured memory_bytes: 38384
/*
 * 16-10-15_ABC046_D.cpp
 *
 *  Created on: 2016/10/15
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;


string s;
int main(){
	cin >> s;
	int N= s.length(),P=0,ans;
	for(int i=0;i<N;i++)
		if(s[i] == 'p')
			P++;
	ans = N/2-P;
	cout << ans << endl;
	return 0;
}




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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

int pal(int a){
	int res = 0;
	while ( a > 0 ){
		res = res * 10 + a % 10;
		a /= 10;
	}
	return res;
}

int main( int argc, char *argv[] ) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a, b, c = 0;
	cin >> a >> b;
	for ( int i = a ; i < b + 1 ; i++ ){
		if ( pal(i) == i )
			c++;
	}
	cout << c << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

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

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

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

	ll t = n / k;
	
	ll x = n - (k * t);
	ll y = n - (k * (t + 1));
	if (x < 0)x *= -1;
	if (y < 0)y *= -1;
	
	ll ans = min(x, y);

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


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Integer[] hills = new Integer[10];
		for(int i=0;i<10;i++)
			hills[i]=Integer.parseInt(in.readLine());
		Arrays.sort(hills, Collections.reverseOrder());
		for(int i=0;i<3;i++)
			System.out.println(hills[i]);
	}
}

Measured memory_bytes: 16868
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int x;
	
	cin>>x;
	
	cout<<!(x)<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

const int NIL = -2000000010;

class Node{
public:
	int key;
	list<Node>::iterator parent,left,right;
};

class Tree{
public:
	list<Node> node_list;
	list<Node>::iterator root;
	vector<int> preorder,inorder;

	Tree(){
		root = node_list.end();
	}
	void insert(list<Node>::iterator z){
		list<Node>::iterator y = node_list.end();
		list<Node>::iterator x = root;

		while(x!=node_list.end()){
			y = x;
			if(z->key<x->key){
				x = x->left;
			}
			else{
				x = x->right;
			}
		}
		z->parent = y;
		if(y==node_list.end()){
			root = z;
		}
		else if(z->key<y->key){
			y->left = z;
		}
		else{
			y->right = z;
		}
	}
	void DFS(list<Node>::iterator parent){
		preorder.push_back(parent->key);
		
		if(parent->left==node_list.end()){
			inorder.push_back(parent->key);
		}
		else{
			DFS(parent->left);
			inorder.push_back(parent->key);
		}

		if(parent->right!=node_list.end()){
			DFS(parent->right);
		}
	}
	void DFS(){
		preorder.clear();
		inorder.clear();
		DFS(root);
	}
};

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

	int N=in();
	Tree tree;
	REP(i,N){
		string S=in<string>();
		if(S=="insert"){
			Node n;
			n.key = in();
			n.parent=n.left=n.right=tree.node_list.end();
			auto z = tree.node_list.insert(tree.node_list.end(),n);
			tree.insert(z);
		}
		else{
			tree.DFS();
			int num = tree.preorder.size();
			REP(j,num){
				cout << ' ' << tree.inorder[j];
			}
			cout << endl;
			REP(j,num){
				cout << ' ' << tree.preorder[j];
			}
			cout << endl;
		}
	}
	
	return 0;
}



Measured memory_bytes: 38216
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;
//ここから

void solve(){
  string s;
  cin>>s;
  int n=s.size();
  bool ng=false;
  for(int i=n-1;i>=0;--i){
    if(s[i]=='r'){
      if(i<2)ng=true;
      else if(s[i-2]=='s'){
        if(i<5)ng=true;
        string t=s.substr(i-5,6);
        if(t=="eraser")i-=5;
        else ng=true;
      }
      else if(s[i-2]=='m'){
        if(i<6)ng=true;
        string t=s.substr(i-6,7);
        if(t=="dreamer")i-=6;
        else ng=true;
      }
      else ng=true;
    }
    else if(s[i]=='e'){
      if(i<4)ng=true;
      string t=s.substr(i-4,5);
      if(t=="erase")i-=4;
      else ng=true;
    }
    else if(s[i]=='m'){
      if(i<4)ng=true;
      string t=s.substr(i-4,5);
      if(t=="dream")i-=4;
      else ng=true;
    }
    else ng=true;
  }
  if(ng)cout<<"NO";
  else cout<<"YES";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 512
import math
def main():
    S=int(input())
    ans=0
    for i in range(1,S+1):
        for j in range(1,S+1):
            tmp=math.gcd(j,i)
            for k in range(1,S+1):
                ans+=math.gcd(k,tmp)
    #print()
    print(ans)
    

main()


Measured memory_bytes: 9176
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
bool compare_by_b(pair<int, long long> a, pair<int, long long> b) {
    if(a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}
bool flg = false;
int ch[1001][1001];
int hi[1001];
vector<queue<int>> A;
void solv(int a, int b) {
    // cout << "in a:" << a << " b:" << b << endl;
    if(ch[a][b] == 1) {
        flg = true;
        return;
    }
    ch[a][b] = 1;
    while(A[b].front() != a) {
        // cout << "in" << endl;
        solv(b, A[b].front());
        if(flg) {
            return;
        }
    }
    int m = max(hi[a], hi[b]);
    hi[a] = m + 1;
    hi[b] = m + 1;
    A[a].pop();
    A[b].pop();
    return;
}
int main() {
    int N;
    cin >> N;
    queue<int> qe;
    A.push_back(qe);
    rep(i, 0, N) {
        queue<int> qe;
        rep(r, 0, N - 1) {
            int a;
            cin >> a;
            qe.push(a);
        }
        A.push_back(qe);
    }
    rep(i, 0, N + 1) { hi[i] = 0; }
    rep(i, 1, N + 1) {
        while(!A[i].empty()) {
            // cout << "while" << endl;
            solv(i, A[i].front());
            if(flg) {
                break;
            }
        }
    }
    if(flg) {
        cout << -1 << endl;
    } else {
        int max = 0;
        // cout << "hi" << endl;
        rep(i, 1, N + 1) {
            // cout << hi[i] << endl;
            if(hi[i] > max) {
                max = hi[i];
            }
        }
        cout << max << endl;
    }
}

Measured memory_bytes: 8576
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

// find x, y such that a * x + b * y = gcd(a, b)
template <class T>
T extgcd(T a, T b, T& x, T& y) {
  T d = a;
  if (b) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1, y = 0;
  }
  return d;
}

void NTL_1_E() {
  int a, b; cin >> a >> b;
  int x, y;
  extgcd(a, b, x, y);
  cout << x << " " << y << '\n';
}

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

  NTL_1_E();

  return 0;
}



Measured memory_bytes: 3216
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
long long me[300];
long long go(int n)
{     if(me[n])return me[n];
      return me[n]=go(n-1)+go(n-2);
}
int main()
{     int n,m,i,j,k;
      cin>>n;
      me[0]=2;
      me[1]=1;
      go(n);
      cout<<me[n]<<endl;
	  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

template <ll Mod>
struct modint {
  ll n;

  modint(const ll x = 0) : n(x) { while (n < 0) n += Mod; n %= Mod; }
  modint operator+(const modint r) const { return modint(*this) += r; }
  modint operator-(const modint r) const { return modint(*this) -= r; }
  modint operator*(const modint r) const { return modint(*this) *= r; }
  modint operator/(const modint r) const { return modint(*this) /= r; }
  modint &operator+=(const modint r) {
    n += r.n;
    if (n >= Mod) n -= Mod;
    return *this;
  }
  modint &operator-=(const modint r) {
    if (n < r.n) n += Mod;
    n -= r.n;
    return *this;
  }
  modint &operator*=(const modint r) { n = n * r.n % Mod; return *this; }
  modint &operator/=(const modint r) { return *this *= r.inv(); }
  modint pow(ll x) const {
    modint<Mod> ret(1), tmp(*this);
    while (x) {
      if (x&1) ret *= tmp;
      tmp *= tmp;
      x >>= 1;
    }
    return ret;
  }
  modint inv() const { return pow(Mod-2); }
  friend ostream& operator<<(ostream& os, const modint& obj) { return os << obj.n; }
  friend istream& operator>>(istream& is, modint& obj) { ll t; is >> t; obj = modint(t); return is; }
};
constexpr ll mod = 998244353;
using mint = modint<mod>;

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

  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) {
    cin >> a[i];
  }

  vl cnt(n);
  ll maxi = 0;
  rep(i, n) {
    cnt[a[i]]++;
    cmax(maxi, a[i]);
  }

  if (cnt[0] != 1 or a[0] != 0) {
    cout << 0 << endl;
    return 0;
  }

  mint ans = 1;
  ll pre;
  rep(i, n) {
    if (cnt[i] == 0 && i <= maxi) {
      cout << 0 << endl;
      return 0;
    }
    if (i != 0) ans *= mint(pre).pow(cnt[i]);
    pre = cnt[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  ll k = 0;
  k = n % 2 + 1;
  vector<ll> num(n);
  for(int i = 0;i < n;i++)cin >> num[i];
  vector<vector<ll>> dp(n + 1,vector<ll>(k + 2));
  for(int i = 0;i < n + 1;i++)for(int j = 0;j < k + 2;j++)dp[i][j] = -1000000000000000000;
  dp[0][0] = 0;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < k + 1;j++){
      if(dp[i + 1][j + 1] < dp[i][j])dp[i + 1][j + 1] = dp[i][j];
      ll add = 0;
      add = dp[i][j];
      if((i + j) % 2 == 0)add += num[i];
      if(dp[i + 1][j] < add)dp[i + 1][j] = add;
    }
  }
  ll res = 0;
  //cout << n << " " << k << endl;
  res = dp[n][k];
  cout << res << endl;
  return 0;
}




Measured memory_bytes: 18744
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


ll ans(ll n, ll a, ll b, ll c, ll d, map<ll,ll> &memo){
  if(n==0) return 0;
  if(n==1) return d;
  if(memo.count(n)) return memo.at(n);
  
  ll ko1 = ans(n/2,a,b,c,d,memo) + (n%2)*d + a;
  ll ko2 = ans((n+1)/2,a,b,c,d,memo) + (n%2)*d + a; 
  ll ko3 = ans(n/3,a,b,c,d,memo) + (n%3)*d + b;
  ll ko4 = ans((n+2)/3,a,b,c,d,memo) + (2-((n-1)%3))*d + b;
  ll ko5 = ans(n/5,a,b,c,d,memo) + (n%5)*d + c;
  ll ko6 = ans((n+4)/5,a,b,c,d,memo) + (4-((n-1)%5))*d + c; 

  vector<ll> p={ko1,ko2,ko3,ko4,ko5,ko6};
  sort(all(p));

  if(p[0]/d>n) p[0]=d*n;

  memo[n]=p[0];

  return p[0];
}


int main() {
  int t;
  cin >> t;

  map<ll,ll> memo;

  rep(i,t){
    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;

    memo.clear();
    
    cout << ans(n,a,b,c,d,memo) << endl;

  }

}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  unordered_map<int, int> wa;
  unordered_set<int> solved;
  int penalty = 0;
  for (int i = 0; i < M; i++) {
    int p;
    string S;
    cin >> p >> S;
    if (S == "WA") {
      wa[p]++;
    } else if (solved.count(p) == 0) {
      solved.insert(p);
      penalty += wa[p];
    }
  }
  cout << solved.size() << " " << penalty << endl;

  return 0;
}


Measured memory_bytes: 8520
#include <iostream>
#include<fstream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;

int fr[200005];

int main(){
   
	int n; cin >> n;
	for (int i = 2; i <= n; ++i) {
		int x; cin >> x;
		fr[x]++;
	}
	for (int i = 1; i <= n; ++i) {
		cout << fr[i] << ' ';
	}
}



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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int W, H, N;
    cin >> W >> H >> N;

    pair<int, int> left;
    pair<int, int> right;

    left.first = 0;
    left.second = 0;
    right.first = W;
    right.second = H;

    for (int i = 0; i < N; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            if (left.first < x)
                left.first = x;
        } else if (a == 2) {
            if (right.first > x)
                right.first = x;
        } else if (a == 3) {
            if (left.second < y)
                left.second = y;
        } else {
            if (right.second > y)
                right.second = y;
        }
    }

    int ans = 0;
    if ((right.first - left.first) > 0 && (right.second - left.second) > 0) {
        ans = (right.first - left.first) * (right.second - left.second);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {
    int bas = 0;
    int tri = 0;
    int fou = 0;

    VI total;
    VI odd;

    VI ans_total(1e06, INF);
    VI ans_odd(1e06, INF);

    while (1) {
        bas++;
        tri += bas;
        fou += tri;
        if (fou >= 1e06) {
            break;
        }
        total.push_back(fou);
        ans_total[fou] = 1;
        if (fou % 2 == 1) {
            odd.push_back(fou);
            ans_odd[fou] = 1;
        }

    }
    int size_total = (int)total.size();
    int size_odd = (int)odd.size();
    int posi;

    for (int i = 0; i < size_total; i++) {
        posi = total[i];
        for (int j = posi + 1; j < 1e06; j++) {
            ans_total[j] = min(ans_total[j], ans_total[posi] + ans_total[j - posi]);
        }
    }
    for (int i = 0; i < size_odd; i++) {
        posi = odd[i];
        for (int j = posi + 1; j < 1e06; j++) {
            ans_odd[j] = min(ans_odd[j], ans_odd[posi] + ans_odd[j - posi]);
        }
    }

    int input;
    while (1) {
        cin >> input;
        if (input == 0) {
            break;
        }
        cout << ans_total[input] << " " << ans_odd[input] << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int ans = 0;

    for(int i = 1; i <= n; ++i){
        int a;
        cin >> a;

        if(a % 2 == 1 && i % 2 == 1){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<stdio.h>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	n>=1200?printf("ARC\n"):printf("ABC\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
using Graph = vector<vector<pair<int, int> > >;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

int dp[100110];
int h[100110];

int main() {
	int N, K; cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
		dp[i] = INF10;
	}
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int k = 1; k <= K; k++) {
			dp[i + k] = min(dp[i + k], dp[i] + abs(h[i] - h[i + k]));
		}
	}
	cout << dp[N - 1] << endl;





	return 0;
}


Measured memory_bytes: 1024
// 以下のライブラリを使ってみる.
// beet氏.
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2117671#1
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 200050
int V;
vector<int> G[MAX_V], rG[MAX_V], vs;
bool used[MAX_V];
int cmp[MAX_V];
void add_edge(int from, int to){
    G[from].push_back(to);
    rG[to].push_back(from);
}

void dfs(int v){
    used[v] = 1;
    for(int i = 0; i < G[v].size(); i++) if(!used[G[v][i]]) dfs(G[v][i]);
    vs.push_back(v);
}

void rdfs(int v, int k){
    used[v] = 1;
    cmp[v] = k;
    for(int i = 0; i < rG[v].size(); i++) if(!used[rG[v][i]]) rdfs(rG[v][i],k);
}

int scc(){
    memset(used, 0, sizeof(used));
    vs.clear();
    for(int v = 0; v < V; v++) if(!used[v]) dfs(v);
    memset(used, 0, sizeof(used));
    int k = 0;
    for(int i = vs.size() - 1; i >= 0; i--) if(!used[vs[i]]) rdfs(vs[i], k++);
    return k;
}

int main(){
    
    int E, Q;
    scanf("%d %d", &V, &E);
    for(int i = 0; i < E; i++){
        int j, k;
        scanf("%d %d", &j, &k);
        add_edge(j, k);
    }
    scc();
    scanf("%d", &Q);
    for(int i = 0; i < Q; i++){
        int j, k;
        scanf("%d %d", &j, &k);
        if(cmp[j] == cmp[k]) printf("%d\n", 1);
        else                 printf("%d\n", 0);
    }
    return 0;

}


Measured memory_bytes: 13948
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

int main ()
{

    int D; cin >> D;
    if (D == 25) {
        cout << "Christmas" << endl;
    } else if (D == 24) {
        cout << "Christmas Eve" << endl;
    } else if (D == 23) {
        cout << "Christmas Eve Eve" << endl;
    } else if (D == 22) {
        cout << "Christmas Eve Eve Eve" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
#define re register
#define il inline
#define pb push_back
#define fp(i,a,b) for(re int i=a;i<=b;++i)
#define fq(i,a,b) for(re int i=a;i>=b;--i)
using namespace std;
const int N=2e5+100,mod=1e9+7;
int n,x,X,Y,mn[N],mn1=mod,mn2=mod,ans=1,inv[N],tot;
vector<int>V[N];
il ll gi()
{
  re ll x=0,t=1;
  re char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9')) x=x*10+ch-48,ch=getchar();
  if(ch=='-') t=-1,ch=getchar();
  while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
  return x*t;
}
int main()
{
  n=gi();X=gi();Y=gi();
  inv[0]=inv[1]=1;
  fp(i,1,n) x=gi(),V[x].pb(gi());
  fp(i,2,n) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
  fp(i,2,n) inv[i]=1ll*inv[i]*inv[i-1]%mod;
  fp(i,1,n)
    if(V[i].size())
      {
	sort(V[i].begin(),V[i].end());
        mn2=min(mn2,mn[i]=V[i][0]);
	if(mn2<mn1) swap(mn1,mn2);
      }
    else mn[i]=mod;
  fp(i,1,n)
    {
      re int mm=(mn[i]==mn1?mn2:mn1),sz=V[i].size();
      while(sz>1&&V[i][sz-1]+mm>Y&&V[i][sz-1]+mn[i]>X) --sz;
      if(mm+mn[i]<=Y) ans=1ll*ans*inv[sz]%mod,tot+=sz;
    }
  fp(i,1,tot) ans=1ll*ans*i%mod;
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 10880
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, D; vll path;
//***********//
int main() {
	ld A, B,H,M;
	cin >> A >> B >> H >> M;
	ld C = (360 / 12) * (H+M/60);
	ld D = (360 / 60) * M;
	ld E;
	if (C >= D) {
		E = C - D;
	}
	else {
		E = D - C;
	}
	E = E * PI / 180.0;
	//debug(C, D,E);
	cout << fixed << setprecision(20) << sqrt(A * A + B * B - (2 * A * B * cos(E)));
}

Measured memory_bytes: 4172
import java.util.*;

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

        int A = sc.nextInt();
        int B = sc.nextInt();

        for (int i = 0; i < 10000; i++) {
            if (Math.floor(i * 0.08) == A && Math.floor(i * 0.1) == B) {
                System.out.println(i);
                return;
            }
        }

        System.out.println(-1);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 620;
const int M = N * N;
int n;
vector<int> g[M];
int col[M];

bool checkCell(int x, int y) {
	return min(x, y) >= 0 && max(x, y) < n;
}

void build(int d) {
	vector<pii> mv;
	int y = 0;
	while(y * y <= d) y++;
	for (int x = 0; x * x <= d; x++) {
		while(x * x + y * y > d) y--;
		if (x * x + y * y != d) continue;
		mv.push_back(mp(x, y));
		if (y != 0) mv.push_back(mp(x, -y));
		if (x != 0) mv.push_back(mp(-x, y));
		if (x != 0 && y != 0) mv.push_back(mp(-x, -y));
	}
	for (int i = 0; i < n * n; i++)
		g[i].clear();
	for (int x = 0; x < n; x++)
		for (int y = 0; y < n; y++) {
			int v = x * n + y;
			for (pii t : mv) {
				int xx = x + t.first, yy = y + t.second;
				if (!checkCell(xx, yy)) continue;
				g[v].push_back(xx * n + yy);
			}
		}
}

bool dfs(int v) {
//	cerr << "dfs " << v << endl;
	for (int u : g[v]) {
		if (col[u] == -2) continue;
		if (col[u] == -1) {
			col[u] = col[v] ^ 1;
			if (!dfs(u)) return false;
		}
		if (col[v] == col[u]) return false;
	}
	return true;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int d1, d2;
	scanf("%d%d%d", &n, &d1, &d2);
	n *= 2;
	for (int i = 0; i < n * n; i++)
		col[i] = -1;
	build(d1);
	for (int i = 0; i < n * n; i++) {
		if (col[i] == -1) {
			col[i] = 0;
			if (!dfs(i)) throw;
		}
	}
	int c0 = 0, c1 = 0;
	for (int i = 0; i < n * n; i++) {
		if (col[i] == 0) c0++;
		if (col[i] == 1) c1++;
	}
	if (c1 > c0) {
		for (int i = 0; i < n * n; i++)
			if (col[i] >= 0)
				col[i] ^= 1;
	}
	for (int i = 0; i < n * n; i++) {
		if (col[i] == 0)
			col[i] = -1;
		if (col[i] == 1)
			col[i] = -2;
	}

	build(d2);
	for (int i = 0; i < n * n; i++) {
		if (col[i] == -1) {
			col[i] = 0;
			if (!dfs(i)) throw;
		}
	}
	c0 = c1 = 0;
	for (int i = 0; i < n * n; i++) {
		if (col[i] == 0) c0++;
		if (col[i] == 1) c1++;
	}
	if (c1 > c0) {
		for (int i = 0; i < n * n; i++)
			if (col[i] >= 0)
				col[i] ^= 1;
	}
	for (int i = 0; i < n * n; i++) {
		if (col[i] == 0)
			col[i] = -1;
		if (col[i] == 1)
			col[i] = -2;
	}

	int ans = n * n / 4;
	for (int i = 0; ans > 0 && i < n * n; i++) {
		if (col[i] == -1) {
			ans--;
			printf("%d %d\n", i / n, i % n);
		}
	}

	return 0;
}


Measured memory_bytes: 75264
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

constexpr int MAX_N = 1 << 24;
int b[25];

bool intersects(vector<int> &x, vector<int> &y, vector<int> &r, int i, int j) {
    int dx = (x[i] - x[j]) * (x[i] - x[j]);
    int dy = (y[i] - y[j]) * (y[i] - y[j]);
    int dist1 = dx + dy;
    int dist2 = (r[i] + r[j]) * (r[i] + r[j]);
    return dist1 < dist2;
}

int main() {

    while (true) {

        int N;
        cin >> N;

        if (N == 0) break;

        vector<int> x(N), y(N), r(N), c(N);
        for (int i = 0; i < N; i++) cin >> x[i] >> y[i] >> r[i] >> c[i];

        //上からi枚目
        for (int i = 0; i < N; i++) {
            b[i] = 0;
            //i枚目よりあとに降ってきたものを見る
            for (int j = 0; j < i; j++) {
                if (intersects(x, y, r, i, j)) b[i] |= (1 << j);
            }
        }

        vector<int> dp(1 << N, -1);
        int ans = 0;
        int to = (1 << N);
        dp[0] = 0;

        //すべての円の使い方の状態を見る
        for (int i = 0; i < to; i++) {
            //このような円の状態はありえない
            if (dp[i] == -1) continue;

            //消せる円盤のペア(j, k)を探す
            for (int j = 0; j < N - 1; j++) {
                if ((i & (1 << j)) != 0 || (i & b[j]) != b[j]) continue;

                //jより下にあるkをさがす
                for (int k = j + 1; k < N; k++) {
                    if (c[j] != c[k] || (i & (1 << k)) != 0 || (i & b[k]) != b[k]) continue;

                    int next = i | (1 << j) | (1 << k);
                    dp[next] = max(dp[next], dp[i] + 2);

                }
            }
        }

        for (int i = 0; i < (1 << N); i++) ans = max(ans, (int) dp[i]);
        cout << ans  << endl;
    }

}














































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

int main()
{
    int K, T; cin >> K >> T;

    auto m = numeric_limits<int>::min();
    for (auto i = 0; i < T; i++)
    {
        int x; cin >> x;
        m = max(m, x);
    }

    if (m <= (K+1)/2) cout << 0 << endl;
    else cout << (K-1) - 2*(K-m) << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = sorted([int(a) for a in input().split()])[::-1]
BC = []
for num in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))
lis = sorted(BC, key = lambda x: -x[1])
total = 0
counter = 0
while counter < N:
    if not lis == []:
        if lis[0][1] > A[0]:
            (b, c) = lis.pop(0)
            b = min(b, N - counter)
            total += c * b
            counter += b
        else:
            total += A.pop(0)
            counter += 1
    else:
        total += A.pop(0)
        counter += 1
print(total)

Measured memory_bytes: 26460
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <ctime>
#include <deque>
using namespace std;

#define N 2100000

int n, m, x, y;
vector <int> ve[N];
bool used[N];

void add(int x, int y) {
	ve[x].push_back(y);
}

void dfs(int x) {
	if (used[x])
		return ;
	used[x] = true;
	for (int i = 0; i < (int) ve[x].size(); i++)
		dfs(ve[x][i]);
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &x);
		while (x--) {
			scanf("%d", &y);
			add(n + y, i);
			add(i, n + y);
		}
	}
	dfs(1);
	bool ok = true;
	for (int i = 1; i <= n; i++)
		if (!used[i])
			ok = false;
	if (ok)
		printf("YES\n");
	else
		printf("NO\n");
}


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

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif
const int N=100005;
int a[N],b[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  cin>>n;
  rep(i,1,n+2) cin>>a[i];
  rep(i,1,n+1) cin>>b[i];
  ll ans=0;
  repv(i,1,n+1)
    {
      int diff=0;
      diff=min(b[i],a[i+1]); a[i+1]-=diff; ans+=diff;
      diff=min(a[i],b[i]-diff); a[i]-=diff; ans+=diff;
    }
  cout<<ans<<endl;
  return 0 ;
}


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

ll minV(ll a,ll b){
    ll r, x, tmp;
    x = a * b;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return x/b;
}

int main(){
    ll A,B,C,D,ans=0;
    cin>>A>>B>>C>>D;
    ll ansB = B - (B/C + B/D) + B/minV(C,D);
    A--;
    ll ansA = A - (A/C + A/D) + A/minV(C,D);
    cout<<ansB-ansA<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;

int main(){
    int R,G,B,N;
    cin >> R >> G >> B >> N;
    int ans = 0;
    for(int r=0; r*R<=N; r++){
        for(int g=0; g*G+r*R<=N; g++){
            if((N-g*G-r*R)%B == 0) ans ++;
        }
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input(""))
aa=input("").split(" ")
lista=[]
for i in aa:
    lista+=[int(i)]
s=1000
a=0
for i in range(n-1):
    tt=lista[i]
    t=lista[i+1]-tt
    
    if(t>0):
        a+=s//tt
        s%=tt
    elif(t<0):
        
        s+=tt*a
        a=0
s+=a*lista[n-1]
print(s)

Measured memory_bytes: 9196
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    rep(i,n) ans += llabs(a[i] - a[n/2]);
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4744
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

constexpr ll MOD = (ll)1e9 + 7;

ll MODpow(ll n, ll m) {
    ll result = 1;
    while (m) {
        if (m % 2 == 1) {
            result *= n;
            result %= MOD;
        }

        m /= 2;
        n *= n;
        n %= MOD;
    }

    return result;
}

int main() {
    ll N, C;
    cin >> N >> C;
    vector<ll> A(N), B(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (ll i = 0; i < N; i++) {
        cin >> B[i];
    }

    //sum[i][j] := iまでの自然数をそれぞれj乗したものの和
    constexpr ll MAX = 400;
    vector<vector<ll>> sum(MAX + 1, vector<ll>(MAX + 1, 0));
    sum[0][0] = 1;
    for (ll i = 1; i <= MAX; i++) {
        sum[i][0] = 1;
        for (ll j = 1; j <= MAX; j++) {
            sum[i][j] = sum[i][j - 1] * i % MOD;
        }
        for (ll j = 0; j <= MAX; j++) {
            (sum[i][j] += sum[i - 1][j]) %= MOD;
        }
    }

    //dp[i][j] := i番目まで考えて次数Cまでを作ったときの和
    vector<vector<ll>> dp(N + 1, vector<ll>(C + 1, 0));
    dp[0][0] = 1;

    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j <= C; j++) {
            for (ll k = 0; k <= j; k++) {
                dp[i + 1][j] += dp[i][j - k] * ((sum[B[i]][k] - sum[A[i] - 1][k] + MOD) % MOD) % MOD;
                dp[i + 1][j] %= MOD;
            }
        }
    }

    cout << dp[N][C] << endl;
}

Measured memory_bytes: 2816
#include <iostream>
#include <cmath>
#include <algorithm>
#include <deque>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
// #define mp make_pair
// #define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
#define show(x) cout << #x << " = " << x << endl;

int memo[301];

ll gcd(ll a, ll b){
  if(b==0){
    return a;
  }else{
    return gcd(b, a%b);
  }

}

int main(){
  int n;
  cin >> n;
  ll t, ans = 1;
  REP(i,n){
    cin >> t;
    ans = ans * (t / gcd(ans,t));
  }

  cout << ans << endl;



  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
edges = [tuple(map(int, input().split())) for _ in range(m)][::-1]
ans = [0] * m

class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, x):
        if self.parent[x] < 0: return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return
        if self.size(x) < self.size(y): x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
    
    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parent[self.find(x)]

cnt = n * (n-1) // 2
uf = UnionFind(n)
for i, (x, y) in enumerate(edges):
    x -= 1; y -= 1
    ans[i] = cnt
    if uf.same(x, y): continue
    cnt -= uf.size(x) * uf.size(y)
    uf.unite(x, y)

print(*ans[::-1], sep="\n")


Measured memory_bytes: 25904
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n;
		cin >> n;
		int z1, z2;
		int up, down;
		up = down = 0;
		for (int j = 0; j < n; j++) {
			cin >> z2;
			if (j == 0) {
			} else {
				if (z1 > z2) {
					down = max(down, z1-z2);
				} else {
					up = max(up, z2-z1);
				}
			}
			z1 = z2;
		}
		cout << up << ' ' << down << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vii t(n), x(n), y(n);
    int now = 0;
    rep(i, 0, n) {
        cin >> t[i] >> x[i] >> y[i];
    }
    int px = 0, py = 0;
    rep(i, 0, n) {
        int tdiff = t[i] - now, ddiff = abs(x[i] - px) + abs(y[i] - py);
        if (tdiff < ddiff || (tdiff % 2) != (ddiff % 2)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1408
N, A, B, C, D = map(int, input().split())
MOD = 10 ** 9 + 7
fact = [1] * (N + 1)
frev = [1] * (N + 1)

dp = [0] * (N + 1)
dp[0] = 1

for i in range(1, N + 1):
    v = fact[i] = (fact[i - 1] * i) % MOD
    frev[i] = pow(v, MOD - 2, MOD)

Y = [None] * (N + 1)
for g in range(A, min(N // C, B) + 1):
    p = C * g
    q = D * g
    y = frev[g]
    Y[p: min(q, N) + 1: g] = (pow(y, j, MOD) * frev[j]
                              for j in range(C, min(D, N // g) + 1))
    dp[p:] = (dp[i] + frev[N - i] * sum(dp[i - j] * fact[N - i + j] * Y[j]
              for j in range(p, min(q, i) + 1, g)) % MOD
              for i in range(p, N + 1))

print(dp[N] % MOD)

Measured memory_bytes: 61020
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    vector<int> A(26,0);

    for(int i=0;i<4;i++){
        A[s[i]-'A']++;
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    if(A[0]==A[1]&&A[0]==2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

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

#define ll long long

int main(){
    int S;
    cin >> S;
    int M[2] = {};
    if(0 < S/100 && S/100 < 13){
        M[0] = 1;
    }
    if(0 < S%100 && S%100 < 13){
        M[1] = 1;
    }
    if(M[0] & M[1])cout << "AMBIGUOUS" << endl;
    else if(M[1])cout << "YYMM" << endl;
    else if(M[0])cout << "MMYY" << endl;
    else cout << "NA" << endl;
    return 0;
}

Measured memory_bytes: 256
def gcd(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    elif x % 2 == 0 and y % 2 == 0:
        return 2 * gcd(x//2, y//2)
    elif x % 2 == 0:
        return gcd(x//2, y)
    elif y % 2 == 0:
        return gcd(x, y//2)
    elif y >= x:
        return gcd(x, (y-x)//2)
    else:
        return gcd((x-y)//2, y)


n, m = tuple(map(int, input().split()))
s = list(input())
t = list(input())
g = gcd(n, m)
ng = n // g
mg = m // g
res = n * m // g
for i in range(0, g):
    if s[ng * i] != t[mg * i]:
        res = -1
        break

print(res)


Measured memory_bytes: 4548
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


int main() {
    int n;
    cin >> n;
    vector<ll> as(n), bs(n);
    rep(i, n)cin >> as[i];
    rep(i, n) cin >> bs[i];

    priority_queue<P> q;
    rep(i, n) q.push(P(bs[i], i));

    auto a_get = [&](int i) {
        if (i == -1) return as.back();
        if (i == n) return as.front();
        return as[i];
    };

    auto b_get = [&](int i) {
        if (i == -1) return bs.back();
        if (i == n) return bs.front();
        return bs[i];
    };

    ll ans = 0;

    while (!q.empty()) {
        P p = q.top();
        q.pop();

        ll l = b_get(p.second - 1);
        ll c = b_get(p.second);
        ll ac = a_get(p.second);
        assert(p.first == c);
        ll r = b_get(p.second + 1);

        if (!(l + r <= c)) continue;
        if (!(ac < c)) continue;


        ll lr = l + r;
        ll diff = c - ac;
        ll nb = diff % lr;
        ll count = diff / lr;

        if (count == 0) break;
        ans += count;
        bs[p.second] = ac + nb;

        if (bs[p.second] != ac) {
            q.push(P(bs[p.second], p.second));
        }
    }

    if (as == bs) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }

}


Measured memory_bytes: 9584