akhauriyash/Code-Regression huggingface dataset:
#D
class UnionFind():
    # https://www.slideshare.net/chokudai/union-find-49066733
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        # root[x]>=0の場合は、特に直接的な意味を持たない気がする。計算に寄与するので意味はあるのだろうが。
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        # 無結合の時はRank=0,結合して1つ木が深くなると根がRank+=1
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    #
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        # (1)xのランクの方が大きい(位置が深い)場合
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        # (2)yのランクの方が大きい(位置が深い)場合 or 等しい場合
        # また等しい場合、引数の2つめのyの方のランクを1つ増やす
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    # xとyが同じグループに属するか判断
    # Return: True or False
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
###################################################################    
N,K=map(int,input().split())
UN=UnionFind(N)
P=list(map(int,input().split()))
C=list(map(int,input().split()))
for i,num in enumerate(P):
    UN.Unite(i+1,num)
root=set()
loop_score=dict()
loop_len=dict()

#print(UN.root)
for i,node in enumerate(UN.root):
    if i==0:
        pass
    else:
        if node<0:
            #print(i,"is root")
            root.add(i)
            score=0
            ini=i
            leng=0
            while True:
                ret=P[ini-1]
                score += C[ret-1]
                leng +=1
                if ret==i:
                    break
                else:
                    ini=ret
            loop_score[i]=score
            loop_len[i] = leng
            
#print(loop_score)
#print(loop_len)

ans_list=[]
ans=float("-inf")

for i in range(1,N+1):
    t=K
    p=UN.Find_Root(i)
    
    
    #ループした方がいいかの確認
    if loop_score[p]>0:
        tmp=0
        pos=i
        tmp += ((t//loop_len[p])-1)*loop_score[p]
        if tmp>0:
            ans=max(tmp,ans)
        t = (t%loop_len[p])+loop_len[p]
        for j in range(t):
            pos = P[pos-1]
            tmp += C[pos-1]
            ans=max(tmp,ans)

    else:
        tmp=0
        pos=i
        
        for j in range(min(t,loop_len[p]-1)):
            pos = P[pos-1]
            tmp += C[pos-1]
            ans=max(tmp,ans)
    
print(ans)

Measured memory_bytes: 76012
#include <stdio.h>

int main(void){
  char abc[4];

  scanf("%s",abc);

  if(abc[0]!=abc[1]){
    if(abc[1]!=abc[2]){
      if(abc[2]!=abc[0]){
        puts("Yes");
      }else{puts("No");}

    }else{puts("No");}

  }else{puts("No");}


  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

int Fnt(ll a, ll b){
  string c=to_string(max(a,b));
  return (int)c.size();
}
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  // 
  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  ll n;cin>>n;
  ll sqn=sqrt(n);
  int mn=INF;
  for(ll i=1;i<=sqn;i++){
    if(n%i==0){
      mn=min(mn, Fnt(n/i,i));
    }
  }
  P(mn);
  return 0;
}


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

int main(int argc,char **argv) {
	int n;
	cin>>n;
	int h[n+2];
	h[0]=2147483647;
	h[n+1]=2147483647;
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	
	int ans=0;
	int now=0;
	bool up=1;
	for(int i=1;i<=n;i++) {
		if(h[i]<h[i+1]) {
			ans=max(ans,now);
			now=0;
		}
		else now++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,s;
  cin>>k>>s;
  int count=0;
  for (int x=0;x<=k;x++) {
    for (int y=0;y<=k;y++) {
      if (0<=s-x-y && s-x-y<=k) count++;
    }
  }
  cout<<count<<endl;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define int long long

#define upper(n,m) (n+m-1)/m
#define rounding(n) (int)((double)n+0.5)

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define ALL(a) a.begin(),a.end()

#define coutALL(i,a) {int i=0;for(int e:a) cout<<(i++?" ":"")<<e; cout<<endl;}
#define coutYN(a) cout<<(a?"Yes":"No")<<endl;
#define coutyn(a) cout<<(a?"yes":"no")<<endl;

#define deb cout<<"debug"<<endl
#define debn(n) cout<<"debug: "<<n<<endl

const int INF=INT_MAX;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
//const int dx[]={0,1,0,-1},dy[]={-1,0,1,0};
const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using namespace std;

typedef pair<int,int> P;
typedef long long LL;

long long ncm(int n,int m){

  long long r=1;

  for(int i=1;i<=n;i++){

    r*=m-i+1;
    r/=i;

  }

  return r;

}


signed main(){

  ios::sync_with_stdio(false);

  int n,a,b;
  cin>>n>>a>>b;

  vector <LL> v(n);
  REP(i,n) cin>>v[i];

  sort(ALL(v),greater <long long>());

  long double ave[51]={},max_ave=0;

  REAP(i,a,b+1){

    REP(j,i)  ave[i]+=v[j];
    ave[i]/=i;
    max_ave=max(max_ave,ave[i]);

  }

  LL ans=0;

  REP(i,51){

    if(ave[i]!=max_ave) continue;

    vector <LL> num;
    set <LL> num_list;
    LL r=1;

    REP(j,i) num_list.insert(v[j]),num.pb(v[j]);

    for(int e:num_list){

      int x=count(ALL(num),e),y=count(ALL(v),e);
      r*=ncm(x,y);

    }

    ans+=r;

  }

  cout<<setprecision(10)<<fixed<<max_ave<<endl<<ans<<endl;

  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const long long INF = INT_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, cnt = 0, w, h;
string s;
vector<ll> v;
vector<ll> v1;
vector < pair<ll, ll > > vp;
vector < pair<ll, ll > > vp1;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
set<ll> st;
map<char, ll> mp;

/*--------------------template--------------------*/



int main()
{
	cin >> n;
	v.resize(3 * n);
	REP(i, 3 * n) cin >> v[i];
	sort(ALL(v));
	FOR(i,n,3*n)
	{
		sum += v[i];
		i++;
	}
	cout << sum << endl;
}

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

using ll = long long;

int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<ll> V(n);
  for(ll& i : V)
    cin >> i;
  int pt = 0;
  int ans = 0;
  while(pt < n-1) {
    ++ans;
    pt += (k-1);
  }
  cout << ans << endl;
  return 0;

}


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

#define NUL NULL

struct node{struct node *p, *r, *l; int key;};
typedef struct node * Node;
Node root;



void inorder(Node root){
  if(root != NUL){
    inorder(root->l);
    printf(" %d", root->key);
    inorder(root->r);
  }
}



void preorder(Node root){
  if(root != NUL){
   printf(" %d", root->key);
   preorder(root->l);
   preorder(root->r);
 }
}



void insert(int k){
  Node y = NUL, x = root, z=malloc(sizeof(struct node));

  z->key = k;
  z->l = NUL;
  z->r = NUL;

  while(x!=NUL){
    y = x;
    if(z->key<x->key){
      x=x->l;
    }else{
      x=x->r;
    }
  }

  z->p=y;
  if(y == NUL){
    root=z;
  }else if(z->key<y->key) {
    y->l=z;
  }else{
    y->r=z;
  }
}


int main(){
  int n,i,x;
  char option[100];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",option);
    if(option[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(option[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 24040
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
int a,b,c;
  cin>>a>>b>>c;
  cout<<c<<' '<<a<<' '<<b;
}

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

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

int main()
{
	int n, m, tmp;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d", &tmp);
		n -= tmp;
	}
	if (n < 0)
		n = -1;
	printf("%d", n);

	return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<map>
#include<queue>
#include <deque>
#include <list>
#include <ctime>
#include <stack>
#include <vector>
#include<set>
#define MAX 1005
typedef long long ll;
const int inf = 0x3f3f3f3f;
using namespace std;

char s[22];
stack<int> a ;

int main()
{
    while(~scanf("%s",s))
    {
        int num ;
        scanf("%d",&num);
        int len=strlen(s);
        int l=s[0]-'0';
        for(int i=1;i<len;i++)
        {
            if(i%2==1)
            {
                if(s[i]=='+')
                    l=l+s[i+1]-'0';
                else
                    l=l*(s[i+1]-'0');
            }
        }
        while(!a.empty()) a.pop();
        int m=1;
        for(int i=0;i<len;i++)
        {
            if(i%2==1)
            {
                if(s[i]=='*')
                {
                   // cout<<m<<endl ;
                    m=a.top();
                    m=m*(s[i+1]-'0');
                    a.pop();
                    a.push(m);
                    i++;
                }
            }
            else
            {
               // cout<<s[i]-'0'<<endl;
                a.push(s[i]-'0');
            }
        }
        m=0;
        while(!a.empty())
        {
            m+=a.top();
            a.pop();
        }
        //cout<<m<<"  "<<l<<endl ;
        if(num==l&&num!=m) printf("L\n");
        else if(num==m&&num!=l)  printf("M\n");
        else if(num==m&&num==l)  printf("U\n");
        else printf("I\n");
    }
    return 0 ;
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

int INF = 1ll << 30;

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

int main(){
  string s, t;
  cin >> s >> t;
  int ans = INF;
  
  rep(i, 0, s.size()-t.size()+1){
    int cnt = 0;
    rep(j , 0, t.size()){
      if(t[j] != s[i+j])
        cnt++;
    }
    chmin(ans,cnt);
    
  }
  
  cout << ans << endl;
  
  return 0;
  
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int count = 0;
	if (a != b)count++;
	if (b != c)count++;
	if (a != c)count++;
	if (count == 0)count++;
	cout << count;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<char> a,b;
    bool ans = true;
    for(int i = 0; i < n/ 2; i++){
        char c = s[i];
        a.push_back(c);
    }
    for(int i = n / 2 + 1; i < n; i++){
        char c = s[i];
        b.push_back(c);
    }
    for(int i = 0; i < n / 2; i++){
        if(s[i] != s[n - 1 - i])
        ans = false;
    }
    for(int i = 0; i < a.size() / 2; i++){
        if(a[i] != a[a.size() - 1 - i])
        ans = false;
    }
    for(int i = 0; i < b.size() / 2; i++){
        if(b[i] != b[b.size() - i - 1])
        ans = false;
    }
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define rep(a,b,c) for(int a=(int)b;a<(int)c;a++)
#define repe(a,b,c) for(int a=(int)b;a<=(int)c;a++)
#define repk(a,b,c,k) for(int a=(int)b;a<(int)c;a+=(int)k)
#define comeback std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define int long long int
#define pii pair<int,int>
#define ful(a) a.begin(),a.end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
using namespace std;
int em(int x,int n)
{
    if(n==0)
    return 1;
    else if(n%2==0)
    return em((x%mod*x%mod)%mod,n/2);
    else
    return (x%mod*em((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int dp[102][100009];
//int dp1[102][100009];	
/*int a[102];
int li;
int fun(int ind,int rem){
	if(ind==li&&rem<=a[ind]){
		return dp[ind][rem]=1;
	}
	if(ind==li&&rem>a[ind])
		return dp[ind][rem]=0;
	int ans=0;
	int i;
	repe(i,0,a[ind]){
		if(i<=rem)
			ans=(ans%mod+fun(ind+1,rem-i)%mod)%mod;
	}
	return dp[ind][rem]=ans;
}*/
signed main()
{
	comeback
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output1.txt","w",stdout);
	#endif*/
		int n,m,i,j,k,l;
		cin>>n>>k;
		int a[n+1];
		repe(i,1,n)
		cin>>a[i];
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		int sum=0;
		repe(i,1,n){
			int c=0;
			repe(j,0,k){
				c=(c%mod+dp[i-1][j]%mod)%mod;
				if(j>=a[i]+1)
					c=(c%mod+mod-dp[i-1][j-a[i]-1]%mod)%mod;
				dp[i][j]=c;
			}
		}
		cout<<dp[n][k];
}

Measured memory_bytes: 80000
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD (int64_t)1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector

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

int N; cin >> N;
VI a(N), b(N); invec(a), invec(b);
vector<pair<int, bool>> events;
rep(i, 0, N){
    events.emplace_back(a[i], false);
    events.emplace_back(b[i], true);
}
sort(ALL(events));
i64 res = 1;
int cnt = 0;
for (pair<int, bool> e: events){
    int delta = (e.second ? 1 : -1);
    if (cnt != 0 && (cnt>0) != e.second)
        res = (res * abs(cnt)) % MOD;
    cnt += delta;
}

cout << res << "\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 4852
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;

int main(){
	int n;
	cin >> n;
	int a = 1, b, c, ans = 0;
	while(a <= n){
		b = 1;
		c = 0;
		while(b <= a){
			if(a % b == 0){
				c++;
				//cout << c << endl;
			}
			b += 2;
		}
		if(c == 8) ans++;
		a += 2;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>

using namespace std;  //このネームスペースを使う

int main(){
  int A,B;
  cin >> A >> B ;
  
  if(A >= 13){
    cout << B << endl;
  }
  else if(A >=6 && A <= 12){
    cout << B/2 << endl;
  }
  else{
    cout << B*0 << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()




int main(void){
	int M, D;
    cin >> M >> D;

    int d1, d10, ans;
    ans = 0;
    

    reps(i,M){
        d1 = 1;
        d10 = 2;
        int j = 1;
        while(j <= D){
            if(d1<9){
                d1++;
            }else{
                d10++;
                d1 = 2;
            }

            if(d10*10 + d1 > D){
                break;
            }

            if(d1*d10 == i){
                ans++;
                //cout << d10 << d1 << " " << i << endl;
            }
            
            j++;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split()))
A = list()
B = list()
for i in range(0, N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
zipped = zip(A, B)
zipped_sorted = sorted(zipped, key=lambda x:x[0])
A, B = zip(*zipped_sorted)
num = 0
total = 0
i = 0
while(True):
    if num + B[i] >= M:
        total += (M - num) * A[i]
        break
    num += B[i]
    total += A[i] * B[i]
    # print(i, A[i], B[i], num, total)
    i += 1
print(total)

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

int main (){
  int i;
  int A,B;
  int H,M;
  double radA;
  double radB = 0;
  double sita;
  double answer;
  const double PI = 3.14159265358979323846;
  
  scanf("%d %d %d %d",&A,&B,&H,&M);
 
  radA = H * PI / 6 + M * PI / 360;
  radB = M * PI / 30;
  if(radA>radB)
    sita = radA - radB;
  else
    sita = radB - radA;
 // sita = max(radA,radB)-min(radA,radB);

  //answer = A*A+B*B-2*A*B* cos(sita) ;/**/
  answer = (double)sqrt((double)A*A+B*B-2*A*B* cos(sita)) ;
  //answer = 
  
  printf("%.18f",answer);
  
  
  
}

Measured memory_bytes: 2580
#include <iostream>
#include <set>

int main(){
  int N;
  std::string str;
  std::cin>>N>>str;
  int best=0;
  for(int s=1;s<N;s++){
    std::set<int> as,bs;
    for(int i=0;i<s;i++){
      as.insert(str[i]);
    }
    for(int i=s;i<N;i++){
      if(as.count(str[i])){
	bs.insert(str[i]);
      }
    }
    best=std::max<int>(best,bs.size());
  }
  std::cout<<best<<std::endl;
  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;


int main()
{
	FAST;
	string o,e;
	cin >> o >> e;

	int start1 = 0;
	int start2 = 0;
	for(int i=0 ; i<o.size()+e.size() ; i++)
	{
		if(!(i&1))
		{
			cout << o[start1++];
		}
		else
			cout << e[start2++];
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  ll N, K;
  cin >> N >> K;
  ll ans = min(N % K, K - (N % K));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String alpha = sc.next();
        String change = alpha.toUpperCase();
        if (alpha.equals(change)) {
            System.out.println("A");
        }else {
            System.out.println("a");
        }
    }
}


Measured memory_bytes: 35608
[a0,b0,k]=input().split()
a0=int(a0)
b0=int(b0)
k =int(k)
if a0>k:
    ak=a0-k
    bk=b0
else:
    ak=0
    bk=b0-(k-a0)

if bk<0:
    bk=0
    
print(ak,bk)

Measured memory_bytes: 3060
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
	string s;
	int a=0;
	cin>>s;
	rep(i,sz(s)){
		a+=int(s[i]-'0');
	}
	if(a%9==0){
		cout<<"Yes";
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and Constants    *******/

#define int long long
#define ull unsigned long long 
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define w(x) int x;cin>>x;while(t--)
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__);
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

const int POSITIVE_INFINITY = 9223372036854775807;
const int NEGATIVE_INFINITY = -9223372036854775807;
const int MOD = 1000000007;
const ld PI = acos(-1.0);
const int INF = 1e18;
const int MX = 1000001;


int32_t main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
    bool n;
    cin>>n;
    cout<<(!n)<<endl;
    
 
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
#include <algorithm>
#include <queue>

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

long long solve(std::vector<std::pair<int, int>> a, int n, int m) {
	int tot = (int) a.size();
	std::sort(a.begin(), a.end(), [](std::pair<int, int> v1, std::pair<int, int> v2) { return v1.first - v1.second > v2.first - v2.second; });
	//for(int i = 0; i < tot; i++) std::cout << "(" << a[i].first << ", " << a[i].second << ")" << (i + 1 == tot ? '\n' : ' ');
	const long long INF = 1e18;
	std::vector<long long> pref(tot+1, -INF);
	std::priority_queue<long long, std::vector<long long>, std::greater<long long>> hp;
	long long sum = 0;
	for(int i = 0; i < tot; i++) {
		sum += a[i].first;
		hp.push(a[i].first);
		if((int) hp.size() > n) {
			sum -= hp.top();
			hp.pop();
		}
		if((int) hp.size() == n) {
			pref[i+1] = sum;
		}
	}
	while(!hp.empty()) hp.pop();
	sum = 0;
	long long ans = -INF;
	for(int i = tot-1; i >= 0; i--) {
		sum += a[i].second;
		hp.push(a[i].second);
		if((int) hp.size() > m) {
			sum -= hp.top();
			hp.pop();
		}
		if((int) hp.size() == m) {
			ans = std::max(ans, sum + pref[i]);
			//std::cout << "got " << sum << " + " << pref[i] << "\n";
		}
	}
	return ans;
}

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n[3];
	std::cin >> n[0] >> n[1] >> n[2];
	int tot = n[0] + n[1] + n[2];
	std::vector<std::pair<int, int>> a(tot);
	long long base = 0;
	for(int i = 0; i < tot; i++) {
		int x, y, z;
		std::cin >> x >> y >> z;
		base += x;
	//std::cout << "base is " << base << '\n';
		a[i] = std::pair<int, int>(y - x, z - x);
	}
	std::cout << base + solve(a, n[1], n[2]) << '\n';
}

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

int main() {
  int n, d;
  string s;
  map<int, int> m, lm;
  
  while(getline(cin, s) && s.size() > 0) {
    sscanf(s.c_str(), "%d,%d", &n, &d);
    m[n]++;
  }

  while(getline(cin, s) && s.size() > 0) {
    sscanf(s.c_str(), "%d,%d", &n, &d);
    lm[n]++;
  }

  for(auto it = m.begin(); it != m.end(); it++) {
    int index = it->first;
    if(lm[index] > 0) {
      int sum = m[index] +lm[index];
      cout << index << ' ' << sum << endl;
    }
  }
}

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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "YES" : "NO")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 3e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "2";

int a[siz];
int mxl[siz], mnr[siz];

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

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    int n;
    cin >> n;

    for (int i = 1; i <= 3 * n; i++) {
        cin >> a[i];
    }

    int suml = 0;
    priority_queue <int, vector <int>, greater <int> > pql;
    for (int i = 1; i <= n; i++) {
        suml += a[i];
        pql.push(a[i]);
    }

    mxl[n] = suml;
    for (int i = n + 1; i <= 2 * n; i++) {
        pql.push(a[i]);
        suml += a[i];
        suml -= pql.top();
        pql.pop();
        mxl[i] = suml;
    }

    int sumr = 0;
    priority_queue <int> pqr;
    for (int i = 2 * n + 1; i <= 3 * n; i++) {
        sumr += a[i];
        pqr.push(a[i]);
    }

    mnr[2 * n + 1] = sumr;
    for (int i = 2 * n; i >= n + 1; i--) {
        pqr.push(a[i]);
        sumr += a[i];
        sumr -= pqr.top();
        pqr.pop();
        mnr[i] = sumr;
    }

    int ans = -MAXX;
    for (int i = n; i <= 2 * n; i++) {
        ans = max(ans, mxl[i] - mnr[i + 1]);
    }

    cout << ans << "\n";

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


Measured memory_bytes: 8936
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int A = stdIn.nextInt();
		int B = stdIn.nextInt();
		int C = stdIn.nextInt();
		int X = stdIn.nextInt();
		int count = 0;
		for(int i = 0; i <= A && i <= X/500; i++) {
			for(int j = 0; j <= B && j <= (X-500*i)/100; j++) {
				if((X-500*i-100*j)%50 == 0 && (X-500*i-100*j)/50 <= C) count++;
			}
		}
		System.out.println(count);

	}

}

Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

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

#define dump(x) cerr << #x << " = " <<(x)<<endl;
#define debug(x) cerr << #x << " = " <<(x) << "(L" << __LINE__ << ")" << __FILE__ << endl;

#define BIT_ON(x,b) ((x)|=(b))
#define BIT_OFF(x,b) ((x)&=~(b))
#define BIT_IS_ON(x,b) (((x)&(b))==(b))


using namespace std;

int main(void){
  int n;
  cin >> n;
  vector<int> v(n);
  int i;
  REP(i,n) scanf("%d",&v[i]);
  sort(v.begin(), v.end());
  
  //REP(i,n) cout << v[i] << endl;
  
  int counter = 1;
  FOR(i,1,n){
    if(v[i] > v[i-1]) counter++;
  }
  cout << counter << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	map<string, int> mp;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		++mp[s];
	}
	for (auto s : {"AC", "WA", "TLE", "RE"})
		cout << s << " x " << mp[s] << "\n";
}

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


double a, l, x;
int main() {
  while (cin >> a >> l >> x) {
    double h = sqrt(x*x / 4 + x*l / 2);
    double area = l*h + 0.5*a*sqrt(l*l - a*a/4);
    printf("%.8f\n", area);
  }
}

Measured memory_bytes: 3124
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  string ans = "";
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0') {
      ans += "0";
    } else if (s[i] == '1') {
      ans += "1";
    } else {
      if (ans != "") {
        ans.pop_back();
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

signed main() {
  int n,m;
  cin>>n>>m;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  vector<int> hen[n];
  int x,y;
  for(int i=0;i<m;i++){
    cin>>x>>y;
    hen[x].push_back(y);
    hen[y].push_back(x);
  }
  int used[n]={};
  int k,t=0,ans=0;
  queue<int> que;
  for(int i=0;i<n;i++){
    if(used[i]!=0)continue;
    used[i]=1;
    que.push(i);
    k=i;
    while(!que.empty()){
      for(int j=0;j<hen[que.front()].size();j++){
       if(!used[hen[que.front()][j]]){
         used[hen[que.front()][j]]=1;
         if(a[k]>a[hen[que.front()][j]])k=hen[que.front()][j];
         que.push(hen[que.front()][j]);
       } 
      }
      que.pop();
    }
    used[k]=2;
    ans+=a[k];
    t++;
  }
  vector<int> u;
  for(int i=0;i<n;i++)if(used[i]!=2)u.push_back(a[i]);
 k=u.size();
  if(2<t-k)cout<<"Impossible";
  else{
    if(t==1){
      cout<<0;
      return 0;
    }
    sort(u.begin(),u.end());
    for(int i=0;i<t-2;i++)ans+=u[i];
    cout<<ans;
  }
  
  return 0;
}


Measured memory_bytes: 8952
#include<iostream>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int a,b,c;
    while(cin>>a>>b)
    {
        int flag=0;
        if(a>b) swap(a,b);
        for(int i=a;i<=b;i++)
        {
            if((i*a*b)%2!=0)
            {
                flag=1;
                break;
            }
        }
        if(flag==1) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

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

int main(){
	char GG[127];
	int a = 0,b = 0,c = 0,d = 0,e = 0,f = 0,g = 0,h = 0,i = 0,j = 0,k = 0,l = 0,m = 0,n = 0,o = 0,p = 0,q = 0,r = 0,s = 0,t = 0,u = 0,v = 0,w = 0,x = 0,y = 0,z = 0;
	int num;
while(cin >> GG){
	num = strlen(GG);
	for(int kero = 0;kero < num; kero++){
		if(GG[kero] == 'a' ||GG[kero] == 'A')a++ ;
		else if(GG[kero] == 'b' ||GG[kero] == 'B')b++ ;
		else if(GG[kero] == 'c' ||GG[kero] == 'C')c++ ;
		else if(GG[kero] == 'd' ||GG[kero] == 'D')d++ ;
		else if(GG[kero] == 'e' ||GG[kero] == 'E')e++ ;
		else if(GG[kero] == 'f' ||GG[kero] == 'F')f++ ;
		else if(GG[kero] == 'g' ||GG[kero] == 'G')g++ ;
		else if(GG[kero] == 'h' ||GG[kero] == 'H')h++ ;
		else if(GG[kero] == 'i' ||GG[kero] == 'I')i++ ;
		else if(GG[kero] == 'j' ||GG[kero] == 'J')j++ ;
		else if(GG[kero] == 'k' ||GG[kero] == 'K')k++ ;
		else if(GG[kero] == 'l' ||GG[kero] == 'L')l++ ;
		else if(GG[kero] == 'm' ||GG[kero] == 'M')m++ ;
		else if(GG[kero] == 'n' ||GG[kero] == 'N')n++ ;
		else if(GG[kero] == 'o' ||GG[kero] == 'O')o++ ;
		else if(GG[kero] == 'p' ||GG[kero] == 'P')p++ ;
		else if(GG[kero] == 'q' ||GG[kero] == 'Q')q++ ;
		else if(GG[kero] == 'r' ||GG[kero] == 'R')r++ ;
		else if(GG[kero] == 's' ||GG[kero] == 'S')s++ ;
		else if(GG[kero] == 't' ||GG[kero] == 'T')t++ ;
		else if(GG[kero] == 'u' ||GG[kero] == 'U')u++ ;
		else if(GG[kero] == 'v' ||GG[kero] == 'V')v++ ;
		else if(GG[kero] == 'w' ||GG[kero] == 'W')w++ ;
		else if(GG[kero] == 'x' ||GG[kero] == 'X')x++ ;
		else if(GG[kero] == 'y' ||GG[kero] == 'Y')y++ ;
		else if(GG[kero] == 'z' ||GG[kero] == 'Z')z++ ;
		else if(GG[kero] == '\n')break;
		}

	}
	cout << "a : " << a << endl;
	cout << "b : " << b << endl;
	cout << "c : " << c << endl;
	cout << "d : " << d << endl;
	cout << "e : " << e << endl;
	cout << "f : " << f << endl;
	cout << "g : " << g << endl;
	cout << "h : " << h << endl;
	cout << "i : " << i << endl;
	cout << "j : " << j << endl;
	cout << "k : " << k << endl;
	cout << "l : " << l << endl;
	cout << "m : " << m << endl;
	cout << "n : " << n << endl;
	cout << "o : " << o << endl;
	cout << "p : " << p << endl;
	cout << "q : " << q << endl;
	cout << "r : " << r << endl;
	cout << "s : " << s << endl;
	cout << "t : " << t << endl;
	cout << "u : " << u << endl;
	cout << "v : " << v << endl;
	cout << "w : " << w << endl;
	cout << "x : " << x << endl;
	cout << "y : " << y << endl;
	cout << "z : " << z << endl;

	return 0;
}

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

using namespace std;

const int N = 1e6 + 9;

int n;
long long a[N];
long long dp[3001][3001];

int main(){
    cin>> n;
    for(int i = 1; i <= n; i++){
        cin>> a[i];
    }
    for(int L = n; L >= 1; L--){
        for(int R = L; R <= n; R++){
            if(L == R){
                dp[L][R] = a[L];
            }
            else{
                dp[L][R] = max(a[L] - dp[L + 1][R], a[R] - dp[L][R - 1]);
            }
        }
    }
    cout<< dp[1][n];
}


Measured memory_bytes: 71936
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
		 static int a_dist[];
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();
	        int A = sc.nextInt();
	        int B = sc.nextInt();
	        int C = sc.nextInt();
	        int[] l = new int[N];
	        for(int i=0;i<N;i++) {
	        	l[i] = sc.nextInt();
	        }
	        
	        long ans=Long.MAX_VALUE;
	        for(int i=0;i<Math.pow(4, N);i++) {
		        int[] cnt= new int[4];
		        int[] length= new int[4];
	        	int now = i;
	        	for(int j=0;j<N;j++) {
	        		int t = now%4;
	        		cnt[t]++;
	        		length[t]=length[t]+l[j];
	        		now=now>>2;
	        	}
	        	if(cnt[0]==0)continue;
	        	if(cnt[1]==0)continue;
	        	if(cnt[2]==0)continue;
	        	long tmp = cnt[0]+cnt[1]+cnt[2]-3;
	        	tmp=tmp*10;
	        	tmp=tmp+Math.abs(length[0]-A);
	        	tmp=tmp+Math.abs(length[1]-B);
	        	tmp=tmp+Math.abs(length[2]-C);
	        	ans=Math.min(ans, tmp);
	        	
	        }
	        System.out.println(ans);
		 }
		 
	}

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


Measured memory_bytes: 2480
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            WriteLine(tmp[0] + tmp[1] >= tmp[2] ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
void solve();
int main(){
    int t = 1;
    while(t --) solve();
    return 0;
}

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

const int maxn = 1e6 + 6;
const int mod = 1e9 + 7;

string s;
int E[maxn];
int W[maxn];
void solve(){
    int n;
    cin >> n >> s;
    for(int i = 1; i <= n; i ++){
        if(s[i-1] == 'E') W[i] = 1;
        W[i] += W[i-1];
    }
    for(int i = n; i >= 1; i --){
        if(s[i-1] == 'W') E[i] = 1;
        E[i] += E[i+1];
    }
    int res = E[1] + W[1] - 1;
    for(int i = 2; i <= n; i ++)
        res = max(res, E[i] + W[i] - 1);
    cout << n - 1 - res;

}



Measured memory_bytes: 5892
#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){


}

Node treeMaximum(Node 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){


}

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(" %d", u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    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: 20448
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define inf 1e18
#define int long long int 
#define pb push_back
#define mp make_pair
#define pq priority_queue<int> 
#define pqs priority_queue<int,vector<int>, greater<int>>
#define setbits(x) __builtin_popcountll(x)  // no of ones in setbit
#define zrobits(x) __builtin_ctzll(x)       //101000 here 3..no of 0 aftrer 1sr right one 
#define mod 1000000007
#define ps(x,y)  fixed<<setprecision(y)<<x  // ans upto 5 decimal place 
#define mk(ar,n,type) type *arr=new type[n];
#define w(x) int x;cin>>x;while(x--)
// #define inf 1000000001
int c=0 ; 
#define mod 1000000007 

struct item
{
	int wt; 
	int val; 
} ; 



void  solve(vector<item> arr, int n, int w)
{
	int max_val=n*1000; 
	int dp[n+1][max_val+1] ; 

	for(int i=0 ; i<=max_val; i++)
	{
		dp[1][i]=inf ; 
	}

	dp[1][0]=0 ; 
	dp[1][arr[1].val]=arr[1].wt ; 

	for(int i=2 ;i<=n; i++ )
	{
		for(int v=0 ; v<=max_val; v++)
		{
			dp[i][v]=dp[i-1][v] ;  

			// if(arr[i].val > v)
			// {
			// 	continue ; 
			// }
			
			if(arr[i].wt<=w)
			dp[i][v]=min(dp[i][v], arr[i].wt+dp[i-1][v-arr[i].val]) ; 
			

			// cout<<dp[i][v]<<" "; 
		}
	}

	int ans=0 ; 
	for(int i=0 ; i<=max_val; i++)
	{
		// cout<<dp[n][i]<<" "; 
		if(dp[n][i]<=w)
		{
			// ans=min(ans, i) ; 
			ans=i ;  
		}
	}

	cout<<ans; 

	


}

int32_t main()
{
	int n, w; 
	cin>>n>>w; 
	vector<item> arr(n+1) ;

	for(int i=1 ; i<=n; i++)
	{
		cin>>arr[i].wt>>arr[i].val ; 

	}
	// for(int i=1 ; i<=n; i++)
	// {
	// 	cout<<arr[i].wt<<" "<<arr[i].val<<endl; 

	// }

	solve(arr, n, w) ; 

}

Measured memory_bytes: 78336
#include <cstdio>
#include <algorithm>

#define ll long long
#define maxn 100000

ll v[maxn + 1];

int main() {
    int n;
    ll x, y, rez;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &v[i]);
    }
    std::sort(&v[1], &v[n + 1]);
    int p = 0, j;
    for (int i = n; i >= 2 && p == 0; i--) {
        if (v[i] == v[i - 1]) {
            p = 1;
            x = v[i];
            j = i - 2;
        }
    }
    for (int i = j; i >= 2 && p == 1; i--) {
        if (v[i] == v[i - 1]) {
            p = 2;
            y = v[i];
        }
    }
    if (p == 2) {
        rez = x * y;
        printf("%lld", rez);
    }
    else {
        printf("0");
    }
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
using namespace std;
#define MAX 101

int cnt;

int binary_search(int array[MAX],int key,int n){
    int left = 0 , right = n-1 , mid;
    
    while(left <= right){
        mid = (left+right)/2;
        if(array[mid]==key){
            cnt++;
            break;
        }
        else if(key < array[mid]){
            right = mid-1;
            cnt++;
        }
        else{
            left = mid+1;
            cnt++;
        }
    }

    return cnt;
}

int main(){
    int n,array[MAX],key;
    
    while(cin >> n,n){
        for(int i = 0 ; i < n ; i++) cin >> array[i];
        cin >> key;
        cnt = 0;
        cout << binary_search(array,key,n) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;

void call(int n){
	for(int i=1;i<=n;++i){
		int x = i;
		if(x % 3 == 0){
			cout << " " << i;
		} else {
			while( x ){
				if(x % 10 == 3){
					cout << " " << i;
					break;
				} else {
					x /= 10;
				}
			}
		}
	}
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	call(n);
	return 0;
}


Measured memory_bytes: 3092
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()

A.sort(reverse=1)
ans = 0
ans += A[0]

tmp = 1
for i in range(1, N - 1):
    ans += A[tmp]
    if i % 2 == 0:
        tmp += 1
print(ans)

Measured memory_bytes: 35084
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,c;
	cin>>n;
   int arr[n][3];
    cin>>arr[0][0]>>arr[0][1]>>arr[0][2];
  for(int i=1;i<n;i++)
  {
      cin>>a>>b>>c;
      arr[i][0]=a+max(arr[i-1][1],arr[i-1][2]);
      arr[i][1]=b+max(arr[i-1][0],arr[i-1][2]);
      arr[i][2]=c+max(arr[i-1][1],arr[i-1][0]);
  }
cout<<max(arr[n-1][0],max(arr[n-1][1],arr[n-1][2]));
return 0;
  }



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


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

    long long n,k;
    cin >> n >> k;
    long long a;
    long long cnt[50]={};
    long long sum = 0;
    for(int i=0;i<n;i++){
        cin>>a;
        sum += a;
        int d = 0;
        while(a){
            if(a%2==1){
                cnt[d]++;
            }
            a/=2;
            d++;
        }
    }
 
    long long dp1[50]={};
    long long dp2[50]={};
    for(int i=0;i<50;i++){
        dp1[i] = -1;
        dp2[i] = -1;
    }
    dp1[45] = 0;
    
    for(int i=44;i>=0;i--){
        long long mask = 1LL<<i;
        if(dp2[i+1] >= 0) dp2[i] = dp2[i+1] + mask * max(cnt[i],n-cnt[i]);
        if(dp1[i+1] >= 0) {
            if(k & (1LL<<i)){
                dp2[i] = max(dp2[i], dp1[i+1] + mask * cnt[i]);
                dp1[i] = dp1[i+1] + mask * (n-cnt[i]); 
            }
            else {
                dp1[i] = dp1[i+1] + cnt[i] * mask ;
            }
        }
    }
    long long ans = max(dp1[0], dp2[0]);
    cout << ans << endl;

}

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

int main(void){
    int n;
    cin >> n;
    vector<long> tn(n),an(n);
    for(int i = 0; i < n; i++){
        cin >> tn[i] >> an[i];
    }
    
    long t = tn[0],a =an[0];
    
    for(int i = 0; i < n; i++){
        long x = max(t/tn[i] + bool(t%tn[i]), a/an[i]+bool(a%an[i]));
        t = tn[i]*x;
        a = an[i]*x;
    }
    
    cout << t + a << endl;
}

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

#define N 1000100

const int mod = 998244353;

int s[N], p[N], ri[N];

inline void add(int &x, int y) {
    ((x += y) >= mod) ? x -= mod : 0;
}

int main() {
    ri[1] = 1;
    for (int i = 2; i < N; i ++) ri[i] = 1ll * (mod - mod / i) * ri[mod%i] % mod;
    int n;
    scanf("%d", &n);
    while (n --) {
        int x;
        scanf("%d", &x);
        add(s[x], x);
        p[x] = (p[x] + 1ll * x * x) % mod;
    }
    for (int i = 1; i < N; i ++) {
        for (int j = i << 1; j < N; j += i) {
            add(s[i], s[j]), add(p[i], p[j]);
        }
    }
    for (int i = 1; i < N; i ++) {
        s[i] = (1ll * s[i] * s[i] - p[i]) % mod;
        if (s[i] < 0) s[i] += mod;
        s[i] = 1ll * s[i] * (mod + 1 >> 1) % mod;
    }
    for (int i = N - 1; i; i --) {
        for (int j = i << 1; j < N; j += i) {
            s[i] -= s[j]; if (s[i] < 0) s[i] += mod;
        }
    }
    int ans = 0;
    for (int i = 1; i < N; i ++) ans = (ans + 1ll * ri[i] * s[i]) % mod;
    printf("%d\n", ans);
}


Measured memory_bytes: 11904
n=int(input())
a=[-1]*n
for i in range(n):
  a[i]=int(input())
  

def all_even(li):
  for i in li:
    if i%2!=0:
      return False
  return True


if all_even(a):
  print("second")
else:
  print("first")
  

  
  

Measured memory_bytes: 6900
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int arr[11];
  memset(arr,0,sizeof(arr));
  for(int i=0;i<=2;i++)
  {
    int temp;
    cin>>temp;
    arr[temp]++;
  }
  if(arr[5]==2 && arr[7]==1)
      cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
N = int(input())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
	if i < N - 2:
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print(dp[N - 1])

Measured memory_bytes: 55752
from collections import Counter

alpha = [float('inf')] * 26
n = int(input())

for _ in range(n):
    dic = Counter(list(input()))
    for i in range(26):
        if chr(i + 97) not in dic:
            alpha[i] = 0
        elif dic[chr(i + 97)] < alpha[i]:
            alpha[i] = dic[chr(i + 97)]

ans = ''
for i in range(26):
    ans += chr(i + 97) * alpha[i]

print(ans)

Measured memory_bytes: 69592