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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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

int gcd(int a, int b){/*{{{*/
  if (b>a) swap(a,b);
  if (b==0) return a;
  return gcd(b, a%b);
}

int lcd(int a, int b){
  return (a/gcd(a,b))*b;  // overflowしにくいように最初に割り算をする。
}/*}}}*/

int solve(){
  int n;cin>>n;
  int a[n];
  int b[n];
  rep(i, n){
    cin>>a[i]>>b[i];
  }

  int pool = 0;
  rrep(i, n){
    int diff = ((a[i]+pool)+b[i]-1)/b[i] * b[i] - (a[i]+pool);
    if (diff>0) {
      pool += diff;;
    }
  }
  cout << pool << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

vector<vector<int>> ans;

void calc(int l, int r, int cnt) {
    if(r-l==1) return;
    int m = (l + r) / 2;
    REP(i, l, m) REP(j, m, r) ans[i][j] = cnt;
    calc(l, m, cnt+1);
    calc(m, r, cnt+1);
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ans.resize(n);
    rep(i, n-1) ans[i].resize(n);
    calc(0, n, 1);
    rep(i, n-1) {
        REP(j, i+1, n) cout << ans[i][j] << (j == n-1 ? '\n' : ' ');
    }
    return 0;
}

Measured memory_bytes: 1536
using System;
using System.Collections.Generic;

namespace abc161
{
    class Program
    {
        static void Main()
        {
            var nm = Console.ReadLine().Split(' ');
            var n = int.Parse(nm[0]);
            var m = int.Parse(nm[1]);
            var aStrList = Console.ReadLine().Split(' ');
            var aList = new List<int>();
            var total = 0;
            foreach (var aStr in aStrList)
            {
                var a = int.Parse(aStr);
                aList.Add(a);
                total += a;
            }
            aList.Sort();
            aList.Reverse();
            var border = (double)total / (4 * m);
            if (border.CompareTo(aList[m - 1]) > 0)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
}


Measured memory_bytes: 11092
package main

import (
	"fmt"
)

func main() {
	var n, m, a int64
	fmt.Scan(&n, &m)
	ret := int64(0)
	for i := int64(0); i < m; i++ {
		fmt.Scan(&a)
		ret += a
	}
	result := int64(0)
	if ret > n {
		result = int64(-1)
	} else {
		result = n - ret
	}
	fmt.Println(result)
}


Measured memory_bytes: 2364
#include <iostream>

using namespace std;

int main()
{
  int N, num = 0, aux = 0; 
  
  string s;
  cin >> s;
  
  for(int i = 0;i<s.length();i++){
      if(s[i] == '0'){
        num++;
      }else{
        aux++;
      }
  }
  if(num < aux){
    cout << num*2 << endl;
  }else{
    cout << aux*2 << endl;
  }
  

  return 0;
}

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define maxn 100
#define int long long int
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

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 mpow(int N, int P, int M)  //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) {           //bit計算
    if (x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) {   //素数判定
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

signed main() {
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> X, dis;
    rep(i, N) {
        int x;
        cin >> x;
        X.push_back(x);
    }
    for (int i = 1; i < N; i++) {
        int d = X[i] - X[i - 1];
        if (d * A > B) {
            d = B;
            dis.push_back(d);
        } else {
            dis.push_back(d * A);
        }
    }
    int ans = 0;
    rep(i, dis.size()) {
        ans += dis[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 2548
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define BIT(n, num) std::bitset<(n)>((num)).to_string()

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

template <typename T, typename U> U read(ll V, T a, U b) {
  REP(i, V) {
    cin >> a;
    b.push_back(a);
  }
  return b;
}

int main() {
  ll N, M, Q;
  ll L, R;
  ll p, q;
  ll a[505][505] = {}, b[505][505] = {};
  cin >> N >> M >> Q;
  vector<ll> out;
  REP(i, M) {
    cin >> L >> R;
    a[L][R] += 1;
  }
  REP(i, N + 1) {
    if (i == 0)
      continue;
    REP(j, N + 1) {
      if (j == 0)
        continue;
      else
        b[i][j] = b[i][j - 1] + a[i][j];
    }
  }
  REP(i, Q) {
    cin >> p >> q;
    ll c = 0;
    FOR(j, p, q + 1) c += b[j][q] - b[j][p - 1];
    out.push_back(c);
  }
  for (auto a : out)
    cout << a << endl;

  return 0;
}


Measured memory_bytes: 5876
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# n行の数をリストへ
t = [int(input()) for i in range(5)] 
answer = 0
a=10
for i in range(5):
    a = min(a,(t[i]-1)%10+1)
#    print(a)
    answer += t[i] +10 -(t[i]%10)
    if t[i] % 10 == 0:
        answer -= 10

answer = answer -10 + a
print(answer)


Measured memory_bytes: 21312
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()
#define fs first
#define sd second
#define couts(x) cout << (x) << (" ")
#define coutn(x) cout << (x) << ("\n")
#define endl "\n"

template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T1, typename T2> std::istream &operator>>(std::istream &is, std::pair<T1,T2> &p){is >> p.first >> p.second; return is; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::deque<T> &vec){ os << "deque["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

template<class T> using V = vector<T>;
template<class T> using V2 = V<V<T>>;
template<class T> using V3 = V<V2<T>>;
using comp = complex<ld>;
const ld PI = acos( (ld)(-1) );

void solve(){
  int n; cin >> n;
  V<comp> vv;
  FOR(i,0,n){
    int x, y;
    cin >> x >> y;
    if(x==0 && y==0) continue;
    vv.push_back(comp(x,y));
  }
  n = (int)vv.size();
  sort(ALL(vv),[&](comp c1, comp c2){
    if( arg(c1)< arg(c2) ) return true;
    return false;
  });
  ld ansr = 0;
  FOR(i,0,n){
    comp c(0,0);
    FOR(j,0,n){
      if(abs(c)<abs(c+vv[(i+j)%n])) c += vv[(i+j)%n];
    }
    if( abs(c)>ansr ) ansr = abs(c);
  }
  std::cout << std::fixed << std::setprecision(20);
  couts(ansr);
}

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

Measured memory_bytes: 256
from collections import deque
def solve():
    H,W = map(int,input().split())
    Ch,Cw = map(lambda x:int(x)-1,input().split())
    Dh,Dw = map(lambda x:int(x)-1,input().split())
    A = [list(input()) for _ in range(H)]
    V = [[-1]*W for _ in range(H)]
    d = ((1,0),(0,1),(-1,0),(0,-1))

    def bfs_2d(sy,sx,v):
        que = deque()
        V[sy][sx] = v
        que.append((sy,sx))

        while que:
            uh, uw = que.popleft()
            for dy, dx in d:
                next_h = uh+dy
                next_w = uw+dx
                if 0 <= next_h < H and 0 <= next_w < W \
                    and A[next_h][next_w] == '.' \
                    and V[next_h][next_w] == -1:
                    V[next_h][next_w] = v
                    que.append((next_h,next_w))
    
    vertex = 0
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#' or V[h][w] != -1:
                continue
            bfs_2d(h,w,vertex)
            vertex += 1

    G = [[] for _ in range(vertex)]
    used = [set() for _ in range(vertex)]
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                continue
            for dh in range(-2, 2+1):
                for dw in range(-2, 2+1):
                    if h + dh < 0 or H <= h + dh or w + dw < 0 or W <= w + dw:
                        continue
                    if A[h+dh][w+dw] == "#":
                        continue
                    if V[h][w] == V[h+dh][w+dw]:
                        continue
                    if V[h+dh][w+dw] in used[V[h][w]]:
                        continue
                    G[V[h][w]].append((V[h+dh][w+dw]))
                    used[V[h][w]].add((V[h+dh][w+dw]))
    
    # s = V[Ch][Cw]
    # g = V[Dh][Dw]

    # dist = [-1 for _ in range(vertex)]
    # que = deque()
    # dist[s] = 0
    # que.append(s)
    # while que:
    #     u = que.popleft()
    #     for v in G[u]:
    #         if dist[v] != -1:
    #             continue
    #         dist[v] = dist[u] + 1
    #         que.append(v)
    
    # print(dist[g])

    start_area_num = int(V[Ch][Cw])
    goal_area_num = int(V[Dh][Dw])

    dist = [-1] * vertex
    dist[start_area_num] = 0
    q = deque()
    q.append(start_area_num)
    while len(q) > 0:
        cur_area_num = q.popleft()
        if cur_area_num == goal_area_num:
            print(dist[cur_area_num])
            return
        
        for next_area_num in G[cur_area_num]:
            if dist[next_area_num] == -1:
                dist[next_area_num] = dist[cur_area_num] + 1
                q.append(next_area_num)
    else:
        print(-1)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 189708
#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <chrono>
using namespace std;
typedef long long ll;

ll i, j, k;
ll a, b;
double sec;

ll n;
ll arr[100005];
unordered_map<ll, ll> x;
unordered_map<ll, bool> mp;

unsigned long long xor64(void);

int main()
{
    
    scanf("%lld %lld", &n, &arr[0]);
    for (i = 1; i < n; i++) {
        scanf("%lld", &arr[i]);

        if (x[arr[i]] == 0) {
            k++;
        }
        x[arr[i]]++;
    }

    if (k > 3) {
        puts("No");
        return 0;
    }

    for (i = 1; i < n && k > 0; i++) {

        if (mp[arr[i]]) continue;

        unordered_map<ll, ll> tmp = x;

        a = arr[0];
        b = arr[i];
        tmp[b]--;

        for (j = 2; j < n; j++) {
            ll f = a ^ b;

            if (tmp[f]) {
                tmp[f]--;
                a = b;
                b = f;
            }
            else {
                mp[arr[i]] = true;
                break;
            }
        }

        if (!(j ^ n)) {
            if (arr[0] == (a ^ b) &&
                arr[i] == (b ^ arr[0])) {
                puts("Yes");
                return 0;
            }
            else {
                mp[arr[i]] = true;
            }
        }
    }

    puts("No");

    return 0;
}   


unsigned long long xor64(void) {
    static unsigned long long x = 88172645463325252ULL;
    
    x = x ^ (x << 13);
    x = x ^ (x >> 7);
    x = x ^ (x << 17);

    return x;
}



Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
int main(){

  int r[2000]={};
  for(int i=1;i<2000;i++)
    for(int j=1;j<=i;j++)
      r[i]+=(i%j==0);

  int n;
  cin>>n;
  for(int i=1;i<2000;i++){
    if(r[i]==n){
      cout<<i<<endl;
      return 0;
    }
  }

}



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

#define ll long long
#define ull unsigned ll

#define vi vector <int>
#define ii pair <int, int>
#define vii vector <ii>
#define vll vector <ll>
#define vull vector <ull>
#define INFL 9e18
#define INF 2e9
#define EPS 1e-9
#define pb push_back
#define emp emplace_back
#define PI acos(-1.0)
#define endl "\n"
#define mp make_pair
#define mod 1000003
#define DEBUG 0




int main ()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, r;
    cin >> n >> r;
    
    cout << (int)(log(n) / log(r) + 1) << endl;

    
}

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

int main()
{
    ll K, X;
    cin >> K >> X;
    if (500 * K >= X)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


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

using namespace std;

int main(){
	int f[10005];
	for(int i=0;i<=10004;i++){
		f[i]=0;
	}
	for(int x=1;x<=105;x++){
		for(int y=1;y<=105;y++){
			for(int z=1;z<=105;z++){
				int tmp=x*x+y*y+z*z+x*y+y*z+x*z;
				if(tmp<=10004)
					f[tmp]++;
			}
		}
	}
		
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cout<<f[i]<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3628
n = int(input())
s = input()
S = list(s)
r = S.count('R')
g = S.count('G')
b = S.count('B')
ans = r * g * b
for k in range(n):
        for j in range(k):
            i = 2*j - k
            if i >= 0 and i < j and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
print(ans)

Measured memory_bytes: 68216
#include <iostream>
using namespace std;
template <class T>
T gcd(T a, T b){
    T m, n, r;
    if(a > b){
        m = a;
        n = b;
    }else{
        m = b;
        n = a;
    }
    
    while(n != 0){
        r = m % n;
        m = n;
        n = r;
    }
    
    return m;
}

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

    long long int res = 0;

    for(int i = 1; i <= k; i++){
        for(int j = 1; j <= k; j++){
            int gcd_ab = gcd(i, j);
            for(int l = 1; l <= k; l++){
                res += gcd(gcd_ab, l);
            }
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define px(str) cout<<(str)<<endl,exit(0);
#define pe(str) return cout<<(str)<<endl,0;
#define IF(a,b,c) ((a)?(b):(c))
using namespace std;

int main(int argc,char** argv){
	int a;
	cin>>a;
	string s[]={"thu","fri","sat","sun","mon","tue","wed"};
	cout<<s[a%7]<<endl;
	return 0;
}



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

int main() {
  int A,B,C,D;
  cin >> A >> B;
  cin >> C >> D;
  int K;
  int H;
  K = A*B;
  H = C*D;
  if (K >= H) {
    cout<<K<<endl;
  }
  else {
    cout<<H<<endl;
  }
}


Measured memory_bytes: 256
import sys
import copy
input = sys.stdin.readline


N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))

ans=-1*(10**10)

if K<10000000:
    for i in range(N):
        tmp=0
        pos=i
        count=0
        while count<K:    
            #print(pos,P[pos])
            tmp+=C[P[pos]-1]
            if tmp>ans:
                ans=tmp
            
            pos=P[pos]-1
            count+=1
     
    print(ans)
else:
    
    for i in range(N):
        tmp=0
        pos=i
        gpos=i
        count=0
        while count<K:    
            #print(pos,P[pos])
            tmp+=C[P[pos]-1]
            if tmp>ans:
                ans=tmp
            
            
            pos=P[pos]-1
            count+=1
            if pos==gpos:
                divide=K//count-1
                tmp=tmp*divide
                count=count*divide
                gpos=10**10
            
    
    print(ans)

Measured memory_bytes: 69208
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int N, K;
    string S;
    cin >> N >> S >> K;
    for (int i = 0; i < N; i++){
        if (S.at(K - 1) == S.at(i)){
            cout << S.at(i);
        }
        else {
            cout << "*";
        }
    }
    cout << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

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

    cout << min(B / A, C) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
#define ALL(a)  (a).begin(),(a).end()
const int MOD = 1000000007;
ll n, m, c, k,sum = (1LL << 60);
int main() {
    cin >> n; vector<ll> a(n,0);
    rep(i, n) {
        cin >> m;
        if (i == 0) a[i] = m;
        else a[i] = a[i - 1] + m;
    }
    rep(i, n - 1) {
        c = a[i]; k = a[n - 1] - c;
        sum = min(abs(k - c), sum);
    }
    cout << sum << endl;
}

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

int main(void)
{
    int n,m;
    cin >>n>>m;
    n++;

    vector<int>ac(n,0);
    vector<int>wa(n,0);
    for (int i = 0;i<m;i++)
    {
        int pi =0;
        cin >>pi;
        string si;
        cin >>si;
        if(si.compare("AC")==0)
        {
            ac[pi] = 1;
        }
        else
        {
            if(ac[pi]!=1)
              wa[pi]  = wa[pi]+1;
        }
        
    }
    int sum_ac = 0;
    int sum_pnl = 0;
    for(int i=0;i<n;i++)
    {
        if(ac[i]==1)
        {
            sum_ac +=1;
            sum_pnl += wa[i];
        }
    }
    cout<<sum_ac <<" "<<sum_pnl;

    

}

Measured memory_bytes: 1024
N,K = map(int,input().split())
A = list(map(int,input().split()))

town = [0 for i in range(N+1)]

def next(A,now):
    return(A[now-1])

now = 1
i = 0
while True:
    if town[now] != 0:
        roop_start = town[now]
        roop_end = i
        break
    town[now] = i+1
    now = next(A,now)
    i += 1

roop = roop_end - roop_start + 1
teleport = min(roop_start + (K - roop_start)%roop,K)

now = 1
for i in range(teleport):
    now = next(A,now)

print(now)


Measured memory_bytes: 32368
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SIZE(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (upper_bound(ALL(c),x)-lower_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *min_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int k; cin >> k;
   V<int> a(k);
   REP(i, k) cin >> a[i];

   if (a[k-1] != 2) {
      cout << -1 << endl;
      return 0;
   }

   int MAX = 3, MIN = 2;
   for (int i = k-2; i >= 0; i--) {
      MAX = (MAX - MAX % a[i]) + (a[i] - 1);
      MIN = (MIN + (((-MIN % a[i]) + a[i]) % a[i]));
      if (MAX < MIN) {
         cout << -1 << endl;
         return 0;
      }
   }
   cout << MIN << " " << MAX << endl;

   return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  int n;string s,t;cin>>n>>s>>t;
  for(int i=0;i<n;i++){
    cout<<s[i]<<t[i];
  }
  cout<<endl;

  
  return 0;
}


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

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

using namespace std;

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

  vector<string> vs(n);

  REP(i, n) {
    cin >> vs[i];
  }

  sort(ALL(vs));

  REP(i, n) {
    cout <<  vs[i];
  }

  cout << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	s=RD()
	ans=0
	if s=="RRR":
		ans=3
	elif s=="SSS":
		ans=0
	elif s=="RRS" or s=="SRR":
		ans=2
	else:
		ans=1
	print(ans)




if __name__ == "__main__":
	main()


Measured memory_bytes: 9128
#include<iostream>
using namespace std; 
int main(){
	int a,b=0;
	cin>>a;
	if(a%3==0 && a>0){
		b=(a/3)+b;
		
	}
	else if(a%3==1 && a>1){
		a-=4;
		b++;
		b=(a/3)+b;
	}
	else if(a%3==2 && a>2){
		a-=5;
		b++;
		b=(a/3)+b;
	}
	else{
		system("pause");
	}
	cout<<b;
}

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

const double pi = 3.1415;

double R;

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

  cin >> R;

  cout << setprecision(6) << fixed << (R * 2.0) * pi << endl;

  return 0;
}

Measured memory_bytes: 3828
a = int(input())
b = int(input())
c = int(input())
x = int(input())
answer = 0

for i in range(a+1):
	for j in range(b+1):
		for k in range(c+1):
			if i*500 + j*100 + k*50 == x:
				answer += 1
			
print(answer)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  map<int,int>m;
  for(int i=0;i<N;i++){
    int t;
    cin>>t;
    m[t]++;
    m[t+1]++;
    m[t-1]++;
  }

  int ans=-1;
  for(auto i=m.begin();i!=m.end();i++)ans=max(ans,i->second);
  cout<<ans<<endl;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
 
int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) cin >> b[i];
  for(int i = 0; i < n; ++i) cin >> c[i];
  
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  
  ll res = 0;
  for(int i = 0; i < n; ++i){
    res += (lower_bound(ALL(a),b[i]) - a.begin())
           * (c.end() - upper_bound(ALL(c),b[i]));
  }
  cout << res;
}

Measured memory_bytes: 4564
def editarr(x,y,arr):
  if abs(x)>=abs(y):
    for i in range(len(arr)):
      arr[i][0],arr[i][1]=arr[i][1],arr[i][0]
  if x<0:
    for i in range(len(arr)):
      arr[i][0]*=-1
  if y<0:
    for i in range(len(arr)):
      arr[i][1]*=-1

k=int(input())
x,y=map(int,input().split())
ans=[]
tx=abs(x)
ty=abs(y)
if tx>=ty:
  tx,ty=ty,tx
if k%2==0 and (tx+ty)%2!=0:
  print(-1)
else:
  if tx+ty<k:
    if (tx+ty)%2==0:
      m=(ty-tx)//2
      ans.append([k-m,m])
    else:
      td=k-(tx+ty)
      ans.append([tx,ty+td])
      ans.append([tx+(k-td//2),ty+td//2])
    ans.append([tx,ty])
    n=len(ans)
  elif ty-(k-tx%k)<k and (ty-(k-tx%k))%2!=0:
    if tx<k and ty<k:
      if (2*k-(tx+ty))%2==0:
        td=2*k-(tx+ty)
        ans.append([tx+td//2,k-(tx+td//2)])
        ans.append([tx,ty])
      else:
        ans.append([tx,k-tx])
        td=ty-(k-tx)
        ans.append([tx+(k-td//2),ans[-1][1]+td//2])
        ans.append([tx,ty])
      n=len(ans)
    else:
      if tx+ty<2*k:
        if (2*k-(tx+ty))%2==0:
          td=2*k-(tx+ty)
          ans.append([tx+td//2,k-(tx+td//2)])
          ans.append([tx,ty])
        else:
          ans.append([tx,k-tx])
          td=ty-(k-tx)
          ans.append([tx+(k-td//2),ans[-1][1]+td//2])
          ans.append([tx,ty])
        n=len(ans)
      else:
        ans.append([0,0])  
  else:
    ans.append([0,0])
    for i in range(tx//k):
      ans.append([ans[-1][0]+k,0])
    if ans[-1][0]!=tx:
      ans.append([tx,k-abs(tx-ans[-1][0])])
    td=ty-ans[-1][1]
    if td%k==0:
      flag=True
    else:
      flag=False
    for i in range(td//k):
      if flag==False and (ty-ans[-1][1])%2==0 and (ty-ans[-1][1])<=2*k:
          break
      ans.append([tx,ans[-1][1]+k])
    if ans[-1][1]!=ty:
      td=ty-ans[-1][1]
      ans.append([tx+(k-td//2),ans[-1][1]+td//2])
      ans.append([tx,ty])
    ans.pop(0)
    n=len(ans)
  editarr(x,y,ans)
  print(n)
  for a,b in ans:
    print(a,b)

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

inline void Disp(int a, int b)
{
	for (int i = 0; i < a; i++)
	{
		for (int j = 0; j < b; j++)
		{
			if ((i + j) % 2 == 0) cout << "#";
			else cout << ".";
		}
		cout << endl;
	}
	cout << endl;
}

int main(void)
{
	int a, b;

	while (true)
	{
		cin >> a >> b;
		if (a == 0 && b == 0) break;
		Disp(a, b);
	}
	return 0;
}


Measured memory_bytes: 3116
/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Department  : Computer Science and Engineering (Batch - CSE'19)
      Email       : souravkumarroy813965@gmail.com
**/


#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()

void solve()
{
    vector <int> v;
    int n,i,x,sum=0,cn=0;
    cin >> n;
    for(i=0; i<2*n; i++)
    {
        cin >> x;
        v.push_back(x);
    }
    sort(all(v));

    for(i=0; i<2*n; i+=2)
    {
        sum += v[i];

    }
    cout << sum << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    solve();

}
/**
Test Case :

**/

Measured memory_bytes: 3560
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	
	public static void main(String[] args) {
		long Q = sc.nextLong();
		long H = Math.min(Q * 2, sc.nextLong());
		long S = Math.min(H * 2, sc.nextLong());
		long D = Math.min(S * 2, sc.nextLong());
		
		long N = sc.nextLong();
		
		System.out.println(D * (N / 2) + S * (N % 2));
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>x(n);
	for (int i = 0; i < n; i++)cin >> x.at(i);
	ll ans = 1e18;
	for (int i = 0; i <= n - k; i++) {
		int l = x.at(0+i);
		int r = x.at(k - 1+i);
		ll res = 0;
		if (r <= 0)res = abs(l);
		else if (l >= 0)res = r;
		else res = min(r - l + abs(l), r - l + r);
		ans = min(ans, res);
		//cout << l << " " << r << " " << res << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;
int dfs(int A_len,int B_len, int C_len,int ind);
int N,A,B,C;
vector<int>l;
void chmin(int& a,int b){
    if(a>b){
        a=b;
    }
}
int main(){
    cin>>N>>A>>B>>C;
    for(int i=0;i<N;i++){
        int tmp;
        cin>>tmp;
        l.push_back(tmp);
    }
    cout<<dfs(0,0,0,0)<<endl;

}

int dfs(int A_len,int B_len, int C_len,int ind){
    if(ind==N){
        if(A_len==0||B_len==0||C_len==0)return 99999999;
        return abs(A_len-A)+abs(B_len-B)+abs(C_len-C);
    } 
    
    int res = dfs(A_len,B_len,C_len,ind+1); 
    chmin(res,dfs(A_len+l[ind],B_len,C_len,ind+1)+(A_len?10:0));
    chmin(res,dfs(A_len,B_len+l[ind],C_len,ind+1)+(B_len?10:0));
    chmin(res,dfs(A_len,B_len,C_len+l[ind],ind+1)+(C_len?10:0));
    return res;
}


Measured memory_bytes: 256
#include<stdio.h>
  #include<string.h>
  #include<stdlib.h>
  int top,N[1000];
  void push(int p){
    N[++top]=p;
  }
  int pop(){
    top--;
    return N[top+1];
  }
  int main(){
    int x,y;
    top=0;
    char n[100];

    while(1){
      if(scanf("%s",n)==EOF) break;
      if(n[0]=='+'){
        x=pop();
        y=pop();
        push(x+y);
      }else if(n[0]=='-'){
        x=pop();
        y=pop();
        push(y-x);
      }else if(n[0]=='*'){
        x=pop();
        y=pop();
        push(x*y);
      }else {
        push(atoi(n));
      }
    }
    printf("%d\n",pop());
    return 0;
  }



Measured memory_bytes: 2076
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

        int cnt = 0;
        for (long i = inpt[0]; i <= inpt[1]; i*=2) {
            cnt++;
        }
        Console.WriteLine(cnt);
    
    }


    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"




3 20



";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 13396
from itertools import chain, groupby


def flatten(list_of_lists):
    return chain.from_iterable(list_of_lists)


def all_equal(iterable):
    g = groupby(iterable)
    return next(g, True) and not next(g, False)


C = [list(map(int, input().split())) for _ in range(3)]
s = sum(flatten(C))

x = all_equal([C[1][i] - C[0][i] for i in range(3)])
y = all_equal([C[2][i] - C[0][i] for i in range(3)])
z = all_equal([C[2][i] - C[1][i] for i in range(3)])

if all((x, y, z)) and s % 3 == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
import sys
inputs = sys.stdin.readlines()

N, K = map(int, inputs[0].split())
X = list(map(int, inputs[1].split()))

ans = 10 ** 9
for i in range(N-K+1):
    xl, xr = X[i], X[i+K-1]
    if xl < 0 and xr <= 0:
        ans = min(ans, -xl)
    elif xl < 0 and 0 < xr:
        ans = min(ans, -2*xl + xr, -xl + 2*xr)
    else:
        ans = min(ans, xr)
        break
print(ans)

Measured memory_bytes: 15140
N = int(input())
alist = list(map(int, input().split()))
alist.sort(reverse=True)
sumscore=alist[0]
for n in range(1,int(N/2)):
  sumscore = sumscore + alist[n]*2
if N%2==1:
  sumscore += alist[n+1]

print(sumscore)

Measured memory_bytes: 31524
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
void solve(){
    int n;
    cin >> n;
    ll sum = 0;
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x;
        sum += x;
    }
    cout << sum-n*1ll;
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    while(t--) solve();
}

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

int x[100001];

int main(){
    int n,k; cin >> n >> k;
    for(int i=0;i<n;i++) cin >> x[i];

    int ans=1e9;
    int zero=n;
    bool zeroaru=false;
    for(int i=0;i<n;i++){
        if(x[i]>0){
            zero=i; break;
        }else if(x[i]==0){
            zero=i; zeroaru=true; break;
        }
    }
    if(zero+int(zeroaru)>=k){
        ans=min(ans,abs(x[zero+int(zeroaru)-k]));
    }
    if(n-zero>=k){
        ans=min(ans,abs(x[zero+k-1]));
    }
    for(int i=0;i<=n-k;i++){
        ans=min(abs(x[i])+abs(x[i+k-1])*2,ans);
        ans=min(abs(x[i])*2+abs(x[i+k-1]),ans);
    }
    cout << ans << endl;
}

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

int main() {
  int h, w;

  cin >> h >> w;

  vector<string> c(h);

  for (int i = 0; i < h; i++) {
    cin >> c[i];
    cout << c[i] << endl << c[i] << endl;
  }

  return 0;
}

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

int main(){
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N);
  vector<int> y(M);
  for(int i = 0;i < N;i++){
    cin >> x.at(i);
  }for(int i = 0;i < M;i++){
     cin >> y.at(i);
  }

  x.push_back(X);
  y.push_back(Y);
  
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());


  if(x.at(N) < y.at(0)){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
}

Measured memory_bytes: 256
#include<vector>
#include<queue>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
#include<string>
#include<map>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<29
#define MAX 30
using namespace std;
int n,m,p,a,b;

int main(){
  int tes,x,y;
  double tk;
  int d[31][31];
  double dp[1<<9][31]; // [ticketの残り枚数][今いる街]
  vector<double> ticket;
  while(true){
    
    scanf("%d %d %d %d %d",&n,&m,&p,&a,&b);
    if(n+m+p+a+b == 0)break;
    ticket.clear();   
    rep(i,31)rep(j,31)d[j][i] = INF;

    rep(i,n){
      cin >> tk;
      ticket.push_back(tk);
    }
    rep(i,p){
      cin >> x >> y >> tes;
      d[x][y] = d[y][x] = tes;
    }
  
    for(int i=0;i<(1<<9);i++){
      for(int j=0;j<31;j++)dp[i][j] = INF;
    }
    dp[(1<<n)-1][a] = 0;

    double ans = INF;
    for(int S = (1<<n)-1; S>=0 ;S--){
      ans = min(ans,dp[S][b]);
      for(int v = 1; v<=m ;v++){
	for(int t = 0; t<n ;t++){
	  if(!(S>>t &1))continue;//tを既に使っていたなら戻る
	  for(int u = 1; u<=m;u++){
	    if(d[v][u] == INF)continue; //（ vからuまでの道は？ ） ないんだな、それが	    
	    dp[S & ~(1<<t)][u] = min(dp[S & ~(1<<t)][u],dp[S][v] + (double)(d[v][u]/ticket[t]) );	    
       
	  }
	}
      }
    }
    if(ans == INF)printf("Impossible\n");
    else printf("%.3f\n",ans);
 
  }
  return 0;
}

Measured memory_bytes: 1436
import sys
from collections import Counter

input = sys.stdin.readline

N = int(input())
ans = 1
mod = 998244353
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
D = sorted(Counter(D).items())
tmp = D[0][1]
stream = 0
for n, i in D:
    if stream != n:
        print(0)
        exit()
    if n == 0 and i == 1:
        stream += 1
        continue
    elif n==0:
        print(0)
        exit()
    ans *= pow(tmp, i)
    ans %= mod
    tmp = i
    stream += 1
print(ans)


Measured memory_bytes: 25732
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
/* 配列の初期化 fill(array, 0); すべて0に初期化 */
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );}
using namespace std;
int main()
{
    int k,s;
    cin >> k>> s;
    int cnt = 0;
    for(int x = 0;x <= k;x++){
        for(int y = 0;y <= k;y++){
            int z = s - x - y;
            if(0 <= z && z <= k){
                cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;

ll popcount(ll num){
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

vector<pair<ll,ll>> factor_arr;

void myfactor(ll num){ 
    ll count = 0;   
    while (!(num % 2)) { 
        num >>= 1; count++; 
    }  
    if (count) factor_arr.push_back({2,count}); 
    for (auto i = 3; i <= sqrt(num); i += 2) { 
        count = 0; 
        while (num % i == 0) { 
            count++; 
            num /= i; 
        } 
        if (count) factor_arr.push_back({i,count}); 
    } 
    if (num > 2) factor_arr.push_back({num,1});
}

void virus(){
       ll a,b;
       cin>>a>>b;
       string one = "", two = "";
       for(auto i=0; i<b; i++) one += (a + '0');
       for(auto i=0; i<a; i++) two += (b + '0');
       cout<<min(one,two); 

}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t=1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
         //cout << "Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = pow(10, 5)+1;//+1しないとREになる(out of rangeになるんかな?? )


int main(){
  int a, b;
  cin >> a >> b;
  
  if(a < b) {
    for(int i=0; i<b; i++){
      cout << a;
    }
    cout << endl;
  }
  else {
    for(int i=0; i<a; i++){
      cout << b;
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
n, yen = map(int, input().split())
man = -1
gosen = -1
sen = -1

for i in range(n + 1):
    for j in range(n - i + 1):
        if 10000 * i + 5000 * j + 1000 * (n - i - j) == yen and (n - i - j) >= 0:
            man = i
            gosen = j
            sen = n - i - j

print(man, gosen, sen)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

int N,M;
vector<int> v;
vector<int> d;

int main(){
  cin>>N>>M;
  for(int i=0; i<M; i++){
    int X; cin>>X;
    v.push_back(X);
  }
  sort(v.begin(), v.end());
  for(int i=1;i<M;i++){
    d.push_back(v[i]-v[i-1]);
  }
  sort(d.begin(), d.end());
  int ans=0;
  for(int i=0;i<M-N;i++){
    ans+=d[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	long long int ar[n];
	for (int i=0;i<n;i++){
		scanf("%lld",&ar[i]);
	}
	long long int l=(1<<31);
	long long int r=(-1)^(1<<31);
	while (l+100<=r){
		long long int mid1=(l*2+r)/3;
		long long int mid2=(l+r*2)/3;
		long long int res1=0;
		long long int res2=0;
		for (int i=0;i<n;i++){
			res1+=abs(ar[i]-(mid1+i+1));
			res2+=abs(ar[i]-(mid2+i+1));
		}
		if (res1<res2){
			r=mid2;
		}
		else{
			l=mid1;
		}
	}
	long long int ans=(-1)^(1ll<<63);
	for (int i=l;i<l+100;i++){
		long long int tmp=0;
		for (int j=0;j<n;j++){
			tmp+=abs(ar[j]-(i+j+1));
		}
		ans=min(ans,tmp);
	}
	printf ("%lld\n",ans);
}

Measured memory_bytes: 1792