akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
public class Main
{
	public static void main(String[] args) throws IOException
	{
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String s= br.readLine();
	    String t=br.readLine();
	    int count=0;
	    for(int i=0;i<s.length();i++)
	    {
	        if(s.charAt(i)==t.charAt(i)) continue;
	        else count++;
	    }
	   System.out.println(count);

	   }
}


Measured memory_bytes: 36748
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
using namespace std;

typedef long long int ll;

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	if(a > 9 or b > 9)
		cout << -1;
	else
		cout << a*b;
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
 
using namespace std;
#define int long long
 
int n,a[100005],k,f[100005][2];
int F(int i,int ok)
{
	if(f[i][ok]!=-1) return f[i][ok];
	else if(i<a[1])
	{
		return 1-ok;
	}
	else
	{
		int res;
		if(ok==1)
		{
			res=0;
			for(int j=1;j<=n;j++)
			{
				if(i>=a[j])res=max(res,F(i-a[j],0));
				if(res==1) break;
			}
			f[i][ok]=res;
		}
		else
		{
			res=1;
			for(int j=1;j<=n;j++)
			{
				if(i>=a[j])res=min(res,F(i-a[j],1));
				if(res==0) break;
			}
			f[i][ok]=res;
		}
		return res;
	}
}
main()
{
	cin>>n>>k;
	memset(f,-1,sizeof(f));
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	if(F(k,1)) cout<<"First";
	else cout<<"Second";
 
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<int> a(3);
    for(int i = 0; i < 3; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());

    cout << a.at(0) + a.at(1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    string ans = "No";
    if(a <= c && c <= b) ans = "Yes";
    cout << ans << endl;
    return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


int sumJ[111111],sumI[111111];

signed main(){
    int N;
    string S;
    cin>>N>>S;
    rep(i,N){
        sumJ[i+1]=sumJ[i]+(S[i]=='J');
        sumI[i+1]=sumI[i]+(S[i]=='I');
    }

    int base=0;
    rep(i,N){
        if(S[i]=='O')base+=sumJ[i]*(sumI[N]-sumI[i]);
    }

    int ma=0;
    int tmp=0;
    rep(i,N)if(S[i]=='O')tmp+=sumI[N]-sumI[i];
    chmax(ma,base+tmp);
    tmp=0;
    rep(i,N)if(S[i]=='O')tmp+=sumJ[i];
    chmax(ma,base+tmp);

    rep(i,N-1){
        chmax(ma,base+sumJ[i]*(sumI[N]-sumI[i]));
    }

    cout<<ma<<endl;
    return 0;
}

Measured memory_bytes: 4876
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define P pair<int,int>
using namespace std;
const int N=1e4+9;
int n,m,p;
struct Edge{
    int v,w,nxt;
}e[N];
int head[N],tot;
inline void add(int u,int v,int w){
    e[tot]=(Edge){v,w,head[u]};
    head[u]=tot++;
}
int dis[N];
queue<int>q;
bool vis[N];
int cnt[N];
void dfs(int u);
void dijkstra(int s){
    for(int i=1;i<=n;i++)dis[i]=-inf;
    dis[s]=0;q.push(s);vis[s]=1;
    while(!q.empty()){
        int u=q.front();q.pop();vis[u]=0;
        if(cnt[u]>=n){dfs(u);continue;}
        for(int i=head[u],v,w;~i;i=e[i].nxt){
            v=e[i].v,w=e[i].w;
            if(dis[v]<dis[u]+w){
                dis[v]=dis[u]+w;
                if(!vis[v])q.push(v),vis[v]=1,cnt[v]++;
            }
        }
    }
}
bool vv[N];
void dfs(int u){
    vv[u]=1;
    for(int i=head[u],v;~i;i=e[i].nxt){
        v=e[i].v;
        if(vv[v]||cnt[v]>=n)continue;
        cnt[v]=n;
        dfs(v);
    }
    vv[u]=0;
}
int main(){
    cin>>n>>m>>p;
    memset(head,-1,sizeof(head));
    for(int i=1,u,v,w;i<=m;i++){
        cin>>u>>v>>w;add(u,v,w-p);
    }
    dijkstra(1);
    if(cnt[n]>=n)cout<<-1<<endl;
    else cout<<max(dis[n],0)<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  for (int i = 0; i < N; ++i) cin >> d.at(i);
  
  for (int i = 0; i < N-1; ++i) {
    for (int j = i+1; j < N; ++j) {
      if (d.at(i) < d.at(j)) {
        int tmp = d.at(i);
        d.at(i) = d.at(j);
        d.at(j) = tmp;
      }
    }
  }
  
  int count = 1;
  for (int i = 1; i < N; ++i) {
    if (d.at(i-1) <= d.at(i)) continue;
    count++;
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
#include <cstdio>
#include <cmath>
#include <deque>

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, z, w;
	cin >> n >> z >> w;
	vi a(n);
	REP(i, n) cin >> a[i];
	if(n == 1) cout << abs(a[0] - w) << "\n";
	else cout << max(abs(a[n - 2] - a[n - 1]), abs(a[n - 1] - w)) << "\n";
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n , a[N] , dp[N] , k;
int main(){
    scanf("%d%d", &n , &k);
    for(int i = 0 ; i < n ; i++){
        scanf("%d", &a[i]);
    }
    dp[0] = 0;
    //dp[1] = dp[0] + abs(a[0] - a[1]);
    for(int i = 1 ; i < n ; i++){
        dp[i] = 1e9 + 10;
        for(int j = 1; j <= k ; j++)
            if(i >= j)
                dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]) , dp[i]);
    }
    cout<<dp[n - 1];
    return 0;
}

Measured memory_bytes: 1024
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i32 = read(&mut stdin_lock, &mut buf, b'\n');
    println!("{}", n * n * n);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll x, y;
    cin >> x >> y;
    if(x + y <= 1) cout << "Brown" << endl;
    else if(abs(x - y) <= 1) cout << "Brown" << endl;
    else cout << "Alice" << endl;
    return 0;
}

Measured memory_bytes: 256
dict = ["a","b","c","d","e","f","g","h","i","j","k","l","m",\
        "n","o","p","q","r","s","t","u","v","w","x","y","z"]
lsalpha = [1,3,5,7,9,11,15,17,19,21,23,25]

def decode(alpha, beta, code):
    msg = ""
    for chara in code:
        if chara != " ":
            f = dict.index(chara)
            for i in range(26):
                if (alpha*i + beta)%26 == f:
                    dechara = dict[i]
                    break
            msg += dechara
        else:
            msg += " "
    return msg
    
n = int(raw_input())
for roop in range(n):
    code = raw_input()
    for alpha in lsalpha:
        flag = 0
        for beta in range(26):
            msg = decode(alpha, beta, code)
            if msg.count("that") > 0 or msg.count("this") > 0:
                flag = 1
                break
        if flag == 1:
            break
    print msg

Measured memory_bytes: 4268
n, k = (int(x) for x in input().split())
list = list(map(int, input().split()))

list_sum=[0]
for i in range(n):
    list_sum.append(list_sum[i]+list[i])
max_sum = 0
for i in range(n-k+1):
    sum_num = list_sum[i+k]-list_sum[i]
    if sum_num>max_sum:
        max_sum = sum_num
print((max_sum+k)/2)


Measured memory_bytes: 76040
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    lis=[]
    ans=0
    for i in range(n):
        s=input()
        s_c=Counter(s)
        s_ct=tuple(sorted(s_c.items()))
        lis.append(s_ct)
    lis_c=Counter(lis)
    for li in lis_c.items():
        x=li[1]
        if x>=2:
            ans+=x*(x-1)//2
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 78644
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
//#include <iomanip> : 表示桁数, ex) cout << fixed << setprecision(15) << ...
//#include <unordered_set>

#define pi 3.14159265358979323846
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using ld = long double;
using Byte = unsigned char;
using namespace std;

//string ans = "Yes";


ll SetAns() {
	/// input
	int N = 0;
	cin >> N;

	vector<int> a(N);
	rep(i, N) cin >> a[i];
	
	/// main_process
	sort(a.begin(), a.end());
	ll ans = a[N - 1];
	int aMax = N - 2;
	bool isTwice = false;
	rep(i, N - 2) {
		ans += a[aMax];
		if (!isTwice) {
			isTwice = true;
		} else {
			aMax--;
			isTwice = false;
		}
	}
	return ans;
}

int main() {

	cout << SetAns() << endl;
	return 0;
}


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

int main() {

  int p[8];
  int d[8] = { 4, 1, 4, 1, 2, 1, 2, 1 };

  while ( cin >> p[0] >> p[1] >> p[2] >> p[3] >> p[4] >> p[5] >> p[6] >> p[7] ) {

    int ans = -1;
    long long int ans2 = -1;
    int ans3;
    for ( int i = 0; i < 8; i++ ) {

      int k = 0;
      long long int k2 = 0;

      for ( int j = 0; j < 8; j++ ) {

	int x = max( 0, p[j] - d[ (j+i)%8 ] );
	k += x;
	k2 = k2 * 10 + d[ (j+i)%8 ];

      }
      if ( ans == -1 || ans > k || ( ans == k && ans2 > k2 ) ) {
	ans = k;
	ans2 = k2;
	ans3 = i;
      }

    }

    for ( int i = 0; i < 8; i++ ) {

      if ( i > 0 ) cout << " ";
      cout << d[ (i+ans3)%8 ];

    }
    cout << endl;

  }

  return 0;

}

Measured memory_bytes: 1164
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int solve(int N, vector<int>& v)
{
    int counter = 0;

    for (int i = N - 1; i > 1; --i)
    {
        int l = 0;
        int r = i - 1;

        while (l < r)
        {
            if (v[i] < v[l] + v[r])
            {
                counter += r - l;
                --r;
            }
            else
            {
                ++l;
            }
        }
    }

    return counter;
}

int main() {
    fast_io();

    int N = fetch<int>();

    vector<int> v(N);
    for (int i = 0; i < N; ++i)
        v[i] = fetch<int>();

    std::sort(v.begin(), v.end());

    std::cout << solve(N, v) << std::endl;

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    double ans = 0;
    for(int i=0;i<N;i++){
        double a;
        cin >> a;
        ans += 1/a;
    }
    cout << fixed;
    cout << setprecision(10) << 1/ans << endl;
}

Measured memory_bytes: 256
#include"stdio.h"
int main(){
    int H,W,res=1;
    scanf("%d%d",&H,&W);
    char s[51][51];
    for(int i=0;i<H;i++){
        scanf("%s",s[i]);
    }
    for(int i=0;i<H&&res;i++){
        for(int j=0;j<W&&res;j++){
            if(s[i][j]=='#'){
                if(s[i-1][j]=='#'||s[i+1][j]=='#'||s[i][j-1]=='#'||s[i][j+1]=='#'){
                    continue;
                }else{
                    res=0;
                }
            }
        }
    }
    if(res) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 1704
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
      	int[] H = new int[N];
      	int max = 1;
      	int cnt = 0;
      
      	for (int i = 0 ; i < N ; i++) {
          H[i] = Integer.parseInt(sc.next());
          if (H[i] >= max) {
            cnt++;
            max = H[i];
          }
        }
        System.out.println(cnt);
    }
}


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

int main() {
    /*
cout<<"Hello World"<<endl;

    int x;
    cin>> x;
    cout<< x*x*x <<endl;

int a;
int b;
cin>>a>>b;
cout<<a*b<<" "<<2*a+2*b<<endl;

    int a;
    int b;
    cin>>a>>b;
    if (a<b){
        cout<< "a < b" <<endl;
    }else if(a>b){
        cout<<"a > b" <<endl;
    }else if(a==b){
        cout<<"a == b"<<endl;
    }else{

    }
    int a;
    int b;
    int c;
    cin>>a>>b>>c;
    if (a<b&&b<c){
        cout<<"Yes"<<endl;
    }else {
        cout<<"No"<<endl;
    }

    int a;
    int b;
    int c;
    int d;
    cin>>a>>b>>c;
    if(a>b){
    d=b;
    b=a;
    a=d;
    }
    if(b>c){
    d=c;
    c=b;
    b=d;
    }
    if(a>b){
    d=b;
    b=a;
    a=d;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;

    int W;
    int H;
    int x;
    int y;
    int r;
    int f1;
    int f2;
    int f3;
    int f4;
    cin>>W>>H>>x>>y>>r;

    bool t = false;

    if (x-r>=0){
        if(t) cout<<"1Yes"<<endl;
        f1=1;
    }else if (x-r<0){
        if(t) cout<<"1No"<<endl;
        f1=0;
    }
    if (y+r<=H){
        if(t) cout<<"2Yes"<<endl;
        f2=1;
    }else if (y+r>H){
        if(t) cout<<"2No"<<endl;
        f2=0;
    }
    if (x+r<=W){
        if(t) cout<<"3Yes"<<endl;
        f3=1;
    }else if (x+r>W){
        if(t) cout<<"3No"<<endl;
        f3=0;
    }
    if (y-r>=0){
        if(t) cout<<"4Yes"<<endl;
        f4=1;
    }else if (y-r<0){
        if(t) cout<<"4No"<<endl;
        f4=0;
    }
    if (f1==1&&f2==1&&f3==1&&f3==1&&f4==1){
        cout<<"Yes"<<endl;
    }else {
        cout<<"No"<<endl;
    }

    int i;

    for (i=1;i<=1000;i++){
        cout<<"Hello World"<<endl;
    }
*/
	int x;
	int y;
	//int a[10];
	//int b[10];
	while (1){
		cin>>x>>y;
		if(x==0&&y==0){
			break;
		}
		else if(x<y){
			cout<<x<<" "<<y<<endl;
		}else{
			cout<<y<<" "<<x<<endl;
		}

	}



	/*
	int a[10];

	for(int i=0; i<10;i++){
		a[i]=0;
	}
	for(int i=0; i<10;i++){
		cout<<a[i]<<endl;
	}

*/





    return 0;
}

Measured memory_bytes: 1156
if __name__ == '__main__':
    N, T = map(int, input().split())
    ts = map(int, input().split())

    ans = 0
    last = -1
    for t in ts:
        s = t + T - 1
        if t <= last:
            ans -= last - t + 1
        ans += T
        last = max(last, s)

    print(ans)


Measured memory_bytes: 82304
#include<stdio.h>
int p(int a){
    return a/2;
}
 
int left(int a){
    return 2*a;
}
 
int right(int a){
    return (2*a)+1;
}

int main(){
  int x[2000000],y,i,j,n;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&x[i]);
  }
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,x[i]);
    if(p(i)>=1){
      printf("parent key = %d, ",x[p(i)]);
    }
    if(left(i)<=n){
      printf("left key = %d, ",x[left(i)]);
    }
    if(right(i)<=n){
      printf("right key = %d, ",x[right(i)]);
    }
    //   if(i==n)break;
    printf("\n");
  }
    return 0;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
struct Edge{
	int nxt,to;
}e[200050];
int n,m,cnt,col[100050],fir[100050];
long long ans=0;
bool flag=0;
void add(int from,int to){
	e[++cnt].nxt=fir[from];
	fir[from]=cnt;e[cnt].to=to;
}
void dfs(int x,int fa,int now){
	col[x]=now;
	for(int i=fir[x];i!=-1;i=e[i].nxt){
		int y=e[i].to;
		if(y==fa) continue;
		if(flag) return;
		if(col[y]==-1){
			dfs(y,x,now^1);
		}
		if(col[y]==col[x]){
			flag=1;
			return;
		}
	}
}
int main(){
	cin>>n>>m;
	memset(fir,-1,sizeof(fir));
	memset(col,-1,sizeof(col));
	int x,y;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	dfs(1,0,0);
	int A=0,B=0;
	if(flag==0){
		for(int i=1;i<=n;i++){
			if(col[i]==1) A++;
			else B++;
		}
		cout<<(long long)A*B-m;
	}
	else{
		printf("%lld\n",(long long)n*(n-1)/2-m);
	}
	return 0;
} 

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
struct edge { int to, cost; };
vector< edge > nex[114514];
int par[20][114514];
int depth[114514];
int dist[114514];
int n;
void lcadfs(int v,int p,int d){
	par[0][v] = p;
	depth[v] = d;
	for(int i=0;i<nex[v].size();i++){
		if( nex[v][i].to != p ) lcadfs( nex[v][i].to, v, d+1 );
	}
}
int lca(int u,int v){
	if(depth[u] > depth[v]) swap(u,v);
	for(int k=0;k<=17;k++){
		if( ( (depth[v] - depth[u] ) >> k ) & 1 ){
			v = par[k][v];
		}
	}
	if( u == v )return u;
	for(int k=17;k>=0;k--){
		if( par[k][u] != par[k][v] ){
			u = par[k][u];
			v = par[k][v];
		}
	}
	return par[0][u];
}
void init(int n){
	lcadfs(1,0,0);
	for(int k=0;k<=17;k++){
		for(int v=1;v<=n;v++){
			if( par[k][v] <= 0 )par[k+1][v]=0;
			par[k+1][v] = par[k][par[k][v]];
		}
	}
}
signed main(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b,c;
		cin>>a>>b>>c;
		nex[a].pb( (edge){ b, c} );
		nex[b].pb( (edge){ a, c} );
	}
	init(n);
	queue< pair<int,int> > que;
	que.push(mp(1,-1));
	while( !que.empty() ){
		int cur = que.front().first;
		int par = que.front().second; 
		que.pop();
		for(int i=0;i<nex[cur].size();i++){
			int nx = nex[cur][i].to;
			if( nx != par ){
				dist[nx] = dist[cur] + nex[cur][i].cost;
				que.push( mp( nx, cur ) );
			}
		}
	}
	int q,k;
	cin>>q>>k;
	vector<int> ans;
	for(int i=0;i<q;i++){
		int x,y;
		cin>>x>>y;
		int d1 = dist[x] + dist[k] - 2 * dist[lca(x,k)];
		int d2 = dist[y] + dist[k] - 2 * dist[lca(y,k)];
		ans.pb(d1+d2);
	}
	for(int i=0;i<q;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 35828
#include <bits/stdc++.h>  
 
using namespace std;
 
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main() {
	int N;
	scanf("%d", &N);
	rep(i, N) {
		double x1, y1, x2, y2, x3, y3;
		scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);     
		double a = 2 * (x2 - x1);
	    double b = 2 * (y2 - y1);
	    double c = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
	    double d = 2 * (x3 - x2);
	    double e = 2 * (y3 - y2);
	    double f = x2 * x2 - x3 * x3 + y2 * y2 - y3 * y3;
	          
	    double p = (b * f - c * e)/(a * e - d * b);
	    double q = (a * f - c * d)/(b * d - a * e);
		double r1 = sqrt( pow( p - x1, 2 ) + pow( q - y1, 2 ) );
        double r2 = sqrt( pow( p - x2, 2 ) + pow( q - y2, 2 ) );
        double r3 = sqrt( pow( p - x3, 2 ) + pow( q - y3, 2 ) );
        double r = ( r1 + r2 + r3 ) / 3.0;
		printf("%.3f %.3f %.3f\n", p, q, r);
	}
	return 0;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
signed main(){
  string a;
  int b=0,c,d;
  cin>>a;
  for(int i=0;i<4;i++){
    if(a[i]==a[i+1]){
      b=1;
    }
  }
  if(b==1){
    cout<<"Bad"<<"\n";
  }
  else{
    cout<<"Good"<<"\n";
  }
  
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)
 
int main() {

string S,T;
cin>>S>>T;
int a;
a=S.size();
int count=a;

for(int i=0;i<a;i++){
    if(S.at(i)==T.at(i)){
        count--;
    }

}
cout<<count<<endl;

}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
ll calculate(ll a, ll b);
int main()
{	
    ll m,n;
    cin >> m >> n;
    cout << calculate(m,n) << endl;
	return 0;
}

ll calculate(ll a, ll b){
	ll res = 1;
	for(int i=0; (1<<i) <= b ;i++){
		if(b>>i&1) res =(res*a) % MOD;
		a = (a*a) % MOD;
	}
	return res % MOD;
}



Measured memory_bytes: 3096
from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())

maze = [list(input()) for i in range(h)]
ans = [[-1]*w for i in range(h)]

dx=[0,1,0,-1]
dy=[1,0,-1,0]

ans[ch-1][cw-1]=0
def bfs(ans):
  qu = deque([])
  qu.append([cw-1,ch-1])
  while qu:
    zahyou=qu.popleft()
    x=zahyou[0]
    y=zahyou[1]
    count=0
    for i in range(4):
      if 0 <= x+dx[i] < w and 0 <= y+dy[i] < h:
        if maze[y+dy[i]][x+dx[i]]=="." and (ans[y+dy[i]][x+dx[i]]>ans[y][x] or ans[y+dy[i]][x+dx[i]]==-1):
          qu.appendleft([x+dx[i],y+dy[i]])
          ans[y+dy[i]][x+dx[i]] = ans[y][x]
          count+=1
    if count!=4:
      for i in range(x-2,x+3):
        for j in range(y-2,y+3):
          if 0<=i<w and 0<=j<h:
            if maze[j][i]=="." and (ans[j][i]>ans[y][x]+1 or ans[j][i]==-1):
              ans[j][i]=(ans[y][x]+1)
              qu.append([i,j])

bfs(ans)
print(ans[dh-1][dw-1])
  



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

struct Process {
	string name;
	long t;
};

int main()
{
	long n = 0, q = 0, time = 0, u = 0;
	string tu;
	queue<Process> a;

	cin >> n >> q;
	
	for (int i = 0; i < n; i++) {
		cin >> tu >> u;
		a.push(Process{tu, u});
	}

	while (!a.empty()) {
		if (a.front().t > q) {
			time += q;
			a.push(Process{ a.front().name, a.front().t - q });
			a.pop();			
		}
		else {
			time += a.front().t;
			cout << a.front().name << " " << time << endl;
			a.pop();
		}
	}

	return 0;
}

Measured memory_bytes: 6228
#include<bits/stdc++.h>
using namespace std;
string s;
int l;
int main() {
	cin>>s;
	l=s.size();
	for(int i=0; i<l; i++) {
		if(s[i]=='C') {
			for(int j=i+1; j<l; j++) {
				if(s[j]=='F') {
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
      int x1,y1,x2,y2,x3,y3,x4,y4;
      scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
      y3=y2+x2-x1;x3=x2+y1-y2;
      x4=x3+x1-x2;
      y4=y3+y1-y2;
      printf("%d %d %d %d\n",x3,y3,x4,y4);
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
#define int long long

int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}

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

signed main(){
    int a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll x, y;
    cin >> x >> y;
    ll tmp = x, res = 0;
    while(tmp <= y){
        res++;
        tmp *= 2;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vpii vector<pair<int,int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string> 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; }
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }

int bubble_sort(vi a)
{
	int res = 0;
	while (true)
	{
		bool update = false;
		rep(i, sz(a)-1)
		{
			if (a[i] > a[i + 1])
			{
				swap(a[i], a[i + 1]);
				update = true;
				res++;
			}
		}
		if (!update)break;
	}
	return res;
}

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

	int n, m;
	cin >> n >> m;
	if (n == m)co("Yes");
	else co("No");
	return 0;
}


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

#define rep(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fill(x,v) memset(x,v,sizeof(x))
#define all(x) (x).begin(), (x).end()
#define trace(x) cerr << #x <<": " << x << endl

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef long double C;

vi a;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    a.resize(n+1);
    rep(i,0,n+1){
        cin >> a[i];
    }
    ll rpta = 0;
    ll b,aux;
    rep(i,0,n){
        cin >> b;
        aux = min(a[i], b);
        b-=aux;
        rpta+=aux;
        aux = min(a[i+1], b);
        a[i+1]-=aux;
        rpta+=aux;
    }
    cout << rpta << endl;
    return 0;
}

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

using namespace std;
class BIT {
public:
    BIT(int n) : vec {vector<int>(n, 0)} {};
    int sum(int l, int r){
        return sum(r) - sum(l-1);
    }
    void add(int i, int v){
        int idx = i;
        int vs = vec.size();
        while(idx <= vs){
            vec[idx-1] += v;
            idx += idx&(-idx);
        }
    }
    void print(){
        for(auto x : vec){
            cout << x << ' ';
        }
        cout << endl;
    }
private:
    vector<int> vec;
    int sum(int x){
        //cout << "x = " << x << ", ";
        if(!x){
         //   cout << "sum = " << 0 << endl;
            return 0;
        }
        int s = 0;
        while(x){
            s += vec[x-1];
            x = x&(x-1);
        }
        //cout << "sum = " << s << endl;
        return s;
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    auto bit = BIT(n);
    //bit.print();
    int com, x, y;
    for(int i = 0; i < q; ++i){
        cin >> com >> x >> y;
        if(com){
            cout << bit.sum(x, y) << endl;
        } else {
            bit.add(x, y);
            //bit.print();
        }
    }
}

Measured memory_bytes: 1524
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  for(;;){
    int n,q;
    cin >> n >> q;
    if(!n&&!q) return 0;
    vector<pair<pair<int,int>,string> > tape;
    // (a,b] a<y,y<=b
    REP(i,n){
      string era;
      int th,y;
      cin >> era >> th >> y;
      tape.push_back(make_pair(make_pair(y-th,y),era));
    }
    SORT(tape);
    REP(i,q){
      int y;
      cin >> y;
      int j;
      for(j=0;j<tape.size();++j) if(tape[j].first.first<y&&y<=tape[j].first.second) break;
      if(j<tape.size()) cout << tape[j].second << ' ' << y-tape[j].first.first << endl;
      else cout << "Unknown" << endl;
    }
  }
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

int dp[50005];
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int n, m;
   cin >> n >> m;
   vector<int> c(m);
   rep(i, 0, m) cin >> c[i];
   rep(j, 0, 50005) dp[j] = INF;
   dp[0] = 0;
   rep(i, 0, m) {
      rep(j, 0, n + 1) {
         if (j >= c[i]) {
            dp[j] = min(dp[j], dp[j - c[i]] + 1);
         } else {
            dp[j] = dp[j];
         }
      }
   }
   cout << dp[n] << endl;
   return 0;
}


Measured memory_bytes: 3364
#include <iostream>
#include <map>

using namespace std;

map<char, int> step;

void Init()
{
    step['1'] = 0;
    step['2'] = 1;
    step['3'] = 2;
    step['4'] = 0;
    step['6'] = 2;
    step['7'] = 0;
    step['8'] = 1;
    step['9'] = 2;
}

int Solve(string s)
{
    const int N = s.size();
    if (N == 2)
        return 0;

    int cnt1 = 0;  // left -> right
    bool left1 = true;
    int cnt2 = 0;  // right -> left
    bool left2 = false;

    for (int i = 1; i < N; ++i) {
        if (left1) {
            if (step[s[i - 1]] < step[s[i]])
                ++cnt1;
            else
                left1 = false;
        }
        else {
            if (step[s[i]] < step[s[i - 1]])
                ++cnt1;
            else
                left1 = true;
        }
        if (left2) {
            if (step[s[i - 1]] < step[s[i]])
                ++cnt2;
            else
                left2 = false;
        }
        else {
            if (step[s[i]] < step[s[i - 1]])
                ++cnt2;
            else
                left2 = true;
        }
    }

    return min(cnt1, cnt2);
}

int main()
{
    string s;

    Init();

    while (cin >> s) {
        if (s == "#")
            break;

        cout << Solve(s) << '\n';
    }

    return 0;
}

Measured memory_bytes: 1324
#include<bits/stdc++.h>
using namespace std;
 
void change(vector<string> &st, int n)
{
	int a=0,w=0,t=0,r=0;
    for(int i=0;i<n;i++)
    {
      if(st[i]=="AC")
      {
      	a++;
      }
      else if(st[i]=="WA")
      {
      	w++;
      }
      else if(st[i]=="TLE")
      {
      	t++;
      }
      else if(st[i]=="RE")
      {
      	r++;
      }
    }
  	cout<<"AC x "<<a<<endl;
  	cout<<"WA x "<<w<<endl;
  	cout<<"TLE x "<<t<<endl;
  	cout<<"RE x "<<r;
}
 
 
int main()
{
  int n;
  cin>>n;
  vector<string> st;
  string s;
  for(int i=0;i<n;i++)
  {
    cin>>s;
    st.push_back(s);
  }
  change(st,n);
  //cout<<res;
}

Measured memory_bytes: 7420
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<20;



int main(){
    int n;cin >> n;
    vector<int> c(250000);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        c[i]--;
    }
    vector<int> nx(n,-1);
    vector<int> cx(250000,-1);
    for (int i = n-1; i >= 0 ; i--) {
        nx[i] = cx[c[i]];
        cx[c[i]] = i;
    }
    vector<LL> dp(n+1,0);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        if(nx[i]!=-1&&nx[i]!=i+1) dp[nx[i]]=(dp[nx[i]]+dp[i])%mod;
        dp[i+1] = (dp[i+1]+dp[i])%mod;
    }
    cout << dp[n]%mod << endl;
    return 0;
}


Measured memory_bytes: 4608
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s,s0;
    cin>>s;
    if(s.size()==2)cout<<s<<endl;
    if(s.size()==3){
        s0[0]=s[2];
        s[2]=s[0];
        s[0]=s0[0];
        cout<<s<<endl;
    }
}


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

mod = 10**9 + 7
INF = float("inf")

N, K = map(int, input().split())

edges = [[] * N for _ in range(N)]
for _ in range(N - 1):
    # 頂点の番号を0-indexに直す
    a, b = map(lambda x: int(x) - 1, input().split())
    edges[a].append(b)
    edges[b].append(a)

# 0をrootとする
dq = deque([0])

# color[i] = i番目の頂点を塗ることが可能な色の数
# visitedの管理も兼ねている（別にvisited配列を作っても特に問題はない）
# 後述するように負の値が入ることを許しているので、-1や0などで初期化するのはNG
color = [INF] * N
color[0] = K

"""
root = 0 から末端に向かって調べる

子1, 子2, 子3, ...と複数の「未着色」の子がある場合、塗ることが出来る色の数は
K-1, K-2, K-3,... (p==0 の場合)
K-2, K-3, K-4,... (p!=0 の場合)　のようになる

子が十分多い場合、どこかで「0」になるので、ans = 0　となる
故に、色の数が負になっても答えには影響しない
"""

while dq:
    # 親となる頂点
    p = dq.popleft()
    # 親をpとした時の、「未着色」な子の数
    cnt = 0
    for c in edges[p]:
        if color[c] == INF:
            if p == 0:
                color[c] = (K - 1 - cnt) % mod
            else:
                color[c] = (K - 2 - cnt) % mod
            cnt += 1
            dq.append(c)

ans = 1
for i in range(N):
    ans = (ans * color[i]) % mod

print(ans)


Measured memory_bytes: 31276
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
int main()
{
	int a, b;
	cin >> a >> b;
	cout << a*b;
	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////
#define pll pair<ll,ll>

char S[201010];

ll i,wn,ans;
int main(){
    scanf("%s",S);
    for (i = 0; S[i] != '\0';i++)
        ;
    for (i--; i >= 0;i--){
        if(S[i]=='W'){
            wn++;
        }else{
            ans += wn;
        }
    }
    printf("%lld", ans);
    return 0;
}

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

class Main
{

	public static void main(String[] args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str;
		while((str=br.readLine())!=null)
		{
			StringBuilder sb =new StringBuilder();
			for(int i=str.length()-1;i>=0;i--)
			{
				sb.append(str.substring(i, i+1));
			}
			System.out.println(sb);

		}
	}
}

Measured memory_bytes: 23792
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
int main(){
    long long  N,K;cin>>N>>K;
    long long ans=0;
    for(long long i=K;i<=N+1;i++){
        long long mi,ma;
        mi=(i-1)*i/2;
        ma=(N+(N-i+1))*i/2;
        //cout<<ma<<" "<<mi<<endl;
        //cout<<ma-mi<<endl;
        ans+=ma-mi+1;
        ans%=mod;
        //cout<<ans<<endl;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define inf             LLONG_MAX
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
bool sortbysec(const pair<pair<string,int>,int> &a, 
              const pair<pair<string,int>,int> &b) 
{ 
	if(a.first.first==b.first.first)
		return a.first.second > b.first.second;
    return (a.first.first < b.first.first); 
} 
bool checkValidity(ll a, ll b, ll c) 
{ 
    // check condition 
    if (a + b > c && a + c > b && b + c > a) 
        return false; 
    else
        return true; 
} 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        ll n=s.size(),sum=0;
        for(ll i=0;i<n;i++)
        {
            sum=sum+(s[i]-48);
        }
        if(sum%9==0)
        cout<<"Yes";
        else
        cout<<"No";
    } 
    return 0;
}


Measured memory_bytes: 3780
S = input()
N = len(S)
S1 = S[:N//2]
S2 = S[N//2 + 1:]
if S1 != S2:
    print('No')
    exit()
for i in range(N//4):
    if S1[i] != S1[-i - 1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <string>

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

static const int max_size = 100000;

ll a[max_size];
ll b[max_size];

int main() {
	ll N, H; cin >> N >> H;
	rep(i, 0, N) {
		cin >> a[i] >> b[i];
	}

	sort(a, a + N);
	sort(b, b + N);

	ll a_max = a[N - 1];
	ll count = 0;

	for (int i = N - 1; i >= 0; i--) {
		if (a_max <= b[i] && H > 0) {
			H -= b[i];
			count++;
		}
	}

	if (H > 0) {
		count += ((H - 1) / a_max) + 1;
	}

	cout << count << endl;

	return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int k, x;
    cin >> k >> x;
    yn(500 * k >= x);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using namespace std;
using LL = long long;
// 型に合わせた値 2倍してもオーバーフローしないようにする
// const int INF = 1e9;
const LL INF = 1e10;

LL N, A, B;
vector<LL> h;

bool f(LL K){
    LL tmp = 0;
    for(int i=0; i<N; i++){
        LL rem = h[i]-B*K;
        if(rem > 0) tmp += (rem+(A-B-1)) / (A-B);
    }
    return (tmp <= K);
}

LL binary_search(LL ok, LL ng){
    while (abs(ok - ng) > 1) {
        LL mid = (ok + ng) / 2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
    cin >> N >> A >> B;
    h = vector<LL>(N);     // サイズNを確保
    for(int i=0; i<N; i++) cin >> h[i];
    cout << binary_search(INF, 0) << endl;
}


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

int main(){
int N,Y,i=0,j=0,k=0;
  bool a=false;
  cin >> N >> Y;
  
  int m=0,fs=0,s=0;
  
  while(i<N+1){
    while(j<N-i+1){
      k=N-i-j;
      if(Y==i*1000+j*5000+k*10000){
        a=true;
        break;
      }
        
       j++;
    }
    if(Y==i*1000+j*5000+k*10000){
        break;
      }
     j=0; 
    i++;
  }
  if(a==true)
 cout << k <<' ' <<  j << ' ' << i << endl;
  else
    cout << "-1 -1 -1" << endl;
}



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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

    while (true) {
        int N, M;
        cin >> N >> M;
        if (N == 0 and M == 0) {
            break;
        }

        vector<vector<double>> f(N, vector<double>(N));
        FOR(i, 0, N) {
            FOR(j, 0, N) {
                cin >> f[i][j];
            }
        }

        vector<vector<double>> dp(M + 10, vector<double>(N, 0));
        FOR(j, 0, N) {
            dp[0][j] = 1.0;
        }

        FOR(i, 0, M) {
            FOR(j, 0, N) {
                FOR(k, 0, N) {
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] * f[j][k]);
                }
            }
        }

        double ans = 0.0;
        FOR(j, 0, N) {
            ans = max(ans, dp[M - 1][j]);
        }
        cout << fixed << setprecision(2) << round(ans * 1000) / 1000 << endl;

    }

	return 0;
}


Measured memory_bytes: 3428
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;

void ABC061C()
{
	long long int N, K;
	cin >> N >> K;
	map<int, long long int> vals;

	for (long long int i = 0; i < N; ++i)
	{
		int a, b;
		cin >> a >> b;
		vals[a] += b;
	}
	long long int x = 0;
	for(auto& y : vals)
	{
		x += y.second;
		if (x >= K)
		{
			cout << y.first << endl;
			return;
		}
	}
}

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

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

string z;
int z0 = 0,o0 = 0,ok0 = 0,pre0 = 0;
const int P = 1e9 + 7;
void add(int &a,int b){
  a += b;
  if(a >= P)
    a -= P;
}
bool pas(char ak,int x){
  return ak == '?' || ak == x + '0';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> z;
//  reverse(ALL(z));
  if(pas(z[0], 0))z0 ++;
  if(pas(z[0], 1))o0 ++;
  for(int i = 1; i < SZ(z); i+=2){
    int z1 = 0,o1 = 0,ok1 = 0,pre1 = 0;
    if(pas(z[i], 0) && pas(z[i+1], 0)){
      add(z1, z0);
      add(pre1, pre0);
      add(pre1, o0);
      add(ok1, ok0);
    }
    if(pas(z[i], 0) && pas(z[i+1], 1)){
      add(z1, z0);
      add(o1, pre0);
      add(o1, o0);
      add(ok1, ok0);
    }
    if(pas(z[i], 1) && pas(z[i+1], 0)){
      add(z1, z0);
      add(pre1, pre0);
      add(ok1, o0);
      add(ok1, ok0);
    }
    if(pas(z[i], 1) && pas(z[i+1], 1)){
      add(o1, z0);
      add(o1, pre0);
      add(ok1, o0);
      add(ok1, ok0);
    }
    z0 = z1;
    pre0 = pre1;
    o0 = o1;
    ok0 = ok1;
  }
  add(ok0, o0);
  cout << ok0 << "\n";
}


Measured memory_bytes: 720