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

#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll MOD = 1000000007;
const long long INF = 1LL << 60;
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

signed main()
{   
    gearup;
    int n; cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    ll res = 0;
    rep(i,n){
        FOR(j,i+1,n){
            res += d[i]*d[j];
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"1"# => r#"1"#,
r#"3"# => r#"6"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
    }

    let mut ans = 0;
    for i in 1..n + 1 {
        ans += i;
    }

    ans.to_string()
}

Measured memory_bytes: 4352
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        int a = 1;
        int p = 0;
        while((1 << a) <= n){
            sb.append(a + " " + (a+1) + " " + 0 + "\n");
            p++;
            sb.append(a + " " + (a+1) + " " + (1 << (a-1)) + "\n");
            p++;
            a++;
        }
        a--;
        int b = 1 << a;
        int last = a + 1;
        for (int i = a; i > 0; i--) {
            int c = (1 << (i-1)) -1;
            if(b + c < n){
                sb.append(i + " " + last + " " + b + "\n");
                p++;
                b += c+1;
            }
        }
        a++;
        System.out.println(a + " " + p);
        System.out.println(sb.toString());
        sc.close();

    }

}


Measured memory_bytes: 21844
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

//LOVE NyantakoGG

using namespace std;


int main() {
	int N, K;
	cin >> N >> K;
	vector<int>h(N);
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	vector<int>dp(N);
	for (int i = 0; i < N; i++) {
		dp[i] = INT_MAX;
	}
	/*if (N - 1 <= K) {
		return 0;
	}*/
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = max(0, i - K); j < i; j++) {
			chmin(dp[i], dp[j] + abs(h[j] - h[i]));
		}
	}
	cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=acos(-1);
const ll INF=1e18;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n;
  cin >> n;
  if(n==1){
    cout << 0 << endl;
  }
  else{
    ll ans=0;
    ll k=sqrt(n)+1;
    FOR(i,2,k+2){
      ll cnt=0;
      while(n%i==0){
        n/=i;
        cnt++;
      }
      ll z=0;
      ll add=1;
      while(z+add<=cnt){
        ans++;
        z+=add;
        add++;
      }
    }
    if(n!=1){
      ans+=1;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3684
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> v(n), a(n + 1), b(n + 1);
    rep(i, 0, n) cin >> v[i];
    a[0] = 0, b[n] = 0;
    a[1] = v[0], b[n - 1] = v[n - 1];
    rep(i, 0, n - 1)
    {
        a[i + 2] = __gcd(a[i + 1], v[i + 1]);
        b[n - 2 - i] = __gcd(b[n - 1 - i], v[n - 1 - i - 1]);
    }
    // rep(i, 0, n + 1) cout << a[i] << " ";
    // cout << endl;
    // rep(i, 0, n + 1) cout << b[i] << " ";
    ll ans = 0;
    rep(i, 0, n + 1)
    {
        if (a[i] == 0)
            ans = max(ans, b[i + 1]);
        else if (b[i + 1] == 0)
            ans = max(ans, a[i]);
        else
            ans = max(ans, __gcd(a[i], b[i + 1]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 5584
n, m = map(int, input().split())
abs = []
for i in range(n):
  a, b = map(int, input().split())
  abs.append({'price': a, 'count': b})
cnt = 0
total_price = 0

for x in sorted(abs, key=lambda x: x['price']):
  if cnt + x['count'] < m:
    cnt += x['count']
    total_price += x['count'] * x['price']
  else:
    total_price += (m - cnt) * x['price']
    break

print(total_price)


Measured memory_bytes: 42296
from bisect import bisect_left, bisect_right
n,q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

numbers = []
for i in range(n-1):
    if s[i]+s[i+1] == "AC":
        numbers.append(i+1)
for l,r in lr:
    x,y = bisect_left(numbers, l), bisect_right(numbers, r)
    if x==y: print(0)
    elif numbers[y-1]+1 <= r:print(y-x)
    else: print(y-x-1)

Measured memory_bytes: 30340
import java.io.File;
import java.io.FileNotFoundException;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {
	Scanner sc;

	int j(int n, int m, int k) {
		int x = -1;
		for (int i = n - k + 1; i <= n; i++) {
			x = (x + m) % i;
		}
		return x;
	}

	void run() {
		for (;;) {
			int n = sc.nextInt();

			int k = sc.nextInt();
			int m = sc.nextInt();

			if ((n | k | m) == 0) {
				break;
			}

			int v = j(n, k, n);

			System.out.println((v +(-k+m +n)+k*n )%n +1);
		}
	}

	Main() {
		sc = new Scanner(System.in);
		try {
			sc = new Scanner(new File(""));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int a[110];
int b[110];
double opv[110];
int cnt;

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int d, g;
    int ans = 0;
    while (cin >> d >> g) {
        FOR(i,0,d) 
            cin >> a[i] >> b[i];
        int ans = 1e9;
        FOR(mask,0,(1 << d)) {
            int cnt = 0, num = 0, j = -1;
            FOR(i,0,d) if (mask & (1 << i)) {
                cnt += a[i];
                num += 100 * (i+1) * a[i] + b[i];
                if (j == -1)
                    j = i;
            }
            if (num >= g) {
                ans = min(ans, cnt);
                FOR(j,0,d) if (mask & (1 << j)) {
                    int c = cnt;
                    int n = num;
                    if (n - b[j] >= g) {
                        n -= b[j];
                        FOR(k,0,a[j]) {
                            if (n - 100 * (j+1) < g)
                                break;
                            c--;
                            n -= 100 * (j+1);
                        }
                    }
                    ans = min(ans, c);
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
n = int(readline())
a = list(map(int,readline().split()))
s = a[0]+a[1]
if n == 2:
  if a[0] < a[1] or s%2 == 1:
    print(-1)
  else:
    print(a[0]-s//2)
  exit()
  
c = 0
for i in a[2:]:
  c ^= i
 
sc = (s-c)//2
if s < c or (s-c)%2 == 1 or c&sc:
  print(-1)
  exit()
 
bb = a[0].bit_length()
x = ''
chk = 0
for i in range(bb-1,-1,-1):
  if not (c>>i&1)|(sc>>i&1):
    x += '0'
  elif not c>>i&1 and sc>>i&1:
    x += '1'
    chk += 2**i
  else:
    x += '?'
  
for i in range(bb):
  if x[i] == '?':
    if a[0] >= chk+2**(bb-1-i):
      chk += 2**(bb-1-i)
 
ans = a[0]-chk
print(ans if a[0] > ans >= 0 else -1)

Measured memory_bytes: 9248
i = 1

while True:
    H,W = map(int, input().split())
    if H == 0 and W == 0:
        break
    print('#' * W)    
    for i in range(H-2):
        print('#' + '.' * (W-2) + '#')   
        i += 1
    print('#' * W)
    print()




Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main(){
    ll a, b, n, i, res = 0;
    cin >> a >> b >> n;
    i = min(n, b-1);
    res = max(res, (ll)floor((double)a * (double)i / (double) b) - a * (ll)floor((double)i / (double) b));
    cout << res;
    
    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>


int main(void)
{
  int card[4][13];
  char Char;
  int num;
  
  int i;
  int j;
  int k;
  
  for( i = 0; i < 4; i++ ){
    for ( j = 0; j < 13; j++ ){
      card[i][j] = 1;
    }
  }
  
  int n;
  scanf("%d", &n);
  
  for( k = 0; k < 2*n; k++ ){
    
    scanf("%c %d", &Char, &num );
    
    if( Char == 'S' ) card[0][num-1] = 0;
    if( Char == 'H' ) card[1][num-1] = 0;
    if( Char == 'C' ) card[2][num-1] = 0;
    if( Char == 'D' ) card[3][num-1] = 0;
       
  }
  
  
  for( i = 0; i < 4; i++ ){
    for( j = 0; j < 13; j++ ){
      switch( i ){
        case 0: { if( card[i][j] ) printf("S %d\n", j+1); break; }
        case 1: { if( card[i][j] ) printf("H %d\n", j+1); break; }
        case 2: { if( card[i][j] ) printf("C %d\n", j+1); break; }
        case 3: { if( card[i][j] ) printf("D %d\n", j+1); break; }
      }
    }
  }
  
  
  
  return 0;

 
}       

Measured memory_bytes: 596
S = int(input())
#(0, 0), (a, b), (c, d)
#S = |ad-bc|

root_S = S**(1/2)

if root_S == int(root_S):
  a, b, c, d = int(root_S), 0, 0, int(root_S)

else:
  a, d = int(root_S)+1, int(root_S)+1
  ad_S = a*d - S
  for b in range(1, 10**5):
    c = ad_S / b
    if c == int(c):
      c = int(c)
      break

print("0 0 " + str(a) + " " + str(b) + " " + str(c) + " " + str(d))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <map>
#include <algorithm>
#define pb push_back
#define fr first
#define sc second
using namespace std;

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

int main(){
  int w,h,n;
  ll cnt = 0;
  cin >> w >> h >> n;
  vector<iP> v;
  for(int i=0;i<n;i++){
    int x,y; cin >> x >> y; v.pb(iP(--x,--y));
  }
  for(int i=0;i<n-1;i++){
    int x = v[i].fr,y = v[i].sc;
    int gx = v[i+1].fr,gy = v[i+1].sc;
    if(x > gx && y > gy) cnt += max(abs(x - gx),abs(gy-y));
    else if(x < gx && y < gy) cnt += max(abs(gx - x),abs(gy-y));
    else if(gx != x && gy != y) cnt += abs(gx - x) + abs(gy - y);
    else if(gx == x && gy != y) cnt += abs(y - gy);
    else if(gx != x && gy == y) cnt += abs(x - gx);
  }
  cout << cnt << endl;
}
    

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);
#define readV(_v) rep(j, _v.size()) cin >> _v[j];
#define readVV(_vv) rep(i, _vv.size()) readV(_vv[i]);
#define print(_x) cout << _x << endl;

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

string rev(string s) {
    string t;
    rrep(i, s.size()) {
        t += (s[i] == '<' ? '>' : '<');
    }
    return t;
}

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    if (s.find(">") == string::npos || s.find("<") == string::npos) {
        cout << n << endl;
        return 0;
    }

    int ans = -1;
    rep(t, 2) {
        vi vr;
        vi vl;
        rep(i, n) {
            if (s[i] == '<') {
                vr.emplace_back(i);
            } else {
                vl.emplace_back(i);
            }
        }

        int l = 0, r = 0;
        int cl = 0, cr = 1;
        rep(i, n) {
            if (s[i] == '>') {
                if (cl < cr) {
                    assert(cl == cr - 1);
                    ans = max(ans, vr[r] + 1);
                    // l???????????????cl???1?¢???????
                    cl++;
                    // cr????¢?????????????????¢???????
                    if (r + 1 < vr.size()) {
                        r++;
                        cr++;
                    }
                } else {
                    assert(cl == cr);
                    ans = max(ans, n - vl[l]);
                    // cl???????????????l???1?????????
                    l++;
                }
            } else {
                // '<'???1?????±?????????
                if (r + 1 < vr.size()) {
                    // ?¨??????????????????°cr????????£???????????????
                    r++;
                } else {
                    // ?¨?????????????????????°1????????????
                    cr--;
                    if (cl > cr) {
                        cl--;
                        l++;
                    }
                }
            }
        }
        s = rev(s);
    }

    cout << ans << endl;

}

Measured memory_bytes: 4700
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }
class UnionFind {
    vector<int> uni;
    int n;
public:
    explicit UnionFind(int n) : uni(static_cast<u32>(n), -1) , n(n){};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        return true;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    auto v = make_v(n, n, 0);
    for (int i = 0; i < m; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        v[x-1][y-1] = v[y-1][x-1] = 1;
    }
    vector<vector<int>> G(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(i != j && !v[i][j]) G[i].emplace_back(j);
        }
    }
    vector<int> used(n), color(n, -1);
    stack<int> s;
    for (int x = 0; x < n; ++x) {
        if(used[x]) continue;
        color[x] = 0;
        s.emplace(x);
        while(!s.empty()){
            int i = s.top(); s.pop();
            used[i] = 1;
            for (auto &&j : G[i]) {
                if(color[j] == color[i]){
                    puts("-1");
                    return 0;
                }
                color[j] = 1-color[i];
                if(!used[j]) s.emplace(j);
            }
        }
    }
    UnionFind uf(n);
    for (int i = 0; i < n; ++i) {
        for (auto &&j : G[i]) {
            uf.unite(i, j);
        }
    }
    vector<pair<int, int>> colors(n, {0, 0});
    for (int i = 0; i < n; ++i) {
        if(color[i] == 0) colors[uf.root(i)].first++;
        else colors[uf.root(i)].second++;
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if(colors[i] != make_pair(0, 0)) cnt++;
    }
    vector<bitset<1000>> dp(cnt+1);
    dp[0].set(0);
    int cur = 0;
    for (int i = 0; i < n; ++i) {
        if(colors[i] != make_pair(0, 0)){
            dp[cur+1] |= dp[cur] << colors[i].first;
            dp[cur+1] |= dp[cur] << colors[i].second;
            cur++;
        }
    }
    ll ans = INF<ll>;
    for (ll i = 0; i <= n; ++i) {
        if(dp[cur][i]){
            chmin(ans, i*(i-1)/2+(n-i)*(n-i-1)/2);
        }
    }
    cout << ans << "\n";
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

int a[10];

int main(int argc,char* argv[])
{
    int n,k;
    cin>>n>>k;
    rep(i,k)
    {
        int x;
        cin>>x;
        a[x]++;
    }

    int m = n;
    while(true)
    {
        int l = m;
        while(l>0)
        {
            if(a[l%10] == 1)break;
            l/=10;
        }
        if(l == 0)
        {
            cout<<m<<endl;
            return 0;
        }
        m++;
    }
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
import math
 

N, D = [int(x) for x in stdin.readline().rstrip().split()]

X = []
x = []
for i in range(0, N):
    x = [int(x) for x in stdin.readline().rstrip().split()]
    X.append(x)

count = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        leng = 0
        for k in range(0,D):
            dist = X[i][k] - X[j][k]
            leng += (dist*dist)
        if leng == 1:
            count += 1
        else:
            for n in range(1,leng):
                if leng == n*n:
                    count += 1

    
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
const ll  mod=1000000007;
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
ll fact[1000005];
ll invfact[1000005];
ll power(ll x,ll y){
  if(y<=0) return 1;
  ll z=power(x,y/2);
  if(y%2) return ((z*z)%mod)*x%mod;
  return (z*z)%mod;
}
ll Cr(ll x, ll y){
  return (((fact[x]*invfact[x-y])%mod)*invfact[y])%mod;
}
void make_fact(ll n){
  fact[0]=1;
  rep(i,1,n+1) fact[i]=(i*fact[i-1])%mod;
  invfact[0]=1;
  rep(i,1,n+1) invfact[i]=(power(i,mod-2)*invfact[i-1])%mod;
}
ll solve1(ll x, ll y ){
  return (((Cr(x,y)*Cr(x,y))%mod)*((fact[y]*fact[y])%mod))%mod;
}
void  solve(){
  ll n,m;
  cin>>n>>m;
  make_fact(n+m+1);
  ll ans= solve1(m,n);
  // cout<<ans<<endl;
  rep(i,1,n+1){
    ll z=solve1(m-i,n-i);
    z=(z*fact[i])%mod;
    z=(z*Cr(n,i))%mod;
    z=(z*Cr(m,i))%mod;
    if(i%2==1)ans=(ans+mod-z)%mod;
    else ans=(ans+mod+z)%mod;
  }
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 19076
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7; 

fn dfs(p: usize, g: &Vec<Vec<usize>>, c: &mut Vec<usize>, used: &mut Vec<bool>){
    used[p] = true;
    for i in &g[p]{
        if used[*i]{
            continue;
        }
        c[*i] += c[p];
        dfs(*i, g, c, used);
    }
}

fn main(){
    let n: usize = read();
    let q: usize = read();
    let mut g: Vec<Vec<usize>> = vec![vec![]; n];
    let mut c: Vec<usize> = vec![0; n];
    let mut used: Vec<bool> = vec![false; n];
    for _ in 0..n-1{
        let mut a: usize = read();
        let mut b: usize = read();
        a -= 1;
        b -= 1;
        g[a].push(b);
        g[b].push(a);
    }
    for _ in 0..q {
        let mut p: usize = read();
        let x: usize = read();
        p -= 1;
        c[p] += x;
    }
    dfs(0, &g, &mut c, &mut used);
    print!("{}", c[0]);
    for i in 1..n {
        print!(" {}", c[i]);
    }
    println!();
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 33276
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    l,r,d = LI()
    ans = 0
    for i in range(l,r+1):
        if i%d ==0 :
            ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 65476
input()
a = list(map(int, input().split()))
b = []
for i in range(len(a)):
  if (a[i] % 2) == 0:
    if (((a[i] % 3) == 0) or ((a[i] % 5) == 0)):
      b.append(True)
    else: 
      b.append(False)
if (False in b):
  print("DENIED")
else:
  print("APPROVED")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000010;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	vector<bool> ans(n*10); int idx = 0;
	rep(i, n) {
		if (idx >= n) break;
		if (i > 0 && a[i] == a[i - 1]) {
			ans[idx] = !ans[idx - 1];
			idx++;
			continue;
		}
		int cnt = min((i ? a[i] - a[i - 1] + 1 : a[i]), n - idx);
		int tp = cnt + (i ? a[i - 1] : 1) - 1;
		if ((a[i] - tp) % 2 != 0) ans[idx + cnt - 1] = true;
		for (int j = idx + cnt - 2; j >= idx; j--) ans[j] = !ans[j + 1];
		if (idx && !ans[idx - 1]) ans[idx] = true;
		idx += cnt;
	}
	cout << (ans[n - 1] ? "First" : "Second") << '\n';
}

Measured memory_bytes: 768
def main():
    import sys
    from collections import deque
    input = sys.stdin.readline

    N, M = map(int, input().split())
    adj = [[] for _ in range(N+1)]
    c2v = {}
    v = N+1
    for _ in range(M):
        p, q, c = map(int, input().split())
        P = p*(10**7) + c
        Q = q*(10**7) + c
        if P not in c2v:
            c2v[P] = v
            adj[p].append((v, 1))
            adj.append([(p, 1)])
            v += 1
        if Q not in c2v:
            c2v[Q] = v
            adj[q].append((v, 1))
            adj.append([(q, 1)])
            v += 1
        adj[c2v[P]].append((c2v[Q], 0))
        adj[c2v[Q]].append((c2v[P], 0))

    que = deque()
    que.append(1)
    seen = [-1] * len(adj)
    seen[1] = 0
    while que:
        v = que.popleft()
        for u, cost in adj[v]:
            if seen[u] == -1:
                seen[u] = seen[v] + cost
                if cost:
                    que.append(u)
                else:
                    que.appendleft(u)
    print(seen[N] // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 170684
#include <bits/stdc++.h>
using namespace std;
#define int long long int
void solve(){
  string s;
  cin>>s;
  int cnt =0 ;
  int ans = 0;
  int n = s.size();
  for(int i=0;i<n;i++){
    if(s[i] == 'R')
      cnt++;
    else{
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  ans = max(ans, cnt);
  cout<<ans<<endl;
}
signed main(){
  // int t;
  // cin>>t;
  // while(t--)
    solve();
}


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

int main(){
    int n;
    cin >> n;
    vector<int> ans(26, 50);
    for (int i = 0; i < n; i++){
        string s;
        cin >> s;
        vector<int> tmp(26, 0);
        for (int j = 0; j < s.size(); j++) tmp[s[j] - 'a']++;
        for (int j = 0; j < 26; j++) ans[j] = min(ans[j], tmp[j]);
    }
    for (int i = 0; i < 26; i++){
        for (int j = 0; j < ans[i]; j++) cout << (char)(i + 'a');
    }
    cout << endl;
}

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

int main(){
    int n;
    int *changePrice;
    cin >> n;
    changePrice = new int[n];
    for(int i=0; i < n; i++){
        cin >> changePrice[i];
    }

    int lowest = changePrice[0];
    int maximumProfit = -2000000000;
    for(int i = 1; i < n; i++){
        int target = changePrice[i];
        int currentProfit = target - lowest;
        if(currentProfit > maximumProfit){
            maximumProfit = currentProfit;
        }
        if(target < lowest){
            lowest = target;
        }
    }
    cout << maximumProfit << endl;

    return 0;
}


Measured memory_bytes: 3872
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;
const int M=1000000007;
const double PI=3.141592653589793238;
#define ri register int 
int n,q,k,i,j,l,t[3005];
double ansx,ansy;
int main()
{
	scanf("%d %d",&n,&l);
	for(i=1;i<=n;i++)
		scanf("%d",&t[i]);
	sort(t+1,t+1+n);
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
		{
			ansx+=cos(PI*(t[i]+t[j])/l)*(n-(j-i+1));
			ansy+=sin(PI*(t[i]+t[j])/l)*(n-(j-i+1));
			ansx-=cos(PI*(t[i]+t[j])/l)*(j-i-1);
			ansy-=sin(PI*(t[i]+t[j])/l)*(j-i-1);
		}
	printf("%.12lf %.12lf",ansx*6/n/(n-1)/(n-2),ansy*6/n/(n-1)/(n-2));
}


Measured memory_bytes: 512
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

import sys
sys.setrecursionlimit(4100000)
rl = sys.stdin.readline

N,K = Ints()
A = IntList()
visited = {}

Nex = [1]
now = 1
now = A[now-1]
visited[1] = 1

toS = 1

while 1:
    if not now in visited:
        if toS==K:
            print(now)
            sys.exit()
        visited[now] = 1
        now = A[now-1]
        toS += 1
    else:
        start = now
        break
    
Nex = [start]
now = start
now = A[now-1]
while now != start:
    Nex.append(now)
    now = A[now-1]    

L = len(Nex)
d = toS-L

#print(Nex)
#print(toS)
#print(toS-L)

print(Nex[(K-d)%L])

Measured memory_bytes: 114028
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const int MOD=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

int main(){
	ll n,m;
	cin>>n>>m;
	int x[M],y[M];
	//切るのは嫌なのでくっつけていく
	rep(i,0,m)cin>>x[i]>>y[i],x[i]--,y[i]--;

	UnionFind tree(n);
	ll cnt=n*(n-1)/2;
	vl ans;
	rep(i,0,m){
		ans.push_back(cnt);
		int a=x[m-1-i],b=y[m-1-i];
		if(tree.same(a,b))continue;
		ll sa=tree.size(a),sb=tree.size(b);
		cnt-=sa*sb;
		tree.merge(a,b);
	}
	reverse(ALL(ans));
	for(auto v:ans)print(v);
}


Measured memory_bytes: 3444
#include <stdio.h>

int main(){
    int touA[3][10],touB[3][10],touC[3][10],touD[3][10];
    
    int tou,kai,ban,ninzu;
    int i,j,k,n;
    
    for(i=0;i<3;i++){
        for(j=0;j<10;j++){
            touA[i][j]=0;
            touB[i][j]=0;
            touC[i][j]=0;
            touD[i][j]=0;
        }
    }
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&tou,&kai,&ban,&ninzu);
        if(tou==1){
            touA[kai-1][ban-1]+=ninzu;
        }else if(tou==2){
            touB[kai-1][ban-1]+=ninzu;
        }else if(tou==3){
            touC[kai-1][ban-1]+=ninzu;
        }else if(tou==4){
            touD[kai-1][ban-1]+=ninzu;
        }
    }
    
    for(i=0;i<3;i++){
        for(j=0;j<10;j++){
            printf(" %d",touA[i][j]);
        }
        printf("\n");
    }
    printf("####################\n");
    
    for(i=0;i<3;i++){
        for(j=0;j<10;j++){
            printf(" %d",touB[i][j]);
        }
        printf("\n");
    }
    printf("####################\n");

    for(i=0;i<3;i++){
        for(j=0;j<10;j++){
            printf(" %d",touC[i][j]);
        }
        printf("\n");
    }
    printf("####################\n");
    
    for(i=0;i<3;i++){
        for(j=0;j<10;j++){
            printf(" %d",touD[i][j]);
        }
        printf("\n");
    }


    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    int n, max = 0, sum = 0, flg;
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> flg;
        if(flg > max) max = flg;
        sum += flg;
    }
    if(max < sum - max)cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> v(n, vector<int>(2));
  int ans = 0;
  
  for(int i = 0; i < n; i++) {
    long long x ,y;
    cin >> x >> y;
    long long a = (x * x) + (y * y);
    double b = sqrt(a);
    if(b <= d) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 14344
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n, ma, mb;
	cin >> n >> ma >> mb;

	Array a(n, 0), b(n, 0), c(n, 0);
	REP(i, n) {
		cin >> a[i] >> b[i] >> c[i];
	}

	vector<Matrix> dp(n + 1, Matrix(410, Array(410, INF)));

	dp[0][0][0] = 0;
	REP(i, n) {
		REP(j, 410) {
			REP(k, 410) {
				//cout << i << " " << j << " " << k << endl;
				if (dp[i][j][k] != INF) {
					chmin(dp[i + 1][j][k], dp[i][j][k]);
					chmin(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
				}
			}
		}
	}

	ll ans = INF;
	for (int i = 1; ma*i<410&&mb*i<410; i ++) {
		chmin(ans, dp[n][ma * i][mb * i]);
	}

	if (ans == INF) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 56064
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,x;
  cin>>a>>b>>x;
    if(a%x==0){
      cout<<(b/x)-(a/x)+1<<endl;
    }
    else{
      cout<<(b/x)-(a/x)<<endl;
    }
  return 0;
}


Measured memory_bytes: 256
function Main(input) {
	var inputArr = input.split("\n");
	var max = 0;
    var sum = 0;
	for(var i = 1; i <= inputArr[0]; i++) {
      var p = parseInt(inputArr[i], 10);;
      if (p > max) {
        max = p;
      }
      sum = sum + p;
	}
    sum = sum - max / 2;
    console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	fmt.Println(resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) int {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	h, w := scanInt(sc), scanInt(sc)
	if h == 1 || w == 1 {
		return 1
	}
	blockNum := (h+1)/2 + h/2
	return blockNum*(w/2) + (h+1)/2*(w%2)
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

#define MAX 100000

int parent(int i){
  return i / 2;
}

int left(int i){
  return 2 * i;
}

int right(int i){
  return 2 * i + 1;
}

int main(void){
  int n, i, A[MAX + 1];

  scanf("%d", &n);

  for(i = 1; i <= n; i++){
    scanf("%d", &A[i]);
  }

  for(i = 1; i <= n; i++){
    printf("node %d: key = %d, ", i, A[i]);
    if(parent(i) >= 1)  printf("parent key = %d, ", A[parent(i)]);
    if(left(i) <= n)  printf("left key = %d, ", A[left(i)]);
    if(right(i) <= n)  printf("right key = %d, ", A[right(i)]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2044
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int a[] = new int[m + 2];
        for (int i = 1; i <= m; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        a[0] = -1;
        a[m + 1] = n + 1;
        List<Integer> b = new ArrayList<>();
        for (int i = 1; i <= m + 1; i++) {
            if (a[i] - a[i - 1] == 1) {
                System.out.println(0);
                return;
            }
            b.add(a[i] - a[i - 1] - 1);
        }
        long memo[] = new long[n + 2];
        memo[1] = 1;
        memo[2] = 1;
        for (int i = 3; i <= n + 1; i++) {
            memo[i] = memo[i - 1] + memo[i - 2];
            memo[i] %= 1_000_000_007;
        }
        long ans = 1;
        for (int i = 0; i < b.size(); i++) {
            ans *= memo[b.get(i)];
            ans %= 1_000_000_007;
        }
        System.out.print(ans);
    }
}

Measured memory_bytes: 45652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
const ll mod = 1e9+7;
#define INFL 0x3f3f3f3f3f3f3f3fLL
 
//-------------------------<MATH>-------------------------------------------------------//
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;
ll c = (a * b)%mod;
//cout << a << " " << b << endl;
return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(5e5 + 5)] , inv_fac[(int)(5e5 + 5)];
void precomp_factorial(int M){fac[0] = 1;for(int i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(int i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int lo[(int)(1e3 + 6)];
void sieve(int M){for(int i = 2 ; i < M ; i++){ if(lo[i]) continue; for(int j = i ; j < M ; j += i)lo[j] = i;}}
int max_expo_prime_n_fac(ll N , int prime){int ress = 0;while(N){ress += (N/prime);N /= prime;}return ress;}
//-------------------------</MATH>-------------------------------------------------------//
 
//-------------------------<STRING>-------------------------------------------------------//
string get_prefix(string x , int MAX){return x.substr(0 , min((int)x.size() , MAX));}
string get_suffix(string x,int MAX){int dn=1;for(int i=x.size()-1;i>=0;i--){if(dn==MAX)return x.substr(i);dn++;}return x;}
string convert_to_binary(int x,int len) {string ans=""; while(x){if(x&1){ans='1'+ans;}
    else{ans ='0'+ans;}x/=2;}int k = ans.size();while(k < len){ans = '0' + ans;k++;}return ans;}
//-------------------------</STRING>-------------------------------------------------------//
 
ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
 
const int SZ = 2345678;

int pre[SZ];

 int main(){
     int n;
     cin >> n;
     string s;
     cin >> s;
     int cnt_r = 0, cnt_w = 0;
     for(int i = 1; i <= n; i++){
          pre[i] = pre[i-1];
         if(s[i-1] == 'R'){
             cnt_r++;
             pre[i]++;
         }
         else cnt_w++;
     }
     int ans = min(cnt_r, cnt_w);
     for(int i = 1; i <= n; i++){
         int lef_r = pre[i], lef_w = i-pre[i];
         int rt_r = cnt_r - lef_r;
         int ans1 = max(lef_w, rt_r);
         ans = min(ans, ans1);
     }
     cout << ans;
 }


Measured memory_bytes: 4524
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i, n){
        if(s.substr(i, n-i) == t.substr(0, n-i)){
            cout << i + n << endl;
            return 0;
        }
    }
    cout << 2 * n << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

constexpr int MAX = 1e5 + 100;
int a[MAX], b[MAX];
int x[MAX], y[MAX], c[MAX];


int main() {
  int A, B, M;
  scanf("%d%d%d", &A, &B, &M);
  for (int i = 0; i < A; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < B; i++)
    scanf("%d", &b[i]);
  for (int i = 0; i < M; i++)
    scanf("%d%d%d", &x[i], &y[i], &c[i]);
  int ans = MAX * 10;
  for (int i = 0; i < M; i++)
    ans = min(ans, a[x[i] - 1] + b[y[i] - 1] - c[i]);
  sort(a, a + A);
  sort(b, b + B);
  ans = min(ans, a[0] + b[0]);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2176
/*  CREATED BY
    STREAM_CIPHER
    7-aug-2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define debug1(a) cout<<#a<<"="<<(a)<<"\n"
#define debug2(a,b) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<"\n"
#define debug3(a,b,c) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<","<<#c<<"="<<(c)<<"\n"
#define fix_precision(n) cout << fixed << setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int mx=5*1000000;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
        int n,w;cin>>n>>w;
        vector<pair<int,int>>a(n+1);
        int sum=0;
        for(int i=0;i<n;i++)
            cin>>a[i].first>>a[i].second,sum+=a[i].second;
        int dp[n+9][sum+9];
        memset(dp,inf,sizeof dp);
        dp[0][a[0].second]=a[0].first;
        for(int i=1;i<n;i++)
        {
            for(int j=1;j<=sum;j++)
            {
                if(j+a[i].second<=sum&&dp[i-1][j]!=inf)
                    dp[i][j+a[i].second]=min(dp[i-1][j+a[i].second],min(dp[i-1][j]+a[i].first,dp[i][j+a[i].second]));
                dp[i][j]=min(dp[i-1][j],dp[i][j]);
            }
            dp[i][a[i].second]=min(dp[i-1][a[i].second],min(dp[i][a[i].second],a[i].first));
        }
        int ans=0;
        for(int i=0;i<n;i++)
            for(int j=1;j<=sum;j++)
                if(dp[i][j]<=w)
                    ans=max(ans,j);
        cout<<ans<<endl;
}

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

int main() {
  int N,X;
  int counter=1;
  int D=0;
  cin >> N>>X;
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin>>L.at(i);
  }
  for(int i=0;i<N;i++){
    D += L.at(i);
    if(D<=X){
      counter++;
    }
  }
  cout<< counter<<endl;
  return 0;
}




Measured memory_bytes: 256