akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> ps(n);
    for (int i = 0; i < n; i++) cin >> ps[i];
    sort(ps.begin(), ps.end());
    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += ps[i];
    }
    cout << ans << endl;
}


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

#define INF 1000000000

int n;
vector<vector<int>> f, p;

void solve() {
  int i, j;
  ll bit, cnt, tmp, ans;

  ans = -INF;

  for (bit = 1; bit < (1 << 10); bit++) {

    tmp = 0;

    for (i = 0; i < n; i++) {

      cnt = 0;

      for (j = 0; j < 10; j++) {

        if ((bit & (1 << j)) && f[i][j] == 1) {
          cnt++;
        }
      }

      tmp += p[i][cnt];
    }

    ans = max(ans, tmp);
  }

  cout << ans << "\n";
}

int main() {
  int i, j, tmp;

  cin >> n;

  f.resize(n);
  p.resize(n);

  for (i = 0; i < n; i++) {
    for (j = 0; j < 10; j++) {
      cin >> tmp;
      f[i].push_back(tmp);
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j <= 10; j++) {
      cin >> tmp;
      p[i].push_back(tmp);
    }
  }

  solve();

  return 0;
}

Measured memory_bytes: 256
import fractions
import sys
from functools import reduce
import math

input = sys.stdin.readline

def main():
    a, b, c, d = input_list()
    l = lcm_base(c, d)
    a -= 1
    ans_b = b - (b//c + b//d) + b//l
    ans_a = a - (a//c + a//d) + a//l
    print(ans_b - ans_a)


def divide_list(l, args):
    result = []
    pre = 0
    for i, a in enumerate(args):
        if i != 0:
            pre = args[i-1]
        result.append(l[pre:a])
        if i == len(args) - 1:
            result.append(l[a:])
    return result

def divide_two(n):
    c = 0
    while True:
        if c >= 2:
            break
        if n % 2 != 0:
            break
        n //= 2
        c += 1
    return c

def get_camulative(l):
    import itertools
    # 累積和
    return [0] + list(itertools.accumulate(l))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if __name__ == "__main__":
    main()


Measured memory_bytes: 63980
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let s: Vec<char> = sc.chars();
    let n: usize = s.len();

    let mut dp = vec![vec![0; 2]; n];
    for i in 0..n {
        dp[i][0] = if i == 0 {
            1
        } else if s[i-1] == s[i] {
            dp[i-1][1] + 1
        } else {
            max!(dp[i-1][1] + 1, dp[i-1][0] + 1)
        };
        dp[i][1] = if i == 0 {
            0
        } else if i == 1 {
            1
        } else if i == 2 {
            2
        } else if s[i-2] == s[i] || s[i-3] == s[i-1] {
            dp[i-2][0] + 1
        } else {
            max!(dp[i-2][0] + 1, dp[i-2][1] + 1)
        };
        // trace!(&dp[i]);
    }
    put!(max!(dp[n-1][0], dp[n-1][1]));
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 12540
use std::collections::VecDeque;
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//https://onlinejudge.u-aizu.ac.jp/solutions/problem/ALDS1_5_B/review/2709881/arsenic28/Rust
trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    let n: usize = read();
    let mut buf = VecDeque::new();

    for i in 0..n {
        let a: u32 = read();
        if i % 2 == 0 {
            buf.push_back(a);
        } else {
            buf.push_front(a);
        }
    }

    let mut v: Vec<u32> = buf.into_iter().collect();

    if n % 2 == 1 {
        v.reverse();
    }

    println!("{}", v.iter().join(" "));
}


Measured memory_bytes: 14588
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
int main(){
    ios_base::sync_with_stdio(false),cin.tie(NULL);
    ll k,a,b;
    cin>>k>>a>>b;
    if(b/k - (a-1)/k>=1)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
	return 0;
}


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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//	LLONG_MAX 9.2*1e18	9223372036854775807LL = (2^63)-1
//	INT_MAX 2.1*1e9 2147483647 = (2^31)-1
//	O(1e8) 1.2sec

void Main()
{
	int N;
	cin>>N;
	vecll(v,2002);

	v[0]=1;
	ll sum=0;
	for(int i=3; i<=N; i++){
		v[i]=(v[i-1]+v[i-3])%mod;
	}
	cout<<v[N]<<_n;
}
void Test();
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n;
int a[100005];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);

  sort(a, a + n);

  printf("%d\n", a[n / 2] - a[n / 2 - 1]);

  return 0;
}

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

const ll MX = 1e18;

int main() {
    int n;
    cin >> n;
    ll a[n];
    bool flag = false;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 0) flag = true;
    }
    if (flag) {
        cout << 0 << endl;
        return 0;
    }
    ll num = 1;
    for (int i = 0; i < n; i++) {
        if (MX / num < a[i]) {
            num = -1;
            break;
        }
        num *= a[i];
    }
    cout << num << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  for(int i=0;i<M;i++){
    int h;
    cin >> h;
    N-=h;
  }
  if(N<0)
    cout << "-1" << endl;
  else
    cout << N << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;

  char a[51][51], b[51][51];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }

  bool exist = false;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i + m - 1 >= n or j + m - 1 >= n) {
        continue;
      }

      bool match = true;
      for (int y = 0; y < m; y++) {
        for (int x = 0; x < m; x++) {
          if (a[i+y][j+x] != b[y][x]) {
            match = false;
          }
        }
      }
      if (match) {
        exist = true;
      }
    }
  }

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


  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
string s;
typedef long long ll;
const ll MOD=1e9+7;
ll dp[2],ans=0,num[100004],q=0;
int main(){
	num[0]=1;
	for (int i=1;i<=1e5;i++) num[i]=num[i-1]*3%MOD;
	cin>>s;
	for (int i=0;i<s.size();i++){
		if (s[i]=='A'){
			dp[0]=(dp[0]+num[q])%MOD;
		}
		if (s[i]=='B'){
			dp[1]=(dp[1]+dp[0])%MOD;
		}
		if (s[i]=='C'){
			ans=(ans+dp[1])%MOD; 
		}
		if (s[i]=='?'){
			ans=(ans*3+dp[1])%MOD;
			dp[1]=(dp[1]*3+dp[0])%MOD;
			dp[0]=(dp[0]*3+num[q])%MOD;
			q++;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

long long gcd(long long x, long long y){
    if(y == 0)return x;
    return gcd(y, x % y);
}

long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}

int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = lcm(a, b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>>vec(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> vec.at(i).at(j);
    }
  }
  vector<char>tag(W+2);
  for(int k=0;k<W+2;k++){
   tag.at(k)='#';
   cout << tag.at(k);
   if (k==W+1) cout << endl; 
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if (j==0) cout << '#';
      cout << vec.at(i).at(j);
      if (j==W-1) cout << '#' << endl;
    }
  }
   for(int k=0;k<W+2;k++){
   tag.at(k)='#';
   cout << tag.at(k);
   if (k==W+1) cout << endl; 
  }
}

Measured memory_bytes: 256
#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;
  else if(a+b < c+d) cout <<"Right" <<endl;
  else cout <<"Balanced" <<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A + B > C + D)
    {
        cout << "Left" << endl;
    }
    else if (A + B == C + D)
    {
        cout << "Balanced" << endl;
    }
    else
    {
        cout << "Right" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
// #define mp make_pair
#define nt _int128 
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define inf 0x3f3f3f3f
 
const ll mod = 1e9 + 7;
const ll mx = 2e6 + 5;
const ll mxi = 2e3 + 5;

int main()
{
    fast_as_levi;
    ll i,j,n,m;
    cin>>n>>m;
    //using specifically optimized knapsack here,
    //as standard O(n*m) knapsack solution will timeout due to the heavy constraints given in the problem
    ll wt[n],cs[n];
    ll value_sum = 0;
    
    for(i=0;i<n;i++)
    {
        cin>>wt[i]>>cs[i];
        value_sum += cs[i]; 
    }
    //So, here, instead of iterating over the accumulated weights(which we do conventionally in 0-1 knapsack),
    //we will iterate over accumulated values here instead
    vector<ll> dp(value_sum+1,inf);
    dp[0] = 0;
    for(i=0;i<n;i++)
    {
        for(j = value_sum - cs[i];j>=0;j--)
        {
            dp[j+cs[i]] = min(dp[j+cs[i]] , dp[j] + wt[i]);
        }
    }
    ll ans = 0;
    for(i=0;i<=value_sum;i++)
    {
        if(dp[i]<=m)
        {
            ans = max(ans,i);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 1024
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = String.valueOf(sc.nextInt());
      	String b = String.valueOf(sc.nextInt());
       	int target = Integer.parseInt(a+b);
      	String result = String.valueOf(Math.sqrt(target));
		String[] test = result.split("\\.",0);
        if (test[1].equals("0")) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");          
        } 	
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


ll dist (int x1, int x2, int y1, int y2) {
    return abs(x2-x1)+abs(y2-y1);
}

int main() {
    int n, m;
    cin >> n >> m;
    vpair p(n);
    rep(i, n) cin >> p[i].fi >> p[i].se;
    vpair c(m);
    rep(i, m) cin >> c[i].fi >> c[i].se;

    rep(i, n) {
        int idx = -1;
        ll mn = LINF;
        rep(j, m) {
            ll d = dist(p[i].fi, c[j].fi, p[i].se, c[j].se);
            if (mn > d) {
                idx = j;
                mn = d;
            }
        }
        cout << idx+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int A, B, X;
    cin >> A >> B >> X;
    cout << (X >= A && X <= A + B ? "YES" : "NO") << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, data[100];
	while (cin >> n && n) {
		int sum = 0;
		for (int i = 0; i < n; ++i) cin >> data[i];
		sort(data, data + n);
		for (int i = 1; i < n - 1; ++i) sum += data[i];
		cout << sum / (n - 2) << endl;
	}
	return 0;
}


Measured memory_bytes: 3120
from functools import reduce


def gcd(a, b):
    if b==0:
        return a
    return gcd(b, a%b)

  
N, K = map(int, input().split())
lst_A = list(map(int, input().split()))
max_A = max(lst_A)
gcd_A = reduce(gcd, lst_A)

ans = "IMPOSSIBLE"
if K%gcd_A==0 and K<=max_A:
    ans = "POSSIBLE"

print(ans)

Measured memory_bytes: 14596
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(scanner.next());
        }
        int ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                ans += A[i] * A[j];
            }
        }

        System.out.println(ans);
    }
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	vector<int> L(n);
	for (int i=0; i<n; i++) cin >> L[i];
	vector<int> R = L;
	sort(L.begin(), L.end());
	ll ret = 0;
	for (int i=0; i<n; i++) {
		for (int j=i+1; j<n; j++) {
			int d = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();
			ret += max(0, d - (j + 1));
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3580
n = int(input())
list_2d = [[] for _ in range(n)]

for i in range(n):
    s, p = input().split()
    list_2d[i].append(s)
    list_2d[i].append(p)
list_2d_sorted = sorted(list_2d, key = lambda x: (x[0],-int(x[1])))
for i in range(n):
    print(list_2d.index(list_2d_sorted[i])+1)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <cstdio>
#define FOR(i,l,r) for(int (i) = (l); (i) <= (r); (i)++)
using namespace std;
int mass[2][3005];
int A,B,C,D,E,F;
struct Fen{
	int zi,mu;
	Fen(int zi = 0, int mu = 0):zi(zi),mu(mu){}
	friend bool operator < (const Fen &a, const Fen &b){
		return a.zi * b.mu < b.zi * a.mu;
	}
	friend bool operator <= (const Fen &a, const Fen &b){
		return a.zi * b.mu <= b.zi * a.mu;
	}
}ans,lim;
int main(){
#ifdef __APPLE__
	freopen("main.in","r",stdin);
#endif
	cin >> C >> D >> A >> B >> E >> F;
	C *= 100; D *= 100;
	mass[0][0] = mass[1][0] = 1;
	for(int i = 0; i <= F; i+=A) mass[0][i] = 1;
	for(int i = 0; i <= F; i++) if(mass[0][i])
		for(int j = i; j <= F; j += B) mass[0][j] = 1;

	for(int i = 0; i <= F; i+=C) mass[1][i] = 1;
	for(int i = 0; i <= F; i++) if(mass[1][i])
		for(int j = i; j <= F; j += D) mass[1][j] = 1;

	ans.zi = 0, ans.mu = C;
	lim.zi = E, lim.mu = E + 100;
	FOR(i,0,F) FOR(j,1,F)if(mass[0][i] && mass[1][j]){
		if(i + j <= F && Fen(i,i+j) <= lim){
			if(ans < Fen(i,i+j)) ans = Fen(i,i+j);
		}
	}
	cout << ans.mu << " " << ans.zi << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 998244353;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

long fact[303030];
long factinv[303030];

long mpow(long a, long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long d = mpow(a, n / 2);
        return d * d % MOD;
    }
    return a * mpow(a, n - 1) % MOD;
}

void make() {
    fact[0] = 1;
    REPI(i,1,303030) {
        fact[i] = fact[i-1] * i % MOD;
    }
    REP(i,303030) {
        factinv[i] = mpow(fact[i], MOD - 2);
    }
}

void check() {
    REP(i,303030) {
        if (fact[i] * factinv[i] % MOD != 1) {
            cout << "ERROR" << endl;
            exit(1);
        }
    }
}

long comb(long n, long k) {
    if (n < 0 || k < 0 || k > n) return 0;
    return fact[n] * factinv[k] % MOD * factinv[n - k] % MOD;
}

int main() {
    make();
    check();
    long n, a, b, k;
    cin >> n >> a >> b >> k;
    long ans = 0;
    for (int i = 0; i <= n; i++) {
        long bs = k - a * i;
        if (bs < 0) continue;
        if (bs % b) continue;
        ans += comb(n, i) * comb(n, bs / b);
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5120
count1,count2 = 0,0
while gets
  a,b,c = $_.chomp.split(',').map(&:to_i)
  count1 += 1 if c**2 == a**2 + b**2
  count2 += 1 if c**2 != a**2 + b**2 && a == b
end
puts count1,count2

Measured memory_bytes: 6104
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
 
int main()
{
    int n, m, a[50], b[50], cnt = 0;

    std::cin >> n >> m;
    for(int i = 0;i < m;i++){
        std::cin >> a[i] >> b[i];
    }

    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            if(a[j] == i + 1){
                cnt++;
            }
            if(b[j] == i + 1){
                cnt++;
            }
        }
        std::cout << cnt << '\n';
        cnt = 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

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

    int sum = 0;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        sum += b - a + 1;
    }

    cout << sum << endl;
}

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

using namespace std;

int main() {
    vector<int> dishes(5);
    for(auto& d : dishes)
        cin >> d;

    sort(dishes.begin(), dishes.end(), [](int x, int y) -> int {
        return (x+9)%10 > (y+9)%10;
    });

    int total_time = 0;

    for(auto d=dishes.begin(); d != dishes.end()-1; d++)
        total_time += *d + 9 - (*d+9)%10;
    total_time += *(dishes.end()-1);
    cout << total_time << endl;

    return 0;
}

Measured memory_bytes: 256
import collections

N = int(input())

#素因数分解
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

max_devide = 0
ans = 1
for i in range(N+1):
    
    if factorize(i).count(2) > max_devide:
        max_devide = factorize(i).count(2)
        ans = i

print(ans)

Measured memory_bytes: 3316
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

//#include "set/union_find_g.h"
template<class T>
struct gufs {
	map<T,T> f;
	map<T,int> c;
	T find(T v) {
		T r, u;
		for(r=v; f.find(r) != f.end(); r=f[r]);
		for(u=v; u!=r; ) {
			T t = f[u];
			f[u] = r;
			u = t;
		}
		if (c.find(r)==c.end()) c[r] = 1;
		return r;
	}
	T merge(T a, T b) {
		a = find(a);
		b = find(b);
		if (a!=b) {
			f[a] = b;
			c[b] += c[a];
		}
		return b;
	}
	void clear() {
		f.clear();
		c.clear();
	}
	int count(int v){
		return c[find(v)];
	}
	void get_sets(map<T,vector<T>> &s) {
		for (auto &x: f) {
			s[find(x.first)].push_back(x.first);
		}
		for (auto &x: s) {
			s[x.first].push_back(x.first);
		}
	}
};

#define MAXN 100000

int n, m;
vector<pair<int,int>> g[MAXN];

map<int, gufs<int>> uf;
map<int, map<int, vector<int>>> us;

int q[MAXN];
int h, t;
int dist[MAXN];

void adde(int a, int b, int c) {
	g[a].push_back({b,c});
	g[b].push_back({a,c});
	uf[c].merge(a, b);
}

int input() {
	if (scanf("%d %d", &n, &m) < 0) return 0;
	for (int i=0; i<m; i++) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		a--, b--, c--;
		adde(a,b,c);
	}
	return 1;
}

void init() {
	for (int i=0; i<n; i++) dist[i] = INT_MAX;
	for (auto &x: uf)
		x.second.get_sets(us[x.first]);
}

int solve() {
	h=0, t=0;
	dist[0] = 0;
	q[t++] = 0;
	set<pair<int,int>> done;
	while (h<t) {
		int v = q[h++], d = dist[v]+1;
		//printf("-->v=%d d=%d\n", v, d);
		for(auto &x: g[v]) {
			int u = x.first, c = x.second;

			//need to process when dist[u]==d
			if (dist[u] < d) continue;

			int r = uf[c].find(v);

			//!! speed up
			if (done.count({c,r})) continue;
			done.insert({c,r});

			for (auto &x: us[c][r]) {
				if (d < dist[x]) {
					dist[x] = d;
					q[t++] = x;
				}
			}
		}
	}
	//cout << us << endl; printa(dist,n);
	return dist[n-1];
}

void output(int ans) {
	printf("%d\n", ans==INT_MAX? -1: ans);
}

void cleanup() {
	for (int i=0; i<n; i++) g[i].clear();
	uf.clear();
	us.clear();
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 109940
# C - AtCoDeerくんと選挙速報
from math import ceil
n=int(input())
t,a=1,1
for i in range(n):
    tt,aa=map(int,input().split())
    min_num=max(-(-t//tt),-(-a//aa))
    # min_num=max(ceil(t/tt),ceil(a/aa))
    t=min_num*tt
    a=min_num*aa
print(t+a)


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

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    ll a, b, n; cin >> a >> b >> n;
    double num = min(n, b-1);
    ll ans = floor(a*num/b);
    cout << ans << endl;
}

Measured memory_bytes: 3732
#include<stdio.h>
#define N 100
#define INF 1000000

void BFS(int );
void enqueue(int);
int dequeue(void);

int n,M[N][N];
int d[N];

int q[2*N];
int head = 1,tail=1;
int i,j;

int main()
{
  int u,k,v;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u=u-1; //0オリジンへ変換
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v=v-1; //0オリジンへ変換
      M[u][v] = 1; // 辺作成
    }
  }
  BFS(0);
  return 0;
}

void BFS(int s){
  int u,v;
  
  enqueue(s);
  for(i=0;i<n;i++) d[i]=INF;
  d[s]=0;
  while(head!=tail){//空ではないとき
    u=dequeue();
    for(v=0;v<n;v++){
      if(M[u][v]==0) continue;
      if(d[v]!=INF) continue;
      d[v]=d[u]+1;
      enqueue(v);
    }
  }
  for(i=0;i<n;i++){
    if(d[i]==INF) printf("%d %d\n",i+1,-1);
    else printf("%d %d\n",i+1,d[i]);
  }
}

void enqueue(int u){
  q[tail++]=u;
}

int dequeue(void){
  return q[head++];
}



Measured memory_bytes: 2108
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long ans = 0;
        if(m/2 >= n){
            ans += n;
        }
        else{
            ans += m/2;
        }
        m -= 2*ans;
        if(m >= 0){
            ans += m / 4;
        }

        System.out.println(ans);
    }
}


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

int main() {
    ll h,w;
    cin >> h >> w;
    if(h==1 || w==1) cout << 1 << endl;
    else{
    ll ans = ((h+1)/2)*((w+1)/2)+(h/2)*(w/2);
    cout << ans << endl;
    }
}

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

int main(void){
    int n, count;
    int x = 1, y = 0;
    int record[120];
    int score[120];
    char name[120][20];
    char order[50];
    
    fgets(order, 50, stdin);
    sscanf(order, "%d", &n);
    
    for(int i = 0; i < n; i++){
        fgets(order, 50, stdin);
        sscanf(order, "%s %d", name[i], &score[i]);
        record[i] = n;
    }
    
    for(int i = 0; i < n; i++){
        for(int k = 0; k < n; k++){
            if(i == k){
                continue;
            }
            if(strcmp(name[i], name[k]) == 0){
                if(score[i] > score[k]){
                    record[i] -= 1;
                    continue;
                }
                if(score[i] < score[k]){
                    continue;
                }
            }
            count = 0;
            while(1){
                if(name[i][count] < name[k][count]){
                    record[i] -= 1;
                    break;
                }
                else if(name[i][count] > name[k][count]){
                    break;
                }
                else if(name[i][count] == name[k][count]){
                count++;
                }
            }
        }
    }
    
    while(1){
        if(x == record[y]){
            printf("%d\n", y + 1);
            x++;
        }
        y++;
        if(x > n){
            break;
        }
        if(y > n - 1){
            y = 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 128
lines = $stdin.read

array = lines.chomp.downcase.each_codepoint.to_a
sum_h = (96..122).to_a.map{ |c| [c, 0]}.to_h
array.each{|i| sum_h[i] += 1 unless sum_h[i].nil? }

sum_h.sort.select{|k,v| 96 < k && k < 123 }.map do |k,v|
        puts "#{k.chr} : #{v}"
end

Measured memory_bytes: 8620
N = int(input())
A = []
XY = []
for i in range(N):
    a = int(input())
    A.append(a)
    XY.append([list(map(int, input().split())) for _ in range(a)])


ans = 0
# print(singi)
for i in range(2 ** N):
    singi = [-1] * (N + 1)
    bin_ = bin(i)[2:].zfill(N)
    flag = True
    for j in range(1, N + 1):
        sin = int(bin_[j - 1])
        person = j
        num = A[j-1]
        questions = XY[j - 1]

        if sin == 0:
            continue

        if singi[j] == -1:
            singi[j] = sin
        else:
            if singi[j] != sin:
                flag = False

        for k in range(num):
            hito, honto = questions[k]
            if singi[hito] == -1:
                singi[hito] = honto
            else:
                if singi[hito] != honto:
                    flag = False

    if flag is True:
        singi = singi[1:]
        for b, s in zip(list(bin_), list(singi)):
            b = int(b)
            s = int(s)
            if (b == 1 and s == 0) or (b == 0 and s==1):
                flag = False
        if flag is True:
            ans = max(ans, singi.count(1))
print(ans)


        



    


Measured memory_bytes: 51676
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
const int MAX = 1000000000;

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    int N;
    cin >> N;
    vector<vector<int>> G(N);
    for(int i = 0; i < N; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for(int i = 0; i < k; i++) {
            int v;
            cin >> v;
            v--;
            G[u].push_back(v);
        }
    }
    for(int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            int ans = 0;
            for (auto v : G[i]) {
                if(j==v){
                    ans = 1;
                }
            }
            cout << ans;
            if(j<N-1)cout<<' ';
        }
        cout << endl;
    }
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
int main()	{
  int n;
  int ans=0;
  cin>>n;
  vector<int>d(n),num(101);
  rep(i,n){cin>>d[i];}
  rep(i,n){
    num[d[i]]++;   
  }
  for(int i=1;i<101;i++){
    if(num[i])
      ans++;
  }
   cout<<ans<<endl;
}


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

int main(){
	ll n,m,ans=0;
	cin>>n>>m;
    ll a[n],st[n+1];
    rep(i,0,n)cin>>a[i];
    map <ll,ll> b;
    b[0]++,st[0]=0;
    rep(i,1,n+1){
        st[i]=(st[i-1]+a[i-1])%m;
        b[st[i]]++;
    }
    for(auto i=b.begin();i!=b.end();i++)ans+=i->second*(i->second-1)/2;
    cout<<ans<<endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX



 
void solve()
{
  int n,m;
  cin >> n >> m;
  int a[n], b[n];
  rep(i,0,n-1)
    cin >> a[i] >> b[i];
  vector<int> arr[100001];
  rep(i,0,n-1)
    arr[a[i]].pb(b[i]);
  int ans = 0;
  multiset<int> q;
  rep(i,1,m)
  {
    loop(arr[i])
        q.insert(it);
    if(q.size()==0)
        continue;
    int xx = *q.rbegin();
    ans += xx;
    q.erase(q.find(xx));
  }

  cout << ans << endl;
  
  
}


signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 9856
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
As = list(mapint())
double_As = As*2
idx_dic = {}
idx_lis = [N+1]*(2*N)
for i in range(N*2-1, -1, -1):
    a = double_As[i]
    if a in idx_dic:
        idx_lis[i] = idx_dic[a]+1
    idx_dic[a] = i
doubling = [[0]*N for _ in range(60)]
accum = [[0]*N for _ in range(60)]
doubling[0] = [i%N for i in idx_lis[:N]]
accum[0] = [a-i for i, a in enumerate(idx_lis[:N])]
for i in range(1, 60):
    for j in range(N):
        doubling[i][j] = doubling[i-1][doubling[i-1][j]]
        accum[i][j] = accum[i-1][j] + accum[i-1][doubling[i-1][j]]
now = 0
cum = 0
cnt = 0
for i in range(59, -1, -1):
    if cum + accum[i][now]>N*K:
        continue
    else:
        cum += accum[i][now]
        now = doubling[i][now]
ans = []
while cum<N*K:
    if cum+accum[0][now]<=N*K:
        cum += accum[0][now]
        now = doubling[0][now]
    else:
        ans.append(As[now])
        now += 1
        cum += 1
print(*ans)


Measured memory_bytes: 568580
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
 
 
const ll INF = 1e18;
const ll N =(2e5+5); // TODO : change value as per problem
const ll MOD = 998244353;
ll dp[3005][3005];
void solve(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for(int i = a;i<=c;i++){
    	for(int j = b;j<=d;j++){
    		dp[i+1][j] = (dp[i+1][j]+(dp[i][j] * j)%MOD + MOD)%MOD;
    		dp[i][j+1] = (dp[i][j+1]+(dp[i][j] * i)%MOD + MOD)%MOD;
    		dp[i+1][j+1] -= (dp[i][j]*i*j);
    		if(dp[i+1][j+1] < 0)dp[i+1][j+1] += MOD;
    		//dp[i+1][j+1] -= (dp[i][j]*j);
    	}
    } 
    cout << dp[c][d] << endl;
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    

 
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

Measured memory_bytes: 73920
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> high(n);
	for (int i = 0; i < n; i++) cin >> high.at(i);
	vector<vector<int>> road(n, vector<int>(0));
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		road.at(a - 1).push_back(b);
		road.at(b - 1).push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int flip = 0;
		for (int j = 0; j < road.at(i).size(); j++) {
			if (high.at(i) <= high.at(road.at(i).at(j)-1)) {
				flip++;
			}
		}
		if (flip == 0) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 8816
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
  static void Main(string[] args) {
    var sc = new Scanner();
    int N = sc.NextInt();
    var list = new int[N];
    for(int i = 0; i < N; i++) list[i] = sc.NextInt();
    int cnt = 0;
    for(int i = 0; i < list.Length; i++) {
      for(int j = list.Length - 1; j > i; j--) {
        if(list[j] < list[j - 1]) {
          int t = list[j];
          list[j] = list[j - 1];
          list[j - 1] = t;
          cnt++;
        }
      }
    }
    Console.WriteLine(string.Join(" ", list.Select(x => x.ToString()).ToArray()));
    Console.WriteLine(cnt);
  }

  class Scanner {
    string[] inp;
    int ptr;

    public Scanner() {
      inp = new string[0];
      ptr = 0;
    }

    private void Fetch() {
      if (ptr >= inp.Length) {
        inp = Console.ReadLine().Split(' ');
        ptr = 0;
      }
    }

    public int NextInt() {
      Fetch();
      return int.Parse(inp[ptr++]);
    }

    public string Next() {
      Fetch();
      return inp[ptr++];
    }

    public double NextDouble() {
      Fetch();
      return double.Parse(inp[ptr++]);
    }
  }

}

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

bool sum_for(std::vector<int>& A, int m, int k){
    if(m == 0){
	return true;
    }else if(0 > m){ // over
	return false;
    }else if(A.size() == k){ // no more candidates
	return false;
    }else{
	if(sum_for(A, m - A.at(k), k + 1) || 
	   sum_for(A, m, k + 1)){
	    return true;
	}else{
	    return false;
	}
    }
}

int main(int argc, char **argv){

    int n, q;

    std::cin >> n;
    std::vector<int> A(n);

    for(int i = 0; i < n; i++){
	std::cin >> A.at(i);
    }

    std::cin >> q;
    std::vector<int> M(q);
    for(int i = 0; i < q; i++){
	std::cin >> M.at(i);
    }

    for(int i = 0; i < q; i++){
	if(sum_for(A, M.at(i), 0)){
	    std::cout << "yes" << std::endl;
	}else{
	    std::cout << "no" << std::endl;
	}
    }
    
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

const int N = 12, Q = 52;
int a[Q], b[Q], c[Q], d[Q];
int p[N];

int solve(int n, int m, int q, int ptr = 2) {
    if (ptr == n + 1) {
        int ans = 0;
        for (int i = 1; i <= q; i++) {
            if (p[b[i]] - p[a[i]] == c[i]) {
                ans += d[i];
            }
        }
        return ans;
    }
    else {
        int ans = 0;
        for (int i = p[ptr - 1]; i <= m; i++) {
            p[ptr] = i;
            ans = max(ans, solve(n, m, q, ptr + 1));
        }
        return ans;
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 1; i <= q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    p[1] = 1;
    cout << solve(n, m, q) << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define ub(s,x) (upper_bound(all(s),x)-s.begin())

int main(void){
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    vector<int> pos[26];
    rep(i,n){
        pos[s[i]-'a'].push_back(i);
    }
    ll turn = 0, k = -1;
    rep(i,m){
        auto &vec = pos[t[i]-'a'];
        if (vec.size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        int index = ub(vec, k);
        if (index == (int)vec.size()) {
            turn++;
            index = ub(vec, -1);
        }
        k = vec[index];
    }
    cout << turn * n + k + 1 << endl;
    return 0;
}


Measured memory_bytes: 1216
import std.stdio;
import std.conv;
import std.array;
import std.math;
import std.string;

int N;
string S;
int mem[8][1001];

void main()
{
  N = to!int(chomp(readln()));
  S = readln();
  writeln(dp(0b00000100, 0));
}

int dp(int n, int m)
{
  if(m == N)
    return 1;
  if(mem[n][m])
    return mem[n][m];
  int ans = 0;
  for(auto i = 0; i < 0b00001000; i++)
  {
    switch(S[m])
    {
      case 'J':
        if((i & 0b00000100) == 0)
          continue;
        break;
      case 'O':
        if((i & 0b00000010) == 0)
          continue;
        break;
      case 'I':
        if((i & 0b00000001) == 0)
          continue;
        break;
      default:
    }
    if((i & n) == 0)
      continue;
    ans += dp(i, m + 1);
  }
  return mem[n][m] = ans % 10007;
}

Measured memory_bytes: 1196
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#define WMAX 10000
#define HMAX 10000

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

struct edge{
  int to,cost;
};

int A,B,C,N,W,H,ans,dp[HMAX][WMAX];
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){
	ans = B + (B-A);
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	cin >>A >> B;
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

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

int main(){
  string stone;
  int ans = 0;
  int n;
  cin >> n;
  cin >> stone;

  int left = 0;
  int right = n-1;
  while(1){
    while(stone[left]=='R'&&left<n)left++;
    while(stone[right]=='W'&&0<=right)right--;
    // cout << "[" << left << ' ' << right << "]";
    if(left>=right)break;
    left++;right--;
    ans++;
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 3756
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
ll a[N];
ll sum[N];
ll f[N];
int main()
{
    memset(sum, 0, sizeof sum);
    memset(f, 0, sizeof f);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if(i > 1)
            sum[i] = sum[i - 2] + a[i];
        else
            sum[i] = a[i];
    }
    for(int i = 2; i <= n; i++)
    {
        if(i & 1)
            f[i] = max(f[i - 2] + a[i], f[i - 1]);
        else
            f[i] = max(f[i - 2] + a[i], sum[i - 1]);
    }
    cout << f[n] << endl;
    return 0;
}


Measured memory_bytes: 8296