akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){  
  int h,w;
  cin >> h >> w;
  rep(i,w+2){ cout<<"#"; } cout<<endl;
  rep(i,h){
    cout<<"#";
    rep(i,w){
      char tmp;
      cin >> tmp; cout << tmp;
    }
    cout<<"#";
    cout<<endl;
  }
  rep(i,w+2){ cout<<"#"; } cout<<endl;
  return 0;
}

Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;
use std::mem;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (_n, _m) = i.read2::<usize, usize>();
    let mut s: Vec<u8> = i.read_line().as_bytes().iter().cloned().collect();
    let mut t: Vec<u8> = i.read_line().as_bytes().iter().cloned().collect();

    if s.len() > t.len() {
        mem::swap(&mut s, &mut t);
    }
    if let Some(len) = solve(&s, &t) {
        writeln!(o, "{}", len).unwrap();
    } else {
        writeln!(o, "-1").unwrap();
    }
}
fn solve(s: &[u8], t: &[u8]) -> Option<usize> {
    let len = lcm(s.len(), t.len());
    for is in 0..s.len() {
        if is * t.len() % s.len() == 0 {
            let it = is * t.len() / s.len();
            if s[is] != t[it] {
                return None;
            }
        }
    }
    Some(len)
}

fn lcm(mut x0: usize, mut x1: usize) -> usize {
    if x0 % x1 == 0 {
        return x0;
    }
    if x1 % x0 == 0 {
        return x1;
    }

    let mut r = 1;
    let end = (min(x0, x1) as f64).sqrt().floor() as usize + 1;
    for n in 2..end {
        let mut i0 = 1;
        while x0 % n == 0 {
            i0 *= n;
            x0 /= n;
        }

        let mut i1 = 1;
        while x1 % n == 0 {
            i1 *= n;
            x1 /= n;
        }
        r *= max(i0, i1);

        if x1 % x0 == 0 {
            x0 = 1;
            break;
        }
        if x0 % x1 == 0 {
            x1 = 1;
            break;
        }
    }

    r * x0 * x1
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

ll mypow(ll a, ll p, ll MOD){
	if(MOD <= 0) return 0;
	if(p == 0) return 1;
	if(p == 1) return (a % MOD);
	if(p & 1) return ((a % MOD) * (mypow(a, p - 1, MOD) % MOD)) % MOD;
	ll x = mypow(a, p / 2, MOD) % MOD;
	return (x * x) % MOD;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	string s;
	cin >> s;
	ll MOD = 0LL;
	rep(i, n) MOD += (s[i] == '1');
	ll MOD1 = MOD + 1, MOD2 = MOD - 1;
	ll cur3 = 0, cur4 = 0;
	reverse(all(s));
	rep(i, n) if(s[i] == '1') (cur3 += mypow(2, i, MOD1)) %= MOD1;
	if(MOD2 > 0) rep(i, n) if(s[i] == '1') (cur4 += mypow(2, i, MOD2)) %= MOD2;
	vi ans;
	rep(i, s.size()){
		if(MOD == 1 && s[i] == '1'){
			ans.pb(0);
			continue;
		}
		int num = 1;
		ll cur1 = cur3;
		ll MOD3 = MOD1;
		if(s[i] == '1') cur1 = cur4, MOD3 = MOD2;
		if(s[i] == '0') (cur1 += mypow(2, i, MOD3)) %= MOD3;
		else cur1 -= mypow(2, i, MOD3);
		while(cur1 < 0) cur1 += MOD3;
		//now we do the operation until we are done
		string nw = "";
		int ppcnt = 0;
		rep(j, 35){
			if(cur1 & (1LL << j)) nw += '1', ppcnt++;
			else nw += '0';
		}
		while(ppcnt){
			ll cur2 = 0;
			rep(j, nw.size()) if(nw[j] == '1') (cur2 += mypow(2, j, ppcnt)) %= ppcnt;
			string nw1 = "";
			ppcnt = 0;
			rep(j, 35){
				if(cur2 & (1LL << j)) nw1 += '1', ppcnt++;
				else nw1 += '0';
			}
			nw = nw1;
			num++;
		}
		ans.pb(num);
	}
	reverse(all(ans));
	rep(i, ans.size()) cout << ans[i] << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 4456
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int c = Integer.parseInt(in.next());
            int x = Integer.parseInt(in.next());
            int y = Integer.parseInt(in.next());
            int ans = a * x + b * y;
            ans = Math.min(ans, c * Math.max(x, y) * 2);

            ans = Math.min(ans, c * x * 2 + b * Math.abs(y - x));
            ans = Math.min(ans, a * Math.abs(x - y) + c * y * 2);

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 21844
#include <cstdio>
int main()
{
    int a[4], b[4];
    while (scanf("%d%d%d%d", a, a+1, a+2, a+3) != EOF) {
        scanf("%d%d%d%d", b, b+1, b+2, b+3);
        int c = 0, d = 0;
        for (int i = 0; i < 4; ++i) if (a[i] == b[i]) c++;
        for (int i = 0; i < 4; ++i)
            for (int j = 0; j < 4; ++j)
                if (i != j && a[i] == b[j]) d++;
        printf("%d %d\n", c, d);
    }
    return 0;
}

Measured memory_bytes: 0
fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn reads<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().split(' ').map(|x| x.parse().unwrap()).collect()
}

use std::collections::BinaryHeap;
use std::cmp::Ordering;

#[derive(Clone, Copy, Eq, PartialEq)]
struct E {
    i: usize,
    j: usize,
    d: i64,
}

impl Ord for E {
    fn cmp(&self, other: &Self) -> Ordering {
        let mut res = other.d.cmp(&self.d);
        if res == Ordering::Equal {
            res = self.i.cmp(&other.i);
            if res == Ordering::Equal {
                res = self.j.cmp(&other.j);
            }
        }

        res
    }
}

impl PartialOrd for E {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

fn main() {
    let hw = reads();
    let mut ts = vec![];
    ts.push(vec![false; hw[1] + 2]);
    let mut res = 0i64;

    for _ in 0..hw[0] {
        let mut xs = vec![];
        xs.push(false);
        for x in get_line().chars().map(|x| x == '.') {
            if x {
                res += 1;
            }
            xs.push(x);
        }
        xs.push(false);

        ts.push(xs);
    }
    ts.push(vec![false; hw[1] + 2]);

    let mut f = false;
    let mut q = BinaryHeap::new();
    
    q.push(E {
        i: 1,
        j: 1,
        d: 0,
    });

    while let Some(e) = q.pop() {
        if e.i == hw[0] && e.j == hw[1] {
            res -= e.d;
            res -= 1;
            f = true;
            break;
        }
        if !ts[e.i][e.j] {
            continue;
        }
        ts[e.i][e.j] = false;

        if ts[e.i - 1][e.j] {
            q.push(E {
                i: e.i - 1,
                j: e.j,
                d: e.d + 1
            });
        }
        if ts[e.i + 1][e.j] {
            q.push(E {
                i: e.i + 1,
                j: e.j,
                d: e.d + 1
            });
        }
        if ts[e.i][e.j - 1] {
            q.push(E {
                i: e.i,
                j: e.j - 1,
                d: e.d + 1
            });
        }
        if ts[e.i][e.j + 1] {
            q.push(E {
                i: e.i,
                j: e.j + 1,
                d: e.d + 1
            });
        }
    }

    if !f {
        res = -1;
    }
    

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

Measured memory_bytes: 4352
gets.to_i
array = gets.split.map(&:to_i)

min = array.inject(:+).abs

array.each_index do |i|
  next if array[i+1..-1].inject(:+).nil?
  abs_diff = (array[0..i].inject(:+) - array[i+1..-1].inject(:+)).abs
  min = abs_diff if abs_diff < min
end

p min


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main(int argc, char *argv[])
{
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
 
    long double max_ratio = -1;
    int m;
    int s;
    for(int a = 0; 100*A*a <= F; ++a)
    {
        for(int b = 0; 100*B*b + 100*A*a <= F; ++b)
        {
            const int water = 100*B*b + 100*A*a;
            for(int c = 0; water + c*C <= F; ++c)
            {
                for(int d = 0; water + c*C + d*D <= F; ++d)
                {
                    const int sugar = c*C + d*D;
                    if(100*sugar > water * E) continue;
                    if(sugar + water == 0) continue;
 
                    long double ratio = (long double)sugar / (water + sugar);
                    if(ratio > max_ratio)
                    {
                        max_ratio = ratio;
                        m = water + sugar;
                        s = sugar;
                    }
                }
            }
        }
    }
    cout << m << ' ' << s << endl;
}

Measured memory_bytes: 256
N, M = map(int, raw_input().split())
heights = map(int, raw_input().split())
connected_max_h = {}
for m in range(M):
	a,b = map(int, raw_input().split())
	a_max = connected_max_h.get(a-1, 0)
	b_max = connected_max_h.get(b-1, 0)
	connected_max_h[a-1] = max(a_max, heights[b-1])
	connected_max_h[b-1] = max(b_max, heights[a-1])

good_count = 0
for n in range(N):
	max_h = connected_max_h.get(n, 0)
	if max_h < heights[n]:
		good_count += 1

print good_count



Measured memory_bytes: 93948
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)

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

string rev(string str)
{
	reverse(str.begin(), str.end());
	return str;
}

int main(void)
{
	int n;
	cin >> n;
	rep(TTT, n) {
		string s;
		set<string> st;

		cin >> s;
		REPI(i, 1, s.size()-1) {
			string s1, s2;
			s1 = s.substr(0, i);
			s2 = s.substr(i, s.size()-i);
			
			st.insert(s1+s2);
			st.insert(s2+s1);
			st.insert(s1+rev(s2));
			st.insert(s2+rev(s1));
			st.insert(rev(s1)+s2);
			st.insert(rev(s2)+s1);
			st.insert(rev(s1)+rev(s2));
			st.insert(rev(s2)+rev(s1));
		}
		cout << st.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1296
#include <iostream>
#include <list>

using namespace std;

int main(){
    string input;
    cin >> input;
    string ans = "Yes";

    for(int i = 0; i < input.size(); i++){
        
        if(i%2 == 1){
            if(input[i] == 'R'){
                ans = "No";
            }
        }
        else{
            if(input[i] == 'L'){
                ans = "No";
            }
        }
        
    }

    cout << ans << endl;
}

Measured memory_bytes: 888
#include<iostream>
using namespace std;
int main(){
  int A,B,C,D,L;
  int J,M;
  int enjoy;
  cin >> L >> A >> B >> C >> D ;
  if(A%C==0){
    J=A/C;
  }else{
    J=A/C+1;
  }
  if(B%D==0){
    M=B/D;
  }else{
    M=B/D+1;
  }
  if(J<M){
    enjoy=L-M;
  }else{
    enjoy=L-J;
  }
  
  cout << enjoy << endl;
  
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int fact(int n)
{
  return (n==1||n==0)?1:n*fact(n-1);
}
long nCr(int n, int r)
{
  long den=1;
  for(int i=2;i<=r;i++) den *=i;
 
  long num=1;
  for(int i=n;i>(n-r);i--) num*=i;

  return num/den;
}
int main()
{
  int n,m;
  cin>>n>>m;
  int count1=0,count2=0;
  if(n>=2)
  {
    count1=nCr(n,2);
  }
  if(m>=2)
  {
    count2=nCr(m,2);
  }
  cout<<count1+count2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//#define debug
int main(int argv, char *argc[]){
    
    unsigned int a, b;
    char op;
    while(1){
        scanf("%d %c %d", &a, &op, &b);
        #ifdef debug
        printf("%d %c %d\n", a, op, b);
        #endif
    
        if(op == '+') printf("%d\n", a+b);
        else
        if(op == '-') printf("%d\n", a-b);
        else
        if(op == '*') printf("%d\n", a*b);
        else
        if(op == '/') printf("%d\n", a/b); 
        else
        if(op == '?') break;
        }
    return 0;
}

Measured memory_bytes: 600
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        long H = in.l();
        out.println(solve(H));
    }
    
    static long solve(long h){
        if(h == 1){
            return 1;
        } else {
            return 1+solve(h/2)*2;
        }
    }
    
    static long solve2(long h){
        int bit = 0;
        while(h != 0){
            bit++;
            h >>= 1;
        }
        return (1L<<bit)-1;
    }
   

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


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


int main(){
  
  char c;
  cin >> c;
  
  if(97 <= (int) c && 122 >= (int) c){
    cout << 'a' << endl;
  }else if(65 <= (int) c && 90 >= (int) c){
    cout << 'A' << endl;
  }
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int n, q_num;
string s;
map<char, set<int>> mp;

int main()
{
    cin>>n>>s>>q_num;
    REPALL(k,s) {
        mp[s[k]].insert(k);
    }
    REP(k,q_num) {
        int q;
        cin>>q;
        if (q == 1) {
            int i;
            char c;
            cin>>i>>c;
            mp[s[i-1]].erase(i-1);
            mp[c].insert(i-1);
            s[i-1] = c;
            //debug(s);
        } else {
            int l, r, tans = 0;
            cin>>l>>r;
            l--; r--;
            REP(kk,26) {
                char tmpc = 'a' + kk;
                auto itr = mp[tmpc].lower_bound(l);
                /*if (itr != mp[tmpc].end()) {
                    debug(tmpc);
                    debug(*itr);
                }*/
                if (itr != mp[tmpc].end() && *itr <= r)
                    tans++;
            }
            cout<<tans<<endl;
        }
    }


    return 0;
}


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

typedef long long int ll;
const ll MOD = 1000000007;

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> v(N);
    for (auto& i : v) cin >> i;

    sort(v.begin(), v.end());

    vector<ll> dp(N);
    for (int i = 0; i < N; i++) {
        ll count = lower_bound(v.begin(), v.end(), v[i] - T) - v.begin();
        dp[i] = i - count + 1;
    }

    ll ans = 1;
    for (int i = 0; i < N; i++) {
        ans *= dp[i];
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

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

#define ARRAYNUM 1000

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

  // ここにプログラムを追記
  int l[ARRAYNUM], r[ARRAYNUM];

  /* 入力ループ */
  for(int i=0; i<N; i++) {
    cin >> l[i] >> r[i];
  }

  int total = 0;
  for(int i=0; i<N; i++) {
    total += r[i] - l[i] + 1;
  }

  /* 出力ループ */
  cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    deque<int> deq;
    int n;
    cin >> n;

    rep(i,n)
    {
        int tmp;
        cin >> tmp;
        if (i&1)
        {
            deq.push_front(tmp);
        }
        else
        {
            deq.push_back(tmp);
        }
    }
    if (n&1)
    {
        rep(i,n)
        {
            cout << deq[n-1-i] << " ";
        }
        cout << endl;
    }
    else
    {
        rep(i,n)
        {
            cout << deq[i] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3072
data_set = readlines
as = data_set[1].split.map(&:to_i)
bs = data_set[2].split.map(&:to_i)
ds = as.zip(bs).map{|a, b| a - b}

if ds.reduce(:+) < 0
  puts -1
  exit
end

lack_list = ds.select{|x| x < 0}
lack = lack_list.reduce(:+)

unless lack
  puts 0
  exit
end

exceed_list = ds.select{|x| x > 0}.sort.reverse

c = 1
sum = 0
0.upto(exceed_list.size-1) do |i|
  sum += exceed_list[i]
  break if sum + lack >= 0
  c += 1
end


puts c + lack_list.size


Measured memory_bytes: 24416
from numpy import cumsum
n = int(input())
a = list(map(int,input().split()))
l = [0]*1001
for i in range(n):
    l[a[i]] += 1
cs = cumsum(l)
count = 0
for i in range(1,1001):
    if l[i] != 0:
        for j in range(i+1,1001):
            if l[j] != 0:
                count += l[i]*l[j]*(cs[min(i+j-1,1000)]-cs[j])
for i in range(1,1001):
    n = l[i]
    if n > 1:
        count += n*(n-1)//2*(cs[min(2*i-1,1000)]-n)
    if n > 2:
        count += n*(n-1)*(n-2)//6
print(count)

Measured memory_bytes: 12420
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
struct data{
    int a,b,c;
};

//降順
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
#define MAXSIZE 200000
int list[MAXSIZE];
int tail;

void Init(void){
    tail=0;
}
int Top(void){
    return 0;
}

int Next(int pos){
    if(pos<tail-1){
        return pos+1;
    }else{
        return -1;
    }
}
int Count(void){
    return tail;
}

int Item(int pos){
    if((pos>=0)&&(pos<tail)){
        return list[pos];
    }else{
        return 0;
    }
}
void Add(int value){
    if(tail<MAXSIZE){
        list[tail]=value;
        tail++;
    }
}
void Delete(int pos){
    if((pos>=0)&&(pos<tail)){
        int i;
        for(i=pos;i<tail-1;i++){
            list[i]=list[i+1];
        }
        tail--;
    }
}

int main(){
    int a,b,c;
    int cnt=0;
    scanf("%d%d%d",&a,&b,&c);
    if(a%2==1 || b%2==1 || c%2==1){
        printf("0");
        return 0;
    }
    if(a==b && b==c){
        printf("-1");
        return 0;
    }
    while(a%2==0 && b%2==0 && c%2==0){
        int temp1=0,temp2=0;
        temp1=(b/2+c/2);
        temp2=(b/2+a/2);
        b=(c/2+a/2);
        c=temp2;
        a=temp1;
        cnt++;
    }
    printf("%d",cnt);
}


Measured memory_bytes: 1704
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, m;
string s;
vector<int> ans;
vector<int> ze;

signed main() {
	cin >> n >> m >> s;
	for (int i = 0; i < n + 1; i++)if (s[i] == '0')ze.push_back(i);
	int k = n;
	while (k) {
		int d = *lower_bound(all(ze), k - m);
		if (!(k - d)) {
			cout << -1 << endl;
			return 0;
		}
		ans.push_back(k - d);
		k = d;
	}
	reverse(all(ans));
	for (int i = 0; i < (int)ans.size(); i++) {
		if (i != (int)ans.size() - 1)cout << ans[i] << " ";
		else cout << ans[i] << endl;
	}
}

Measured memory_bytes: 2676
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,k;
  cin >> n >> k;
  cout << (n%k==0?0:1) << endl;
}


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

using namespace std;
using ll = long long;

int main() {
  int n, q;
  cin >> n >> q;
  vector<vector<int> > graph(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  vector<ll> cnts(n, 0);
  rep(i, q) {
    int p, x;
    cin >> p >> x;
    p--;
    cnts[p] += x;
  }
  vector<bool> visited(n, false);
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    visited[v] = true;
    for (auto nv : graph[v]) {
      if (visited[nv]) {
        continue;
      }
      cnts[nv] += cnts[v];
      que.push(nv);
    }
  }
  rep(i, n) {
    if (i == n - 1) {
      cout << cnts[i] << endl;
    } else {
      cout << cnts[i] << " ";
    }
  }
  return 0;
}


Measured memory_bytes: 17368
N=int(input())
memo=[None]*(N+1)
def luca(N):
  if memo[N]!=None:
    return memo[N]
  if N==0:
    memo[N]=2
    return 2
  elif N==1:
    memo[N]==1
    return 1
  else:
    memo[N]=luca(N-1)+luca(N-2)
    return memo[N]
ans=luca(N)
print(ans)  

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int partation(int *,int,int);
void swap(int *, int *);

int *A,*x;
int main(){
  int n,i,j,r,a;

  scanf("%d",&n);
  A=malloc(sizeof(int)*n+1);
  for(i=1;i<=n;i++) scanf("%d",&A[i]);

 
  a=partation(A,0,n);
  
  for(j=1;j<=n;j++){
    if(j==a) printf("[%d]",A[j]);
    else  printf("%d",A[j]);
    if(j!=n) printf(" ");
  }
  printf("\n");
  
}

int partation(int *A, int p, int r){
  int i,j,x;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  
  return i+1;
}

void swap(int *x,int *y){
  int tmp;
  tmp=*x;
  *x=*y;
  *y=tmp;
}



Measured memory_bytes: 2248
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

class BinaryIndexedTree:
    def __init__(self, size):
        """
        :param int size:
        """
        self.bit = [0 for _ in range(size)]
        self.size = size
 
    def add(self, i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return
 
    def sum(self, i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += self.bit[x - 1]
            x -= x & -x
        return res
 
    def search(self, x):
        """
        二分探索。和がx以上となる最小のインデックス(>= 1)を返す
        :param int x:
        :return :
        """
        i = 1
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.bit[i + step - 1] < x:
                i += step
                s += self.bit[i - 1]
            step >>= 1
        return i
 
    def __len__(self):
        return self.size

n = I()
s = list(input())

lst = [BinaryIndexedTree(n+1) for _ in range(26)]
S = [ord(i) - ord("a") for i in s]

for i in range(n):
    lst[S[i]].add(i+1,1)

q = I()
for _ in range(q):
    query = input().split()
    if query[0] == '1':
        i,c = query[1:]
        i = int(i)-1
        lst[S[i]].add(i+1,-1)
        lst[ord(c) - ord("a")].add(i+1,1)
        S[i] = ord(c) - ord("a")
    else:
        l,r = query[1:]
        l = int(l)-1
        r = int(r)-1
        cnt = 0
        for i in range(26):
            if lst[i].sum(r+1) - lst[i].sum(l) > 0:
                cnt += 1
        print(cnt)


Measured memory_bytes: 253776
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]

g = [set() for i in range(N)]
for a, b in AB:
    a, b = a-1, b-1
    g[a].add(b)
    g[b].add(a)

c = 0
for i in range(N):
    if all(H[c]<H[i] for c in g[i]):
        c += 1

print(c)

Measured memory_bytes: 63560
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string s[n];
int ans=0;
int a=0;
int b=0;
int c=0;
for(int i=0;i<n;i++){
  cin>>s[i];
  if(s[i].at(0)=='B'){
    b++;
  }
  if(s[i].at(s[i].size()-1)=='A'){
    a++;
  }
  if(s[i].at(s[i].size()-1)=='A'&&s[i].at(0)=='B'){
    c++;
  }
  for(int j=0;j<s[i].size()-1;j++){
    if(s[i].at(j)=='A'&&s[i].at(j+1)=='B'){
      ans++;
    }
  }
}
if(0==a&&0==b){
  cout<<ans;
}
else if(c==a&&c==b){
  ans+=(c-1);
  cout<<ans;
}
else{
  ans+=min(a,b);
  cout<<ans;
}
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define ll long long
typedef pair<int, int> P;

int main(){
  ll n, h, w, res = 0;
  cin >> n >> h >> w;
  ll a[n], b[n];
  rep(i, n){
    cin >> a[i] >> b[i];
  }
  rep(i, n) {
    if (a[i] >= h && b[i] >= w) {
      res += 1;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll n;
  cin >> n;
  vl a(n),b(n);
  rep(i,n) cin >> a[i] >> b[i];
  
  ll cnt=0;
  for(int i=n-1;i>=0;i--){
    a[i]+=cnt;
    if(a[i]%b[i]==0)continue;
    ll c=(a[i]+b[i]-1)/b[i];
    cnt+=c*b[i]-a[i];
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

#include <vector>
#include <queue>
using namespace std;

struct Node{
  int now;
  //int sub;
  long cost;
};

struct Edge{
  int from;
  int to;
  long cost;
};

bool operator<(const Node &a, const Node &b){
  if(a.cost != b.cost){
    return a.cost < b.cost;
  }else{
    return a.now < b.now;
  }
}
bool operator>(const Node &a, const Node &b){return (b < a);}
bool operator<=(const Node &a, const Node &b){return !(b < a);}
bool operator>=(const Node &a, const Node &b){return !(a < b);}

//vector<vector<Edge>> Graph(n);
//sは始点
vector<long> Dijkstra(vector<vector<Edge>> &Graph, int s){ //最小コスト
  priority_queue<Node, vector<Node>, greater<Node>> que;
  vector<long> dist(Graph.size(), 1e16);

  dist.at(s) = 0;
  que.push(Node{s, 0});

  while(que.size()){
    Node node = que.top();
    que.pop();
    int v = node.now;
    if(node.cost > dist.at(v)) continue;
    for(Edge edge : Graph.at(v)){
      int nv = edge.to;
      long cost = edge.cost;
      if(dist.at(nv) > dist.at(v) + cost){
        dist.at(nv) = dist.at(v) + cost;
        que.push(Node{nv, dist.at(nv)});
      }
    }
  }
  for(int i=0;i<dist.size();i++){
    if(dist.at(i) > 9*1e15) dist.at(i) = -1;
  }
  return dist;
}

int main(){
  long n,m;
  cin >> n >> m;
  vector<vector<Edge>> Graph(n);
  REP(i,1,n){
    Graph.at(i).push_back(Edge{i,i-1,0});
  }
  rep(i,m){
    long l,r,c;
    cin >> l >> r >> c;
    l--;r--;
    Graph.at(l).push_back(Edge{l,r,c});
  }
  vector<long> dist = Dijkstra(Graph,0);;
  cout << dist.at(n-1) << endl;
}

Measured memory_bytes: 10104
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) { for (auto& e : t) fill_v(e, v); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a; cin >> a;
	string s; cin >> s;
	if(a >= 3200)
		cout << s << endl;
	else
		cout << "red" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	ll N;
	cin >> N;
	vi ans;
	int n;
	repr(i, 50) {
		if(N >= (1LL<<i)-1) {
			n = i;
			break;
		}
	}
	rep(i, n) ans.pb(i);
	N -= (1LL<<n)-1;
	repr(i,n) {
		if(N < (1LL<<i)) continue;
		ans.insert(ans.begin()+i, n++);
		N -= (1LL << i);
	}
	cout << n * 2 << endl;
	rep(i, n) cout << ans[i] + 1 << " ";
	rep(i, n) {
		cout << i+1;
		if(i != n-1) cout << " ";
		else cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    int MOD = 10;
    if(n%MOD==3){
        cout << "bon";
    }else{
        if(n%MOD!=0&&((n%2==0&&n%MOD<5)||(n%2==1&&n%MOD>4))){
            cout << "hon";
        }else{
            cout << "pon";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define maxn 2100
#define base 1000000007

using namespace std;

int n,a[maxn],ans=0,K;


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
   // freopen("input.txt", "r", stdin);
    cin>>n>>K;
    for (int i=0;i<n;i++) cin>>a[i];
    for (int i=0;i<n;i++) {
        for (int j=i+1;j<n;j++) {
            if (a[i]>a[j]) ans = (ans + (1ll*K*(K+1)/2)%base)%base;
            else if (a[i]<a[j]) ans = (ans + (1ll*K*(K-1)/2)%base)%base;
        }
    }
    cout<<ans;

}


Measured memory_bytes: 256
import math

n1 = int(input())
n2 = [int(i) for i in input().split()]
n3 = [int(i) for i in input().split()]

a1 = []
a2 = []
for i1 in range(n1):
    a1.append(i1 + 1)
    a2.append(i1 + 1)

c4 = 0
for i5 in range(n1 - 1):
    c4 += (a1.index(n2[i5])) * math.factorial(n1 - i5 - 1)
    a1[a1.index(n2[i5])] = n1
    a1.sort()

c5 = 0
for i6 in range(n1- 1):
    c5 += (a2.index(n3[i6]) ) * math.factorial(n1 - i6 - 1)
    a2[a2.index(n3[i6])] = n1
    a2.sort()

print(abs(c5 - c4))

Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
    int x,b;
    scanf("%d %d", &x, &b);

    if(x==b)
    {
        printf("Draw");
    }
    else if(x==1)
    {
        printf("Alice");
    }
    else if(b==1)
    {
        printf("Bob");
    }
    else if(x>b)
    {
        printf("Alice");
    }
    else{
        printf("Bob");
    }
    return 0;
}

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

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

  vector<vector<int>> G(N);
  for(auto i = 0; i < M; ++i) {
    int A, B;
    cin >> A >> B;
    --A; --B;
    G[A].emplace_back(B);
    G[B].emplace_back(A);
  }

  vector<bool> used(N);
  list<int>  P = {0};
  used[0] = true;
  while(true) {
    bool ok = true;
    for(auto to: G[P.back()]) if(!used[to]) {
      ok = false;
      P.emplace_back(to);
      used[to] = true;
      break;
    }
    if(!ok) continue;
    for(auto to: G[P.front()]) if(!used[to]) {
      ok = false;
      P.emplace_front(to);
      used[to] = true;
      break;
    }
    if(ok) break;
  }

  cout << P.size() << endl;
  for(auto v: P) cout << (v==P.front() ? "" : " ") << v+1;
  cout << endl;
}


Measured memory_bytes: 9472
using System;

namespace abc132A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string A = Console.ReadLine();
            string[] B = new string[4];
            int C = 0;
            for(int i = 0; i < 4; i++)
            {
                B[i] = A.Substring(i, 1);
                for(int r = 0; r < 4; r++)
                {
                    B[r] = A.Substring(r, 1);
                    if (B[i] == B[r])
                        C = C + 1;
                }
            }
            C = (C - 4) / 2;
            if (C == 2)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	bs := ReadInts(N - 1)
	as := make([]int, N)
	for i := 0; i < N; i++ {
		as[i] = 1e10
	}

	for i := 0; i < len(bs); i++ {
		as[i] = Min(as[i], bs[i])
		as[i+1] = Min(as[i+1], bs[i])
	}

	fmt.Println(Sum(as...))
}

func Sum(slice ...int) int {
	sum := 0
	for _, v := range slice {
		sum += v
	}
	return sum
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 1844
#include<cstdio>
#include<map>
const int MaxN=100010;
int N,P[2][MaxN];
struct edge{int to,cap;edge*rev,*next;}E[MaxN*4],*ne=E,*fir[MaxN],*cur[MaxN];
void link(int a,int b,int c){
	*ne=(edge){b,c,ne+1,fir[a]};fir[a]=ne++;
	*ne=(edge){a,0,ne-1,fir[b]};fir[b]=ne++;
}
int Q[MaxN],D[MaxN];
int dfs(int i,int c){
	if(i==1||!c)return c;
	int fl=0,f;
	for(edge*&e=cur[i];e&&c;e=e->next)if(e->cap&&D[e->to]==D[i]-1&&(f=dfs(e->to,c<e->cap?c:e->cap)))
		fl+=f,e->cap-=f,e->rev->cap+=f,c-=f;
	return fl;
}
int vtot;
int mf(){
	for(int f=0;;f+=dfs(0,1<<30)){
		for(int i=0;i<vtot;i++)D[i]=0,cur[i]=fir[i];
		for(int*h=Q,*t=Q+(D[*h=1]=1);h<t;h++){
			for(edge*e=fir[*h];e;e=e->next){
				if(e->rev->cap&&!D[e->to])D[*t++=e->to]=D[*h]+1;
			}
		}
		if(!D[0])return f;
	}
}
int id[2][MaxN],sz[2][MaxN],w[2][MaxN];
int main(){
	scanf("%d",&N);
	for(int t=0;t<2;t++)
		for(int i=0;i<N;i++)scanf("%d",P[t]+i);
	int cc[2]={0};
	for(int t=0;t<2;t++){
		for(int i=0;i<N;i++)if(P[t][i]!=i&&!id[t][i]){
			cc[t]++;
			for(int j=i;!id[t][j];j=P[t][j])id[t][j]=cc[t],sz[t][cc[t]]++;
		}
	}
	int ans=0;
	std::map<std::pair<int,int>,int>Es;
	for(int i=0;i<N;i++){
		if(P[0][i]==i&&P[1][i]==i)continue;
		if(P[0][i]==i)ans++,w[1][id[1][i]]++;
		else if(P[1][i]==i)ans++,w[0][id[0][i]]++;
		else{
			ans++;
			Es[std::make_pair(1+id[0][i],1+cc[0]+id[1][i])]++;
			if(P[0][i]==P[1][i])Es[std::make_pair(1+cc[0]+id[1][i],1+id[0][i])]++;
		}
	}
	for(int i=1;i<=N;i++){
		if(w[0][i])link(1+i,1,w[0][i]);
		if(w[1][i])link(0,1+cc[0]+i,w[1][i]);
	}
	for(std::map<std::pair<int,int>,int>::iterator it=Es.begin();it!=Es.end();it++){
		link(it->first.first,it->first.second,it->second);
	}
	vtot=2+cc[0]+cc[1];
	printf("%d\n",ans-mf());
}

Measured memory_bytes: 20096
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<numeric>
#include<functional>
#include<sstream>
#include<iomanip>

using namespace std;

#define ll long long

int main() {
    int n; cin >> n;
    vector<pair<ll, ll>> kukan(n);
    for(int i=0; i<n; i++) {
        ll xi, li;
        cin >> xi >> li;
        kukan[i] = pair<ll, ll>(xi+li, xi-li);
    }
    sort(kukan.begin(), kukan.end());
    ll ans = 0;
    ll ptr = -100000000000;
    for(int i=0; i<n; i++) {
        if(ptr<=kukan[i].second) {
            ptr=kukan[i].first;
        } else {
            ans++;
        }
    }
    cout << n-ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
  	string s;
  	cin >> s;
    
  	sort(s.begin(), s.end());
   
    if (s[0] == s[1] && s[0] != s[2] && s[2] == s[3])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  double a, b, x;
  cin >> a >> b >> x;

  double s = x / a;
  double h = 0, ans = 0;
  if (s >= a * b / 2) {
    h = (a * b - s) * 2 / a;
    ans = atan2(h, a);
  } else {
    h = s * 2 / b;
    ans = atan2(b, h);
  }

  cout << fixed << setprecision(10) << ans * 360 / (2 * M_PI) << endl;
}


Measured memory_bytes: 4176
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {

    	/*Scanner = テキスト入力を扱うためのクラス
		 *キーボードからの入力を受けつける場合は
		 *System.inを使って下記のように記述
		 */
		Scanner scan = new Scanner(System.in);

		//入れ替えた値を一時保管する箱
		int wx;


		/*while(true)で無限ループをセット
		 *int x = scan.nextInt(); xに値を入れてる(今回2つを入力させるので用意させるのも2つ)
		 *そして一回ずつ表示させ0の時にbreakさせてる。
		 */
		while(true){
		int x = scan.nextInt();
		int y = scan.nextInt();
		if ( x == 0 && y == 0 ) break;
		if(x > y){ wx = y; y = x; x = wx;}

		//最後は表示させる。あとCaseナンバーの加算をしてます。
		System.out.println(x + " " + y);
		}

    }
}

Measured memory_bytes: 27128
n,w=map(int,input().split())
value=[0]*n
weight=[0]*n
for i in range(n):
    value[i],weight[i]=map(int,input().split())

dp=[[0]*(w+1) for i in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j-weight[i]>=0:
            dp[i+1][j]=max(dp[i+1][j],dp[i+1][j-weight[i]]+value[i])
        dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(dp[n][w])


Measured memory_bytes: 41888
#include <stdio.h>
int main(void)
{
  int a,b,c;
  char str[16];
  fgets(str,16,stdin);
  sscanf(str,"%d%d%d",&a,&b,&c);
  if( ((a+b) == c) || ((b+c) == a) || ((c+a) == b) )
  {
    printf("Yes\n");
  }
  else
  {
    printf("No\n");
  }
  return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  
  sort(h.begin(), h.end());
  
  int ans = 1001001001;
  rep(i, n-k+1) {
    ans = min(h[k-1+i] - h[i], ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3716
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]
pay=0
for si in s:
    aa=list(filter(lambda x: x==si, s))
    dd=list(filter(lambda x: x==si, t))
    tmp=len(aa)-len(dd)
    pay = tmp if pay<tmp else pay
print(pay)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;

bool check(std::string &S, char &turn) {
    turn = S.front();
    S.erase(S.begin());
}

int main(int argc, char const *argv[]) {
    std::string A, B, C;
    std::cin >> A >> B >> C;
    char turn = 'a';
    while (true) {
        if (turn == 'a') {
            if (A.empty()) {
                std::cout << "A" << '\n';
                break;
            }
            check(A, turn);

        } else if (turn == 'b') {
            if (B.empty()) {
                std::cout << "B" << '\n';
                break;
            }
            check(B, turn);
        } else {
            if (C.empty()) {
                std::cout << "C" << '\n';
                break;
            }
            check(C, turn);
        }
    }
    return 0;
}


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

long long n;
vector<long long> a;
vector<vector<long long>> dp;

int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  dp.assign(n, vector<long long>(2, 1));
  for (int i = 1; i < n; ++i) {
    dp[i][0] = min(dp[i - 1][0] + (a[i] > a[i - 1]), dp[i - 1][1] + 1);
    dp[i][1] = min(dp[i - 1][0] + 1, dp[i - 1][1] + (a[i] < a[i - 1]));
  }
  cout << min(dp[n - 1][0], dp[n - 1][1]) << endl;
  return 0;
}


Measured memory_bytes: 6528
S = input()
ls = len(S)
if ls == 1:
    print(S)
else:
    g = 0
    for i in range(2**(ls-1)):
        w = ''
        for u,v in zip(format(i,'#0'+str(2+ls-1)+'b')[2:],S):
            if u=='1':w=w+v+'+'
            else:w=w+v
        else:w=w+S[-1]
        g += eval(w)
    print(g)

Measured memory_bytes: 3064
#include <stdio.h>
int main(){
	int n, p, i, a;
	while(1){
	int Hozon[50] = {};
		scanf("%d %d", &n, &p);
		if( n == 0 && p == 0 ){
			break;
		}
		a = p;
		for( i = 0 ; ; i = (i + 1) % n ){
			if( a == 0 ){
				a = Hozon[i];
				Hozon[i] = 0;
			}else{
			--a;
			++Hozon[i];
				if( Hozon[i] == p ){
					break;
				}
			}
		}
		printf("%d\n", i);
	}
	return 0;
}

Measured memory_bytes: 600