akhauriyash/Code-Regression huggingface dataset:
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    
    let mut xs: Vec<&[u8]> = vec![];
    
    for _ in 0..n {
    	let x = get().as_bytes();
        if let Some(&y) = xs.last() {
        	if x[0] != y[y.len() - 1] {
            	println!("No");
                return;
            }
        }
        for &y in xs.iter() {
        	if x == y {
            	println!("No");
                return;
            }
        }
        xs.push(x);
    }
    
    println!("Yes");    
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

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

	for (long long int a = 1; a <= 3500; a++)
	{
		for (long long int b = a; b <= 3500; b++)
		{
			if ((4 * a * b - n * b - n * a) > 0 && (n * a * b) % (4 * a * b - n * b - n * a) == 0)
			{
				cout << a << " " << b << " " << (n * a * b) / (4 * a * b - n * b - n * a) << endl; 
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
// created on : Sun Jun 21 2020
 
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        long sum = 0;
        HashMap<Long, Long> map = new HashMap<>();
        for(int i = 0; i < n; i++){
            long num = in.nextLong();
            map.put(num, map.getOrDefault(num, 0L) + 1);
            sum += num;
        }

        int q = in.nextInt();
        while(q-->0){
            long b = in.nextLong();
            long c = in.nextLong();

            if(map.containsKey(b)){
                // remove all b
                long count = map.get(b);
                sum -= b * count;
                sum += c * count;
                map.remove(b);
                
                // update count of c
                map.put(c, map.getOrDefault(c, 0L) + count);
            }
            println(sum);
        }
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static int[] readInt(int N) throws IOException { 
    	int arr[] = new int[N];
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    	return arr;
    }
    
    static long[] readLong(int N) throws IOException { 
    	long arr[] = new long[N];
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    	return arr;
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i] + " "); 
    	} 
    	println(""); 
    }
    
    static void displayRuntime(long startTime){
        long stopTime = System.currentTimeMillis();
        long elapsedTime = stopTime - startTime;
        System.out.println("Runtime: " + elapsedTime / 1000D);
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dij geo2 kruskal graph uf lca BIT

int calc(int b, int n)
{
    if (n) {
        return calc(b, (n / b)) + (n % b);
    } else {
        return 0;
    }
}

signed main()
{
    int2(n, s);
    int ans = INF;
    if (n == s) {
        ans = n+1;
    }
    for (int i = 2; i * i <= n; i++) {
        if (calc(i, n) == s) {
            ans = min(ans, i);
        }
    }
    //std::cout << "OK" << std::endl;
    for (int i = 1; i * i <= n; i++) {
        int b = (n - s) / i + 1;
        if (b < 2) continue;
        if (calc(b, n) == s) {
            ans = min(ans, b);
        }
    }

    if (ans == INF) {
        std::cout << -1 << std::endl;
    } else {
        std::cout << ans << std::endl;
    }

    return 0;
}


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

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

int main(){
  int N;
  cin >> N;
  int total = findSumOfDigits(N);
  if(N % total == 0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
ll n,w,wi[105],vi[105],dp[100005],ans;
int main(){
   cin>>n>>w;
   for(ll i=1;i<=n;i++) cin>>wi[i]>>vi[i];
   for(ll i=1;i<=100000;i++) dp[i]=1000000001;
   for(ll i=1;i<=n;i++){
      for(ll j=100000;j>=vi[i];j--){
         dp[j]=min(dp[j],dp[j-vi[i]]+wi[i]);
         if(dp[j]<=w) ans=max(ans,j);
      }
   }
   cout<<ans;
   return 0;
}

Measured memory_bytes: 4360
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int n, k;
ll ans;
vvi adj;

void dfs(int u, int p) {
	int avail = k - 2;
	if(p == -1) avail++;
	for(int i : adj[u]) {
		if(i == p) continue;
		ans *= avail;
		ans %= P;
		avail--;
		dfs(i, u);
	}
}

void solve() {
	cin >> n >> k;
	
	adj.resize(n);
	for(int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		
		adj[a].pub(b);
		adj[b].pub(a);
	}
	
	ans = k;
	dfs(0, -1);
	
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 13484
S = sorted(list(input()))
T = sorted(list(input()))

for s in S:
    for t in T:
        if s < t:
            print("Yes")
            exit(0)
else:
    for s in S:
        if s not in T:
            print("No")
            break
    else:
        if len(S) < len(T):
            print("Yes")
        else:
            print("No")


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

int main() {
  int a,b;
  cin >> a >> b;
  if((a+b)%2 == 0) cout << (a+b)/2 << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD=1e9+7;

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

  ll n,a,b;cin>>n>>a>>b;
  std::vector<ll> h(n);
  for(int i=0;i<n;i++) cin>>h[i];
  sort(h.begin(),h.end());
  ll low=0,high=1e9+1;
  for(int i=0;i<30;i++){
      ll mid=(high+low)/2;
      ll res=0;
      for(int j=0;j<n;j++){
          if(h[j]<=b*mid)continue;
          else{
              res+=((h[j]-b*mid-1)/(a-b)+1);
          }
      }
      if(res<=mid) high=mid;
      else low=mid;
  }
  cout<<high<<endl;
}


Measured memory_bytes: 1024
var
  s:string;
  i,l,a,b:longint; 
begin
  readln(s);
  l:=length(s);
  a:=maxlongint; 
  for i:=l downto 1 do 
    if s[i]='F'then 
    begin
      b:=i;
      break;
    end;
  for i:=1 to l do 
    if s[i]='C'then 
    begin
      a:=i;
      break;
    end;
  if a<b then writeln('Yes')
           else writeln('No'); 
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// string q=s.insert(0,str);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	int n;
	cin>>n;
	if(n%1000==0)
	{
		cout<<0<<endl;
	}	
	else
	{
		int x = (n/1000)+1;
		cout<<x*1000-n<<endl;
	}
}

Measured memory_bytes: 3608
#include <stdio.h>

int main( void ) {
	int n, num_d, d[ 10 ];

	while ( scanf( "%d", &n ), n >= 0 ) {
		num_d = 0;
		do {
			d[ num_d++ ] = n % 4;
		} while ( n /= 4 );

		while ( num_d-- )
			printf( "%d", d[ num_d ] );
		putchar( '\n' );
	}

	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << max(A * B, C * D) << endl;
    return 0;
}


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

int main() {
    lnt N;
    cin>>N;
    vector<lnt>A(N);
    rep(i,N){
        cin>>A[i];
    }
    sort(A.rbegin(),A.rend());

    lnt ans = -A[0];
    if(N%2 == 0){
        rep(i,N/2){
            ans += 2*A[i];
        }
    }
    else{
        rep(i,(N-1)/2){
            ans += 2*A[i];
        }
        ans += A[(N-1)/2];
    }
    cout << ans<< endl;
}


Measured memory_bytes: 4768
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m;
ll a[200010];
ll l,r,mid,cnt0;
vector<ll> pos,neg;
ll ps,ng;
bool check()
{
	if (!mid)
	{
		//cout <<cnt0*(cnt0-1)/2+cnt0*(n-cnt0)<<" "<<m-ps*ng<<" ----------------\n";
		return cnt0*(cnt0-1)/2+cnt0*(n-cnt0)>=m-ps*ng;
	}
	ll res=0,li,ri,midi;
	if (mid<0)
	{
		for (int i=0;i<ps;i++)
		{
			li=0,ri=ng;
			while (li<ri)
			{
				midi=(li+ri)/2;
				//cout <<li<<" "<<ri<<" "<<midi<<" ##\n";
				if (neg[midi]*pos[i]>mid) ri=midi;
				else li=midi+1;
			}
			//cout <<li<<" #\n";
			res+=li;
		}
		//cout <<mid<<" "<<res<<" ##\n";
		return res>=m;
	}
	else
	{
		for (int i=0;i<ps-1;i++)
		{
			li=i+1,ri=ps-1;
			while (li<ri)
			{
				midi=(li+ri)/2;
				if (pos[midi]*pos[i]>mid) ri=midi;
				else li=midi+1;
			}
			if (pos[li]*pos[i]>mid) li--;
			//cout <<pos[i]<<" "<<li-i<<" ##\n"; 
			res+=li-i;
		}
		//cout <<res<<" ##\n";
		for (int i=0;i<ng-1;i++)
		{
			li=i+1,ri=ng-1;
			while (li<ri)
			{
				midi=(li+ri)/2;
				if (neg[midi]*neg[i]>mid) li=midi+1;
				else ri=midi;
			}
			if (neg[li]*neg[i]>mid) li++;
			//cout <<neg[i]<<" "<<li-i<<" ##\n"; 
			res+=ng-li;
		}
		ll mi=m-ps*ng-cnt0*(cnt0-1)/2-cnt0*(n-cnt0);
		//cout <<mid<<" "<<mi<<" "<<res<<" ##\n";
		return res>=mi;
	}
} 
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++)
	{
		cin >>a[i];
		if (!a[i]) cnt0++;
		else if (a[i]>0) pos.push_back(a[i]);
		else neg.push_back(a[i]);
	}
	ps=pos.size(),ng=neg.size();
	sort(pos.begin(),pos.end());
	sort(neg.begin(),neg.end());
	l=-1e18,r=1e18;
	while (l<r)
	{
		mid=(l+r+(l+r<0 ? -1 :0))/2;
		//cout <<l<<" "<<r<<" "<<mid<<" ##########\n"; 
		if (check()) r=mid;
		else l=mid+1;
	}
	cout <<l;
	return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>     
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  long long ans = 0;
  int s = 0;
  mp[0] = 1;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    s += a;
    s %= m;
    ans += mp[s];
    mp[s]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i,n) for (int i=0; i < int(n); i++)
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	cout << '\n';
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	cout << '\n';
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	cout << '\n';
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) * b;
	//a*bは64bit integer overflow
}

bool integer(double num) {
	return floor(num) == num;
}

Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	IOS;
	int n;
	cin >> n;
	map<string, int> data;
	for (int i = 0; i < n;i++){
		string s;
		cin >> s;
		ssort(s);
		data[s]++;
	}
	Int ans=0;
	for (auto temp:data){
		Int num = temp.second;
		ans += num * (num - 1) / 2;
	}
	cout << ans;

	cout << endl;
	return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


Measured memory_bytes: 11264
# -*- coding: utf-8 -*-
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a_s = [list(map(int, input().split())) for i in range(n)]

correct = 0
for a in a_s:
    val = c
    for _a, _b in zip(a, b):
        val += _a * _b

    correct += 1 if val > 0 else 0

print(correct)


Measured memory_bytes: 3060
total = 0
a = int(input())
f = [];
g = [];
for i in range(a):
    b, c = map(str, input().split())
    c = int(c)
    f.append(b)
    g.append(c)
e = input()
h = f.index(e)
j = len(f)
for i in range(j-h-1):
    total += int(g[h+i+1])
print(total)


Measured memory_bytes: 3060
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    int data[] = new int[n];
    int x = 0;
    int y = 0;

    for(int i=0 ; i<n ; i++){
      a[i] = sc.nextInt();
    }
    for(int i=0 ; i<n ; i++){
      if(a[i]%2==0){
        x++;
        if(a[i]%3==0 || a[i]%5==0){
          y++;
        }
      }
    }
    
    if(x==y){
      System.out.println("APPROVED");
    }else{
      System.out.println("DENIED");
    }
  }
}


Measured memory_bytes: 22100
from itertools import permutations

n  = int(input())
a, b = [int(x) for x in input().split(' ')]
p = sorted([int(x) for x in input().split(' ')])

p_easy = len([x for x in p if x<=a])
p_normal = len([x for x in p if a<x<=b])
p_hard = len([x for x in p if b<x])

print(min(p_easy,p_normal,p_hard))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int k,t;
    cin>>k>>t;
    int a[109];
    for( int i=1;i<=t;i++) cin>>a[i];
    sort(a+1,a+t+1);
    int ans=a[t]-1;
    for(int i=t-1;i>=1;i--) ans=ans-a[i];
    cout<<max(ans,0);
}


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

int main() {
	int h, w, k;
	cin >> h >> w >> k;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	int ans = 1001001001;
	for(int bit = 0; bit < (1 << h-1); bit++) {
		int split = 0;
		vector<int> id(h);
		rep(i, h) {
			id[i] = split;
			if(bit>>i & 1) split++;
		}
		int tmp = split;
		vector<int> sp(split+1);
		bool ok = true;
		rep(j, w) {
			vector<int> now(split+1);
			bool is_split = false;
			rep(i, h) {
				if(s[i][j] == '1') sp[id[i]]++, now[id[i]]++;
				if(now[id[i]] > k) {
					ok = false;
					break;
				}
				if(sp[id[i]] > k) {
					// jで縦に分割
					is_split = true;
				}
				
			}
			if(!ok) break;
			if(is_split) {
				sp = now;
				tmp++;
			}
		}
		if(!ok) continue;
		
		ans = min(ans, tmp);
	}
	
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys

# sys.stdin = open('d1.in')

n, m = map(int, input().split())
weights = {}
for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    weights[(a, b)] = c

score = [-10 ** 50] * n
score[0] = 0
pred = [-1] * n
for i in range(n):
    for edge, c in weights.items():
        a, b = edge
        if score[b] < score[a] + c:
            score[b] = score[a] + c
            pred[b] = a
res = score[n - 1]

b = n - 1
while b != 0:
    a = pred[b]
    c = weights[(a, b)]
    if score[b] < score[a] + c:
        res = 'inf'
        break
    b = a

print(res)


Measured memory_bytes: 3572
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
      //日数
      int n = sc.nextInt();
      //基準泊数
      int k = sc.nextInt();
      //k泊目までの料金
      int x = sc.nextInt();
      //k+1泊目以降の料金
      int y = sc.nextInt();
      
      int total = 0;
      
      for(int i = 1;i <= n;i++){
        if(i <= k){
          total += x;
        }else{
          total += y;
        }
      }
      
      System.out.println(total);
	}
}


Measured memory_bytes: 35340
X=input()
Xi=int(X)
if Xi>=100:
    if len(X)>=4 and Xi>=2000:
        print(1)
    else:
        if Xi<1000:
            print(1 if int(X[0])*5>=int(X[1:3]) else 0)
        else:
            print(1 if int(X[0:2])*5>=int(X[2:4]) else 0)
else:
    print(0)

Measured memory_bytes: 3060
import numpy as np

A=[list(map(int, input().split())) for _ in range(3)]
N=int(input())
B=[int(input()) for _ in range(N)]

for b in B:
	for i in range(3):
		for j in range(3):
			if A[i][j]==b:A[i][j]=0
			
ans_axis0=np.sum(np.array(A),axis=0)
ans_axis1=np.sum(np.array(A),axis=1)
ans_naname=[A[0][0]+A[1][1]+A[2][2],A[0][2]+A[1][1]+A[2][0]]

#print(A,ans_axis0,ans_axis1,ans_naname)

if 0 in ans_axis0 or 0 in ans_axis1 or 0 in ans_naname:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 26836
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    string s;
    cin >> s;
    int flag = 0;
    rep(i,3)if(s[i] == '7')flag = 1;
    if(flag)yn;
    return 0;
}
 
 


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
int main(){
    int N,res = 0;
    cin >> N;
    vector<int> value(N),cost(N),ans(N);
    rep(i,N){
        cin >> value[i];
    }
    rep(i,N){
        cin >> cost[i];
    }
    rep(i,N){
        ans[i] = value[i] - cost[i];
    }
    rep(i,N){
        if(ans[i] >= 0)
        res += ans[i];
        else
        {
            res += 0;
        } 
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
   
   ll n;
   cin>>n;
   ll a[(n+1)];
   memset(a,0,sizeof(a));
   for(int i=1;i<n;i++)
   {
       ll x;
       cin>>x;
       a[x]++;
   }
   for(int i=1;i<=n;i++)
   {
        cout<<a[i]<<endl;
   }
}
return 0;
}

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

int main() {
	string s;
	cin >> s;
	int ans = 0;
	rep(i, s.size()){
		if(s[i] == '+'){
			ans++;
		}else{
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
#define MAXN 99999
int Query(int ans){
    char ret[20];
    printf("%d\n", ans);
	fflush(stdout);
    scanf("%s", ret);
    if(ret[0] == 'V') exit(0);
    return ret[0] == 'M' ? 1 : 0;
}
int n;
int a[MAXN+5];
int main()
{
	scanf("%d",&n);
	int l=0,r=n-1;
	int ls=Query(l);
	int rs=Query(r);
	while(1)
	{
		int mid=(l+r)/2;
		int ms=Query(mid);
		if(((mid-l)&1)==(ms!=ls))
			l=mid,ls=ms;
		else r=mid;
	}
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
LL lcm(LL a,LL b){
	return a*b/__gcd(a,b);
}
int main(){
	LL a,b;
	while(scanf("%lld %lld",&a,&b)!=EOF){
		printf("%lld %lld\n",__gcd(a,b),lcm(a,b));
	}
}

Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {
    

    unsigned long long h, w, h1, h2, w1, w2, ans;
    cin >> h >> w ;

    h1 = floor((double)h/2);
    h2 = ceil((double)h/2);
    w1 = floor((double)w/2);
    w2 = ceil((double)w/2);


    ans = (unsigned long long)h1*w1 + (unsigned long long)h2*w2;

    if(h==1 || w==1){
        ans = 1;
    }
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1), b(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  int ret = 0;
  for (int i = 1; i <= n; i++) {
    ret = max(ret, a[i] + b[n] - b[i - 1]);
  }
  cout << ret << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main()
{
   IOS;
   //freopen("inputfile.txt","r",stdin);
   ll n;cin>>n;
   map<ll,ll> ma;
   for(ll i=0;i<n-1;i++)
   {
       ll x;cin>>x;
       ma[x]++;
   }
   for(ll i=1;i<=n;i++)
   {
       cout<<ma[i]<<endl;
   }
    return 0;
}
//<!...........ALHAMDULILLAH.............!!>>



Measured memory_bytes: 16144
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD 1000000007
using namespace std;

int main(){
ll N;
cin>>N;
vector<pair<double,double>> en(N);
vector<double> arg(N);
double tmp,tmp1;
for(int i=0;i<N;i++){
  cin>>tmp>>tmp1;
  en[i]=make_pair(tmp,tmp1);
}

double max =0;
for(int i=0;i<360;i++){
  double tarx = cosf(i);
  double tary = sinf(i);
  double tx=0;
  double ty=0;
  for(int j=0;j<N;j++){
      if((tarx*en[j].first+tary*en[j].second)>0){
        tx+=en[j].first;
        ty+=en[j].second;
      }
  }
double tans = sqrt(tx*tx+ty*ty);
if(max<tans){
  max = tans;
}

}


printf("%.20f",max);


}


Measured memory_bytes: 384
#include<iostream>


using namespace std;

int main(){
   int N,K;
 cin >> N >> K;
   int sum =1;
   for(int i=0;i<N;i++){
       if(sum*2>=(sum+K)){
           sum =sum+K;
       }
       else{
           sum=sum*2;

       }
   }
cout<<sum<<endl;

}
  

Measured memory_bytes: 3560
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		String S = sc.nextLine();

		int a = Integer.parseInt(S.substring(0, 2));
		int b = Integer.parseInt(S.substring(2, 4));

		if(1 <= a && a <= 12) {
			if(1<= b && b <= 12) {
				System.out.println("AMBIGUOUS");
			}else {
				System.out.println("MMYY");
			}
		}else {
			if(1<= b && b <= 12) {
				System.out.println("YYMM");
			}else {
				System.out.println("NA");
			}
		}
	}
}


Measured memory_bytes: 25172
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>

using namespace std;

int N, C;
int ruisekiwa[30][200001];


int main() {
	cin >> N >> C;
	for (int i = 0; i < N; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		ruisekiwa[c - 1][a * 2 - 1] ++, ruisekiwa[c - 1][b * 2]--;
	}
	int ans = 0;
	for (int i = 1; i <= 200000; i++) {
		int h = 0;
		for (int j = 0; j < C; j++) {
			ruisekiwa[j][i] += ruisekiwa[j][i - 1];
			if (ruisekiwa[j][i] > 0)h++;
		}
		ans = max(ans, h);
	}
	cout << ans << endl;
	return 0;
}

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

//int _; 

int x;

int main()
{
	//for(scanf("%d",&_);_;_--)
	cin >> x;
	for(int i=0;i<1000;i++)
		for(int j=0;j<1000;j++)
		{
			for(int k=0;k<3;k++)
			{
				if(k == 1)
					i=-i;
				if(k == 2)
					j=-j;
				if(i*i*i*i*i-j*j*j*j*j == x)
				{
					cout << i << ' ' << j << endl;
					return 0;
				}
				i=abs(i);
				j=abs(j);
			}
		} 	
	return 0;
}

Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class GFG
{
    static public void Main()
    {
        try
        {

            var input1 = Console.ReadLine().Split(' ');
            var n = int.Parse(input1[0]);
            var k = int.Parse(input1[0]);
            var aar = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();

            IrohaObsession(n, k, aar);
        }
        catch (Exception ex)
        {
            Console.Write(ex);
        }
    }

    static void IrohaObsession(int n, int k, int[] digit)
    {

        bool[] D = new bool[10];
        for (int i = 0; i < digit.Length; i++)
        {
            D[digit[i]] = true;
        }


        int ans = int.MaxValue;
        List<int> permutation = new List<int>();
        GetPermutation(D, 0, 0, permutation);
        foreach (var v in permutation)
        {
            if (v >= n)
            {
                ans = Math.Min(ans, v);
            }
        }

        Console.WriteLine(ans);
    }

    static void GetPermutation(bool[] D, int level, int curr, List<int> permutation)
    {
        if (level == 6)
        {
            return;
        }
        permutation.Add(curr);

        for (int i = 0; i < 10; i++)
        {
            if (D[i])
            {
                continue;
            }
            GetPermutation(D, level + 1, curr * 10 + i, permutation);
        }
    }


}

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

    int n; cin >> n;
    int a[n], b[n], c[n];
    for( int i = 0 ; i < n ; ++i ){
        cin >> a[i];
    }
    for( int i = 0 ; i < n ; ++i ){
        cin >> b[i];
    }
    for( int i = 0 ; i < n ; ++i ){
        cin >> c[i];
    }
    sort( a, a+n );
    sort( b, b+n );
    sort( c, c+n );
    reverse( a, a+n );
    reverse( b, b+n );
    reverse( c, c+n );
    int j = 0;
    long long ans[n];
    for( int i = 0 ; i < n ; ++i ){
        while( j < n && c[j] > b[i] ){
            j++;
        }
        ans[i] = j;
    }
    j = 0;
    long long r = 0, sum = 0;
    for( int i = 0 ; i < n ; ++i ){
        while( j < n && b[j] > a[i] ){
            sum+=ans[j];
            j++;
        }
        r+=sum;
    }
    cout << r << '\n';
}


Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;

int main(void)
{
    int ans = 0;

    int n;
    scanf("%d", &n);

    char s[n];
    scanf("%s", s);

    for (int i = 1; i < n; i++)
        if (s[i - 1] != s[i])
            ans++;

    printf("%d\n", ans + 1);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
using Graph=vector<vector<int>>;
int main() {
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  double time=60*h+m;
  double pi = 3.141592653589793;
  double ah=(time*360)/720;
  double bh=(m*360)/60;
  double x=abs(ah-bh);
  if(x>=180){
    x=360-x;
  }
  double y=180;
  double t=a*a+b*b-2*a*b*cos(pi/(y/x));
  cout<<fixed<<setprecision(13);
  cout<<sqrt(t)<<endl;
}


Measured memory_bytes: 4180
import sys

def read_int():
    l = sys.stdin.readline().rstrip('\n').split(' ')
    return int(l[0])

def read_int_list():
    l = sys.stdin.readline().rstrip('\n').split(' ')
    return [int(i) for i in l]

N = read_int()
A = read_int_list()

all_xor = 0                                                                                           

for a in A:                                                                                           
    all_xor ^= a                                                                                      

for a in A:                                                                                           
    print(all_xor ^ a)                                                                                



Measured memory_bytes: 31616
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int arr[] = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            Arrays.sort(arr);
            if (arr[n - 1] - arr[0] > 1) {
                out.println("No");
                return;
            } else if (arr[0] == arr[n - 1]) {
                if (arr[0] == n - 1 || n >= 2 * arr[0])
                    out.println("Yes");
                else
                    out.println("No");
                return;
            }
            int x = 0;
            for (int i = 0; i < n; i++) {
                if (arr[i] == arr[0])
                    x += 1;
            }
            if (x < arr[n - 1] && n >= 2 * (arr[n - 1]) - x)
                out.println("Yes");
            else
                out.println("No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 33756
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		ArrayList<Integer> listA = new ArrayList<Integer>();
		
		listA.add(a);
		listA.add(b);
		listA.add(c);

		
		Collections.sort(listA);

		//最大の数から素数を探す
		int tmp =  listA.get(2) * 10 + listA.get(1);
		int ans = tmp + listA.get(0);

		System.out.println(ans);
   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 23124
list = input().split(' ')

OPERATOR = {
  '+': lambda a, b: a + b,
  '*': lambda a, b: a * b,
  '-': lambda a, b: a - b,
  '/': lambda a, b: a / b,
}

stack = []
for item in list:
  if item in OPERATOR:
    b = stack.pop()
    a = stack.pop()
    stack.append(OPERATOR[item](a, b))
  else:
    stack.append(int(item))

print(stack.pop())



Measured memory_bytes: 5600
#include<stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int main(){
  int i;
  int num[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
  int m,d,ans;
 
  while(scanf("%d %d",&m,&d) && (m||d)){
    ans = 0;
    for(i=0;i<m-1;i++)ans += num[i];
    ans+=d;
    if(ans%7==0)printf("Wednesday\n");
    if(ans%7==1)printf("Thursday\n");
    if(ans%7==2)printf("Friday\n");
    if(ans%7==3)printf("Saturday\n");
    if(ans%7==4)printf("Sunday\n");
    if(ans%7==5)printf("Monday\n");
    if(ans%7==6)printf("Tuesday\n");
  }
  return 0;
}


Measured memory_bytes: 1968
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        s: chars,
    };
     println!("{}", 700 + s.iter().filter(|&&c| c == 'o').count() * 100);
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		double sum = 0;
		for(int i = 0; i < N; i++) {
			double A = stdIn.nextInt();
			sum += 1/A;
		}
		
		System.out.println(1/sum);

	}

}

Measured memory_bytes: 21844
open System

[<EntryPoint>]
let main args =
    let N  = Console.ReadLine () |> int

    let Ai = Console.ReadLine ()
             |> fun s -> s.Split(' ')
             |> Seq.map int

    let M1 = Ai
             |> Seq.zip [ 0 .. N ]
             |> Seq.sumBy (fun (i, e) -> e * (if i % 2 = 0 then 1 else -1))

    let Mi = Ai
             |> Seq.scan (fun Mb a -> 2 * a - Mb) M1
             |> Seq.take N
    
    Mi
    |> Seq.map string
    |> String.concat " "
    |> printfn "%s"

    0

Measured memory_bytes: 42944
#include<stdio.h>
#include<math.h>

int main() {
	long long n;
	int ans = 0;
	scanf("%lld", &n);

	for (int i = 2; i <= sqrt(n); i++) {
		long long pow = i;
		while (n%pow==0) {
			n /= pow;
			ans++;
			pow *= i;
		}
		while (n % i == 0) {
			n /= i;
		}
	}
	if (n != 1) ans++;

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 2120
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define RREP(i,n) for(int i=(n)-1; i>=0; --i)
#define SREP(i,s,n) for(int i=(s), i##_len=(n); i<i##_len; ++i)

using namespace std;
typedef long long int ll;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool comp(pair<int, int> a, pair<int, int> b) {
    return a.second > b.second;
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

ll f(ll b, ll n) {
    if (n < b) return n;
    return f(b, n/b) + n%b;
}

int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll M, D;
    cin >> M >> D;
    
    ll cnt = 0;
    SREP(m,1, M+1) {
        SREP(d,1, D+1) {
            int d1 = d%10;
            int d10 = d/10;
            if (d1>=2 && d10 >=2 && m == d1*d10) cnt++;
        }
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

template <class T>inline bool chmin(T &a, const T b){
    if(a > b){a = b; return true;}
    return false;
}

template <class T>inline bool chmax(T &a, const T b){
    if(a < b){a = b; return true;}
    return false;
}

int main(){
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<ll> dp(N, 1000);
    rep(i, N){
        if(i > 0) chmax(dp[i], dp[i - 1]);
        ll stock = dp[i] / A[i];
        ll money = dp[i] % A[i];
        rep(j, N){
            chmax(dp[j], money + stock * A[j]);
        }
    }
    cout << dp[N - 1] << endl;
} 

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

int main() {
	int A , B;
  	string op;
  	cin >> A >> op >> B ;
  	if(op == "+"){
    	cout << A + B << endl;
    }else if(op == "-"){
    	cout << A - B << endl;
    }
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int D; //365
    cin >> D;
    int c[26];
    rep(i, 0, 26) {
        cin >> c[i];
    }
    int s[D][26];
    rep(i, 0, D) {
        rep(j, 0, 26) {
            cin >> s[i][j];
        }
    }
    int t[D];
    rep(i, 0, D) {
        cin >> t[i];
        t[i]--;
    }
    ll score[D] = {};
    vector<int> last_day(26, -1);
    rep(i, 0, D) {
        if (i != 0) score[i] = score[i - 1];
        score[i] += s[i][t[i]];
        last_day[t[i]] = i;
        int decrease = 0;
        rep(j, 0, 26) {
            decrease += c[j] * (i - last_day[j]);
        }
        score[i] -= decrease;
    }
    rep(i, 0, D) {
        cout << score[i] << endl;
    }
    return 0;
}


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

int main() {
  string S;
  int N,Q;
  cin>>N>>S>>Q;
  for(int i=0;i<Q;i++){
    int k;
    cin>>k;
    int64_t D=0,M=0,dm=0,Z=0;
    for(int i=0;i<N;i++){
      if(i-k>=0){
        if(S[i-k]=='M'){
          M--;
        }
        if(S[i-k]=='D'){
          D--;
          dm-=M;
        }
      }
      if(S[i]=='D'){
        D++;
      }
      if(S[i]=='M'){
        M++;
        dm+=D;
      }
      if(S[i]=='C'){
        Z+=dm;
      }
    }
    cout<<Z<<endl;
  }
}



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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

struct Edge{
	int src,dst,weight;
	Edge(){}
	Edge(int s,int d,int w):src(s),dst(d),weight(w){}
};
typedef vector<vector<Edge>> Graph;

void chmin(int& a,int b)
{
	a=min(a,b);
}

int main()
{
	for(int n,m,s;cin>>n>>m>>s && n|m|s;){
		Graph g(n);
		rep(i,m){
			int u,v,w; cin>>u>>v>>w;
			g[u].emplace_back(u,v,w);
			g[v].emplace_back(v,u,w);
		}
		vi cs(s);
		rep(i,s) cin>>cs[i];
		
		vvi dp(n,vi(n,INF));
		rep(i,n) dp[i][i]=0;
		rep(i,n) for(auto e:g[i]) chmin(dp[e.src][e.dst],e.weight);
		rep(k,n) rep(i,n) rep(j,n) chmin(dp[i][j],dp[i][k]+dp[k][j]);
		
		vd cnt1(n,0); cnt1[0]=1;
		{
			Graph gg(n);
			rep(i,n) for(auto e:g[i]) if(dp[0][e.src]+e.weight+dp[e.dst][n-1]==dp[0][n-1])
				gg[e.src].push_back(e);
			vi is(n); iota(all(is),0);
			sort(all(is),[&](int i,int j){return dp[0][i]<dp[0][j];});
			for(auto u:is) for(auto e:gg[u]) cnt1[e.dst]+=cnt1[u];
		}
		vd cnt2(n,0); cnt2[n-1]=1;
		{
			Graph gg(n);
			rep(i,n) for(auto e:g[i]) if(dp[0][e.src]+e.weight+dp[e.dst][n-1]==dp[0][n-1])
				gg[e.dst].emplace_back(e.dst,e.src,e.weight);
			vi is(n); iota(all(is),0);
			sort(all(is),[&](int i,int j){return dp[n-1][i]<dp[n-1][j];});
			for(auto u:is) for(auto e:gg[u]) cnt2[e.dst]+=cnt2[u];
		}
		
		for(auto i:cs) printf("%.9f\n",cnt1[i]*cnt2[i]/cnt1[n-1]); puts("");
	}
}

Measured memory_bytes: 1520