akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;
template<int64_t M = 1000000007>
class ModInt {
public:
	ModInt() : val_(0) {};

	ModInt(int64_t val) {
		this->val_ = val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0)  this->val_ += M;
	}

	operator int64_t() const {
		return this->val_;
	}

	ModInt& operator += (int64_t val) {
		this->val_ += val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0) this->val_ += M;

		return *this;
	}

	ModInt& operator -= (int64_t val) {
		this->val_ -= val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0) this->val_ += M;

		return *this;
	}

	ModInt& operator *= (int64_t val) {
		this->val_ *= val;
		this->val_ %= M;

		return *this;
	}

	ModInt& operator /= (int64_t val) {
		ModInt v = ModInt::pow(val, M - 2);
		*this *= v;

		return *this;
	}

	ModInt operator + (int64_t v) const {
		ModInt ret = *this;
		return (ret += v);
	}

	ModInt operator - (int64_t v) const {
		ModInt ret = *this;
		return (ret -= v);
	}

	ModInt operator * (int64_t v) const {
		ModInt ret = *this;
		return (ret *= v);
	}

	ModInt operator / (int64_t v) const {
		ModInt ret = *this;
		return (ret /= v);
	}

	static ModInt pow(ModInt n, int64_t m) {
		if (m == 0) {
			ModInt ret(1);
			return ret;
		}
		if (m == 1) {
			return n;
		}

		ModInt v = pow(n, m / 2);
		ModInt ret = v * v;
		if (m & 1) {
			ret *= n;
		}
		return ret;
	}

	ostream& operator << (ostream& out) {
		out << this->val_;
		return out;
	}

private:
	int64_t val_;
};

ModInt<> dp[2001];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int s; cin >> s;
	dp[0] = 1;

	FOR_LE(i, 0, s) {
		FOR_LE(j, 0, i - 3) {
			dp[i] += dp[j];
		}
	}
	cout << dp[s] << endl;
	

	return 0;
}

Measured memory_bytes: 3660
#include  <stdio.h>

int main(void){
	int a,b,n,i,sum=0,temp=0;
	while(scanf("%d %d %d",&a,&b,&n)!=EOF){
		temp=0;sum=0;
		temp=a%b;
		for(i=1;i<=n;i++){
			temp*=10;
			sum+=(temp/b);
			temp%=b;
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
using namespace std;
int main() {
  string S;
  cin >> S;
  int sum=1;
  int check=0;
  int N=S.size();
  for(int i=0;i<N;i++){
    if(S[i]!=S[N-1-i]){
      sum=0;
      //cout << "a";
    }
  }
  for(int i=0;i<(N-1)/2-1;i++){
    if(S[i]!=S[(N-1)/2-1-i]){
      sum=0;
      //cout << "b";
    }
  }
  int tmp=0;
  for(int i=(N+3)/2-1;i<N;i++){
    if(S[i]!=S[N-tmp-1]){
      sum=0;
      //cout << "c";
    }
    tmp++;
  }
  if(sum==1){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#define PI 3.14159265358979323846

using namespace std;
int main()
{
	double a, b, c, s, t, r, h;
	cin >> a >> b >> c;
	c = c / 180.0 * PI;
	s = sin( c );
	t = cos( c );
	r = sqrt( a*a + b*b - 2*a*b*t );
	h = b * s;
	cout << fixed << setprecision(5) << 0.5 * a * h << "\n";
	cout << fixed << setprecision(5) << a + b + r << "\n";
	cout << fixed << setprecision(5) << h << "\n";

	return 0;
}

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

N,M = map(int, input().split())
neighbor = [[] for _ in range(N)]
A = [-1]*M; B = [-1]*M
for i in range(M):
    a,b = map(lambda x: int(x) - 1, input().split())
    A[i] = a; B[i] = b
    neighbor[a].append(b)
    neighbor[b].append(a)

cnt = 0
for i in range(M):
    a,b = A[i],B[i]
    neighbor[a].remove(b)
    neighbor[b].remove(a)
    visited = [False]*N
    queue = deque()
    queue.append(0)
    visited[0] = True
    
    while queue:
        x = queue.popleft()
        
        for z in neighbor[x]:
            if not visited[z]:
                visited[z] = True
                queue.append(z)
    
    
    if False in visited:
        cnt += 1
    
    neighbor[a].append(b)
    neighbor[b].append(a)

print(cnt)

Measured memory_bytes: 9484
#include<stdio.h>
const int N = 55;
int main()
{
	int n, S[N] = {0}, H[N] = {0}, C[N] = {0}, D[N] = {0};
	
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++)
	{
		int p;
		char k;
		scanf(" %c %d", &k, &p);
		if(k == 'S')
			S[p]++;
		
		else if(k == 'H')
			H[p]++;
		
		else if(k == 'C')
			C[p]++;
		
		else if(k == 'D')
			D[p]++;
		
	}
	for(int i = 1; i <= 13; i++)
	{
		if(S[i] == 0)
			printf("S %d\n", i);
	}
	for(int i = 1; i <= 13; i++)
	{
		if(H[i] == 0)
			printf("H %d\n", i);
	}
	for(int i = 1; i <= 13; i++)
	{
		if(C[i] == 0)
			printf("C %d\n", i);
	}
	for(int i = 1; i <= 13; i++)
	{
		if(D[i] == 0)
			printf("D %d\n", i);
	}
	return 0;
}


Measured memory_bytes: 2672
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, arr[1001], lcm=1;
int main() {
    IOS
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        lcm = (lcm * arr[i])/__gcd(lcm, arr[i]);
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        cnt += lcm/arr[i];
    }
    cout.precision(5);
    cout << fixed << (1.0 * lcm) / cnt << endl;

    return 0;


}


Measured memory_bytes: 256
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8
from numba.types import Omitted

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 1_000_000_007

@njit((i8, i8), cache=True)
def main(N, K):
    K -= 1
    U = 2010
    C = np.zeros((U, U), np.int64)
    C[0, 0] = 1
    for n in range(1, U):
        C[n] += C[n - 1]
        C[n, 1:] += C[n - 1, :-1]
        C[n] %= MOD

    dp = np.zeros((N + 10, N + 10), np.int64)
    dp[0, 0] = 1
    for n in range(1, N + 10):
        dp[n, n] = (dp[n - 1, n - 1] + dp[n - 1, n]) % MOD
        for m in range(n + 1, N + 10):
            dp[n, m] = (dp[n - 1, m] + dp[n, m - 1]) % MOD
    for n in range(N + 9, 0, -1):
        dp[n] -= dp[n - 1]
        dp[n] %= MOD
    ans = 0
    if K == N - 1:
        return dp[:N, N - 1].sum() % MOD
    for r in range(N - K, N + 1):
        x = C[r - 2, N - K - 2]
        a = N - r
        b = K - a
        if b == 0:
            x = x * (dp[:a + 1, a].sum() % MOD) % MOD
        else:
            x *= (dp[1:a + 2, a + 1] * C[b - 1:a + b, b - 1][::-1] %
                  MOD).sum() % MOD
            x %= MOD
        ans += x
    ans %= MOD
    for i in range(N - K - 2):
        ans = ans * 2 % MOD
    return ans % MOD

N, K = map(int, read().split())
print(main(N, K))


Measured memory_bytes: 170760
#include <iostream>
#include <cstdio>
using namespace std;
 
int main(void){
  int a,b,c;
  cin >> a;
  cin >> b;
  cin >> c;
 
  if(a>b){
      if(a<c){
          cout << b;
          cout << " ";
          cout << a;
          cout << " ";
          cout << c;
     }
     else {
         if(b<c){
         cout << b;
         cout << " ";
         cout << c;
         cout << " ";
         cout << a;
         }
         else {
         cout << c;
         cout << " ";
         cout << b;
         cout << " ";
         cout << a;
         }
     }
  }
  else {
      if(b<c){
          cout << a;
          cout << " ";
          cout << b;
          cout << " ";
          cout << c;
      }
      else {
          if(c<a){
          cout << c;
          cout << " ";
          cout << a;
          cout << " ";
          cout << b;
          }
          else if(c<b){
          cout << a;
          cout << " ";
          cout << c;
          cout << " ";
          cout << b;
          }
      }
  }
  cout << endl;
}


Measured memory_bytes: 3076
import numpy as np
N, K, Q = map(int, input().split())
first = K - Q
board = np.array([first] * N)
for _ in range(Q):
    A = int(input())
    board[A - 1] += 1
for player in board:
    if player > 0:
        print("Yes")
    else:
        print("No")


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

using namespace std;

#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
    FAST();
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i] == '?')s[i]='D';
    }
    cout << s;
    return 0;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll a[100005],b[100005];
int main(){
  ll n;
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>b[i];
  vector<P> pv;
  for(int i=0;i<n;i++) pv.push_back(P(b[i],a[i]));
  sort(pv.begin(),pv.end());
  for(int i=0;i<n;i++){
    a[i]=pv[i].second;
    b[i]=pv[i].first;
  }
  vector<P> av;
  for(int i=0;i<n;i++) av.push_back(P(a[i],i+1));
  sort(av.begin(),av.end());
  for(int i=0;i<n;i++){
    if(av[i].first>pv[i].first){
      cout<<"No"<<endl;
      return 0;
    }
  }
  vector<bool> used(100005,false);
  ll pos=1;
  while(!used[pos]){
    used[pos]=true;
    pos=av[pos-1].second;
  }
  bool f=true;
  for(int i=1;i<=n;i++){
    if(!used[i]) f=false;
  }
  if(!f){
    cout<<"Yes"<<endl;
    return 0;
  }
  for(int i=0;i<n-1;i++){
    if(av[i+1].first<=pv[i].first){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 6384
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int a[200001],f[200001];
ll n,k;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>k;
	rep(i,n){
		cin>>a[i];
	}
	rep(i,n){
		cin>>f[i];
	}
	sort(a,a+n);
	sort(f,f+n);
	ll l=0,r=2e18;
	while(l!=r){
		ll mid=(l+r)/2,cnt=0ll;
		vector<ll> v;
		rep(i,n){
			v.pb(mid/f[i]);
		}
		
		sort(all(v));
		rep(i,n){
			if(a[i]>v[i]){
				cnt+=(a[i]-v[i]);
			}
		}
		if(cnt<=k){
			r=mid;
		}else{
			l=mid+1;
		}
	}
	cout<<r;
	re 0;
}


Measured memory_bytes: 6060
import heapq

# max heap
class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        return heapq.heappop(self.hq) * self.sign
 
    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)
 
    def top(self):
        return self.hq[0] * self.sign
 
    def size(self):
        return len(self.hq)

from collections import defaultdict
d = defaultdict(list)

n, m = map(int, input().split())
ab = [tuple(map(int,input().split())) for i in range(n)]
for a,b in ab:
    d[a].append(b)

q = Heapq([], True)
 
ans = 0
for i in range(1,m+1):
    for b in d[i]:
        q.push(b)
    if q.size():
        ans += q.pop()
print(ans)

Measured memory_bytes: 37936
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
P = list(map(int, input(). split()))
if X not in P:
    print(X)
    exit()

for n in range(1, N + 1):    
    if not (X - n) in P:
        print(X - n)
        exit()
    if not (X + n) in P:
        print(X + n)
        exit()
print(min(P) - 1)

Measured memory_bytes: 9144
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

long long int N, M, K, L, R, H, W;
//int N, M, K, L, R, H, W;


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

	cin >> N;
	vector<pair<long long int, int>>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i].first;
		v[i].second = i + 1;
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	vector<vector<long long int>>dp(N + 2, vector<long long int>(N + 2));
	for (int i = 0; i < N; i++) {
		int len = N - i + 1;
		for (int j = 0; j + len < N + 2; j++) {
			dp[j + 1][j + len] = max(dp[j + 1][j + len], dp[j][j + len] + v[i].first*abs(v[i].second - (j + 1)));
			dp[j][j + len - 1] = max(dp[j][j + len - 1], dp[j][j + len] + v[i].first*abs(v[i].second - (j + len - 1)));
		}
	}
	long long int ans = 0;
	for (int i = 0; i < N + 1; i++) {
		ans = max(ans, dp[i][i + 1]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 34616
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

const int N = 1e5+10;
int n, dp[N][3], a, b, c;

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    cin >> n;
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    FOR(i, 1, n) {
    	cin >> a >> b >> c;
    	dp[i][0] = a+max(dp[i-1][1], dp[i-1][2]);
    	dp[i][1] = b+max(dp[i-1][0], dp[i-1][2]);
    	dp[i][2] = c+max(dp[i-1][0], dp[i-1][1]);
    }
    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]) << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting min to 0 instead of -INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)


Measured memory_bytes: 1408
def bellman(start, n, edges)
    dist = Array.new(n+1, Float::INFINITY)
    prev = Array.new(n+1)
    dist[start] = 0
    n.times do |i|
        update = false
        edges.length.times do |src|
            edges[src].each do |dst, cost|
                if dist[dst] > dist[src] + cost
                    update = true
                    prev[dst] = src
                    if i == n - 1
                        dist[dst] = -Float::INFINITY
                    else
                        dist[dst] = dist[src] + cost
                    end
                end
            end
        end
        break unless update
    end
    return dist, prev
end



N, M = gets.split.map(&:to_i)

edges = Array.new(N+1){Hash.new}
M.times do |i|
    a, b, c = gets.split.map(&:to_i)
    edges[a][b] = -c
end

dist, _ = bellman(1, N, edges)

if dist[N] == -Float::INFINITY
    puts 'inf'
else
    puts -dist[N]
end


Measured memory_bytes: 4348
#include<stdio.h>
#include<math.h>
#define PI 3.141592653589793

int main()
{

double a,b,C,S,H,K,k,J;
a=0;b=0;C=0;S=0;H=0;K=0;k=0;J=0;
scanf("%lf",&a);scanf("%lf",&b);scanf("%lf",&C);
C=C*(PI)/180;



H=b*sin(C);
S=0.5*a*H;
k=a*a+b*b-2*a*b*cos(C);
K=sqrt(k);
J=a+b+K;
printf("%f\n%f\n%f\n",S,J,H);
return 0;
}

Measured memory_bytes: 1080
#include<iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int* a = new int[n+1];
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
	}
	for (int i = 1;i <= n;i++) {
		cout << "node " << i << ": key = " << a[i]<<", ";
		if (i != 1) {
			cout << "parent key = " << a[i / 2]<<", ";
		}
		if (2 * i <= n) {
			cout << "left key = " << a[2 * i] << ", ";
		}
		if (2 * i + 1 <= n) {
			cout << "right key = " << a[2 * i + 1] << ", ";
		}
		cout << endl;
	}
}


Measured memory_bytes: 3116
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

if((Math.abs(b-a)<=d&&Math.abs(c-b)<=d)||(Math.abs(c-a)<=d)){
System.out.println("Yes");	
}else{
	System.out.println("No");
}

	}
}

Measured memory_bytes: 21844
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    const n = chunk.toString();
    const input = n.split(' ').map(x=>Number(x));
    const returna = input[0]%input[1];
    const returnb = input[0]/input[1];
    console.log(`${kirisute(input)} ${returna} ${kiru(input)}`);
});

function kirisute(input) {
    const returnc = input[0]/input[1];
    return Math.floor(returnc); 
 }

 function kiru(input) {
    const returnb = input[0]/input[1];
    return Math.floor(returnb*1000000)/1000000; 
 }


Measured memory_bytes: 15532
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <functional>
#include <cstring>
#include <cmath>
#include <random>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), k(n);
    vector<int64_t> r(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        k[i] = i;
    }
    sort(k.begin(), k.end(), [&](int i0, int i1) {
        return a[i0] > a[i1] || (a[i0] == a[i1] && i0 < i1);
    });
    int j = 0, h = 0;
    for (int i = 0; i < n;) {
        for (; j < n && a[k[j]] == a[k[i]]; j++);
        if (j == n) {
            r[k[h]] += (int64_t)(a[k[i]] - 0) * j;
            break;
        }
        r[k[h]] += (int64_t)(a[k[i]] - a[k[j]]) * j;
        if (k[j] < k[h]) h = j;
        i = j;
    }

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

    return 0;
}


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

struct Node {
  int key;
  int pri;
  Node *r, *l;
};

Node *rrotate(Node *t) {
  Node *s = t->l;
  t->l = s->r;
  s->r = t;
  return s;
}
Node *lrotate(Node *t) {
  Node *s = t->r;
  t->r = s->l;
  s->l = t;
  return s;
}

Node *insert(Node *t, int k, int p) {
  if (t == NULL) {
    Node *n = new Node();
    n->key = k;
    n->pri = p;
    n->l = n->r = NULL;
    return n;
  }
  if (t->key == k) return t;

  if (k < t->key) {
    t->l = insert(t->l, k, p);
    if (t->pri < t->l->pri) t = rrotate(t);
  } else {
    t->r = insert(t->r, k, p);
    if (t->pri < t->r->pri) t = lrotate(t);
  }
  return t;
}
Node *find(Node *t, int k) {
  if (t == NULL) return NULL;
  if (t->key == k) return t;
  if (k < t->key)
    return find(t->l, k);
  else
    return find(t->r, k);
}
Node *dele(Node *t, int k) {
  if (t == NULL) return NULL;
  if (k == t->key) {
    if (t->l == NULL && t->r == NULL) {
      return NULL;
    } else if (t->l == NULL) {
      t = lrotate(t);
    } else if (t->r == NULL) {
      t = rrotate(t);

    } else {
      if (t->l->pri > t->r->pri)
        t = rrotate(t);
      else
        t = lrotate(t);
    }
    return dele(t, k);
  }
  if (k < t->key)
    t->l = dele(t->l, k);
  else
    t->r = dele(t->r, k);
  return t;
}
void printinorder(Node *t) {
  if (t == NULL) return;
  printinorder(t->l);
  cout << " " << t->key;
  printinorder(t->r);
}
void printpreorder(Node *t) {
  if (t == NULL) return;
  cout << " " << t->key;
  printpreorder(t->l);
  printpreorder(t->r);
}
int main() {
  int m, k, p;
  string cmd;
  Node *root=NULL;

  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> cmd;
    if (cmd[0] == 'i') {
      cin >> k >> p;
      root = insert(root, k, p);
    } else if (cmd[0] == 'f') {
      cin >> k;
      if (find(root, k) != NULL)
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    } else if (cmd[0] == 'd') {
      cin >> k;
      root = dele(root, k);
    } else {
      printinorder(root);
      cout << endl;
      printpreorder(root);
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 9436
#include <bits/stdc++.h>
# define int long long
using namespace std;
int GCD(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int LCM(int a, int b)
{
   return a * b / GCD(a,b);
}



main() {
   int c,d;
   cin >> c >> d;
  int lcm = LCM(c,d);
  cout << lcm << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define int long long

signed main(){
    int n,h;cin>>n>>h;
    priority_queue<int> q;
    int am=0;
    rep(i,n){
        int a,b;cin>>a>>b;
        am=max(am,a);
        q.push(b);
    }
    int ans=0;
    while(h>0&&!q.empty()&&q.top()>am){
        h-=q.top();
        q.pop();
        ans++;
    }
    if(h>0)ans+=(h+am-1)/am;
    cout<<ans<<endl;
}

Measured memory_bytes: 1400
#include<stdio.h>
int main(){
int a,b,c;
int x,k;
scanf("%d %d %d",&a,&b,&c);
for(x=0;x<=6;x++){
if(a>b){k=a;a=b;b=k;}
if(b>c){k=b;b=c;c=k;}
if(a>b){k=a;a=b;b=k;}
}
    printf("%d %d %d\n",a,b,c);
return 0;
}

Measured memory_bytes: 596
n = int(input())
ans = 0
last = 0
for i in range(n):
  d1, d2 = map(int,input().split())
  if d1 == d2:
    ans += 1
  else:
    last = max(last,ans)
    ans = 0
last = max(last,ans)
if last > 2:
  print('Yes')
else:
  print('No')


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

int main(){
  string s;
  cin >> s;
  bool b = true;
  rep(i, s.size()/2){
    if(s[i] != s[s.size()-i-1]) {
      b = false;
      break;
    }
  }
  rep(i, ((s.size()-1)/2)/2){
    if(s[i] != s[(s.size()-1)/2-i-1]) {
      b = false;
      break;
    }
  }
  rep(i, (s.size()-3)/2){
    if(s[i+(s.size()+3)/2 - 1] != s[s.size()-i-1]) {
      b = false;
      break;
    }
  }

  if(b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        for(int i = 0; 2 * i + 1 <= n; i++)
            count += checkNum(2 * i + 1);
        System.out.println(count);
    }

    public static int checkNum(int n){
        int count = 0;
        for(int i = 1; i <= n; i++) {
            if (n % i == 0)
                count++;
            if(count > 8)
                return 0;
        }
        if(count == 8)
            return 1;
        else
            return 0;
    }
}


Measured memory_bytes: 21588
S=input()
n=len(S)
dp=[[0]*n for _ in range(20)]

for i,s in enumerate(S):
    dp[0][i]=i-1 if s =='L' else i+1

for k in range(19):
    for i in range(n):
        dp[k+1][i]=dp[k][dp[k][i]]

A=[0 for i in range(n)]
for d in dp[-1]:
    A[d]+=1
print(*A)


Measured memory_bytes: 29440
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)
const long double PI = (acos(-1));


int main() {

	int a, b, c;
	cin >> a >> b >> c;

	if (a * c <= b) cout << c << endl;
	else cout << b / a << endl;

	return 0;
}

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


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

void chmin(int &a, int b) {if (a > b) a = b;}
void chmax(int &a, int b) {if (a < b) a = b;}

string s;

int main() {
  while (cin >> s) {
	int res = (int)s.size();
	for (int i = 0; i < 26; ++i) {
	  char c = 'a' + i;
	  int tmp = 0;
	  int con = 0;
	  for (int j = 0; j < (int)s.size(); ++j) {
		if (s[j] == c) {
		  chmax(tmp, con);
		  con = 0;
		}
		else {
		  ++con;
		}
	  }
	  chmax(tmp, con);
	  chmin(res, tmp);
	}
	cout << res << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int m = INF;
    for(int i = 0 ; i < n; i++){
        int cnt = 0;
        while(a[i] % 2 == 0){
            a[i] /= 2;
            cnt++;
        }
        m = min(m, cnt);
        if(m == 0) break;
    }
    cout << m;
}

Measured memory_bytes: 256
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const int INF = int(1e9);

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) s[i] = 'x';
    cout << s;
    return 0;
}

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

l = [0]*N
l[0] = A[0]
r = [0]*N
r[-1] = A[-1]
for i in range(1, N):
    l[i] = l[i-1]+A[i]
    r[N-i-1] = r[N-i]+A[N-i-1]

res = 10**10
for i in range(N-1):
    res = min(abs(l[i]-r[i+1]), res)

print(res)

Measured memory_bytes: 35772
N, K = map(int, input().split())
num = list(map(int, input().split()))

# 各サイコロの期待値を出す
expect = []
for i in range(N):
  expect.append((1 + num[i]) / 2)

# 累積和を作る
cs = [0]
for (i, number) in enumerate(expect):
  cs.append(cs[i] + expect[i])

max = 0
for i in range(K, N+1): # 配列0番目に初期値0が増えてるので1足す
  if max < cs[i] - cs[i-K]:
    max = cs[i] - cs[i - K]
print(max)


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

using namespace std;
using ll = long long;

signed main() {
    ll a, b, k;
    cin >> a >> b >> k;
    if (k == a) {
        cout << 0 << " " << b;
        return false;
    }
    if (k < a) {
        cout << a - k << " " << b;
        return false;
    }
    if (k > a) {
        k -= a;
        if (k > b) {
            cout << 0 << " " << 0 << "\n";
        } else {
            cout << 0 << " " << b - k << "\n";
        }
    }
    return false;
}

Measured memory_bytes: 256
from bisect import bisect_left as bl
from itertools import accumulate

h, w= map(int, input().split())
aList = sorted(map(int, input().split()))
bList = list(map(int, input().split()))
acc = [0]+list(accumulate(aList))
aList.insert(0, -1)

ans = 0
for b in bList:
    index = bl(aList, b)
    ans += acc[index - 1] + (h - index + 1) * b
print(ans)



Measured memory_bytes: 20648
import math
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    A[i] -= (i+1)


buff = math.ceil(sum(A)/N)
buff2 = sum(A)//N
buff3 = sum(A)//N-1
A.sort()
buff3 = A[N//2]
ans = 0
for i in range(N):
    ans += abs(A[i]-buff)

ans2 = 0
for i in range(N):
    ans2 += abs(A[i]-buff2)

ans3 = 0
for i in range(N):
    ans3 += abs(A[i]-buff3)
print(min(ans, min(ans2, ans3)))

Measured memory_bytes: 26612
#include <cstdio>
#include <algorithm>
using namespace std;

int w, h, n;
int x[100], y[100], a[100];
int minx, maxx, miny, maxy;

int main(){
	scanf("%d %d %d", &w, &h, &n);
	for(int i=0; i<n; i++)
		scanf("%d %d %d", &x[i], &y[i], &a[i]);

	minx = 0;
	miny = 0;
	maxx = w;
	maxy = h;
	for(int i=0; i<n; i++){
		if(a[i] == 1) minx = max(minx, x[i]);
		else if(a[i] == 2) maxx = min(maxx, x[i]);
		else if(a[i] == 3) miny = max(miny, y[i]);
		else maxy = min(maxy, y[i]);
	}

	int dx, dy;
	dx = max(0, maxx - minx);
	dy = max(0, maxy - miny);
	printf("%d\n", dx * dy);
	return 0;
}

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int x,y;
    cin>>x>>y;
    x --, y --;
    cout<<x*y<<endl;
}
//./problem.exe

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

using namespace std;
using i64 = int64_t;

i64 dp[3005][3005];
i64 N, S;
const i64 MOD = 998244353LL;


int main(){
  cin >> N >> S;
  vector<int> A(N);
  for(auto&& x:A)cin >> x;
  dp[0][0] = 1;
  for(int i=0;i<N;i++){
    for(int j=0;j<=S;j++){
      dp[i+1][j] += 2 * dp[i][j];
      dp[i+1][j] %= MOD;
      if(j+A[i] <= S)
      	dp[i+1][j+A[i]] += dp[i][j];
      	dp[i+1][j+A[i]] %= MOD;
    }
  }
  cout << dp[N][S] << endl;
}

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

using namespace std;

const int MOD = 1e9 + 7;

int main () {
	int n;
	cin >> n;
	vector<int> dp(n + 1);
	dp[0] = 1;

	for (int i = 1; i <= n; i++) {
		for (int j = 3; i - j >= 0; j++) {
			dp[i] = (dp[i] + dp[i - j]) % MOD;
		}
	}
	
	cout << dp[n] << '\n';
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007

ll PowMod(ll n, ll p) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    ll t = PowMod(n, p / 2);
    return t * t % DIV;
  }
  return n * PowMod(n, p - 1) % DIV;
}

ll comb(ll n, ll r) {
  // 分母と分子。いい名前思いつかなかった
  ll res, deno, mole;
  res = deno = mole = 1;
  for (ll i = 0; i < r; i++) {
    mole *= (n - i);
    mole %= DIV;
    deno *= (r - i);
    deno %= DIV;
  }
  // 分母の逆元
  res = PowMod(deno, DIV - 2);
  res = (res * mole) % DIV;
  return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long N,K;
    cin >> N >> K;
    long red = N - K;

    for(size_t i=1;i<=K; i++)
    {
        if(min((long)K-i, (long)red-i+1) < 0) {
            cout << 0 << endl;
            continue;
        }
        // 赤いボールの間 red+1 箇所から青いボールのまとまり i を置く場所を考える comb(red+1 , red-i+1)
        // 青いボール、ボールとボールの間 K-1 個から i-1 個の場所を選択する方法　comb(K-1 , K-i)
        cout << comb(K-1 , K-i) * comb(red+1 , i) % DIV << endl;
    }
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int n,k,doe,ans;
int now[101010],pre[202020],son[202020];
int deep[101010];
void add(int x,int y)
{
	++doe;
	pre[doe]=now[x];
	now[x]=doe;
	son[doe]=y;
}
void dfs(int x,int fa)
{
	deep[x]=1;
	int p=now[x];
	while (p)
	{
		int y=son[p];
		if (y!=fa)
		{
			dfs(y,x);
			deep[x]=max(deep[x],deep[y]+1);
		}
		p=pre[p];
	}
	if (deep[x]==k && x!=1 && fa!=1) deep[x]=0,++ans;
}
int main()
{
	scanf("%d%d",&n,&k);
	int x;
	scanf("%d",&x);
	if (x!=1) ++ans;
	for (int i=2;i<=n;++i)
	{
		scanf("%d",&x);
		add(x,i);
	}
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

ll tab[100] = {};

ll f(ll n){
  if(tab[n]) return tab[n];
  if(n == 0) return 2;
  if(n == 1) return 1;
  tab[n] = f(n-1)+f(n-2);
  return tab[n];
}

int main(){
  int n;
  cin >> n;
  ll ans = f(n);
  cout << ans << endl;
}



Measured memory_bytes: 384
from itertools import groupby

s = list(input())
f = 0
ans = 0
for k,v in groupby(s):
  d = len(list(v))
  left = d if k==">" else 0
  right = d if k=="<" else 0
  if f>left:
    ans += d*(d+1)//2 - left
  else:
    ans += -1*f + d*(d+1)//2  
  f = right 
print(ans) 

Measured memory_bytes: 11676
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;


int main()
{ 
  char a,b,c;
  char d,f,e;
  scanf("%c%c%c\n%c%c%c",&a,&b,&c,&d,&f,&e);
  if(a==e&&c==d&&b==f)
    	 printf("YES"); 
    else 
    	printf("NO");
	
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;

int main()
{
	int n, k;
	cin >> n >> k;
	if (k == 2) cout << 2 << endl;
	else
	{
		ll res = k;
		res *= pow(k - 1, n - 1);
		cout << res << endl;
	}

}

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

template <typename T>
using lim = numeric_limits<T>;

const double PI = acos(-1);
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	double r; cin >> r;
	cout << r*2*PI << "\n";

}

Measured memory_bytes: 3804
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

int main(void){
    int n, q;
    std::cin >> n >> q;

    std::string s;
    std::cin >> s;

    std::vector<int> check(n);
    check.at(0) = 0;
    for(int i = 1; i < n; i++){
        if(s.at(i-1) == 'A' && s.at(i) == 'C'){
            check.at(i) = check.at(i-1) + 1;
        }
        else{
            check.at(i) = check.at(i-1);
        }
    }


    for(int i = 1; i <= q; i++){
        int l, r;
        std::cin >> l >> r;

        int ans = check.at(r-1) - check.at(l-1);
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using ip = pair<int,int>;
using lp = pair<ll,ll>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll atcoder = int(1e9 + 7);

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

ll ketawa(ll a) {
	if (a < 10)return a;
	return ketawa(a / 10) + a % 10;
}

int main() {
	
	int h, w;
	cin >> h >> w;

	int c[10][10];
	rep(i, 10)rep(j, 10)cin >> c[i][j];

	rep(k, 10) rep(i, 10) rep(j, 10) chmin(c[i][j], c[i][k] + c[k][j]);

	ll ans = 0;
	int a;
	rep(i, h) {
		rep(j, w) {
			cin >> a;
			if (a >= 0)ans += c[a][1];
		}
	}
	
	pr(ans);

	return 0;
}

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

int main(){
  int n;cin>>n;
  int a[n];
  fol(i,n){
    cin>>a[i];
  }
  int dp[n+2]={};
  fol(i,n+2){dp[i] = 1E9;}
  dp[0] = 0;
  for(int i=0;i<n;i++){
    dp[i+1] = min(dp[i+1],abs(a[i]-a[i+1])+dp[i]);
    dp[i+2] = min(dp[i+2],abs(a[i]-a[i+2])+dp[i]);
  }
  cout << dp[n-1] << endl;
  return 0;
}


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



int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    long int cnt_r, cnt_g, cnt_b;
    cnt_r = cnt_g = cnt_b = 0;
    rep(i,n) {
        if(s[i] == 'R')
            cnt_r++;
        else if(s[i] == 'G')
            cnt_g++;
        else if(s[i] == 'B')
            cnt_b++;
    }
    
    long int cnt = cnt_r * cnt_g * cnt_b;
    //cout << cnt << endl;
    
    rep(j,n) rep(i,j) {
        int k = j + (j-i);
        if(k < n && s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
            cnt--;
    }
    
    if(cnt < 0)
        cnt = 0;
    
    cout << cnt << endl;
    
    return 0;
}




Measured memory_bytes: 3612
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const s: string = tmp.shift().split(" ")[0];
    return `${s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2) ? "No" : "Yes"}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
typedef long long int lli;
const lli inf = 1e18;
const lli mod = 998244353;

lli ExGCD(lli a, lli b, lli &x, lli &y){
    lli d=a;
    x=1; y=0;
    if(b!=0){ d=ExGCD(b, a%b, y, x); y-=a/b*x; }
    return d;
}

lli fact[300001];
lli inv[300001];
void maketable(){
	fact[0] = 1;
	REP(i, 300000){
		fact[i+1] = fact[i]*(i+1) %mod;
	}
	lli y;
	REP(i, 300001){
		ExGCD(fact[i], mod, inv[i], y);
		while(inv[i]<0) inv[i]+=mod;
	}
}

int main(){
	lli n,a,b,k;
	cin >> n >> a >> b >> k;
	if((a+b)*n < k){
		cout << 0 << endl;
		return 0;
	}
	
	maketable();
	
	if(a>b) swap(a,b);
	lli ans=0;
	for(int i=0; i<=n; i++){
		lli nb=i;
		if((k-nb*b)%a!=0 || (k-nb*b)/a>n) continue;
		lli na=(k-nb*b)/a;
		if(na < 0 || na>n) continue;
		ans += fact[n] *inv[n-na] %mod *inv[na] %mod *fact[n]%mod *inv[n-nb]%mod *inv[nb]%mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ans = 0
    la, lb = len(a), len(b)
    J = (i for i in range(lb)) if a == b else (-1 for i in range(la))

    j = lb - 1
    #for i in range(la):
    for i, k in enumerate(J):
        xa = a[i]

        for j in range(j, k, -1):
            x1 = b[j] * xa
            if x1 <= x:
                break
        else:
            break
        ans += j - k

    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 97876
def isKaibun(s):
  for a, b in zip(s, reversed(s)):
    if a != b:
      return False
  return True

S = list(input())
N = len(S)
if isKaibun(S) and isKaibun(S[:(N-1)//2]) and isKaibun(S[(N+1)//2:]):
  print("Yes")
else:
  print("No")


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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;

int main ()
{
  prep();
  int n, k;
  cin >> n >> k;
  int cnt = 0;
  for (int i=0; i<n; i++){
      int num;
      cin >> num;
      if (num >=k){
          cnt++;
      }
      
  }
  cout << cnt;
  return 0; 
}


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

#define MAX_N 1000000
#define rep(i,N) for(int i=0; i<N; ++i)

template<typename T>
void my_sort(T *x, int n) {
	// 0: 5 4 3 2 1
	// 1: 3 5 4 2 1
	// 2: 2 3 5 4 1
	// 3: 1 2 3 5 4
	// 4: 1 2 3 4 5 
	
	// 0: 4 5 1 2 3
	// 1: 3 4 5 1 2
	// 2: 2 3 4 5 1
	// 3: 1 2 3 4 5
	//
	// 残り1手でソートできる状況
	// 2 が先頭に来ている. -> 1が 2 3 4 5 の先頭以外に挿入されている.
	// 2 1 3 4 5
	// 2 3 1 4 5
	// 2 3 4 1 5
	// 2 3 4 5 1	
	// 4 が後尾に来ている. -> 5が 1 2 3 4 の後尾以外に挿入されている.
	// 1 2 3 5 4
	// 1 2 5 3 4
	// 1 5 2 3 4
	// 5 1 2 3 4
	// 残り2手でソートできる状況
	// 3 4 5 2 1 -> 2が 3 4 5 の先頭以外に挿入されている
	// 1 3 4 5 2 
	// ..
	// 1 2 4 3 5 -> 4が 1 2 3 の後尾以外に挿入されている
	//
}

template<class T>
int check_sorted_numbers(T *x, int n) {
	// sort済み部分列の最大の長さを求める...というのができれば回数はわかる
	// より限定する必要があり,両端に動かす必要がない昇順部分列の長さを数える必要がある
	// その列の中では、1ずつ値が大きくなっている
	
	// 1 4 2 5 3 => 1 2 3 が最大で3
	// 1 1 2 2 3 <= 各要素までの1ずつ増加する部分列の最大長の配列
	T y[MAX_N];
	rep(i,n) y[x[i]-1] = i; // 0 startの配列を使うのならばx[i]-1 の-1を忘れてはいけない
	// x: 1 4 2 5 3
	// y: 1 3 5 2 4 /1が1番目, 2が3番目, 3が5番目, 4が2番目, 5が4番目に位置する, という情報を保持する配列
	// y[i] < y[i+1] <=> iがi+1よりも小さいindexに位置する
//	// ダメな例
//	for (int i=1; i<n; ++i) {
//		if (x[i-1] + 1 == x[i]) y[x[i]]++;
//		else y[x[i]] = 1;
	int count = 1, max_len=1;
	for (int i=1; i<n; ++i) {
		if (y[i-1] < y[i]) count++; 
		else count=1;
		max_len = std::max(max_len, count);
	}	
	return max_len;
}

using namespace std;

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

	vector<int> x(N);
	rep(i,N) {
		scanf("%d", &x[i]);
	}
	cout << N - check_sorted_numbers(x.data(), x.size()) << endl; 
	return 0;
}





Measured memory_bytes: 3840
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;

long long int pow_m1(long long int num){
	long long int pow_num = MOD - 2;
	long long int mod_num = MOD;
	long long int pow_cur = num;
	long long int ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

long long int DP[2001][2001];

int main(){
	
	while(true){
		
		long long int N, D, X;
		
		cin >> N >> D >> X;
		if(N == 0){
			break;
		}
		
		D %= MOD;
		
		for(int i = 0; i <= N; i++){
			for(int j = 0; j <= N; j++){
				DP[i][j] = 0;
			}
		}
		
		for(int i = 1; i < X; i++){
			DP[1][i] = 1;
		}
		for(int i = 2; i <= N; i++){
			for(int j = 2; j <= N; j++){
				DP[i][j] = DP[i][j - 1] + DP[i - 1][j - 1];
				if(j - 1 >= X){
					DP[i][j] -= DP[i - 1][j - X];
				}
				DP[i][j] += MOD;
				DP[i][j] %= MOD;
			}
		}
		
		long long int ans = 0, comb = 1;
		
		for(long long int i = 1; i <= N; i++){
			comb *= (D - i + 1);
			comb %= MOD;
			comb *= pow_m1(i);
			comb %= MOD;
			ans += comb * DP[i][N];
			ans %= MOD;
		}
		
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 34332