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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}

int gcd (int x, int y, int z){
    int m = __gcd(x, y);
    int n = __gcd(y, z);
    return __gcd(m, n);
}
long long k, ans;
int main(){
    k = read();
    for (int a = 1; a <= k; a++){
        for (int b = 1; b <= k; b++){
            for (int c = 1; c <= k; c++){
                ans += gcd(a, b, c);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
n = int(input())
l = [["", 0, i + 1] for i in range(n)]
for i in range(n):
    new = input().split()
    l[i][0] = new[0]
    l[i][1] = 100 - int(new[1])
l.sort()
for i in range(n):
    print(l[i][2])


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


int main(){
  int n,m;
  while(cin >> n&&n!=0){
  
    char conv[n][2];
    for(int i=0;i<n;i++){
      cin >> conv[i][0] >> conv[i][1];
    }
  
    cin >> m;

    char inp[m];

    for(int i=0;i<m;i++){
      cin >> inp[i];
      for(int j=0;j<n;j++){
	if(inp[i]==conv[j][0]){
	  inp[i]=conv[j][1];
	  break;
	}
      }
    }


    for(int i=0;i<m;i++){
      cout << inp[i];
    }
    cout << endl;
  }
  

}

Measured memory_bytes: 3180
void main() {
    long n = readln.chomp.to!long;
    writeln(2 * n / gcd(2, n));
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.uni;

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> x(N);
  for(int i=0;i<N;i++){
    cin >> x.at(i);
  }
  int ans=0;
  for(int i=0;i<N;i++){
    ans += 2*min(x.at(i),K-x.at(i));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

/*==================================================*/
/*variable*/
int N;
int F[105][5][2];
int P[105][11];

int ans = -INF;

/*==================================================*/
/*function*/
/*==================================================*/

int main() {

    cin>>N;
    REP(i,0,N){
        REP(j,0,5){
            cin>>F[i][j][0]>>F[i][j][1];
        }
    }

    REP(i,0,N)REP(j,0,11){
        cin>>P[i][j];
    }

    REP(state, 1, (1<<10)){
        int ttt = 0;

        REP(i,0,N){
            int d = 0;
            REP(j,0,5){
                REP(k,0,2){
                    if( ((state & (1<<((4-j)*2+(1-k)))) != 0) & (F[i][j][k] == 1) ) d++;
                }
            }
            ttt += P[i][d];
            
        }

        ans = max(ans, ttt);
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n,a[2][100]={};
 cin>>n;
 for(int i=0;i<2;i++) 
  for(int j=0;j<n;j++)
   cin>>a[i][j];
  
  int sum=a[1][n];
  for(int i=0;i<n;i++)sum+=a[0][i];
  for(int i=0;i<n;i++){
   int sum1=0;
   for(int j=0;j<=i;j++)sum1+=a[0][j];	
   for(int k=i;k<n;k++)sum1+=a[1][k];
   if(sum1>sum)sum=sum1;
  }
  cout<<sum<<endl;
  return 0;
}

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

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

  if (X == 3 || X == 5 || X == 7)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3552
N = list(input())
if(N[-1]== "2" or N[-1]== "4" or N[-1]== "5" or N[-1]== "7" or N[-1]== "9"):
    print("hon")
elif(N[-1]== "0" or N[-1]== "1" or N[-1]== "6" or N[-1]== "8"):
    print("pon")
elif(N[-1]== "3"):
    print("bon")

Measured memory_bytes: 9028
a, b, x = map(int, input().split())

# 猫の絶対数 => a
# 犬の絶対数 => d = b-x
# いてほしい猫の数 => x
# 不明な犬猫の数 => b-a

# いるべき総数よりも猫が多い　またはいてほしい猫の数よりも現在の猫の数のほうが多い
if a+b < x or x-a < 0:
  print('NO')
else:
  print('YES')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))

template <class T>
constexpr T modp(T x, T y)
{
    return (y + x % y) % y;
}
template <class T>
constexpr T sq(T x)
{
    return x * x;
}
template <class T>
constexpr double divd(T x, T y)
{
    static_cast<double>(x) / static_cast<double>(y);
}

template <class T>
T nextInput()
{
    T t;
    cin >> t;
    return t;
}

#define netint nextInput<ll>()
#define netstr nextInput<string>()

template <class T>
void print(T&& t)
{
    cout << forward<T&&>(t) << endl;
}

void print(double t) { cout << fixed << setprecision(14) << t << endl; }

//

int main()
{
    //
    string N = netstr;
    int cnt = 0;
    rep(i, 1, N.size()) if (N[i] == '9') cnt++;
    if (cnt != N.size() - 1)
        print((N.size() - 1) * 9 + N[0] - '0' - 1);
    else {
        print((N.size() - 1) * 9 + N[0] - '0');
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int f[100001],a[100001];
int main()
{
    int i,n,min_v=INT_MAX,k,j;
    scanf("%d %d",&n,&k);
    for(i=1;i<=n;i++)
    	scanf("%d",&a[i]);
    for(i=2;i<=n;i++)
    {
    	f[i]=INT_MAX;
    	for(j=1;i-j>=1&&j<=k;j++)
    		f[i]=min(abs(a[i-j]-a[i])+f[i-j],f[i]); 
	}
	printf("%d",f[n]);
    return 0;
}

Measured memory_bytes: 1024
from collections import deque
INF = 1145141919810364364334
s = [None]
r = [None]

n = int(input())
for _ in range(n):
    temp = list(map(int,input().split()))
    s.append(temp[2:])
    
d = [INF] * (n+1)

d[1] = 0
q = deque()
q.append(1)

while q:
    x = q.popleft()
    for i in s[x]:
        if d[i] == INF:
            q.append(i)
            
        d[i] = min(d[x] + 1 , d[i])
        
for i in range(1,n+1):
    if d[i] == INF:
        d[i] = -1
    print(i,d[i])


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  vector<string> s(N);
  vector<int>  t(N);

  for(int i = 0; i < N; i++){
    cin >> s[i] >> t[i];
  }

  string X;
  cin >> X;
  bool start = false;
  int ans = 0;
  for(int i = 0; i < N; i++){
    if(start){
      ans += t[i];
    }
    if(X == s[i]){
      start = true;
    }
  }

  cout << ans << endl;

  

  return 0;
}


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

const int MAX_N = 2e5;
const int64_t MOD = 1e9 + 7;
int64_t n, k;

int64_t dp[MAX_N + 2];

void solve() {
    for (int64_t i = k; i <= n + 1; i++) {
        dp[i] = dp[i - 1] + (i * (2 * n - i + 1) / 2) - ((i - 1) * i / 2) + 1;
    }
    
    cout << dp[n + 1] % MOD << endl;
}

int main() {
    cin >> n >> k;
    solve();
}

Measured memory_bytes: 5080
#include <stdio.h>
int main(void){
    int w,h,x,y,r;
    scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
    if((x - r >= 0)&&(x + r <= w)&&(y - r >= 0)&&(y + r <= h)){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2100
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Vector.Unboxed   as VU
import qualified Control.Arrow         as Arrow


getI :: BSC8.ByteString -> Maybe (Int, BSC8.ByteString)
getI = fmap (Arrow.second BSC8.tail) . BSC8.readInt
getABC :: IO (Int, Int, Int)
getABC = (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2)) . VU.unfoldrN 3 getI <$> BSC8.getLine

main :: IO ()
main = do
  (a, b, c) <- getABC
  BSC8.putStrLn $ solver a b c

solver :: Int -> Int -> Int -> BSC8.ByteString
solver a b c
  | a == 5 && b == 5 && c == 7 = "YES"
  | a == 5 && b == 7 && c == 5 = "YES"
  | a == 7 && b == 5 && c == 5 = "YES"
  | otherwise                  = "NO"


Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
typedef long long ll;
 
int main() {
  ll a,b,c,d,e,k;cin>>a>>b>>c>>d>>e>>k;
  cout<<(e-a>k ? ":(":"Yay!");
  return 0;
}

Measured memory_bytes: 256
#abc122_b
#word = 'HATAGAYA'
#word = 'SHINJUKU'
word = input()
chl = ['A','C','G','T']
lmax = 0
temp = 0
for ch in word:
    if ch in chl:
        temp += 1
    else:
        temp = 0
    if temp >= lmax:
            lmax = temp
print(lmax)

Measured memory_bytes: 2940
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (PrintWriter out = new PrintWriter(System.out); Scanner sc = new Scanner(System.in);) {

			int n = sc.nextInt();
			int m = sc.nextInt();
			int q = sc.nextInt();
			List<int[]> listlr = new ArrayList<>();
			for (int i = 0; i < m; i++) {
				int[] lr = new int[2];
				lr[0] = sc.nextInt() - 1;
				lr[1] = sc.nextInt() - 1;
				listlr.add(lr);
			}

			int[][] t = new int[n][n];

			for (int[] lr : listlr) {
				t[lr[0]][lr[1]]++;
			}

			for (int i = 1; i < n; i++) {
				for (int j = i - 1; j >= 0; j--) {
					t[j][i] = t[j][i] + t[j + 1][i];
				}
			}

			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					t[i][j] = t[i][j] + t[i][j - 1];
				}
			}

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

		}
	}

}


Measured memory_bytes: 158404
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename F>
static inline constexpr decltype(auto) fix(F&& f) noexcept {
  return [f = std::forward<F>(f)](auto&&... args) {
    return f(f, std::forward<decltype(args)>(args)...);
  };
}
template<typename T>
static inline T fin() { T t; cin >> t; return std::move(t); }

int main() {
  i64 n;
  cin >> n;
  vector<i64> h(n);
  for(int i = 0;i < n;i++) cin >> h[i];
  h[0]--;
  for(int i = 1;i < n;i++) {
    if(h[i] > h[i - 1]) {
      h[i]--;
    }
    if(h[i - 1] <= h[i]) {

    }
    else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 1024
#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+1);
	rep(i,n+1) cin >> a[i];
	ll ans = 0;
	rep(i,n){
		ll b;
		cin >> b;
		if(b >= a[i]){
			ans += a[i];
			b -= a[i];
		}
		else{
			ans += b;
			b = 0;
		}
		if(b >= a[i+1]){
			ans += a[i+1];
			a[i+1] = 0;
		}
		else{
			ans += b;
			a[i+1] -= b;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

const int MAX = 8000;
bool dpx[2][2*MAX];
bool dpy[2][2*MAX];

int main(){
    string op; cin >> op;
    int gx,gy; cin >> gx >> gy;

    const int N = op.size();

    vector<vector<int> > disp(2);
    int d=0;
    for(int i=0;i<N;i++){
        int count = 0;
        while(op[i] == 'F' && i < N){
            count++;
            i++;
        }
        disp[d].push_back(count);
        d = 1-d;
    }
    const int start = 8000; //原点を(8000,8000)と考える
    dpx[0][start] = true;
    dpy[0][start] = true;
    for(int i=0;i<disp[0].size();i++){
        for(int j=0;j<2*MAX;j++){
            if(dpx[i%2][j]){
                dpx[(i+1)%2][j+disp[0][i]] = true;
                if(i>0){
                    dpx[(i+1)%2][j-disp[0][i]] = true;
                }
            }
            dpx[i%2][j] = false;
        }
    }
    for(int i=0;i<disp[1].size();i++){
        for(int j=0;j<2*MAX;j++){
            if(dpy[i%2][j]){
                dpy[(i+1)%2][j+disp[1][i]] = true;
                dpy[(i+1)%2][j-disp[1][i]] = true;
                dpy[i%2][j] = false;
            }
        }
    }

    if(dpx[(disp[0].size())%2][gx + start] && dpy[(disp[1].size())%2][gy + start]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main(){
	int a, b, c; cin >> a >> b >> c;
	if(c >= a && c <= b) puts("Yes");
	else puts("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 301
using namespace std;
int w[N],mem[N][N],used[N][N];

int dfs(int l,int r){
  if(l==r) return 0;
  if(r-l==1) return 2*(abs(w[l]-w[r])<=1);
  if(used[l][r]++) return mem[l][r];
  
  int res=0;
  if(abs(w[l]-w[r])<=1&&dfs(l+1,r-1)==r-l-1)res=2+dfs(l+1,r-1);
  
  for(int i=l;i<r;i++) res=max(res,dfs(l,i)+dfs(i+1,r));
  return mem[l][r]=res;
}

int main(){
  int n;
  while(cin>>n,n){
    for(int i=0;i<n;i++)cin>>w[i];
    memset(used,0,sizeof(used));
    cout<<dfs(0,n-1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int A, B, m;
    cin >> A >> B >> m;
    vint a(A), b(B);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];

    int ans = vmin(a) + vmin(b);
    rep(i, m) {
        int x, y, c;
        cin >> x >> y >> c;
        --x;
        --y;
        ans = min(ans, a[x]+b[y]-c);
    }

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

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

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  vector<int> Nums;

  int now = 1;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == (char)('0' + now)) {
      cnt++;
    } else {
      Nums.push_back(cnt);
      now = 1 - now;
      cnt = 1;
    }
  }
  if (cnt != 0) {
    Nums.push_back(cnt);
  }
  if (Nums.size() % 2 == 0) {
    Nums.push_back(0);
  }

  vector<int> cum(Nums.size() + 1);
  for (int i = 0; i < (int)Nums.size(); i++) {
    cum[i + 1] = cum[i] + Nums[i];
  }

  // 1 0 1 0 1  0  1
  // 0 1 3 5 8 10 14
  int Add = 2 * k + 1;
  int ans = 0;
  for (int i = 0; i < (int)Nums.size(); i += 2) {
    int left = i;
    int right = min(i + Add, (int)Nums.size());
    int tmp = cum[right] - cum[left];
    ans = max(tmp, ans);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 1272
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int a = 0;
	int A[2020] = {};
	A[0] = 1;

	ll kotae = 0;
	int tmp = 0;
	int are = 1;
	char c;
	while((c = getchar_unlocked()) >= '0') {
		tmp += (c - '0') * are;
		tmp %= 2019;
		kotae += A[tmp]++;
		are *= 202;
		are %= 2019;
	}

	printf("%lld\n", kotae);


	Would you please return 0;
}

Measured memory_bytes: 1604
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const ll mod = 1e9+7;
 
int n;
 
int main()
{
    cin >> n;
    vl t,a;
    t.resize(n); a.resize(n);
    rep(i,n) cin >> t[i] >> a[i];
 
    ll l = 1;
    ll r = 1;
    rep(i,n){
        if(l*a[i] == r*t[i]) continue;
        ll k = max((long double)ceil((long double)l/t[i]), (long double)ceil((long double)r/a[i]));
        l = t[i]*k; r = a[i]*k;
    }
    cout << (ll)(r+l) << endl;
}

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

int64 N, M, L, K[2000], S[100000], dp[2000][2000];

int64 Range(int a, int b) {
  if(a < b) swap(a, b);
  if(b == 0) return(S[a]);
  return(S[a] - S[b - 1]);
}

int64 rec(int idx, int right, int left){
  if(idx == N) return Range( K[right], K[left]) / L;
  if(~dp[right][left]) return dp[right][left];
  int64 ret = 1LL << 55;
  ret = min( ret, rec( idx + 1, idx, left) + Range( K[right], K[idx]) / L);
  ret = min( ret, rec( idx + 1, right, idx) + Range( K[left], K[idx]) / L);
  return dp[right][left] = ret;
}
 
int main()
{
  fill_n( *dp, 2000 * 2000, -1);
  cin >> N >> M >> L;
  for(int i = 0; i < N; i++) {
    cin >> K[i];
    --K[i];
  }
  for(int i = 0; i < M; i++) {
    cin >> S[i];
    if(i > 0) S[i] += S[i - 1];
  }
  sort(K, K + N);
  cout << rec(1, 0, 0) << endl;
}

Measured memory_bytes: 33376
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

vector<ll> dx={1,0,-1,0};
vector<ll> dy={0,1,0,-1};

inline bool valid(int x,int y,int H,int W){return 0<=x && x<H && 0<=y && y<W;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll H,W,K;
  cin>>H>>W>>K;
  vector<string> A(H);
  cin>>A;
  vector<vector<ll>> dp1(H,vector<ll>(W,MOD*MOD));
  queue<pll> Q;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(A[i][j]=='S'){dp1[i][j]=0; Q.push({i,j});}
    }
  }
  while(!Q.empty()){
    pll u=Q.front(); Q.pop();
    int x=u.F,y=u.S;
    if(dp1[x][y]==K){continue;}
    for(int j=0;j<4;j++){
      int X=x+dx[j];
      int Y=y+dy[j];
      if(valid(X,Y,H,W) && dp1[X][Y]>dp1[x][y]+1 && A[X][Y]!='#'){
        dp1[X][Y]=dp1[x][y]+1;
        Q.push({X,Y});
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(dp1[i][j]<=K){dp1[i][j]=2*K-1; Q.push({i,j});}
      else{dp1[i][j]=MOD*MOD;}
    }
  }
  while(!Q.empty()){
    pll u=Q.front(); Q.pop();
    int x=u.F,y=u.S;
    for(int j=0;j<4;j++){
      int X=x+dx[j];
      int Y=y+dy[j];
      if(valid(X,Y,H,W) && dp1[X][Y]>dp1[x][y]+1){
        dp1[X][Y]=dp1[x][y]+1;
        Q.push({X,Y});
      }
    }
  }
  ll ans=MOD*MOD;
  for(int i=0;i<H;i++){
    ans=min<ll>(ans,dp1[i][0]);
    ans=min<ll>(ans,dp1[i][W-1]);
  }
  for(int j=0;j<W;j++){
    ans=min<ll>(ans,dp1[0][j]);
    ans=min<ll>(ans,dp1[H-1][j]);
  }
  ans/=K;
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 16272
A, a = input().split()
B, b = input().split()
T = input()

A = int(A)
a = int(a)
B = int(B)
b = int(b)
T = int(T)

distance = abs(A-B)
speed = a-b

if distance - speed * T <= 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            long x = Long.parseLong(in.next());
            long ans1 = 0;
            long ans2 = 0;

            for (int i = -200; i < 200; i++) {
                for (int j = -200; j < 200; j++) {
                    if ((long) Math.pow(i, 5.0) - (long) Math.pow(j, 5.0) == x) {
                        ans1 = i;
                        ans2 = j;
                        // 出力
                        out.println(ans1 + " " + ans2);
                        return;
                    }
                }
            }

        }

    }
}



Measured memory_bytes: 38896
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    long N;
    void solve()
    {
        var Q = cin.nextlong;
        var H = cin.nextlong;
        var S = cin.nextlong;
        var D = cin.nextlong;
        N = cin.nextlong;

        long x = (N / 2) * (Math.Min(Math.Min(Q * 8, H * 4), Math.Min(S * 2, D)));
        long y = (N % 2) * (Math.Min(Math.Min(Q * 4, H * 2), S));
        WriteLine(x + y);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11216
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
long long power(long long n,int x,long long MOD){
    long long a = 1;
    long long b = x;
    while(n>0){
        if(n%2==1){
            a*=b;
            a%=MOD;
        }
        n/=2;
        b = b*b;
        b%=MOD;
    }
    return a;
}
int main(){
    int n;
    cin >> n;
    long long a;
    long long zo[62][2];
    rep(i,62){
        rep(j,2) zo[i][j]=0;
    }
    rep(i,n){
        cin >> a;
        int cnt = 0;
        while(a>0){
            zo[cnt][a%2]++;
            a/=2;
            cnt++;
        }
    }
    long long ans = 0;
    //cout << zo[0][0] << " " << zo[1][0] << endl;
    rep(i,62){
        if(zo[i][0]!= 0 || zo[i][1]!=0){
            long long hoge = zo[i][1]*(n-zo[i][1]);
            hoge%=MOD;
            hoge*=power(i,2,MOD);
            hoge%=MOD;
            ans+=hoge;
            ans%=MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
using System;
public class Program {
  public static void Main() {
    int[] costs = new int[4];
    for (int i = 0; i < 4; i++) costs[i] = int.Parse(Console.ReadLine());
    Console.WriteLine(Math.Min(costs[0],costs[1]) + Math.Min(costs[2], costs[3]));
  }
}


Measured memory_bytes: 11092
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] list = new int[n];
        Arrays.fill(list, - 1);
        for (int i = 0; i < m; i++) {
            int orderIndex = sc.nextInt();
            int v = sc.nextInt();
            if (list[orderIndex - 1] >= 0 && list[orderIndex - 1] != v) {
                System.out.println(-1);
                return;
            }
            list[orderIndex -1] = v;
        }

        if (n > 1 && list[0] == 0) {
            System.out.println(-1);
            return;
        }

        if (list[0] == -1) {
            if (n == 1) {
                list[0] = 0;
            } else {
                list[0] = 1;
            }
        }

        StringBuilder builder = new StringBuilder();
        for (Integer v: list
             ) {
            if (v == - 1) {
                v = 0;
            }
            builder.append(v);
        }
        int ans = Integer.parseInt(builder.toString());
        System.out.println(ans);
    }
}

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

int main(int argc, char const* argv[])
{
	int Y[10001];
	int N, A, B, C, X;
	while(cin >> N >> A >> B >> C >> X, N || A || B || C || X) {
		for (int i = 0; i < N; i++) {
			int buf; cin >> buf;
			Y[i] = buf;
		}
		int x = X;
		int frame = -1;
		int stopped = 0;
		do{
			++frame;
			if (x == Y[stopped]) {
				++stopped;
			}
			x = (A * x + B) % C;
			if (frame > 10000) {
				frame = -1;
				break;
			}
		}while(stopped < N);
		cout << frame << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int n;

void solve(string s, int kinds){
    if(s.size() == n){
        cout << s << endl;
    }
    else{
        for(int i=0; i<=kinds; i++){
            solve(s + (char)('a' + i), max(i + 1, kinds));
        }
    }
}

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

    cin>>n;

    solve("", 0);

    return 0;
}

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

int checkDigit(int n){
	int sum=0;
	while(n>0){
    	sum += n%10;
      	n/=10;
    }
  return sum;
}

int main(){
	int A;
  	cin >> A;
  	int ans;
  	ans = checkDigit(A);
  	if(A%ans==0){
    	cout << "Yes" << endl;
    }else{
     	cout << "No" << endl;   	
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

bool field[100][100];
int n, m;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

int dfs(int y, int x){
	int res = 1;
	field[y][x] = false;
	rep(i, 4){
		int y2 = y + dy[i];
		int x2 = x + dx[i];
		if(field[y2][x2]) res = max(res, 1 + dfs(y2, x2));
	}
	field[y][x] = true;
	return res;
}

int main(){
	while(cin >> m >> n && (m || n)){
		memset(field, false, sizeof(field));
		rep(i, n)rep(j, m) cin >> field[i+1][j+1];
		int res = 0;
		rep(i, n)rep(j, m)if(field[i+1][j+1])res = max(res, dfs(i+1, j+1));
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N;
ll X, x[200000], res, s[200001];

int main() {
	cin >> N >> X;
	for (int i = 0; i < N; ++i) {
		cin >> x[i];
	}
	for (int i = 0; i < N; ++i) {
		s[i + 1] = s[i] + x[i];
	}
	res = llmax;
	for (int i = 1; i <= N; ++i) {
		ll t = X*(i + N) + (s[N] - s[N - i]) * 2;
		ll c = 3;
		for (int j = N; j > 0; j -= i) {
			t += c*(s[j] - s[max(0, j - i)]);
			if (t >= 1e17) {
				break;
			}
			c += 2;
		}
		res = min(res, t);
	}
	cout << res << endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<cstdlib>
#include<typeinfo>
#include<sstream>
#include<list>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fori(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int stringInt(string a)
{
	return atoi(a.c_str());
}
string intString(int a)
{
	stringstream ss;
	ss<<a;
	return ss.str();
}
vector<int> SieveOfEratosthenes(int x)
{
	vector<int> a;
	vector<int> b(x+1,0);
	for(int i=2;i<=x;i++)
	{
		if(b[i]==0)
		{
			a.push_back(i);
			for(int l=i;l<=x;l+=i)
			{
				b[l]=1;
			}
		}
	}
	return a;
}

vector<int> merge(vector<int> a,int left,int mid,int right)
{
	int n1=mid-left;
	int n2=right-mid;
	vector<int> R,L;
	for(int i=0;i<n1;i++)
	{
		L.push_back(a[left+i]);
	}
	for(int i=0;i<n2;i++)
	{
		R.push_back(a[mid+i]);
	}
	L.push_back(999999999);
	R.push_back(999999999);
	int i=0,j=0;
	for(int k=left;k<right;k++)
	{
		if(L[i]<=R[j])
		{
			a[k]=L[i];
			i++;
		}
		else
		{
			a[k]=R[j];
			j++;
		}
	}



	return a;
}
vector<int> mergeSort(vector<int> a,int left,int right)
{
	if(left+1<right)
	{
		int mid = (right+left)/2;
		a=mergeSort(a,left,mid);
		a=mergeSort(a,mid,right);
		a=merge(a,left,mid,right);
	}
	return a;
}

int ans=0;
int a[500003];
int n;
int R[500003],L[500003];
void merge(int left,int mid,int right)
{
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;i++)
	{
		L[i]=a[left+i];
	}
	for(int i=0;i<n2;i++)
	{
		R[i]=a[mid+i];
	}
	R[n2]=L[n1]=999999999;
	int i=0;int j=0;
	for(int k=left;k<right;k++)
	{
		ans++;
		if(L[i]<=R[j])
		{
			a[k]=L[i];
			i++;
		}
		else
		{
			a[k]=R[j];
			j++;
		}

	}

	return ;
}

void mergeSort(int left,int right)
{
	if(left+1<right)
	{
		int mid = (left+right)/2;
		mergeSort(left,mid);
		mergeSort(mid,right);
		merge(left,mid,right);
	}
	return ;
}



int main() {

	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	ans=0;
	mergeSort(0,n);

	for(int i=0;i<n;i++)
	{
		cout<<a[i];
		if(i!=n-1)cout<<" ";
	}

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

Measured memory_bytes: 6056
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
#include <utility>
using namespace std;

using ll = long long;
using p = pair<int, int>;

constexpr int inf = INT_MAX >> 1;

class edge{
public:
  int to, weight;
  edge(int t, int w){
    to = t; weight = w;
  }
};

class graph{
public:
  vector<vector<edge>> g;
  int n;

  graph(int n){
    this-> n = n;
    g.resize(n); 
  }

  void init(int e){
    for(int i=0; i<e; i++){
      int s, t, d;
      cin >> s >> t >> d;
      g[s].push_back({t, d});
    }
  }

  void dijkstra(int s){
    ll dis[n];
    for(int i=0; i<n; i++) dis[i] = inf;
                                                       
    priority_queue<p, vector<p>, greater<p>> pq;
    pq.push({0, s});
    dis[s] = 0;

    while(!pq.empty()){
      auto f = pq.top(); pq.pop();
                                                       
      for(int i=0; i<g[f.second].size(); i++){
        int next = g[f.second][i].to;
        ll nd = dis[f.second] + g[f.second][i].weight;
        
        if(nd > dis[next]) continue;
        else{
          dis[next] = nd;
          pq.push({nd, next});
        }
      }
    }
    
    for(int i=0; i<n; i++){
      if(dis[i] == inf) cout << "INF" << endl;
      else cout << dis[i] << endl;
    }
  }

  void dijkstra(int s, int e){
    ll dis[n];
    for(int i=0; i<n; i++) dis[i] = INT_MAX >> 1;

    priority_queue<p, vector<p>, greater<p>> pq;
    pq.push({0, s});
    dis[s] = 0;
    
    while(!pq.empty()){
      auto f = pq.top(); pq.pop();
      if(f.second == e){
        cout << dis[e] << endl;
        return;
      } 

      for(int i=0; i<g[f.second].size(); i++){
        int next = g[f.second][i].to;
        ll nd = dis[f.second] + g[f.second][i].weight;
        
        if(nd > dis[next]) continue;
        else{
          dis[next] = nd;
          pq.push({nd, next});
        }
      }
    }
  }
};

int main(){
  int v, e, s; 
  cin >> v >> e >> s;

  graph g(v);
  g.init(e);

  g.dijkstra(s); 

  return 0;
}



Measured memory_bytes: 13336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    
    int ans = 0;
    ans = a + b + c;
    
    if(ans>=22) {
        cout << "bust";
    } else {
        cout << "win";
    }
    
    //cout << ans << endl;
    return 0;
}

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

const int NUM_MAX = 50000;

bool isPrime(int num){
    for(int i=3; i*i<=num; i+=2){
        if(num%i==0){
            return false;
        }
    }
    return true;
}

int getPrimeOverMin(int value){
	if((value & 0x00000001) == 0x00000000){
		++value;
	}else{
		value += 2;
	}
	for(int i=value; i>0; i+=2){
		if(isPrime(i)){
			return i;
		}
	}
	return 0;
}

int getPrimeUnderMax(int value){
	if((value & 0x00000001) == 0x00000000){
		--value;
	}else{
		if(value==3)return 2;
		value -= 2;
	}

	for(int i=value; i>2; i-=2){
		if(isPrime(i)){
			return i;
		}
	}
	return 0;
}


//0044
int main(){
	int n;
	
	while(cin >> n){
		cout << getPrimeUnderMax(n) << " " << getPrimeOverMin(n) << endl;
	}
	return 0;	
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, char> P;
typedef long long ll;
//const ll INF = 114514810;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
/*struct edge
{
	int to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
*/
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }

int n, m, p, a, b;
typedef double Weight;
Weight INF = 1000000000;
struct Edge{
	int src, dest; Weight weight;
	bool operator < (const Edge &rhs) const { return weight > rhs.weight; }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;

void dijkstra(Graph &g, Array &d, int s) {
	d.assign(g.size(), INF);
	d[s] = 0;
	typedef pair<Weight, int> P;
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0, s));
	while (!que.empty()) {
		Weight dist = que.top().first;
		int v = que.top().second;
		que.pop();
		if (d[v] < dist) continue;
		REP(i, g[v].size()) {
			Edge e = g[v][i];
			if (d[e.dest] > d[v] + e.weight) {
				d[e.dest] = d[v] + e.weight;
				que.push(P(d[e.dest], e.dest));
			}
		}
	}
}

int main()
{
	while (cin >> n >> m >> p >> a >> b, n)
	{
		a--; b--;
		vi t(n);
		REP(i, n) cin >> t[i];
		Graph g;
		int s = 1 << n;
		g.resize(m*s);
		REP(i, p)
		{
			int x, y, z;
			cin >> x >> y >> z;
			x--; y--;
			REP(i, n)
			{
				REP(j, s)
				{
					if ((j >> i) & 1)
					{
						int k = j ^ (1 << i);
						double cost = (double)z / t[i];
						g[s*x + j].push_back(Edge{ s*x + j, s*y + k, cost });
						g[s*y + j].push_back(Edge{ s*y + j, s*x + k, cost });
					}
				}
			}
		}
		Array d(99999);
		dijkstra(g, d, (a + 1)*s - 1);
		double ans = INF;
		FOR(i, b*s, (b + 1)*s - 1) ans = min(ans, d[i]);
		if (ans >= INF) puts("Impossible");
		else cout<< D10 << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 24548
#include <stdio.h>
#include <string.h>

int main(void){

  char S[100000];
  int count0=0;
  int count1=0;
  
  scanf("%s",S);
  int len = strlen(S);
  
  for(int i=0;i<len;i++){
  	if(S[i]=='0')count0++;
    else count1++;
  }
  
  if(count0<=count1)printf("%d",count0*2);
  else{
    printf("%d",count1*2);
  }
  
  return 0;
}


Measured memory_bytes: 1828
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = input()
if n[-1] == '2' or n[-1] == '4' or n[-1] == '5' or n[-1] == '7' or n[-1] == '9':
    print('hon')
elif n[-1] == '3':
    print('bon')
else:
    print('pon')

Measured memory_bytes: 27132
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
#define fst first
#define snd second
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}
inline int Log2(ll x) {int k; for(k=0; x>0; ++k) x>>=1; return k;} // number of binary digits
template<typename T> inline int count_between(vector<T>& a, T l, T r) {
  return lower_bound(all(a), r) - lower_bound(all(a), l); // [l, r)
}

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};


int main() {
  ll N, K, L; cin >> N >> K >> L;

  UnionFind uf1(N), uf2(N);

  rep(i, K) {
    int u, v; cin >> u >> v;
    --u; --v;
    uf1.unite(u, v);
  }
  rep(i, L) {
    int u, v; cin >> u >> v;
    --u; --v;
    uf2.unite(u, v);
  }

  vector<P> c(N);
  map<P, int> cnt;
  rep(i, N) {
    c[i] = P(uf1.find(i), uf2.find(i));
    ++cnt[c[i]];
  }

  rep(i, N) {
    cout << cnt[c[i]] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 15104
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

  int ans = 0;
  for(int i=0;i<N;i++){
    ll a;
    cin >> a;
    while(1){
      if(a%2==0){
        ans++;
        a/=2;
      }else{
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    long long a, b, x;
    cin >> a >> b >> x;
    
    long long ans = (b / x) - max(a - 1, 0LL) / x;
    if (a == 0) ans++;
    
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>


// function that checks if given a weight limit, the number of allocations does
// not exceed the number of available trucks
bool fits(int limit, int n_weights, int n_trucks, std::vector<int> &weights) {
    for (int i = 0; i < n_weights; ++i, --n_trucks) { // for each allocation
        int cur_truck_weight = 0;
        if (weights[i] > limit) return false; // if single weight cannot fit into limit
        while (i < n_weights && cur_truck_weight + weights[i] <= limit) {
            cur_truck_weight += weights[i];
            ++i;
        }
        --i;
    }
    return (n_trucks >= 0); // return false if allocations exceed number of trucks
}

int main()
{
    int n_weights, n_trucks;
    scanf("%d %d", &n_weights, &n_trucks);
    std::vector <int> weights;
    for (int i = 0; i < n_weights; ++i) {
        int weight;
        scanf("%d", &weight);
        weights.push_back(weight);
    }
    
    // binary search
    int left = 0, right = 1e9;
    while (left < right) {
        int mid = (left + right) / 2;
        if (fits(mid, n_weights, n_trucks, weights)) {
            right = mid; // set upper bound
        } else {
            left = mid + 1; // set lower bound
        }
    }
    printf("%d\n", left);
}

Measured memory_bytes: 3024
N = int(input())
B = list(map(lambda x: int(x) - 1, input().split()))
for i in range(N):
    if B[i] > i:
        print(-1)
        break
else:
    ans = []
    for _ in range(N):
        for i in range(len(B) - 1, -1, -1):
            if B[i] == i:
                ans.append(i)
                B = B[:i] + B[i + 1 :]
                break
    print("\n".join(map(lambda x: str(x + 1), ans[::-1])))


Measured memory_bytes: 3064
/*
	ID: sixathofpain
	TASK: friday
	LANG: C++   

*/


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 998244353;
const int N = int(2e5) + 999;
#define int long long int

int ans[N];

int32_t main(){
    IOS;
	
    // freopen("friday.in","r",stdin);
    // freopen("friday.out","w",stdout);

    int n,k;
    cin>>n>>k;

    vector<pii> v(k);
    
    for(int i=0;i<k;i++)
    	cin>>v[i].ff>>v[i].ss;

    ans[1]=1;
    ans[2]=-1;
    int tmp=0;

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

    	tmp = tmp+ans[i];
    	tmp%=MOD;
    	if(tmp<0)
    		tmp+=MOD;

    	ans[i]=tmp;

    	for(int j=0;j<k;j++){

    		int x = i+v[j].ff;
    		int y = i+v[j].ss+1;
    		if(x<=n){
    			ans[x]+=tmp;ans[x]%=MOD;
    		}
    		if(y<=n){
    			ans[y]-=tmp;ans[y]%=MOD;
    		}

    		if(x<=n){
    			if(ans[x]<0)
    				ans[x]+=MOD;
    		}

    		if(y<=n){
    			if(ans[y]<0)
    				ans[y]+=MOD;
    		}
    		// cerr<<"for i "<<x<<" "<<ans[x]<<" "<<y<<" "<<ans[y]<<endl;

    	}

    }
	cout<<ans[n]<<endl;    

    return 0;
}

Measured memory_bytes: 5212
n = $stdin.gets.chomp.to_i

result = []
n.times do |n|
  x1,y1,x2,y2,x3,y3,x4,y4 = $stdin.gets.chomp.split(' ').map(&:to_f)

  a = (y2-y1)/(x2-x1)
  b = (y4-y3)/(x4-x3)

  if a == b
    result << "YES"
  else
    result << "NO"
  end
end

result.each do |r|
  puts r
end

Measured memory_bytes: 2324