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

#[allow(unused_macros)]
macro_rules! tf {
    ($c:expr, $t:expr, $f:expr) => {{
        if $c { $t } else { $f }
    }};
}

fn main() {
    let n = read_i64() as usize;
    let xs = read_vec_i64();
    let mut even_sum = vec![0; n+1];
    for i in 0..n {
        even_sum[i+1] = even_sum[i] + tf!(i % 2 == 0, xs[i], 0);
    }
    let mut odd_sum = vec![0; n+1];
    for i in 0..n {
        odd_sum[i+1] = odd_sum[i] + tf!(i % 2 == 1, xs[i], 0);
    }
    if n % 2 == 0 {
        let even_s = even_sum[n] - even_sum[0];
        let odd_s  = odd_sum[n] - odd_sum[0];
        println!("{} {}", max(even_s, odd_s), min(even_s, odd_s));
    }
    else {
        let mut lower = 0;
        let mut upper = 1i64 << 30;
        while upper - lower != 1 {
            let x = (lower+upper)/2;
            let mut l = 0;
            let mut r = n;
            let mut offset = 0;
            while r - l != 1 {
                if xs[l] + offset >= x && xs[l+1] >= xs[l] + offset {
                    l += 2;
                    offset = 0;
                }
                else {
                    offset = xs[l] + offset - xs[l+1];
                    l += 2;
                }
            }
            let yes = xs[l] + offset >= x;
            if yes {
                lower = x;
            }
            else {
                upper = x;
            }
        }
        let black = lower + odd_sum[n];
        let white = even_sum[n] + odd_sum[n] - black;
        println!("{} {}", black, white);
    }
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    //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: 18160
#include <string>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <math.h>
 
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
    vector<int> vec(114514);
    for(int i=0; i<5; i++){
      cin >> vec.at(i);
    }
  for(int i=0; i<5; i++){
      if(vec.at(i)==0){
        cout << i+1;
        return 0;
    }
  
}
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define M 1000000007
typedef long long int ll;
const int N=1005;
int g[N][N];
ll dp[N][N];
ll solve(int x,int y){
	if(dp[x][y]!=-1) {
		return dp[x][y];
	}
	if(x==1&&y==1) {
		return 1;
	}
	if(!g[x][y]) {
		return 0;
	}
	ll ans1=0;
	ll ans2=0;
	if(x>1) ans1=solve(x-1,y);
	if(y>1) ans2=solve(x,y-1);
	return dp[x][y]=(ans1+ans2)%M;
}
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			char c; cin>>c;
			if(c=='.') {
				g[i][j]=1;
			}

		}
	}
	memset(dp,-1,sizeof dp);
	cout<<solve(n,m)<<endl;




	return 0;
}


Measured memory_bytes: 12160
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<deque>
#include<array>
#include<map>
#include<tuple>
#include<algorithm>


#define REP(i,a,b) for(int i = (a); i < b; ++i)
#define inf 1e9+10
#define MOD 1000000007

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

// Reference https://qiita.com/ofutonfuton/items/c17dfd33fc542c222396

struct UnionFind {
    vector<int> par, rank; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2、rank：ランク（木の高さ）

    UnionFind(int N) : par(N),rank(N) { //最初は全てが根であるとして初期化、ランクは1で初期化
        for (int i = 0; i < N; i++) par[i] = i, rank[i] = 1;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        if (rank[rx] < rank[ry]) { // xとyの根が同じでない(=同じ木にない)時
            par[rx] = ry; // xの根rxをランクの高いyの根ryにつける
        }
        else {
            par[ry] = rx;// yの根ryをランクの高い場合xの根rxにつける、同じならばrxのランクを高くする
            if (rank[rx] == rank[ry]) rank[rx]+=rank[ry];
        }
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        return root(x) == root(y);
    }
};

inline ll modpow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

inline ll mod(ll val, ll m) {
    ll res = val % m;
    if (res < 0) res += m;
    return res;
}

int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    UnionFind uf(n);

    REP(i, 0, m) {
        int a, b;
        cin >> a >> b;
        uf.unite(a - 1, b - 1);
    }
    int cnt = 0;
    REP(i, 0, n) {
        if (!uf.same(0, i)) {
            uf.unite(0, i);
            cnt++;
        }
    }

    cout << cnt;

    return 0;
}

Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
char a[100000+1];//0表是
int L,r,c[100001];
void prime(){
	a[0]=a[1] = 1;
	int t=sqrt(100000);					
	for(int i=2;i<=t;i++){
		if(a[i]==0) {
			for(int j=i*i;j<=100000;j+=i)
			     a[j] = 1;	
		}				
	}
	for (int i=1; i<=100000; i++)//构造前缀和
    {
        if(a[i]==0 && a[(i+1)/2]==0)//如果该数满足要求，前缀和加1；否则不变
        {
            c[i]=c[i-1]+1;
        }
        else c[i]=c[i-1];
    }
}
int main(){
	prime(); 						 
	int q;//输入q组数据 
	cin>>q;							
	for(int i=0;i<q;i++){
		cin>>L>>r;
	    cout<<c[r]-c[L-1]<<endl;
	}	
	return 0;
} 

Measured memory_bytes: 1152
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N;
	string S;
	cin>>N>>S;
	int counter=0;
	vec(B);
	fx(N){
		if(S.at(x)=='('){
			counter++;
		}else{
			counter--;
		}
		if(counter<0){
			pb(B,x)
              counter=0;
		}
	}

	string ans;
	fx(B.size()){
     ans+="("; 
    }
  ans+=S;
  	fx(counter){
     ans+=")"; 
    }
	ce(ans)
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define B 330
#define N 100010
ll res[N], s[N];
int main(){
	int n, m;
	cin>>n>>m;
	rep(i, n){
		int l, r;
		cin>>l>>r;
		int mn = INF;
		for(int j = 1; j < B; j++){
			int a = (l+j-1)/j, b = r/j;
			if(a<=b){
				res[j]++;
				b = min(b, mn-1);
				a = max(a, B);
				if(a<=b){
					s[a]++;
					s[b+1]--;
					mn = min(mn, a);
				}
			}
		}
	}
	rep(i, N-1) s[i+1] += s[i];
	rep(i, N) res[i] += s[i];
	rep(i, m) cout<<res[i+1]<<endl;
	return 0;
}


Measured memory_bytes: 2432
from functools import reduce
while True:
    n = input()
    if n == '0000': break
    if len(n) < 4:
        n = '0'*(4-len(n)) + n
    if reduce(lambda x,y: x and y, [n[0] == s for s in n]):
        print('NA')
    else:
        cnt = 0
        while n != '6174':
            l = ''.join(sorted(n, reverse=True))
            s = ''.join(sorted(n))
            n = str(int(l)-int(s))
            if len(n) < 4:
                n = '0'*(4-len(n)) + n
            cnt += 1
        print(cnt)

Measured memory_bytes: 6724
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,t,a;
    cin >> n >> t >> a;
    double h;
    int ans=0;
    double tmp=1e9+1.0;
    for(int i=0;i<n;i++){
        cin >> h;
        if(abs((double)1.0*tmp-1.0*a)>abs(1.0*a-1.0*t+h*0.006)){
            ans=i+1;
            tmp=1.0*t-h*0.006;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int A, B;
    cin >> A >> B;
    if(A == B) {
        cout << "Draw" << endl;
        return 0;
    }
    if(1 < A and A < B) {
        cout << "Bob" << endl;
        return 0;
    }
    if(B == 1) {
        cout << "Bob" << endl;
        return 0;
    }
    cout << "Alice" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
dance = input()
num = 0
odd = []
even = []
for i in dance:
    num += 1
    if num %2 == 0:
        even.append(i)
    else:
        odd.append(i)
for i in odd:
    if i == "L":
        print('No')
        sys.exit()
    else:
        pass
for i in even:
    if i == "R":
        print('No')
        sys.exit()
    else:
        pass
print('Yes')

Measured memory_bytes: 3064
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int n, x;
    cin >> n >> x;
    priority_queue<int, vector<int>, greater<int>> q;
    rep(i, n)
    {
        int tmp;
        cin >> tmp;
        q.push(tmp);
    }
    int ans = 0;
    while (q.size() && x > 0)
    {
        x -= q.top();
        ans++;
        q.pop();
    }
    if (x != 0)
    {
        ans--;
    }
    cout << ans << endl;
}

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

typedef long long ll;
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define rerepi(i, a, b) for(int i = int(a)-1; i >= b; --i)
#define rerep(i, n) rerepi(i, n, 0)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const long long INF = 1LL << 60;

// 降順ソート
// std::sort(data.begin(),data.end(),std::greater<ll>());
// 昇順ソート
// std::sort(data.begin(),data.end());

// ここから開始だよ！
ll AB, BC, CA;

int main() {
	// 呪文エリア
	cin.tie(0);
	ios::sync_with_stdio(false);
	// 詠唱完了
  
	cin >> AB >> BC >> CA;
	
	cout << 2 * BC * AB / 4 << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int h1,h2,k1,k2,a,b,c,d;
    cin >> h1 >> h2 >> k1 >> k2;
    cin >> a >> b >> c >> d;
    int scoreh,scorek;
    scoreh = h1*a + h2*b + (h1/10)*c + (h2/20)*d;
    scorek = k1*a + k2*b + (k1/10)*c + (k2/20)*d;
    
    if(scoreh < scorek){cout << "kenjiro" << endl;}
    else if(scoreh > scorek){cout << "hiroshi" << endl;}
    else{cout << "even" << endl;}
}



Measured memory_bytes: 3100
#!/usr/bin/env python3
import sys


def solve(N: int, L: int):
    ls = range(L, L + N)
    print(sum(ls) - min(ls, key=abs))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    solve(N, L)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
p = [1]
mod = 10**9+7
for i in range(n):
    p.append(p[-1]*(i+1)%mod)
p.pop()
def comb(n,k,mod):
    s = p[n]*pow(p[k],mod-2,mod)%mod
    s = s*pow(p[n-k],mod-2,mod)%mod
    return s
max_sum = 0
min_sum = 0
for i in range(n-k+1):
    max_sum += a[-(i+1)]*comb(n-1-i,k-1,mod)
    max_sum = max_sum%mod
    min_sum += a[i]*comb(n-1-i,k-1,mod)
    min_sum = min_sum%mod
ans = max_sum-min_sum
if ans < 0:
    ans += mod
print(ans)

Measured memory_bytes: 20080
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N;
ll A[300];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    ll x = A[0]+A[1];
    ll y = 0;
    for(int i = 2; i < N; i++) y ^= A[i];
    ll d =x-y;
    if(d < 0 || d%2 == 1){
        cout << -1 << endl;
        return 0;
    }
    if(((d/2)&y) || d/2 > A[0]){
        cout << -1 << endl;
        return 0;
    }
    ll e = d/2;
    ll tmp = 0;
    for(int j = 40; j >= 0; j--){
        ll m = (ll)1<<j;
        if(e&m) continue;
        if(!(y&m)) continue;
        if(tmp+m+e <= A[0]) tmp += m;
    }
    if(tmp+e == 0){
        cout << -1 << endl;
    }else{
        cout << A[0]-(tmp+e) << endl;
    }
}

Measured memory_bytes: 3544
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

c=v()
aa = "abcdefghijklmnopqrstuvwxyz"
print(aa[aa.index(c)+1])


Measured memory_bytes: 10248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> x(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    ll ans = 1145141919810;
    for (int i = 0; i <= n - k; i++)
    {
        if (x[i] < 0 && x[i + k - 1] > 0)
            ans = min(ans, max(abs(x[i]),abs(x[i + k - 1])) + 2 * min(abs(x[i]),abs(x[i + k - 1])));
        else
            ans = min(ans, max(abs(x[i]), abs(x[i + k - 1])));
    }
    cout << ans << endl;
}

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

int main(){
    int_fast64_t H, W;
    string s, t("snuke");
    scanf("%lld%lld", &H, &W);
    for(int i = 0; i < H * W; ++i){
        cin >> s;
        if(s == t)return 0 & printf("%c%lld\n", 'A' + (i % W), i / W + 1);
    }
    return 0;
}


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

int A[26];

int main(){
	string s;
	cin >> s;
	for(int i=0;i<s.size();i++){
		A[s[i]-'a']++;
	}
	
	for(int i=0;i<26;i++){
		if(A[i]>1){
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def f(x, a, b):
    return ((a*x)//b) - (a*(x//b))

def main():
    a, b, n = map(int, readline().split())
    if n < b:
        print(f(n, a, b))
    else:
        print(f(b-1, a, b))
if __name__ == '__main__':
    main()


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

int main(){

	int n,x;
	while(cin >> n >> x, n){
		int cnt=0;
		for(int i=1; i<=n; i++){
			for(int j=i+1; j<=n; j++){
				for(int k=j+1;k<=n; k++){
					if(i+j+k == x && i != j && j != k){
						cnt++;
					}
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

	int n;
	boolean[] color;
	int[][] map;
	int INF = 1 << 24;

	private void run() {
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		map = new int[n][n];
		for (int[] a : map)
			Arrays.fill(a, INF);
		for (int i = 0; i < n; i++) {
			int u = scanner.nextInt();
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int v = scanner.nextInt();
				int c = scanner.nextInt();
				map[u][v] = c;
			}

		}
		dijkstra();
	}

	private void dijkstra() {
		int minv;
		int[] d = new int[n];
		color = new boolean[n];
		Arrays.fill(d, INF);
		d[0] = 0;
		while (true) {
			minv = INF;
			int u = -1;
			for (int i = 0; i < n; i++) {
				if (minv > d[i] && !color[i]) {
					u = i;
					minv = d[i];
				}
			}
			if (u == -1)
				break;
			color[u] = true;
			for (int i = 0; i < n; i++) {
				if (!color[i] && d[i] > d[u] + map[u][i]) {
					d[i] = d[u] + map[u][i];
				}
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.printf("%d %d\n", i, d[i] == INF ? -1 : d[i]);
		}

	}
}

Measured memory_bytes: 34880
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  set<int> st;
  REP(i, n) {
    int d; cin >> d;
    st.insert(d);
  }
  cout << st.size() << '\n';
  return 0;
}


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

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //string[] str = Console.ReadLine().Split(' ');
            //int n = int.Parse(Console.ReadLine());

            var x = new int[] {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

            int n = int.Parse(Console.ReadLine());

            Console.WriteLine(x[n - 1]);




            //ここまで
        }
    }

}


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

int i, j, n;
string str;

bool interact(long long ask) {
    cout << "? " << ask << endl;
    char c;
    cin >> c;
    return c == 'Y';
}

int main() {
    long long digit = 1;
    int l = 1, r = 10;
    int number;
    long long last = 0;
    int ans;
    string res;
    bool f = true;
    for (i = 0, last = 10; i < 9; i++, last *= 10) {
        if (!interact(last)) {
            f = false;
            digit = last;
            break;
        }
    }
    if (f) {
        ans = 1;
        for (i = 0; i < 9; i++) {
            if (interact(ans + 1)) {
                break;
            } else {
                ans *= 10;
            }
        }
    } else {
        l = 0;r = 9;
        number = 1;
        last -= 1;
        while (digit > 1) {
            if (r - l > 1) {
                number = (r + l) / 2;
                if(interact(last+number*digit)){
                    r = number;
                } else {
                    l = number;
                }
            } else {
                last += r*digit;
                digit /= 10;
                last -= 9*digit;
                l = -1;r = 9;
            }
        }
        ans = last/10;
    }
    cout << "! " << ans << endl;
}


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

int main()
{
    string s, result;
    cin >> s;
    result = "Yes";

    for(int i = 0; i < s.size(); i++)
    {
        if((i % 2 == 0 && s[i] == 'L') || (i % 2 == 1 && s[i] == 'R'))
        {
            result = "No";
        }
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int N,M,X,A;
	int fot=0,bk=0;
	cin>>N>>M>>X;
	for(int i=1;i<=M;i++)
	{
	cin>>A;
	if(A>=X)
	fot++;
	else
	bk++;
	}
	if(fot>=bk)
	cout<<bk;
	else
	cout<<fot;
	return 0;
}

Measured memory_bytes: 256
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


while True:
    N = int(input())
    if N == 0:
        break
    table = list(map(int,input().split()))

    tmp_sum = 0
    for i in range(len(table)):
        tmp_sum += table[i]
    B = tmp_sum/len(table) #平均

    squared_sum = 0
    for i in range(len(table)):
        squared_sum += table[i]*table[i]
    A = squared_sum/len(table)

    print("%.10f"%(math.sqrt(A-B*B)))


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

#define MAX_N 6
#define MAX_X 100000
#define INF 10000000000

int N = 6;
// int X = 615;
int X;
int w[] = {100, 101, 102, 103, 104, 105};
int dp[MAX_X + 1];

// DPi i円の買い物が出来る
int main() {
    cin >> X;
    dp[0] = 1;
    for (int i = 0; i <= X; i++) {
        if (dp[i]) {
            for (int j = 0; j < 6; j++) {
                dp[i + w[j]] = 1;
            }
        }
    }

    printf("%d\n", dp[X]);
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int a, b, t;
    cin >> a >> b >> t;

    cout << t / a * b << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            long a,b,gcd;
            String line = br.readLine();
            StringTokenizer st;
            st=new StringTokenizer(line);
            a=Long.parseLong(st.nextToken());
            b=Long.parseLong(st.nextToken());
            Test t = new Test();
            gcd=t.gcd(a,b);
            System.out.println(gcd);
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

class Test{
    long r;
    long gcd(long a, long b){
        while(true){
            if(a>b){
                a=a-b;
            }else{
                break;
            }
        }
        if(b%a==0){
            r=a;
        }else{
            gcd(b,a);
        }
        return r;
    }
}

Measured memory_bytes: 24376
//詰め終わった箱の数、詰めた饅頭の数でDPする。箱には{詰めない,残りの饅頭すべて詰める,満タンにする}の
//3つのパターンで入れるとよい。(入れた饅頭の個数が同じの時、高いのから入れてれば、饅頭の売り上げは一緒.)
//要するに箱代の最小化問題だ。饅頭は高いのから入れたほうがいいに決まっている。饅頭は箱に詰めるならたくさん
//詰めたほうがいいに決まっている。証明は知らないけど、自明だろう。
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;

int M,N,P[10000],C[500],E[500];
int DP[501][10001];	//箱代でDPする

int main(){
	cin >> M >> N;
	for(int i = 0;i < M;i++){
		cin >> P[i];
	}
	for(int i = 0;i < N;i++){
		cin >> C[i] >> E[i];
	}
	for(int i = 0;i <= N;i++){
		for(int j = 0;j <= M;j++){
			DP[i][j] = 1000000000;
		}
	}
	DP[0][0] = 0;
	//DPする(小問題+初期値(箱代)に分けられる)
	for(int i = 0;i < N;i++){
		for(int j = 0;j <= M;j++){
			int num;
			num = j+C[i];
			if(num > M)num = M;
			//代入
			if(DP[i+1][j] > DP[i][j])
				DP[i+1][j] = DP[i][j];
			if(DP[i+1][num] > DP[i][j]+E[i])
				DP[i+1][num] = DP[i][j]+E[i];
		}
	}
	sort(P,P+M,greater<int>());
	//貪欲法
	int max_le = 0,sum = 0;
	for(int i = 0;i <= M;i++){
		if(max_le < sum-DP[N][i])
			max_le = sum-DP[N][i];
		sum += P[i];
	}
	cout << max_le << endl;
	return 0;
}

Measured memory_bytes: 20796
<?php
fscanf(STDIN, '%d %d', $n, $f);
for($i=0;$i<$n;$i++){
  fscanf(STDIN,'%s',$p[$i]);
}
usort($p, "strnatcmp");
for($i=0;$i<$n;$i++){
  echo $p[$i]++;
}
?>

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

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;

    if (a == b + c || b == a + c || c == a + b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


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

int main(void){
    string s;
    cin >> s;
    if(s == "100" || s == "010" || s == "001"){
        printf("1\n");
    }
    else if(s == "110" || s == "101" || s == "011"){
        printf("2\n");
    }
    else if(s == "111"){
        printf("3\n");
    }
    else{
        printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d;
  cin>>d;
  vector<int> c(26);
  for(int i=0;i<26;i++)
    cin>>c.at(i);
  vector<vector<int>> s(d,vector<int>(26));
  for(int i=0;i<d;i++)
    for(int j=0;j<26;j++)
      cin>>s.at(i).at(j);
  vector<set<int>> l(26);
  for(int i=0;i<26;i++)
    l.at(i).insert(0);
  vector<int> t(d);
  int64_t p;
  for(int i=1;i<=d;i++){
    vector<int> x(26,0);
    int m=0;
    for(int j=0;j<26;j++){
      int64_t pi=s.at(i-1).at(j);
      for(int k=0;k<26;k++)
        pi-=c.at(k)*(k==j?0:i-*rbegin(l.at(k)));
      x.at(j)=pi;
      if(x.at(j)>x.at(m))
        m=j;
    }
    t.at(i-1)=m;
    p=x.at(m);
    l.at(m).insert(i);
  }
  for(int i=0;i<26;i++)
    l.at(i).insert(d+1);
  for(int i=0;i<100000;i++){
    int pn=p;
    int di=rand()%d+1;
    int qn=rand()%26;
    int qo=t.at(di-1);
    l.at(qo).erase(di);
    auto io=lower_bound(l.at(qo).begin(),l.at(qo).end(),di);
    auto in=lower_bound(l.at(qn).begin(),l.at(qn).end(),di);
    pn+=s.at(di-1).at(qn)-s.at(di-1).at(qo);
    pn+=(di-*prev(in,1))*(*in-di)*c.at(qn)-(di-*prev(io,1))*(*io-di)*c.at(qo);
    if(pn>p){
      p=pn;
      l.at(qn).insert(di);
      t.at(di-1)=qn;
    }else
      l.at(qo).insert(di);
  }
  for(int i=0;i<d;i++)
    cout<<t.at(i)+1<<endl;
}

Measured memory_bytes: 3676
use std::io::{self, Read};

fn main() {
    let mut buffer = String::new();
    io::stdin().read_to_string(&mut buffer).unwrap();
    let buffer = buffer.trim();

    let mut v = Vec::new();
    for word in buffer.split_whitespace() {
        let n: i32 = word.parse().unwrap();
        v.push(n);
    }
    let a = v.get(0);
    let b = v.get(1);
    if a == b {
        println!("a == b");
    } else if a > b {
        println!("a > b");
    } else {
        println!("a < b");
    }
}



Measured memory_bytes: 5024
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

int main()
{
	ll n, x;
	cin >> n >> x;

	vector<ll> a(n);
	for (int i = 0; i < n; i++)
	{
		ll y;
		cin >> y;

		a[i] = abs(y - x);
	}

	ll res = inf;

	for (int i = 1; i < n; i++)
	{
		res = min(res, gcd(a[i], a[i - 1]));
	}

	if (n == 1)
	{
		res = a[0];
	}

	println(res);
}

Measured memory_bytes: 1024
n = int(input())
s = input()
ans = 0
lis = [0]*1000
one = [0]*10
two = [0]*100

for i in range(n):
  temp1 = int(s[i])
  if one[temp1]==1:
    continue
  else:
    one[temp1]=1
 
  for j in range(i+1, n):
    temp2 =  int("".join([s[i], s[j]]))
    if two[temp2]==1:
      continue
    else:
      two[temp2]=1
    
    for k in range(j+1, n):
      pin=int("".join([s[i], s[j], s[k]]))
      if lis[pin]==0:
        ans+=1
        lis[pin]=1
print(ans)

Measured memory_bytes: 9280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int n, k, i, sum = 0;
	cin >> n >> k;
  	int x[n];
  	for(i=0;i<n;i++){
      cin >> x[i];
      if(x[i] > k-x[i]){
        sum += 2*(k-x[i]);
      }else{
        sum += 2*x[i];
      }
    }
  	cout << sum << endl;
}

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

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

Measured memory_bytes: 640
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
const int mod = 1000000007;

bool valid(int k, int W)
{
    bool ok = true;
    for (int l = 0; l < W - 2; ++l)
    {
        if (((k >> l) & 1) && ((k >> (l + 1)) & 1))
        {
            ok = false;
        }
    }
    return ok;
}

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<int>> dp(H + 1, vector<int>(W, 0));
    dp[0][0] = 1;
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            for (int k = 0; k < 1 << (W - 1); ++k)
            {
                if (valid(k, W))
                {
                    if (j >= 1 && ((k >> (j - 1)) & 1))
                    {
                        dp[i + 1][j - 1] += dp[i][j];
                        dp[i + 1][j - 1] %= mod;
                    }
                    else if (j <= W - 2 && ((k >> j) & 1))
                    {
                        dp[i + 1][j + 1] += dp[i][j];
                        dp[i + 1][j + 1] %= mod;
                    }
                    else
                    {
                        dp[i + 1][j] += dp[i][j];
                        dp[i + 1][j] %= mod;
                    }
                }
            }
        }
    }
    cout << dp[H][K - 1] << endl;
    return 0;
}


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

int main(void){
    int N; cin >> N;
    string S; cin >> S;
    
    int cnt = 0;
    for(int i = 0; i < 1000; i++){
        int c[3] = {i/100, (i / 10) % 10, i % 10};
        int f = 0;
        for (int j = 0; j < N; j++){
            if (S[j] == ('0' + c[f])) f++;
            if (f == 3) break;
        }
        if (f == 3) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {

	int D[][];
	final int dir[][]={{1, 0}, {1, 1}, {0, 1}, {-1, 1}};
	int N;
	BufferedReader input;
	
	int ni() throws Exception {
		return Integer.parseInt(input.readLine());
	}
	
	String ns() throws Exception {
		return input.readLine();
	}
	
	int search(int i, int j, int d){
		if(i<0||i>=N||j<0||j>=N||D[i][j]==0) return 0;
		else return 1+search(i+dir[d][0], j+dir[d][1], d);
	}
	
	int solve(){
		int max=0;
		for(int i=0;i<N;++i){
			for(int j=0;j<N;++j){
				for(int d=0;d<4;++d){
					int k=search(i, j, d);
					max=max>k?max:k;
				}
			}
		}
		return max;
	}
	
	void setD() throws Exception{
		D=new int[N][N];
		for(int i=0;i<N;++i){
			String s=ns();
			for(int j=0;j<N;++j){
				char c=s.charAt(j);
				if(c=='1') D[i][j]=1;
				else if(c=='0') D[i][j]=0;
			}
		}
	}
	
	void io(){
		input=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			try {
				N=ni();
				if(N==0)break;
				setD();
				System.out.println(solve());
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().io();
	}

}

Measured memory_bytes: 24836
/*
Writer: SPD_9X2
https://atcoder.jp/contests/arc073/tasks/arc073_c

全体の最大値と、最小値は必ず4つ中に含まれる
最大を必ず赤に割り振るとする

(1)最小が最大とペアでないとき、→自由な方における
(2)ペアの時、→青にしか置けない

ありうる分け方は2つ
(A)最小を赤にすると決めた時
    青の最大値を最小化して、最小値を最大化するのがよさそう？

(B)最小を青にするとき
    →赤の最小値を最大化、青の最大値を最小化するのが良い
    →貪欲に大きい方を赤&小さい方を青に選んでいけばよい

問題は(A)の時か…

青には、最小と最大の余り物は必ず含まれる。
また、残りのペアの内、最小値の最大 <= 青最大 　最大値の最小>=青最小
は必ず満たされる。


尺取り法！！
で、Nこのペアから1つづつ取るときの最大と最小の差の最小値を求められる

x>yにしておこう
*/

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

#define rep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
using ll = long long;

int main(){

    ll N;
    cin >> N;

    ll maxind = 0, minind = 0;
    ll x,y,t;
    vector<vector<ll>> xy(N,vector<ll> (2,0));

    rep(i,0,N){
        cin >> x >> y;

        if (x < y){
            t = x;
            x = y;
            y = t;
        }

        xy[i][0] = x;
        xy[i][1] = y;

        if (x > xy[maxind][0]) maxind = i;
        if (y < xy[minind][1]) minind = i;
    }

    ll rmin = 10000000000;
    ll bmax = 0;

    rep(i,0,N){

        x = xy[i][0];
        y = xy[i][1];

        if ((i==maxind) && (i==minind)){
            continue;
        }else if (i==maxind){
            bmax = max(bmax,y);
            continue;
        }else if (i==minind){
            rmin = min(rmin,x);
            continue;
        }
        
        rmin = min(rmin,max(x,y));
        bmax = max(bmax,min(x,y));

    }

    ll ans = ((xy[maxind][0]-rmin) * (bmax-xy[minind][1]));

    if (maxind != minind){

        ll side_R = (xy[maxind][0] - xy[minind][1]);

        ll apnum = 0;
        vector<ll> aplis(N,0);
        vector<vector<ll>> wait(0,vector<ll> (2,0));

        rep(i,0,N){

            if (i==maxind){
                wait.push_back({xy[i][1],i});
            }else if (i==minind){
                wait.push_back({xy[i][0],i});
            }else{
                wait.push_back({xy[i][0],i});
                wait.push_back({xy[i][1],i});
            }
        }

        vector<vector<ll>> q(0,vector<ll> (2,0));
        sort(wait.begin(),wait.end());
        
        ll find = 0;

        rep(i,0,wait.size()){

            ll num = wait[i][0];
            ll ind = wait[i][1];

            if (aplis[ind] == 0){
                apnum++;
            }

            aplis[ind] ++;
            q.push_back({num,ind});

            if (apnum==N){

                while (aplis[q[find][1]] > 1){
                    aplis[q[find][1]] -= 1;
                    find++;
                }

                ans = min(ans, side_R*(q[q.size()-1][0] - q[find][0]) );
            }
        }
    }

    cout << ans << endl;
}

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

int main()
{
  string name;
  getline(cin, name);

  if(name[0] == 'Y')
  {
    if(name[1] == 'A')
    {
      if(name[2] == 'K')
      {
        if(name[3] == 'I')
        {
          cout << "Yes" << endl;
        }
        else
        cout << "No" << endl;
      }
      else
      cout << "No" << endl;
    }
    else
    cout << "No" << endl;
  }
  else
  cout << "No" << endl;
}


Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {
	
	static Map<Integer, Card> cardMap = new HashMap<Integer, Card>();
	static Map<Integer, Integer> numMap = new HashMap<Integer, Integer>();
	
	//?????????????´?????????????????????????????????????????????????????????§?????????????????????????????????????????????Map???????????§??????????????????????????????????????????????????????
	//?????????????????¨?????????????????????int???????????°??¨?????????????????????????????£????°????????????????
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		//???????´?????????°????????¨??????Card????????????????????????????????????
		//CardMap<?????????,??????????????????????????????>???NumMap<?????????,???????????????????????°???)>
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			String[] str = br.readLine().split(" ");
			Card card = new Card(str[0], Integer.parseInt(str[1]), i);
			cardMap.put(i, card);
			numMap.put(i, card.num);
			a[i] = i;
		}
		quickSort(a, 0, n - 1);
		
		//?????????????????????????????????????????????????????????????????¨??§??????
		//
		boolean flag = true;
		Card card = cardMap.get(a[0]);
		int num = card.num;
		int order = card.order;
		//System.out.println(card.mark + " " + card.num + " " + card.order);
		for (int i = 1; i < n; i++) {
			int k = a[i];
			card = cardMap.get(k);
			if(num == card.num && card.order < order){
				flag = false;
			}
			num= card.num;
			order = card.order;
			//System.out.println(card.mark + " " + card.num + " " + card.order);
		}
		if(flag == true){
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}
		//?????????????????????????????????
		for (int i = 0; i < n; i++) {
			int k = a[i];
			card = cardMap.get(k);
			num= card.num;
			System.out.println(card.mark + " " + card.num);
		}
	} 
//??\???????????????partition????????????????????¨??????Card?????????????????°?????????????????¨??§???????????£???????????¨?????????????????????????????°??§??????int???????????????Card???????????????????????????????´?????????????
	static int partition(int[] a, int p, int r) {
		int x = numMap.get(a[r]);
		int i = p - 1;
		int tmp;
		for (int j = p; j < r; j++) {
			if (numMap.get(a[j]) <= x) {
				i = i + 1;
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
		tmp = a[i + 1];
		a[i + 1] = a[r];
		a[r] = tmp;
		return i + 1;
	}
	//?????????????????????
	static void quickSort(int[] a, int p, int r){
		int q = 0;
		if(p < r){
			q = partition(a, p, r);
			quickSort(a, p, q-1);
			quickSort(a, q+1, r);
		} else {
			return;
		}
	}
}
//??????????????????????????????????????????
//???????????????????????????????????????????????????????????????????????????????????????????´???????(order)??????????????????
class Card{
	
	String mark;
	int num;
	int order;
	
	Card(String mark, int num, int order){
		this.mark = mark;
		this.num = num;
		this.order = order;
	}
}

Measured memory_bytes: 96872
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define mod 1000000007
#define har ios_base::sync_with_stdio(),cout.tie(NULL),cin.tie(NULL);
const int N = 1e5 + 5;
int arr[N];
int main()
{
	har;
	int n, k;
	cin >> n >> k;
	ll dp[N];
	for (int i = 0; i < n; ++i)
	{
		cin >> arr[i];
		dp[i] = INT_MAX;
	}
	dp[0] = 0;
	for (int i = 1; i < n; i++)
	{
		for (int j = max(i - k, 0); j < i; j++)
		{
			dp[i] = min(dp[j] + abs(arr[j] - arr[i]), dp[i]);
		}
	}
	cout << dp[n - 1] << "\n";
}

Measured memory_bytes: 1408
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M,X = LI()
CA = np.array([LI() for _ in range(N)])
ans = float('INF')
for i in range(2**N):
    bit = np.array([[i>>j&1 for j in range(N)]]).T
    temp = np.sum(CA*bit,axis=0).tolist()
    temp2 = []
    temp2.append(temp)
    for money,*x in temp2:
        for y in x:
            if y<X:
                break
        else:
            ans = min(ans,money)
print(ans if ans !=float('INF') else -1)


Measured memory_bytes: 27268
L,R = map(int,input().split())

circle = (R- L)/ 2019
if circle >=2:
    R = L+2019*2+10
# print(R)

mod_list = []
for i in range(L,R+1):
    mod_list.append(i%2019)

mod_list.sort()

result_list = []
for i in range(len(mod_list)-1):
    for j in range(i+1, len(mod_list)):
        result_list.append((mod_list[i]*mod_list[j])%2019)
print(min(result_list))

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

int main() {
  int n,m,q;
  cin>>n>>m>>q;
  vector<vector<int>>c(n+1,vector<int>(n+1));
  vector<int>a(m),b(m);
  rep(i,m){
    cin>>a.at(i)>>b.at(i);
    c.at(a.at(i)).at(b.at(i))++;
  }
  rep(i,n+1){
    rep2(j,1,n+1){
      c.at(i).at(j)+=c.at(i).at(j-1);
    }
  }
  
  rep(i,q){
    int P,Q;
    cin>>P>>Q;
    int ans=0;
    rep2(j,P,Q+1){
      ans+=c.at(j).at(Q)-c.at(j).at(P-1);
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3456
N, K, Q = map(int, input().split())
soten = [K-Q]*N
not_genten = [0]*N

for i in range(Q):
    A = int(input())
    soten[A-1] +=1

for i in range(N):
    print('Yes' if soten[i] > 0 else 'No')


Measured memory_bytes: 51672
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
Threshold=sum(a)/(4*m)
ans='Yes'
#print(Threshold,a)
for i in range(m):
    if a[i]<Threshold:
        ans='No'
        break
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
using namespace std;

int main(void) {
	int r,g;

	cin >> r >> g;

	cout << g*2-r << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std ;
typedef long long int ll ;


int main(){
	ios;
	string s;
	cin>>s;
	for(int i=0; i<s.size(); i++){
		if((i+1)%2==1){
			if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
				continue;
			}
			else{
				cout<<"No\n";
				return 0;
			}
		}
		else{
			if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
				continue;
			}
			else{
				cout<<"No\n";
				return 0;
			}
		} 
	}
	cout<<"Yes\n";
	return 0;
}



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

#define lli long long int

using namespace std;

lli bigmod = 1000000007, faktorial[200010];

lli pangkat(lli a, lli b) {
	lli temp, total;
	if (b == 0)
		return 1;
	temp = pangkat(a, b / 2);
	total = (temp * temp) % bigmod;
	if (b & 1)
		total = (total * a) % bigmod;
	return total;
}

lli combine(lli p, lli r) {
	lli ret, temp;
	ret = faktorial[p];
	temp = pangkat(faktorial[r], bigmod - 2);
	ret = (ret * temp) % bigmod;
	temp = pangkat(faktorial[p - r], bigmod - 2);
	ret = (ret * temp) % bigmod;
	return ret;
}

int main() {
	lli n, m, k, sum = 0, ans, c;
	scanf("%lld %lld %lld", &n, &m, &k);
	faktorial[0] = 1;
	for (lli i = 1; i <= (n * m); i++)
		faktorial[i] = (faktorial[i - 1] * i) % bigmod;
	lli dist[n + 5][m + 5];
	for (lli i = 1; i <= n; i++)
		for (lli j = 1; j <= m; j++)
			dist[i][j] = i * j * (i + j - 2) / 2;
	for (lli i = 0; i < n; i++)
		for (lli j = 0; j < m; j++)
			sum = (sum + dist[n - i][m - j] + dist[n - i][j + 1] - dist[n - i][1] - dist[1][j + 1]) % bigmod;
	c = combine((n * m) - 2, k - 2);
	ans = (c * sum) % bigmod;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
int lpath;
unordered_map<int,bool> visited;
unordered_map<int,int> height;
vector<vector<int>> graph;
void dfs(int u){
  visited[u]=true;
  for(auto &v:graph[u]){
    if(!visited[v]){
      dfs(v);
      height[u]=max(height[u],1+height[v]);
    }
    else height[u]=max(height[u],1+height[v]);
  }
  lpath=max(lpath,height[u]);
}
int main(){
  fast;
  int n,m;
  cin>>n>>m;
  graph=vector<vector<int>>(n+1);
  for(int i=0;i<m;i++){
    int u,v;
    cin>>u>>v;
    graph[u].emplace_back(v);
  }
  for(int i=1;i<=n;i++){
    if(!visited[i])
        dfs(i);
  }
  cout<<lpath<<"\n";
  return 0;
}
  

Measured memory_bytes: 16700
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
int main() {
    int x,y;
    string S;
    cin >> x >> y;
//    cin >> N >> K;
//    vector<int> A(N);
    rep(i, 0, 101){
        rep(j, 0, 101){
            int sum = 2*i+4*j;
            if(y == sum && (i+j) == x){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3624
from collections import deque
import sys
input = sys.stdin.readline

def bfs(graph, start):
    while graph != {}:
        start = min(graph.keys())
        queue = deque([])
        queue.append(start)
        pos = {}
        pos[start] = 0
        while queue:
            u = queue.popleft()
            for v,d in graph[u].items():
                if v not in pos:
                    pos[v] = pos[u] + d
                    if v in graph:
                        queue.append(v)
                elif pos[v] != pos[u] + d:
                    return False
            del graph[u]
            # print(queue)
    return True

n,m = map(int, input().split())

graph = {}
for i in range(m):
    l,r,d = map(int, input().split())
    if l not in graph:
        graph[l] = {}
    graph[l][r] = d
    if r not in graph:
        graph[r] = {}
    graph[r][l] = -d

if m == 0 or bfs(graph, min(graph.keys())):
    print('Yes')
else:
    print('No')
# print(graph)

Measured memory_bytes: 115548
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

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

    if (x >= 30)cout << "Yes" << endl;
    else cout << "No" << endl;
   
return 0;
}

Measured memory_bytes: 3104