akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define REP(i, a, b)  for(int i = a, _b = b; i < _b; ++i)
#define FOR(i, a, b)  for(int i = a, _b = b; i <= b; ++i)
#define FORD(i, a, b) for(int i = a, _b = b; i >= b; --i)

#define endl "\n"
#define newline	cout << "\n"
#define puts(x)	cout << x << endl

using namespace std;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef long long llong;

int check (string & s) {
	int p1 = 0, p2 = s.length()-1;
	int ret = 0;
	while(p1 <= p2) {
		if(s[p1] == s[p2]) {
			p1++;
			p2--;
		}
		else{
			if(s[p1] != 'x' and s[p2] != 'x') return -1;
			if(s[p1] == 'x') p1++;
			else p2--;
			ret++;
		}
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
#ifdef Home
   freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	string s;
	cin >> s;
	cout << check(s) << endl;
   return 0;
}

Measured memory_bytes: 512
import java.util.*;
import java.io.*;

class Main {

	void solve () {

		char[] ar = in.next().toCharArray();
		if (ar[0]==ar[1] || ar[1]==ar[2] || ar[2]==ar[3]) out.println("Bad");
		else out.println("Good");
		
	}

	public static PrintWriter out = new PrintWriter(System.out);
	public static Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

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

using namespace std;
using ll = long long;

int const N = 100 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;

int n;
string s;
char w[128];

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  cin >> s;
  n = s.size();

  int ans = n;
  for(char c = 'a'; c <= 'z'; ++c) {
    int cnt = 0;
    int m = n;
    copy_n(s.begin(), n, w);
    while(1) {
      bool f = false;
      for(int i = 0; i < m; ++i)
        f |= (w[i] != c);
      if(not f)
        break;
      cnt++;
      for(int i = 0; i < m-1; ++i)
        if(w[i] != c && w[i+1] == c)
          w[i] = c;
      m--;
    }

    ans = min(ans, cnt);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */

/* main */
int main(){
    int N;
    cin >> N;
    vector<double> v1(N), v2(N);
    double a, b;
    for (int i = 0; i < N; i++) {
        cin >> v1[i] >> v2[i];
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    if (N % 2 == 1) {
        double minM = v1[N / 2];
        double maxM = v2[N / 2];
        int ans = maxM - minM + 1;
        cout << ans << '\n';
    }
    else {
        double minM = (v1[(N - 1) / 2] + v1[N / 2] ) / 2.0;
        double maxM = (v2[(N - 1) / 2] + v2[N / 2] ) / 2.0;
        int ans = (maxM - minM) * 2 + 1;
        cout << ans << '\n';
    }
}


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

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

    long long num_r=0, num_g=0, num_b=0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') num_r++;
        else if (s[i] == 'G') num_g++;
        else if (s[i] == 'B') num_b++;
    }

    int eq = 0;
    for (int i = 0; i < n-2; i++) {
        for (int j = i+1; j < n-1; j++) {
            int k = (j - i) + j;
            if (k >= n) continue;
            if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) eq++;
        }
    }

    long long ans = num_r*num_g*num_b - eq;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int a = 0;
		int b = 0;
		int d = 0;
		int r = 0;
		double f = 0.0;

		Scanner sc= new Scanner(System.in);

		a = sc.nextInt();
		b = sc.nextInt();

		d = a / b;
		r = a % b;
		f = (double)a / (double)b;

		System.out.println( d + " " + r + " " + BigDecimal.valueOf(f).toPlainString() );
		sc.close();
	}
}


Measured memory_bytes: 26744
#include <iostream>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (a + b < b + c && a + b < a + c) cout << a + b << endl;
  else if (b + c < a + b && b + c < a + c) cout << b + c << endl;
  else cout << a + c << endl;
}

Measured memory_bytes: 256
c,p,l,k;main(n){for(;scanf("%d%*d\n",&n)*n;k=l=!printf("%d\n",k))for(c=1;p=c;p-c&&c&1||(k+=l/2>n?l/2-n:0,l=1-c/4))c=getchar(l++)&5;}

Measured memory_bytes: 0
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
		long k=sc.nextLong();
	
 	if(k>=a){
      	b=b-(k-a);
        a=0;
    	}else{
     	a=a-k;
   	 }
	if(b<0){
    	b=0;
    }
    	System.out.println(a);
  		System.out.println(b);
    }
}



Measured memory_bytes: 23252
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979
 
void mul_mod(ll& a, ll b){
    a *= b;
    a %= MOD;
}
 
void add_mod(ll& a, ll b){
    b += MOD;
    a += b;
    a %= MOD;
}

int main(void){
	int n,i;
	ll a[225816],ans=0ll,tmp;
	vector<ll> x;
	cin >> n;
	a[0] = 0ll;
	for(i=1; i<=n; ++i){
		cin >> a[i];
		a[i] += a[i-1];
	}
	sort(a,a+n+1);
	for(i=0; i<=n; ++i){
		tmp = (ll)((upper_bound(a,a+n+1,a[i])-lower_bound(a,a+n+1,a[i])));
		ans += (tmp-1);
	}
	ans /= 2;
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import numpy as np

n = int(input())
a = np.array(input().split(), np.int64)

S = a[0]

for i in range(1, n):
    S = np.bitwise_xor(S, a[i]) #xor logic
    #print(format(S, 'b')) decimal number→binary number

for i in range(n):
    print(np.bitwise_xor(S, a[i]))

Measured memory_bytes: 53344
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

vll nums(300010, 0);
vll ds(300010, 0);
vll kds(300010, 0);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vll A(N);
    REP(i, 0, N) {
        cin >> A[i];
        nums[A[i]]++;
    }
    REP(i, 0, N + 1) {
        ds[nums[i]]++;
    }
    REP(i, 0, N + 1) {
        kds[i] = ds[i] * i;
        if (i > 0) {
            kds[i] += kds[i - 1];
        }
    }
    PER(i, N - 1, -1) {
        ds[i] += ds[i + 1];
    }
    vll f(N + 1);
    f[0] = inf;
    REP(i, 1, N) {
        f[i] = (kds[i] + i * ds[i + 1]) / i;
    }
    f[N] = kds[N] / N;
    ll ans = N;
    REP(i, 1, N + 1) {
        while (i > f[ans]) {
            ans--;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 12672
def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 0:
        return a

    else:
        return gcd(b, a % b)

A, B, C, D = map(int, input().split())
lcm = C * D // gcd(C, D)
tmp = (B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // lcm - (A - 1) // lcm)
output = B - A + 1 - tmp

print(output)

Measured memory_bytes: 3060
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x
N,X=map(int,input().split())
l=[int(x) for x in input().split()]
l.append(X)
l.sort()
ans=float("inf")
if N==1:
  ans=l[1]-l[0]
else:
  for i in range(N-1):
    ans=min(ans,gcd(l[i+1]-l[i],l[i+2]-l[i+1]))
print(ans)

Measured memory_bytes: 14252
#!/usr/bin/env python3
import sys
from fractions import gcd
input = sys.stdin.readline

class DisjointSparseTable:
    def __init__(self, a):
        # Identity element
        self.e = 0
        self.level = (len(a) - 1).bit_length()
        self.size = 2**self.level
        self.table = [[self.e] * self.size for _ in range(self.level)]
        # Set bottom first
        for i, item in enumerate(a):
            self.table[-1][i] = item
        self.build()

    def build(self):
        for i in range(1, self.level):
            step = 2**i
            lv = self.level - 1 - i
            for mid in range(step, self.size, step*2):
                # Forward
                val = self.e 
                for j in range(step):
                    val = gcd(self.table[-1][mid + j], val)
                    self.table[lv][mid + j] = val
                # Backward
                val = self.e
                for j in range(step):
                    val = gcd(self.table[-1][mid - 1 - j], val)
                    self.table[lv][mid - 1 - j] = val

    # Returns f[l:r)
    def query(self, l, r):
        if l == r:
            return self.e
        elif l == r - 1:
            return self.table[-1][l]
        lv = self.level - (l ^ r-1).bit_length()
        return gcd(self.table[lv][l], self.table[lv][r-1])

 
if __name__ == "__main__":
    n = int(input())
    a = [int(item) for item in input().split()]
    DST = DisjointSparseTable(a)
    ans = 0
    for i in range(0, n):
        ans = max(ans, gcd(DST.query(0, i), DST.query(i+1, n)))
    print(ans)

Measured memory_bytes: 30088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static String X;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        X  = sc.next();
        System.out.println( solve() );
    }

    private static int solve() {
        int T = 0;
        int S = 0;
        for (int i = 0; i < X.length(); i++) {
            char c = X.charAt(i);
            if( c == 'T' ) {
                if( S > 0 ) {
                    S--;
                } else {
                    T++;
                }

            } else {
                S++;
            }
        }
        return T+S;
    }

    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}



Measured memory_bytes: 25268
from sys import stdin
input = stdin.readline

N, M = map(int, input().split())
A = [list(input().rstrip()) for _ in range(N)]
B = [list(input().rstrip()) for _ in range(M)]


for i in range(N - M + 1):
    for j in range(N - M + 1):
        br = False
        for k in range(M):
            for l in range(M):
                if A[i + k][j + l] != B[k][l]:
                    br = True
                    break
            if br:
                break
        if not br:
            print("Yes")
            exit()


print("No")


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;for(int i=0;i<w+2;i++)cout<<"#";
   cout<<endl; for(int i=1;i<=h;i++){
        char arri[w];cout<<"#";
        for(int j=0;j<w;j++){
            cin>>arri[j];cout<<arri[j];
            
        }cout<<"#"<<endl;
    }
    for(int i=0;i<w+2;i++)cout<<"#";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

#define Max 1000000

int prime[Max + 1];
void prime_Eratos(void)
{
        int i,j,k;
        for(i = 0;i <= Max;i++) prime[i] = 1;
        prime[0] = 0;
        prime[1] = 0;
        for(j = 2;j <= sqrt((double)Max) + 1;j++)
                {
                        if(!prime[j]) continue;
                        for(k = 2*j;k <= Max;k += j)
                                {
                                        prime[k] = 0;
                                }
                }
        return ;
}
int main(void)
{
        int a,n,count;
        prime_Eratos();
        while(scanf("%d",&n) != EOF)
        {
                count = 0;
                for(a = 0;a <= n;a++)
                {
                        if(prime[a] == 1) count++;
                }

                printf("%d\n",count);
        }
        return 0;
}

Measured memory_bytes: 4500
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 1000000000000000

int main(){
  int N,K,C;
  string S;
  cin>>N>>K>>C>>S;
  vector<int> left(K),right(K);
  int day=0;
  for(int i=0;i<K;i++){
    while(S.at(day)=='x'){
      day++;
    }
    left.at(i)=day;
    day+=C+1;
  }
  day=N-1;
  for(int i=0;i<K;i++){
    while(S.at(day)=='x'){
      day--;
    }
    right.at(K-i-1)=day;
    day-=C+1;
  }
  for(int i=0;i<K;i++){
    if(left.at(i)==right.at(i)){
      cout<<left.at(i)+1<<endl;
    }
  }
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int a0,a1,a2;
	a0=a1=a2=0;
	for(int i=0;i<n;++i){
		int a,t=0; cin>>a;
		while(a%2==0){
			++t;
			a/=2;
		}
		if(t==0)++a0;
		else if(t==1)++a1;
		else ++a2;
	}
	cout<<(a2-a0>=0||a2-a0>=-1&&a1==0?"Yes"s:"No"s)<<"\n"s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll i = 1; i * i < n; i++)
    if(n % i == 0 && n / i - 1 > i) ans += n / i - 1;
  if(n == 2) ans = 0;
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-10
//#define p 2173412051LL
#define sz 2

using namespace std;

ll a[ 200000 ];

int main() {
	int n, m;
	ll ans = 0;
	scanf( "%d%d", &n, &m );
	for( int i = 0; i < n; ++i )
		scanf( "%lld", &a[ i ] );
	sort( a, a + n );
	for( int i = n - 1 - m; i >= 0; --i )
		ans += a[ i ];
	printf( "%lld", ans );
	return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll dp[101][4][4][4];
//0:A,1:C,2:G,T:3
int main(){
    int n;
    cin>>n;
 for(int i=0;i<4;i++){
     for(int j=0;j<4;j++){
         for(int k=0;k<4;k++){
             if(i==0&&j==1&&k==2)continue;
             if(i==0&&j==2&&k==1)continue;
             if(i==1&&j==0&&k==2)continue;
             dp[3][i][j][k]=1;

         }
     }
 }
 for(int d=3;d<n;d++)for(int i=0;i<4;i++)for(int j=0;j<4;j++)for(int k=0;k<4;k++){
      if(i==0&&j==1&&k==2)continue;
      if(i==0&&j==2&&k==1)continue;
      if(i==1&&j==0&&k==2)continue;
     for(int l=0;l<4;l++){
      if(l==0&&i==1&&k==2)continue;
      if(l==0&&j==1&&k==2)continue;
        (dp[d+1][i][j][k]+=dp[d][l][i][j])%=mod;
     }
 }
 ll ans=0;
for(int i=0;i<4;i++)for(int j=0;j<4;j++)for(int k=0;k<4;k++)(ans+=dp[n][i][j][k])%=mod;
cout<<ans<<endl;
}

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


// doc: https://shibh308.github.io/library/library/lib/classes/segtree.cpp.html
template<typename T>
struct Segtree{
    int n;
    T op;
    vector<T> elm;
    function<T(T, T)> f;

    Segtree(int n, T init, function<T(T, T)> f, T op = T()) :
        n(n),
        op(op),
        elm(2 * n, init),
        f(f)
    {
        for(int i = n - 1; i >= 1; --i)
            elm[i] = f(elm[2 * i], elm[2 * i + 1]);
    }

    Segtree(int n, vector<T> init, function<T(T, T)> f, T op = T()) :
        n(n),
        op(op),
        elm(2 * n),
        f(f)
    {
        for(int i = 0; i < n; ++i)
            elm[i + n] = init[i];
        for(int i = n - 1; i >= 1; --i)
            elm[i] = f(elm[2 * i], elm[2 * i + 1]);
    }

    void set(int x, T val){
        x += n;
        elm[x] = val;
        while(x >>= 1)
            elm[x] = f(elm[2 * x], elm[2 * x + 1]);
    }

    void update(int x, T val){
        x += n;
        elm[x] = f(elm[x], val);
        while(x >>= 1)
            elm[x] = f(elm[2 * x], elm[2 * x + 1]);
    }

    T get(int x, int y) const{
        T l = op, r = op;
        for(x += n, y += n - 1; x <= y; x >>= 1, y >>= 1){
            if(x & 1)
                l = f(l, elm[x++]);
            if(!(y & 1))
                r = f(elm[y--], r);
        }
        return f(l, r);
    }
};


signed main(){
    int n;
    cin >> n;
    vector<i64> l(n), r(n);
    i64 ans = 0;
    vector<pair<int,int>> v;
    for(int i = 0; i < n; ++i){
        cin >> l[i] >> r[i];
        --l[i];
        chmax(ans, r[i] - l[i]);
        v.emplace_back(r[i], l[i]);
    }
    vector<i64> vx, vy;
    sort(v.begin(), v.end());
    for(int i = 0; i < n; ++i){
        vx.emplace_back(v[i].first);
        vy.emplace_back(v[i].second);
    }

    Segtree<i64> seg(n, vy, [](auto x, auto y){return max(x, y);}, -INF);
    Segtree<i64> seg2(n, vy, [](auto x, auto y){return min(x, y);}, INF);

    for(int i = 1; i < n; ++i){
        i64 r0 = v.front().first;
        i64 r1 = v[i].first;
        i64 l0 = seg.get(0, i);
        i64 l1 = seg.get(i, n);
        chmax(ans, r0 + r1 - l0 - l1);
        chmax(ans, r0 + r1 - max(l0, l1) - seg2.get(i, n));
    }
    cout << ans << endl;
}


Measured memory_bytes: 11116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string t = sc.Next();

        StringBuilder sb = new StringBuilder();

        foreach(var c in t)
        {
            if(c == '?')
            {
                sb.Append("D");
            }
            else
            {
                sb.Append(c.ToString());
            }
        }

        string answer = sb.ToString();

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 31904
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        int N;
        String S;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            S = sc.next();

        }

        //len(暫定値)
        int NStart = 0;
        int NEnd = N;
        int window =0;
        int result = 0;



        while (true) {

            window = (NEnd + NStart) / 2;

            //探索
            boolean check = chackSub(S, window);
            if (check) {
                result = window;
                NStart = window;
            } else {
                NEnd = window;
            }
            if(NEnd - NStart  <=1){
                break;
            }
        }

        System.out.println(result);
    }

    private static boolean chackSub(String S, int window) {
        int i = 0;
        HashMap<String,Integer> set = new HashMap<>();
        while (true) {
            int start = i;
            int end = start + window;

            if (end> S.length()) {
                break;
            }

            String sub1 = S.substring(start, end);


            if(set.containsKey(sub1)){
                Integer l1 = set.get(sub1);
                if(l1 + window <= start){
                    return true;
                }
            }else{
                set.put(sub1, start);
            }

            i++;
        }
        return false;
    }

}


Measured memory_bytes: 104560
N, K= map(int, input().split())
h = list(map(int, input().split()))
DP = [float('inf')]*N
DP[0] = 0
for i in range(N-1):
  L = N-1-i
  for j in range(min(K,L)):
    DP[i+j+1] = min(DP[i+j+1], DP[i] + abs(h[i+j+1] - h[i]))  
print(DP[-1])


Measured memory_bytes: 55136
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <stack>
#include <string>
#include <cmath>
#define SIZE 200005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int cnt[SIZE];

int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++)
	{
		int a;
		scanf("%d",&a);a--;
		cnt[a]++;
	}
	vector <int> vx;
	for(int i=0;i<n;i++) vx.push_back(cnt[i]);
	sort(vx.begin(),vx.end());
	int ret=0;
	for(int i=0;i<n-k;i++) ret+=vx[i];
	printf("%d\n",ret);
	return 0;
}



Measured memory_bytes: 2168
#include<stdio.h>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
       int a,b,c,d;
       while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
       {
               int nums[200];
               memset(nums,0,sizeof(nums));
               for(int i=a+1;i<=b;i++)
                nums[i]++;
                for(int i=c+1;i<=d;i++)
                nums[i]++;
                int cnt=0;
                for(int i=0;i<=100;i++)
                        if(nums[i]==2)
                        cnt++;
                printf("%d\n",cnt);
       }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
    int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
    
    int h, w;
    cin >> h >> w;
    
    string field[50];
    for (int i = 0; i < h; i++) cin >> field[i];
    
    for (int x = 0; x < h; x++) {
        for (int y = 0; y < w; y++) {
            if (field[x][y] == '#') continue;
            int num = 0;
            for (int i = 0; i < 8; i++) {
                int nx = x + dx[i], ny = y + dy[i];
                if (0 > nx || nx >= h) continue;
                if (0 > nx || ny >= w) continue;
                if (field[nx][ny] == '#') num++;
            }
            field[x][y] = char(num + '0');
        }
    }
    for (int i = 0; i < h; i++) cout << field[i] << endl;
}


Measured memory_bytes: 256
//152A A - AC or WA
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n , m; cin >> n >> m;
    cout << ( (n == m) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
// AOJ Volume5 0513 Shuffle The Cards

#include <stdio.h>
#include <string.h>

int main(void)
{
	int card[210];
	int n;
	int m;
	int k;
	int i, j;
	int card_next[210];

	
	scanf("%d", &n);

	// カードの初期化
	for (i = 1; i <= 2 * n; i++){
		card[i] = i;
	}

	scanf("%d", &m);
	for (i = 0; i < m; i++){
		scanf("%d", &k);
		if (k == 0){
			for (j = 1; j <= n; j++){
				card_next[j * 2 - 1] = card[j];
				card_next[j * 2    ] = card[j + n];
			}
		}
		else {
			for (j = k + 1; j <= 2 * n; j++){
				card_next[j - k] = card[j];
			}
			for (j = 1; j <= k; j++){
				card_next[j + 2 * n - k] = card[j];
			}
		}
		memcpy(card, card_next, sizeof(card));
	}

	for (i = 1; i <= 2 * n; i++){
		printf("%d\n", card[i]);
	}

	return (0);
}

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

int main() {
    int n;    cin >> n;
    int F[50];
    F[0] = F[1] = 1;
    for ( int i = 2; i <= n; i++ ) { F[i] = F[i - 1] + F[i - 2]; }

    cout << F[n] << endl;

    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
//vector<vector<int>> data(3, vector<int>(4));

int main() {
	unsigned long long	 N, M;cin >> N >> M;
	unsigned long long	 ans = 0;
	if (N >= 3&&M>=3) ans += ((N - 2) * (M - 2));
	else if (N == 1 && M == 1) ans += 1;
	else if (N == 1 || M == 1) ans += (N*M)-2;
	cout << ans << endl;
}

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

using namespace std;

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= N; ++j) {
      int r = R * i;
      int g = G * j;
      if (r + g > N) break;
      int remain = N - (r + g);
      if (remain % B == 0) {
	ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
const ll INF = (1ll << 60);

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

  vector<double> A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  double ans = 0;
  for (ll i = 0; i < N; i++) {
    ans += (double)1 / A[i];
  }

  cout << fixed << setprecision(10);

  cout << (double)1 / ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define MP make_pair
#define pb push_back
const int INF = 1e9;
const int MOD = INF+7;
using i64 = long long;

int main(){
    i64 A,B;
    cin >> A >> B;
    A--;
    i64 a[64]={},b[64]={};

    for(int i=0;i<48;i++){
        a[i] = (1ll<<i)*(A/(2ll<<i));
        if(A%(2ll<<i) >= (1ll<<i)) a[i] += A%(2ll<<i) - (1ll<<i) + 1;
    }
    

    for(int i=0;i<48;i++){
        b[i] = (1ll<<i)*(B/(2ll<<i));
        if(B%(2ll<<i) >= (1ll<<i)) b[i] += B%(2ll<<i) - (1ll<<i) + 1;
    }

    //for(int i=63;i>=0;i--) cout << a[i] << " ";
    for(int i=0;i<64;i++) b[i] -= a[i];
    i64 ans = 0;
    for(int i=0;i<64;i++) ans += (1ll<<i) * (b[i]&1);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    while(s != "-") {
        int m;
        int h;
        int l = s.size();
        scanf("%d", &m);
        while(m) {
            s = s + s;
            scanf("%d", &h);
            s = s.substr(h, l);
            m--;
        }
        cout << s << endl;
        cin >> s;
    }
}


Measured memory_bytes: 3296
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_abc151_d();
	}
  
  	public static void solve_abc151_d(){

		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int W = sc.nextInt();
		char S[][] = new char[H][W];

		for(int i=0;i<H;i++){
			String s = sc.next();
			
			for(int j=0;j<W;j++){
				S[i][j] = s.charAt(j);
			}
		}

		int distMax = 0;
		final int vx[] = {-1,	1,	0,	0	};
		final int vy[] = { 0,	0,	1,	-1	};
		

		//for x
		for(int x=0;x<H;x++){
			for(int y=0;y<W;y++){

				//if char[x][y] == '.'
				if(S[x][y] == '.'){

					//dist[x][y] = bfs
					int distance = solve_abc151_bfs(H, W, S, x, y, vx, vy);

					//if distMax < dist[x][y] then distMax = dist[x][y]
					if(distMax < distance) distMax = distance;
				}
			}
		}
		
		//System.out.println("--------------------------");

		//print distMax
		System.out.println(distMax);

		sc.close();
	}

	public static int solve_abc151_bfs(int H, int W, char[][] maze, int idxStartX, int idxStartY, int[] vx, int[] vy){

		//initialization
		Queue<Integer> qx = new LinkedList<Integer>();
		Queue<Integer> qy = new LinkedList<Integer>();
		int distance[][] = new int[H][W];
		int distMax = 0;
		
		for(int x=0;x<H;x++){
			for(int y=0;y<W;y++){
				distance[x][y]	= Integer.MIN_VALUE;
			}
		}
		
		distance[idxStartX][idxStartY] = 0;

		qx.add(idxStartX);
		qy.add(idxStartY);

		//System.out.println("--------------------------");

		//while queue is not empty
		while(!qx.isEmpty()){

			//poll queue
			int x = qx.poll();
			int y = qy.poll();


			//for vx
			for(int i=0;i<vx.length;i++){
				int nextX = x + vx[i];
				int nextY = y + vy[i];

				//if child in maze & child == '.' & distChild != 0
				if(	nextX >= 0	&&	nextX < H 	&&
					nextY >= 0	&&	nextY < W 	&&
					maze[nextX][nextY] == '.'	&&
					distance[nextX][nextY] == Integer.MIN_VALUE){

					//distChild(dist[i+vx][j+vy]) = distParent + 1
					distance[nextX][nextY] = distance[x][y] + 1;

					//add child to queue
					qx.add(nextX);
					qy.add(nextY);

					//if distMax < distChild then distMax = distChild
					if(distMax < distance[nextX][nextY]) distMax = distance[nextX][nextY];
				}
			}
			//System.out.println("x:" + x + "\ty:" + y);

			//end while
		}
		

		//return distMax
		return distMax;
	}
}

Measured memory_bytes: 29372
#include<iostream>
using namespace std;
int main(){
    int n,i,j;
    cin >> n;
    int a[2][n];
    int b[2][n];
    for(i=0;i<2;i++){
        for(j=0;j<n;j++){
            cin >>a[i][j];
        }
    }
    b[0][0]=a[0][0];
    for(i=1;i<n;i++){
        b[0][i]=b[0][i-1]+a[0][i];
    }
    b[1][0]=b[0][0]+a[1][0];
    for(i=1;i<n;i++){
        if(b[0][i]>b[1][i-1]){
            b[1][i]=b[0][i]+a[1][i];
        }else{
            b[1][i]=b[1][i-1]+a[1][i];        
            }
    }
    cout <<b[1][n-1]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int MOD = 1000000007;

LL N,M,K,C;
LL a,b,c,d;
string s;
LL ans[200010];
int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a;
        if(i%2==0){
            ans[N/2+i/2]=a;
        }else{
            ans[N/2-1-i/2]=a;
        }
    }
    if(N%2==1){
        reverse(ans,ans+N);
    }
    for(int i=0;i<N;i++){
        cout<<ans[i]<<" ";
    }cout<<endl;
    
    return 0;
}


Measured memory_bytes: 3712
def solve(a, b):
    for i in range(1, 1000):
        c = (i-1)*i/2 - a
        d = i*(i+1)/2 - b
        if c == d:
            return c
    return -1

assert solve(8, 13) == 2
assert solve(54, 65) == 1
a, b = map(int, raw_input().split())
print solve(a, b)

Measured memory_bytes: 2568
using System;

class P
{
public static void Main()
{
            //?????????????????????
            string x = Console.ReadLine();

            //?????????????????????????????????
            var y = x.Split(' ');

            //????????????????????????
            Array.Sort(y);

            //?????°???????????????
            int a = Int32.Parse(y[0]);
            int b = Int32.Parse(y[1]);
            int c = Int32.Parse(y[2]);

            //??¨???
            Console.WriteLine(a + " " + b + " " + c);
}
}

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

int main() {
  string s;
  cin >> s >> s;
  cout << 'A' << s[0] << 'C' << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)

vector<pair<int,double> > vs[50];
double dat[10];
double d[50][1<<10];

int n,m,st,gl,tn;
int main(void){
	for(;;){
		scanf("%d%d%d%d%d",&tn,&n,&m,&st,&gl); 
		if(n==0)break;
		rep(i,tn)scanf("%lf",&dat[i]);
		reg(i,1,n)vs[i].clear();
		rep(i,m){
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			vs[a].push_back(mp(b,c));
			vs[b].push_back(mp(a,c));
		}
		
		fill(d[0],d[50],-1.0);
		//rep(i,50)rep(j,20)printf("%f ",d[i][j]);
		typedef pair<double,mp> dmp;
		priority_queue<dmp,vector<dmp>,greater<dmp> >que;
		
		que.push(dmp(0,mp(st,0)));
		while(!que.empty()){
			dmp pa = que.top(); que.pop();
			int no = pa.sec.fir,
				ns = pa.sec.sec;
			double co = pa.fir;
			//printf("(%d %d , %f)",no,ns,co);
			if(d[no][ns]>=0 && d[no][ns] <= co)continue;
			d[no][ns] = co;
			rep(i,tn){
				if(ns&(1<<i))continue;
				int ts = ns | (1<<i);
				rep(j,vs[no].size()){
					mp e = vs[no][j];
					int to = e.fir;
					double tc = co + (e.sec / dat[i]);
					if(d[to][ts] >=0 && d[to][ts] <= tc)continue;
					que.push(dmp(tc,mp(to,ts)));
				}
			}
		}
		
		double ans = -1;
		rep(i,1<<tn){
			double c = d[gl][i];
			if(c<0)continue;
			if(ans<0)ans = c;
			else ans = min(ans,c);
		}
		if(ans<0)printf("Impossible\n");
		else printf("%f\n",ans);
	}
	return 0;
}

Measured memory_bytes: 15028
using System;

class Program
{
  static void Main()
  {
    int h, w, nh;
    string[] data;

    while (true)
    {
      data = Console.ReadLine().Split(' ');
      h = int.Parse(data[0]);
      w = int.Parse(data[1]);

      if (h == 0 && w == 0) break;

      for (int i = 0; i < h; i++)
      {
        nh = i + 1;
        for (int j = 0; j < w; j++)
        {
          if (i * j == 0 || nh == h || j + 1 == w) Console.Write("#");
          else Console.Write(".");
        }
        Console.WriteLine();
      }
      Console.WriteLine();
    }
  }
}

Measured memory_bytes: 8820
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int res[N];
vector < int > edges[N];
void rec(int u , int p){
	res[u] += res[p];
	for(int v = 0; v < edges[u].size(); v ++)
		if(edges[u][v] != p)
			rec(edges[u][v] , u);
}
int main(){
	int n , q; 
	cin >> n >> q;
	for(int i = 1; i < n; i ++){
		int u , v;
		scanf("%d%d" , &u , &v);
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	while(q --){
		int a , b;
		scanf("%d%d" , &a , &b);
		res[a] += b;
	}
	rec(1 , 0);
	for(int i = 1; i <= n; i ++) printf("%d " , res[i]);
}

Measured memory_bytes: 23424
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	long long arr[n+1];
	for(int i=1; i<=n; i++) cin>>arr[i];
	for(int i=1; i<=n; i++) arr[i]-=i;
	sort(arr+1,arr+n+1);
	int p1 = 1;
	int p2 = n;
	long long ret = 0;
	while(p1<p2){
		ret+=arr[p2]-arr[p1];
		p1++;
		p2--;
	}
	cout<<ret;
}

Measured memory_bytes: 5180
A,B=input().split()
a=0
A=int(A)
B=B[::-1]
b=0
for i in range(len(B)):
  c=pow(10,b)
  if B[i]!='.':
    b+=1
    a+=(int(B[i])*c*A)
count=0
for j in range(len(B)):
  if B[j]=='.':
    break
  count+=1
a=a//pow(10,count)
a=int(a)
print(a)

Measured memory_bytes: 9208
#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->left,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 x; 
  
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
  
  if(y->left != NIL) x = y->left;
  else x = y->right;
  
  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
  
  if(y != z) z->key = y->key;
}
  
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->left != NIL)inorder(u->left);
  printf(" %d",u->key);
  if(u->right != NIL)inorder(u->right); 
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL)preorder(u->left);
  if(u->right != NIL)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");
      puts("");
      }
      else {
        printf("no");
        puts("");
      }
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      puts("");
      preorder(root);
      puts("");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  
  return 0;
}



Measured memory_bytes: 20412
#include<stdio.h>
#define N 100
int main(){
  int hako[N];
  int n,i,j;
  int flag = 1;
  int count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&hako[i]);
  }
  while(flag){
    flag=0;
    for(j=n-1;j>0;j--){
      if(hako[j]<hako[j-1]){
	i= hako[j-1];
	hako[j-1]=hako[j];
	hako[j]=i;
	flag =1;
	count++;
      }
    }
  }
  for(i=0;i<n-1;i++) printf("%d ",hako[i]);
  printf("%d\n",hako[n-1]);
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2084
N = int(input())
S = input()
q = S

while "()" in q:
    q = q.replace("()", "")

l = []
r = []
for i in q:
    if i == ")":
        l.append("(")
    else:
        break

for i in q:
    if i == "(":
        r.append(")")

ans = l + list(S) + r
print("".join(map(str, ans)))



Measured memory_bytes: 3060
(n,m)=map(int,input().split())
a=input().split()
a=list(map(int,a))
l=[]
k=0
a=sorted(a)
for i in range(m-1):
    d=abs(a[i]-a[i+1])
    k=k+d
    l.append(d)
# k=k-d
c=n-k
l.append(c)
l=sorted(l)

print(n-l[-1])

Measured memory_bytes: 26420
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#define SIZE 1000000007
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;

int main() {
	int N, Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	vector<int>  l(100000);
	vector<int>  r(100000);
	rep(i, Q) {
		cin >> l[i] >> r[i];
	}
	vector<int> sum(100001);
	int flag = 0, a = 0;
	for (int i = 1; i < N + 1; i++) {
		if (s[i-1] == 'A') {
			flag = 1;
			sum[i] = a;
		}
		else if (s[i-1] == 'C'&&flag == 1) {
			a++;
			sum[i] = a;
			flag = 0;
		}
		else {
			flag = 0;
			sum[i] = a;
		}
	}
	rep(i, Q) {
		cout << sum[r[i]] - sum[l[i]] << endl;
	}
	return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
#define mod  (long long)(1e9+7)
long long a[300010];
int main(){
	int n;
	long long res=0,d=1;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	scanf("%lld",&a[i]);
	for(int j=0;j<60;j++)
	{
		long long c=0;
		for(int i=0;i<n;i++)
		{
			if(a[i]&1)
			c++;
			a[i]>>=1;
		}
		res+=(((c*(n-c))%mod)*d)%mod;
		d*=2;
		d=d%mod; 
	}
	printf("%lld\n",res%mod);
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iomanip>

#define ll long double
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll a,b,h,m;
    cin >> a >> b >> h >> m;
    ll disp = abs(((h*60+m)*0.5) - m*6);
    ll c = a*a + b*b - 2*a*b*cos(disp*M_PI/180);
    ll ans = sqrt(c);
    cout << fixed << setprecision(20) << ans;
    
}









Measured memory_bytes: 4056
#include <bits/stdc++.h>
#define MOD 1000000007
int memo[1001][1001] = {};
char mmm[1001][1001] = {};
using namespace std;
int main(void)
{
  int h, w;
  cin >> h >> w;
  for(int i = 0; i != h; i++)
    for(int j = 0; j != w; j++)
      cin >> mmm[i][j];
  for(int i = 1; i <= h; i++){
    for(int j = 1; j <= w; j++){
      if(i * j == 1) memo[i][j] = 1;
      else{
        memo[i][j] = (memo[i - 1][j] + memo[i][j - 1]) % MOD;
        if(mmm[i - 1][j - 1] == '#')
          memo[i][j] = 0;
      }
    }
  }
  cout << memo[h][w] << endl;
  return 0;
}

Measured memory_bytes: 5120