akhauriyash/Code-Regression huggingface dataset:
// -*- coding:utf-8-unix -*-

use std::cmp::*;
use std::collections::*;
use std::fs::File;
use std::io::prelude::*;
use std::io::*;
use std::vec;

const INF: i64 = 1223372036854775807;
const MEM_SIZE: usize = 202020;
const MOD: i64 = 1000000007;
use std::cmp::*;
use std::collections::*;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(unused_macros)]
macro_rules! p {
    ([$($x:expr), *]) => {{
        let mut f = true;
        $(
            print!("{}{}", if f {""} else {" "}, $x);
            f = false;
        )*
78786    print!("\n");
    }};
    ($x:expr) => {{
        let mut f = true;
        for a in $x.iter() {
            print!("{}{}", if f {""} else {" "}, a);
            f = false;
        }
        print!("\n");
    }};
}
#[allow(dead_code)]
fn readii() -> (i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}
#[allow(dead_code)]
fn readuu() -> (usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[allow(dead_code)]
fn readuuu() -> (usize, usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn solve() {
    let s: String = read();
    let mut v = s.as_bytes().to_vec();
    let mut res: usize = 0;
    for i in 0..s.len() {
        if (i % 2 == 0) {
            if (v[i] == 'p' as u8) {
                res -= 1;
            }
        } else {
            if (v[i] == 'g' as u8) {
                res += 1;
            }
        }
    }
    println!("{}", res);

    return;
}
fn main() {
    solve()
}


Measured memory_bytes: 2316
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n, a, b;

int main()
{
	cin >> n;
	cout << n / 3 << endl;

	return 0;
}


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

using namespace std;

int main(void)
{
	ll int N, W, answer=-1;
	cin>>N>>W;
	ll int w[N+1];
	ll int v[N+1];
	w[0]=0;
	v[0]=0;

	for(ll int i=1; i<=N; i++)
		cin>>w[i]>>v[i];

	ll int dp[N+1][W+1];
	
	for(ll int j=0; j<=W; j++)
		dp[0][j]=0;

	for(ll int k=0; k<=N; k++)
		dp[k][0]=0;

	for(ll int item=1; item<=N; item++)
	{
		for(ll int weight=1; weight<=W; weight++)
		{
			if(w[item]>weight)
				dp[item][weight]=dp[item-1][weight];

			else
				dp[item][weight]=max(v[item]+dp[item-1][weight-w[item]],dp[item-1][weight]);

			
		}
	}

	cout<<dp[N][W]<<"\n";

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

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  LL n, k;
  cin >> n >> k;
  if(n > k) n -= ((n - k) / k + 1) * k;
  vector<LL> ans;
  for(int i = 0; i < 3; ++i) {
    ans.push_back(n);
    n = abs(n - k);
  }
  cout << *min_element(ans.begin(), ans.end()) << '\n';
}


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

int main()
{
  int n;
  cin >> n;
  int l[n];
  int max = 0, max_i = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> l[i];
    if (max < l[i])
    {
      max = l[i];
      max_i = i;
    }
  }
  int sum = 0;
  for (int i = 0; i < n; i++)
  {
    if (i != max_i)
      sum += l[i];
  }

  if (max < sum)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}


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

vector<int> val(5,1);
vector<vector<int>> tmpp;
int h,w;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};

bool nextval(){
  val[3]++;
  if(val[3] == 7){
    val[3] = 1;
    val[2]++;
    if(val[2] == 7){
      val[2] = 1;
      val[1]++;
      if(val[1] == 7){
	val[1] = 1;
	val[0]++;
	if(val[0] == 7){
	  val[0] = 1;
	  return false;
	}
      }
    }
  }
  return true;
}

bool isin(int x, int y){
  bool ans;
  if(0 <= x and x < h and 0 <= y and y < w) ans = true;
  else ans = false;
  return ans;
}

void changeto(int to){
  queue<pair<int,int>> q;
  int from = tmpp[0][0];

  q.push(pair<int,int>(0,0));
  tmpp[0][0] = to;

  while(not q.empty()){
    pair<int,int> p = q.front();
    q.pop();

    rep(i, dx.size()){
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(isin(nx,ny) and tmpp[nx][ny] == from){
	q.push(pair<int,int>(nx, ny));
	tmpp[nx][ny] = to;
      }
    }
  }
}

int area(){
  queue<pair<int,int>> q;

  q.push(pair<int,int>(0,0));
  int c = tmpp[0][0];
  tmpp[0][0] = -1;
  int res = 1;

  while(not q.empty()){
    pair<int,int> p = q.front();
    q.pop();

    rep(i, dx.size()){
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(isin(nx,ny) and tmpp[nx][ny] == c){
	q.push(pair<int,int>(nx, ny));
	tmpp[nx][ny] = -1;
	res++;
      }
    }
  }
  return res;
}

int main(void){
  int c;
  while(cin >> h >> w >> c, h){
    vector<vector<int>> p(h,vector<int>(w));
    rep(i,h) rep(j,w) cin >> p[i][j];
    val[4] = c;

    int res = 0;
    do{
      tmpp = p;
      rep(i,5) if(tmpp[0][0] != val[i]) changeto(val[i]);
      res = max(res, area());
    }while(nextval());
    cout << res << endl;
  }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define pr(n) cout << fixed << setprecision(n)
#define ci(n) cin >> n
#define ci2(n, o) cin >> n >> o
#define ci3(n, o, p) cin >> n >> o >> p
#define co(n) cout << n << endl
#define mp(n, o) map<n, o>
#define so(n) sort(n.begin(), n.end())

int main() {
  st S;
  ci(S);
  st a = "Good";
  if(S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3)) {
    a = "Bad";
  }
  co(a);
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
signed main() {
	int a, b;
	cin >> a >> b;
	for (int i = 1; i <= 2000; i++) {
		if ((i * 8 / 100 == a) && (i * 10 / 100 == b)) {
			cout << i << endl;
			ggr
		}
	}
	puts("-1");
	ggr
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
#非再帰
import sys
def scc(Edge):
    N = len(Edge)
    Edgeinv = [[] for _ in range(N)]
    for vn in range(N):
        for vf in Edge[vn]:
            Edgeinv[vf].append(vn)
    
    used = [False]*N
    dim = [len(Edge[i]) for i in range(N)]
    order = []
    for st in range(N):
        if not used[st]:
            stack = [st, 0]
            while stack:
                vn, i = stack[-2], stack[-1]   
                if not i and used[vn]:
                    stack.pop()
                    stack.pop()
                else:
                    used[vn] = True
                    if i < dim[vn]:
                        stack[-1] += 1
                        stack.append(Edge[vn][i])
                        stack.append(0)
                    else:
                        stack.pop()
                        order.append(stack.pop())
    res = [None]*N
    used = [False]*N
    cnt = -1
    for st in order[::-1]:
        if not used[st]:
            cnt += 1
            stack = [st]
            res[st] = cnt
            used[st] = True
            while stack:
                vn = stack.pop()
                for vf in Edgeinv[vn]:
                    if not used[vf]:
                        used[vf] = True
                        res[vf] = cnt
                        stack.append(vf)
    M = cnt+1
    components = [[] for _ in range(M)]
    for i in range(N):
        components[res[i]].append(i)
    tEdge = [[] for _ in range(M)]
    teset = set()
    for vn in range(N):
        tn = res[vn]
        for vf in Edge[vn]:
            tf = res[vf]
            if tn != tf and tn*M + tf not in teset:
                teset.add(tn*M + tf)
                tEdge[tn].append(tf)
    return res, components, tEdge
        
N, M = map(int, readline().split())
Edge = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, readline().split())
    Edge[a].append(b)

R, comp, tE = scc(Edge)
Ans = [str(len(comp))]

for c in comp:
    Ans.append(f'{len(c)} ' + ' '.join(map(str, c)))

print('\n'.join(Ans))



Measured memory_bytes: 367464
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy
print("R" * dx + "U" * dy + "L" * dx + "D" * dy + "L" + "U" * (dy + 1) + "R" * (dx + 1) + "DR" + "D" * (dy + 1) + "L" * (dx + 1) + "U")

Measured memory_bytes: 3060
N = int(input())
l = list(map(int,input().split()))

ans = 0
tmp = 0

for i in range(N-1):       
    if l[i] >= l[i + 1]:
        tmp += 1
        if tmp > ans:
          ans = tmp
    else:
        if tmp > ans:
            ans = tmp
            tmp = 0
        else:
            tmp = 0
            
print(ans)

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

int main(){
	int N, i, j, ans = 0;
	scanf("%d", &N);
	string S;
	cin >> S;
	vector<vector<int>> dp(N + 1, vector<int>(N + 1, 0));
	for(i = N - 1; i >= 0; i--){
		for(j = N - 1; j >= 0; j--){
			if(S[i] == S[j]){
				dp[i][j] = dp[i + 1][j + 1] + 1;
			}
			ans = max(ans, min(abs(i - j), dp[i][j]));
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 98176
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<double>v(n);
  for(int i=0;i<n;i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  for(int i=0;i<n-1;i++){
    v.at(i+1)=(v.at(i)+v.at(i+1))/2.0;
  }
  cout << v.at(n-1) << endl;
}

Measured memory_bytes: 256
// This file is a "Hello, world!" in C# language by Mono for wandbox.
using System;

using System.Linq;

using System.Collections.Generic;

namespace Wandbox
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var a = Console.ReadLine().Split(' ').OrderBy(x => -int.Parse(x)).ToArray();
                if (a[0] == "0" && a[1] == "0")
                    break;
                Console.WriteLine("{0} {1}",a[1], a[0]);
                }
            
        }
    }
}



Measured memory_bytes: 9828
#include <iostream>

int main() {
  uint32_t W = 0, H = 0, N = 0;
  std::cin >> W >> H >> N;

  uint32_t left = 0, bottom = 0, top = H, right = W;
  for (size_t i = 0; i < N; i++) {
    uint32_t x = 0, y = 0, a = 0;
    std::cin >> x >> y >> a;
    switch (a) {
      case 1:
        if (x > left) left = x;
        break;

      case 2:
        if (x < right) right = x;
        break;

      case 3:
        if (y > bottom) bottom = y;
        break;

      case 4:
        if (y < top) top = y;
        break;

      default:
        break;
    }
  }

  std::cout << ((right > left) && (top > bottom)
                    ? (right - left) * (top - bottom)
                    : 0)
            << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int N, M;
int G[10][10];
bool visited[10];
int ans = 0;

int main() {
	cin >> N >> M;
	memset(G, 0, sizeof(G));
	for (int i = 0; i < M; ++i) {
		int a, b; cin >> a >> b;
		a--, b--;
		G[a][b] = 1;
		G[b][a] = 1;
	}
	vector<int>v;
	int res = 0;
	for (int i = 1; i < N; ++i)v.push_back(i);
	sort(v.begin(), v.end());
	do {
		int now = 0;
		for (int i = 0; i < v.size(); ++i) {
			if (G[now][v[i]] == 0)break;
			now = v[i];
			if (i == v.size() - 1)res++;
		}
	} while (next_permutation(v.begin(), v.end()));
	cout << res << endl;
	return 0;

}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=9999999999999999;

int main() {
 int N;
 string S;
 cin>>N>>S;
 int count=0;
 for(int i=0;i<S.size();){
   if(S.substr(i,3)=="ABC"){count++;i+=3;}
   else{i++;}
 } 
 cout<<count<<endl;
return 0;}

Measured memory_bytes: 256
N = int(input())
SPs = []
for i in range(N):
  l = input()
  ws = l.split()
  S = ws[0]
  P = int(ws[1])
  SPs.append([S, P])
#print(SPs)
a = list(range(1, N+1))
a.sort(key = lambda i: [SPs[i-1][0], -SPs[i-1][1]])
#print(a)
for i in range(N):
  print(a[i])


Measured memory_bytes: 3060
#include <iostream>
#include <math.h>

# define REP(i,n) for(int i=0; i<n;i++)

using namespace std;

int main(){
	while(1){
		double x, h, ans;
		cin >> x >> h;
		if (x==0 && h==0) return 0;
		ans = sqrt((x/2)*(x/2)+h*h)*x*2+x*x;
		printf("%.6lf\n",ans);
	}
	return 0;
}




Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define LL lon long

using namespace std;

string s;
string str1,str2;
static const int MOD=10000;
int M;
int mem[501][10][3][3][500];

int cal(int n,int p,int pp,int f,int mod){
    int res=0;
    if(n==s.size()){
        if(mod==0)return 1;
        else return 0;
    }
    if(mem[n][p][pp][f][mod]!=-1)return mem[n][p][pp][f][mod];
    int t=9;
    if(f!=1)t=s[n]-'0';
    for(int i=0;i<=t;++i){
        if(pp==1&&p>=i)continue;
        else if(pp==0&&p<=i)continue;
        else if(pp==2&&p!=0&&p==i)continue;

        int b;
        if(pp==2){
            if(p==0)b=2;
            else if(p<i)b=0;
            else b=1;
        }
        else if(pp==1)b=0;
        else b=1;

        int k;
        if(f==1)k=1;
        else if(i!=s[n]-'0')k=1;
        else k=0;

        int temp=mod*10+i;
        if(temp==0)res+=cal(n+1,i,b,k,0);
        else res+=cal(n+1,i,b,k,temp%M);
    }
    return mem[n][p][pp][f][mod]=res%MOD;
}

int main(){
    int vr=0;
    int vl=0;
    cin>>str1>>str2>>M;
    s=str1;
    memset(mem,-1,sizeof(mem));
    vl=cal(0,0,2,0,0);
    s=str2;
    memset(mem,-1,sizeof(mem));
    vr=cal(0,0,2,0,0);
    if((str1[0]-'0')%M==0&&str1.size()==1)vl--;
    cout<<(vr-vl+MOD)%MOD<<endl;

    return 0;
}

Measured memory_bytes: 89352
using System;

namespace A___Consecutive_Integers
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var n = int.Parse (input[0]);
            var k = int.Parse (input[1]);
            Console.WriteLine (n - k + 1);
        }
    }
}

Measured memory_bytes: 11092
n, m = map(int, input().split())
ps = [input().split() for _ in range(m)]

ps = sorted(ps, key=lambda x: x[0])

flag = 0
wa = {}
AC_count = 0
WA_count = 0
for i in range(m):
    if ps[i][0] != flag:
        if ps[i][1] == 'AC':
            AC_count += 1
            if ps[i][0] in wa.keys():
                WA_count += wa[ps[i][0]]
            flag = ps[i][0]
        else:
            if ps[i][0] in wa.keys():
                wa[ps[i][0]] += 1
            else:
                wa[ps[i][0]] = 1
print(AC_count, WA_count)

Measured memory_bytes: 36780
import sys
import math

def main():
    input = sys.stdin.readline
    X = int(input())
    count = 1
    s = 100
    while True:
        s = math.floor(s * 0.01) + s
        if s >= X:
            return count
        count += 1

if __name__ == '__main__':
    print(main())



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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    ll a,b,c;
  cin>>a>>b>>c;
  cout<<min(a*b,c)<<endl;

}
    // Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


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

using namespace std;

int main() {
    int H, W;
    int N;
    const int MAXN = 1e2+5;
    vector<int> a(MAXN*MAXN,0);
    cin >> H >> W;
    cin >> N;
    for(int i = 1; i <= N; ++i) {
        cin >> a[i];
    }
    vector<vector<int>> grid(MAXN,vector<int> (MAXN,0));
    int color = 1;
    int paint = 0;
    for(int i = 1; i <= H; ++i) {
        if(i%2 == 0) {
            for(int j = W; j >= 1; --j) {
                if(paint == a[color]) {
                    ++color;
                    paint = 0;
                }
                grid[i][j] = color;
                ++paint;
            }
        } else {
            for(int j = 1; j <= W; ++j) {
                if(paint == a[color]) {
                    ++color;
                    paint = 0;
                }
                grid[i][j] = color;
                ++paint;
            }
        }
    }
    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) {
            cout << grid[i][j] << " ";
        } cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
from collections import deque
def dfs(v,N,memo):
    ans =0
    if not False in memo.values():
        return 1
    for u in E[v]:
        if memo[u]!=True:
            memo[u] = True
            ans += dfs(u,N,memo)
            memo[u] = False
    return ans
N,M = list(map(int,input().split()))
memo = {i:False for i in range(1,N+1)}
E = {i: []for i in range(1,N+1)}
for i in range(M):
    u,v = list(map(int,input().split()))
    E[u].append(v)
    E[v].append(u)
memo[1] = True
print(dfs(1,N,memo))

Measured memory_bytes: 3316
#include <stdio.h>

int main(){
	int N, Q;
	int M, data;
	int i,j;
	int maxMember,maxMemberdata;
	while(1){
		int canAttend[100]={0,};
		scanf("%d%d",&N,&Q);if(N==0&&Q==0) break;
		maxMember=Q-1;
		maxMemberdata=0;
		for(i=0;i<N;i++){
			scanf("%d", &M);
			for(j=0;j<M;j++){
				scanf("%d", &data);
				canAttend[data]=canAttend[data]+1;
			}
		}
		for(i=0;i<100;i++){
			if(canAttend[i]>maxMember){
				maxMember=canAttend[i];
				maxMemberdata=i;
			}
		}
		printf("%d\n",maxMemberdata);
	}
	return 0;
}

Measured memory_bytes: 600
import collections


def main():
    n = int(input())
    # if n == 1:
    #     print("a")
    # for i in range(2**(n-1)):
    #     bin_str = "0" + format(i, f'0{n-1}b')
    #     print(bin_str.replace("0", "a").replace("1", "b"))

    ret = [[] for _ in range(10)]
    ret[0] = ["a"]

    alp = "abcdefghijklmnopqrstuvwxyz"

    if n == 1:
        print(ret[n-1][0])
        return

    ind = 1
    while ind < n:
        tmp_len = len(ret[ind-1])
        for j, _r in enumerate(ret[ind-1]):
            alphabet_num = len(collections.Counter(_r))
            for k in range(alphabet_num+1):
                ret[ind].append(_r+alp[k])
        ind += 1


    for r in ret[n-1]:
        print(r)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 14852
x,y=map(int,input().split())
a=1
k=pow(y,0.5)
for i in range(1,int(k)+1):
    if y%i==0:
        if i*x<=y:
            a=max(a,i)
        if (y//i)*x<=y:
            a=max(a,y//i)
print(a)            

Measured memory_bytes: 38640
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		Shop[] arr = new Shop[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = new Shop(sc.nextInt(), sc.nextInt());
		}
		Arrays.sort(arr);
		long total = 0;
		for (Shop s : arr) {
		    total += Math.min(m, s.count) * (long)(s.cost);
		    m -= s.count;
		    if (m < 0) {
		        break;
		    }
		}
		System.out.println(total);
	}
	
	static class Shop implements Comparable<Shop> {
	    int cost;
	    int count;
	    
	    public Shop(int cost, int count) {
	        this.cost = cost;
	        this.count = count;
	    }
	    
	    public int compareTo(Shop s) {
	        return this.cost - s.cost;
	    }
	}
}


Measured memory_bytes: 94020
from itertools import accumulate
from operator import xor

MOD = 10**9 + 7
M = 2**20

def solve():
    N = int(input())
    As = list(map(int, input().split()))

    Bs = list(accumulate([0]+As, xor))

    if Bs[-1] != 0:
        dp = [1, 0]
        for B in Bs[:-1]:
            if B == 0:
                dp[0] = (dp[0]+dp[1]) % MOD
            elif B == Bs[-1]:
                dp[1] = (dp[0]+dp[1]) % MOD
        return dp[0]
    else:
        ans = (2 ** (Bs.count(0)-2)) % MOD
        RunLens = [[] for _ in range(M)]
        num0 = 0
        num0Prevs = [0] * M
        numBs = [0] * M
        for B in Bs:
            if B == 0:
                num0 += 1
            else:
                if num0 != num0Prevs[B]:
                    RunLens[B].append(numBs[B])
                    RunLens[B].append(num0 - num0Prevs[B])
                    numBs[B] = 0
                    num0Prevs[B] = num0
                numBs[B] += 1
        for B in range(M):
            RunLens[B].append(numBs[B])
            RunLens[B].append(num0 - num0Prevs[B])

        for B in range(M):
            if len(RunLens[B]) == 2: continue
            dp = [1, 0]
            for i, RL in enumerate(RunLens[B][2:-1], 1):
                dp[i%2] = (dp[i%2] + dp[1-i%2]*RL) % MOD
            ans = (ans + dp[1]) % MOD
        return ans

print(solve())


Measured memory_bytes: 224676
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////
int N;
vector<vector<pii>>G;
int ans[100100];
void dfs(int n, int p, int c) {
	ans[n] = c;
	for (auto v : G[n]) {
		if (v.first != p) {
			if (v.second % 2 == 0) {
				dfs(v.first, n, c);
			}
			else {
				dfs(v.first, n, 1 - c);
			}
		}
	}
}
int main() {
	cin >> N;
	G.resize(N);
	for (int i = 0; i < N - 1; ++i) {
		int u, v, w;
		cin >> u >> v >> w;
		u--, v--;
		G[u].push_back({ v,w });
		G[v].push_back({ u,w });
	}
	dfs(0, -1, 1);
	for (int i = 0; i < N; ++i) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 8960
use proconio::input;
use std::cmp;

fn main() {
    input! {
        n: isize,
        k: isize,
    }

    let mut ans = 0;
    for b in 1..n + 1 {
        let p = n / b;
        let r = n % b;
        ans += cmp::max(b - k, 0) * p + cmp::max(r + 1 - k, 0);
    }
    if k == 0 {
        ans -= n;
    }

    println!("{}", ans);
}


Measured memory_bytes: 2152
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)

ab_list = []
ans =0
for i in range(M):
    a,b = map(int, input().split())
    a, b = a-1, b-1
    uf.union(a, b)

ans = 0
ans_list = uf.roots()
for i in range(len(ans_list)):
    ans = max(ans, uf.size(ans_list[i]))

print(ans)


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

using namespace std;
long long a[200000];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    cout<<a[n/2+1]-a[n/2]<<endl;
    return 0;
}

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

int main() {
    int n,m; cin >> n >> m;
    vector<vector<int>> G(n,vector<int>(0));
    vector<bool> done(n,false);
    for(int i=0; i<m; i++){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int ans = 0;
    for(int i=0; i<n; i++){
        if(done[i]) continue;
        done[i] = true;
        queue<int> q;
        q.push(i);

        int cnt = 1;
        while(!q.empty()){
            int x = q.front();
            q.pop();
            for(int j=0; j<G[x].size(); j++){
                if(done[G[x][j]]) continue;
                done[G[x][j]] = true;
                q.push(G[x][j]);
                cnt++;
            }
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}

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

using namespace std;

#define foru(i, l, r) for (register int i = l; i <= r; i++)
#define ford(i, r, l) for (register int i = r; i >= l; i--)

int N, M, dp[102][102];
char ch[102][102];

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) scanf("%s", ch[i] + 1);
  dp[1][1] = (ch[1][1] == '#');
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (i > 1 || j > 1) dp[i][j] = 0x3f3f3f3f;
      if (i > 1)
        dp[i][j] = min(dp[i][j],
                       dp[i - 1][j] + (ch[i][j] == '#' && ch[i - 1][j] == '.'));
      if (j > 1)
        dp[i][j] = min(dp[i][j],
                       dp[i][j - 1] + (ch[i][j] == '#' && ch[i][j - 1] == '.'));
    }
  }
  printf("%d\n", dp[N][M]);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;

int main() {
	string s;
	int n;
	cin >> n >> s;
	for (int i = 0; i < s.size(); i++) {
		s[i] += n;
		if (s[i] > 'Z') {
			s[i] -= ('Z' - 'A' + 1);
		}

	}
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <limits>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdint>
#include <stdio.h>
#include <stdlib.h>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;

const ll mod = 1000000000 + 7; //10^9

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll ans = 0;
    for (int  i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    ll b = 0;
    for (int  i = 0; i < N; i++)
    {
        if (A[i] >= b)
        {
            b = A[i];
        }else
        {
            ans += b - A[i];
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 4388
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(void)
{
    int i,n,x[100],y[100];
    double p1=0,p2=0,p3=0,p0=0;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++) scanf("%d",&x[i]);
    for(i=0;i<n;i++) scanf("%d",&y[i]);
        
    for(i=0;i<n;i++){
        p1=p1+abs(x[i]-y[i]);
        p2=p2+pow(fabs((double)x[i]-y[i]),2.0);
        p3=p3+pow(fabs((double)x[i]-y[i]),3.0);
        if(p0<abs(x[i]-y[i])) p0=abs(x[i]-y[i]);
    }
           
    printf("%lf\n %lf\n %lf\n %lf\n",p1,pow(p2,1.0/2.0),pow(p3,1.0/3.0),p0);
    
    return 0;
}


Measured memory_bytes: 2112
a=b=1
n=gets.to_i
n.times{
	i,j=gets.split.map(&:to_i)
	a1 = a%i==0? a/i : a/i +1
	b1 = b%j==0? b/j : b/j +1
	s =  [a1, b1].max
 	a,b=i*s,j*s
}

p (a+b).to_i

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

int main(){
	std::string str;
	std::cin>>str;

	for (int i = 0; i < str.size()/2; i++) {
		if (str[i] != str[str.size() - 1 - i]) {
			std::cout <<"No" << std::endl;
			exit(0);
		}
	}

	for (int i = 0; i < str.size() / 4; i++) {
		if (str[i] != str[str.size() / 2 -1- i]) {
			std::cout << "No" << std::endl;
			exit(0);
		}

		if (str.size() % 2 == 0) {
			if (str[str.size() / 2 + i] != str[str.size() - 1 - i]) {
				std::cout << "No" << std::endl;
				exit(0);
			}
		}
		else {
			if (str[str.size() / 2 + 1 + i] != str[str.size() - 1 - i]) {
				std::cout << "No" << std::endl;
				exit(0);
			}
		}

	}

	std::cout<<"Yes"<<std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char* add(const char* a, const char* b)
{
    int sizeA, sizeB, sizeX;
    int A, B, C;
    char* x;
    char* t;
    int la, lb, lx;
    C = 0;
    sizeA = strlen(a);
    sizeB = strlen(b);
    sizeX = (sizeA > sizeB ? sizeA : sizeB)+1;
    x = (char*)calloc(sizeX, 1);
    la = sizeA - 1;
    lb = sizeB - 1;
    lx = sizeX - 1;
    
    while(lx >= 0){
        A = la >= 0 ? a[la] - '0' : 0;
        B = lb >= 0 ? b[lb] - '0' : 0;
        x[lx] = '0' + (A + B + C) % 10;
        C = (A + B + C) / 10;
        la--;
        lb--; 
        lx--;
    }
    if (*x == '0'){
        t = (char*)calloc(sizeX - 1, 1);
        strcpy(t, x + 1);
        free(x);
        return t;
    }
    return x;
}
int main()
{
    int i;
    int N;
    char first[201];
    char second[201];
    char* result;
    scanf("%d", &N);
    for(i = 0; i < N; ++i){
        scanf("%s", first);
        scanf("%s", second);
        if(strlen(first) > 80
        || strlen(second) > 80){
            printf("overflow\n");
            continue;
        }
        result = add(first, second);
        if(strlen(result) <= 80){
            printf("%s\n", result);
        }else{
            printf("overflow\n");
        }
        free(result);
    }
    return 0;
}
 

Measured memory_bytes: 2544
using System;
using System.Collections.Generic;
using System.Linq;
using static Constans;

public static class Constans
{
    public const long Mod = 998244353;
}

public struct ModInt
{
    public long Num;

    public ModInt(long num)
    {
        Num = num;
    }

    // x^n
    public static long Power(long x, long n)
    {
        long pow = 1;
        while (n > 0)
        {
            if (n % 2 == 0)
            {
                x *= x;
                x %= Mod;
                n /= 2;
            }
            else
            {
                pow *= x;
                pow %= Mod;
                n--;
            }
        }

        return pow;
    }

    public static ModInt GetInv(long f)
    {
        // フェルマーの小定理 a^(-1) = a^(mod-2)
        return new ModInt(Power(f, Mod - 2));
    }

    public ModInt GetInv()
    {
        return GetInv(Num);
    }

    public override string ToString()
    {
        return Num.ToString();
    }

    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Num += r.Num;
        if (l.Num >= Mod)
        {
            l.Num -= Mod;
        }
        return l;
    }

    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Num -= r.Num;
        if (l.Num < 0)
        {
            l.Num += Mod;
        }
        return l;
    }

    public static ModInt operator *(ModInt l, ModInt r)
    {
        return new ModInt(l.Num * r.Num % Mod);
    }

    public static implicit operator ModInt(long n)
    {
        n %= Mod;
        if (n < 0)
        {
            n += Mod;
        }
        return new ModInt(n);
    }
}

public static class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var K = vals[1];
        var ranges = new (int l, int r)[K];
        for (int i = 0; i < K; i++)
        {
            vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            ranges[i] = (vals[0], vals[1]);
        }

        var diffs = new ModInt[N + 1];
        diffs[1] = 1;
        diffs[2] = -1;

        ModInt cur = 0;
        for (int i = 1; i <= N; i++)
        {
            cur += diffs[i];
            foreach (var range in ranges)
            {
                var l = i + range.l;
                var r = Math.Min(i + range.r, N) + 1;
                if (l <= N)
                {
                    diffs[l] += cur;
                    if (r <= N)
                    {
                        diffs[r] -= cur;
                    }
                }
            }
        }

        Console.WriteLine(cur);
    }
}

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

using namespace std;

int N;
int X[15];
int Y[15];
int A[15];
double B[15];
double D[15][15];
double dp[15][1<<15];
double dp2[15][1<<15];
double dp3[1<<15];
double dp4[1<<15];

double rec(int i, int mask);

double rec2(int i, int mask)
{
    if(mask==0)
        return 0.0;
    double& ret=dp2[i][mask];
    if(ret==ret)
        return ret;
    ret=-1e300;
    for(int j=0; j<N; j++) if((mask>>j)&1)
        ret=max(ret, rec(j, mask^(1<<j))-D[i][j]);
    return ret;
}

double rec(int i, int mask)
{
    if(mask==0)
        return A[i];
    double& ret=dp[i][mask];
    if(ret==ret)
        return ret;
    ret=-1e300;
    for(int smask=mask; smask>0; smask=(smask-1)&mask)
    {
        int mmask=mask^smask;
        ret=max(ret, rec(i, mmask)+rec2(i, smask));
    }
    return ret;
}

double rec4(int mask)
{
    double& ret=dp4[mask];
    if(ret==ret)
        return ret;
    ret=-1e300;
    for(int i=0; i<N; i++) if((mask>>i)&1)
        ret=max(ret, rec(i, mask^(1<<i)));
    ret/=__builtin_popcount(mask);
    return ret;
}

double rec3(int mask)
{
    if(mask==0)
        return 1e300;
    double& ret=dp3[mask];
    if(ret==ret)
        return ret;
    ret=-1e300;
    for(int smask=mask; smask>0; smask=(smask-1)&mask)
    {
        int mmask=mask^smask;
        ret=max(ret, min(rec3(mmask), rec4(smask)));
    }
    return ret;
}

int main()
{
    scanf("%d", &N);
    for(int i=0; i<N; i++)
        scanf("%d%d%d", X+i, Y+i, A+i);
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            D[i][j]=hypot(X[i]-X[j], Y[i]-Y[j]);
    memset(dp, -1, sizeof dp);
    memset(dp2, -1, sizeof dp2);
    memset(dp3, -1, sizeof dp3);
    memset(dp4, -1, sizeof dp4);
    printf("%.15f\n", rec3((1<<N)-1));
    return 0;
}


Measured memory_bytes: 8448
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  sort(all(b));
  reverse(all(b));
  int g=0;
  if(a%2==0){
  rep(i,a/2-1){
  g+=2*b[i+1];
  }
    out(g+b[0]);
  }
  else{
  rep(i,a/2-1){
  g+=2*b[i+1];
  }
    out(g+b[0]+b[a/2]);
  }
}


Measured memory_bytes: 4984
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define pl pair<ll,ll>
#define TC int t;cin>>t;while(t--)
#define in(n) ll n;cin>>n;
#define inarr(n) ll n;cin>>n;vector<ll>arr;
int main(void){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    ll dp[s.length()+1][t.length()+1];
    memset(dp,0,sizeof(dp));
    s='-'+s;t='-'+t;
    for(int i=1;i<s.length();i++){
        for (int j = 1; j < t.length(); j++){
            if(i==1 && j==1){
                if(s[i]==t[j]) dp[i][j]=1;
            }
            else if(s[i]==t[j]){
                dp[i][j]=1+dp[i-1][j-1];
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    string ans;
    ll i=s.length()-1,j=t.length()-1;
    while(i>=1 && j>=1){
        if(s[i]==t[j]){
            ans+=s[i];
            i--;j--;
        }
        else if(dp[i-1][j]>dp[i][j-1]){
            i--;
        }
        else{
            j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 73924
io = STDIN
n=io.gets.to_i
a=io.gets.split.map(&:to_i).sort
b=io.gets.split.map(&:to_i)
c=io.gets.split.map(&:to_i).sort
ans= b.map do |bb|
  aix=a.bsearch_index{|aa|aa>=bb}
  cix=c.bsearch_index{|cc|cc>bb}
  aix=n unless aix
  cix=n unless cix
  aix*(n-cix)
end #.to_a.inject(:+)
p ans.inject(:+)

Measured memory_bytes: 23912
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	int n,d,x;
	int arr[101];

	cin >> n;
	cin >> d >> x;
	for(int i=0 ; i<n ; i++)
		cin >> arr[i];
	
	int ans = 0;
	for(int i=0 ; i<n ; i++)
	{
		int j = 0;
		int temp = 1;
		while(temp <= d)
		{
			ans++;
			j++;
			temp = j*arr[i] + 1; 
		}
	}

	cout << ans+x;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int n,m;
char s[500][500];
int vis[500][500];
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
void dfs(int x, int y, ll& p, ll& q){
    vis[x][y]=1;
    if(s[x][y]=='#') p++;
    else q++;
    for(int i=0;i<4;i++){
        int X=x+dx[i];
        int Y=y+dy[i];
       // cout<<X<<" "<<Y<<"\n";
        if(X>=0 && X<=n-1 && Y>=0 && Y<=m-1){
            if(s[x][y]=='#' && s[X][Y]=='.' && vis[X][Y]==0){
                dfs(X,Y,p,q);
            }
            else if(s[x][y]=='.' && s[X][Y]=='#' && vis[X][Y]==0){
                dfs(X,Y,p,q);
            }
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>s[i][j];
        }
    }
    for(int i=0;i<500;i++){
        for(int j=0;j<500;j++) vis[i][j]=0;
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(vis[i][j]==0){
                ll p=0; ll q=0;
                dfs(i,j,p,q);
              //  cout<<p<<" "<<q<<"\n";
                ans+=p*q;
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 11392
#include<bits/stdc++.h>
using namespace std;
   
int n,m,b[510][510];
int pc[1<<24],dp[2][1<<24],bits[510];
   
void compute() {
  int maxi = 0;
  if( n <= m ) {
    for(int i=0;i<(1<<n);i++) {
      if( maxi >= pc[i] ) continue;
      bool ok = true;
      for(int x=0;x<m;x++) {
    int cnt = 0;
    for(int y=0;y<n;y++) if( ( (i>>y) & 1 ) && b[y][x] ) ++cnt;
    if( cnt & 1 ) {
      ok = false;
      break;
    }
      }
      if( ok ) maxi = max(maxi,pc[i]);
    }
  } else { // n > m
   int list[501];
      fill(list,list+n,0);
      for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
          if(b[i][j]){
            list[i]=list[i]|(1<<j);
          }
        }
      }
      for(int i=0;i<2;i++)for(int j=0;j<(1<<m);j++)dp[i][j]=-1;
      dp[0][0]=0;
      for(int i=0;i<n;i++){
        for(int j=0;j<(1<<m);j++)dp[(i+1)&1][j]=-1;
        for(int j=0;j<(1<<m);j++){
          if(dp[i&1][j]==-1)continue;
          dp[(i+1)&1][j^list[i]]=max(dp[(i+1)&1][j^list[i]],dp[i&1][j]+1);
          dp[(i+1)&1][j]=max(dp[(i+1)&1][j],dp[i&1][j]);
        }
      }
      if(dp[n&1][0]!=-1)maxi=dp[n&1][0];
  }
  cout << maxi << endl;
}
   
int main() {
  for(int i=0;i<(1<<23);i++) pc[i] = __builtin_popcount(i);
  while( cin >> n >> m, n|m ) {
    for(int i=0;i<n;i++) {
      string s;
      cin >> s;
      for(int j=0;j<m;j++) b[i][j] = ( s[j] == '1' );
    }
    compute();
  }
  return 0;
}


Measured memory_bytes: 53364
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let a = read_as_vec::<i32>()[0];
    let b = read_as_vec::<i32>()[0];
    let c = read_as_vec::<i32>()[0];
    let d = read_as_vec::<i32>()[0];

    println!("{}", cmp::min(a, b) + cmp::min(c, d));
}


Measured memory_bytes: 4352