akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

const int maxn=505;

int n,m;
int a[maxn][maxn],b[maxn][maxn];

int main()
{
	scanf("%d%d\n",&n,&m);
	char ch;
	for (int i=1; i<=n; i++)
	{
		for (int j=1; j<=m; j++)
		{
			ch=getchar();
			if (ch=='#') a[i][j]=b[i][j]=1;
		}
		scanf("\n");
	}
	for (int i=1; i<=n; i++) a[i][1]=1,b[i][m]=1;
	for (int i=2; i<=n-1; i++)
	{
		if (i%2==1) {
			for (int j=2; j<=m-1; j++) 
				a[i][j]=1;
		}
	}
	for (int i=2; i<=n-1; i++)
	{
		if (i%2==0) {
			for (int j=2; j<=m-1; j++)
				b[i][j]=1;
		}
	}
	for (int i=1; i<=n; i++)
	{
		for (int j=1; j<=m; j++)
			if (a[i][j]) printf("#");
			else printf(".");
		printf("\n");
	}
	printf("\n");
	for (int i=1; i<=n; i++)
	{
		for (int j=1; j<=m; j++)
			if (b[i][j]) printf("#");
			else printf(".");
		printf("\n");
	}
	
	return 0;
}

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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e6;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

int n,m,x,y,mx;
vi v;
vector<vi> g(maxn);
int a[maxn],b[maxn];
string s;

bool mk[maxn*2];

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

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

	long double c;
	cin >> n >> c;
	int ans  = n * c;
	cout << ans;
	return 0;
}



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

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <map>
#include <tuple>

using namespace std;


#define anyfill(n,s) setw(n) << setfill(s)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define pb push_back
#define MAX 1000000000
#define MOD 1000000007


/*
確認ポイント
to_string() はC++11以降の実装;
cout<< (char)数値 //数値にあった文字に置き換えられる
cout<< (double)int型/(2など)//小数になる
length(),size()に括弧をつけ忘れてないか;
sort()が使える型//vector,string...
大文字小文字間違えてないか
cout << fixed << 小数計算//正しい小数表記になる(基本6桁)(e記法回避にも使える)
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
sqrt(数値型)でrootが取れる
vector.unique()は隣接した同じ要素を削除するので先にソートをする
*/
vector<int> A[100000][2];
int ans[100000];
bool lck[100000];
void DFS(int nw,int cl){
  for(int i = 0; A[nw][0].size() > i; i++){
    if(!lck[A[nw][0][i]]){
      lck[A[nw][0][i]] = true;
      ans[A[nw][0][i]] = cl;
      DFS(A[nw][0][i],cl);
    }
  }
  for(int i = 0; A[nw][1].size() > i; i++){
    if(!lck[A[nw][1][i]]){
      lck[A[nw][1][i]] = true;
      ans[A[nw][1][i]] = (cl+1)%2;
      DFS(A[nw][1][i],ans[A[nw][1][i]]);
    }
  }
}
int main() { 
  int n;cin>>n;
  for(int i = 0; n-1 > i; i++){
    int u,v,w;cin>>u>>v>>w;u--;v--;
    A[u][w%2].push_back(v);
    A[v][w%2].push_back(u);
  }
  ans[0]=0;
  DFS(0,0);
  for(int i = 0; n > i; i++){
    cout << ans[i] << endl;
  }
}




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

const int mxN = 1e5 + 5;
long long a[mxN], dp[mxN];
int main() {
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	for(int i = 2; i <= n; ++i) {
		dp[i] = 2e9 + 5;
		for(int j = 1; j <= 2; ++j) {
			if(i - j < 1)
				continue;
			dp[i] = min(dp[i], abs(a[i] - a[i - j]) + dp[i - j]);
		}
	}
	cout << dp[n];
}


Measured memory_bytes: 1792
#include <unordered_map>
  #include <functional>
  #include <algorithm>
  #include <iostream>
  #include <climits>
  #include <vector>
  #include <stack>
  #include <queue>
  #include <map>
  #include <set>
  #define mod 1000000007
  using namespace std;
  #define ll long long int

  int main()
  {
    // freopen("input1.txt","r",stdin);
    // freopen("output1.txt","w",stdout);
    
    int d,t,s;
    cin>>d>>t>>s;
    double x=(double)d/s;
    if(x<=t)
    {
      cout<<"Yes";
    }
    else
    {
      cout<<"No";
    }
  }

Measured memory_bytes: 3612
#include<stdio.h>
#include<stdlib.h>

typedef struct contry{
        char name[22];
        int point;
} Contry;

int cmp(const void *a, const void *b){
        return ((Contry *)b)->point -((Contry *)a)->point;
}

int main(void){
        int flag = 0;
        while(1){
                int n;
                scanf("%d", &n);
                if(n==0) break;
                if(flag) puts("");
                else flag = 1;

                Contry contries[n];
                for(int i=0; i<n; i++){
                        char name[21];
                        int w, l, d;
                        scanf("%s %d %d %d", contries[i].name, &w, &l, &d);
                        contries[i].point = w*3+d;
                }

                qsort(contries, n, sizeof(Contry), cmp);
                for(int i=0; i<n; i++){
                        printf("%s,%d\n", contries[i].name, contries[i].point);
                }
        }
        return 0;
}


Measured memory_bytes: 2076
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

int x[50];

int main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		for (int j = 0; j < k; j++) {
			int ips;
			cin >> ips;
			x[ips]++;
		}
	}
	int cnt = 0;
	for (int i = 1; i <= m; i++) {
		if (x[i] == n)cnt++;

	}
	print(cnt);







	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10,mod=1e9+7;
int n,k,a[maxn];
ll Min,Max;
ll fac[maxn],inv[maxn];
ll fpm(ll a,ll b){
    ll ret=1ll;
    for(;b;b>>=1,a=a*a%mod)
        if(b&1)ret=ret*a%mod;
    return ret;
}
void init(){
    fac[0]=inv[0]=1;
    for(int i=1;i<=n;++i){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=fpm(fac[i],mod-2);
    }
}
ll C(ll n,ll k){
    if(n<0||k<0||n-k<0)return 0;
    return fac[n]*inv[k]%mod*inv[n-k]%mod;
}

void solve(){
    ios::sync_with_stdio(false);
    cin>>n>>k;
    init();
    for(int i=1;i<=n;++i){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i){
        Min+=1ll*(a[i]+mod)*C(n-i,k-1)%mod;
        Min%=mod;
    }
    sort(a+1,a+n+1,greater<int>());
    for(int i=1;i<=n;++i){
        Max+=1ll*(a[i]+mod)*C(n-i,k-1)%mod;
        Max%=mod;
    }
    cout<<(Max-Min+mod)%mod<<endl;
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const double pi = 3.141592653589793;

#define INF 1000000000000

int min(int a,int b){
  if(a<b)return a;
  else return b;
}
signed main(){
  int n;string s;
  cin>>n>>s;
  int ans=0;
  rep(i,1000){
    int a=i%10;
    int b=(i%100)/10;
    int c=i/100;

    int p=INF,q=INF,r=INF;
  rep(j,n){
    if(s[j]-'0'==c){p=min(j,p);}
    if(s[j]-'0'==b&&j>p){q=min(q,j);}
    if(s[j]-'0'==a&&j>q){r=min(j,r);}
  }
  if(r!=INF){ans++;}
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define M 1046527
#define NIL (-1)
#define L 14
char H[M][L];
int getChar(char ch){
    if(ch=='A') return 1;
    else if(ch=='C') return 2;
    else if(ch=='G') return 3;
    else if(ch=='T') return 4;
    else return 0;
}
long long getkey(char str[]){
    long long sum=0,p=1,i;
    for(i=0;i<strlen(str);i++){
        sum+=p*(getChar(str[i]));
        p*=5;
    }
    return sum;
}
int h1(int key){
    return key%M;
}
int h2(int key){
    return 1+(key%(M-1));
}
int find(char str[]){
    long long key,i,h;
    key=getkey(str);
    for(i=0;;i++){
        h=(h1(key)+i*h2((key)))%M;
        if(strcmp(H[h],str)==0) return 1;
        else if(strlen(H[h])==0) return 0;
    }
    return 0;
}
int insert(char str[]){
    long long key,i,h;
    key=getkey(str);
    for(i=0;;i++){
        h=(h1(key)+i*h2(key))%M;
        if(strcmp(H[h],str)==0) return 1;
        else if(strlen(H[h])==0){
            strcpy(H[h],str);
            return 0;
        }
    }
    return 0;
}

int main() {
    int i,n,h;
    char str[L],com[9];
    for(i=0;i<M;i++){
        H[i][0]='\0';
    }
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s %s",com,str);
        if(com[0]=='i'){
            insert(str);
        }else{
            if(find(str)){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 16092
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int K;
  string S;
  cin >> S >> K;
  long int ans=0;
  
  if(S[0] != S[S.size()-1]){ //最初と最後の文字が一致してないなら
    for(int i=0; i<S.size()-1 ; i++){
      if(S[i] == S[i+1]){
        ans++;
        S[i+1] = '!';
      }
    }
    ans *= K;
    cout << ans << endl;
    return 0;
  }
  
  //最初と最後の文字が一致してるなら
  long int start_size = 1;
  long int end_size = 1;
  for(int i=0; i<S.size()-1; i++){
    if(S[i] == S[i+1]) start_size++;
    else break;
  }
  for(int i=S.size()-1; i>=0; i--){
    if(S[i] == S[i-1]) end_size++;
    else break;
  }
  
  if(start_size == S.size()){//全部同じ文字なら
    ans = S.size()*K/2;
    cout << ans << endl;
    return 0;
  }
  
  //まず最初と最後の文字の部分を数える(i)
  const long int len = start_size + end_size; 
  ans = start_size/2  +  (len/2) *(K-1)  + end_size/2;  
  
  //最後に真ん中の文字の部分の連続部分を数える(ii)
  long int count = 0;
  for(int i=start_size; i<S.size()-1 -end_size; i++){
    if(S[i]==S[i+1]){
      count++;
      S[i+1] = '!';
    }
  }
  count *= K;
  
  //(i) + (ii)
  ans = ans + count;
  
  cout << ans << endl;
  
  return 0;
}
 
  
  

Measured memory_bytes: 256
h, w, a, b = map(int, input().split(" "))
div = 10 ** 9 + 7
size = h + w - 1

fact = [0] * size
inverse = [0] * size
inv_calced = [0] * size
fact[:2] = [1, 1]
inverse[:2] = [1, 1]
inv_calced[:2] = [0, 1]

for i in range(2, size):
  fact[i] = fact[i - 1] * i % div
  inv_calced[i] = -inv_calced[div % i] * (div // i) % div
  inverse[i] = inverse[i - 1] * inv_calced[i] % div
  
result = 0
for x in range(b, w):
  y = h - a - 1
  temp_1 = (fact[x+y] * inverse[x] % div) * inverse[y] % div
  temp_2 = (fact[h+w-x-y-3] * inverse[w-x-1] % div) * inverse[h-y-2] % div
  result += ((temp_1 % div) * (temp_2 % div)) % div

print(result % div)

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


def solve(A: int, B: int, T: int):
    count = 0
    for i in range(1,T+1,1):
        if i%A == 0:
            count += B
    print(count)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(A, B, T)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
using namespace std;
using ll=long long;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>

int main()
{
	ll N, x;
	ll a;
	vector<ll> box;
	cin >> N >> x;
	ll sum = 0;
	for (size_t i = 0; i < N; i++)
	{
		cin >> a;
		box.push_back(a);
		sum += a;
	}
	int index = 1;
	while (index<N)
	{
		if (box[index] + box[index - 1] <= x) { index++; continue; }
		ll subrange = (box[index] + box[index - 1])-x;
		box[index] -= subrange;
		if (box[index] < 0) {
			box[index - 1] += box[index];
			box[index] = 0;
		}
		index++;
	}
	for (auto a : box) {
		sum -= a;
	}
	cout << sum << endl;
    return 0;
}



Measured memory_bytes: 1400
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;

#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    bool two = false;
    int count = 0;
    for (int i = 0; i < n; i++) {
      int k;
      cin >> k;
      if (k > 1) two = true;
      if (k > 0) count++;
    }
    if (two)
      cout << count + 1 << endl;
    else
      cout << "NA" << endl;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S; cin >> S;
  int N = S.size(); S += "0";
  reverse(S.begin(), S.end());
  vector<int> T(N+1, 0);
  vector<int> X(N+1, 0);
  vector<int> A(2019, 0);
  int MOD = 2019;
  T[1] = (S[1]-'0')%MOD; // 初期値
  X[0] = 1; // 初期値
  A[0]++; A[T[1]]++; // 初期値
  for(int i = 1; i < N; i++){
    X[i] = (X[i-1] * 10)%MOD;
    T[i+1] = (T[i] + X[i] * (S[i+1]-'0'))%MOD;
    A[T[i+1]]++;
  }
  int ans = 0;
  REP(i, 2019){
    ans += A[i]*(A[i]-1)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5124
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 result = 0;
		for(int i = A; i <= B; i++) {
			int num1 = i / 10000;
			int num2 = i / 1000 % 10;
			int num3 = i / 10 % 10;
			int num4 = i % 10;
			if(num1 == num4 && num2 == num3) {
				result++;
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 27064
import heapq
import math
n, m = map(int, input().split())
src = list(map(int, input().split()))
new_src = []
for s in src:
    new_src.append(s*-1)
heapq.heapify(new_src)

def waru(heap):
    tmp = heapq.heappop(heap)
    heapq.heappush(heap, math.ceil(tmp / 2))
    return heap
for _ in range(m):
    new_src = waru(new_src)
print(sum(new_src)*-1)

Measured memory_bytes: 14532
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PB push_back

int main()
{
    ll N; cin >> N;
    map<ll, ll> value_count;
    vector<ll> A(N);
    rep(i, N){
        cin >> A.at(i);
        value_count[A.at(i)]++;
    }
    ll all_conbination=0;
    for(auto i=value_count.begin(); i!=value_count.end(); i++){
        all_conbination+=i->S*(i->S-1)/2;
    }
    rep(i,N)
        cout << all_conbination-value_count[A.at(i)]+1 << endl;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define fo(i,m,n) for(int i = m; i <= n; i++)
#define fod(i,m,n) for(int i = m; i >= n; i--)
#define fov(i,x) for(auto &i : x)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> _ii;
int n;
vector <i64> a;
i64 ans = 0;
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    cin >> n;
    a.resize(n);
    fov(i,a) cin >> i;
    fo(i,1,n-1)
    {
        if(a[i] >= a[i-1]) continue;
        ans += (a[i-1]-a[i]);
        a[i] = a[i-1];
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4784
#include <iostream>

using namespace std;

const int M = 1e9+7;

int mpow(long long a, int n)
{
  if (n % 2) return mpow(a, n-1) * a % M;
  if (n == 0) return 1;
  return mpow(a*a%M, n/2);
}

int main()
{
  int n; cin >> n;
  long long a[300000]; long long ans = 0;
  for (int i = 0; i < n; ++i) {cin >> a[i]; ans = (ans + a[i]) % M;}
  
  ans = ans * (n-1) % M;
  
  long long x[63] = {};
  for (int i = 0; i < 63; ++i)
    for (int j = 0; j < n; ++j)
      x[i] += (a[j] >> i) & 1;
  
  for (int i = 0; i < 63; ++i)
    ans = (ans - x[i]*(x[i]-1)%M*mpow(2, i)%M + M) % M;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  int result = 0;
  while (n > 0) {
    n /= k;
    result++;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <limits>
using namespace std;
//B - Palace
int main(void){
    int n;
    double t,a;
    std::cin >> n >> t >> a;
    double minTmp=10000;
    int ans=0;
    for(int i=1;i<=n;i++){
        double h;
        std::cin >> h;
        double x=fabs(a-(t-h*0.006));
        if(x<minTmp){
            minTmp=x;
            ans=i;
        }
    }
    std::cout << ans << std::endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> R(n,pair<int,int>());
    vector<pair<int,int>> B(n,pair<int,int>());
    for(int i = 0;i < n;i++)cin >> R[i].first >> R[i].second;
    for(int i = 0;i < n;i++)cin >> B[i].first >> B[i].second;
    sort(R.begin(),R.end());
    sort(B.begin(),B.end());
    int count = 0;
    for(int i = 0;i < n;i++){
        int maxy = -1;
        int maxitr = -1;
        int x = B[i].first;
        int y = B[i].second;
        B[i].first = 2*n+10;
        B[i].second = 2*n+10;
        for(int j = 0;j < n;j++){
            if(R[j].first < x && R[j].second < y){
                if(maxy < R[j].second){
                    maxitr = j;
                    maxy = R[j].second;
                }
            }
        }
        if(maxitr != -1){
            count++;
            R[maxitr].first = 2*n+10;
            R[maxitr].second = 2*n+10;
        }
    }
    cout << count << endl;
    //cin >> n;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n,b;

  while(cin >> n ,n){
    int a[7] = {0};
    while(n--){
      cin >> b;

      if(b < 10) a[0]++;
      else if(b < 20) a[1]++;
      else if(b < 30) a[2]++;
      else if(b < 40) a[3]++;
      else if(b < 50) a[4]++;
      else if(b < 60) a[5]++;
      else a[6]++;
    }

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

  return 0;
}

Measured memory_bytes: 1160
import sys
N,K=map(int, raw_input().split())

H=[]
for i in range(N):
	h=int( sys.stdin.readline() ) 
	H.append(h)

H.sort()

ans=float("inf")
for i in range(N-K+1):
	ans=min( ans, H[i+K-1]-H[i] )

print ans

Measured memory_bytes: 38940
#include <stdio.h>

int main(void)
{
	int N,i,k,k2;
	int x[365],y[365],b[365],p[365],g[365];
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d %d %d %d",&x[i],&y[i],&b[i],&p[i]);
		k=x[i]*b[i]+y[i]*p[i];
		if(b[i]>=5 && p[i]>=2) g[i]=k*8/10;
		else if(b[i]>=5){
			k2=(x[i]*b[i]+y[i]*2)*8/10;
			if(k>k2) g[i]=k2;
			else g[i]=k;
		}
		else if(p[i]>=2){
			k2=(x[i]*5+y[i]*p[i])*8/10;
			if(k>k2) g[i]=k2;
			else g[i]=k;
		}
		else g[i]=k;
		}
	for(i=0;i<N;i++){
		printf("%d\n",g[i]);
	}
	return 0;
}


Measured memory_bytes: 2120
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var A, B, C, D int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &A)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &B)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &C)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &D)

	fmt.Println(min(A, B) + min(C, D))
}

func min(ns ...int) int {
	ret := math.MaxInt64
	for _, n := range ns {
		if n < ret {
			ret = n
		}
	}
	return ret
}


Measured memory_bytes: 640
# https://atcoder.jp/contests/abc065/tasks/arc076_b
import copy


class UnionFind():
    def __init__(self, n):
        super().__init__()
        self.n = n
        self.parents = [-1] * n

    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return True


n = int(input())
rows = [[i] + list(map(int, input().split())) for i in range(n)]

# (start, end, cost)
edges = []

# x座標でソートしてx座標が隣り合う点にをedge候補に
rows_x = copy.deepcopy(rows)
rows_x.sort(key=lambda x: x[1])
for i in range(len(rows)-1):
    left = rows_x[i]
    right = rows_x[i+1]
    edges.append((left[0], right[0], right[1] - left[1]))

# print(rows)
rows_y = copy.deepcopy(rows)
rows_y.sort(key=lambda x: x[2])
for i in range(len(rows)-1):
    down = rows_y[i]
    up = rows_y[i+1]
    edges.append((down[0], up[0], up[2] - down[2]))

# print(edges)

uf = UnionFind(n)

edges.sort(key=lambda edge: edge[2])

result = 0
for edge in edges:
    s, t, c = edge
    unioned = uf.union(s, t)
    if unioned:
        result += c

print(result)


Measured memory_bytes: 217016
fun main(args: Array<String>) {
    val s = readLine()!!.map{ it.toInt()-'0'.toInt() }
    if( s[0]+s[1]+s[2]+s[3]==7 ) { println("${s[0]}+${s[1]}+${s[2]}+${s[3]}=7"); return }
    if( s[0]+s[1]+s[2]-s[3]==7 ) { println("${s[0]}+${s[1]}+${s[2]}-${s[3]}=7"); return }
    if( s[0]+s[1]-s[2]+s[3]==7 ) { println("${s[0]}+${s[1]}-${s[2]}+${s[3]}=7"); return }
    if( s[0]+s[1]-s[2]-s[3]==7 ) { println("${s[0]}+${s[1]}-${s[2]}-${s[3]}=7"); return }
    if( s[0]-s[1]+s[2]+s[3]==7 ) { println("${s[0]}-${s[1]}+${s[2]}+${s[3]}=7"); return }
    if( s[0]-s[1]+s[2]-s[3]==7 ) { println("${s[0]}-${s[1]}+${s[2]}-${s[3]}=7"); return }
    if( s[0]-s[1]-s[2]+s[3]==7 ) { println("${s[0]}-${s[1]}-${s[2]}+${s[3]}=7"); return }
    if( s[0]-s[1]-s[2]-s[3]==7 ) { println("${s[0]}-${s[1]}-${s[2]}-${s[3]}=7"); return }
}

Measured memory_bytes: 33732
from collections import OrderedDict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    od = OrderedDict()
    a = list(map(int, input().split()))
    for i in range(len(a)):
        od[a[i]] = i+1

    p = OrderedDict(
        sorted(od.items(), key=lambda x: x[0])
    )

    print(*[v for k, v in p.items()])


if __name__ == '__main__':
    main()


Measured memory_bytes: 126044
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define sz(x) int(x.size())
#define pb push_back
#define int long long

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7;

int mpow(int a, int n)
{
	int r = 1;
	a %= MOD;
	while (n) {
		if (n&1) r = r*a % MOD;
		a = a*a % MOD;
		n >>= 1;
	}
	return r;
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k; cin >> n >> k;
	int ans = 0;
	vector<int> dp(k+1, 0);
	for (int x = k; x >= 1; --x) {
		int ct = k/x;
		int tot = mpow(ct, n);
		// cerr << tot << ' ' << ct << ' ';
		for (int y = 2*x; y <= k; y += x) {
			tot = tot - dp[y];
			if (tot < 0) tot += MOD;
		}
		dp[x] = tot;
		// cerr << x << ' ' << dp[x] << "\n";
		ans += x * dp[x]; ans %= MOD;
	}
	cout << ans%MOD;
}

Measured memory_bytes: 4028
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> P;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n,w,d;

bool cmp(const P& a, const P& b){
  return a.first*a.second < b.first*b.second;
}

int main(){
  while(scanf("%d%d%d",&n,&w,&d) && n+w+d){
    vector<P>cake;
    cake.push_back(P(w,d));

    rep(i,n){
      int p,s;
      scanf("%d%d", &p,&s); p--;
      P c = cake[p]; cake.erase(cake.begin()+p);
      P f,g;
      s %= c.first+c.second;
      if(s <= c.first){
	f.first = s; f.second = c.second;
	g.first = c.first-s; g.second = c.second;
      }else{
	int tmpd = s-c.first;
	f.first = c.first; f.second = tmpd;
	g.first = c.first; g.second = c.second-tmpd;
      }
      if(f.first*f.second > g.first*g.second) swap(f,g);
      cake.push_back(f);
      cake.push_back(g);
      //      rep(i,cake.size()) cout << cake[i].first << " "<< cake[i].second << " "; cout << endl;
    }

    sort(cake.begin(), cake.end(), cmp); 
    rep(i,cake.size())  cout << (i?" ":"") << cake[i].first*cake[i].second; cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
a = [i for i in input().split()]
stack = []
for i in a:
    if i.isdecimal():
        stack.append(int(i))
    elif i == '+':
        c = stack[-1]
        stack.pop()
        c += stack[-1]
        stack.pop()
        stack.append(c)
    elif i == '-':
        c = -stack[-1]
        stack.pop()
        c += stack[-1]
        stack.pop()
        stack.append(c)
    elif i == '*':
        c = stack[-1]
        stack.pop()
        c *= stack[-1]
        stack.pop()
        stack.append(c)
print(stack[-1])



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

int main() {

  int N, L;
  cin >> N >> L;

  vector<string> S(N);
  
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }

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

  for (int i = 0; i < N; i++) {
    cout << S[i];
  }

  cout << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>


#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 VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S,False(1,-1);
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

template<typename A,size_t N,typename T>
void Fill(A(&array)[N],const T &val){
    fill((T*)array,(T*)(array+N),val);
}

const ll INF = 1e10;
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> cnt(n, 1);
    vector<bool> flag(n, false);
    flag[0] = true;

    rep(i, m){
        int x, y;
        cin >> x >> y;
        x--;y--;

        if(flag[x]){
            flag[y] = true;
            cnt[x]--;
            cnt[y]++;
            if(cnt[x] <= 0)flag[x] = false;
        }

        else {
            cnt[x]--;
            cnt[y]++;
        }
    }

    int res = 0;
    rep(i, n)if(flag[i])res++;
    cout << res << endl;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if (a*b>c*d) {
		cout<<a*b<<endl;
	} else if (a*b<c*d) {
		cout<<c*d<<endl;
	} else {
		cout<<a*b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  string s;
  cin >> s;
  
  ll x, y;
  cin >> x >> y;
  
  vector<vector<ll>> xydir(2, vector<ll>(0));
  ll dir = 0, t = 0;
  for (ll i = 0; i < s.size(); i++){
    if (s[i] == 'T'){
      if (t != 0){
        xydir[dir].emplace_back(t);
      }
      dir = 1 - dir;
      t = 0;
    }
    else {
      t++;
    }
  }
  if (t != 0)
    xydir[dir].emplace_back(t);


  ll sumx = 0, sumy = 0;
  for (ll i = 0; i < xydir[0].size(); i++){
    sumx += xydir[0][i];
  }
  for (ll i = 0; i < xydir[1].size(); i++){
    sumy += xydir[1][i];
  }


  if (sumx < abs(x) || sumy < abs(y) || (sumx % 2 != abs(x) % 2) || (sumy % 2 != abs(y) % 2)){
    cout << "No" << endl;
  }
  else {
    ll a = (sumx + x)/2;
    ll b = (sumy + y)/2;

    vector<vector<ll>> dpx(xydir[0].size() + 1, vector<ll>(a + 1, 0));
    dpx[0][0] = 1;
    for (ll i = 1; i < xydir[0].size() + 1; i++){
      for (ll j = 0; j < a + 1; j++){
        if (j >= xydir[0][i-1])
          dpx[i][j] = dpx[i-1][j] | dpx[i-1][j-xydir[0][i-1]];
        else
          dpx[i][j] = dpx[i-1][j];
      }
      if (s[0] == 'F' && i == 1)
        dpx[i][0] = 0;
    }
    vector<vector<ll>> dpy(xydir[1].size() + 1, vector<ll>(b + 1, 0));
    dpy[0][0] = 1;
    for (ll i = 1; i < xydir[1].size() + 1; i++){
      dpy[i][0] = 1;
      for (ll j = 0; j < b + 1; j++){
        if (j >= xydir[1][i-1])
          dpy[i][j] = dpy[i-1][j] | dpy[i-1][j-xydir[1][i-1]];
        else
          dpy[i][j] = dpy[i-1][j];
      }
    }
    if (dpx[xydir[0].size()][a] && dpy[xydir[1].size()][b])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }


  return 0;
}


Measured memory_bytes: 58960
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a[1000006],n,k,i,j,d,x,res=0;
int main()
{
	
	cin>>n>>k;
	for(i=1;i<=k;i++)
	{
		cin>>d;
		for(j=1;j<=d;j++)
		{
			cin>>x;
			a[x]++;
		}	
	}
	for(j=1;j<=n;j++)
		{
			if(a[j]==0)res++;
		}
	cout<<res;
	
}

Measured memory_bytes: 3636
#include    <iostream>
#include    <cstdio>

using namespace std;

int main() {
    double r;
    // const double PI = 3.14159265;
    const double PI = 3.14159265358979323846;

    cin >> r;
    printf("%.6f %.6f\n", r*r*PI, 2*r*PI);

    return 0;
}


Measured memory_bytes: 3200
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int open[]= new int[n];
		int p[][] = new int[n][11];
		
		for(int i=0;i<n;i++){
			
			int a = 0;
			for(int j=0;j<10;j++){
				int in = sc.nextInt();
				a <<=1; a|=in;
			}
			open[i] = a;
		}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<11;j++){
				p[i][j] = sc.nextInt();
			}
		}
		
		int ans = (int)-1e9;
		for(int i=1;i<(1<<10);i++){
			int tmp = 0;
			for(int j=0;j<n;j++){
				tmp += p[j][sameBit(i, open[j])];
			}
			ans = Math.max(ans, tmp);
		}
		System.out.println(ans);
	}
	static int sameBit(int a, int b){
		int c = a&b;
		int cnt =0;
		while(c>0){
			cnt += c&1;
			c>>=1;
		}
		
		return cnt;
	}
}


Measured memory_bytes: 26212
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9 + 5

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}
	vector<int> dp(n, INF);
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 1; j < k+1; j++){
			if(i+j < n){
				dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
			}
		}
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
long long int GCD(long long int a,long long int b){
    if(b==0){
        return a;
    }
    return GCD(b,a%b);
}
int main(){
    int N,X; cin>>N>>X;
    vector<long long int> x(N,0);
    vector<long long int> sa(N,0);
    for(int i=0;i<N;i++){
        cin>>x[i];
        sa[i]=abs(x[i]-X);
    }

    if(N==1){
        cout<<sa[0];
        return 0;
    }
    long long int gcd=sa[0];
    for(int i=i;i<N;i++){
        gcd=GCD(gcd,sa[i]);
    }
    cout<<gcd;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,k,r,s,p;cin>>n>>k>>r>>s>>p;
    string t;cin>>t;
    char use[n][2];
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(t[i]=='r'){
            if(i<k){
                ans+=p;
                use[i][0]=use[i][1]='p';
            }
            else{
                if(use[i-k][0]!='p' || use[i-k][1]!='p'){
                    ans+=p;
                    use[i][0]=use[i][1]='p';
                }
                else{
                    use[i][0]='r';
                    use[i][1]='s';
                }
            }
        }
        else if(t[i]=='p'){
            if(i<k){
                ans+=s;
                use[i][0]=use[i][1]='s';
            }
            else{
                if(use[i-k][0]!='s' || use[i-k][1]!='s'){
                    ans+=s;
                    use[i][0]=use[i][1]='s';
                }
                else{
                    use[i][0]='p';
                    use[i][1]='r';
                }
            }
        }
        else{
            if(i<k){
                ans+=r;
                use[i][0]=use[i][1]='r';
            }
            else{
                if(use[i-k][0]!='r' || use[i-k][1]!='r'){
                    ans+=r;
                    use[i][0]=use[i][1]='r';
                }
                else{
                    use[i][0]='p';
                    use[i][1]='s';
                }
            }
        }
    }
    cout<<ans;

}



Measured memory_bytes: 720
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
double pie=3.14159265358979;
long long mod=998244353;
//
int n,m;
int d[200000];
int ans[200000];
vector<int> e[200000];
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		d[i]=1e9+7;
	}
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	queue<pair<int,int> > que;
	pair<int,int> hoge;
	hoge.first=0;
	hoge.second=0;
	que.push(hoge);
	d[0]=0;
	while(!que.empty()){
		pair<int,int> now=que.front();
		que.pop();
		for(int i=0;i<e[now.first].size();i++){
			int mow=e[now.first][i];
			if(d[mow]==1e9+7){
				d[mow]=now.second+1;
				que.push(make_pair(mow,now.second+1));
				ans[mow]=now.first;
			}
		}
	}
	bool f=true;
	for(int i=0;i<n;i++){
		if(d[i]==1e9+7){
			f=false;
			break;
		}
	}
	if(!f){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
		for(int i=1;i<n;i++){
			cout<<ans[i]+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 13372
n,k = list(map(int,input().split()))

a = 4;b = 2;c = 0;d = 9;e = 7
f = [a,b,c,d,e]
ans = 0
for i in range((n-2)%11):
	if k in (a,b,c,d,e):
		ans += 1
	a = (a+8)%11
	b = (b+8)%11
	c = (c+8)%11
	d = (d+8)%11
	e = (e+8)%11

print(ans+((n-2)//11)*5)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll ans=0;
	rep(i,0,4){
		char c;
		c=getchar();
		if(c=='+')ans++;
		else ans--;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
using namespace std;
struct Node{
    int key;
    Node *right;
    Node *left;
    Node *parent;
};

Node *root, *NIL;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node* treeSearch(Node *u, int k){
    while (u != NIL && k != u->key){
        if (k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}
Node nodeSearch(Node u, int k){
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
    Node y; // node to be deleted
    Node x; // child of y



}

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node*)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL){
        y = x;
        if (z->key < x->key) x = x->left;
        else x = x->right;
    }
    z->parent = y;
    if (y == NIL) root = z;
    else{
        if (z->key < y->key) y->left = z;
        else y->right = z;
    }
}

void inorder(Node *u){
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}
void preorder(Node *u){
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
    int n, i, x;
    string cmd;
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
        cin >> cmd;
        if (cmd == "find"){
            scanf("%d", &x);
            Node *t = treeSearch(root, x);
            if ( t != NIL ) printf("yes\n");
            else printf("no\n");
        } else if (cmd == "insert"){
            // insert
            scanf("%d", &x);
            insert(x);
        } else if (cmd == "print"){
            // print
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } else if (cmd == "delete"){
            // delete
            //scanf("%d", &x);
            //treeDelete(treeSearch(root, x));
        }
    }

    return 0;
}



Measured memory_bytes: 26732
A = list(input().strip())
B = list(input().strip())
C = list(input().strip())
 
current = A
currentName = 'A'
while True:
    if len(current) == 0:
        break
    card = current.pop(0)
    if card is 'a':
        current = A
        currentName = 'A'
    elif card is 'b':
        current = B
        currentName = 'B'
    else:
        current = C
        currentName = 'C'
 
print(currentName)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
   while (x->left != NIL){
    x = x->left;
}
return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key) return u;

  if(k < u->key) return treeSearch(u->right,k);

  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
      }
  y = x->parent;

  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else x = x->right; 
  }
  z->parent = y;

  if(y == NIL){
    root = z;
  }
  else if (z->key < y->key){
    y->left = z;
  }
  
  else y->right = z;
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" ");
    printf("%d",u->key);
    inorder(u->right);
  }
 
}




void preorder(Node u){
  
  
    if (u != NIL) {
      printf(" ");
      printf("%d",u->key); 
      preorder(u->left);
      preorder(u->right);
    
 
    
    }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n,m,pos=0;
    cin>>n>>m;
    vector<pair<int,int>> pa(n);
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        pa[i]={a,b};
    }
    sort(pa.begin(),pa.end());
    int ans=0;
    priority_queue<int> que;
    for(int i=1;i<=m;i++){
        while(pa[pos].first==i){
            que.push(pa[pos].second);
            pos++;
            if(pos==n) break;
        }
        if(!que.empty()) {
            ans+=que.top();
            que.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int c[3][3];
    rep(i,3) {
        rep(j,3) {
            cin >> c[i][j];
        }
    }
    
    string ans = "No";

    rep(i,c[0][0]+1) {
        rep(j,c[1][2]+1) {
            rep(k,c[2][2]+1) {
                bool tmp = true;
                int a[3],b[3];
                a[0] = i;
                a[1] = j;
                a[2] = k;
                b[0] = c[0][0]-a[0];
                b[1] = c[1][1]-a[1];
                b[2] = c[2][2]-a[2];

                rep(ii,3) {
                    rep(jj,3) {
                        if (c[ii][jj]!=a[ii]+b[jj]) {
                            tmp = false;
                        }
                    }
                }
                if (tmp) {
                    ans = "Yes";
                }
            }
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int X, N, T,time=0;
	cin >> N >> X >> T;
	if (N % X == 0) {
		cout << N / X * T << endl;
		return 0;
	}
	else {
		cout << (N / X + 1) * T << endl;
		return 0;

	}
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define enl cout<<endl
#define pb(x) push_back(x)
#define xx first
#define yy second
typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

int main()
{
	int a,b,n;
	cin>>n>>a>>b;
	int k=abs(b-a)-1;
	if(k%2==0)cout<<"Borys"<<endl;
	else cout<<"Alice"<<endl;
	return 0;
}


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

int main() {
  int n;
  cin>>n;
  ll ans=0;
  int a[100005],b[100005];
  rep(i,n+1) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,n) {
    if (a[i]>=b[i]) {
      ans+=b[i];
    }
    else {
      ans+=a[i];
      b[i]-=a[i];
      ans+=min(a[i+1],b[i]);
      a[i+1]=max(0,a[i+1]-b[i]);
    }
  }
  cout<<ans<<endl;
  return 0;
}



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

const int64_t MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n,k;
  cin >> n >> k;
  
  double p = 0;
  if(k-1<n){
  // (n-k+1)/n
    p += ((double)(n-(k-1)))/(double)n;
  }
  for(int i=1;i<=k-1&&i<=n;i++){
    double pTmp = 1.0/(double)n;
    int value = i;
    while(value < k){
      value *= 2;
      pTmp /= 2.0;
    }
    p += pTmp;
  }
  cout << fixed << setprecision(12) << p << endl;
  return 0;
}



Measured memory_bytes: 3712
import sys
input = sys.stdin.readline

def main():
    S = input()
    N = len(S)
    ans = "Yes"
    for i in range(N):
        if i % 2 == 0 and S[i] == "L":
            ans = "No"
            break
        elif i % 2 == 1 and S[i] == "R":
            ans = "No"
            break
    print(ans)

if __name__ == '__main__': main()

Measured memory_bytes: 3060
#include "bits/stdc++.h"
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 1000000007;

signed main() {
	int N; cin >> N;
	vector<int>x(N), y(N);
	for(int i = 0; i < N; i++)
	{
		int a, b; cin >> a >> b;
		x[i] = a + b; y[i] = a - b;
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	int ans = max(x[N-1]-x[0],y[N-1]-y[0]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6424