akhauriyash/Code-Regression huggingface dataset:
use io::*;
use std::cmp;
use std::collections::BinaryHeap;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let mut v: Vec<Vec<usize>> = sc.next_mat(2, n);
    for i in 0..n {
        if v[i][0] > v[i][1] {
            let t = v[i][0];
            v[i][0] = v[i][1];
            v[i][1] = t;
        }
    }
    let mut mini = 0;
    let mut maxi = 0;
    for i in 1..n {
        if v[mini][0] > v[i][0] {
            mini = i;
        }
        if v[maxi][1] < v[i][1] {
            maxi = i;
        }
    }
    let min1 = v[mini][0];
    let min2 = v.iter().min_by_key(|x| x[1]).unwrap()[1];
    let max1 = v.iter().max_by_key(|x| x[0]).unwrap()[0];
    let max2 = v[maxi][1];
    let mut ans = (max1 - min1) * (max2 - min2);

    if maxi != mini {
        let mut bh: BinaryHeap<(usize,usize)> = BinaryHeap::new();
        for i in 0..n {
            bh.push((v[i][1],v[i][0]));
        }
        loop {
            let (a,b) = bh.pop().unwrap();
            if a > b && b != min1 {
                bh.push((b,a));
            } else {
                bh.push((a,b));
                break;
            }
        }
        let bv = bh.into_vec();
        let r = bv.iter().map(|x| x.0).max().unwrap() - bv.iter().map(|x| x.0).min().unwrap();
        ans = cmp::min(ans, (max2 - min1) * r);
    }
    println!("{}",ans);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 23276
using System;

class main
{
    public static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        int a = int.Parse(s[0]), b = int.Parse(s[1]);
        int d = a / b;
        int r = a % b;
        double f = (double)a / b;

        Console.WriteLine("{0} {1} {2:f5}", d, r, f);
    }
}

Measured memory_bytes: 9280
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
const long long MOD = 1000000007;
int S[200];
long long dp[100001];
long long pow(long long m, long long n){
    long long res = 1;
    while(n > 0){
        if(n & 1) {
            res = (res * m) % MOD;
        }
        m = (m * m) % MOD;
        n >>= 1;
    }
    return res;
}

long long inverse(long long a){
    return pow(a, MOD - 2);
}

int main(){
  int N;
  int X;
  cin >> N >> X;
  for(int i = 0; i < N; i++){
    cin >> S[i];
  }
  sort(S, S + N);
  for(int i = 0; i <= X; i++){
    int smaller_ind = -1;
    for(int j = N - 1; j >= 0; j--){
      if(i >= S[j]){
        smaller_ind = j;
        break;
      }
    }
    if(smaller_ind < 0){
      dp[i] = i;
      continue;
    }
    long long denom = inverse(smaller_ind + 1);
    for(int j = 0; j <= smaller_ind; j++){
      dp[i] = (dp[i] + (denom * dp[i % S[j]]) % MOD) % MOD;
    }
  }

  long long fact_n = 1;
  for(int i = 0; i < N; i++){
    fact_n = (fact_n * (i + 1)) % MOD;
  }
  cout << (dp[X] * fact_n) % MOD << endl;
  return 0;
}


Measured memory_bytes: 1024
from collections import defaultdict
from itertools import combinations

N = int(input())
testimonies = []
for _ in range(N):
    A = int(input())
    ts = defaultdict(set)
    for _ in range(A):
        x, y = map(int, input().split())
        x -= 1
        ts['honest' if y else 'not'].add(x)
    testimonies.append(ts)

for n in range(N, 0, -1):
    for honests in combinations(range(N), r=n):
        hs = set()
        ns = set()
        for i in honests:
            hs |= testimonies[i]['honest']
            ns |= testimonies[i]['not']
        if not hs & ns and not hs - set(honests) and not set(honests) & ns:
            print(n)
            break
    else:
        continue
    break
else:
    print(0)

Measured memory_bytes: 45276
//
//  main.cpp
//  ABC158D
//
#include <iostream>
#include<string>
#include<algorithm> // reverse
using namespace std;
int main(int argc, const char * argv[]) {
    string S,TMP;
    string L;
    string R;
    cin>>S;
    int Q;
    cin >> Q;
    int T;
    int F;
    string C;
    int direction=0;
    int num=0;
    for (int i=0; i<Q; i++) {
        cin>>T;
        if (T==1) {
            direction++;
            direction=direction%2;
            num++;
            swap(R,L);// 左側の文字列と右側の文字列を入れ替える
        }
        if (T==2) {
            cin>>F;
            cin>>C;
            if (F==1) { // 左側に足す文字、最終的に反転するので末尾に追加しておく
                L=L+C;
            }
            if(F==2){ // 右側に足す文字
                R=R+C;
            }
        }
    }
    reverse(L.begin(), L.end()); // 左側になった文字列Lは最後に反転する
    if (num%2==1) {
        reverse(S.begin(), S.end()); // 前後の反転が奇数回なら文字列Sを反転する
    }
    cout<<L<<S<<R<<endl;
    return 0;
}


Measured memory_bytes: 1456
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	/**
	 * AcCepted
	 * @param 4 ≤ |S| ≤ 10

	 */
	public static void main(String... args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.next();
			List<String> list = Arrays.asList(s.split(""));
			String ans = "AC";

			if (list.get(0).equals("A")
					&& list.contains("C")
					&& !list.get(1).equals("C")
					&& !list.get(list.size() - 1).equals("C")) {
				int count = 0;
				for (String t : list) {
					if (Character.isUpperCase(t.charAt(0))) {
						count ++;
					}
				}
				if (count > 2) {
					ans = "WA";
				}
			} else {
				ans = "WA";
			}
			System.out.print(ans);
		}
	}
}

Measured memory_bytes: 21716
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

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

#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second

using namespace std;
using ll = long long;
using namespace __gnu_pbds;

//#define int ll

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 10 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7;

void solve() {
    ll a , b ,c , d;
    cin >> a >> b >> c >> d;
    cout << max({a*c , a*d , b*c , b*d});
}

/*
*/
main() {
    ios;
    int tt = 1;
    //cin >> tt;
    while(tt --) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
import java.io.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
class Main{
    public static void main(String[] a){
    	String n = "";
    	String at = "@";
    	Scanner scan = new Scanner(System.in);
    	while (scan.hasNext()){
    	n = scan.next();

    	String  after = "";
    	for (int i = 0;i < n.length();i++){
    		if(n.charAt(i) == '@'){
    			for(int k = 0;k < Integer.parseInt(String.valueOf(n.charAt(i+1)));k++){
    				after += n.charAt(i + 2);
    			}
    			i = i + 2;
    		}else{
    			after += n.charAt(i);
    		}
    	}
    	System.out.println(after);
    	}
    	
    	}
 }

Measured memory_bytes: 25892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int N = sc.nextInt();
		int []A = new int [N];
		int i, j, t, k, l;
		int count = 0;
		
		for (i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		for(j = 0; j <= N-1; j++) {
			for(k = N-1;k > j;k--) {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			}
			
		}
		
		for (l = 0;l < N - 1; l++) {
			System.out.print(A[l] + " ");
		}
		System.out.println(A[N-1]);
		System.out.println(count);
	}
}


Measured memory_bytes: 26312
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define int ll

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define fst first
#define snd second
#define pb push_back

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

double log5(double x) {
    return log(x) / log(5);
}

signed main() {
    int N;

    cin >> N;

    if (N < 2 || N % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }

    // 圧倒的2の因数により、それは気にしなくていい
    // 5の因数の数を数えればよい。

    int digits = log5(N);
    int ans = 0;
    FORE(i, 1, digits) {
        // 5^i * 2, 5^i * 4, 5^i *6 ... maxは?
        int a = pow(5, i);
        int b = pow(5, i+1);

        // 5の奇数倍は除きたい…

        int num = (N / a) / 2 - (N / b) / 2;
        debug(i);
        debug(num);
        ans += num * i;
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int sum = 0;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++)
    {
        sum += ((int)s[i] - '0');

    }
    if(sum % 9 == 0)
    {
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    //cout << sum << endl;

}


Measured memory_bytes: 3720
use std::cmp::min;
use core::ops::Bound::Excluded;
use core::ops::Bound::Included;
use std::collections::BTreeSet;
use std::cmp::Ordering;
use std::fmt::Debug;

fn read_line() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("No Line");
    buffer
}
fn read_lines<R, T: Fn(&str)->R> (count: usize, transformer: T) -> Vec<R> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for _ in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(transformer(buffer.trim()));
        buffer.clear();
    }
    vec
}
fn read_value<T: std::str::FromStr>() -> T {
    read_line().trim().parse().ok().unwrap()
}
fn read_values<T: std::str::FromStr>() -> Vec<T> {
    read_line().trim().split(' ').map(|x| x.parse().ok().expect("Can't Parse")).collect::<Vec<T>>()
}
fn read_tabulate<T: std::str::FromStr>(count: usize) -> Vec<T> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for _ in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(buffer.trim().parse().ok().expect("Can't Parse"));
        buffer.clear();
    }
    vec
}
macro_rules! define {
    () => {};
    ($($token:tt)*) => {
        let mut iter = read_values::<String>().into_iter();
        define_iter!(iter, $($token)*);
    };
}
macro_rules! define_iter {
    ($iter:expr) =>{};
    ($iter:expr,) =>{};
    ($iter:expr, $id:ident:$t:tt $($tail:tt)*) => {
        let $id: $t = $iter.next().unwrap().parse().ok().expect("Can't Parse");
        define_iter!($iter, $($tail)*);
    };
    ($iter:expr, mut $id:ident:$t:tt $($tail:tt)*) => {
        let mut $id: $t = $iter.next().unwrap().parse().ok().expect("Can't Parse");
        define_iter!($iter, $($tail)*)
    };
}
macro_rules! freeze {
    ($($id:ident), *) => {
        $(let $id = $id;)*
    };
}
struct KeyValue<K, V> {
    key: K,
    value: V
}
impl <K: PartialOrd, V> PartialEq for KeyValue<K, V> {
    fn eq(&self, other: &Self) -> bool {
        self.key.eq(&other.key)
    }
}
impl <K: PartialOrd, V> Eq for KeyValue<K, V> {}
impl <K: PartialOrd, V> PartialOrd for KeyValue<K, V> {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        self.key.partial_cmp(&other.key)
    }
}
impl <K: PartialOrd, V> Ord for KeyValue<K, V> {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        self.key.partial_cmp(&other.key).ok_or("Can't Compare").unwrap()
    }
}

fn main() {
    define! {
        n: usize
        a: i64
        b: i64
    }
    let cities = read_values::<i64>();
    let mut time = 0i64;
    for i in 1 .. n {
        time += min(a * (cities[i] - cities[i - 1]), b);
    }
    println!("{}", time);
}


Measured memory_bytes: 3900
#include<cstdio>
#include<algorithm>
#include<queue>
#define mp make_pair 
using namespace std;
typedef long long ll;
typedef pair<ll,int>pa;
const ll INF=1LL<<61;
ll x[200010],a[200010];
struct que{
	priority_queue<pa>q;
	int flag[100010];
	void Push(pa x)
	{
		q.push(x);
	}
	pa Top()
	{
		while (!q.empty()&&flag[q.top().second]) q.pop();
		if (q.empty()) return mp(-INF,0);
		return q.top();
	}
	void Del(int pos)
	{
		flag[pos]=1;
	}
}Q1,Q2;
int main()
{
	int n;
	ll C;
	scanf("%d%lld",&n,&C);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&x[i],&a[i]);
	}
	ll val=0;
	for (int i=n;i;i--)
	{
		ll dist=C-x[i];
		val+=a[i];
		Q1.Push(mp(val-dist,i));
	}
	ll ans=max(0LL,Q1.Top().first);
	val=0;
	for (int i=1;i<=n;i++)
	{
		val+=a[i];
		ll dist=x[i];
		Q1.Del(i);
		ans=max(ans,val-dist-dist+Q1.Top().first);
	}
	val=0;
	for (int i=1;i<=n;i++)
	{
		ll dist=x[i];
		val+=a[i];
		Q2.Push(mp(val-dist,i));
	}
	ans=max(ans,Q2.Top().first);
	val=0;
	for (int i=n;i;i--)
	{
		val+=a[i];
		ll dist=C-x[i];
		Q2.Del(i);
		ans=max(ans,val-dist-dist+Q2.Top().first);
	}
	printf("%lld\n",ans);
	return 0;
 } 

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

using namespace std;

int main(){
	
	while(1){
		int n,m,a;
		cin >> n >> m >> a;
		if(n==0) break;
		pair<int,pair<int,int> > p[m];
		for(int i=0;i<m;i++){
			cin >> p[i].first >> p[i].second.first >> p[i].second.second;
		}
		int c[n+1];
		for(int i=1;i<=n;i++) c[i]=i;
		sort(p,p+m);
		for(int i=0;i<m;i++){
			swap(c[p[i].second.first],c[p[i].second.second]);
		}
		cout << c[a] << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a, b, c, k;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		k = sc.nextInt();
		int sum = 0;
        if (a < k) {
            k -= a;
            sum += a;
            if (b < k) {
                k -= b;
                if (c < k) {
                    System.out.println(sum-c);
                } else if (c == k) {
                    System.out.println(sum-k);
                } else {
                    System.out.println(sum-k);
                }
            }
            else if (b == k) {
                System.out.println(sum);
            } else {
                System.out.println(sum - k);
            }
            
        } else if (a == k) {
            System.out.println("" + (a));
        } else {
            System.out.println("" + k);
        }
		
	}
}

Measured memory_bytes: 38720
#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 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);
  ll x; std::cin >> x;
  if ( x%11 == 0 ) std::cout << (x/11)*2 << std::endl;
  else if ( x%11 <= 6 ) std::cout << (x/11)*2 + 1 << std::endl;
  else std::cout << (x/11)*2 + 2 << std::endl;

  return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>

const int N = 1e5 + 100;
vector<vector<int>> g(N);
vector<bool> visited(N, false);
vector<int> topo;
vector<int> dp(N, 0);
void topo_sort(int v) {
    visited[v] = true;
    for (auto &u : g[v]) {
        if (!visited[u]) {
            topo_sort(u);
        }
    }
    topo.push_back(v);
}
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
    }
    for (int i = 1; i <= n; i++) {
        if (!visited[i]) {
            topo_sort(i);
        }
    }
    reverse(topo.begin(), topo.end());
    for (auto &v : topo) {
        for(auto &u : g[v]) {
            dp[u] = max(dp[u], dp[v] + 1);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << "\n";
}

Measured memory_bytes: 9720
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

#define DIV 1000000007
long long kaidan[10000000];

void kaical(long long n){
	kaidan[0] = 1;
	for(long long i = 1; i < n; i++){
		kaidan[i] = kaidan[i-1] * i;
		kaidan[i] %= DIV;
	}
}

long long modpow(long long ori, long long po){
	long long res = 1;
	while(po > 0){
		if(po&1){
			res *= ori;
			res %= DIV;
		}
		ori *= ori;
		ori %= DIV;
		po >>= 1;
	}
	return res;
}

//nCk
long long combination(long long n, long long k){
	if(n == 0 && k == 0)return 1;
	if(n < k || n < 0)return 0;
	long long n_kai = kaidan[n];
	long long k_kai = kaidan[k];
	long long nmk_kai = kaidan[n-k];

	long long ans = n_kai * modpow(k_kai, DIV - 2);
	ans %= DIV;
	ans *= modpow(nmk_kai, DIV-2);
	ans %= DIV;
	return ans;
}

int main(){
	long long X, Y;
	cin >> X >> Y;
	if(X > Y) swap(X, Y);

	long long pat1 = Y - X;
	Y -= pat1*2;
	X -= pat1;
	if(X < 0) {
		cout << 0 << endl;
		return 0;
	}

	if(X % 3 != 0){
		cout << 0 << endl;
		return 0;
	}

	pat1 += X/3;
	long long pat2 = X/3;


	kaical(1000005);
	cout << combination(pat1+pat2, pat1) << endl;




}


Measured memory_bytes: 11432
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50



def run():
    H, W, M = map(int, sysread().split())
    Hs = defaultdict(lambda:0)
    Ws = defaultdict(lambda:0)
    hws = set()
    for i in range(M):
        h,w = map(int, sysread().split())
        hws.add((h,w))
        Hs[h] += 1
        Ws[w] += 1

    max_hs = []
    max_h_val = max(Hs.values())
    for h, count in Hs.items():
        if count == max_h_val:
            max_hs.append(h)

    max_ws = []
    max_w_val = max(Ws.values())
    for w, count in Ws.items():
        if count == max_w_val:
            max_ws.append(w)
    #print(Hs)
    #print(Ws)
    #print(hws)
    #print(max_w_val)
    #print(max_ws)
    for hh in max_hs:
        for ww in max_ws:
            if not (hh, ww) in hws:
                print(max_h_val + max_w_val)
                return
    print(max_h_val + max_w_val - 1)




if __name__ == "__main__":
    run()

Measured memory_bytes: 80536
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        //System.setIn(Main.class.getResourceAsStream("input"));
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int h = sc.nextInt();
        int n = sc.nextInt();
        sc.nextLine();
        int[] a = toArray(sc.nextLine());
        int sum = Arrays.stream(a).sum();
        System.out.println((h-sum) > 0 ? "No" : "Yes");
    }

    private static int nextInt(Scanner sc) {
        return Integer.valueOf(sc.nextLine());
    }

    private static int[] toArray(String text) {
        return Arrays.stream(text.split("\\s")).mapToInt(Integer::valueOf).toArray();
    }

}

Measured memory_bytes: 49424
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll k, n;
    ll s = 0;
    cin >> k >> n;

    vector<ll> a(n);

    cin >> a[0];

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

        s = max(s, a[i] - a[i - 1]);
    }

    s = max(s, k - a[n - 1] + a[0]);

    cout << k - s << endl;
}

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

int main(){
  int N;
  string S;
  cin>>N >>S;
  string P = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
  for (int i=0;i<S.size(); i++) {
    for (int j=0;j<27; j++) {
      if(S.at(i)==P.at(j)) {
        S.at(i)=P.at(j+N);
        break;
      }
    }
  }
  
  cout << S << endl;


    return 0;
}

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

int main() {
 
  int N,A,B;
  cin >> N >> A >> B;
  
  int ans=0;
  for(int i=1; i<N+1; i++){
    int c=0, t=i;
    for(int j=0; j<5; j++){
      c += t % 10;
      t /= 10;
    }
    if(A <= c && c <= B){
      ans += i;
    }
  }

 cout << ans << endl;
  
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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 vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  string S;
  cin>>S;
  ll DP[S.size()][2];
  // DP[i][j] i桁まで見てあり得る文字列の数(j=0なら既にS未満が確定)
  REP(i,S.size()){
    REP(j,2){
      DP[i][j]=0;
    }
  }
  DP[0][0]=1;
  DP[0][1]=2;
  
  for(int i=1; i<S.size(); ++i){
    if(S[i]=='0'){
      DP[i][1]=DP[i-1][1];
      DP[i][0]=3*DP[i-1][0];
    }
    if(S[i]=='1'){
      DP[i][1]=2*DP[i-1][1];
      DP[i][0]=3*DP[i-1][0]+DP[i-1][1];
    }
    
    DP[i][1]%=MOD;
    DP[i][0]%=MOD;
  }
  
  co((DP[S.size()-1][0]+DP[S.size()-1][1])%MOD);
  return 0;
}

Measured memory_bytes: 2048
N, M = map(int, input().split())
A = list(map(int, input().split()))
S = [0]*(N+1)
mods = {}
ans = 0

mods[0] = 1

for i in range(N):
    S[i+1] = A[i] + S[i]
    t = S[i+1]%M
    if t in mods:
        mods[t] += 1
    else:
        mods[t] = 1

for k, v in mods.items():
    ans += v*(v-1)//2

print(ans)

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

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

    int x;
    cin >> x;
    int ans = x / 500 * 1000;
    x %= 500;
    cout << ans + x / 5 * 5 << endl;
}


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


int main(){
    int N,M;
    cin >> N >> M;

    vector<int> H(N,0);
    for(int i=0;i<N;i++) cin >> H[i];

    int A,B;
    vector<int> bad(N,0);
    for(int i=0;i<M;i++){
        cin >> A >> B;
        if(H[A-1]<=H[B-1]){
            bad[A-1] = 1; // 悪である
        }
        if(H[A-1]>=H[B-1]){
            bad[B-1] = 1; // 悪である
        }
    }

    int count=0;
    for(int i=0;i<N;i++){
        if(bad[i]==0){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 4048
#include <cstdio>
#include <cstring>
#define int long long
#define dp(i,j) dp[(i)+2300][(j)+2300]
int dp[5001][5001],n,a[200001],b[200001],fac[100001];const int p=1e9+7;
int qpow(int bs,int ex){int ans=1;while(ex){if(ex&1)ans=1ll*ans*bs%p;bs=1ll*bs*bs%p;ex>>=1;}return ans;}
int binom(int n,int m){return 1ll*fac[n]*qpow(fac[m],p-2)%p*qpow(fac[n-m],p-2)%p;}
signed main()
{
	scanf("%lld",&n);for(int i=1;i<=n;++i)scanf("%lld%lld",a+i,b+i);fac[0]=1;
	for(int i=1;i<=n;++i)++dp(-a[i],-b[i]);for(int i=1;i<=100000;++i)fac[i]=1ll*fac[i-1]*i%p;
	for(int i=-2020;i<=2020;++i)for(int j=-2020;j<=2020;++j)(dp(i,j)+=dp(i-1,j)+dp(i,j-1))%=p;
	int ans=0;for(int i=1;i<=n;++i)(ans+=dp(a[i],b[i]))%=p,ans-=binom((a[i]+b[i])*2,a[i]*2),ans=(ans%p+p)%p;
	printf("%lld\n",1ll*ans*500000004%p);return 0;
}

Measured memory_bytes: 164864
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize, a: usize, b: usize};
    let mut result = 0;

    for i in 1..n + 1 {
        let i_s = i.to_string();
        let mut sum = 0;
        for i_num in i_s.as_str().chars() {
            // println!("{}", i_num);
            sum += i_num as usize - 48;
            // println!("{}", sum)
        }

        if sum >= a && b >= sum {
            result += i;
        }
    }

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


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

int main() {
    string s;
    cin >> s;
    int a[s.size()] = {0};
    for(int i = 0; i < s.size()-1; ++i) {
        if(s[i] == 'R' && s[i+1] == 'L') {
            a[i] = 1, a[i+1] = 1;
            // ←
            for(int j = i - 1; j >= 0; --j) {
                if(s[j] == 'R') {
                    if((i-j)%2 == 0) a[i]++;
                    else a[i+1]++;
                } else {
                    break;
                }
            }
            // →
            for(int j = i + 2; j < s.size(); ++j) {
                if(s[j] == 'L') {
                    if((j-i)%2 == 0) a[i]++;
                    else a[i+1]++;
                } else {
                    break;
                }
            }
        }
    }

    for(int i = 0; i < s.size(); ++i) cout << a[i] << ' ';
    cout << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
 
Node root;
 
 
Node treeSearch(Node x, int k){
  if(x == NIL || k == x->key) return x;
  if(k < x->key) return treeSearch(x->left,k);
  else return treeSearch(x->right,k);
 
}
 
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
    
  if(y==NIL) root = z;
  else if(z->key<y->key) y->left = z;
  else y->right = z;
 
 
 
}
 
void inorder(Node u){
 if(u!=NIL){
    if(u->left!=NIL) inorder(u->left);
     
    printf(" %d",u->key);
        
    if(u->right!=NIL) inorder(u->right);
   }
}
void preorder(Node u){
   printf(" %d",u->key);
  if(u!=NIL){
    if(u->left!=NIL) preorder(u->left);
     
    if(u->right!=NIL) preorder(u->right); 
  }
}
 
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }
 
  return 0;
}

Measured memory_bytes: 19364
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int Q;
  cin >> Q;
  int count = 0;
  string front, rear;
  for(int i = 0; i < Q; i++) {
    int t;
    cin >> t;
    if(t == 1) {
      count += 1;
    }
    else {
      int f;
      char c;
      cin >> f >> c;
      if((f + count) % 2 == 1) {
        front += c;
      }
      else {
        rear += c;
      }
    }
  }
  reverse(front.begin(), front.end());
  s = front + s + rear;
  if(count % 2 != 0) {
    reverse(s.begin(), s.end());
  }
  cout << s << endl;
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){
    int w, a, b,ans;
    cin >>w >> a >> b;
    if(a < b){
        if(a+w >= b)
            ans=0;
        else
            ans=b-(a+w);
    }
    else{
        if(b+w >= a)
            ans=0;
        else
            ans=a-b-w;
    }
    cout << ans fin;
  
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



Measured memory_bytes: 256
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=mi()
ans=1
for i in a:
  if 1<=i<=9:
    ans*=i
  else:
    print(-1)
    sys.exit()
print(ans)

Measured memory_bytes: 3440
#include<bits/stdc++.h>
#define sz 100003
using namespace std;
int main() {
    long long int n,s=0;
    cin>>n;
    int ara[sz],ara2[sz];

    for(int i=1;i<=n+1;i++)cin>>ara[i];
     for(int i=1;i<=n;i++)cin>>ara2[i];

       long long int x,y;
     for(int i=1;i<=n;i++)
     {
       x=min(ara[i],ara2[i]);
       ara2[i]-=x;
       y=min(ara[i+1],ara2[i]);
       ara[i+1]-=y;
       s+=x+y;
     }
     cout<<s<<endl;


}


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

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

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	double a, b, x; cin >> a >> b >> x;
	
	if(a * a * b / 2. <= x) printf("%.12lf\n", atan(2. / (a * a * a) * (a * a * b - x)) * 180. / M_PI);
	else printf("%.12lf\n", atan(a * b * b / (2. * x)) * 180. / M_PI);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	float max = -1000000000.0f;
	float min = 1000000000.0f;

	float height;

	while (cin >> height) {
		if (height > max) max = height;
		else if (height < min) min = height;
	}
	cout << max - min << endl;
}

Measured memory_bytes: 1288
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
template <typename T = int>
T in() {
    T temp; cin >> temp; return temp;
}

template <typename VType = int>
list<VType> const LR(VType start, VType end) {
    list<VType> ret; for (VType i = start; i < end; i++) ret.push_back(i); return move(ret);
}

int main() {
    int N;
    cin >> N;
    cout << N* N * N << endl;
    return 0;
}




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

#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 998244353;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 5e5 + 10;

int a[maxn];
int ans[maxn];

vector<int>graph[maxn];
int idx = 1;
map<int,int>mapa;

int tree[4* maxn];


void update(int node, int l, int r, int pos, int val)
{
  if( l > r || l > pos || r < pos)
    return;
  if( l == r && l == pos )
  {
    tree[node] = val;
    return;
  }

  int mid = (l + r) >> 1;
  update(2*node, l, mid, pos, val);
  update(2*node + 1, mid+1, r, pos, val);
  tree[node] = max(tree[2*node], tree[2*node + 1]);
}

int query(int node, int l, int r, int x, int y)
{
  if(l > r || l > y || r < x)
    return 0;
  if( x <= l && r <= y)
  {
    return tree[node];
  }
  int mid = (l + r) >> 1;
  int a = query(2*node, l, mid, x, y);
  int b = query(2*node + 1, mid+1, r, x, y);
  return max(a,b);
}


void dfs(int u, int p)
{
  auto old = query(1, 1, idx, mapa[a[u]] , mapa[a[u]]);
  auto val = query(1, 1, idx, 1 , mapa[a[u] - 1]) + 1;
  update(1, 1, idx, mapa[a[u]], val);
  ans[u] = query(1, 1, idx, 1 , maxn);
  for(const auto &v: graph[u])
  {
    if(v == p)
      continue;
    dfs(v, u);
  }
  update(1, 1, idx, mapa[a[u]], old);
}

int main()
{
  int n;
  ios::sync_with_stdio(false);
  cin >> n;

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

  for(auto &c : mapa)
    c.second = idx++;
  
  for(int i = 1; i < n ; i++)
  {
    int u,v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }

  dfs(1, 0);

  for(int i = 1; i <= n ; i++)
  {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 61284
n, m = map(int, input().split())
ab  = list(list(map(int, input().split())) for _ in range(m))

goal = [0] * n
start = [0] * n

for a, b in ab:
    if a == 1:
        start[b] = 1
    if b == n:
        goal[a] = 1

flg = False
for i in range(n):
    if start[i] and goal[i]:
        flg = True

print('POSSIBLE' if flg else 'IMPOSSIBLE')


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

int main() {
  
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if (A+B > C+D)
    cout << "Left" << endl;
  if (A+B == C+D)
    cout << "Balanced" << endl;
  if (A+B < C+D)
    cout << "Right" << endl;
    
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        s: Chars,
    }

    println!(
        "{}",
        s.iter()
            .enumerate()
            .filter(|(i, &c)| if i % 2 == 0 { c == '0' } else { c == '1' })
            .count()
            .min(
                s.iter()
                    .enumerate()
                    .filter(|(i, &c)| if i % 2 == 1 { c == '0' } else { c == '1' })
                    .count()
            )
    );
}


Measured memory_bytes: 2512
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string s;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  	cin >> s;
  sort(s.begin(), s.end());
  	if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
      	cout << "Yes";
  else
    cout << "No";
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
	int n;
	cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	sort(a.begin(), a.end(),greater<int>());
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			ans = max(ans, a[i] - a[j]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;

struct BIT {
	int *bit;
	int n;
	BIT(int _n) :n(_n) {
		bit = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			bit[i] = 0;
		}
	}
	int sum(int i) {
		int s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i&-i;
		}
		return s;
	}
	void add(int i, int x) {
		while (i <= n) {
			bit[i] += x;
			i += i&-i;
		}
	}
};

vector<PI> v[100001];

int main() {
	int N, M;
	cin >> N >> M;
	rep(i, N) {
		int l, r;
		cin >> l >> r;
		v[r - l + 1].push_back(MP(l, r));
	}
	int sum = 0;
	REP(i, 2, M + 1) sum += v[i].size();
	BIT bit(M + 1);
	rep(i, v[1].size()) {
		bit.add(v[1][i].first, 1);
		bit.add(v[1][i].second + 1, -1);
	}
	cout << N << endl;
	REP(i, 2, M + 1) {
		sum -= v[i].size();
		rep(j, v[i].size()) {
			bit.add(v[i][j].first, 1);
			bit.add(v[i][j].second + 1, -1);
		}
		int ans = sum;
		for (int j = i; j <= M; j += i) {
			ans += bit.sum(j);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
#define int1 long long
#define maxx 1000000007;
using namespace std;
int1 dp[22][1024*1024*8];
int1 recur(int1 a[][30],int1 n,int1 i,int1 mask)
{
    if(i==n)
    {
        return 1;
    }
    if(dp[i][mask]!=-1)
        {
            return dp[i][mask];
        }
        int1 ans1=0;
    for(int1 j=0;j<n;j++)
    {
        if(((mask&(1<<j))==0)&&a[i][j]==1)
        {

            ans1+=(recur(a,n,i+1,(mask|(1<<j))));
        ans1%=maxx;

        }
    }
    dp[i][mask]=ans1%maxx;
    return ans1;

}


int main()
{
    int1 n;
    cin>>n;
    for(int i=0;i<=n;i++)
        for(int j=0;j<=(1<<(n+1));j++)
        dp[i][j]=-1;
    int1 a[30][30];
    for(int1 i=0;i<n;i++)
        for(int j=0;j<n;j++)
        cin>>a[i][j];
        map<int,int> m;
      cout<<recur(a,n,0,0);
      return 0;

}


Measured memory_bytes: 766208
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
const int INF = (1 << 30);

int main(){
  int H, W, h, w;
  int a[50][50], b[50][50], c[50][50];

  cin >> H >> W;
  for(int i = 0 ; i < H ; i++ ){
    for(int j = 0 ; j < W ; j++ ){
      cin >> a[i][j];
    }
  }
  for(int i = 0 ; i < H ; i++ ){
    for(int j = 0 ; j < W ; j++ ){
      cin >> b[i][j];
    }
  }
  cin >> h >> w;
  for(int i = 0 ; i < h ; i++ ){
    for(int j = 0 ; j < w ; j++ ){
      cin >> c[i][j];
    }
  }

  int ret = -INF;
  for(int i = 0 ; i <= H - h ; i++ ){
    for(int j = 0 ; j <= W - w ; j++ ){
      bool flag = false;
      int sum = 0;
      for(int k = 0 ; k < h ; k++ ){
        for(int l = 0 ; l < w ; l++ ){
          if( b[i + k][j + l] != c[k][l]) flag = true, k = h, l = w;
          else sum += a[i + k][j + l];
        }
      }
      if(!flag) ret = max( ret, sum);
    }
  }
  if(ret == -INF) cout << "NA" << endl;
  else cout << ret << endl;

}


Measured memory_bytes: 1188
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int w; string s;
    cin>>s>>w;
    int n = s.length();

    string ans;

    for (int i = 0; i < n; i+=w) ans.push_back(s[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int search(int A[], int n, int key)
{
    int i = 0;
    A[n] = key;
    while (A[i] != key) i++;
    return i != n;
}

int main()
{
    int n, A[10000 + 1], q, key, sum = 0;


    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d", &key);
        if (search(A, n, key)) sum++;
    }

    printf("%d\n", sum);

    return 0;
}



Measured memory_bytes: 2676
import java.text.DecimalFormat;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		DecimalFormat df = new DecimalFormat("0");
		double debt = 100000;
		for(int i=0;i<n;i++){
			debt = debt + (debt * 0.05);
			if(debt % 1000 != 0){
				debt = (debt / 1000 + 1) * 1000;
				debt = debt - debt % 1000;
			}
		}
		System.out.println(df.format(debt));
	}

}

Measured memory_bytes: 17168
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

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

int main()
{
  int a[4], b[4];
  while(cin >> a[0]){
    REP(i,3) cin >> a[i+1];
    REP(i,4) cin >> b[i];

    int hit=0, blow=0;
    REP(i,4){
      if(a[i]==b[i])
	hit++;
      else{
	REP(j,4){
	  if(a[i]==b[j])
	    blow++;
	}
      }
    }

    cout << hit << " " << blow << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int a = 0;
    int b = 0;
    int ab = 0;
    int o = 0;
    while (scanner.hasNext()) {
      String line = scanner.nextLine();
      String[] p = line.split(",");
      if (p[1].equals("A")) {
        a++;
      } else if (p[1].equals("B")) {
        b++;
      } else if (p[1].equals("AB")) {
        ab++;
      } else if (p[1].equals("O")) {
        o++;
      }
    }
    System.out.println(a);
    System.out.println(b);
    System.out.println(ab);
    System.out.println(o);
  }
}

Measured memory_bytes: 17160