akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main {

    private int n;
    private int m;
    private List<Long> primeFactors;
    private final long d = 1000000007;
    
    public static void main(String[] args) {
	Main f = new Main();
	System.out.println(f.solve());
    }

    private Main() {
	set();
    }

    private void set() {
	n = m = 0;
	try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
	    int[] nm = Arrays.stream(br.readLine().trim().split("[\\s]+")).mapToInt(Integer::parseInt).toArray();
	    n = nm[0];
	    m = nm[1];
	} catch(IOException e) {
	    e.printStackTrace();
	}
	primeFactors = new ArrayList<>();
	int num = m;
	for (long i=2;i<=num;i++) {
	    long count = 0;
	    while (num%i == 0) {
		count++;
		num /= i;
	    }
	    if (count > 0) primeFactors.add(count);
	    if (num == 1) break;
	}
    }

    private long solve() {
	long ans = 1;
	for (long v : primeFactors) {
	    ans = (ans*h(n,v))%d;
	}
	return ans%d;
    }

    private long h(long a,long b) {
	a = a+b-1;
	if (a-b < b) b = a-b;
	long u = 1;
	long l = 1;
	for (long i=1;i<=b;i++) {
	    u *= a-i+1;
	    u %= d;
	    l *= i;
	    l %= d;
	}
	return (u*pinv(l,d-2))%d;
    }

    private long pinv(long l,long p) {
	if (p == 0) return 1;
	if (p%2 == 0) {
	    long h = pinv(l,p/2)%d;
	    return (h*h)%d;
	} else {
	    return (l*pinv(l,p-1))%d;
	}
    }
}

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

int main() {
    string S;
    int K;
    cin>>S;
    cin>>K;
    // dp[桁][未満][ゼロでない個数]
    long dp[S.size()][2][K+1];
    for(int i=0;i<S.size();++i){
        for(int j=0;j<2;++j){
            for(int k=0;k<=K;++k){
                dp[i][j][k] = 0;
            }
        }
    }
    dp[0][0][1] = 1;
    for(int i=0;i<S.size();++i){
        dp[i][1][0] = 1;
    }
    dp[0][1][0] = 1;
    dp[0][1][1] = S[0] - '0' - 1;
    for(int i=1;i<S.size();++i){
        for(int k=1;k<=K;++k){
            if(S[i]=='0'){
                dp[i][0][k] = dp[i-1][0][k];
                dp[i][1][k] = dp[i-1][1][k] + dp[i-1][1][k-1]*9;
            }
            else{
                dp[i][0][k] = dp[i-1][0][k-1];
                dp[i][1][k] = dp[i-1][0][k-1]*(S[i]-'0'-1) + dp[i-1][1][k-1]*9 + dp[i-1][1][k] + dp[i-1][0][k];
            }
        }
    }
    /**
    for(int i=0;i<S.size();++i){
        for(int j=0;j<2;++j){
            for(int k=0;k<=K;++k){
                cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
            }
        }
    }
    **/
    cout<<dp[S.size()-1][1][K]+dp[S.size()-1][0][K]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define FT() int t; scanf("%d",&t); while(t--)
#define pb push_back
#define nl printf("\n")
#define fi(i,start,end) for(int i=start; i < (int)end ; ++i)
#define ip(n)   scanf("%d",&n)
#define mz(a)   memset(a,0,sizeof(a))
#define inpArr(A,n) fi(i,0,n)   ip(A[i]);
#define print(a)  for(auto i : a)   cout<<i<<" "; nl;
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll max(ll a,ll b) { return a>b?a:b;}
ll min(ll a,ll b) { return a<b?a:b;}
void solve()
{   
}
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    
    char ch;
    cin>>ch;
    if(ch>='a' && ch<='z')
        cout<<"a";
    else
        cout<<"A";

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
    #endif
    return 0;
}


Measured memory_bytes: 3632
<?php
  
$s = trim(fgets(STDIN));
$e = [];
$o = [];

for($i=0; $i<strlen($s); $i++){
  if ($i%2==0){
    array_push($o,$s[$i]);
  } else {
    array_push($e,$s[$i]);
  }
}

echo !in_array('L',$o) && !in_array('R',$e)? 'Yes' : 'No';

?>

Measured memory_bytes: 4604
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, K = get_ints
A = get_ints

waru = (N - 1) / (K - 1)
amari = (N-1) % (K-1)

puts waru + (amari == 0 ? 0 : 1)


Measured memory_bytes: 21072
#include<bits/stdc++.h>
#define db double
using namespace std;
int n;
db xp1,xp2,xp3,xp4,yp1,yp2,yp3,yp4;
db sum1,sum2,xa,xb,xc,xd,ya,yb,yc,yd;
db len(db xp1,db yp1,db xp2,db yp2,db xp3,db yp3){
	db l1=xp2-xp1,r1=yp2-yp1,l2=xp3-xp1,r2=yp3-yp1;
	if(l1*l2+r1*r2>=0&&abs((l1*l2+r1*r2)/sqrt(l1*l1+r1*r1))<=sqrt(l1*l1+r1*r1))return(abs((l1*r2-l2*r1)/sqrt(l1*l1+r1*r1)));
	else{
		db sum1=sqrt(l2*l2+r2*r2);
		db sum2=sqrt((xp3-xp2)*(xp3-xp2)+(yp3-yp2)*(yp3-yp2));
		return(min(sum1,sum2));
	}
} 
void solve(int t){
	db mn=40000;
	mn=min(mn,len(xp1,yp1,xp2,yp2,xp3,yp3));
	mn=min(mn,len(xp1,yp1,xp2,yp2,xp4,yp4));
	mn=min(mn,len(xp3,yp3,xp4,yp4,xp1,yp1));
	mn=min(mn,len(xp3,yp3,xp4,yp4,xp2,yp2));
	printf("%.10lf\n",mn);
}
int main(){	
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		scanf("%lf%lf%lf%lf",&xp1,&yp1,&xp2,&yp2);
		scanf("%lf%lf%lf%lf",&xp3,&yp3,&xp4,&yp4);
		xa=min(xp1,xp2);
		xb=max(xp1,xp2);
		ya=min(yp1,yp2);
		yb=max(yp1,yp2);
		xc=min(xp3,xp4);
		xd=max(xp3,xp4);
		yc=min(yp3,yp4);
		yd=max(yp3,yp4);
		if(xc>xb||xa>xd||yc>yb||ya>yd){
			solve(i);
			continue;
		}
		xb=xp4-xp3;
		yb=yp4-yp3;
		xa=xp1-xp3;
		ya=yp1-yp3;
		sum1=xa*yb-xb*ya;
		xa=xp2-xp3;
		ya=yp2-yp3;
		sum2=xa*yb-xb*ya;
		if(sum1*sum2>0){
			solve(i);
			continue;
		}
		xb=xp2-xp1;
		yb=yp2-yp1;
		xa=xp3-xp1;
		ya=yp3-yp1;
		sum1=xa*yb-xb*ya;
		xa=xp4-xp1;
		ya=yp4-yp1;
		sum2=xa*yb-xb*ya;
		if(sum1*sum2>0){
			solve(i);
			continue;
		}
		printf("0.0000000000\n");
	}
}


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

int main(){
  int k,i;
  char s[101];
  char ans[105];
  int len;

  scanf("%d",&k);
  scanf("%s",s);

  len = strlen(s); //文字列の文字数を取得

  if(k < len){
    for(i=0;i<k;i++){
      ans[i]=s[i];
    }
    ans[i]='.';
    ans[i+1]='.';
    ans[i+2]='.';
    ans[i+3]='\0';
    printf("%s\n",ans);
  }else{
    printf("%s\n",s);
  }
  return 0;
}


Measured memory_bytes: 1644
module Main where

import Data.Functor
import Numeric

main :: IO ()
main =  do
  { [n] <- getInts
  ; xs  <- getDoubles
  ; ys  <- getDoubles
  ; let zs = zipWith ((abs .) . subtract) xs ys
  ; putStr $ unlines $ map (flip (showFFloat Nothing) "") (map (flip minkovsky zs) [1,2,3] ++ [maximum zs])
  }

minkovsky :: Double -> [Double] -> Double
minkovsky p = (** recip p) . sum . map (** p)

done :: IO ()
done = return ()

getInts :: IO [Int]
getInts = map read . words <$> getLine

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++)

const char nl = '\n';
const int MOD = 1e9 +7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 + 5;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  int sum = 0;
  int tmp = 10;
  bool ok = 0;
  for(int i = 0; i < 5; i++){
    int x; cin >> x;
    if(x%10 == 0)
      sum += x;
    else{
      sum += ceil(x/10.0) * 10;
      tmp = min(tmp,x%10);
      ok =1;
    }

  }
  ok ? cout << sum - 10 + tmp << nl : cout << sum << nl;


}


Measured memory_bytes: 3540
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <array>
#include <list>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef long long ll;

int main() {
    ll k, s, cont = 0;
    cin >> k >> s;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            if (s - x - y <= k && x + y <= s) {
                cont++;
            }
        }
    }
    cout << cont << endl;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)

#pragma comment(linker, "/STACK:16777216")

typedef long long int64;
typedef unsigned long long uint64;

int64 a[100005];

int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	a[0] = 0;
	a[n + 1] = 0;

	int64 s = 0;
	for (int i = 0; i < (n+1); i++) s += abs(a[i+1] - a[i]);

	for (int i = 1; i <= n; i++) {
		int64 ss = s - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]);
		cout << ss << endl;
	}	

	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>

int main() {
  int l = -1000000;
  int r = 1000000;
  int k, x;
  std::cin >> k >> x;
  int nl = std::max(l, x - k + 1);
  int nr = std::min(r, x + k - 1);
  for (int i = nl; i <= nr; ++i) std::cout << i << " ";
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int vs[200];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
  }
  int maxi = 0;
  int mini = 0;
  int maxIdx = 0;
  int minIdx = 0;
  REP(i, n) {
    if(maxi < vs[i]) {
      maxIdx = i;
      maxi = vs[i];
    }
    if(mini > vs[i]) {
      minIdx = i;
      mini = vs[i];
    }
  }
  vector<pair<int,int> > res;
  if(abs(maxi) > abs(mini)) {
    REP(i, n) {
      if(i != maxIdx) {
        res.push_back(make_pair(maxIdx, i));
      }
    }
    REP(i, n-1) {
      res.push_back(make_pair(i, i+1));
    }
  } else {
    REP(i, n) {
      if(i != minIdx) {
        res.push_back(make_pair(minIdx, i));
      }
    }
    REP(i, n-1) {
      res.push_back(make_pair(n-i-1, n-i-2));
    }
  }

  printf("%d\n", (int)res.size());
  REP(i, res.size()) {
    printf("%d %d\n", res[i].first+1, res[i].second+1);
  }
  return 0;
}


Measured memory_bytes: 256
def enq(a,x)
  b = a[i=-1]
  until b.frozen?
    return a.unshift x  if x <= (a=b)[0]
    return a << x  if x >= a[-1]
    i = a.bsearch_index {|y| x <= (y.frozen? ? y: y[0])}
    b = a[i-=1]  if (b=a[i]).frozen? ? x<b: x<b[0]
  end  if b && b=a
  return a.insert(i+1, x)  if a.size-i < 9
  i > 9 ? a[i] = [a[i],x] : a.unshift(*a.shift(i+1),x)
end
def deq(a)
  return a.shift  if !a[1]
  l,a = a,n  until (n=a[0]).frozen?
  if (r=a[1]).frozen?; l[0] = r if l && !a[2]; a.shift
  else a[0] = deq r; a[1] = r[0] if !r[1]; n end
end
N,M,*A = $<.read.split.map{|x| -x.to_i}
A.sort!
(-M).times { break if A[0]==0; enq A, -(-(deq A)/2) }
p A.flatten.inject(0,:-)

Measured memory_bytes: 14168
#pragma GCC optimize ("-O3")
    #include <bits/stdc++.h>  
     
    using namespace std;
     
    typedef long long ll;
    typedef long double ld;
    typedef pair<int,int> p32;
    typedef pair<ll,ll> p64;
    typedef pair<double,double> pdd;
    typedef vector<ll> v64;
    typedef vector<int> v32;
    typedef vector<vector<int> > vv32;
    typedef vector<vector<ll> > vv64;
    typedef vector<vector<p64> > vvp64;
    typedef vector<p64> vp64;
    typedef vector<p32> vp32;
    ll MOD = 998244353;
    #define forn(i,e) for(ll i = 0; i < e; i++)
    #define forsn(i,s,e) for(int i = s; i < e; i++)
    #define rforn(i,s) for(ll i = s; i >= 0; i--)
    #define rforsn(i,s,e) for(ll i = s; i >= e; i--)
    #define ln "\n"
    #define dbg(x) cout<<#x<<" = "<<x<<ln
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define INF 1e18
    #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
    #define all(x) (x).begin(), (x).end()
    #define sz(x) ((ll)(x).size())
     
    ll mpow(ll a, ll b){
        if(b >= (MOD-1)) b %= (MOD-1);
        if(b==0) return 1;
        ll t1 = mpow(a,b/2);
        t1 *= t1;
        t1 %= MOD;
        if(b%2) t1 *= a;
        t1 %= MOD;
        return t1;
    }
     
    ll mpow(ll a, ll b, ll p){
        if(b==0) return 1;
        ll t1 = mpow(a,b/2,p);   t1 *= t1;
        t1 %= p;
        if(b%2) t1 *= a;
        t1 %= p;
        return t1;
    }
    ll modinverse(ll a, ll m){
        ll m0 = m; 
        ll y = 0, x = 1; 
        if (m == 1) return 0; 
        while (a > 1){
            ll q = a / m; 
            ll t = m; 
            m = a % m, a = t; 
            t = y; 
            y = x - q * y; 
            x = t; 
        }
        if (x < 0) x += m0; 
        return x; 
    }
    ll range(ll l, ll r){
        return l + rand()%(r-l+1);
    }
    
    int main()
    {
        ll t=1;
        //cin>>t;
        while(t--)
        {
            ll n,x,t;
            cin>>n>>x>>t;
            ll ans = t * (n/x);
            if(n%x != 0)ans+=t;
            cout<<ans<<endl;
        }
    }

Measured memory_bytes: 3592
#include <stdio.h>
int main(void){
    int w, h;
    while (1) {
        scanf("%d%d", &w, &h);
        if (h == 0) break;
        for (int i=0; i < w;i++) {
            for (int j=0; j < h; j++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}



Measured memory_bytes: 2056
// ProblemURL : https://atcoder.jp/contests/code-festival-2017-qualb/tasks/code_festival_2017_qualb_a
// ---------------------------------------------
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	suf := "FESTIVAL"
	fmt.Println(s[:len(s)-len(suf)])
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define N 1000000007
using namespace std;

long long n;
long long a[30][30] = {0};
// dp[i][s]: i-man number, s-women state
long long dp[30][4194304] = {0};

long long solve();

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j) cin >> a[i][j];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  for(int i = 0; i < n; ++i)
    if(a[0][i]) dp[0][(1 << n) - 1 - (1 << i)] = 1;
  for(int i = 1; i < n; ++i)
    for(int j = 0; j < n; ++j)
      if(a[i][j]) {
        int now = (1 << n) - 1 - (1 << j);
        for(int mask = now; mask >= 0; --mask &= now) {
          dp[i][mask] += dp[i - 1][mask + (1 << j)];
          dp[i][mask] %= N;
          if(mask == 0) break;
        }
      }
  return dp[n - 1][0];
}

Measured memory_bytes: 377088
#include<iostream>
#include<string>

using namespace std;

int main(void){

    string str;
    bool flag = false;

    cin >> str;


    int tmp;
    for(int i = 0;i < 3;i++){
        if(str[i] == str[i+1]) flag = true;
    }

    cout << (flag ? "Bad" : "Good") << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	int ans=0;
	REP(i, s.size()-1){
		if(s[i]!=s[i+1]){
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
bool ispal(string a)
{
    long long int n=a.length();
    if(n==1)
        return true;
    else{
    int i=0,j;
    j=n-1;
    while(1)
    {
        if(a[i]!=a[j])
        {
            cout<<i<<" "<<j;
           return false;
        }
        i++,j--;
        if(i==j)
         {
        //     cout<<i<<" ";
             break;
        }
    }
    return true;
}}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 ll n,k;
 cin>>n>>k;
 ll ans=0,tm;
 tm= k*k;
 for(int i=0;i<n;i++)
 {
    ll a,b;
    cin>>a>>b;
    ll sum = (a*a) + (b*b);
    if(sum<=tm)
    {
        ans++;
    }
 }
 cout<<ans;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;

int main(int argc, char* argv[]){
  int N, K, tmp, i;
  cin >> N;
  cin >> K;
  tmp = 1;
  for (i=0; i<N; i++){
    if(tmp < K){
      tmp *= 2;
    }else{
      tmp += K;
    }
  }
  cout << tmp;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-07-30 18:54:32 +0900
# LastModified: 2020-07-30 19:11:26 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
def gcd(s, t):
    while t != 0:
        tmp = s % t
        s = t
        t = tmp
    return s


def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    a = []
    for i, s in enumerate(x):
        if i == 0:
            a.append(abs(x[0]-X))
            continue
        a.append(abs(x[i]-x[i-1]))
    ans = a[0]
    for i in range(1, len(a)):
        ans = gcd(max(ans, a[i]), min(ans, a[i]))
        
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 20516
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    long long x, y, ans;
    cin >> x >> y;
    ans = 0;
    while (x <= y)
    {
        ans++;
        x *= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 string s;
 cin>>s;
 ll res = 0;
 ll cnt = 0;
 ll n = s.size();
 for(ll i=0;i<n;i++){
  res += s[i]-'0';
 }
 /*
 ll i = 0;
 bool f = true;

 for(ll j=1;j<n;j++){
  if( s[i] != '0'){
   f = false;
   break;
  }
 }
 if( f ) {
  cout<<s[0]<<endl;
  return 0;
 }else{
  f = true;
 }

 for( i=0;i<n;i++){
  if( s[i] <='5' ){
   cnt += s[i]-'0';
  }else{
   f = false;
   break;
  }
 }
 if( f ){
  cout<<cnt<<endl;
  return 0;
 }
 for(ll j=i+1;j<n;j++){
  if( s[j] != '0'){
   f = false;
   break;
  }
 }
 if( f ){
  cout<<cnt<<endl;
  return 0;
 }



 //if(i==0){
 //  cnt++;
  
 //}
  if(i != n )cnt++;
 for( ;i<n;i++){
  ll tmp = s[i]-'0';
  cnt+= min( tmp , 10 - tmp );
 }*/
 /*for(ll i=0;i<n;i++){
  ll tmp = s[i]-'0';
  cnt+= min( tmp , 10 - tmp );
  if( tmp >= 10 - tmp){
   if( i == 0 || s[i-1] >= '5' ){
    cnt++;
   }
  }
 }*/
 vector< vector<ll> > dp( n ,vector<ll>(2, 0 ) );
 dp[0][0] = s[0]-'0';
 dp[0][1] = 11- (s[0]-'0');
 for(ll i=1;i<n;i++){
  dp[i][0] = min( dp[i-1][0] , dp[i-1][1] ) + (s[i]-'0');
  dp[i][1] = min( dp[i-1][0] + 11 - (s[i]-'0') , dp[i-1][1] + 9 - ( s[i]-'0') );
 }
 cout<<min( dp[n-1][0] , dp[n-1][1] )<<endl;
    return 0;
}


Measured memory_bytes: 55940
#include <cstdio>
#include <cstring>

int main()
{
  int h,w;
  scanf("%d%d",&h,&w);
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      char s[10];
      scanf("%s",s);
      if(!strcmp(s,"snuke")){
	printf("%c%d\n",'A'+j,1+i);
      }
    }
  }
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

const int INF = 1e9;

void solve() {
  int N, M;
  cin >> N >> M;
  vector<vi32> sg(N + 1);
  vector<vi32> rg(N + 1);
  vi32 deg(N + 1);
  rep(i, N + M - 1) {
    int u, v;
    cin >> u >> v;
    sg[u].emplace_back(v);    
    rg[v].emplace_back(u);
    deg[v]++;
  }
  int root;
  reps(i, N) if (deg[i] == 0) {
    root = i;
  }
  vi32 dag;
  {
    vi32 seen(N + 1);
    auto dfs = [&](auto dfs, int u) -> void {
      seen[u] = 1;
      each(v, sg[u]) if (!seen[v]) {
        dfs(dfs, v);
      }
      dag.emplace_back(u);
    };
    reps(i, N) if (!seen[i]) dfs(dfs, i);
    reverse(all(dag));
  }
  vi32 dep(N + 1);
  rep(i, N) {
    int u = dag[i];
    int ma = -1;
    each(p, rg[u]) amax(ma, dep[p]);
    dep[u] = ma + 1;
  }
  vi32 par(N + 1);
  {
    auto dfs = [&](auto dfs, int u) -> void {
      each(v, sg[u]) {
        if (dep[v] == dep[u] + 1) {
          par[v] = u;
          dfs(dfs, v);
        }
      }
    };
    dfs(dfs, dag[0]);
  }
  reps(i, N) cout << par[i] << endl;
}


Measured memory_bytes: 17524
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;

void solve(){
  int h, w; cin >> h >> w;
  vector<vector<char> > v(h, vector<char>(w));
  for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) cin >> v[i][j];
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(v[i][j] == '.') continue;
      if(i == 0 && j == 0){
        if(v[i + 1][j] == '.' && v[i][j + 1] == '.'){
          cout << "No\n";
          return;
        }
      }
      else if(i == 0 && j == w - 1){
        if(v[i + 1][j] == '.' && v[i][j - 1] == '.'){
          cout << "No\n";
          return;
        }

      }
      else if(i == h - 1 && j == 0){
        if(v[i - 1][j] == '.' && v[i][j + 1] == '.'){
          cout << "No\n";
          return;
        }

      }
      else if(i == h - 1 && j == w - 1){
        if(v[i - 1][j] == '.' && v[i][j - 1] == '.'){
          cout << "No\n";
          return;
        }

      }
      else if(i == 0){
        if(v[i + 1][j] == '.' && v[i][j + 1] == '.' && v[i][j - 1] == '.'){
          cout << "No\n";
          return;
        }

      }
      else if(i == h - 1){
        if(v[i - 1][j] == '.' && v[i][j + 1] == '.' && v[i][j - 1] == '.'){
          cout << "No\n";
          return;
        }

      }
      else if(j == 0){
        if(v[i + 1][j] == '.' && v[i - 1][j] == '.' && v[i][j + 1] == '.'){
          cout << "No\n";
          return;
        }

      }
      else if(j == w - 1){
        if(v[i + 1][j] == '.' && v[i - 1][j] == '.' && v[i][j - 1] == '.'){
          cout << "No\n";
          return;
        }

      }
      else{
        if(v[i + 1][j] == '.' && v[i - 1][j] == '.' && v[i][j + 1] == '.' && v[i][j - 1] == '.'){
          cout << "No\n";
          return;
        }
      }
    }
  }
  cout << "Yes\n";
  return;
}

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


Measured memory_bytes: 256
from heapq import heappush, heappop
n=int(input())
a=list(map(int,input().split()))
l=[]
for v in a[:n]:
  heappush(l,v)
suml=[sum(a[:n])]
for i in range(n):
  suml.append(suml[i]+a[n+i])
  heappush(l,a[n+i])
  suml[i+1]-=heappop(l)
r=[]
for v in a[2*n:]:
  heappush(r,(10**10-v,v))
sumr=[sum(a[2*n:])]
for i in range(n):
  sumr.append(sumr[i]+a[2*n-i-1])
  heappush(r,(10**10-a[2*n-i-1],a[2*n-i-1]))
  _,t=heappop(r)
  sumr[i+1]-=t
ans=-10**20
for i in range(n+1):
  ans=max(ans,suml[i]-sumr[n-i])
print(ans)

Measured memory_bytes: 121128
import collections
n = int(input())
v = [int(i) for i in input().split()]
l = collections.Counter(v[1:len(v):2])
r = collections.Counter(v[0:len(v):2])
r = r.most_common()
l = l.most_common()
if l[0][0] == r[0][0]:
    if (len(l) > 1) & (len(r) > 1):
        ans = min(n-l[1][1]-r[0][1], n-l[0][1]-r[1][1])
    else:
        ans = min(l[0][1], r[0][1])
elif l[0][0] != r[0][0]:
    ans = (n - l[0][1] - r[0][1])
print(ans)

Measured memory_bytes: 18656
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout<<fixed<<setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	SETP(20);
	cout << in() * in() / 3.305785 << endl;
}


Measured memory_bytes: 3260
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

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

  int n; cin >> n;
  vector<int> w(n);
  rep(i, n) cin >> w[i];

  int sum = accumulate(all(w), int());

  int ans = 1e8;
  int cur = 0;

  for (int i = 0; i < n; ++i) {
    cur += w[i];
    chmin(ans, abs(sum - cur - cur));
  }

  print(ans);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A,B;
	cin >> A >> B;
	if(A==B){
		cout << "Draw" << endl;
	}else if((A==1||A>B)&&B!=1){
		cout << "Alice" << endl;
	}else{
		cout << "Bob" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF=2e9;

int N,M;
int C[20];
int x[20010];
int dp[20010][260]={};
int main(){
    while(cin>>N>>M,N!=0){
        for(int i=1;i<=M;i++){
            cin>>C[i];
        }
        for(int i=1;i<=N;i++){
            cin>>x[i];
        }
        for(int i=0;i<=N;i++){
            for(int j=0;j<=255;j++){
                dp[i][j]=INF;
            }
        }
        dp[0][128]=0;
        for(int i=0;i<N;i++){
            for(int j=0;j<=255;j++){
                //if(dp[i][j]!=INF){
                    for(int k=1;k<=M;k++){
                        int sig=j+C[k];
                        if(sig<0){
                            sig=0;
                        }else if(sig>255){
                            sig=255;
                        }
                        dp[i+1][sig]=min(dp[i+1][sig],dp[i][j]+(x[i+1]-sig)*(x[i+1]-sig));
                    }
                //}
            }
        }
        int ans=INF;
        for(int i=0;i<=255;i++){
            ans=min(ans,dp[N][i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 23500
A, B, C, D = [int(x) for x in input().split(' ')]

ans = 'Yes'

def takahashiattack():
    global A
    global B
    global C
    global D
    global ans
    C -= B
    if C <= 0:
        print(ans)
    else:
        tanakaattack()
    
def tanakaattack():
    global A
    global B
    global C
    global D
    global ans
    A -= D
    if A <= 0:
        ans = 'No'
        print(ans)
    else:
        takahashiattack()
    
takahashiattack()

Measured memory_bytes: 9180
from fractions import gcd

class PERM_COMB_MOD():
    # http://drken1215.hatenablog.com/entry/2018/06/08/210000
    def __init__(self, max_n=510000, mod=10**9+7):
        self.fac = [0]*max_n
        self.finv = [0]*max_n
        self.inv = [0]*max_n
        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1
        self.max = max_n
        self.mod = mod
        self._maesyori()

    def _maesyori(self):
        for i in range(2,self.max):
            self.fac[i] = self.fac[i-1] * i % self.mod
            self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.finv[i] = self.finv[i-1] * self.inv[i] % self.mod

    def comb(self, n, k):
        if n < k : return 0
        if n < 0 or k < 0:return 0
        return self.fac[n] * (self.finv[k] * self.finv[n-k] % self.mod) % self.mod

mod = 998244353
hoge = PERM_COMB_MOD(mod=mod)
n,a,b,k = map(int, input().split())
if k % gcd(a,b) != 0:
    print(0)
    exit()
ans = 0
for i in range(n+1):
    tmp = k-a*i
    if tmp % b:
        continue
    j = tmp//b
    if j < 0 or n < j:
        continue
    ans += hoge.comb(n, i)*hoge.comb(n, j)
    ans %= mod
print(ans)

Measured memory_bytes: 79080
#include<stdio.h>

int main(void)
{
	int hoge,num,i,j,a,x[10];
	char s[10];
	scanf("%s",s);
	for(j = 0; s[j] != '\0'; j++);
	
	a = 0;
	num = 0;
	
	for(i = 0; i < j; i++){
		if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
			num++;
		}
			if(s[i+1] == 'A' || s[i+1] == 'C' || s[i+1] == 'G' || s[i+1] == 'T'){
			}
			else{
				x[a] = num;
				num = 0;
				a++;
			}
	}
	
	for(i = 0; i < a-1; i++){
		for(j =i+1 ; j < a; j++){
			if(x[i] < x[j]){
				hoge = x[i];
				x[i] = x[j];
				x[j] = hoge;
			}
		}
	}
	
	printf("%d\n",x[0]);
	
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int Q;
        public bool[] P;
        public int[] C;
        public const int PMAX = 100000;
        public void Run()
        {
            P = new bool[PMAX+1];

            for (int i = 2; i <= PMAX; i++)
            {
                P[i] = true;
            }

            for (int i = 2; i <= PMAX; i++)
            {
                if (P[i])
                {
                    for (int j = i * 2; j <= PMAX ; j += i)
                    {
                        P[j] = false;
                    }
                }
            }

            C = new int[PMAX+1];
            int c = 0;
            for (int i = 3; i <= PMAX; i += 2)
            {
                if (P[i] && P[(i + 1) / 2]) c++;
                C[i] = c;
            }


            Q = Input.ReadInt();
            for (int i = 0; i < Q; i++)
            {
                var line = Input.ReadIntArray();
                int l = line[0];
                int r = line[1];

                int a = C[r] - (l == 1 ? 0 : C[l - 2]);

                Console.WriteLine(a);
            }
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 17976
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    // ABC137 - D - Summer Vacation //
    int n, m; cin >> n >> m;
    
    vvi v(100001);
    rep(i, n){
        int a, b;
        cin >> a >> b;
        v[a].pb(b);
    }
    
    ll ans = 0;
    priority_queue<int> q;
    rep3(i, 1, m){
        for(auto b : v[i]){
            q.push(b);
        }
        if(!q.empty()){
            int now = q.top(); q.pop();
            ans += now;
        }
    }
    
    cout << ans << endl;
	return;
}

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

Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    long long x;

    cin >> N >> x;

    vector<long long> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    sort( A.begin(), A.end() );

    int ans = 0;
    long long s = 0;
    for ( int i = 0; i < N; i++ ) {
        if ( x >= A[i] ) {
            x -= A[i];
            ans++;
        }
        else { x = 0; break; } 
    }
    if ( x > 0 ) { ans--; }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

ll floor_sum(ll n, ll m, ll a, ll b){
    ll ans = 0;
    if(a >= m) {
        ans += (n-1)*n/2*(a/m);
        a %= m;
    }
    if (b >= m){
        ans += n*(b/m);
        b %= m;
    }
    ll y = (a*n+b)/m, x = (y*m - b);
    if(!y) return ans;
    ans += (n-(x+a-1)/a)*y;
    ans += floor_sum(y, a, m, (a - x%a)%a);
    return ans;
}


int main() {
    int t;
    cin >> t;
    while(t--) {
        ll n, m, a, b;
        scanf("%lld %lld %lld %lld", &n, &m, &a, &b);
        printf("%lld\n", floor_sum(n, m, a, b));
    }
    return 0;
}

Measured memory_bytes: 3776
def primeFactorize(n):
    fac = []
    if n < 2: return fac
    while n%2 == 0:
        n //= 2
        fac.append(2)
    for i in range(3,int(n**0.5)+1,2):
        while n%i == 0:
            n //= i
            fac.append(i)
    if n != 1: fac.append(n)
    return fac

n = int(input())
s = set()
ans = 0
x = 1
p = -1
for f in primeFactorize(n):
    if p != f: x = 1
    x *= f
    p = f
    if x not in s:
        ans += 1
        s.add(x)
        x = 1
print(ans)
# print(primeFactorize(n))
    



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

int main()
{
    string a;
    cin >> a;
    int p(0);
    while ((unsigned)p < a.size()) {
        if (p + 7 <= a.size() && (p + 7 == a.size() || a[p + 7] != 'a') && a[p] == 'd' && a[p + 1] == 'r' && a[p + 2] == 'e' && a[p + 3] == 'a' && a[p + 4] == 'm' && a[p + 5] == 'e' && a[p + 6] == 'r')
            p += 7;
        else if (p + 5 <= a.size() && a[p] == 'd' && a[p + 1] == 'r' && a[p + 2] == 'e' && a[p + 3] == 'a' && a[p + 4] == 'm')
            p += 5;

        else if (p + 6 <= a.size() &&  (p + 6 == a.size() || a[p + 6] != 'a') &&a[p] == 'e' && a[p + 1] == 'r' && a[p + 2] == 'a' && a[p + 3] == 's' && a[p + 4] == 'e' && a[p + 5] == 'r')
            p += 6;
        else if (p + 5 <= a.size() && a[p] == 'e' && a[p + 1] == 'r' && a[p + 2] == 'a' && a[p + 3] == 's' && a[p + 4] == 'e')
            p += 5;

        else {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		int a, b;
		String str;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		str = br.readLine();
		String[] line = str.split(" ");
		a = Integer.parseInt(line[0]);
		b = Integer.parseInt(line[1]);
		System.out.println(a * b + " " + (a + b) * 2);

	}

}



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

int main() {
	int N = 0;
	int x, y, b, p;
	int max = 0;
	int wari = 0;

	int i = 0;

	cin >> N;

	while (1) {
		cin >> x;
		cin >> y;
		cin >> b;
		cin >> p;

		max = ((x * b) + (y * p));

		if (b < 5){
			b = 5;
		}

		if (p < 2){
			p = 2;
		}


		wari = ((x * b) + (y * p)) * 0.8;

		if (max < wari) {
			cout << max << "\n";
		} else {
			cout << wari << "\n";
		}

		i++;

		if(i == N) {
			return 0;
		}
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
      string s; cin>>s;
      int sum=0;
      rep(i,0,s.ln){
         int d=s[i]-'0';
         sum+=d;
      }
    if(sum%9==0)cout<<"Yes\n";
    else cout<<"No\n";
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read question. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


Measured memory_bytes: 3752
n=int(input())
cnt=0

a,b,c=0,0,0
for i in range(n):
    s=input()
    cnt +=s.count("AB")
    if s[0]=="B" and s[-1]=="A":c +=1
    elif s[0]=="B":b +=1
    elif s[-1]=="A": a +=1

if a==0 and b==0:print(cnt+max(0,c-1))
else:print(cnt+min(a,b)+c)

Measured memory_bytes: 44008
// Should be correct.
// But still not very carefully tested.
#ifndef LOCAL
#define NDEBUG 1
#endif
#include<bits/stdc++.h>

bool ask(int one, int two){
	std::cout<<"? "<<one<<' '<<two<<std::endl;
	char c;std::cin>>c;
	return c=='Y';
}

std::vector<char> result; // 1: honest

void solve(std::vector<int> const& value){
	if(value.size()<=2){
		for(auto x: value) result[x]=true;
		return;
	}
	for(auto x: value) assert(result[x]==-1);

	std::vector<char> answer(value.size(), -1);
	std::vector<int> sub;
	for(int index=0;index+1<(int)value.size();index+=2) {
		if(
				(answer[index]=ask(value[index], value[index+1])) and
				(answer[index+1]=ask(value[index+1], value[index]))
				) sub.push_back(value[index]);
	}

	if(sub.size()%2==0) sub.push_back(value.back());

	assert(not sub.empty());
	solve(sub);

	for(int index=0;index+1<(int)value.size();index+=2) {
		if(answer[index]==1 and answer[index+1]==1){
			assert(value[index]!=-1);
			result[value[index+1]]=result[value[index]];
		}
	}

	std::sort(begin(sub),end(sub));
	auto good=*std::find_if(begin(sub),end(sub),[&](auto x){return result[x];});
	for(auto x: value) if(result[x]==-1)
		result[x]=ask(good, x);
}

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	int a, be; std::cin>>a>>be;
	if(a<=be){
		std::cout<<"Impossible\n";
		return 0;
	}
	
	result.assign(a+be, -1);

	std::vector<int> value(a+be);
	for(int i=0;i<(int)value.size();++i) value[i]=i;
	solve(value);

	std::cout<<"! ";
	for(char c: result) std::cout<<char(c+'0');
	std::cout<<'\n';
}


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

int     main() {
	int H, W;
	cin >>H >>W;
	vector<vector<int>> s(H+2, vector<int> (W+2, 10000));
	int SS=0;
	for (int i=1; i<=H; i++)
		for (int j=1; j<=W; j++) {
			char C;
			cin >>C;
			if ('.'==C) {
				s.at(i).at(j)=3000;
				SS++;
			}
		}
	s.at(1).at(1)=1;
	while(true) {
		bool found=false;
		for (int i=1; i<=H; i++)
			for (int j=1; j<=W; j++) {
				if (10000!=s.at(i).at(j)) {
					int V=s.at(i).at(j)-1;
					V=min(V, s.at(i-1).at(j));
					V=min(V, s.at(i+1).at(j));
					V=min(V, s.at(i).at(j-1));
					V=min(V, s.at(i).at(j+1));
					if (V+1<s.at(i).at(j)) {
						s.at(i).at(j)=V+1;
						found=true;
					}
				}
			}
		if (!found)
			break;
	}
	if (3000==s.at(H).at(W)) {
		cout <<-1 <<endl;
	} else {
		cout <<SS-s.at(H).at(W) <<endl;
	}
	return 0;
};


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

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

    int num = 1;
    char prev = s.at(0);
    for (int i = 1; i < n; i++)
    {
        if (prev != s.at(i))
        {
            num++;
            prev = s.at(i);
        }
    }

    cout << num << endl;
}

Measured memory_bytes: 512
L = int(input())

bL = bin(L)[2:]

l = len(bL)

edges = []

for i in range(1,l):
    edges.append([i, i+1, 0])
    edges.append([i, i+1, 2**(i-1)])

w = 2**(l-1)
    
for idx, a in enumerate(bL):
    if idx == 0:
        continue
    if a == '0':
        continue
    n = l - idx
    edges.append([n, l, w])
    w += 2**(n-1)

print(l, len(edges))

for e in edges:
    print(e[0], e[1], e[2])


Measured memory_bytes: 3064
#include <string>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

long long int gcd (long long int n, long long int m)
{
    long long int maxn = max(n,m);
    long long int minn = min(n,m);
    if (maxn % minn == 0) {
        return minn;
    }
    return gcd(minn, maxn % minn);
}

long long int lcm (long long int n, long long int m)
{
    long long int lcmn = gcd(n, m);
    return n * m / lcmn;
}
int main ()
{
    long long int n , m;
    string s, t;
    cin >> n >> m >> s >> t;
    long long int l = lcm(n,m);
    long long int f = lcm(l/n, l/m);
    bool good_str = true;
    long long int comp_rate_s = l / n;
    long long int comp_rate_t = l / m;
    long long int gcdn = gcd(n,m);
    long long int itr_judge = lcm(n / gcdn, m / gcdn);
    for (int i = 0; i < n; ++i) {
        if (i * comp_rate_s % itr_judge == 0) {
            if (s[i] != t[i * m / n]) {
                good_str = false;
                break;
            }
        }
    }
    cout << (good_str ? l : -1);
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(c: "List[List[int]]"):
    if (c[0][1] - c[0][0] == c[1][1] - c[1][0] and
        c[0][1] - c[0][0] == c[2][1] - c[2][0] and
        c[0][2] - c[0][1] == c[1][2] - c[1][1] and
        c[0][2] - c[0][1] == c[2][2] - c[2][1] and
        c[1][0] - c[0][0] == c[1][1] - c[0][1] and
        c[2][0] - c[1][0] == c[2][1] - c[1][1]):
        ret = YES
    else:
        ret = NO
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    c = [ [ int(next(tokens)) for _ in range(3) ] for _ in range(3) ]  # type: "List[List[int]]"
    solve(c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
int main()
{
    char s[MAXN];
    cin >> s;
    ll cnt = 0;
    for(ll i = 0; i < strlen(s); i++) cnt += s[i] - '0';
    if(cnt % 9 == 0) cout << "Yes";
	else cout << "No"; 
    return 0;
}

Measured memory_bytes: 3740
BIG_NUM = 2000000000

N = int(input())

table = list(map(int,input().split()))

maximum = -BIG_NUM
minimum = BIG_NUM
total = 0

for y in table:
    if maximum < y:
        maximum = y
    if minimum > y:
        minimum = y
    total += y

print("%d %d %d"%(minimum,maximum,total))



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

using namespace std;

using int64 = long long;


int main()
{
  int S[3][3];
  for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
      cin >> S[i][j];
    }
  }

  for(int a_1 = 0; a_1 <= S[0][0]; a_1++) {
    for(int a_2 = 0; a_2 <= S[1][1]; a_2++) {
      for(int a_3 = 0; a_3 <= S[2][2]; a_3++) {
        int x[] = {a_1, a_2, a_3};
        int y[] = {S[0][0] - a_1, S[1][1] - a_2, S[2][2] - a_3};

        if([&]()
        {

          for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
              if(x[i] + y[j] != S[i][j]) return(false);
            }
          }
          return(true);
        }()) {
          cout << "Yes" << endl;
          return(0);
        }
      }
    }

  }
  cout << "No" << endl;
}


Measured memory_bytes: 256