akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <string>
using namespace std;


int main(int, char**) 
{
    string val;
    string ans;
    cin >> val;
    long long t;
    int len = val.length();
    
    for(int bit = 0; bit < (1<<(len - 1)); bit++)
    {
        t = val[0] - '0';
        ans = (val[0]);
        for(int i = 0; i< len - 1; i++)
        {
            if(bit & (1<<i))
            {                
                t += val[i+1] - '0';
                ans += '+';                
            }
            else
            {
                t -= val[i+1] - '0';
                ans += '-';
            }
            ans += val[i+1];          
        }
        if(t==7)break;        
    }
    cout << ans << "=7";
    cin >> val;
    return 0;
}

Measured memory_bytes: 256
// --------------
// Tejas Pandey  |
// 13 - 08 - 20  |
// Atcoder BC 175|
// --------------

#include <bits/stdc++.h>
using namespace std;
     
#define mod 1000000007
#define vi vector<int>
typedef long long int ll;
   
int main (void){
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n,k;
  cin >> n >> k;
  ll a[n],c[n];
  for(int i = 0;i < n;i++) cin >> a[i]; 
  for(int i = 0;i < n;i++) cin >> c[i];
  ll ans = -mod;
  for(int j = 1;j <= n;j++){
	vector<ll> tot;
	bool vis[n + 1];
	memset(vis,0,sizeof(vis));
	tot.push_back(c[j - 1]);
	vis[j] = 1;
	int cur = a[j - 1];
	while(!vis[cur]) vis[cur] = 1,tot.push_back(c[cur - 1]),cur = a[cur - 1];
	ll cs = tot.size();
	ll mx = tot[0];
	for(int i = 1;i < min(k,cs);i++) tot[i] += tot[i - 1],mx = max(mx,tot[i]);
	ans = max(ans,mx);
	if(cs > k) continue;
	ll tt = k/cs;
	ll ex = k%cs;
	ans = max(ans,(tt - 1)*tot[cs - 1] + mx);
	ans = max(ans,tt*tot[cs - 1]);
	for(int i = 0;i < ex;i++) ans = max(ans,tt*tot[cs - 1] + tot[i]);
  }
  cout << ans << "\n";
  return 0;
}


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

using namespace std;

int main(){

int n,m,x;

cin>>n>>m>>x;

vector<int> a(m);

for(int i=0;i<m;i++){
  cin>>a.at(i);
}

int sum1=0,sum2=0;
for(int i=0;i<m;i++){
  if(a.at(i)<x){
    sum1 ++;
  }else{
    sum2 ++;
  }
}

if(sum1>=sum2){
  cout<<sum2;
}else{
  cout<<sum1;
}


}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    int n, k;
    std::cin >> n >> k;

    std::vector<long long> x(n);
    for (int i = 0; i < n; i++) {
        std::cin >> x[i];
    }

    long long ans = std::numeric_limits<long long>::max();

    for (int i = 0; i < n - k + 1; i++) {
        ans = std::min(ans, std::abs(x[i]) + abs(x[i] - x[i + k - 1]));
    }

    for (int i = n - 1; i >= k - 1; i--) {
        ans = std::min(ans, std::abs(x[i]) + abs(x[i] - x[i - k + 1]));
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(void){
    int n = 0;
    int cnt = 1;
    cin >> n;
    for(int i = 1; i < n; i++){
        if(i % 2 == 0){
            cnt++;
        }
    }
    cout << float(cnt)/float(n) << endl;
}

Measured memory_bytes: 256
def floyd_warshall(dp, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
    return dp

H, W = [int(x) for x in input().split()]
c = [[int(x) for x in input().split()] for _ in range(10)]
A = [[int(x) for x in input().split()] for _ in range(H)]

c = floyd_warshall(c, 10)

ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] == -1: continue
        ans += c[A[i][j]][1]

print(ans)

Measured memory_bytes: 9484
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	string s;
	cin>>s;
	ll ans=0,ans2=0;//01 10
	for(ll i=0;i<s.length();i++)
	{
		if(s[i]=='0'&&i%2==0)
		ans2++;
		if(s[i]=='1'&&i%2==0)
		ans++;
		if(s[i]=='0'&&i%2==1)
		ans++;
		if(s[i]=='1'&&i%2==1)
		ans2++;
	}
	cout<<min(ans,ans2);
}

Measured memory_bytes: 512
object Main extends App {

    def allEven(list: List[Int]): Boolean = list.forall(_ % 2 == 0)

    def update(list: List[Int], count: Int = 0): Int =
        if (allEven(list)) update(list.map(_ / 2), count + 1) else count

    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val in2 = List.fill(n)(sc.nextInt)
    print(update(in2))
}


Measured memory_bytes: 25668
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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 n, a[20], x[20][20], y[20][20];

int count(int x) {
    if (x == 0) return 0;
    return count(x>>1) + (x & 1);
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        for (int j = 1; j <= a[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }

    int ans = 0;
    for (int bit = 1; bit < 1<<n; bit++) {
        bool ok = true;
        for (int i = 1; i <= n; i++) {
            if (!(bit & (1<<(i-1)))) continue;
            for (int j = 1; j <= a[i]; j++) {
                if (((bit >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
            }
        }
        if (ok) ans = max(ans, __builtin_popcount(bit));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//#include "grader.h"
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
//#define   Y            imag()
//#define   X            real()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
//#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
//#define    dp(a,b)          (((conj(a))*(b)).real())
//#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
//#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     PT                    complex<double>
#define outfile freopen("out.out", "w", stdout);
#define infile  freopen("in.in", "r", stdin);
#define PI acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void FS(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
const int N=100009;
string st;
int main()
{
    int k;
    cin>>st;
    k=sz(st);
    int cnt=0;
    for(int i=0;i<sz(st);i++)
    {
        if(st[i]=='o')
            cnt++;
    }
    cnt+= (15-k);
    if(cnt>=8)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}


























Measured memory_bytes: 256
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
p = list(map(int,input().split()))
flag = True
i = 0
while flag:
    if x - i not in p:
        print(x-i)
        flag = False
        break
    elif x + i not in p:
        print(x+i)
        flag = False
        break
    i += 1

Measured memory_bytes: 9192
H, W, N = map(int, input().split())
s_y, s_x = map(int, input().split())
S = str(input())
T = str(input())

# 高橋: 落とそうとする
# 青木: 残そうとする

lr = []
ud = []

for tup in zip(S, T):
    for n, i in enumerate(tup):
        if i == "L" or i == "R":
            lr.append((n, i))
        else:
            ud.append((n, i))

def f():
    crd = s_x
    # 貪欲に左へ
    # i == 0 -> 高橋
    # i == 1 -> 青木
    for i, j in lr:
        if i == 0 and j == "L":
            crd -= 1
        if i == 1 and j == "R" and crd < W:
            crd += 1
        if crd == 0:
            return 0
    # 貪欲に右へ
    crd = s_x
    for i, j in lr:
        if i == 0 and j == "R":
            crd += 1
        if i == 1 and j == "L" and crd > 1:
            crd -= 1
        if crd == W + 1:
            return 0
    # 貪欲に上へ
    crd = s_y
    for i, j in ud:
        if i == 0 and j == "U":
            crd -= 1
        if i == 1 and j == "D" and crd < H:
            crd += 1
        if crd == 0:
            return 0
    # 貪欲に下へ
    crd = s_y
    for i, j in ud:
        if i == 0 and j == "D":
            crd += 1
        if i == 1 and j == "U" and crd > 1:
            crd -= 1
        if crd == H + 1:
            return 0
    return 1

if f():
    print("YES")
else:
    print("NO")

Measured memory_bytes: 97200
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N;
int a[100001];
bool b[100001];

int main(){
    cin>>N;
    repn(i,N) cin>>a[i];

    int ans=0;
    int i=1;
    while(true){
        if(i==2){
            cout<<ans<<endl;
            return 0;
        }
        if(b[i]){
            cout<<-1<<endl;
            return 0;
        }
        b[i]=true;
        ans++;
        i=a[i];
    }
}

Measured memory_bytes: 768
N = int(input())
dic = {}
for i in range(1,10):
    for j in range(1,10):
        x = str(i) + str(j)
        dic[x] = 0
#print(dic)
for i in range(1,N+1):
    a = i % 10
    for j in range(7):
        b  = i // 10 ** (6 - j)
        if b != 0 :
            break
    z = str(b) + str(a)
    if a != 0 and b != 0:
        dic[z] += 1
ans = 0
for i in range(1,10):
    for j in range(1,10):
        x = str(i) + str(j)
        y = str(j) + str(i)
        ans += dic[x] * dic[y]
print(ans)   

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

int main()
{
	char str[1000];
	scanf("%s", str);
	
	for(int i = 0; i < strlen(str); i++)
	{
		if(str[strlen(str) - 1] == 's')
		{
			printf("%ses\n", str);
			break;
		}
		else 
		{
			printf("%ss\n", str);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,a[N],x,y;
long long ans;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	int x=0,y=0,j=0;
	for (int i=1;i<=n;++i){
		while ((x+a[j+1])==(y|a[j+1])&&j<n){
			j++;
			x+=a[j];
			y|=a[j];
		}
		ans+=j-i+1;
		x-=a[i];
		y^=a[i];
	}
	printf("%lld\n",ans);
}

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

#define each(i, c) for (auto& i : c)

typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9+7;

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

  map<pair<ll, ll>, ll> m;
  for (ll i = 1; i <= n; ++i) {
    auto s = to_string(i);
    ll a = s[0] - '0';
    ll b = s[s.size()-1] - '0';
    if (m.count(make_pair(a, b))) m[make_pair(a, b)]++;
    else m[make_pair(a, b)] = 1;
  }

  ll ans = 0;
  for (ll i = 1; i <= n; ++i) {
    auto s = to_string(i);
    ll a = s[0] - '0';
    ll b = s[s.size()-1] - '0';

    if (m.count(make_pair(b, a))) {
      ans += m[make_pair(b, a)];
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  unsigned N;
  std::cin >> N;
  std::vector<long long> A(N);
  std::vector<char> op(N);
  op[0] = '+';
  std::cin >> A[0];
  for (unsigned i = 1; i < N; ++i) {
    std::cin >> op[i] >> A[i];
  }
  std::vector<std::vector<long long>> dp(N, std::vector<long long>(3));
  dp[0][0] = A[0];
  dp[0][1] = std::numeric_limits<long long>::min() / 2;
  dp[0][2] = std::numeric_limits<long long>::min() / 2;
  for (unsigned i = 1; i < N; ++i) {
    if (op[i] == '+') {
      dp[i][0] = std::max(dp[i - 1][0] + A[i], dp[i - 1][1] + A[i]);
      dp[i][1] = std::max(dp[i - 1][1] - A[i], dp[i - 1][2] - A[i]);
      dp[i][2] = dp[i - 1][2] + A[i];
    } else {
      dp[i][0] = std::max(dp[i - 1][0] - A[i], dp[i - 1][1] - A[i]);
      dp[i][1] = std::max(std::max(dp[i - 1][0] - A[i], dp[i - 1][2] + A[i]), dp[i - 1][1] + A[i]);
      dp[i][2] = std::max(dp[i - 1][1] + A[i], dp[i - 1][2] + A[i]);
    }
  }
  std::cout << std::max(std::max(dp.back()[0], dp.back()[1]), dp.back()[2]);
  return 0;
}

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

constexpr int INF = 1e9;

int main() {
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    int n;
    cin >> n;
    bool fur[201][201] = {};
    for(int i=0; i<n; ++i) {
        int x, y;
        cin >> x >> y;
        fur[x+100][y+100] = true;
    }
    int lx, ly;
    cin >> lx >> ly;

    using state = tuple<int, int, int, int>;
    int d[201][201][6];
    fill(d[0][0], d[201][0], INF);
    d[sx+100][sy+100][0] = 0;
    priority_queue<state, vector<state>, greater<state>> que;
    que.push(make_tuple(0, sx+100, sy+100, 0));
    constexpr int dx[7] = {0, 1, 1, 0, -1, -1, 0};
    constexpr int dy[2][7] = {{1, 0, -1, -1, -1, 0, 0}, {1, 1, 0, -1, 0, 1, 0}};
    while(!que.empty()) {
        int cnt, x, y, tm;
        tie(cnt, x, y, tm) = que.top();
        que.pop();
        if(d[x][y][tm] < cnt) {
            continue;
        }
        for(int i=0; i<7; ++i) {
            int nx = x + dx[i], ny = y + dy[x % 2][i];
            if(nx-100 < -lx || lx < nx-100 || ny-100 < -ly || ly < ny-100 || fur[nx][ny]) {
                continue;
            }
            bool ignore = (abs((x-100) * (y-100) * tm) % 6) != i;
            if(d[nx][ny][(tm+1)%6] > d[x][y][tm] + ignore) {
                d[nx][ny][(tm+1)%6] = d[x][y][tm] + ignore;
                que.push(make_tuple(d[nx][ny][(tm+1)%6], nx, ny, (tm+1)%6));
            }
        }
    }
    int res = INF;
    for(int i=0; i<6; ++i) {
        res = min(res, d[gx+100][gy+100][i]);
    }
    cout << (res == INF ? -1 : res) << endl;
}


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

int main() {
  int H, W, K; cin >> H >> W >> K;
  vector<string> C(H);
  for (int i = 0; i < H; i++) cin >> C.at(i);
  int ans = 0;
  for (int bith = 0; bith < (1 << H); bith++) {
    vector<bool> flagh(H);
    for (int i = 0; i < H; i++) {
      if ((bith >> i) & 1) flagh.at(i) = true;
    }
    for (int bitw = 0; bitw < (1 << W); bitw++) {
      vector<bool> flagw(W);
      for (int j = 0; j < W; j++) {
        if ((bitw >> j) & 1) flagw.at(j) = true;
      }
      int cnt = 0;
      for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
          if (flagh.at(y) || flagw.at(x)) continue;
          if (C.at(y).at(x) == '#') cnt++;
        }
      }
      if (cnt == K) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;
 
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)
 
typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;
 
constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
 
int main() {
    int s; cin>>s;
    if (s==1 || s==2) {
        cout<<4<<endl;
        return 0;
    }
    int cnt = 0;
    while (1) {
        cnt++;
        if (s%2==0) s /= 2;
        else s = 3*s+1;
        if (s==1) break;
    }
    cout<<cnt+2<<endl;
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = unordered_set<int32_t>;
using setstr = unordered_set<string>;
using qint = queue<int32_t>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= 9; ++i)
    {
        if (n % i == 0)
        {
            if (n / i >= 1 && n / i <= 9)
            {
                Yes;
                return;
            }
        }
    }
    No;
    return;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 384
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  
  val a = inputs(0).toInt
  val b = inputs(1).toInt
  val h = inputs(2).toInt

  println(solve(a, b, h))

  def solve(a: Int, b: Int, h: Int): Int = {
    (a + b) * h / 2
  }
}

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

int main(void){
    int N; cin >> N;
    unsigned long long tmp;
    vector<unsigned long long> num;

    for(int i=0; i<N; i++){
        cin >> tmp;
        if(0 == tmp){
            cout << 0 << endl;
            exit(0);
        }
        num.push_back(tmp);
    }

    unsigned long long prod = 1;

    for(int i=0; i<N; i++){
        if(num[i] > 1000000000000000000 / prod){
            cout << -1 << endl;
            exit(0);
        }
        else{
            prod *= num[i];
        }
    }


    cout << prod << endl;

    return 0;
}


Measured memory_bytes: 3960
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int min = Integer.MAX_VALUE;
        int sum = 0;
        for(int i=0;i<N;i++){
            int m = sc.nextInt();
            min = Math.min(min,m);
            sum += m;
        }
        int ans = N+(X-sum)/min;
        System.out.print(ans);
    }
}




Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;

const int MAX_N = 2e5 + 10;
int n, q, ans;
int Arr[MAX_N];
int cnt[MAX_N];
int val[MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> Arr[i];
		cnt[Arr[i]]++;
	}

	for (int i = 1; i <= n; i++)
		for (int j = max(0, i - cnt[i]); j < i; j++)
			val[j]++;

	for (int i = 0; i < n; i++)
		ans += !val[i];

	while (q--) {
		int x, y;
		cin >> x >> y;
		x--;

		if (0 <= Arr[x] - cnt[Arr[x]]) {
			if (val[Arr[x] - cnt[Arr[x]]] == 1)
				ans++;

			val[Arr[x] - cnt[Arr[x]]]--;
		}

		cnt[Arr[x]]--;

		Arr[x] = y;
		cnt[Arr[x]]++;
		if (0 <= Arr[x] - cnt[Arr[x]]) {
			if (val[Arr[x] - cnt[Arr[x]]] == 0)
				ans--;
			
			val[Arr[x] - cnt[Arr[x]]]++;
		}

		cout << ans << "\n";
	}
	return 0;
}
////

Measured memory_bytes: 3960
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = SR(3)
    for i in range(3):
        print(s[i][i], end="")
    print()
    return

#B
def B():
    a, b = LI()
    ans = 0
    for i in range(a, b + 1):
        x = str(i)
        for k in range(len(x)//2):
            if x[k] != x[-k - 1]:
                break
        else:
            ans += 1
    print(ans)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 39664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll n; cin>>n;
  ll ans = inf;
  rep(i, n) {
    ll a; cin>>a;
    ll tmp = 0;
    while (a%2 == 0) {
      tmp++;
      a /= 2;
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
//#include<cmath>
using namespace std;

const int INFTY = 1000000001;
int S[500010], n, cmp;

void merge(int left, int mid, int right)
{
	int n1 = mid - left, n2 = right - mid;
	vector<int>L(n1 + 1), R(n2 + 1);
	for (int i = 0; i < n1; i++)
		L[i] = S[left + i];
	for (int i = 0; i < n2; i++)
		R[i] = S[mid + i];
	L[n1] = R[n2] = INFTY;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			S[k] = L[i];
			i += 1;
			cmp++;
		}
		else {
			S[k] = R[j];
			j += 1;
			cmp++;
		}
	}
}

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

int main(void)
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> S[i];
	mergeSort(0, n);
	int i = 0;
	for (int j = 0; j < n; j++) {
		if (i++)
			cout << " ";
		cout << S[j];
	}
	cout << endl;
	cout << cmp << endl;
	return 0;
}


Measured memory_bytes: 6888
#include <iostream>
#include <vector>
#include <cmath>
#include <iterator>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int p,q, p_sum=0, q_sum=0;
    //数pを作る
    REP(i,n){
        cin >> p;
        p_sum += p*pow(10,n-i-1);
    }
    //数qを作る
    REP(i,n){
        cin >> q;
        q_sum += q*pow(10,n-i-1);
    }
    //1からnまでの配列を作る
    vector<int> list(n);
    REP(i,n){
        list[i]=i+1;
    }
    
    //辞書順の配列を作る
    vector<int> dic_list;
    do{
        int sum=0;
        REP(i, n){
            sum += list[i]*pow(10,n-1-i);
        }
        dic_list.push_back(sum);
    }while(next_permutation(ALL(list)));

    //辞書順の配列から検索するイテレータを取得する
    int d1, d2;
    auto itr_p = find(ALL(dic_list), p_sum);
    auto itr_q = find(ALL(dic_list), q_sum);

    //イテレータで添字を求める
    d1 = distance(dic_list.begin(), itr_p);
    d2 = distance(dic_list.begin(), itr_q);

    //2数間の距離を求める
    cout << abs(d1-d2);
    
    return 0;
}


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

#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    int N;
    cin >> N;
    cout << (N + 1)/2;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

ll n,k;

void solve(istream& cin, ostream& cout) {
	cin >> n >> k;
	cout << min(n%k,  -(n%k-k)) << endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int main(){
    int h,a;
    cin >> h>>a;
    cout<<(h-1)/a+1<<endl;
    
    return 0;
}



Measured memory_bytes: 256
s = gets
if /^.*keyence$/.match(s) ||
   /^k.*eyence$/.match(s) ||
   /^ke.*yence$/.match(s) ||
   /^key.*ence$/.match(s) ||
   /^keye.*nce$/.match(s) ||
   /^keyen.*ce$/.match(s) ||
   /^keyenc.*e$/.match(s) ||
   /^keyence.*$/.match(s)
then
  puts 'YES'
else
  puts 'NO'
end



Measured memory_bytes: 3836
#include <stdio.h>

int main(){
    int N, X;
    int L[100 + 1];

    scanf("%d%d", &N, &X);
    L[0] = 0;
    for (int i = 1; i <= N; i++) {
        scanf("%d", &L[i]);
    }

    int dist = 0;
    int bound = 0;
    for (bound = 0; bound <= N; bound++) {
        if (dist + L[bound] > X) break;
        dist += L[bound];
    }

    printf("%d", bound);

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    long long int a[n+1],b[n+1],dpa[n+1],dpb[n+1],dpc[n+1],c[n+1];
    
    for(long long i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dpa[1]=a[1];
    dpb[1]=b[1];
    dpc[1]=c[1];
    for(long long int i=2;i<=n;i++)
    {
        dpa[i]=a[i] + max(dpb[i-1],dpc[i-1]);
        dpb[i]=b[i] + max(dpa[i-1],dpc[i-1]);
        dpc[i]=c[i] + max(dpb[i-1],dpa[i-1]);
    }
    cout<<max(dpc[n],max(dpa[n],dpb[n]));
    
    
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <stdlib.h>
#define rep(i,l,r) for((i)=(l);(i)<(r);(i)++)
#define erep(i,l,r) for((i)=(l);(i)<=(r);(i)++)
#define drep(i,l,r) for((i)=(l);(i)>=(r);(i)--)
#define MOD 1000000007
#define ll long long
#define MAX(a,b) ((a)>(b)?(a):(b))
using namespace std;
int main(){
    int n,i,j;
    cin>>n;
    cout<<n*n*n<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""077-c"""

import sys
import pprint
import re
import itertools

import bisect

pp = pprint.PrettyPrinter(indent=2)

def main():
    """Main function."""
    N = int(input())

    As = sorted(list(map(int, input().split(' '))))
    Bs = map(int, input().split(' '))
    Cs = sorted(list(map(int, input().split(' '))))

    count = 0
    for b in Bs:
        i = bisect.bisect_left(As, b)
        k = N - bisect.bisect_right(Cs, b)
        count += i * k

    print(count)

if __name__ == '__main__':
    sys.exit(main())

Measured memory_bytes: 27892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

ll mod = 1e9+7;
#define NMAX 200001
ll fac[NMAX];
ll inv[NMAX];

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

ll mod_inv(ll a, ll mod){
    return mod_pow(a, mod-2, mod);
}

void mae_nck(){
    fac[1] = 1;
    inv[1] = 1;
    for(ll i = 2; i < NMAX; i++){
        fac[i] = (fac[i-1] * i)%mod;
        inv[i] = (inv[i-1] * mod_inv(i, mod))%mod;
    }
}

ll mod_nck(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    if(k == 0 || k == n) return 1;
    ll ret = ((fac[n] * inv[k])%mod * inv[n-k])%mod;
    return ret;
}

int main(){
    ll N, K;
    cin >> N >> K;
    VL A(N);
    rep(i, 0, N) cin >> A[i];

    sort(A.begin(), A.end());
    VL CA(A);
    reverse(CA.begin(), CA.end());
    mae_nck();

    ll ans = 0;
    rep(i, K-1, N){
        ans += (A[i]%mod) * mod_nck(i, K-1);
        ans %= mod;
        ans -= (CA[i]%mod) * mod_nck(i, K-1);
        ans %= mod;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;

public class Hello{
    public static void Main(){

        string[] line = Console.ReadLine().Split(' ');
        int count = int.Parse(line[0]);
        var money = int.Parse(line[1]);

        if(count <= 5)
        {
            Console.WriteLine("0");
        }
        else if(count >= 13)
        {
            Console.WriteLine(money);
        }
        else 
        {
            Console.WriteLine(money / 2);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>

using namespace std;

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

    while (a > 0 && c > 0){
        a -= d;
        c -= b;
    }
    if (c < 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
import itertools
N = int(input())
P,Q = input().rstrip().split(" "),input().rstrip().split(" ")

for i in range(N):
  P[i],Q[i] = int(P[i]),int(Q[i])

seq=list(range(1,N+1))
a = list(itertools.permutations(seq, N))

for i in range(len(a)):
  if a[i] == tuple(P):
    pindex= i+1
  if a[i] == tuple(Q):
    qindex= i+1
    
print(abs(pindex-qindex))

Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int h, w;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
vector<vector<ll>> d(1001, vector<ll>(1001));
vector<vector<char>> a(1001, vector<char>(1001));

int bfs(){
  queue<pair<int, int>> que;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      d.at(i).at(j)=INF;
      if(a.at(i).at(j)=='#'){
        d.at(i).at(j)=0;
        que.push(pair<int, int>(i, j));
      }
    }
  }

  while(que.size()){
    pair<int, int> p=que.front();
    que.pop();
    for(int i=0; i<4; i++){
      int ny=p.first+dy[i], nx=p.second+dx[i];
      if(0<=ny && ny<h && 0<= nx && nx <w && 
        d.at(ny).at(nx)>d.at(p.first).at(p.second)+1){
        d.at(ny).at(nx) = d.at(p.first).at(p.second)+1;
        que.push(pair<int, int>(ny, nx));
      }
    }
  }

  int cnt=0;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(cnt>=d.at(i).at(j)){
        cnt=cnt;
      }else{
        cnt=d.at(i).at(j);
      }
    }
  }
  return cnt;
}

int main(){
  cin >> h >> w;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cin >> a.at(i).at(j);
    }
  };

  cout << bfs() << endl;

  return 0;
}

Measured memory_bytes: 17296
#include <stdio.h>
#include <string.h>
#define NMAX 100000
#define MMAX 20
#define INF 1000000000
int n, m, imos[MMAX][NMAX+1], dp[1<<MMAX];
int rec(int S, int v);
int main(void)
{
  int i, j, d;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d", &d);
    d--;
    for (j = 0; j < m; j++) {
      if (d != j) imos[j][i+1]++;
      imos[j][i+1] += imos[j][i];
    }
  }
  memset(dp, -1, sizeof(dp));
  dp[(1<<m)-1] = 0;
  printf("%d\n", rec(0, 0));
}

int rec(int S, int v)
{
  int i, res = INF;
  if (dp[S] != -1) return dp[S];
  for (i = 0; i < m; i++) {
    if (!(S & 1 << i)) {
      int lans, isum = n - imos[i][n], icnt = imos[i][v+isum] - imos[i][v];
      lans = rec(S | 1 << i, v + isum) + icnt;
      if (res > lans) res = lans;
    }
  }
  return dp[S] = res;
}



Measured memory_bytes: 13608
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

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


Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

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

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)
	a := make([]int, 5)
	for i := 0; i < 5; i++ {
		a[i] = nextInt()
	}
	k := nextInt()
	sort.Ints(a)
	if a[4]-a[0] > k {
		fmt.Fprintf(writer, ":(")
	} else {
		fmt.Fprintf(writer, "Yay!")
	}
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
using System.Collections.Generic;
using CompLib.Util;
using System;

public class Program
{

    int H, N;
    int[] A, B;
    public void Solve()
    {
        var sc = new Scanner();
        H = sc.NextInt();
        N = sc.NextInt();


        A = new int[N];
        B = new int[N];
        for (int i = 0; i < N; i++)
        {
            A[i] = sc.NextInt();
            B[i] = sc.NextInt();
        }


        long[] dp = new long[H + 1];
        for (int i = 0; i <= H; i++)
        {
            dp[i] = long.MaxValue;
        }

        dp[H] = 0;

        for (int i = 0; i < N; i++)
        {
            for (int j = H; j >= 0; j--)
            {
                if (dp[j] == long.MaxValue) continue;

                int n = Math.Max(0, j - A[i]);
                dp[n] = Math.Min(dp[n], dp[j] + B[i]);
            }

            // Console.WriteLine(string.Join(" ", dp));
        }

        Console.WriteLine(dp[0]);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;
    class Scanner
    {
        private int _index;
        private string[] _line;
        const char separator = ' ';

        public Scanner()
        {
            _index = 0;
            _line = new string[0];
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(separator);
                _index = 0;
            }
            return _line[_index++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(separator);
            _index = _line.Length;
            return _line;
        }
        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
    }
}

Measured memory_bytes: 11188
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
typedef pair<string, P> Q;
int main(void){
    int n, p;
    Q q[100];
    string s;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s >> p;
        q[i] = Q(s, P(-p, i+1));
    }
    sort(q, q+n);
    for(int i=0;i<n;i++){
        cout << q[i].second.second << endl;
    }
}


Measured memory_bytes: 256
n,m = map(int,input().split())
k = []
s = []
for i in range(m):
    kk,*ss = map(int,input().split())
    k.append(kk)
    s.append(ss)
p = [int(x) for x in input().split()]
d = []
ans = 0

for i in range(2**n): #スイッチの押し方の全列挙
    flag = True
    for j in range(m): #各電球について
        count = 0
        for l in range(len(s[j])): #各電球のスイッチにについて
            tmp = s[j][l]
            #l番目のスイッチがオンかどうか
            if (i >> tmp-1) & 1 == 1:
                count += 1
        #各電球について、オンになっているスイッチの総数を2で割って点灯しているか調べる
        if count%2 != p[j]:
            flag = False
    #flagがTrueであればi番目のスイッチの押し方で全ての電球が点灯する
    if flag:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX / 2;
constexpr lint LINF = LLONG_MAX / 2;
constexpr double eps = 1e-9;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
lint mypow(lint a, lint b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	lint memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
std::string to_string(std::vector<int>& vec) {
	std::string res = "[";
	rep(i, vec.size() - 1)res += std::to_string(vec[i]) + ", ";
	res += std::to_string(vec.back()) + "]";
	return res;
}
int main() {
	lint n,a,b;
	std::cin>>n>>a>>b;
	std::cout<<n/(a+b)*a+std::min(a,n%(a+b))<<std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n+1);
  vector<int> b(n);
  for(int i=0;i<n+1;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  int64_t ans=0;

  for(int i=0;i<n;i++){
    if(a[i]<=b[i]){
      ans+=a[i];
      b[i]-=a[i];
    }
    else{
      ans+=b[i];
      b[i]=0;
    }
    if(a[i+1]<=b[i]){
      ans+=a[i+1];
      a[i+1]=0;
    }
    else{
      ans+=b[i];
      a[i+1]-=b[i];
    }
    
  }
  cout<<ans<<endl;
}
    


Measured memory_bytes: 1024
H1, M1, H2, M2, K = map(int, input().split())

J = H2 - H1
if (M1 > M2):
  J -= 1
  F = 60 + M2 - M1
else:
  F = M2 - M1

F = J * 60 + F

print(F - K)


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

typedef long long ll;

// 最大公約数（a > b）
ll gcd(ll a, ll b) {
  ll r = a % b;
  while (r > 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

// 最小公倍数（a > b）
ll lcm(ll a, ll b) {
  //return (a * b) / gcd(a, b);
  ll g = gcd(a, b);
  return ((a / g) * (b / g)) * g;
}

int main() {
  int N;
  cin >> N;
  ll T[N];
  for (int i = 0; i < N; i++) cin >> T[i];

  sort(T, T + N);
  // ll tmp = T[N-1];
  // ll ans;
  // for (int i = 1; tmp * i <= 1e18; i++) {
  //   ans = tmp * i;
  //   bool flag = true;
  //   for (int j = 0; j < N - 1; j++) {
  //     if (ans % T[j] != 0) flag = false;
  //   }
  //   if (flag) break;
  // }

  ll ans = T[N-1];
  for (int i = 0; i < N - 1; i++) {
    if (ans % T[i] == 0) continue;
    ans = lcm(ans, T[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<bool, bool> pbb;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
#define enum(i, j, k) for(int i = j; i <= k; i ++)
#define open(i, j, k)  for(int i = j; i <  k; i ++)
#define dec(i, j, k)  for(int i = j; i >= k; i --)
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
template <class T> bool chkmin(T &x, T y)
{ return y < x ? x = y , true : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? x = y , true : false; }
void __init()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(16);
    srand(time(0) ^ ui(ul(new char)));
}
/* default code ends here */
#define mod 1000000007
#define maxn 200100
int n;
int a[maxn];
ll s[maxn];
ll f[maxn];
int main()
{
    __init();
    cin >> n;
    enum(i, 1, n)
        cin >> a[i];
    f[n + 1] = 1;
    dec(i, n, 1)
    {
        f[i] = s[a[i]];
        if(a[i] != a[i + 1])
        {
            f[i] = (f[i] + f[i + 1]) % mod;
            s[a[i]] = (s[a[i]] + f[i + 1]) % mod;
        }
    }
    cout << f[1] << endl;
    return 0;
}

Measured memory_bytes: 4224
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;
const int M = 1e9+7;

long long a , b;
vector < long long > common;

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

vector < int > primeFactors(long long num){
    vector < int > prm;
    while (num % 2 == 0){
        prm.push_back(2);
        num = num/2;
    }
    for (long long i = 3; i*i <= num; i = i + 2){
        while (num % i == 0){
            prm.push_back(i);
            num = num/i;
        }
    }
    if (num > 2)
        prm.push_back(num);
    return prm;
}

int main(){
    cin >> a >> b;
    map < int , bool > taken , did;
    vector < int > A[2] = {primeFactors(a) , primeFactors(b)};
    for(int i = 0; i < A[0].size(); i++){
        taken[A[0][i]] = 1;
    }
    int cnt = 1;
    for(int i = 0; i < A[1].size(); i++){
        if(taken[A[1][i]] && !did[A[1][i]]){
            cnt++;
            did[A[1][i]] = 1;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll //9223372036854775807
#define pi acos(-1.0)
#define ms(a,b) memset(a,b,sizeof(a))
#define nl "\n"
#define FAST_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
//ll qpow(ll x, ll y){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;}
ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;}
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}
ll inve(ll x){return x==1?1:(mod-mod/x)*inve(mod%x)%mod;}

int main()
{
    int n, a, b;
    cin>>n>>a>>b;
    int x=0;
    x=min(a,b);
    int y=0;
    if(n-a-b>=0)
        y=0;
    else
        y=a+b-n;
    cout<<x<<" "<<y;

    
    
    
    return 0;
}



Measured memory_bytes: 256