akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::ops::*;

fn digitsum(x: i64) -> i64 {
    let mut res = 0;
    let mut x = x;
    while x != 0 {
        res += x % 10;
        x /= 10;
    }
    res
}

fn main() {
    let n = read_i64();
    let mut res = 1 << 50;
    for i in 1..n {
        let t = digitsum(i) + digitsum(n-i);
        res = min(res, t);
    }
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 4352
import bisect
s = list(input())
t = list(input())

ds = {}  # ｓに含まれる文字それぞれの数
dsl = {}  # ｓの文字の位置
for i in range(len(s)):
    if s[i] not in ds.keys():
        ds[s[i]] = 0
        dsl[s[i]] = []
    ds[s[i]] += 1
    dsl[s[i]].append(i)

for i in range(len(t)):
    if t[i] not in ds.keys():
        ds[t[i]] = 0

#print(ds, dsl)

ans = 0
now = -1#ここが-1じゃないと、最初の遷移でsの最初の文字を使えない
for i in range(len(t)):
    if ds[t[i]] == 0:  # ｓにｔを構成する文字がない場合
        print("-1")
        exit()
    elif ds[t[i]] == 1:
        if dsl[t[i]][0] > now:  # ｔの次の文字が現在地より右にある場合
            ans += (dsl[t[i]][0] - now)
        else:  # ｔの次の文字が現在地より左にある場合
            ans += dsl[t[i]][0] + (len(s) - now)
        now = dsl[t[i]][0]
    else:
        index = bisect.bisect_right(dsl[t[i]], now)
        if index == len(dsl[t[i]]):
            index = -1
        if dsl[t[i]][index] > now:  # ｔの次の文字が現在地より右にある場合
            ans += (dsl[t[i]][index] - now)
            now = dsl[t[i]][index]
        else:  # ｔの次の文字が現在地より左にある場合
            ans += dsl[t[i]][0] + (len(s) - now)
            now = dsl[t[i]][0]

print(ans)


Measured memory_bytes: 8996
#include <iostream>
using namespace std;

int main() {
	int i,n,a,b,now;
	int ans = 0;
	cin >> n >> a >> b;
	
	for (i = 0; i < n; i++){
		cin >> now;
		if (now>b - 1 || now<a){
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int x, a, b;
	scanf("%d %d %d", &x, &a, &b);
	int sum1 = x-a;
	int sum2 = x-b;
	if(sum1 < 0){
		sum1*= -1; 
	}if(sum2 < 0){
		sum2*= -1;
	}
	
	(sum1<sum2) ? printf("A") : printf("B");
	return 0;
}

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

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }

#define fi first
#define se second

typedef long long ll;
typedef double ff;
typedef std::pair<int, int> pii;

const int kN = 1e6 + 5;

int c[kN], n; bool bg[kN];

int main() {
	rd(n);
	for(int i = 1; i <= n; ++i) {
		int x; rd(x);
		c[x] = i; bg[x] = true;
	}
	for(int i = 1, ptr = 1; i <= n * n; ++i) {
		if(c[i] && bg[i]) {
			int j;
			for(j = 1; ptr < i && j < c[i]; ++j, ++ptr) {
				while(c[ptr]) ++ptr;
				c[ptr] = c[i];
			}
			if(j < c[i]) {
				printf("No\n");
				return 0;
			}
		}
	}
	for(int i = n * n, ptr = n * n; i; --i) {
		if(c[i] && bg[i]) {
			int j;
			for(j = 1; ptr > i && j <= n - c[i]; ++j, --ptr) {
				while(c[ptr]) --ptr;
				c[ptr] = c[i];
			}
			if(j <= n - c[i]) {
				printf("No\n");
				return 0;
			}
		}
		//for(int i = 1; i <= n * n; ++i) printf("%d ", c[i]);
		//	printf("\n");
	}
	printf("Yes\n");
	for(int i = 1; i <= n * n; ++i) printf("%d ", c[i]);
	printf("\n");
	return 0;
}

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

using namespace std;

int main(){
    int h, n;
    cin >>h>>n;
    vector<int> dam(n), mp(n), dp(h+1, (int)1e9);

    for(int i=0;i<n;i++){
        cin >>dam[i]>>mp[i];
    }

    dp[0] = 0;
    for(int i=1;i<=h;i++){
        for(int j=0;j<n;j++){
            dp[i] = min(dp[i], dp[max(0, i - dam[j])] + mp[j]);
        }
    }

    cout << dp[h];
}


Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n,m;cin >> n >> m;
    vi rui(n+1),RUI(m+1);
    rui[0]=RUI[0]=0;
    int k;
    rep(i, n) {
        int a;cin >> a;
        if(i==0)k=a;
        rui[i+1]=a+rui[i]-k;
        rui[i+1]%=mod;
    }
    rep(i, m) {
        int a;cin >> a;
        if(i==0)k=a;
        RUI[i+1]=a+RUI[i]+k;
        RUI[i+1]%=mod;
    }
    int s=0,t=0;
    rep1(i, n-1) {
        // s+=rui[n]-(rui[i]-rui[i-1])*(n-i-1);
        s+=(rui[n]-rui[i])-(rui[i]-rui[i-1])*(n-i);
        s%=mod;
    }
    rep1(i, m-1) {
        t+=(RUI[m]-RUI[i])-(RUI[i]-RUI[i-1])*(m-i);
        t%=mod;
    }
    cout << s*t%mod << endl;
    return 0;
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a[4];
    a[0] = 1,a[1] = 2,a[2] = 6,a[3] = 5;
    int b[4];
    b[0] = 1,b[1] = 3,b[2] = 6,b[3] = 4;
    int x[6];
    for(int i = 0;i < 6;i++)cin >> x[i];
    string op;
    cin >> op;
    int f;
    for(int i = 0;i < op.size();i++){
        if(op[i] == 'N'){
            f = a[0],a[0] = a[1],a[1] = a[2],a[2] = a[3],a[3] = f,b[0] = a[0],b[2] = a[2];
        }
        if(op[i] == 'S'){
            for(int k = 0;k < 3;k++){
                f = a[0],a[0] = a[1],a[1] = a[2],a[2] = a[3],a[3] = f,b[0] = a[0],b[2] = a[2]; 
            }
        }
        if(op[i] == 'E'){
            for(int k = 0;k < 3;k++){
                f = b[0],b[0] = b[1],b[1] = b[2],b[2] = b[3],b[3] = f,a[0] = b[0],a[2] = b[2];
            }
        }
        if(op[i] == 'W'){
            f = b[0],b[0] = b[1],b[1] = b[2],b[2] = b[3],b[3] = f,a[0] = b[0],a[2] = b[2];
        }
        
    }
    int r;
    r = a[0];
    cout << x[r - 1] << endl;
}


Measured memory_bytes: 3212
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int d;
	scanf("%d", &d);
	rep(i, d){
		int n;
		scanf("%d", &n);
		
		char field[128][128];
		rep(j, n){
			fill(field[j], field[j]+n, ' ');
			field[j][n] = '\0';
		}
		
		const int dy[] = {-1, 0, 1, 0};
		const int dx[] = {0, 1, 0, -1};
		int y=n-1, x=0;
		field[y][x] = '#';
		int dir = 0;
		int okok = 0;
		for(;;){
			int py = y + dy[dir];
			int px = x + dx[dir];
			
			bool ok = true;
			if(py<0 || n<=py || px<0 || n<=px)
				ok = false;
			
			rep(j, 4){
				int ny = py + dy[j];
				int nx = px + dx[j];
				if(ny<0 || n<=ny || nx<0 || n<=nx || (y==ny && x==nx))
					continue;
				
				if(field[ny][nx] == '#'){
					ok = false;
					j=3;
					break;
				}
			}
			
			if(!ok){
				dir = (dir+1) % 4;
				++okok;
				if(okok == 4)
					break;
				continue;
			}
			else
				okok = 0;
			
			y = py;
			x = px;
			field[y][x] = '#';
		}
		
		if(i) puts("");
		rep(j, n)
			puts(field[j]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define vec(x) vector<x>
ll gcd(ll a,ll b){while(b){ll tmp = a % b;a = b;b = tmp;}return a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
#define rep(x, y) for(int x = 0; x < (y); x++)
#define rrep(x, y) for(int x = (y); x >= 0; x--)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define out(x) for(auto i : x) cout << i << " "; cout << endl;
#define outln(x) for(auto i : x) cout << i << " " << endl;
#define vec_cpy(to,from) copy(all(to),back_inserter(from))
#define ary_cpy(to,from) memcpy(to, from, sizeof from)
#define MOD = 1000000007; 
#ifdef DEBUG
#define debug_echo(e) cout << "L" << __LINE__ << ": " << e << endl
#define debug_var(e) cout << "L" << __LINE__ << ": " << #e << " = " << e << endl
#define debug_echo_dp(dp, N) { cout << "[ "; rep(i, N) cout << dp[i] << " ";  cout << "]" << endl; }
#else
#define debug_echo(e)
#define debug_var(e)
#define debug_echo_dp(dp, N)
#endif

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

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int n, m;
  cin >> n >> m;
  vector<int> x(n+1,0), y(n+1,0);
  vector<int> a(m), b(m);
  REP(i, m) cin >> a[i] >> b[i];
  REP(i, m) {
    if (a[i]==1) {
      x[b[i]] = 1;
    }
    if (b[i]==n) {
      y[a[i]] = 1;
    }
  }

  string ans = "IMPOSSIBLE";
  REP(i, n) {
    if (x[i]==1&&y[i]==1) {
      ans = "POSSIBLE";
      break;
    }
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int a,b;
    vector<vector<int> > v(n);
    for(int i=0;i<m;i++){
    	cin >> a >> b;
    	a--;b--;
    	v[a].pb(b);
    	v[b].pb(a);
    }
    int used[n];
    memset(used, -1 ,sizeof(used));
    used[0] = -2;
    queue<int> q;
    q.push(0);
    while(!q.empty()){
    	int now = q.front();
    	q.pop();
    	for(auto& to: v[now]){
    		if(used[to] == -1){
    			used[to] = now;
    			q.push(to);
    		}
    	}
    }
    cout << "Yes" << endl;
    for(int i=1;i<n;i++){
    	cout << used[i] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 10136
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int dp[n];
int arr[n];
for(int i=0; i<n; ++i)
cin>>arr[i];
dp[0]=0;
dp[1]=abs(arr[1]-arr[0]);
for(int i=2; i<n; ++i)
{
dp[i]=min(dp[i-2]+abs(arr[i-2]-arr[i]),dp[i-1]+abs(arr[i]-arr[i-1]));
//dp[i]=min(dp[i],arr[i]);
}
cout<<dp[n-1];
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
R, S, P = map(int, input().split())
t = input()
point = {'r':P, 's':R, 'p':S}

ans = 0
for i in range(k):
    j = i
    m = 0
    pre_t = 'na'
    counted = False
    while j < n:
        if not (t[j] == pre_t and counted):
            ans += point[t[j]]
            counted = True
        else:
            counted = False
        pre_t = t[j]
        m += 1
        j = i + m * k
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define RSort(a) reverse(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
int max_int = 1000000007;
void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

signed main(){
    int n,m;
    cin >> n >> m;
    vec(a,m+1);
    REP(i,n){
        int k;
      cin >> k;
        REP(j,k){
            int t;
            cin >> t;
            a[t]++;
        }
    }
    Sort(a);
    RSort(a);
    int ans = 0;
    REP(i,m+1){
        if(a[i] == n){
            ans++;
        }
        else{
            break;
        }
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int main(){
	string s1, s2;

	while(cin >> s1 >> s2){
		int H=0, B=0;
		if(s1 == "0" && s2 == "0") break;
		for(int i=0; i<4; ++i){
			if(s1[i] == s2[i]) H++;
			for(int j=0; j<4; ++j){
				if(s1[i] == s2[j] && i != j) B++;
			}
		}

		cout << H << " " << B << endl;
	}

    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int ans=0,ans2=0;
    string s2=s;
    for(int i=1; i<s.length(); i++){
        if(s[i]==s[i-1]){
            if(s[i]=='1') s[i]='0';
            else s[i]='1';
            ans++;
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 512
use std::cmp::max;
use std::collections::HashMap;
const MOD: usize = 1000000007;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    // var... 変数の識別子, $t...型を一つよむ
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        //ここで繰り返し
        input_inner!{$iter $($r)*}
    };
}

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

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

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    // 配列の最後のNestではここで型が指定されてparseされる
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
        t: String,
    }
    let s: Vec<char> = s.chars().collect();
    let t: Vec<char> = t.chars().collect();
    let n: usize = s.len();
    let m: usize = t.len();
    let mut memo: Vec<Vec<usize>> = vec![vec![0; m + 1]; n + 1];

    for i in 0..n {
        for j in 0..m {
            memo[i + 1][j + 1] = if s[i] == t[j] {
                max(max(memo[i][j] + 1, memo[i][j + 1]), memo[i + 1][j])
            } else {
                max(max(memo[i][j], memo[i][j + 1]), memo[i + 1][j])
            }
        }
    }
    let mut x = n;
    let mut y = m;
    let mut res: Vec<char> = vec![];
    while x > 0 && y > 0 {
        if memo[x][y] == memo[x - 1][y] {
            x -= 1;
        } else if memo[x][y] == memo[x][y - 1] {
            y -= 1;
        } else {
            x -= 1;
            y -= 1;
            res.push(s[x]);
        }
    }
    let mut ans = String::new();
    for c in res.iter().rev() {
        ans.push(*c);
    }
    println!("{}", ans);
}


Measured memory_bytes: 90364
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

struct P {
    int x,y,id;
};

struct edge {
    int u,v,w;

    bool operator<( const edge& t ) const {
        if  ( w==t.w ) {
            if ( u==t.u ) {
                return v<t.v;
            }
            return u<t.u;
        }
        return w<t.w;
    }
    bool operator==( const edge& t ) const {
        return u==t.u&&v==t.v&&w==t.w;
    }
};

vector<P> ps;
bool cmp1( int i, int j ) {
    auto a=ps[i],b=ps[j];
    if ( a.x==b.x ) return a.y<b.y;
    return a.x<b.x;
}

bool cmp2( int i, int j ) {
    auto a=ps[i],b=ps[j];
    if ( a.y==b.y ) return a.x<b.x;
    return a.y<b.y;
}

vector<int> par;
int find( int a ) {
    return a==par[a] ? a : (par[a]=find(par[a]));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    ps.resize(n);
    REP(i,n) {
        cin >> ps[i].x >> ps[i].y;
        ps[i].id=i;
    }
    vector<int> xs(n),ys(n);
    iota(ALL(xs),0);
    iota(ALL(ys),0);

    // sort points with x-coordinate
    sort(ALL(xs),cmp1);
    // sort points with y-coordinate
    sort(ALL(ys),cmp2);

    vector<edge> es;
    REP(i,n-1) {
        auto &a=ps[xs[i]];
        auto &b=ps[xs[i+1]];
        es.push_back({min(a.id,b.id),max(a.id,b.id),abs(a.x-b.x)});
    }
    REP(i,n-1) {
        auto &a=ps[ys[i]];
        auto &b=ps[ys[i+1]];
        es.push_back({min(a.id,b.id),max(a.id,b.id),abs(a.y-b.y)});
    }
    // sort_uniq(es);
    sort(ALL(es));

    par.resize(n);
    iota(ALL(par),0);

    LL ans=0;
    // kruskal
    REP(i,es.size()) {
        int u=es[i].u,v=es[i].v,w=es[i].w;
        if ( find(u)!=find(v) ) {
            ans+=w;
            par[find(v)]=find(u);
        }
    }
    cout << ans << '\n';
    return 0;
}





Measured memory_bytes: 8348
N = int(input())
a = list(map(int, input().split()))

def sum(a):
    max_value = max(a)
    ind = a.index(max_value)
    a[ind] = 0
    return a,max_value

Asum = 0
Bsum = 0
max_value = 100
while max_value > 0:
    a,max_value = sum(a)
    Asum += max_value
    a,max_value = sum(a)
    Bsum += max_value

print(Asum - Bsum)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1; char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int inf=1e9;
const int maxn=2e5+20;

struct Edge {
	int u,v,w;
};
Edge E[maxn];

int d[maxn],n,m,vis[maxn],col[maxn];
vector<int>ed[maxn];
queue<int>q;

inline void init()
{
	n=read();m=read();
	REP(i,1,n)d[i]=read();
	REP(i,1,m)
	{
		int u=read(),v=read();
		E[i]=(Edge){u,v,inf};
		if(d[u]==d[v] && !vis[u] && !vis[v])
			q.push(u),q.push(v),E[i].w=d[u],vis[u]=1,vis[v]=1,col[u]=1,col[v]=0;
		ed[u].push_back(i);
		ed[v].push_back(i);
	}
}

inline void doing()
{
	while(!q.empty())
	{
		int u=q.front();q.pop();
		for(int i:ed[u])
		{
			int v=E[i].u^E[i].v^u;
			if(d[v]>=d[u] && !vis[v])
				vis[v]=1,q.push(v),E[i].w=d[v],col[v]=col[u]^1;
		}
	}
	int s=0;
	REP(i,1,n)s+=vis[i];
	if(s==n)
	{
		REP(i,1,n)printf("%c",col[i]?'B':'W'); puts("");
		REP(i,1,m)printf("%d\n",E[i].w);
	}else puts("-1");
}

int main()
{
	init();
	doing();
	return 0;
}


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

const int M = 1000005;

int main() {
  string ans = "hon";
  int n;
  cin >> n;
  n = n%10;
  if(n == 3) ans="bon";
  else if(n == 0 || n ==1 || n == 6 || n == 8) ans = "pon";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

#define INF (1<<31-1)
#define ll long long



int main(){

	ll A, B;

	cin >> A >> B;

	if (A*B%2==0)	cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}


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

string s, ans;

int main(){
	cin >> s;
	int n = s.size();
	for(int i = 0;i < n;i += 2){
		ans += s[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
// Author : Epsilon573
// If it works, don't touch it.

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ll mod  = 1e9+7;
const ld eps  = 1e-9 ;
const ll maxn = 1e5+1;
const ll inf  = LLONG_MAX;
const ll minf = LLONG_MIN;

#define mp make_pair
#define pb push_back
#define endl "\n"
#define deb(x) cerr << #x << " " << x << endl

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll a,b;
    cin >> a >> b;

    cout << a*b ;

    return 0;
} 

Measured memory_bytes: 3612
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W, n = map(int, input().split())
    AB = set(tuple(tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(n)))

    d = ((1, 1), (1, 0), (1, -1), (0, 1), (0, 0), (0, -1), (-1, 1), (-1, 0), (-1, -1))
    target = set()
    res = [0] * 10
    for h, w in AB:
        cnt = 0
        flg = True
        for dh, dw in d:
            next_h, next_w = h + dh, w + dw
            if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                flg = False
            if (next_h, next_w) in AB:
                cnt += 1
            else:
                target.add((next_h, next_w))
        if flg:
            res[cnt] += 1

    for h, w in target:
        cnt = 0
        for dh, dw in d:
            next_h, next_w = h + dh, w + dw
            if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                break
            if (next_h, next_w) in AB:
                cnt += 1
        else:
            res[cnt] += 1

    total = (H - 2) * (W - 2)
    res[0] = total - sum(res)
    print(*res, sep="\n")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 162784
a,b,c=map(int,input().split())
cnt=0

if a==b==c and a%2==0:
  print(-1)
   
else:
  while a%2==0 and b%2==0 and c%2==0:
    a,b,c=(b+c)//2,(a+c)//2,(a+b)//2
    cnt+=1
  print(cnt)





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

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int main()
{
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];

    vector<vector<int>> dp(n + 1, vector<int>(k + 1)); //dp[i][j] := i人目までみた時に飴をj個使う場合の数
    dp[0][0] = 1;

    for(int i = 0; i < n; i++) {
        vector<ll> sum(k + 1); //sum[i] := i個目までの累積和
        sum[0] = dp[i][0];
        for(int j = 1; j <= k; j++) {
            sum[j] = sum[j - 1] + dp[i][j];
            sum[j] %= mod;
        }

        for(int j = 0; j <= k; j++) {
            dp[i + 1][j] += sum[j] - (j - a[i] - 1 < 0 ? 0 : sum[j - a[i] - 1]);
            dp[i + 1][j] %= mod;
        }

    }
    cout << ((dp[n][k] % mod) + mod) % mod << endl;
}

Measured memory_bytes: 43436
S = input()
T = ''
idx = 0

while(len(T) < len(S)):
    
    try:
        if(S[idx: idx + 7] == 'dreamer' and S[idx + 5: idx + 10] != 'erase'):
            T += 'dreamer'
            idx += 7

        elif(S[idx: idx + 5] == 'dream'):
            T += 'dream'
            idx += 5

        elif(S[idx: idx + 6] == 'eraser'):
            T += 'eraser'
            idx += 6

        elif(S[idx: idx + 5] == 'erase'):
            T += 'erase'
            idx += 5

        else:
            break
    
    except IndexError:
        pass

if(S == T):
    print('YES')

else:
    print('NO')

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;


int main() {
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	rep(i, h) cin >> a[i];
	int cnt = 0;
	rep(i, h) {
		rep(j, w) {
			if (a[i][j] == '#') cnt++;
		}
	}
	string ans = (h + w - 1 == cnt) ? "Possible" : "Impossible";
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	/* several useful subroutines */
	private static final BigDecimal BD1000000007 = new BigDecimal(1000000007);
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	private static BigDecimal mod1000000007(BigDecimal bd) {
		return bd.subtract(BD1000000007.multiply(bd.divide(BD1000000007, BigDecimal.ROUND_DOWN))) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(int i) {
		return mod1000000007(new BigDecimal(i)) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(long l) {
		return mod1000000007(new BigDecimal(l)) ;
	}

	
	/* main routine */
	public static void main(String args[]) throws IOException {
		char s[] = getString().toCharArray();
		int r,l;
		int c = 1;
		while ( c < s.length ) {
			for ( r = 1 ; s[c++] == 'R' ; r++ );
			for ( l = 1 ; c < s.length && s[c++] == 'L'  ; l++ );
			for ( int i = 1 ; i < r ; i++ ) {
				System.out.printf( "0 " );
			}
			if ( (r+l) % 2 == 1 ) {
				if ( r % 2 == 1 ) {
					System.out.printf( "%d %d ", (r+l)/2+1, (r+l)/2 );
				} else {
					System.out.printf( "%d %d ", (r+l)/2, (r+l)/2+1 );
				}
			} else {
				System.out.printf( "%d %d ", (r+l)/2, (r+l)/2 );
			}
			for ( int i = 1 ; i < l ; i++ ) {
				System.out.printf( "0 " );
			}
		}
		System.out.println();
	}
}


Measured memory_bytes: 63000
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  [n, a, b] <- readIntegerList
  coords <- readIntegerList
  print $ calc a b coords

calc !a !b (x:y:rest) = min (a * (y - x)) b + calc a b (y:rest)
calc !a !b _ = 0


Measured memory_bytes: 8444
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

inline int opposite(int p) {
	return (p + 1) % 2;
}

int n;
ll a[3001];
ll dp[3001][3001];
int is_used[3001][3001];

ll solve(int l, int r) {
	if(is_used[l][r]) {
		return dp[l][r];
	}

	if(l + r == n) {
		return 0;
	}

	is_used[l][r] = true;

	int x1, x2;
	ll xy;
	if((l + r) % 2 == 0) {
		/* Taro */
		xy = max(solve(l + 1, r) + a[l], solve(l, r + 1) + a[n - (r + 1)]);
	} else {
		/* Jiro */
		xy = min(solve(l + 1, r) - a[l], solve(l, r + 1) - a[n - (r + 1)]);
	}

	return dp[l][r] = xy;
}

int main() {
	cin >> n;
	REP(i, n) { cin >> a[i]; }
	solve(0, 0);
	int result;
	cout << solve(0, 0) << endl;
	return 0;
}


Measured memory_bytes: 77420
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;

int const N = 1e5+5;
int res,n,m;
vector<int> v[N];
bool tr[N];

void bfs(int r){
	tr[r] = true;
	for(int i=0;i<v[r].size();i++){
		int j = v[r][i];
		if(!tr[j]) bfs(j);
	}
	
	return;
}

int main() {
	
	int a,b,c,i;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>a>>b>>c;
		v[a].push_back(b);
		v[b].push_back(a);
		
	}
	
	for(i=1;i<=n;i++){
		if(!tr[i]) { bfs(i); res++; }
	}
	
	cout<<res;
 	return 0;
}

Measured memory_bytes: 8960
#include <iostream>
using namespace std;

int main()
{
	int N, M;

	cin >> N >> M;

	for (int i = M / N;i>0; i--) {
		if (M%i == 0) {
			cout << i << endl;
			return 0;
		}
	}
	
	return 0;
}

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

int count(int);
int main(void)
{
	int c=0, i, n, N;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &N);
		c+=count(N);
	    
	}
	printf("%d\n", n-c);
	return 0;
}

int count(int N)
{
	int j;
	if(N>100){
			for(j=3; j<=sqrt(N); j+=2){	
				if(N%j==0){ return 1; } 
				else if(N%2==0){ return 1;}}
	    
	            }
	else{ for(j=2; j<N; j++){ if(N%j==0){ return 1; } } }
	return 0;
}


Measured memory_bytes: 2072
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
int main(){
  int n , total;
  cin >> n >> total;
  int w[n];
  int v[n];
  vector<vector<ll>> dp(n+1,vector<ll>(total+1,0));
  for(int i=0;i<n;i++) cin >> w[i] >> v[i];
  for(int row=1;row<=n;row++){
    for(int col=1;col<=total;col++){
      if(col>=w[row-1]){
        dp[row][col] = dp[row-1][col-w[row-1]] + v[row-1];
      }
       dp[row][col] = max(dp[row][col],dp[row-1][col]);
    }
  }
  ll ans = 0;
  for(int col=0;col<=total;col++){
    ans = max(ans,dp[n][col]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 83160
/*
    Author - Param Kothari
    Ah shit, here we go again
*/
 
/* Ordered Set Implementaton:

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

typedef tree<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    ll n, k;
    cin >> n >> k;
    if(n == k){
        cout << 0 << "\n";
    }
    else{
        n = n % k;
        ll res = min(n, abs(n - k));
        cout << res << "\n";
    }
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    for(int i = 1; i <= t; i++){
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


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

int main(){
    int a, b; cin >> a >> b;
    for(int i = 0; i <= 1010; i++) {
        if(a==floor(i*0.08) && b==floor(i*0.1)){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

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

int t1[500000];
bool t1c[500000];
int t1d = 0;

//k番目以内に入るように、順次要素を並べていくクラス
class SegLine
{
    public:
        // o(n)
        SegLine(int n)
        {
            m_n = n;
            m_pos = new int[n];
            for( int i = 0; i < n; i++ ) m_pos[i] = i;
        }

        ~SegLine()
        {
            delete m_pos;
        }

        // k番目以内に入るように入れる。（先の人優先）
        bool add(int k)
        {
            if( m_pos[k] == k )
            {
                if( k == 0 )
                {
                    m_pos[k] = -1;    
                }
                else
                {
                    m_pos[k] = m_pos[k - 1];
                }
                return true;
            }
            if( m_pos[k] < 0 ) return false;
            bool ret = add(m_pos[k]);
            m_pos[k] = m_pos[m_pos[k]];
            return ret;
        }

    private:
        int m_n;
        int* m_pos;
};

_LL sub()
{
    int n;
    cin >> n;
    SegLine lline(n);
    SegLine rline(n);
    int *l = new int[n];
    int *r = new int[n];
    int *k = new int[n];
    vector<pair<int, int>> lh;
    vector<pair<int, int>> rh;

    _LL ans = 0;

    for( int i = 0; i < n; i++ )
    {
        cin >> k[i] >> l[i] >> r[i];
        k[i]--;
        if( k[i] == n - 1 )
        {
            ans += l[i];
        }
        else if( l[i] > r[i] ) 
        {
            lh.push_back( make_pair(r[i] - l[i], i) );
        }
        else if( l[i] < r[i] ) 
        {
            rh.push_back( make_pair(l[i] - r[i], i) );
        }
        else
        {
            ans += l[i];
        }
    }

    sort( lh.begin(), lh.end() );
    sort( rh.begin(), rh.end() );

    for( auto itr = lh.begin(); itr != lh.end(); itr++ )
    {
        int i = (*itr).second;
        if( lline.add(k[i]) )
        {
            ans += l[i];
        }
        else
        {
            ans += r[i];
        }
    }

    for( auto itr = rh.begin(); itr != rh.end(); itr++ )
    {
        int i = (*itr).second;
        if( rline.add(n - 2 - k[i]) )
        {
            ans += r[i];
        }
        else
        {
            ans += l[i];
        }
    }
    return ans;
}

int main()
{
    int t;
    cin >> t;
    for( int i = 0; i < t; i++)
    {
        cout << sub() << endl;
    }
}

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

using namespace std;

const int MaxN = 503;

long long a[MaxN][MaxN];

vector <int> p1;
vector <int> p2;

long long lcm(long long a, long long b)
{
    return a / __gcd(a, b) * b;
}

bool isPrime(int x)
{
    if(x == 1)
        return false;
    for(int i = 2; i * i <= x; ++i)
        if(x % i == 0)
            return false;
    return true;
}

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

void build(int x, int y)
{
    for(int i = 0; i < 4; ++i)
    {
        int xx = x + dx[i];
        int yy = y + dy[i];

        if(xx >= 0 && xx < MaxN && yy >= 0 && yy < MaxN)
            a[x][y] = lcm(a[x][y], a[xx][yy]);
    }

    ++a[x][y];

    assert(a[x][y] <= 1e15 && a[x][y] > 0);
}

void check()
{
    for(int i = 0; i < MaxN; ++i)
        for(int j = 0; j < MaxN; ++j)
        {
            for(int d = 0; d < 4; ++d)
            {
                int x = i + dx[d];
                int y = j + dy[d];

                if(x >= 0 && x < MaxN && y >= 0 && y < MaxN)
                {
                    long long k1 = min(a[i][j], a[x][y]);
                    long long k2 = max(a[i][j], a[x][y]);

                    assert(k2 % k1 == 1);
                }
            }
        }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
    mt19937 rnd(clock());

    for(int i = 0; i < MaxN; ++i)
        for(int j = 0; j < MaxN; ++j)
            a[i][j] = 1;

    for(int i = 2; i <= 20000; ++i)
        if(isPrime(i))
        {
            if(p1.size() <= MaxN)
                p1.push_back(i);
            else
                p2.push_back(i);
        }

//    shuffle(p1.begin(), p1.end(), rnd);
//    shuffle(p2.begin(), p2.end(), rnd);

    for(int i = 0; i < MaxN; i += 2)
        for(int j = 0; j + i < MaxN; ++j)
            a[i + j][j] *= p1[i];

    for(int j = 2; j < MaxN; j += 2)
        for(int i = 0; i + j < MaxN; ++i)
            a[i][j + i] *= p1[j - 1];


    for(int i = 0; i < MaxN; i += 2)
        for(int j = 0; j < MaxN && i - j >= 0; ++j)
            a[i - j][j] *= p2[i];

    for(int j = 2; j < MaxN; j += 2)
        for(int i = 0; j + i < MaxN; ++i)
            a[MaxN - 1 - i][j + i] *= p2[j - 1];

    for(int i = 0; i < MaxN; ++i)
        for(int j = 0; j < MaxN; ++j)
            if((i + j) & 1)
                build(i, j);

    check();

    int n;
    cin >> n;

    assert(n <= MaxN);

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < n; ++j)
            cout << a[i][j] << ' ';
        cout << '\n';
    }

    return 0;
}



Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
map<int, int> mp;
int main()
{
	long long a, b, c;
	long long sum = 0;
	cin >> a >> b >> c;
	bool tmp = false;
	for (int i = 1; i <= 110; i++) {
		sum += a;
		if (sum % b == c) tmp = true;
	}
	if (tmp) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
N, B = map(int, input().split())
R = N-B
MOD = 10**9+7

# パスカルの三角形
C = [[0 for i in range(N + 1)] for j in range(N + 1)]
C[0][0] = 1
C[1][0] = 1
C[1][1] = 1
for i in range(2, N+1):
    C[i][0] = 1
    C[i][i] = 1
    for j in range(1, i):
        C[i][j] = C[i-1][j-1] + C[i-1][j]

for i in range(1, B+1):
    print((C[R+1][i] * C[B-1][i-1]) % MOD)

Measured memory_bytes: 357584
#include<iostream>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

int main()
{
	FAST_IO ;
	int i,j,k,n,x;
    cin >> n;
    if(n==2)
    {
        cout << "1\n" ;
        return 0;
    }
    j = 0;
    for(i=1;i<=n-1;++i)
    {
        x = n - i;
        for(k=1;k*k<=x;++k)
        {
            if(x%k!=0)
                continue ;
            if(k*k==x)
                j++ ;
            else
                j += 2;
        }
    }
    cout << j endl ;
	return 0;
}

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 3628
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
const ll mod = 1e9 + 7;
const ll inf = 1e9;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    int ans = 1;
    rep(i, 0, N-1) {
        if (S[i] != S[i+1]) {
            ans += 1;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int compare(const void *a,const void *b){
    return *(int*)a-*(int*)b;
}
/*
int comb(int n, int r){
  if(r==0 || r==n)return (1);
  else if(r==1)return(n);
  return(comb(n-1,r-1)+comb(n-1,r));
}
*/
int main(){
  int n;
  int a[100001];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  qsort(a,n,sizeof(a[0]),compare);
  double nmax=a[n-1];
  double med = nmax/2.000;
  int rmax=1111111111;
  double tempbest=1111111111;
  for(int i=0;i<n-1;i++){
    int temp=abs(med-a[i]);
    if(temp<tempbest){
      rmax=a[i];
      tempbest=temp;
    }
  }
//printf("%f",nmax);
  printf("%d %d\n",(int)nmax,rmax);
  return 0;
}

Measured memory_bytes: 892
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	ll a,b,c,k,ans;
	std::cin >> a >> b >> c >> k;
	ans = std::min(a,k);
	k -= std::min(a,k);
	k -= std::min(b,k);
	ans -= std::min(c,k);
	std::cout << ans << std::endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    int first = n / 100;
    int second = n % 100 / 10;
    int third = n % 10;
    if (first == 7 || second == 7 || third == 7)  cout << "Yes";
    else  cout << "No";
  
    return 0;
}


Measured memory_bytes: 3636