akhauriyash/Code-Regression huggingface dataset:
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <cstdio>
#include <vector>
#include <functional>
using namespace std;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }


  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

int main() {
  int N, Q;
  scanf("%d %d", &N, &Q);
  //<型> seg(サイズ,二項演算,単位元) 1-index
  SegmentTree< int > seg(N, [](int a, int b) { return max(a, b); }, -1);
  
  rep(i,N){
    int x;
    scanf("%d", &x);
    seg.set(i,x);
  }
  seg.build();
  
  rep(i,Q){
    int T, X, Y;
    scanf("%d %d %d", &T, &X, &Y);
    if(T==1) seg.update(X-1,Y);
    else if(T==2) printf("%d\n", seg.query(X-1,Y));
    else{
      int a=seg.find_first(X-1,[&](int b){return b>=Y;});
      if(a==-1) a=N;
      printf("%d\n", a+1);
    }
  }
  return 0;
}

Measured memory_bytes: 4852
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (n, k, q) = {
        let v: Vec<usize> = read_vec();
        (v[0], v[1], v[2])
    };
    let mut check = vec![0; n];
    for _ in 0..q {
        let a: usize = read();
        check[a-1] += 1;
    }

    for &score in &check {
        if score + k > q {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


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

using namespace std;
using ll = long long;

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

int main() {
  ll h;
  cin >> h;
  int cnt = 0;
  while (h > 1) {
    h /= 2;
    ++cnt;
  }

  ll ans = 1;
  rep(i, cnt + 1) ans *= 2;
  cout << ans - 1 << endl;
  return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){

	int d;
	cin >> d;

	cout << "Christmas";

	d = 25 - d;

	while( d-- > 0 )
		cout << " Eve";

	cout << endl;

	ret 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<string>
using namespace std;
typedef long long ll;
typedef vector < int > vi;
typedef pair<int,int> pi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define re(i,a,b) for(ll i=a;i<b;i++)
//add below to remove endl in input just before getline()
//cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
int main(){
	//ios::sync_with_stdio(0);cin.tie(0);
	//freopen("input.txt", "r", stdin);
	int d,n,c=0;
	cin>>d>>n;
	if(d==0){
		for(int i=0;;i++){
			if(i%100!=0){
				c++;
				if(c==n){cout<<i;break;}
				}
			}
		}
	else if(d==1){
		for(int i=100;;i+=100){
			if( i%100==0 && (i/100)%100!=0 ){
				c++;
				if(c==n){cout<<i;break;}
				}
			}
		}
	else if(d==2){
		for(int i=10000;;i+=10000){
			if( i%10000==0 && (i/10000)%100!=0 ){
				c++;
				if(c==n){cout<<i;break;}
				}
			}
		}
	

	
return 0;}


Measured memory_bytes: 3436
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repd(i,n) for(ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll n, k, m, M = 1e9 + 7;

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

string s;
cin >> n >> s;

ll num = 0;
for(int pass = 1000; pass < 2000; pass++) {
    string t = to_string(pass);
    t.erase(t.begin());
    
    int idx = 0;
    rep(i, n) {
        if(s[i] == t[idx]) idx++;
        if(idx == 3) {
            num++;
            break;
        }
    }
}

cout << num << endl;
}


Measured memory_bytes: 3804
#include<bits/stdc++.h>
#define N 10005
#define rank raljfds
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P2;
 
class UF{
public:
  int V;
  vector<int> par, rank, mil;
  UF(){}
  UF(int V):V(V),par(V),rank(V,0),mil(V,-1){for(int i=0;i<V;i++) par[i]=i;}
 
  int find(int x){
    assert(x<V);
    if(par[x]==x) return x;
    return par[x]=find(par[x]);
  }
   
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    
    if(mil[x]!=-1) mil[y]=mil[x];
    if(mil[y]!=-1) mil[x]=mil[y];
    
    if(rank[x]<rank[y]) par[x]=y;
    else{
      par[y]=x;
      if(rank[x]<rank[y]) rank[x]++;
    }
  }
   
  bool same(int x,int y){return find(x)==find(y);}
   
  void add_mil(int num){
    mil[num]=num;
  }
   
  int get_mil(int x){
    return mil[find(x)];
  }
  
};
 
int n,t,k;
vector<P2> G;
UF uf;
 
int solve(){
   
  uf=UF(n);
   
  int milnum;
   
  for(int i=0;i<t;i++){
 
    cin>>milnum;
     
    uf.add_mil(milnum-1);
  }
   
  vector<int> ans;
   
  for(int idx=0;idx<G.size();idx++){
     
    int cost=G[idx].first;
    int A=G[idx].second.first;
    int B=G[idx].second.second;
    
    if(!(uf.get_mil(A)!=-1&&uf.get_mil(B)!=-1)) uf.unite(A,B);
    else ans.push_back(cost);
    
  }
 
  sort(ans.begin(),ans.end());
 
  int res=0;
  
  for(int i=0;i<k;i++) res+=ans[i];
   
  return res;
}
 
int main(){
 
  int T=1;
   
  while(1){
 
    cin>>n>>t>>k;
    if(!n&&!t&&!k) break;
 
    int a,b,cost;
     
    for(int i=0;i<n-1;i++){
       
      scanf("%d %d %d",&a,&b,&cost);
       
      a--, b--;
 
      G.push_back(P2(cost,P(a,b)));
    }
     
    sort(G.begin(),G.end(),greater<P2>());
     
    cout<<"Case "<<T<<": ";
     
    cout<<solve()<<endl;
 
    G.clear();
     
    T++;
  }
   
  return 0;
}

Measured memory_bytes: 3400
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;

//123:0(1個未満)
//132:1(二個未満)
//213:2(二個未満)
//321:3(二個未満)
//231:4
//312:5
std::array<int, 3> get_type(int id)
{
	switch (id)
	{
	case 0:
		return {1,2,3};
	case 1:
		return { 1,3,2 };
	case 2:
		return { 2,1,3 };
	case 3:
		return { 3,2,1 };
	case 4:
		return { 2,3,1 };
	case 5:
		return { 3,1,2 };
	default:
		break;
	}
}
int get_id(std::array<int, 3> res)
{
	if (res[0] == 1) {
		if (res[1] == 2) {
			return 0;
		}
		else {
			return 1;
		}
	}
	else if (res[0] == 2) {
		if (res[1] == 1) {
			return 2;
		}
		else {
			return 4;
		}
	}
	else  {
		if (res[1] == 1) {
			return 5;
		}
		else {
			return 3;
		}
	}
}

int amida_num[6];

bool func(std::array<int, 3> v)
{
	for (int32_t i = 0; i < 6; i++)
	{
		if (amida_num[i] > 0)
		{
			--amida_num[i];
			auto sw = get_type(i);

			std::array<int, 3> next;
			next[0] = v[sw[0] - 1];
			next[1] = v[sw[1] - 1];
			next[2] = v[sw[2] - 1];
			if (get_id(next) == 0) { return true; }
			if (func(next)) {
				return true;
			}
			++amida_num[i];
		}
	}
	return false;
}


int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (int32_t i = 0; i < N; i++)
	{
		int32_t w;
		in >> w;
		std::array<int, 3> res{ 1,2,3 };
		while(w--)
		{
			int t;
			in >> t;
			if (t == 1) {
				std::swap(res[1], res[2]);
			}
			else {
				std::swap(res[1], res[0]);
			}
		}
		amida_num[get_id(res)]++;
	}
	if (amida_num[0] >= 1) { out << "yes" << endl; return 0; }
	if (amida_num[1] >= 2) { out << "yes" << endl; return 0; }
	if (amida_num[2] >= 2) { out << "yes" << endl; return 0; }
	if (amida_num[3] >= 2) { out << "yes" << endl; return 0; }
	if (amida_num[4] >= 3) { out << "yes" << endl; return 0; }
	if (amida_num[5] >= 3) { out << "yes" << endl; return 0; }

	if (func({ 1,2,3 })) {
		out << "yes" << endl;
	}
	else {
		out << "no" << endl;
	}

	return 0;
}
#endif



Measured memory_bytes: 3224
import bisect

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
B.sort()
C.sort()
a = [0] * N
for i in range(N):
	a[i] = N - bisect.bisect_right(C, B[i])
i = N - 1
while 0 < i:
	a[i - 1] += a[i]
	i -= 1
ans = 0
for i in A:
	b = bisect.bisect_right(B, i)
	if b == N:
		continue
	ans += a[b]
print(ans)

Measured memory_bytes: 23232
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

ll gcd(ll a, ll b) {
    return b != 0 ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int main() {
    ll N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    ll ans = lcm(N, M);
    ll divi = gcd(N, M);
    int marka = 0;
    int markb = 0;
    bool ok = true;
    for (int i = 0; i < divi; i++) {
        if (S[marka] != T[markb]) {
            ok = false;
            break;
        }
        marka += (N / divi);
        markb += (M / divi);
    }
    if (ok) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  bool ok = true;
  int n;
  cin >> n;
  vector<string> w(n);
  set<string> kind;
  rep(i,0,n){
    cin >> w[i];
    kind.insert(w[i]);
  }
  if (kind.size()!=n) ok = false;
  rep(i,0,n-1) {
    if (w[i][w[i].size() - 1] != w[i+1][0]) {
      ok = false;
      break;
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
mod = 10**9 + 7
ans = 1
L = [0] * (n+1)
for i in range(2, n+1):
    f = i
    for j in range(2, i+1):
        while f != 1 and f % j == 0:
            f //= j
            L[j] += 1

# print(L)

for i in range(2, len(L)):
    if L[i] > 0:
        ans = (ans * (L[i]+1)) % mod
print(ans)

Measured memory_bytes: 39792
//
//  main.cpp
//  A - Security
//
//  Created by Hashizo on 2019/06/22.
//  Copyright © 2019 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>

using namespace std;

#undef INT_MAX
#undef INT_MIN

#define INT_MAX	2147483647
#define INT_MIN	(-INT_MAX  -1)

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define REPLACE(s, f, t) regex_replace(s, regex(f), t)

int main(int argc, const char * argv[]) {
	char s[4];
	cin >> s;

	
	if(s[0] == s[1]) {
		cout << "Bad" << endl;
		return 0;
	}
	else if (s[1] == s[2]){
		cout << "Bad" << endl;
		return 0;
	}
	else if (s[2] == s[3]){
		cout << "Bad" << endl;
		return 0;
	}

	cout << "Good" << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
X, N = map(int, input().split())
p = list(map(int, input().split()))

if N == 0:
    print(X)
    sys.exit()

small = X
while small in p:
    small -= 1

large = X
while large in p:
    large += 1

if X - small <= large - X:
    print(small)
else:
    print(large)


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

# 長さじゃなくて、棒自体で区別してるやんけー！

import numpy as np

N = int(readline())
L = np.array(read().split(),np.int32)

L.sort()

U=1000
counter = np.bincount(L,minlength=U+U+10)
cum = counter.cumsum()

add = L[:,None] + L[None,:]
max_c = cum[add-1]
cnt_c = max_c - np.arange(len(L)) - 1

answer = np.triu(cnt_c,1).sum()
print(answer)

Measured memory_bytes: 153152
/*
ID: markusz1
TASK: template
PROG: template
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ul;
typedef priority_queue<int> p_int_max; // top is max
typedef priority_queue<int, vector<int>, greater<int> >p_int_min; // top is min
typedef priority_queue<ll> p_ll;
typedef priority_queue<double> p_double;

int a,b,i1,i2,ans;
string str;
bool isBroken=true;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("template.in","r",stdin);
  //freopen("template.out","w",stdout);

	cin >> a >> b;
	for (int n=a;n<=b;n++){
		str = to_string(n);
		i1=0;
		i2=str.size()-1;
		isBroken=false;
		while (i2 > i1) {
			if (str[i2] != str[i1]) {
				isBroken = true;
				break;
			}
			i1++;
			i2--;
		}
		if (!isBroken) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int i,n,r=0;
    char s[101];
    scanf("%d",&n);
    scanf("%s",s);
    for(i=0;i<n;i++){
        if(s[i]=='R')r++;
    }
    if(r>n/2)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define moder 1000000007
#define double long double
#define INF LLONG_MAX/10000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, a[100010], b, c, d, kaijo[100010];
set<int> st;
int mypow(int a, int b) {
	if (!b)return 1;
	if (b % 2)return mypow(a, b - 1) * a % moder;
	int memo = mypow(a, b / 2);
	return memo * memo% moder;
}
int comb(int a, int b) {
	if (a < b)return 0;
	return kaijo[a] * mypow(kaijo[a - b], moder - 2) % moder * mypow(kaijo[b], moder - 2) % moder;
}
signed main() {
	cin >> n;
	rep(i, n + 1)cin >> a[i];
	rep(i, n + 1) {
		if (st.find(a[i]) != st.end()) {
			c = i;
			d = a[i];
			break;
		}
		st.insert(a[i]);
	}
	rep(i, n + 1) {
		if (a[i] == d) {
			b = i;
			break;
		}
	}
	cout << n << endl;
	cout << ((n + 1) * n / 2 - b - (n - c)) % moder << endl;
	kaijo[0] = 1;
	rep(i, 100010) {
		if (i)kaijo[i] = kaijo[i - 1] * i % moder;
	}
	for (int i = 3; i <= n + 1; i++) {
		int cnt = comb(n + 1, i);
		if (b + (n - c) >= i - 1) {
			cnt -= comb(b + (n - c), i - 1);
			cnt += moder;
			cnt %= moder;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
int main()
{
      long long int i,j,b,h=0,n;
      int a[3000];
      cin>>n;
      for(i=0;i<n;i++)
      {
          cin>>a[i];
      }
       for(i=0;i<n;i++)
       {
           h = h+(a[i]-1);
       }
       cout<<h<<endl;


      return 0;
      }


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
struct Query {
    int head;
    int a;
    int b;
};

int main(void)
{
    int l;
    int r;
    ll  min = 0;
    int sum = 0;
    priority_queue<int> lQue;
    priority_queue< int, std::vector<int>, std::greater<int> > rQue;

    int head, q;
    cin >> q;
    vector<Query> query(q);
    rep(i, q){
        cin >> query[i].head;
        if(query[i].head == 1){
            cin >> query[i].a >> query[i].b;
        }
    }

    lQue.push(query[0].a);
    min += query[0].b;

    for (int i = 1; i < q; i++)
    {
        if(query[i].head == 1){
            //lQue.size() >= rQue.size() を維持し続ける
            //偶数個の場合は中央2個が最小
            if(lQue.size() == rQue.size()) {
                if(query[i].a <= lQue.top()){
                    min +=  lQue.top() - query[i].a;
                    lQue.push(query[i].a);
                }else if(rQue.top() <= query[i].a){
                    min +=  query[i].a - rQue.top();
                    rQue.push(query[i].a);
                    lQue.push(rQue.top());
                    rQue.pop();
                }else{
                    lQue.push(query[i].a);
                }
            }else{//奇数個の場合はlQue.size()のほうが大きく、このtopが最小。
                if(query[i].a <= lQue.top()){
                    min +=  lQue.top() - query[i].a;
                    lQue.push(query[i].a);
                    rQue.push(lQue.top());
                    lQue.pop();
                }else {
                    min +=  query[i].a - lQue.top();
                    rQue.push(query[i].a);
                }
            }
            min += query[i].b;
        }else{
            cout << lQue.top() << " " << min << endl;  
        }
    }
    return 0;
}

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

int main(){
  int n, r;
  cin >> n >> r;
  if (n >= 10) cout << r << endl;
  if (n < 10) cout << r + 100*(10-n);

}

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

using namespace std;

int main(){
    int r,w,c,R;
    while(cin>>r>>w>>c>>R,r){
        int ans=(w*c-r)/R;
        if((w*c-r)%R)++ans;
        if(w*c<=r)ans=0;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3076
N = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7
s = [0] * 60

for i in range(N):
    for j in range(60):
        if (A[i] >> j) & 1 == 1:
            s[j] += 1

ans = 0            
for i in range(60):
    ans += (((N - s[i]) * s[i]) << i) % mod
    ans %= mod
    
print(ans)

Measured memory_bytes: 122808
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	static class Reader {
		BufferedReader br;
		StringTokenizer st;
 
		public Reader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
	
	// static int min = Integer.MAX_VALUE;
	static int[] dp, a;

	public static void main(String[] args) {
		Reader r = new Reader();
		
		int n = r.nextInt();
		a = new int[n];
		dp = new int[n];
		
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		for (int i = 0; i < n; i++) {
			a[i] = r.nextInt();
		}
		
		dp[0] = 0;
		dp[1] = Math.abs(a[1] - a[0]);
		for (int i = 2; i < n; i++) {
			dp[i] = Integer.min(dp[i - 1] + Math.abs(a[i] - a[i - 1]), dp[i - 2] + Math.abs(a[i] - a[i - 2]));
		}
		System.out.println(dp[n - 1]);
	}
}


Measured memory_bytes: 31500
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 2e5+7;

int main()
{
    
    int n;
    scf(n);
    
    int a[n];
    
    rep(i,0,n)
    {
        scf(a[i]);
            
        a[i]=a[i]-(i+1);
    
    }    
    
    sort(a,a+n);
    
    int b=0;
    
    ll res=0;
    
    if(n&1)
    b=a[n/2];
    
    
    else
    b=(a[n/2]+a[n/2-1])/2;
    
    rep(i,0,n)
    res+=abs(a[i]-b);
    
    lprin(res);
    
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int A,B,i,cnt=0;
  
  scanf("%d",&A);
  scanf("%d",&B);
  for(i=0;i<2;i++){
    if (A > B){
      cnt += A;
      A -= 1;
    }else{
      cnt += B;
      B -=1;
    }
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll t=1;
   //cin>>t;
   while(t--)
   {
       ll n;
       cin>>n;
       if(n>=400&&n<=599)
        cout<<8<<endl;
       else if(n>=600&&n<=799)
        cout<<7<<endl;
       else if(n>=800&&n<=999)
        cout<<6<<endl;
    else if(n>=1000&&n<=1199)
        cout<<5<<endl;
        else if(n>=1200&&n<=1399)
        cout<<4<<endl;
        else if(n>=1400&&n<=1599)
        cout<<3<<endl;
        else if(n>=1600&&n<=1799)
        cout<<2<<endl;
        else
            cout<<1<<endl;
   }

}


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

#define LL long long int
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define mp make_pair
#define FOR(i, n) for(i = 0; i < n; ++i)
typedef vector <int> vi;
typedef vector <LL> vll;
typedef pair<LL, LL> iPair;
const int MOD = 1e9+7;

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

    LL t = 1;
    LL i,j;
    // cin>>t;
    
    while(t--)
    {
        int n;
        cin>>n;
        set <iPair> s;
        vll arr(n), brr(n);
        FOR(i, n) cin>>arr[i];
        FOR(i, n) cin>>brr[i];
        FOR(i, n) s.insert({brr[i], i});
        LL ans = 0;
        while (!s.empty())
        {
            LL i = s.rbegin()->second;
            auto it = s.end();
            it--;
            s.erase(it);
            LL step = brr[(i - 1 + n) % n] + brr[(i + 1) % n];
            if((brr[i] - arr[i]) % step == 0)
            {
                ans += (brr[i] - arr[i]) / step;
                brr[i] = arr[i];
                continue;
            }
            if(step > (brr[i] - arr[i]))
            {
                cout<<"-1";
                return 0;
            }
            ans += brr[i] / step;
            brr[i] %= step;
            if(brr[i] < arr[i])
            {
                cout<<"-1";
                return 0;
            }
            s.insert({brr[i], i});
        }
        cout<<ans;
        


    }

	return 0;
}


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

const int INF = 1e9;

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int a[n+1];
  for(int i=0;i<n+1;i++)a[i]=0;
  for(int i=0;i<n;i++){
    if(s[i]=='E'){
      a[i+1]=a[i]+1;
    }else{
      a[i+1]=a[i];
    }
  }
  int ans=n;
  for(int i=1;i<n+1;i++){
    ans=min(ans,i-1-a[i-1]+a[n]-a[i]);
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 1796
import java.util.*;

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

	String table[];

	void run() {
		Scanner sc = new Scanner(System.in);
		for (;;) {
			int R = sc.nextInt();
			int C = sc.nextInt();
			if (R == 0 && C == 0)
				break;
			table = new String[R];
			for (int r = 0; r < R; r++) {
				table[r] = sc.next();
			}
			System.out.println(solve(R, C));
		}
	}

	int LargestRect(int a[]) {
		int best = 0;
		Stack<Integer> pos = new Stack<Integer>();
		Stack<Integer> height = new Stack<Integer>();

		pos.add(-1);
		height.add(-1);
		for (int i = 0; i < a.length; i++) {
			if (height.peek() <= a[i]) {
				pos.add(i);
				height.add(a[i]);
			} else {
				int last_pos = -1;
				while (height.peek() > a[i]) {
					best = Math.max(best, (height.peek()) * (i - pos.peek()));
					height.pop();
					last_pos = pos.pop();
				}
				pos.add(last_pos);
				height.add(a[i]);
			}
		}
		return best;
	}

	int solve(int R, int C) {
		int temp[][] = new int[R][C];
		for (int c = 0; c < C; c++) {
			int len = 0;
			for (int r = 0; r < R; r++) {
				if (table[r].charAt(c) == '.')
					len++;
				else
					len = 0;
				temp[r][c] = len;
			}
		}
		int a[] = new int[C + 1];
		a[C] = -1;
		int res = 0;
		for (int r = 0; r < R; r++) {
			for (int c = 0; c < C; c++)
				a[c] = temp[r][c];
			res = Math.max(res, LargestRect(a));
		}
		return res;
	}
}

Measured memory_bytes: 15000
#include<iostream>
#include<sstream>
using namespace std;
main()
{
	long s;cin>>s;
	s--;
	int id=0;
	for(int i=0;i<17;i++)
	{
		long p=1;
		for(int j=0;j<i;j++)p*=10;
		long c3=(p*10-1)/3-(p-1)/3;
		long c5=(p*10-1)/5-(p-1)/5;
		long c15=(p*10-1)/15-(p-1)/15;
		long now=(i+1)*(p*10-p-c3-c5+c15)+c3*4+c5*4;
		if(now<=s)s-=now;
		else{
			id=i;
			break;
		}
	}
	long a=1;
	for(int i=0;i<id;i++)a*=10;
	if(s>=(id?4:1))s-=id?4:1;
	else a--;
	for(int i=id;i>=0;i--)
	{
		long p=1;
		for(int j=0;j<i;j++)p*=10;
		while(s)
		{
			long L=a,R=a+p;
			long c3=R/3-L/3,c5=R/5-L/5,c15=R/15-L/15;
			long now=(id+1)*(R-L-c3-c5+c15)+c3*4+c5*4;
			if(now<=s)
			{
				s-=now;
				a+=p;
			}
			else break;
		}
	}
	stringstream ss;
	for(int j=1;j<=20;j++)
	{
		long now=a+j;
		if(now%15==0)ss<<"FizzBuzz";
		else if(now%3==0)ss<<"Fizz";
		else if(now%5==0)ss<<"Buzz";
		else ss<<now;
	}
	string t;ss>>t;
	cout<<t.substr(s,20)<<endl;
}



Measured memory_bytes: 3228
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main(){
  string s;
  cin >> s;

  cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1) << endl;
}

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

int main() {

  int N;
  cin >> N;
  vector<double> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }

  for (int i = 0; i < N-1; i++) {
    sort(v.begin(), v.end());
    v.at(i+1)=(v.at(i)+v.at(i+1))/2;
    v.at(i)=0;
  }

  cout << v.at(N-1) << endl;

}

Measured memory_bytes: 256
n, k = map(int, input().split())
v = list(map(int, input().split()))
sum_jewel = []
for i in range(1, min(n, k)+1):
    for j in range(i+1):
        take = v[:j] + v[n-i+j:]
        take.sort()
        for l in range(k-i):
            try:
                if take[0] < 0:
                    del take[0]
            except:
                pass
        value = 0
        for m in range(len(take)):
            value += take[m]
        sum_jewel.append(value)
print(max(sum_jewel))

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

int main() {
	int K, S;
	cin >> K >> S;
	int X, Y, a=0, b;
	for(X=0; X<=K; ++X)
	{
	    b=S-X;
	    for(Y=0; Y<=K; ++Y) if(b>=Y && b-Y<=K) ++a;
	}
	cout << a << endl;
	return 0;
}


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

double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;

bool isOverlap() {
  // x, y に関して大きいほうが小さい方より大きい
  if( min( xa1, xa2) <= max( xb1, xb2 ) && min( xb1, xb2 ) <= max( xa1, xa2 ) ) {
    if( min( ya1, ya2 ) <= max( yb1, yb2 ) && min( yb1, yb2 ) <= max( ya1, ya2 )) return true;
  }
  return false;
}

int main() {

  while( cin >> xa1 >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2  ) {
    if( isOverlap() ) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  
  return 0;
}

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


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

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight=1) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool augment(const Graph& g, int u,
    vector<int>& matchTo, vector<bool>& visited) {
  if (u < 0) return true;
  FOR(e, g[u]) if (!visited[e->dst]) {
    visited[e->dst] = true;
    if (augment(g, matchTo[e->dst], matchTo, visited)) {
      matchTo[e->src] = e->dst;
      matchTo[e->dst] = e->src;
      return true;
    }
  }
  return false;
}
int bipartiteMatching(const Graph& g, int L) {
  const int n = g.size();
  vector<int> matchTo(n, -1);
  int match = 0;
  REP(u, L) {
    vector<bool> visited(n);
    if (augment(g, u, matchTo, visited)) ++match;
  }
  return match;
}

int main(){
	int n,m;
	while( cin >> n >> m and n){
		Graph g(n+m);
		int A[510],B[510];
		for(int i = 0 ; i < n ; i++) cin >> A[i];
		for(int i = 0 ; i < m ; i++) cin >> B[i];
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < m ; j++)
				if( __gcd(A[i],B[j]) != 1 )
					g[i].push_back(Edge(i,n+j)),
					g[n+j].push_back(Edge(n+j,i));

		cout << bipartiteMatching(g,n) << endl;
	}
}

Measured memory_bytes: 7216
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(true){
			int n = sc.nextInt();
			if(n == 0) break;

			Fraction[] f = new Fraction[n];

			for(int i=0;i<n;i++){
				f[i] = new Fraction(sc.nextLong(),sc.nextLong());
				long g = f[i].gcd(f[i].p,f[i].q);
				f[i].p /= g;
				f[i].q /= g;
			}

			Fraction fl = f[0];
			for(int i=1;i<n;i++) fl = fl.flcm(f[i]);
			for(int i=0;i<n;i++) System.out.println(fl.p * f[i].q / fl.q / f[i].p);
		}
	}
}

class Fraction{
	long p,q;

	Fraction(long p,long q){
		this.p = p;
		this.q = q;
	}

	long gcd(long a,long b){
		return b == 0 ? a : gcd(b,a%b);
	}

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

	Fraction flcm(Fraction f){
		Fraction res = new Fraction(lcm(this.p * f.q, f.p * this.q), this.q * f.q);

		long g = gcd(res.p, res.q);
		res.p /= g;
		res.q /= g;

		return res;
	}
}

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

def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    l = [0]*X*Y
    for i in range(X):
        for j in range(Y):
            l[i+j*X] = A[i]+B[j]

    l.sort(reverse=True)
    t = min(3000,X*Y)
    l = l[:t]

    ans = [0] * (t) * Z
    for i in range(t):
        for j in range(Z):
            ans[i+j*t] = l[i] + C[j]

    ans.sort(reverse=True)
    for i in range(K):
        print(ans[i])


    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(X) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(Y) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(Z) ]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 115164
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        
        if(a<b && b<c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26232
sx, sy, tx, ty = map(int, input().split())

ans = (tx-sx)*'R' + (ty-sy)*'U' + (tx-sx)*'L' + (ty-sy+1)*'D' + (tx-sx+1)*'R' + (ty-sy+1)*'U' + 'LU' + (tx-sx+1)*'L' + (ty-sy+1)*'D' + 'R'

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long


signed main(){
	
	int a,b,c;cin>>a>>b>>c;
	
	if(a%2==0 || b%2==0 || c%2==0) cout << 0 <<endl;
	else
	{
		int ans = min(a*b,b*c);
		ans = min(ans,c*a);
		cout << ans << endl;
	}
}

//cout << ans << endl;

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,w,h) rep(j,h)rep(i,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> a(n);rep(i,n)std::cin >> a[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
    string s,ss;
    std::cin >> ss>>s;
    int ans=0;
    rep(i,3){
        if(ss[i]==s[i])
        ans++;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(n):
  ans += b[a[i]-1]
  if i <= n-2:
    if a[i] == a[i+1] - 1:
      ans += c[a[i]-1]
print(ans)

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int a[3]; repp(i,0,3) cin >> a[i];
	sort(a,a+3);
	cout << a[0]*a[1]/2 << endl;
	return 0;
}


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

using namespace std;

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

  int n; 
  double t, a, h, dist, curr=1e9;
  cin >> n >> t >> a;
  int besti = 0;
  for (int i = 0; i < n; ++i) {
    cin >> h;
    dist = abs(a-t+h*0.006);
    if (dist < curr) {
      curr = dist; 
      besti = i;
    }
  }
  cout << besti+1 << endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
int A[14];
int main(){
	cin >> N;
	int ret = 1,al = 1;
	for(int i=0;i<N;i++){
		cin >> A[i];
		if(A[i]%2==0)ret*=2;
		al*=3;
	}
	cout << al-ret << endl;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h = list(map(int, input().split()))
H = sorted(h, reverse = True)
A = 0
for i in range(N):
  if K > 0:
    if H[i] > N:
      H[i] -= N
    else:
      H[i] = 0
    K -= 1
  else:
    A += H[i]
print(A)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
  ll a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if (a1 + a2 + a3 >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  return 0;
}

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

ll n, m, k;

int root(int x, vector<int> &par)
{
    if(par[x]==x)return x;
    else return par[x]=root(par[x], par);
}

void unite(int x, int y, vector<int> &par, vector<int> &sizet)
{
    x=root(x,par);
    y=root(y,par);
    if(x==y)return;
    else if(x<y){par[y]=x;sizet[x]+=sizet[y];}
    else {par[x]=y;sizet[y]+=sizet[x];}
}

int main(){
    cin >> n >> m >> k;
    vector<int> uf(n+1);
    vector<int> sizet(n+1,1);
    FOR(i,1,n+1)
    {
        uf[i]=i;
    }
    vector<set<int>> fri(n+1);
    vector<set<int>> bl(n+1);
    REP(i,m)
    {
        int a,b;
        cin >> a >> b;
        fri[a].insert(b);
        fri[b].insert(a);
        unite(a,b,uf, sizet);
    }
    FOR(i,1,n+1){int p=root(i,uf);sizet[i]=sizet[p];}
    REP(i,k)
    {
        int c,d;
        cin >> c >> d;
        bl[c].insert(d);
        bl[d].insert(c);
    }
    FOR(i,1,n+1)
    {
        int ans=sizet[i]-fri[i].size()-1;
        if(!bl[i].empty())
        {
            for(auto it:bl[i])
            {
                if(uf[i]==uf[it])
                {
                    ans--;
                }
            }
        }
        cout << ans << " ";
    }
    return 0;
}

Measured memory_bytes: 29696
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define VI vector<int>
#define LL long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
using namespace std;
int n, a, b;
int main(){
	scanf("%d %d %d", &n, &a, &b);
	if(abs(a - b) % 2 == 0) printf("Alice\n"); else printf("Borys\n");
	return 0;
}

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

using namespace std;
#define ll long long
const int mod=998244353;
int a[200];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        for(int j=0;j<=100;j++)
            a[j]+=(x-j)*(x-j);
    }
    int mn=2e9;
    for(int i=0;i<=100;i++)
        mn=min(mn,a[i]);
    cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input());
G=[[0 for i in range(n)]for j in range(n)]
for i in range(n):
    list=[int(m) for m in input().split()]
    u=list[0]
    k=list[1]
    for j in range(2,len(list)):
        v=list[j]
        G[u-1][v-1]=1
for i in range(n):
    for j in range(n):
        if j!=n-1:
            print(G[i][j],end=" ")
        else:
            print(G[i][j],end="\n")



Measured memory_bytes: 6392
/*************************************************************
191022-001_cpp_ABC045B
AtCorer問題を解いてC++を学習する
c++学習

＜情報＞
独自　基本学習

*************************************************************/
#include<iostream>
#include<string>
using namespace std;
int main(int argc, char const *argv[])
{
	string S[3];
	cin >> S[0] >> S[1] >> S[2];

	int turn = 0;

	while(true)
	{
		if(S[turn].size()==0)
		{
			break;
		}
		string &ss = S[turn];
		turn = int(ss[0] - 'a');
		ss = ss.substr(1, ss.size() - 1);
	}

	cout << char('A' + turn) << endl;

	return 0;
}



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

int main(){
	string str;
	int q, l;
	deque<char> de;
	deque<char> :: iterator it;
	cin >> str >> q;
	l = str.size();
	for(int i = 0; i < l; i++)
		de.push_back(str[i]);
	bool f = false;
	int t, c;
	char s;
	for(int i = 0; i < q; i++){
		scanf("%d",&t);
		if(t == 1) f = !f;	//直接记录翻转 
		else if(t == 2){
			scanf("%d %c", &c, &s);
			if(!f){		//如果没翻转，或者又翻转回来了 
				if(c == 1) de.push_front(s);
				else if(c == 2) de.push_back(s);
			}
			else {
				if(c == 2) de.push_front(s);
				else if(c == 1) de.push_back(s);				
			}
		}
	}
	if(!f){
		for(it = de.begin(); it != de.end(); it++)
			printf("%c", *it);		
	}
	else{	//注意-1 
		for(it = de.end() - 1; it != de.begin() - 1; it--)
			printf("%c", *it);			
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		int p = sc.nextInt();
		int[] a = new int[(int)n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		boolean odd = true;
		for(int i = 0 ; i < n ; i++) {
			if(a[i] % 2 != 0) odd  = false;
		}
		if(odd) {
			System.out.println(p == 0 ? 1L<<n : 0);
		} else {
			System.out.println(1L<<(n - 1));
		}
	}
}


Measured memory_bytes: 23252
from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    n = cino()
    t = cina()
    ans = sum(t)
    k = cino()
    for i in range(k):
      a,b = cin()
      print(ans+(b-t[a-1]))
      


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import queue
from collections import deque
h,w = map(int,input().split())

#aij = [input() for i in range(h)]

moji = [[0 for i in range(w)] for j in range(h)]

dist = [[-1]*w for _ in range(h)]

for i in range(h):
    aij = input()
    #print(aij)
    for j in range(w):
        moji[i][j] = aij[j]

#moji = aij
#print(moji,aij)
#exit()

#print(aij)
vx = [0,1,0,-1]
vy = [1,0,-1,0]

ans = 0
q = deque()

for i in range(h*w):
    y = i//w
    x = i%w
    #print(i)
    if moji[y][x] == '#':
        q.append(i)
        dist[y][x] = 0

#ans = -1

ans = 0

while q:
    #print(q.qsize())
    tmp = q.popleft()
    y = tmp//w
    x = tmp%w
    d = dist[y][x]
    #print(tmp,num)
    for j in range(4):
        nx = x+vx[j]
        ny = y+vy[j]
        #print(ny,nx)
        if nx < 0 or nx >= w or ny < 0 or ny >= h:
            continue
        if dist[ny][nx] == -1:
            dist[ny][nx] = d+1
            #moji[ny][nx] = '#'
            q.append(ny*w+nx)
    #ans += 1
    ans = max(d,ans)

print(ans)


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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N){
    cin >> a[i];
  }
  int maxa=0, maxi = -1;
  REP(i, N){
    if(abs(maxa) <= abs(a[i])){
      maxa = a[i];
      maxi = i;
    }
  }
  vector<pair<int, int>> ans;
  REP(i, N){
    if(maxi == i) continue;
    ans.push_back({maxi, i});
  }
  if(a[maxi] < 0){
    REPR(i, N-2){
      ans.push_back({i+1, i});
    }
  }
  else{
    REP(i, N-1){
      ans.push_back({i, i+1});
    }
  }
  cout << (int)ans.size() << endl;
  REP(i, (int)ans.size()){
    cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
  }
  return 0;
}


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

using namespace std;

int main() {

  int N, A[100005];

  fill(A, A+100005, 0);

  cin>>N;
  for(int i=0; i<N; i++){
    int a;
    cin>>a;
    A[a]++;
  }

  int odd = 0, eve = 0;
  for(int i = 0; i<100005; i++){
    if(A[i] == 0) continue;
    if(A[i] % 2 == 0) eve++;
    else odd++;
  }

  cout<<odd + (eve/2)*2 <<endl;

  return 0;
}


Measured memory_bytes: 640
import sys

def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())

n, m = ISI()
l = ILI()
cnt = 0
s = sum(l)
for a in l:
	if a >= s/(4*m): cnt +=1
if cnt<m:print("No")
else:print("Yes")

Measured memory_bytes: 9120
#include <stdio.h>

int main(void)
{
	int w, n, line[30], a, b, t, i;
	
	scanf("%d %d", &w, &n);
	
	for (i = 0; i < w; i++){
		line[i] = i + 1;
	}
	
	for (i = 0; i < n; i++){
		scanf("%d,%d", &a, &b);
		t = line[a - 1];
		line[a - 1] = line[b - 1];
		line[b - 1] = t;
	}
	
	for (i = 0; i < w; i++){
		printf("%d\n", line[i]);
	}
	
	return (0);
}

Measured memory_bytes: 596
s = gets.chomp

max = 0

doit = ->(str) {
  return if str.empty?
  (str.length).downto(1) do |l|
    next if /[^ACGT]/.match(str[0, l])
    max = l if l > max
  end
  doit.(str[1..-1])
}
doit.(s)

puts max

Measured memory_bytes: 1788