akhauriyash/Code-Regression huggingface dataset:
// CODE by Kazhybay Askar

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

/*
find_by_order(k);
order_of_key(k);
ordered_set(int) s;
*/

/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
rng();
shuffle(permutation.begin(), permutation.end(), rng);
*/

/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC    optimize("Ofast")
#pragma GCC    target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define F      first
#define S      second
#define pb     push_back
#define pf     push_front
#define ppb    pop_back
#define ppf    pop_front
#define Speed  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define sz     size()
#define all(x) x.begin(),x.end()
#define cont   continue
#define r0     return 0
#define nl     '\n'
#define ordered_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>

typedef unsigned long long ull;
typedef long long ll;
typedef long double   ld;
typedef pair<ll,ll>   pll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;

const int MAXN  = 5e5  + 7;
const int MOD   = 1e9  + 7;
const int INF   = 1e9  + 7;
const ll  MINF  = 1e18 + 7;
const int EPS   = 1e-6;
const int dx[]  = {0, 0, 1, -1, -1, -1, 1, 1};
const int dy[]  = {1, -1, 0, 0, -1, 1, -1, 1};
const double pi = acos(-1.0);

ll n,a[MAXN];

void solve(){
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                int g=__gcd(i,j);
                g=__gcd(g,k);
                ans+=g;
            }
        }
    }
    cout<<ans;
}



int main(){
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
    Speed;
    ll T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    r0;
}


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

#define int long long
#define endl "\n"
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("output.txt","w",stdout);

const int N = 2e5 + 5;

void solve();
int32_t main()
{
    IOS;
    int x,n;
    cin >> x >> n;
    set<int>a;
    for(int i=0;i<=101;i++)
        a.insert(i);
    for(int i=0;i<n;i++){
        int t;
        cin >> t;
        a.erase(t);
    }
    auto it = a.lower_bound(x);
    int p = abs(*it-x);
    int q = INT_MAX;
    if(it!=a.begin())
        q = abs(*(--it) - x);
    if(p<q)
        cout << x+p << endl;
    else
        cout << x-q << endl;
}


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

int64_t f(int64_t n){
    return n*(n-1)/2;
}

int main(){
    int n;
    cin>>n;
    
    vector<int64_t> a(n);
    rep(i,n)cin>>a[i], a[i]--;
    
    vector<int64_t> m(n,0);
    rep(i,n)m[a[i]]++;
    
    int64_t ans = 0;
    rep(i,n)ans += f(m[i]);
    
    for(int i=0; i<n; i++){
        //cout << ans -f(m[a[i]]) + f(m[a[i]]-1) << endl;
        printf("%lld\n", ans -f(m[a[i]]) + f(m[a[i]]-1));
    }
    
    return 0;
}

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

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

int main(){
	int K;
	scanf("%d",&K);
	printf("%d\n",360/gcd(K,360));
	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int d(ll n) {
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int main() {
    ll n;
    cin >> n;
    ll a[210000];
    ll cnt[210000];
    rep(i, n) {
        ll A;
        cin >> A;
        A--;
        a[i] = A;
        cnt[A]++;
    }
    // rep(i, n) cout << cnt[i] << ' '; // 確認済
    // cout << endl;
    ll sum = 0;
    rep(i, n) {
        sum += cnt[i] * (cnt[i] - 1) / 2;
    }
    // cout << sum << endl;
    // int count;
    ll k;
    rep(i, n) {
        k = sum;
        k -= cnt[a[i]] * (cnt[a[i]] - 1) / 2;
        cnt[a[i]]--;
        // count = 0;
        // rep(j, n) {
            // count += cnt[j] * (cnt[j] - 1) / 2;
        // }
        // cout << count << endl;
        k += cnt[a[i]] * (cnt[a[i]] - 1) / 2;
        cout << k << endl;
        cnt[a[i]]++;
    }
    
}

Measured memory_bytes: 6760
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if (k % 2 == 0) {
        cout << a - b << endl;
    }else{
        cout << b - a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
use std::collections::HashMap;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

fn main() {
  let n: usize = read();
  let mut a: Vec<usize> = read_vec();

  let mut hash = HashMap::new();

  for i in 0..n {
    hash.insert(a[i], i+1);
  }

  a.sort();

  for i in a {
    let tmp = hash.get(&i).unwrap();
    print!("{} ", tmp);
  }
  println!();
}

Measured memory_bytes: 12540
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  string s,t; cin >> s >> t;
  s+='#';
  bool f1=0,f2=0;
  ll ans=3;
  rep(i,n){
    if(i==0&&s[i]==s[i+1]) ans*=2;
    if(f1==1) ans*=2;//cout << s[i]<<2 << endl;}
    if(f2==1&&s[i]==s[i+1]) ans*=3;//cout << s[i]<<3 << endl;}
    if(f2==1&&s[i]!=s[i+1]) ans*=1;//cout << s[i]<<1 << endl;}
    if(s[i]==s[i+1]){
      i++;
      f1=0; f2=1;
    }
    else{
      f1=1; f2=0;
    }
    ans%=mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let a: usize = sc.read();
    // let b: String = sc.read::<String>();
    // b.retain(|x| x != '.');
    // let b = b.split(".").collect::<Vec<&str>>();

    // let ans = a * b[0].parse::<usize>().unwrap() + a * b[1].parse::<usize>().unwrap() / 100;

    let b: f64 = sc.read();
    let ans = a * (b * 100.0).round() as usize / 100;
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2732
#include <bits/stdc++.h>
 
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
 
struct rule {
  int l, x;
};
 
void solve() {
  int N, M;
  cin >> N >> M;
  vector<vector<rule>> R(N + 1);
  for (int i = 0; i < M; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    R[r].push_back({l, x});
  }
  
  const int mod = 1e9 + 7;
  vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(N + 1, vector<ll>(N + 1, 0)));
  dp[0][0][0] = 1;
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= N; j++) {
      for(int k = 0; k <= N; k++) {
        int m = max({i, j, k});
        vector<int> c{i, j, k};
        sort(all(c));
        auto f = [&c](int l) {
          if (l > c[1]) return 1;
          if (l > c[0]) return 2;
          return 3;
        };
        bool flag = true;
        for(int p = 0; p < R[m].size(); p++) {
          int l = R[m][p].l;
          int x = R[m][p].x;
          if (f(l) != x) {
            flag = false;
            break;
          }
        }
        if (!flag) {
          dp[i][j][k] = 0;
          continue;
        }
 
        int m_ = m + 1;
        if (m_ > N) continue;
        dp[m_][j][k] += dp[i][j][k]; dp[m_][j][k] %= mod;
        dp[i][m_][k] += dp[i][j][k]; dp[i][m_][k] %= mod;
        dp[i][j][m_] += dp[i][j][k]; dp[i][j][m_] %= mod;
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      ans += dp[N][i][j]; ans %= mod;
      ans += dp[i][N][j]; ans %= mod;
      ans += dp[i][j][N]; ans %= mod;
    }
  }
  cout << ans << endl;
 
}
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

Measured memory_bytes: 218880
#!/usr/bin/perl

$line = 0;
while (<>) {
    if ($line == 0) {
        ($n, $k) = split /\s+/, $_;
    } else {
        @l = split /\s+/, $_;
    }
    $line++;
}

$i = 1;
foreach (sort {$b <=> $a} @l) {
    if ($i > $k) {
        last;
    }
    $total += $_;
    $i++;
}

print "$total\n";


Measured memory_bytes: 384
N,M = map(int,input().split())

L=1
R=N
num='inf'
for i in range(M):
    l,r = map(int,input().split())
    L=max(L,l)
    R=min(R,r)
    if L>R:
        num=0
        break
if num==0:
    print(0)
else:
    print(R-L+1)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
  
int main() {
	int tc;
	cin >> tc;
	string verdicts[] = {"AC", "WA", "TLE", "RE"};
	map<string, int> mp;
	while(tc--) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for (int i = 0; i < 4; i++) {
		cout << verdicts[i] << " x " << mp[verdicts[i]] << "\n";
	} 
}


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

int main() {
    string S, T;
    bool a;
    a = false;
    cin >> S >> T;
    for (int i = 0; i < S.size(); i++){
        if(S.at(i) != T.at(i))a = true;
    }
    if(a) cout << "No" << endl;
    else  cout << "Yes" << endl;
}


Measured memory_bytes: 3620
x = list(map(int, input().split()))
N = int(input())

L2=x[3]
L1=x[2]
L05=x[1]
L025=x[0]
lowestL1=min(L1,L05*2,L05+L025*2,L025*4)

if (lowestL1*2<L2):
    print('{0}'.format(N*lowestL1))
    quit()

n=int(N/2)
print('{0}'.format(n*L2+(N%2)*lowestL1))


quit()


Measured memory_bytes: 3064
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial;
     
    void main(){
        auto ab=readln.split.map!(to!int).array;
        writeln((ab[0]+ab[1])%24);
    }

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

int main()
{
	int n;
	scanf("%d",&n);
	std::vector<int> data(n);
	for(int i = 0;i < n;++i) {
		scanf("%d",&data[i]);
	}
	std::sort(data.begin(),data.end());
	int ans = 0,cnt = 0;
	for(int i = 0;i < n;++i) {
		if(i > 0 && data[i] != data[i - 1]) {
			ans += cnt % 2;
			cnt = 0;
		}
		++cnt;
	}
	ans += cnt % 2;
	cnt = 0;
	printf("%d\n",ans);
}

Measured memory_bytes: 640
n, m, k = map(int, input().split())
mod = 998244353

N = 10**6  # N!まで求める
fact  = [1, 1]  # 階乗の元テーブル
fact_inv = [1, 1]  # 階乗の逆元テーブル
inv = [0, 1]  # 逆元テーブル計算用テーブル 1,2,,...の逆元を求めてる

# 計算 O(1)
def comb(n, r, mod):
    if (r<0 or r>n):
        return 0
    r = min(r, n-r)
    return fact[n] * fact_inv[r] * fact_inv[n-r] % mod

# 順列
def perm(n, r, mod):
    if (r<0 or r>n):
        return 0
    return fact[n] *  fact_inv[n-r] % mod

# 前処理 O(n)
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod//i)) % mod)
    fact_inv.append((fact_inv[-1] * inv[-1]) % mod)

ans = 0
for i in range(k+1):
    ans += comb(n-1, i, mod) * m * pow(m-1, n-i-1, mod)
    ans %= mod

print(ans)

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

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

    int h,w;
    cin >> h >> w;

    int magic[10][10];
    int board[h][w];
    rep(i,10){
        rep(j,10){
            cin >> magic[i][j];
        }
    }
    rep(i,h){
        rep(j,w){
            cin >> board[i][j];
        }
    }

    for(int k = 0; k < 10; k++){
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                magic[i][j] = min(magic[i][j], magic[i][k] + magic[k][j]);
            }
        }
    }

    int ans = 0;
    rep(i,h){
        rep(j,w){
            if(board[i][j] == 1 or board[i][j] == -1) continue;
            ans += magic[board[i][j]][1];
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>

int main(void) {

	int a, b, c;

	std::cin >> a >> b >> c;

	if (a < b) {
		std::swap(a, b);
	}

	if (b < c) {
		std::swap(b, c);
	}

	if (a < b) {
		std::swap(a, b);
	}

	std::cout << std::abs(a - b) + std::abs(b - c) << std::endl;



	return 0;
}

Measured memory_bytes: 256
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define MOD 1000000007;//1e9+7

void solve() {
    int N, M;
    cin >> N >> M;
    if (N == M)cout << "Yes";
    else cout << "No";
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;

  int ac_ans = 0, wa_ans = 0;
  for (int i = 0; i < m; i++) {
    int p;
    string s;
    cin >> p >> s;

    auto itr = mp.find(p);
    if (itr != mp.end()) {
      if (s == "AC" && mp[p] > 0) {
        ac_ans++;
        wa_ans += mp[p];
        mp[p] = -1;
      }
      if (s == "WA" && mp[p] > 0) {
        mp[p]++;
      }
      
    } else {
      if (s == "AC") {
        ac_ans++;
        mp[p] = -1;
      } else {
        mp[p] = 1;
      }
    }
  }
  
  cout << ac_ans << " " << wa_ans << endl;
} 

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <cstdlib>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int triple_max(int x, int y, int z){
    int ans = x;
    if (y > x && y > z) ans = y;
    else if (z > x && z > y) ans = z;

    return ans;
}

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    cout << (n * a < b ? n * a : b) << endl;

    return 0;
}


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

int n, ans;
string a[12], b[12];

void solve(const string &s, const string &g, int cnt = 0){
	if( s == g ){
		ans = min(ans, cnt);
		return ;
	}
	if( s.size() > g.size() ) return ;
	
	for(int i=0 ; i < n ; i++ ){
		string t = s;
		bool flag = false;
		for(int j=0 ; j < t.size() ; ){
			if( t.substr(j, a[i].size()) == a[i] ){
				flag = true;
				t.replace(j, a[i].size(), b[i]);
				j = j + b[i].size();
			}else{
				j++;
			}
		}
		
		if( flag ) solve(t, g, cnt+1);
	}
}

int main(){
	while( cin >> n , n ){
		string s, g;
		for(int i=0 ; i < n ; i++ ){
			cin >> a[i] >> b[i];
		}
		cin >> s >> g;
		ans = 100;
		solve(s, g);
		if( ans == 100 ) ans = -1;
		cout << ans << endl;
	}
}

Measured memory_bytes: 1232
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int n, A[21];

//O(n^2)
int solve(int i, int m) {
	if (m == 0)return 1;
	if (i >= n)return 0;
	int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> A[i];
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int m; cin >> m;
		if (solve(0, m))
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}




Measured memory_bytes: 3116
n,m,c = gets.split(' ').map(&:to_i)
b = gets.split(' ').map(&:to_i)
a = n.times.map{gets.split(' ').map(&:to_i)}
count = 0
n.times do |j|
	sum = 0
	m.times {|i| sum += b[i] * a[j][i]}
	count += 1 if (sum + c > 0)
end

puts count

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main(){
    ll a,b,c,d,n,A,B,C,E;
    cin>>a>>b>>c>>d;
    n=b-a+1;
    //c
    ll buf=a%c;
    A=((b/c)-(a/c)+1);
    if(buf!=0)A--;
    buf=a%d;
    B=((b/d)-(a/d)+1);
    if(buf!=0)B--;
    E=(c*d)/gcd(c,d);
    buf=a%E;
    C=((b/E)-(a/E)+1);
    if(buf!=0)C--;
    cout<<n-(abs(A+B)-C)<<endl;
}

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

using namespace std;
using ll = long long;

const long long INF = 1LL << 60;

ll dp[101][100001] = {};

int main() {
    #ifdef MYLOCAL
        ifstream in("input.txt");
        cin.rdbuf(in.rdbuf());
    #endif

    int n, w; cin >> n >> w;
    vector<int> ws(n);
    vector<int> vs(n);
    ll max_v = 0;
    for (int i = 0; i < n; ++i) {
        cin >> ws[i] >> vs[i];
        max_v += vs[i];
    }

    for (int i = 0; i <= n; ++i) {
        for(int j = 0; j <= max_v; ++j) {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    for (int i = 0; i < n; ++i) {
        for(int j = 0; j <= max_v; ++j) {
            if (j - vs[i] >= 0) {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - vs[i]] + ws[i]);
            }
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }

    ll ans = 0;
    for (int i = 0; i <= max_v; ++i) {
        if(dp[n][i] <= w) {
            ans = i;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
  string S;
  cin >> S;
  
  int size = S.size();
  
  if(S.at(size-1) == 's')
    S = S + "es";
  else
    S = S + "s";
  
  cout << S << endl;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String[] line1 = sc.nextLine().split(" ");

        final int N = Integer.valueOf(line1[0]);
        final int K = Integer.valueOf(line1[1]);
        final int Q = Integer.valueOf(line1[2]);

        //user init
        int[] userPt = new int[N];
        for (int i = 0; i < userPt.length; i++) {
            userPt[i] = K - Q;
        }

        //get answer user
        for (int i = 0; i < Q; i++) {
            int userI = Integer.valueOf(sc.nextLine()) -1;
            userPt[userI] += 1;
        }

        //output

        for (int anUserPt : userPt) {
            if (anUserPt <= 0) {
                System.out.println("No");
            } else {
                System.out.println("Yes");
            }
        }
    }
}


Measured memory_bytes: 95388
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define pb push_back
#define PI 3.141592653589793
#define MOD 1000000007
using namespace std;
int main(){
    FAST
    ll n; cin >> n;
    string s[n];
    vector<string>vec;
    map<string,ll>mpp;
    for(ll i=0;i<n;i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
        vec.pb(s[i]);
        mpp[s[i]]++;
    }
    ll cnt =0;
    for(ll i=0;i<n;i++){
        cnt+=(mpp[s[i]]*(mpp[s[i]]-1))/2;
        mpp[s[i]]=0;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 17344
N = input()
A, B = map(int, input().split(" "))
P = list(map(int, input().split(" ")))
num = [0, 0, 0]
for score in P:
    if score <= A:
        num[0] += 1
    elif A < score <= B:
        num[1] += 1
    elif B < score:
        num[2] += 1

print(min(num))


Measured memory_bytes: 3060
def frequencies(arr)
  buckets = Hash.new { 0 }
  arr.each do |elt|
    buckets[elt] += 1
  end
  buckets
end

n, k = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)

f = frequencies(arr)
kinds = f.size
ans = 0
f.sort_by { |_,v| v }.each do |_, value|
  if kinds <= k
    break
  end
  ans += value
  kinds -= 1
end
puts ans


Measured memory_bytes: 41728
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N;i ++) arr[i] = sc.nextInt();

        long[] left = new long[N+1];
        long[] right = new long[N+1];
        for(int i = 0; i < N; i++) {
            left[i+1] = gcd(left[i], arr[i]);
        }
        for(int i = N-1; i >= 0; i--) {
            right[i] = gcd(right[i+1], arr[i]);
        }
        long res = 0;
        for(int i = 0; i < N; i++) {
            int l = (int)left[i];
            int r = (int)right[i+1];
            res = Math.max(res, gcd(l,r));
        }
        System.out.println(res);
    }
    public static long gcd(long a, long b) {
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }
}


Measured memory_bytes: 59308
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 500010;

int n;
pair<ll, int> art[N];

int main() {

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%lld%d", &art[i].first, &art[i].second);
    sort(art + 1, art + n + 1);
    ll ans = 0, pre = -1LL << 60, s = 0;
    for (int i = 1; i <= n; ++i) {
        pre = max(pre, -s + art[i].first);
        s += art[i].second;
        ans = max(ans, pre + s - art[i].first);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 11020
def inpl(): return list(map(int, input().split()))
A, B, C = inpl()

if A%2 or B%2 or C%2:
    print(0)
elif A == B == C:
    print(-1)
else:
    ans = 1
    while True:
        A, B, C = (C+B)//2, (A+C)//2, (A+B)//2
        if A%2 or B%2 or C%2:
            print(ans)
            break
        ans += 1

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


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

  int A, B, C, D, E, F; std::cin >> A >> B >> C >> D >> E >> F;

  const int Amax = F/(100*A) + 1;
  const int Bmax = F/(100*B) + 1;
  const int Cmax = F/C + 1;
  const int Dmax = F/D + 1;

  double centre = -1.;
  int ans_w = 0, ans_s = 0;
  for(int a = 0; a <= Amax; a++)
  for(int b = 0; b <= Bmax; b++)
  for(int c = 0; c <= Cmax; c++)
  for(int d = 0; d <= Dmax; d++) {
    int water = (100*A)*a + (100*B*b);
    int suger = (c*C + d*D);
    if ( water <= 0. ) continue;
    if ( water + suger > F ) continue;
    if ( (double)water < ((double)suger/E)*100. ) continue;
    double tmp = (100.*(double)suger)/((double)water+suger);
    if( chmax(centre, tmp) ) {
      ans_w = water;
      ans_s = suger;
    }
  }

  std::cout << ans_w+ans_s << " " << ans_s << std::endl;
  return 0;
}


Measured memory_bytes: 256
import Data.List

split :: Char -> [Char] -> [[Char]]
split c str=
  if ind == Nothing then
    [str]
  else
    let Just i = ind in (take i str) : (split c (drop (i+1) str))
  where
    ind = elemIndex c str

main = putStrLn =<< return . unwords . (split ',') =<<getLine


Measured memory_bytes: 380
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n,d,q,a[500010],b[500010],f[500010];
int main()
{
	scanf("%d%d",&n,&d);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	b[0]=d;
	for (int i=1;i<=n;i++)
	{
		if (2*b[i-1]>a[i])
		{
			b[i]=abs(a[i]-b[i-1]);
		}
		else
		{
			b[i]=b[i-1];
		}
	}
	f[n+1]=0;
	for (int i=n;i;i--)
	{
		if (a[i]<=2*f[i+1]+1)
		{
			f[i]=f[i+1]+a[i];
		}
		else
		{
			f[i]=f[i+1];
		}
	}
	scanf("%d",&q);
	while (q--)
	{
		int x;
		scanf("%d",&x);
		if (b[x-1]>f[x+1])
		{
			puts("YES");
		}
		else
		{
			puts("NO");
		}
	}
    return 0;
}
//形之美，人人可见，心之美，非眼能看到，我愿意独享。 

Measured memory_bytes: 7808
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  cin >> n;

  if(n == 1){
    cout << "Hello World\n";
  }else{
    int a, b;
    cin >> a >> b;
    cout << a + b << "\n";
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

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

int H, W;
ll A[210][210];
ll dp[210][210][410];

void solve() {
	cin >> H >> W;
	rep(i, 0, H) {
		rep(j, 0, W) {
			cin >> A[i][j];
		}
	}
	if(H <= 2) {
		ll sum = 0;
		rep(i, 0, H) {
			rep(j, 0, W) {
				sum += A[i][j];
			}
		}
		cout << sum << "\n"; return;
	}
	dp[0][0][0] = A[0][0];
	rep(i, 0, H) {
		rep(j, 0, W) {
			rep(k, 0, H + W - 3) {
				if(dp[i][j][k]) {
					int x1 = i, y1 = k - x1;
					int x2 = j, y2 = k - x2;
					rep(m, 0, 2) {
						rep(n, 0, 2) {
							int nx1 = x1 + dx[m], ny1 = y1 + dy[m];
							int nx2 = x2 + dx[n], ny2 = y2 + dy[n];
							// debug(x1, y1, x2, y2, nx1, ny1, nx2, ny2);
							if(nx1 < H && nx2 < H && ny1 < W && ny2 < W) {
								if(nx1 != nx2 || ny1 != ny2) {
									MAX(dp[nx1][nx2][k + 1], dp[i][j][k] + A[nx1][ny1] + A[nx2][ny2]);
								}
							}
						}
					}
				}
			}
		}
	}
	cout << dp[H - 2][H - 1][H + W - 3] + A[H - 1][W - 1] << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 137728
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll n;
    cin >> n;
    if(n%1000 == 0)cout << 0 << endl;
    else cout << 1000 - n%1000 << endl;
}

Measured memory_bytes: 3648
# Heaps - Priority Queue
import heapq
op = input().split()
heap = []
while not op[0] == 'end':
    if op[0] == 'insert':
        heapq.heappush(heap, -int(op[1]))
    elif op[0] == 'extract':
        v = heapq.heappop(heap)
        print(-v)
    op = input().split()


Measured memory_bytes: 47144
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define l first
#define r second

using namespace std;

const int maxn = 2e5 + 1;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string x; cin >> x;
    int cln = 0, cbl = 0;
    for (int i = 0; i < x.size(); i++) {
        cbl += (x[i] == 'S' ? 1 : -1);
        if (cbl < 0) {cbl = 0; ++cln;}
    }
    cout << cln + cbl;
    return 0;
}


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

public class Main {

	static int[][] map;
	static int a, b;
	static int route;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0 0")) {
			a = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			b = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
			map = new int[a][b];
			route = 0;

			int a1, b1, n = Integer.parseInt(br.readLine());
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				a1 = Integer.parseInt(line.substring(0, line.indexOf(' ')));
				b1 = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
				map[a1 - 1][b1 - 1] = 1;
			}
			go(new int[] { 0, 0 });
			System.out.println(route);
		}

	}

	static void go(int[] p) {
		if (p[0] + 1 == a && p[1] + 1 == b) {
			route++;
			return;
		}

		int[] e = east(p);
		int[] n = north(p);
		if (e != null)
			go(e);
		if (n != null)
			go(n);
	}

	static int[] east(int[] p) {
		if (p[0] + 1 < a && map[p[0] + 1][p[1]] != 1) {
			int[] q = (int[]) p.clone();
			q[0]++;
			return q;
		} else {
			return null;
		}
	}

	static int[] north(int[] p) {
		if (p[1] + 1 < b && map[p[0]][p[1] + 1] != 1) {
			int[] q = (int[]) p.clone();
			q[1]++;
			return q;
		} else {
			return null;
		}
	}
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

int N, K;
vector<ll> a;
 
ll dfs(int i, int k, ll sum, ll ma){
    if (k == K) return sum;
    if (i == N) return longinf;

    ll ret;
    if (ma < a[i]) {
        ret = dfs(i + 1, k + 1, sum, a[i]);
    } else {
        ret = min(dfs(i + 1, k + 1, sum + ma + 1 - a[i], ma + 1), dfs(i + 1, k, sum, ma));
    }
    
    return ret;
}

int main() {
    cin >> N >> K;

    REP(i, N) {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }

    cout << dfs(0, 0, 0, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int a,b,c;
  int ans=0;

  scanf("%d %d %d",&a,&b,&c );

  if( (ans = (( b + c) - a)) < 0)ans = 0;
  printf("%d\n",  ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


signed main() {
  int n,m;cin>>n>>m;
  pair<int,int> p[100000];rep(i,n)cin>>p[i].first>>p[i].second;
  sort(p,p+n);
  int ans = 0;
  rep(i,n){
    if(m <= 0)break;
    if(m >= p[i].second){
      m -= p[i].second;
      ans += p[i].first * p[i].second;
    }else{
      ans += m * p[i].first;
      m = 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>

using namespace std;

/*int main (){
	int h, m;
	cin >> h >> m;
	while( h!=0 && m!=0 ){
		for(int i=0; i<h; i++){
			for(int j=0; j<m; j++)
				cout << "#";

	        cout << endl;
		}
	}
	
	return 0;
}
*/




int main (){


	int h, w;
	cin >> h >> w;

	while( h!=0 && w!=0 ){
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++) cout << "#";
			cout << endl;
		}
		cout << endl;
		cin >> h >> w;
	}


	return 0;
}

Measured memory_bytes: 3060
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);
        int kin = 100000;
        int ans;
        for(int i = 0; i < n; i++) {
            kin *= 1.05;//1.05倍
            //切り上げ
            if(kin%1000!=0) {
                kin -= kin%1000;
                kin+=1000;
            }
        }
        System.out.println(kin);
        
        
    
    }
 } 


Measured memory_bytes: 25988
#include<iostream>
using namespace std;
int main()
{
    int n, n_4 = 0, n_2 = 0, n_other = 0, temp;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> temp;
        if(temp % 4 == 0)
            n_4++;
        else if(temp % 2 == 0)
            n_2++;
        else
            n_other++;
    }
    if(n_2 != 0)
    {
        if(n_4 >= n_other)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else
    {
        if(n_4 >= n_other - 1)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
A,B,C,X,Y = map(int, input().split())
a = min(X,Y)
b = min(A+B,2*C)
price=a*b
if X<Y:
  price+=(Y-X)*min(B,2*C)
else:
  price+=(X-Y)*min(A,2*C)
print(price)

Measured memory_bytes: 3060
// abc129_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;

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

template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

template <typename T>
using Mat = vector<vector<T>>;

template <typename T>
Mat<T> calc_mat_mod(Mat<T> A, Mat<T> B, T mod){
    Mat<T> C;
    C.assign(A.size(), vector<T>(B[0].size(), 0));

    REP(i, A.size()) {
        REP(j, B[0].size()) {
            REP(k, A[0].size()){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
            }
        }
    }
    return C;
}

template <typename T>
vector<T> calc_mat_vec_mod(Mat<T> A, vector<T> x, T mod){
    vector<T> y(x.size(), 0);

    REP(i, A.size()) {
        REP(k, A[0].size()){
            y[i] = (y[i] + A[i][k] * x[k]) % mod;
        }
    }
    return y;
}

template <typename T>
Mat<T> mat_pow_mod(Mat<T> A, ll n, T mod) {
    Mat<T> B;
    B.assign(A.size(), vector<T>(A.size(), 0));
    REP(i, A.size()) B[i][i] = 1;

    while(n > 0) {
        if (n & 1) {
            B = calc_mat_mod(A, B, mod);
        }
        A = calc_mat_mod(A, A, mod);
        n >>= 1;
    }
    return B;
}

ll d_10[37];

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt");
    cin.rdbuf(in.rdbuf());
#endif

    ll L, A, B, M;
    cin >> L >> A >> B >> M;

    d_10[0] = 1;
    REP(i, 36){ d_10[i+1] = (d_10[i] * 10); }

    ll now_l = 0;
    ll s = A % M;
    ll ans = A % M;
    Mat<ll> mat;
    vector<ll> x{ans, s, B%M};
    for (int d = 1; d < 40 && now_l < L-1; d++) {
        if (d_10[d] - A - 1 < 0) continue;

        ll next_l = (d_10[d] - A - 1) / B;

        mat.assign({
            {d_10[d]%M, 1, 1},
            {0,       1, 1},
            {0,       0, 1}
        });

        ll l_cnt = min(next_l, L-1) - now_l;
        Mat<ll> mat_l = mat_pow_mod(mat, l_cnt, M);
        x = calc_mat_vec_mod(mat_l, x, M);
        now_l = next_l;
    }

    print(x[0]);

    return 0;
}



Measured memory_bytes: 256
import sys
from collections import Counter

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG: {} -> {}'.format(name, val), file=sys.stderr)
            return None

N = int(input())
cnt_A = Counter(map(int, input().split()))

# debug(cnt_A, locals())
# debug(cnt_A.values(), locals())

dabuli = sum(cnt_A.values()) - len(cnt_A.values())

if dabuli % 2 == 0:
    ans = N - dabuli
else:
    ans = N - (dabuli + 1)

print(ans)

Measured memory_bytes: 22636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll ans=0,count=0;
  string s;
  cin>>s;
  for(ll i=0;i<s.size();i++){
    if(s[i]=='W'){
      ans+=i-count;
      count++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3708
import kotlin.*


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val s = sc.next()

        for(i in 0 until s.length -1){
            if(s[i] == s[i+1]){
                println("${i+1} ${i+2}")
                return
            }
        }

        for(i in 0 until s.length -2){
            if(s[i] == s[i+2]){
                println("${i+1} ${i+3}")
                return
            }
        }

        println("-1 -1")
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 39372
use proconio::input;
use std::collections::HashSet;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

fn main() {
    input! {
        k: i64,
    }

    let mut count: i64 = 0;
    let mut map: HashSet<i64> = HashSet::new();
    let mut s = 0;
    loop {
        s = s * 10 + 7;
        count += 1;
        s = s % k;
        if s == 0 {
            println!("{}", count);
            return;
        }
        if map.contains(&s) {
            println!("-1");
            return;
        }
        map.insert(s);
    }
}


Measured memory_bytes: 29660