akhauriyash/Code-Regression huggingface dataset:
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
 
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
 
using namespace std;
 
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
 
const int N = 300;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    ll ans = -1;
    ll sum = 0;
    rep(i, 0, n) {
        ll d, c;
        cin >> d >> c;
        ans += c;
        sum += d * c;
        ans += sum / 9;
        sum %= 9;
    }
    if (sum == 0) {
        ans--;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N,K;
  cin >> N >> K;
  bool ans[N];
  int res = 0;
  for (int i = 0; i < N; i++) {
    ans[i] = false;
  }
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int t;
      cin >> t;
      ans[t - 1] = true;
    }
  }
  for (int i = 0; i < N; i++) {
    if (!(ans[i])){
      res++;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
pair<int,int> p[4];
int d[100000];
char x[2]={'S','W'};
int main()
{
	int n;
	string s;
	cin>>n;
	cin>>s;
	p[0]=make_pair(0,0);
	p[1]=make_pair(0,1);
	p[2]=make_pair(1,0);
	p[3]=make_pair(1,1);
	for(int i=0;i<4;i++)
	{
		d[0]=p[i].first;
		d[1]=p[i].second;
		for(int i=1;i<n-1;i++)
		{
			if((s[i]=='o'&&d[i]==0)||(s[i]=='x'&&d[i]==1))
			  d[i+1]=d[i-1];
			else
			  d[i+1]=1^d[i-1];
		}
			if((s[n-1]=='o'&&d[n-1]==0)||(s[n-1]=='x'&&d[n-1]==1))
			{
				if(d[0]!=d[n-2])
				  continue;
				else
				{
					if((s[0]=='o'&&d[0]==0)||(s[0]=='x'&&d[0]==1))
					{
						if(d[1]!=d[n-1])
						  continue;
						else
						{
						  for(int i=0;i<n;i++)
					  		cout<<x[d[i]];
						  return 0;	
						}
					}
					else
					{
						if(d[1]==d[n-1])
						  continue;
						else
						{
						  for(int i=0;i<n;i++)
					  		cout<<x[d[i]];
						  return 0;	
						}
					}
				}
			}
			else
			{
				if(d[0]==d[n-2])
				  continue;
				else
				{
					if((s[0]=='o'&&d[0]==0)||(s[0]=='x'&&d[0]==1))
					{
						if(d[1]!=d[n-1])
						  continue;
						else
						{
						  for(int i=0;i<n;i++)
					  		cout<<x[d[i]];
						  return 0;	
						}
					}
					else
					{
						if(d[1]==d[n-1])
						  continue;
						else
						{
						  for(int i=0;i<n;i++)
					  		cout<<x[d[i]];
						  return 0;	
						}
					}
				}
			}
	}
	cout<<-1;
	return 0;
}

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

string S;
int dp[510][510];

bool rec(int l,int r){
    if(dp[l][r]!=-1) return dp[l][r];
    dp[l][r] = 0;
    if(l>r) return dp[l][r] = 1;
    if(S[l]!='m' || S[r]!='w') return dp[l][r] = 0;
    for(int i=l+1;i<r;i++){
        if(S[i]=='e') dp[l][r] = (dp[l][r] | (rec(l+1,i-1) & rec(i+1,r-1)));
    }
    return dp[l][r];
}

int main(){
    cin >> S;
    int N = S.size();
    for(int i=0;i<N;i++) for(int j=0;j<N;j++) dp[i][j] = -1;
    cout << (rec(0,N-1)? "Cat":"Rabbit") << endl;
    /*for(int i=0;i<N;i++){
        for(int j=i;j<N;j++) cerr << dp[i][j] << " ";
        cerr << endl;
    }*/
}


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

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

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;

int main() {
    int n, m;
    cin >> n >> m;

    vector<double> products(n);
    double sum = 0;
    rep (i, n) {
        cin >> products[i];
        sum += products[i];
        // cout << sum << endl;
    }

    sort(products.begin(), products.end(), greater<int>());
    rep (i, m) {
        if (products[i] < sum / (4 * m))
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
x=int(input())
a=0
while True:
    for b in range(10**3):
        if a**5-b**5==x:
            print(a,b)
            exit()
        elif a**5+b**5==x:
            print(a,-b)
            exit()
        elif -a**5+b**5==x:
            print(-a,-b)
            exit()
    a+=1

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

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

using namespace __gnu_pbds;
using namespace std;

#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define pii pair<int,int>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define nl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main()
{   fastio;

    int n;
    cin>>n;
    if(n%1000 == 0) cout<<0<<endl;
    else
        cout<<1000-(n%1000)<<endl;
}


Measured memory_bytes: 3648
a,b,c,d=map(int,input().split())
if a>b:a,b=b,a
if c>d:c,d=d,c
# # if b>=0 or d>=0:
# 	temp=max(b*d,a*c,a*d,b*c)
# 	if c<=0<=d or a<=0<=b:
# 		print(max(0,temp))
# 	else:
# 		print(temp)
# elif b>0: 	
# 	print(b*d)

# if b==0:
# 	print(0)
# elif b<0:
# 	if c<=0<=d:
# 		print(0)
# 	elif 
temp=max(b*d,a*c,a*d,b*c)
if c<=0<=d or a<=0<=b:
		print(max(0,temp))
else:
	print(temp)
		

Measured memory_bytes: 9172
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	int a,b;
	cin >> a>>b;
	printf("%d %d %.6f", a / b, a % b, (double(a) / b));
	//cout << a / b << " " << a % b << " " << (double(a) / b) << endl;
	return 0;
}



Measured memory_bytes: 3204
#include <stdio.h>
#include <string.h>
#define SMAX 4000
int next0[2][SMAX+2], next1[2][SMAX+2], dp[SMAX+2][SMAX+2];

int dfs(int aloc, int bloc);
void scns(int aloc, int bloc);
int main(void)
{
  int i, alen, blen;
  char a[SMAX+2], b[SMAX+2];
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  a[0] = b[0] = '?';
  alen = strlen(a);
  blen = strlen(b);
  memset(dp, -1, sizeof(dp));
  dp[alen][blen] = 0;
  next0[0][alen] = next1[0][alen] = next0[0][alen-1] = next1[0][alen-1] = alen;
  next0[1][blen] = next1[1][blen] = next0[1][blen-1] = next1[1][blen-1] = blen;
  for (i = alen - 2; i >= 0; i--) {
    if (a[i+1] == '0') {
      next0[0][i] = i + 1;
      next1[0][i] = next1[0][i+1];
    } else {
      next0[0][i] = next0[0][i+1];
      next1[0][i] = i + 1;
    }
  }
  for (i = blen - 2; i >= 0; i--) {
    if (b[i+1] == '0') {
      next0[1][i] = i + 1;
      next1[1][i] = next1[1][i+1];
    } else {
      next0[1][i] = next0[1][i+1];
      next1[1][i] = i + 1;                                                                                                  }
  }
  scns(0, 0);
  putchar_unlocked('\n');
}

int dfs(int aloc, int bloc)
{
  int res, ans = SMAX + 2;
  if (dp[aloc][bloc] != -1) return dp[aloc][bloc];
  res = dfs(next0[0][aloc], next0[1][bloc]);
  if (ans > res) ans = res;
  res = dfs(next1[0][aloc], next1[1][bloc]);
  if (ans > res) ans = res;
  return dp[aloc][bloc] = ans + 1;
}

void scns(int aloc, int bloc)
{
  if (dfs(aloc, bloc) == dfs(next0[0][aloc], next0[1][bloc]) + 1) {
    putchar_unlocked('0');
    scns(next0[0][aloc], next0[1][bloc]);
  } else if (dfs(aloc, bloc) == dfs(next1[0][aloc], next1[1][bloc]) + 1) {
    putchar_unlocked('1');
    scns(next1[0][aloc], next1[1][bloc]);
  }
}


Measured memory_bytes: 64468
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;
  cin>>s>>t;
  int a=0;

  if(s[0]==t[0])
      a++;
   if (s[1]==t[1])
      a++;
    if(s[2]==t[2])
      a++;
      

  cout<<a;
  return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  
  if(N==1){
    int a;
    cin >> a;
    cout << a << endl;
  }
  
 else{
  vector<int> vec(N);
  
  for(int i=0; i<N; i++){
   cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  long sum = 0; 
   for(int i=0; i<K; i++){
     sum = sum + vec.at(i);
   }
  
  cout << sum << endl;
 }
   
  return 0;
}


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

int main() {
	int n, m;
	cin>>n>>m;
	vector<int> A(m);
	int sum=0;
	for(int i=0;i<m;i++)
	{
		cin>>A[i];
		sum+=A[i];
	}
	if(sum>n)
	cout<<"-1\n";
	else
	cout<<n-sum<<endl;
}

Measured memory_bytes: 3640
import scala.io.StdIn.{readInt,readLine}

object Main {
  def calc(n:Int):Int = {
    val op = readLine
    op match {
      case "+" => calc(n+readInt)
      case "-" => calc(n-readInt)
      case "*" => calc(n*readInt)
      case "/" => calc(n/readInt)
      case _ => n
    }
  }

  def main(args:Array[String]) = println(calc(readInt))
}

Measured memory_bytes: 43648
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pd(x) cerr<<"//"<<(x)<<endl;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,l,q;
ll x[500005],y[500005],z[500005];
bool dp[205][205];
char s[500005];
bool flag,dame;

ll  fact[400005];
ll rfact[400005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<400000; i++){
        fact[i] = (fact[i-1]*i) % mod;
        rfact[i] = rui(fact[i],mod - 2);
    }
}
ll ncr(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;
}

int main(){
	cin >> a >> b >> c >> d >> e >> k;
	if(e - a > k){
		p(":(");
	}else{
		p("Yay!");
	}
	return 0;
}

Measured memory_bytes: 23808
#include <stdio.h>
#include <math.h>
#define PI 3.1415926535897932386

double getArea(double a, double b, double rad){
	return a*b*sin(rad)/2;
}

double getcl(double a, double b, double rad){
	return sqrt(a*a + b*b -2*a*b*cos(rad));
}

int main(void){
	double a,b,c,C,L,S,h,rad;
	int deg;
	scanf("%lf %lf %d", &a, &b, &deg);
	rad = deg*PI/180;
	S = getArea(a, b, rad);
	c = getcl(a, b, rad);
	L = a + b + c;
	h = 2*S/a;
	
	printf("%.4f\n%.4f\n%.4f\n", S, L, h);
	
	return 0;
}

Measured memory_bytes: 704
#include <stdio.h>
#include <vector>
#include <utility>

int main() {
    int n; scanf("%d", &n);

    int latte = n + 1 - n % 2;
    std::vector<std::pair<int, int>> edges;
    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            if(i + j == latte) continue;
            edges.push_back({i, j});
        }
    }

    printf("%d\n", edges.size());
    for(auto e: edges) printf("%d %d\n", e.first, e.second);
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> vec;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        vec.push_back(a);
    }

    sort(vec.begin(), vec.end());

    int m = n / 2;
    int ans = vec[m] - vec[m-1]; 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
fun readInts() = readLine()!!.split(' ').map(String::toInt)

fun <T> Iterable<T>.groupingCount(): Map<T, Int> {
    val map = mutableMapOf<T, Int>()
    for (element in this) {
        map[element] = map.getOrElse(element) { 0 } + 1
    }
    return map
}

fun main(args: Array<String>) {
    val (n, k) = readInts()
    val aa = readInts().groupingCount()
    if (aa.size <= k) {
        println(0)
        return
    }
    println(aa.toList()
        .sortedBy(Pair<Int, Int>::second)
        .subList(0, aa.size - k)
        .sumBy(Pair<Int, Int>::second))
}


Measured memory_bytes: 80776
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

hoge = {i: t[i::k] for i in range(k)}
score_map = {"r": p, "s": r, "p": s}

ans = 0
for i in range(k):
  prev_hand = None
  for hand in hoge[i]:
    if hand != prev_hand:
      ans += score_map[hand]
      prev_hand = hand 
    else:
      prev_hand = None

print(ans)

Measured memory_bytes: 20072
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
	if (a > b) swap(a, b);
	while (a != 0) tie(a, b) = make_pair(b%a, a);
	return b;
}
int main() {
	int N;
	vector<int> can; can.clear();
	unordered_map<int, int> m; m.clear();
	cin >> N;
	for(int i = 0, ai; i < N; i++) {
		cin >> ai;
		m[ai]++;
	}
	int pre = 0;
	for (const auto &it: m) {
		if (it.second >= 2) pre = gcd(pre, it.first);
		else can.push_back(it.first);
	}
	int ans = 1, tmp;
	sort(can.begin(), can.end());
	for (const int &t: can) {
		tmp = pre;
		for (const int &i: can) {
			if (i == t) continue;
			tmp = gcd(tmp, i);
			if (tmp <= ans) break;
		}
		ans = max(ans, tmp);
	}
	if (can.empty()) ans = pre;
	cout << ans << endl;
  	assert(can.size()<=1e4);
	return 0;
}


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

typedef long long ll;

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

	string a, b;
	cin >> a >> b;
	int count = 0;
	for (int i = 0; i < (int) a.size(); i++) {
		if (a[i] != b[i]) {
			count++;
		}
	}
	cout << count;
}


Measured memory_bytes: 3828
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <queue>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<PII,char> PIIC;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second
#define DEBUG(X) { cout << #X << " = " << (X) << endl; }

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define FOREACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)

#define MOD 1000000007
#define INF 2000000000

int GI(LL& x) { return scanf("%lld", &x); }

int main() {
    char test;
    cin >> test;
    if (test == 'a' || test == 'e' || test == 'i' || test == 'o' || test == 'u') printf("vowel\n");
    else printf("consonant\n");

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#include<vector>
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define ub upper_bound
using namespace std;

int main(){
	string s;
	cin>>s;
	int a=0,b=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='A')
		a++;
		else
		b++;
	}
	if(a==s.length() || b==s.length()){
		cout<<"No";
}
else
cout<<"Yes";
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 45
int fibonacci(int);
int F[45];
int main(){
  int n,i;
  scanf("%d",&n);
  for(i = 0 ;i < MAX;i++){
    F[i] = -1;
  }
  printf("%d\n",fibonacci(n));
}

int fibonacci(int i){

  if(i == 1 || i == 0) return F[i] = 1;
  else{
    if(F[i] != -1) return F[i];
    return F[i] = fibonacci(i-1) + fibonacci(i-2);
  
  }
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n, a, M = 1e9+7;
    map<int, int> mp;
    cin >> n;
    bool ok = true;
    fore(i,0,n) {
        cin >> a;
        mp[a]++;
        if (n&1) {
            if ((a&1) || (a==0 && mp[a]>1)) ok = false;
        } else {
            if (!(a&1) || a<1) ok = false;
        }
        if (mp[a]>2) ok = false;
    }
    if (ok) {
        n = n/2;
        int ans = 1;
        fore(_,0,n) ans = (ans*2) % M;
        cout << ans << endl;
    } else {
        cout << "0\n";
    }
}


Measured memory_bytes: 3200
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;


int main(){
    ll n,k;
    cin >> n >> k;
    vector<pll> a(n);
    rep(i,n){
        cin >> a[i].fi >> a[i].se;
    }
    ll le=0,ri=INF;
    while(ri-le>1){
        ll mid=(ri+le)/2;
        ll cnt=0;
        rep(i,n){
            if(a[i].fi<mid) cnt+=a[i].se;
        }
        if(cnt<k) le=mid;
        else ri=mid;
    }
    cout << le << endl;
    return 0;
}

Measured memory_bytes: 4816
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = 2*(int)1e5 + 3;

int n, d, x, y, res;

signed main() {
  init_ios();
  cin >> n >> d;
  for (int i = 1; i <= n; ++i) {
    cin >> x >> y;
    if (x*x+y*y <= d*d)
      ++res;
  }
  cout<<res<<"\n";
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int N;
string S;
vector<vector<int> > g;

int dfs(int a, int p, int d) {
	int res = 0;
	for (int i : g[a]) {
		if (i != p) {
			res += dfs(i, a, d + 1);
		}
	}
	if (S[a] == '1') {
		res += d;
	}
	return res;
}



pair<int, int> dfs2(int a, int p, int d) {
	int res = 0;
	pair<int, int> pa;
	vector<int> tot;
	int num = 0;
	int sum = 0;
	int mx = 0;
	for (int i : g[a]) {
		if (i != p) {
			pa = dfs2(i, a, d + 1);
			num += pa.second;
			tot.push_back(pa.first + pa.second);
			sum += pa.first + pa.second;
			mx = max(mx, pa.first + pa.second);
		}
	}

	res = max(sum % 2, 2 * mx - sum);

	if (S[a] == '1') {
		num++;
	}
	return make_pair(res, num);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	cin >> S;
	g.resize(N);
	int a, b;
	for (int i = 0; i < N - 1; i++) {
		cin >> a >> b; a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int INF = (int)1 << 60;
	int res = INF;
	for (int i = 0; i < N; i++) {
		int sum = 0;
		int mx = 0;
		vector<pair<int, int> > vp;
		for (int j : g[i]) {
			int t = dfs(j, i, 1);
			pair<int, int> p = dfs2(j, i, 1);
			sum += t;
			vp.emplace_back(p.first + p.second, t);
		}

		if (sum % 2 == 0) {
			int mx1 = 0;
			int mx2 = 0;

			int mxmn = 0;
			for (int t = 0; t < vp.size(); t++) {
				if (mx1 < vp[t].second) {
					mx2 = mx1;
					mx1 = vp[t].second;
					mxmn = vp[t].first;
				}
				else if (mx2 < vp[t].second) {
					mx2 = vp[t].second;
				}
			}
			bool ok = false;
			if (2 * mx1 <= sum)ok = true;
			else {
				//cerr << mx1 << " " << mx2 << " " << mxmn << endl;
				int n = max(mxmn, mx2 + ((mx1 + mx2) % 2));
				int diff = mx1 - n;

				if (2 * (mx1 - diff) <= (sum - diff) )ok = true;

			}

			if (ok) {
				//cerr << i << endl;
				res = min(res, sum / 2);
			}
		}

	}
	if (res == INF)res = -1;
	cout << res << endl;
}

Measured memory_bytes: 640
def solve(n, k):
    mx = (n - 1) * (n - 2) // 2
    if k > mx:
        print(-1)
        return
    buf = []
    for i in range(2, n + 1):
        buf.append('1 {}'.format(i))

    p = 2
    q = 3
    for _ in range(mx - k):
        buf.append('{} {}'.format(p, q))
        if q >= n:
            p += 1
            q = p + 1
        else:
            q += 1

    print(len(buf))
    print('\n'.join(buf))


n, k = list(map(int, input().split()))
solve(n, k)


Measured memory_bytes: 3444
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		//HashMap<String, Integer> map = new HashMap<>();
		int n = scanner.nextInt();
		List<String> key = new ArrayList<>();  
		List<Integer> value = new ArrayList<>();  
		
		for(int i = 0; i < n; i++) {
			String s = scanner.next();
			if(key.contains(s)) {
				value.set(key.indexOf(s), value.get(key.indexOf(s))+1);
			}else {
				key.add(s);
				value.add(1);
			}
		}
		int m = scanner.nextInt();
		for(int i = 0; i < m; i++) {
			String ss = scanner.next();
			if(key.contains(ss)) {
				value.set(key.indexOf(ss), value.get(key.indexOf(ss))-1);
			}else {
				key.add(ss);
				value.add(-1);
			}
		}
		int s = 0;
		for(int a : value) {
			s =Math.max(s, a);
		}
		System.out.println(s);
		
	}

}

Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <deque>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
const int inf = 1e9+123;
const ll mod = 1e9+7;

void solve()
{
    int a, b;
    cin >> a >> b;
    cout << a*b << '\n';
}

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

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define mem1(x)  memset(x,1,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
 
int32_t main(){
    IOS;
    ll i,j,k;
    ll x,sum=100;
    cin >> x;
    for(i=1;sum<x;i++){
        sum = sum  + sum/100 ; 
    }
    cout << i-1 <<"\n";

} 

Measured memory_bytes: 3664
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n,count=1;
	cin >> n;
	string t;
	vector<string> s;
	s.reserve(n);

	for (int i = 0; i < n; i++) {
		cin >> t;
		s.emplace_back(t);
	}
	sort(s.begin(), s.end());
	
	for (int i=1; i < n; i++) {
		if (s[i - 1] != s[i])
			count++;
	}
	cout << count;
}

Measured memory_bytes: 9604
import java.util.Scanner;

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


Measured memory_bytes: 26168
N = int(input())
now_t, now_x, now_y = 0, 0, 0

for _ in range(N):
  t, x, y = list(map(int, input().split()))
  distance = abs(now_x - x) + abs(now_y - y)
  has_time = t - now_t
  if (distance - has_time) > 0 or (distance - has_time) % 2:
    print("No")
    break
  now_t, now_x, now_y = t, x, y
else:
  print("Yes")
    
  

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(i,arr)       for(int& i:arr)cin>>i;
#define output(i,arr)      for(int& i:arr)cout<<i<<" ";
#define for_each(arr)      for(auto& it:arr)
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    #endif*/
    cin>>s>>s1;
    ans=0;
    for(int i=0;i<3;i++){
    	if(s[i]==s1[i])
    		++ans;
    }
    cout<<ans<<endl;
    

    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 


Measured memory_bytes: 256
def main():
    c = [list(map(int, input().split())) for _ in range(3)]
    s1 = c[0][0] + c[1][1] + c[2][2]
    s2 = c[1][0] + c[2][1] + c[0][2]
    s3 = c[2][0] + c[0][1] + c[1][2]
    s4 = c[0][0] + c[1][2] + c[2][1]
    s5 = c[1][0] + c[2][2] + c[0][1]
    s6 = c[2][0] + c[0][2] + c[1][1]
    
    if s1 == s2 == s3 == s4 == s5 == s6:
        print('Yes')
    else:
        print('No')
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();
            var sum = 0;
            for (int i = 0; i < n.Length; i++)
            {
                sum += int.Parse(n.Substring(i, 1));
            }
            if (int.Parse(n) % sum == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    string Sp, T;
    cin >> Sp >> T;
    int nS = (int)Sp.size();
    int nT = (int)T.size();
    
    for (int St = nS-nT; St >= 0; --St) {
        bool OK = true;
        for (int t = 0; t < nT; ++t) {
            if (Sp[St+t] != '?' && Sp[St+t] != T[t]) {
                OK = false;
                break;
            }
        }
        if (OK) {
            string S = Sp;
            for (int t = 0; t < nT; ++t) {
                S[St+t] = T[t];
            }
            for (int s = 0; s < nS; ++s) {
                if (S[s] == '?') S[s] = 'a';
            }
            cout << S << endl;
            return 0;
        }
    }
    
    cout << "UNRESTORABLE" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
int N;
int ans=lmax;
int go(int A,int B)
{
	int sum=0;
	while(A!=0)
	{
		sum+=A%10;
		A/=10;
	}
	while(B!=0)
	{
		sum+=B%10;
		B/=10;
	}
	return sum;
}
int main(){std::ios::sync_with_stdio(false);
cin>>N;
for(int i=1;i<N;i++)
{
	ans=min(ans,go(i,N-i));
}
cout<<ans<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/





Measured memory_bytes: 256
h, w = map(int,input().split())
s = [input() for j in range(h)]

ans = 'Yes'
 
for i in range(h):
  for j in range(w):
    if s[i][j] == '#':
      flag = False
      
      for k in [-1, 1]:
        if k+i>= 0 and k+i<=h-1 and s[k+i][j] == '#':
          flag = True
          break
        if k+j>= 0 and k+j<=w-1 and s[i][j+k] == "#":
          flag = True
          break
      
      if flag == False:
        ans = 'No'
        break
        
        
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	long long int a, b, k;
	cin >> a >> b >> k;
		if (a+b<=k) {
			a=b=0;
		}
		else if(a>k){
			a-=k;
		}
		else {
			b -= k - a;
			a = 0;
		}
	cout << a <<" "<<b << endl;
}

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

int N, n[21];

int dfs(int suma, int sumb, int k){
    int a, b;
    if(k >= N)   return abs(suma - sumb);
    a = dfs(suma+n[k], sumb, k+1);
    b = dfs(suma, sumb+n[k], k+1);
    return min(a, b);
}

int main(void){
    while(cin >> N){
        if(N==0)    break;
        for(int i=0; i<N; i++){
            cin >> n[i];
        }
        cout << dfs(0, 0, 0) << endl;
    }
    return 0;
}


Measured memory_bytes: 3016
#include<iostream>
#define int long long
using namespace std;
int n;
int p[114514],q[114514];
signed main(){
	cin>>n;
	int i,j;
	for(i=0;i<n;i++)
		cin>>p[i];
	for(i=0;i<n;i++){
		if(p[i]>0){
			q[p[i]-1]++;
			q[p[i]]++;
			q[p[i]+1]++;
		}else{
			q[p[i]]++;
			q[p[i]+1]++;
		}
	}
	int u=0;
	for(i=0;i<100000;i++)
		if(q[u]<q[i])
			u=i;
	cout<<q[u]<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int x = 1;
        int i = 1;
        
        while(true){
            x = sc.nextInt();
            if(x == 0){
                break;
            }
            System.out.println("Case " + (i++) + ": " + x);
        }
    }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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 L;
int A[555555];

signed main(){
    string s;cin>>s;
    reverse(all(s));
    L=s.size();
    rep(i,L)A[i]=s[i]-'0';

    rep(i,L)A[i]*=9;
    rep(i,L+10){
        A[i+1]+=A[i]/10;
        A[i]%=10;
    }

    int sum=0;
    rep(i,555555)sum+=A[i];


    for(int i=0;;i++){
        if(sum<=i&&(i-sum)%9==0){
            cout<<(i+8)/9<<endl;
            return 0;
        }

        for(int j=0;;j++){
            A[j]++;
            sum++;
            if(A[j]!=10)break;
            sum-=10;
            A[j]=0;
        }
    }
    return 0;
}


Measured memory_bytes: 5124
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
 int N;
 string str;
 cin>>N >>str;
 string str1,str2;
 int i,j,ans;
 int cnt;
 ans=0;
 for(i=0;i<N-1;i++){
   str1=str.substr(0,i+1);
   str2=str.substr(i+1,N-i-1);
   cnt=0;
   for(j=97;j<123;j++){
     if((str1.find((char)j)!=-1)&&(str2.find((char)j)!=-1))cnt+=1;
   }
   if(ans<cnt) ans =cnt;
 }
 cout <<ans;
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int a,b,c,d;

int main(){
  cin >> a >> b >> c >> d;
  cout << max(a*b,c*d) << endl;
  
  return 0;
}



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

#define ll long long
#define ull unsigned long long
#define ld long double
#define fo(i,start,end) for(int i=start;start<end?i<end:i>end;start<end?i+=1:i-=1)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vop vector<pll>
#define vov vector<vector<ll>>
using namespace std;
const ld pi=3.14159265358979323;

const long long mod1=1e9+7;
const long long mod2=1e18;
const ll mod3=9e18;
const ll N=1e9+7;

long long power(ll  x, ll n){if(n==0)return 1;ll temp=power(x,n/2);if(n%2==0)return temp*temp;else return x*temp*temp;}

ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return (a*b)/(gcd(a,b));}
void swap(int* a, int* b){int t = *a;*a = *b;*b = t;}
bool f(ll x,ll y){return x>y;}
bool cmp(ll x ,ll y){
    return abs(x)<abs(y);
}
ll MAX(ll a,ll b){return a>b?a:b;}
ll MIN(ll x,ll  y){return x>y?y:x;}

ll pmod(ll a, ll b,ll mod)//a^b%mod
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return ans;
}
int main(){
    ll n,d,count=0,i,x,y;
    cin>>n>>d;
    for(i=0;i<n;i++){
        cin>>x>>y;
        if(abs(sqrt(x*x+y*y))<=d)count++;
    }
    //cout<<v.size()<<endl
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define sc second
#define mp make_pair
#define ps push
#define fr front
typedef pair<int,int> pii;//Be careful in topcoder.

#define MAX_H 50
#define MAX_W 50

string s[MAX_H];
int d[MAX_H][MAX_W];

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

int main(){
	int h,w,ans=0;
	scanf("%d %d",&h,&w);
	for(int x=0;x<h;++x){
		cin>>s[x];
		for(int y=0;y<w;++y) if(s[x][y]=='.') ++ans;
		fill(d[x],d[x]+w,-1);
	}
	d[0][0]=1;
	queue<pair<int,int> > q;
	q.ps(mp(0,0));
	while(!q.empty()){
		int x=q.fr().fi,y=q.fr().sc;
		q.pop();
		for(int k=0;k<4;++k){
			int nx=x+dx[k],ny=y+dy[k];
			if(nx<0||h<=nx||ny<0||w<=ny) continue;
			if(s[nx][ny]=='#') continue;
			if(d[nx][ny]>=0) continue;
			d[nx][ny]=d[x][y]+1;
			if(nx==h-1&&ny==w-1) goto end;
			q.ps(mp(nx,ny));
		}
	}
	printf("-1\n");
	return 0;
end:
	printf("%d\n",ans-d[h-1][w-1]);
	return 0;
}

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

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

    if ((a <= x) && (x <= a+b)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

vector<bool> sieve(int n) {
    vector<bool> prime(n + 1, true);
    prime[0] = prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (prime[i]) {
            for (int j = i * 2; j <= n; j += i) prime[j] = false;
        }
    }
    return prime;
}

int main()
{
    int Q;
    cin >> Q;
    vector<bool> prime = sieve(100000);
    vector<int> count(100001, 0);
    repd(i, 1, prime.size()) {
        if (prime[i] && prime[(i + 1) / 2]) {
            count[i] = count[i - 1] + 1;
        }
        else {
            count[i] = count[i - 1];
        }
    }

    rep(i, Q) {
        int l, r;
        cin >> l >> r;
        cout << count[r] - count[l - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    int n,i;
     scanf("%d ",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        printf("%d",a[n-i-1]);
if(n-i-1 != 0){
printf(" ");
    }
    }
printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
int main(void)
{
	int n, q, i, j, k=0;
	scanf("%d", &n);
	int a[n];
	for(i = 0; i < n; i++)scanf("%d", &a[i]);
	
	scanf("%d", &q);
	int b[q];
	for(j = 0; j < q; j++)scanf("%d", &b[j]);
	
	for(i = 0; i < q; i++){
		for(j = 0; j < n; j++){
			if(a[j] == b[i]){
				k++;
				break;
			}
		}
	}
	
	printf("%d\n", k);
	
	return 0;
}


Measured memory_bytes: 2092
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    int cnt[2] = {};//g p
    for(auto c:S)if(c == 'g')cnt[0]++;else cnt[1]++;
    int p = S.length() / 2,g = S.length() - g;
    cout << p - cnt[1] << endl;
}

Measured memory_bytes: 512
import bisect
MOD = 10**9 + 7
 
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
  
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
n, k = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
bit = Bit(2010 * 2)
ans = 0
 
for i, p in enumerate(a):
    bit.add(p, 1)
    ans += i + 1 - bit.sum(p)
 
a.sort()
big = 0
for item in a:
    big += n - bisect.bisect_right(a, item)
 
times = (k * (k - 1) // 2) % MOD
ans2 = (ans * k) % MOD + (big * times) % MOD
ans2 %= MOD
print(ans2)

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

int main(){
    double L;
    cin >> L;
    cout << fixed << setprecision(12) << pow(L / 3. , 3) << endl;
}

Measured memory_bytes: 4080
fn main() {
    let abc = read_to_vec();
    let k = read_to_vec()[0];
    
    let mut m = 0;
    for n in &abc {
        if m < *n {
            m = *n;
        }
    }
    
    let mut b = true;
    let mut sum = 0;
    for mut n in abc {
        if b && m == n {
            for _ in 0..k {
                n = n * 2;
            }
            sum += n;
            b = false;
        } else {
            sum += n;
        }
    }
    
    println!("{}", sum);
}

fn read_to_vec() -> Vec<u64> {
    use std::io::stdin;
    
    let mut s = String::new();
    stdin().read_line(&mut s);
    
    s.trim().split(" ").map(|t| t.parse().unwrap()).collect()
}

Measured memory_bytes: 4352
// AGC 009 A
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    ll x,y; cin >> x >> y;
    ll ans = abs(abs(x) - abs(y));
    if((x >= 0 && y < 0) || (x < 0 && y > 0)){
        ans+=1;
    }else{
        if(x>y && abs(x) > 0 && abs(y) > 0) ans+=2;
        else if(x > y) ans+=1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int n, k;
    cin >> n >> k;
    vector<double> p(n);
    vector<double> d(n);
    vector<double> r(n);
    rep(i, n){
        cin >> p[i];
        d[i] = (p[i]+1) / 2;
        if(i)
            r[i] = d[i] + r[i-1];
        else
            r[i] = d[i];
    }

    double tmp, ans = 0;
    REP(i, k-1, n){
        tmp = r[i] - r[i-k];
        ans = max(ans, tmp);
    }

    cout << fixed << setprecision(7) << ans << endl;

    return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> P(N);
	vector<int> Q(N);
	vector<int> A(N);
	for(auto &i:P)cin >> i;
	for(auto &i:Q)cin >> i;
	for(int i=0;i<N;i++)A[i]=i+1;
	
	int p,q;
	int k=0;
	do{
		if(A==P)p=k;
		if(A==Q)q=k;
		k++;
	}while(next_permutation(A.begin(),A.end()));
	
	cout << abs(p-q) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

long long get_lcm(long long m, long long n) {
    /* Euclidean Algorithm */
    long long k=m*n;
    while (n)
        swap(m%=n, n);

    return k/m;
}

long long get_lcm(const vector<long long> a) {
    long long lcm=a[0];
    for (size_t i=1; i<a.size(); ++i)
        lcm = get_lcm(lcm, a[i]);

    return lcm;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<long long> a(n);
    for (size_t i=0; i<n; ++i)
        scanf("%lld", &a[i]);

    printf("%lld\n", get_lcm(a));
    return 0;
}

Measured memory_bytes: 2776
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

int N;

LL A[1 << 20], B[1 << 20];
priority_queue<pair<LL, int> > heap;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N;
	FOR (i, N)
		cin >> A[i];
	FOR (i, N)
		cin >> B[i];
		
	while (!heap.empty())
		heap.pop();
		
	FOR (i, N)
		heap.push(make_pair(B[i], i));
		
	LL ret = 0LL;
	while (!heap.empty()) {
		pair<LL, int> val = heap.top();
		heap.pop();
		int idx = val.second;
		if (A[idx] == B[idx])
			continue;
		
		int idxLeft = idx - 1;
		if (idxLeft < 0)
			idxLeft = N - 1;
		int idxRight = idx + 1;
		if (idxRight == N)
			idxRight = 0;
			
		LL sum = B[idxLeft] + B[idxRight];
		if (sum <= 0) {
			ret = -1;
			break;
		}
		LL times = (B[idx] - A[idx]) / sum;
		if (times == 0LL)
			times = 1LL;
		ret += times;
			
		B[idx] -= times * sum;
		if (B[idx] < A[idx]) {
			ret = -1;
			break;
		}
		
		heap.push(make_pair(B[idx], idx));
	}
	
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 9840