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

int main() {
  int N;
  cin >> N;
  
  if(N == 2){
    int k;
    cin >>k;
    cout << 2*k << endl;
  }
  else{
  vector<int> vec(N-1);
   for (int i = 0; i < N-1; i++) {
  cin >> vec.at(i);
}
  long long int cou =0;
  cou += vec.at(0)+vec.at(N-2);
  
  for (int i = 0; i < N-2; i++) {
    cou += min(vec.at(i),vec.at(i+1));
  }
    
  cout << cou << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
    VECCIN(head);
    VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
    seco[head]=IN();
    VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair

int main(){

    CIN(n);
    V v(n,-1);

    auto f = [&](int num){
        COUT(num);
        SCIN(s);
        if(s=="Vacant")
            exit(0);
        return v[num]=(s=="Male");
    };

    f(0);

    int st=0;int en=n;
    //長さが偶数になるような区間を取る
    //en-stが偶数

    REP(ccc,25){
        int num = (en+st)/2;
        int range = num-st;

        //差が偶数でstとenが同じならstをずらす
        ( (f(num) == v[st]) ^ (range % 2) ? st : en) = num;
    }



    return 0;
}

Measured memory_bytes: 1620
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

int main(){
  ll N;
  cin >> N;
  ll query[N][2];
  rep(i, N) scanf("%lld %lld", query[i], query[i]+1);

  ll odd = ((query[0][0] + query[0][1]) % 2 + 2) % 2;
  rep(i, N){
    if(((query[i][0] + query[i][1]) % 2 + 2) % 2 != odd){
      odd = -1;
      break;
    }
  }

  if(odd == -1){
    cout << -1 << endl;
  }
  else{
    const ll m = 31;
    cout << (m + 1 - odd) << endl;
    ll powm = 1;
    powm <<= m;
    ll d = 1;
    if(!odd) printf("%d ", 1);
    rep(i, m-1){
      printf("%lld ", d);
      d <<= 1;
    }
    printf("%lld\n", d);

    rep(i, N){
      ll u = (query[i][0] + query[i][1] + powm - odd) / 2;
      ll v = (query[i][0] - query[i][1] + powm - odd) / 2;
      ll mask = 1;
      if(!odd) cout << 'L';
      rep(i, m){
        if(!(u & mask) && !(v & mask)) cout << 'L';
        if((u & mask) && (v & mask)) cout << 'R';
        if(!(u & mask) && (v & mask)) cout << 'D';
        if((u & mask) && !(v & mask)) cout << 'U';
        mask <<= 1;
      }
      cout << endl;
    }
  }
  return 0;
}


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

int main(){
	while(1){
		std::string str;
		std::string Astr;
		int h=0,b=0;
		std::cin>>str>>Astr;
		if(str=="0"&&Astr=="0")break;
		for(int i=0;i<str.size();i++){
			for(int j=0;j<Astr.size();j++){
				if(str[i]==Astr[j]){
					if(i==j)h++;
					else b++;
				}
			}
		}
		std::cout<<h<<" "<<b<<std::endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  deque<ll> ans;

  for (ll i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (n % 2 == 0) {
      if (i % 2 == 0) {
        ans.push_back(a);
      } else {
        ans.push_front(a);
      }
    } else {
      if (i % 2 != 0) {
        ans.push_back(a);
      } else {
        ans.push_front(a);
      }
    }
  }

  for (ll i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;

  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin >> a >> b;
    if(a<=b) cout << a << "\n";
    else cout << a-1 << "\n";

    return 0;
}

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

int main(void){
    ll x, y;
    cin >> x >> y;

    cout << x + y / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
long mod=1e9+7,dp[50][50][99],a[50][50],b[50][50],k;
main(n)
{
	scanf("%d%ld",&n,&k);
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)scanf("%d",dp[i][j]);
	for(int K=1;K<60;K++)
	{
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)
		{
			for(int l=0;l<n;l++)dp[i][j][K]=(dp[i][j][K]+dp[i][l][K-1]*dp[l][j][K-1])%mod;
		}
	}
	for(int i=0;i<n;i++)a[i][i]=1;
	for(int K=0;K<60;K++)
	{
		if(k&1LL<<K)
		{
			for(int i=0;i<n;i++)for(int j=0;j<n;j++)
			{
				b[i][j]=0;
				for(int l=0;l<n;l++)b[i][j]=(b[i][j]+a[i][l]*dp[l][j][K])%mod;
			}
			for(int i=0;i<n;i++)for(int j=0;j<n;j++)a[i][j]=b[i][j];
		}
	}
	long ans=0;
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)ans=(ans+a[i][j])%mod;
	printf("%d",ans);
}

Measured memory_bytes: 2176
#include<stdio.h>

_Bool rev(_Bool a){
	if(a == 0) return 1;
	else return 0;
}

char SW(_Bool a){
	if(a == 0) return 'S';
	else return 'W';
}

int main(){
	long N, i;
	int sc;
	sc = scanf("%ld", &N);
	char s[N + 1];
	sc = scanf("%s", s);
	
	s[N + 1] = s[N];
	s[N] = s[0];
	
	int j, k;
	
	_Bool wolf = 1, sheep = 0, animal[N + 1];
	
//	animal[0] = sheep;
//	animal[1] = sheep;   //0番目と1番目が羊
	for(j = 0; j < 2; j ++){
		for(k = 0; k < 2; k ++){
			animal[0] = j;
			animal[1] = k;
			
			
			for(i = 1; i < N + 1; i ++){
				if(s[i] == 'o'){
					if(animal[i] == sheep){
						animal[i + 1] = animal[i - 1];
					}else animal[i + 1] = rev(animal[i - 1]);
				}else{
					if(animal[i] == sheep){
						animal[i + 1] = rev(animal[i - 1]);
					}else animal[i + 1] = animal[i - 1];
				}
			}
			

			if(animal[N] == animal[0] && animal[N + 1] == animal[1]){
				for(i = 0; i < N; i ++){
					printf("%c", SW(animal[i]));
				}
				printf("\n");
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
   int a, b, c, d, i;

   scanf("%d%d%d%d",&a,&b,&c,&d);

   while(1){
      c=c-b;
      a=a-d;
      if(c<=0){
         printf("Yes\n");
         return 0;
      }
      else if(a<=0){
         printf("No\n");
         return 0;
      }
   }
}

Measured memory_bytes: 1652
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
const int mod = 1e9 + 7;
int n;

int add(int x, int y) {
	if (x + y >= mod) {
		return x + y - mod;
	}
	return x + y;
}

int mul(int x, int y) {
	return (long long) x * y % mod;
}

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

	cin >> n;

	int pref = 0;
	int ans = 0;

	int x;
	for (int i = 0; i < n; i++) {
		cin >> x;
		ans = add(ans, mul(x, pref));
		pref = add(pref, x);
	}

	cout << ans << '\n';

	return 0;
}


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

int main() {
	int n;

	cin >> n;

	long long minus_count = 0;
	long long min_value = 1000000000; 
	long long total_count = 0;
	long long a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];

		if (a[i] < 0) {
			a[i] = - a[i];
			minus_count ++;

		}

		if (a[i] < min_value) {
			min_value = a[i];
		}
		total_count += a[i];
	}

	if ((minus_count & 1) == 1) {
		total_count -= min_value * 2;
	}

	cout << total_count << endl;

	return 0;

}

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

//#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")

#define int long long
typedef pair <int, int> pii;
const int maxn = 21;
string s[maxn];
int dist[maxn][maxn];
bool mark[maxn][maxn];
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, ans = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (s[i][j] == '#')
				continue;
			for (int k = 0; k < n; k++) {
				fill(dist[k], dist[k] + m, 0);
				fill(mark[k], mark[k] + m, 0);
			}
			queue <pii> Q;
			Q.push(pii(i, j));
			mark[i][j] = 1;
			while (Q.size()) {
				auto P = Q.front();
				Q.pop();
				int a = P.first, b = P.second;
				for (int d = 0; d < 4; d++) {
					int x = a + dx[d];
					int y = b + dy[d];
					if (x >= 0 && x < n && y >= 0 && y < m && !mark[x][y] && s[x][y] == '.') {
						Q.push(pii(x, y));
						mark[x][y] = 1;
						dist[x][y] = dist[a][b] + 1;
					}
				}
			}
			for (int k = 0; k < n; k++) {
				ans = max(ans, *max_element(dist[k], dist[k] + m));
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
elc_tap = input().split(" ")
for i in range(2):
    elc_tap[i] = int(elc_tap[i])

count = 0
now_tap = 1
while elc_tap[1]>now_tap:
    now_tap += (elc_tap[0]-1)
    count += 1

    
print(count)

Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[100005],dis[100005];
int main(){
	ll n,i;
	scanf("%lld",&n);
	ll sum=0;
	for(i=1;i<=n;i++)scanf("%lld",&a[i]),sum+=a[i];
	if(sum%(n*(n+1)/2)){
		printf("NO\n");
		return 0;
	}
	sum/=(n*(n+1))/2;
	dis[1]=a[1]-a[n];
	for(i=2;i<=n;i++)dis[i]=a[i]-a[i-1];
	ll cnt=0;
	for(i=1;i<=n;i++){
		if((sum-dis[i]<0)||(sum-dis[i])%n){
			printf("NO\n"); 
			return 0;
		}
		else cnt+=(sum-dis[i])/n;
	}
	if(cnt!=sum)printf("NO\n");
	else printf("YES\n");
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll k;
int dp[3001][3001];
string final;
int lcs(string& x, string& y, int n, int m)
{
  if(n==0 || m==0)
  {
    return 0;
  }

  if(dp[n][m]!=-1)
  { //cout<<"here"<<endl;
    return dp[n][m];
  }

  if(x[n-1]==y[m-1])
  {
      //final.push_back(x[n-1]);
      dp[n][m] = 1+ lcs(x,y,n-1,m-1);
      return dp[n][m];
  }
  else{
    dp[n][m]=max(lcs(x,y,n-1,m),lcs(x,y,n,m-1));
    return dp[n][m];
  }




}

int main()
{
	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(dp,-1,sizeof(dp));
  string x;
  cin>>x;
  string y;
  cin>>y;
  int n,m;
  n=x.length();
  m=y.length();
  k=  lcs(x,y,n,m);
  int i = n, j = m;
   while (i > 0 && j > 0)
   {
      if (x[i-1] == y[j-1])
      {
          final.push_back(x[i-1]);

          i--; j--;
      }

      else if (dp[i-1][j] > dp[i][j-1])
         i--;
      else
         j--;
   }

   if(final.length()>0)
   {
     for(int i=final.length()-1;i>=0;i--)
     {
       cout<<final[i];
     }
   }

   //cout<<endl;

}


Measured memory_bytes: 39252
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-8;
int n;
double x[102], y[102];
vector<double> v;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i ++) {
        scanf("%lf %lf", &x[i], &y[i]);
    }

    for (int i = 1; i <= n; i ++) {
        v.clear();
        for (int j = 1; j <= n; j ++) if (i != j) {
            double a1 = atan2(y[j]-y[i], x[j]-x[i]);
            v.push_back(a1);            
        }
        
        sort(v.begin(), v.end());
        v.push_back(v[0] + 2*PI);
        

        int gg = 0; double gap = 0;
        for (int j = 0; j < (int)v.size() - 1; j ++) {
            //printf("%.3f\n", v[j]);
            if (v[j+1] - v[j] + EPS > PI) {
                gg ++; gap = v[j+1] - v[j];
            }
        }
        if (gg >= 2 || gap < PI) {
            printf("%.7f\n", 0.0);
            continue;
        } 
        //printf("%.6f\n", gap);
    
        printf("%.7f\n", (gap-PI) / 2 / PI);




    }
}

Measured memory_bytes: 512
b=input()
a=sorted([int(x) for x in input().split()])
c=0
while True:
    if a[c]==a[c+1]:
        ANS=False
        break
    if c==len(a)-2:
        ANS=True
        break
    c+=1
if ANS:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 25172
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = (n*(n-1))/2;
			int[] sum = new int[n];
			int a, b, c, d;
			for(int i=0;i<m;i++){
				a = sc.nextInt();
				b = sc.nextInt();
				c = sc.nextInt();
				d = sc.nextInt();
				if(c>d){
					sum[a-1] += 3;
				}else if(d>c){
					sum[b-1] += 3;
				}else{
					sum[a-1]++;
					sum[b-1]++;
				}
			}

			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i=0;i<n;i++){
				list.add(sum[i]);
			}
			Collections.sort(list);
			
			for(int i=0;i<n;i++){
				System.out.println(n-(list.lastIndexOf(sum[i])));
			}
			
		}
		
	}	
}

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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P   = pair<int, int>;

template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template <class T>
void dump_vector(const vector<T> &v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == len - 1 ? "\n" : " ");
    }
}

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

//---------------------------------------------------------------------------------------------------
template <class T>
T gcd(T x, T y) {
    return (y == 0) ? x : gcd(y, x % y);
}
//---------------------------------------------------------------------------------------------------

signed main() {
    int x, y;
    cin >> x >> y;
    cout << gcd(x, y) << "\n";
}



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

int main() {
 ll n; cin >> n;
 vector<ll> a(5);
 rep(i,5) cin >> a[i];
 sort(a.begin(),a.end());
 ll ans=5+n/a[0];
 if(n%a[0]!=0) cout << ans << endl;
 else cout << ans-1 <<endl;

}


Measured memory_bytes: 256
N = int(input())

temp = N
result = []

while temp != 0:
    if temp % 2 == 0:
        ans = 0
    else:
        ans = 1
    temp = (temp - ans) // (-2)
    result.append(str(ans))
result.reverse()
if N == 0:
    print(0)
else:
    print("".join(result))


Measured memory_bytes: 3060
import sys
import math

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a,b,h,m=map(int,input().split())

pi=3.141592653589793238


ha=(h+(m/60))/6
hb=m/30

agl=abs(pi*(ha-hb))

hh=(a**2+b**2-2*a*b*math.cos(agl))**0.5

print(hh)

Measured memory_bytes: 9604
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
 
int main() {
	ll n;
	cin>>n;
	map<string,ll> b;
	for(ll i=0;i<n;i++){
		string a;cin>>a;
		b[a]++;
		
	}
	vector<string> v;ll x=-1;

	for(auto i:b)
	{
		if(i.ss==x)
		{
			v.push_back(i.ff);
		}
		else if(i.ss>x)
		{
			x=i.ss;
			v.clear();
			v.push_back(i.ff);
		}
	}
	sort(v.begin(),v.end());
	for(auto i:v)
	cout<<i<<endl;
}

Measured memory_bytes: 26868
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	Scanner stdIn = new Scanner(System.in);
	double a, b;
	double S;
	final double t = 3.305785;

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

	S = a * b / t;
	System.out.println(S);
    }
}

Measured memory_bytes: 26116
#include <iostream>

int main(void) {
	using namespace std;

	int n = 1;
	cin >> n;
	int y[n], m[n], d[n];
	long sum[n];

	for(int i = 0; i< n ; i++){
		cin >> y[i] >> m[i] >> d[i];
		sum[i] = 0;
	}

	//day calculate
	for(int i = 0; i < n ; i++){//person

		while(y[i]< 1000){

			while(m[i] <= 10){

				if((m[i] % 2) || ((y[i] % 3) == 0)){
					while(d[i]++ <= 20){
						sum[i]++;
					}
				}
				else 	{
					while(d[i]++ <= 19){
						sum[i]++;
					}
				}
				m[i]++;
				d[i]=1;//(y, m+1, 1)

			}

			y[i]++;
			m[i]=1;//(y+1, 1, 1)

		}

	}

	for(int i=0; i<n; i++){
		cout << sum[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
import static java.lang.Math.abs;
public class Main{
public static void main(String... args){
Scanner sc=new Scanner(System.in);
String string=sc.next();
if(string.charAt(0)==string.charAt(2)){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
}


Measured memory_bytes: 21588
x,y,a,b,c=map(int,input().split())
p=list(map(lambda x:['red',int(x)],input().split()))
q=list(map(lambda x:['green',int(x)],input().split()))
r=list(map(lambda x:['nan',int(x)],input().split()))
p.sort(key=lambda x:x[1])
p=p[-x:]
q.sort(key=lambda x:x[1])
q=q[-y:]
p[len(p):len(p)]=q
p[len(p):len(p)]=r
p.sort(key=lambda x:x[1])
p=p[-x-y:]
print(sum([pi[1] for pi in p]))
  


Measured memory_bytes: 52788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int c,b,a,re;
    string s,t,u;
    cin>>s;
    if(s=="SAT"){
        cout<<1<<endl;
    }
    else if(s=="SUN"){
        cout<<7<<endl;
    }
    else if(s=="MON"){
        cout<<6<<endl;
    }
    else if(s=="TUE"){
        cout<<5<<endl;
    }
    else if(s=="WED"){
        cout<<4<<endl;
    }
    else if(s=="THU"){
        cout<<3<<endl;
    }
    else if(s=="FRI"){
        cout<<2<<endl;
    }
    return 0;
}


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<char> vec((W+2)*(H+2));
  int i=0;
  
  rep(i,H+2){
    rep(j,W+2){
      if(i==0||i==H+1){
        vec.at(i*(W+2)+j) = '#';
      }
      else{
        if(j==0||j==W+1)
          vec.at(i*(W+2)+j) = '#';
        else
          cin >> vec.at(i*(W+2)+j);
      }
    }
  }
  
  rep(i,H+2){
    rep(j,W+2){
      cout << vec.at(i*(W+2)+j);
    }
    cout << endl;
  }
  
  return 0;
}







Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=5050;

int gti(void)
{
    int ret=0,st=1;
    char c=getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') st=-1;
    for (;isdigit(c);c=getchar()) ret=ret*10+c-'0';
    return ret*st;
}

struct edge{edge *nxt;int to;}pool[N],*pt[N],*p=pool;
void add(int a,int b)
{
    *(++p)=(edge){pt[a],b},pt[a]=p;
}

int f[N][N],g[N],x[N];
bool vis[N][N],c[N];
void upd(int x,int y,int num)
{
    if (!vis[x][y]) f[x][y]=num;
    else f[x][y]=max(f[x][y],num);
    vis[x][y]=true;
}
void solve(int v)
{
    for (edge *i=pt[v];i;i=i->nxt)
        solve(i->to);
    int cnt=0;
    for (edge *i=pt[v];i;i=i->nxt,++cnt)
    {
        memset(vis[cnt],0,sizeof(vis[cnt]));
        if (!c[i->to]) return;
        if (i==pt[v])
        {
            if (g[i->to]<=x[v])
                upd(cnt,g[i->to],x[i->to]);
            if (x[i->to]<=x[v])
                upd(cnt,x[i->to],g[i->to]);
        }
        else
        {
            for (int j=0;j<=x[v];j++)
                if (vis[cnt-1][j])
                {
                    if (j+g[i->to]<=x[v])
                        upd(cnt,j+g[i->to],f[cnt-1][j]+x[i->to]);
                    if (j+x[i->to]<=x[v])
                        upd(cnt,j+x[i->to],f[cnt-1][j]+g[i->to]);
                }
        }
    }
    g[v]=1e9;
    for (int i=0;i<=x[v];i++)
        if (vis[cnt-1][i])
        {
            g[v]=min(g[v],f[cnt-1][i]);
            c[v]=true;
        }
    if (!pt[v])
        c[v]=true,g[v]=0;
}

int main(void)
{
    int n=gti();
    for (int i=2;i<=n;i++)
        add(gti(),i);
    for (int i=1;i<=n;i++)
        x[i]=gti();
    solve(1);
    puts(c[1]?"POSSIBLE":"IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 26752
"""Boot-camp-for-Beginners_Easy010_B_Toll-Gates_29-August-2020.py"""
import numpy as np

N = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)

Alice = [a[i] for i in range(0, len(a), 2)]
Bob = [a[i] for i in range(1, len(a), 2)]
#print(Alice)
#print(Bob)

s_max = 0
for i in range(len(Alice)):
    s_max += Alice[i]
s_min = 0
for i in range(len(Bob)):
    s_min += Bob[i]
#print(s_max)
#print(s_min)
print(s_max-s_min)


Measured memory_bytes: 26992
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

const LL INF = 0x3fffffffffffffff;

struct Edge {
  int to;
  LL len;
};

int N;
map<int, int> sz[114514];
map<int, int> mx[114514];
LL depth[114514];
vector<Edge> es[114514];

void CalcDepth(int v, int p, LL l) {
  depth[v] = depth[p] + l;
  for (auto &e : es[v]) {
    int u = e.to;
    if (u == p) continue;
    CalcDepth(u, v, e.len);
  }
}

int CalcSize(int v, int p) {
  if (sz[v].count(p)) return sz[v][p];

  int s = 1;
  int m = 0;
  int m2 = 0;
  for (auto &e : es[v]) {
    int u = e.to;
    if (u == p) continue;
    int res = CalcSize(u, v);
    s += res;
    if (m <= res) {
      MX(m2, m);
      m = res;
    }
  }

  if (p == v) {
    for (auto &e : es[v]) {
      int u = e.to;
      sz[v][u] = s-sz[u][v];
      if (sz[u][v] == m) mx[v][u] = m2;
      else mx[v][u] = m;
    }
  }

  mx[v][p] = m;
  return sz[v][p] = s;
}

void CallAllSize(int v, int p) {
  CalcSize(v, v);
  for (auto &e : es[v]) {
    int u = e.to;
    if (u == p) continue;
    CallAllSize(u, v);
  }
}

LL CalcCycle(int v, int p, int k) {
  int rem = k - 2*(sz[v][p]-mx[v][p]);
  //printf("%d: k=%d rem=%d conv=%lld\n", v, k, rem, conv);
  if (rem <= 0) return 0;

  LL ret = INF;
  int u;
  LL l;
  for (auto &e : es[v]) {
    u = e.to;
    if (u == p) continue;
    if (sz[u][v] != mx[v][p]) continue;
    l = e.len;
    break;
  }
  return CalcCycle(u, v, rem) + l * rem;
}

LL CalcEdge(int v) {
  LL ret = INF;
  int rem = N - 2*(N-mx[v][v]);
  
  for (auto &e : es[v]) {
    int u = e.to;
    ////printf("v=%d, u=%d, e=%lld, rem:%d\n", v, u, e.len, rem);
    if (rem+1 <= 0) {
      MN(ret, e.len);
    } else if (mx[v][v] == sz[u][v]) {
      if (N-mx[v][v] >= mx[v][v]) {
        MN(ret, e.len);
      }
    }
  }
  return ret;
}

int main() {
  scanf("%d", &N);
  rep(i, N-1) {
    int a, b;
    LL c;
    scanf("%d%d%lld", &a, &b, &c);
    --a;
    --b;
    es[a].eb(Edge{b, c});
    es[b].eb(Edge{a, c});
  }

  int root = 0;
  CalcDepth(root, root, 0);
  CallAllSize(root, root);

  LL ans = 0;
  rep(v, N) {
    ans += depth[v]*2;
  }
  ans -= CalcCycle(root, root, N)*2;

  LL sub = INF;
  rep(v, N) {
    MN(sub, CalcEdge(v));
  }
  printf("%lld\n", ans-sub);
}


Measured memory_bytes: 58496
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextInt()) {
            int n = scan.nextInt();
            int x = 0;

            for (int a = 0; a <= 9; a++) {
                for (int b = 0; b <= 9; b++) {
                    for (int c = 0; c <= 9; c++) {
                        for (int d = 0; d <= 9; d++) {
                            if (a + b + c + d == n) {
                                x++;
                            }
                        }
                    }
                }
            }
            System.out.println(x);
        }
    }
}



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

int main()
{
	int N;
	cin >> N;
	int sum = 0;
	int squares = 0;
	int d;
	for (int i = 0; i < N; ++i)
	{
		cin >> d;
		squares += d*d;
		sum += d;
	}
	cout << (sum * sum - squares) / 2 << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	string s;
	cin >> s;
	cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
}

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

int main() {
    int ans = 0;
    string S;
    cin >> S;
    string S_r = S;
    reverse(S_r.begin(), S_r.end());
    for(int i = 0; i < S.size() / 2; i++) {
        if(S[i] != S_r[i])
            ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  long long ans = 0;
  int s = 0;
  mp[0] = 1;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    s += a;
    s %= m;
    ans += mp[s];
    mp[s]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>

int main()
{
	std::string s;
	std::cin >> s;

	bool is9 = false;
	for( int i = 0; i < s.size(); i++ ) {
		if( s[ i ] == '9' ) {
			is9 = true;
			break;
		}
	}

	std::cout << ( is9 ? "Yes" : "No" ) << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,i;
  cin>>n>>m;
  long int a[n],b[n],c[m],d[m],ans[n];
  for(i=0;i<n;++i){
    cin>>a[i]>>b[i];
  }
  for(i=0;i<m;++i){
    cin>>c[i]>>d[i];
  }
  for(i=0;i<n;++i){
    long min = 400000001;
    for(int j=0;j<m;++j){
      if(min>(abs(a[i]-c[j])+abs(b[i]-d[j]))){
        min = (abs(a[i]-c[j])+abs(b[i]-d[j]));
        ans[i] = j+1;
      }
    }
  }
  for(i=0;i<n;++i){
    cout<<ans[i]<<endl;
  }
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

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

    vector<int> nums(n);
    rep(i, n) cin >> nums[i];
    sort(all(nums));
    reverse(all(nums));

    int score = 0;
    rep(i, n){
        if(i % 2 == 0){
            score += nums[i];
        }else{
            score -= nums[i];
        }
    }

    cout << score << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,k;
	cin>>n>>k;
	vector<ll> dice(n);
	for (int i = 0; i<n; i++){
		cin>>dice[i];
	}
	ll maxsum = 0;
	ll cursum = 0;
	for (int i = 0; i<k; i++){
		cursum+=dice[i];
	}
	maxsum=cursum;
	for (int i = k; i<n; i++){
		cursum+=dice[i];
		cursum-=dice[i-k];
		maxsum=max(maxsum,cursum);
	}
	//cout<<maxsum<<endl;
	maxsum+=k;
	long double ans = maxsum;
	ans/=2;
	cout<<setprecision(15)<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int N;
bool go = true;
vector<int> b;

int main()
{
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];
    while (a.size() > 0 && go)
    {
        go = false;
        for (int i = a.size() - 1; i >= 0; i--)
        {
            if (a[i] == i + 1)
            {
                b.push_back(a[i]);
                a.erase(a.begin() + i);
                go = true;
                break;
            }
        }
    }

    if (b.size() != N)
    {
        cout << -1 << endl;
    }
    else
    {
        reverse(b.begin(), b.end());
        for (int i = 0; i < N; i++)
            cout << b[i] << endl;
    }
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i_len=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define pb push_back
#define mp make_pair

int main()
{
    ll N;
    cin >> N;
    vec X(N);
    REP(i,0,N) cin >> X[i];

    ASC(X);
    ll sum, m = INF;
    REP(i,X[0],X[N-1]+1) {
        sum = 0;
        REP(j,0,N) sum += (X[j] - i) * (X[j] - i);
        m = MIN(m,sum);
    }
    PR(m);

    return 0;
}

/*



*/

Measured memory_bytes: 256
#include<iostream>
main(){int N,M;std::cin>>N>>M;long d[N+1],a=1,m=1e9+7;d[0]=1;for(int i=1;i<=N;i++){d[i]=((M-N+i-1)*d[i-1]+(i-1)*d[i-2])%m;a=a*(M-i+1)%m;}std::cout<<a*d[N]%m;}

Measured memory_bytes: 7548
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = null;
		if(a.equals("Sunny")){
			b = "Cloudy";
		}
		if(a.equals("Cloudy")){
			b = "Rainy";
		}
		if(a.equals("Rainy")){
			b = "Sunny";
		}
		System.out.print(b);
	}

}


Measured memory_bytes: 21588
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    double h,w,n;

    cin >> h >> w >> n;

    if(h > w){
        cout << ceil(n/h) << endl;
    }else{
        cout << ceil(n/w) << endl;
    }


    return 0;
}

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


int main() {
    int N;
    cin >> N;
    vector<int> v(100003, 0);
    for(int i=0; i<N; ++i) {
        int a, b;
        cin >> a >> b;
        ++v[a-1];
        --v[b];
    }
    int ret = 0;
    for(int i=1; i<v.size(); ++i) {
        v[i] += v[i-1];
        if(v[i] >= i) {
            ret = i;
        }
    }
    cout << ret << endl;
}


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

int main(void) {
    string S; cin >> S;
    int i, cnt, max = 0;

    for (i = 0, cnt = 0; i < S.size(); i++) {
        if(S.at(i) == 'A' || S.at(i) == 'T' || S.at(i) == 'C' || S.at(i) == 'G') {
            cnt++;
            if (cnt > max) {
                max = cnt;
            }
        }else {
            cnt = 0;
        }
    }

    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
M, D = input().split()
M = int(M)
d10 = int(D[0])
if len(D) >1:
  d1 = int(D[1])
ans = 0
for i in range(2,d10+1):
  for j in range(2,10):
    if i == d10 and j<=d1 and i*j <= M:
      ans += 1
     
    elif i*j <= M and i<d10:
      ans += 1
      
print(ans)


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


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
  int x, y;
  cin >> x >> y;
  if (x % y == 0) {
    cout << -1 << endl;
  } else {
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()

r = set([i+1 for i in range(n) if s[i] == "R"])
g = set([i+1 for i in range(n) if s[i] == "G"])
b = set([i+1 for i in range(n) if s[i] == "B"])
ans = len(r)*len(g)*len(b)


def check(s1, s2, s3):
    t = 0
    for i in range(1, n+1):
        if not i in s1:
            continue
        for j in range(i+1, n+1):
            if not j in s2:
                continue
            if (j+(j-i)) in s3:
                t += 1
    return t


ans -= check(r, g, b)
ans -= check(r, b, g)
ans -= check(g, b, r)
ans -= check(g, r, b)
ans -= check(b, r, g)
ans -= check(b, g, r)
print(ans)


Measured memory_bytes: 9372
import math

# input
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]


T = 1 # 高橋くんの最小得票数
A = 1 # 青木くんの最小得票数
ans = 2

for i in range(0, N):
    #m = max(math.ceil(T / TA[i][0]), math.ceil(A / TA[i][1]))
    m = max(-(-T // TA[i][0]), -(-A // TA[i][1]))
    T = TA[i][0] * m
    A = TA[i][1] * m
    ans = T + A

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;

int main(){
    char ch;
    int cnt[26]={};
    
    while( cin >> ch ){
        ch = tolower(ch);
        if( isalpha(ch) ){
            cnt[ch-'a']++;
        }
    }
    
    for ( int i=0; i < 26; i++ ){
        printf("%c : %d\n", i+'a',cnt[i]);
    }// Your code here!
    return 0;
}


Measured memory_bytes: 3144
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>

using namespace std;

double EPS = 1e-10;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }

  point operator / (double d){
    return point(x/d,y/d);
  }
};

struct segment{ point a,b; };

struct circle{ point p; double r; };

double dot(point a, point b) { return (a.x * b.x + a.y * b.y); }

double cross(point a, point b) { return (a.x * b.y - a.y * b.x); }

int ccw(point p0, point p1, point p2){
  point a = p1 - p0;
  point b = p2 - p0;
  if(cross(a,b)>EPS)return +1;
  if(cross(a,b)<EPS)return -1;
  if(dot(a,b)<-EPS)return +2;
  if(a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y)return -2;
  return 0;
}

double vec_abs(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}

double distance_ls_p(point a, point b, point c) {
  if ( dot(b-a, c-a) < EPS ) return vec_abs(c-a);
  if ( dot(a-b, c-b) < EPS ) return vec_abs(c-b);
  return abs(cross(b-a, c-a)) / vec_abs(b-a);
}

double dist(point a,point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}

int crossCS(point a, point b, circle c){
  double res=distance_ls_p(a,b,c.p);
  double ac=dist(a,c.p);
  double bc=dist(b,c.p);

  if(res>c.r || (ac<c.r && bc<c.r))return 0;
  else if(c.r-res<EPS ||(ac<c.r && bc>=c.r)||(ac>=c.r && bc<c.r))return 1;
  else return 2;
}

vector<segment> construct_edge(point* p, int n){
  vector<segment>seg,seg2;
  segment temp;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j){
	temp.a=p[i];
	temp.b=p[j];
	seg.push_back(temp);
      }
    }
  }

  int t=seg.size();
  for(int i=0;i<t;i++){
    int fg=0;
    for(int j=0;j<t;j++){
      if(i!=j && vec_abs(seg[i].b-seg[j].a)<=EPS){
	if(ccw(seg[i].a,seg[i].b,seg[j].b)==1){
	  fg=1;
	  break;
	}
      }
    }
    if(!fg)seg2.push_back(seg[i]);
  }
  return seg2;
}

int point_contain(vector<segment> ps, point p, int n){
  int cnt=ccw(ps[0].a,ps[0].b,p);

  for(int i=0;i<n;i++)
    if(cnt!=ccw(ps[i].a,ps[i].b,p))return 0;
  
  return 1;
}

int main(void){
  point p[3];
  vector<segment> t;
  circle C;

  while(true){
    for(int i=0;i<3;i++){
      cin >> p[i].x >> p[i].y;
      if(p[i].x==0 && p[i].y==0)return 0;
    }
    cin >> C.p.x >> C.p.y >> C.r;

    double ans=0;
    for(int i=0;i<3;i++){
	int tmp=dist(p[i],C.p);
	if(tmp>ans)ans=tmp;
    }
    if(C.r>=ans){
      cout <<'b'<<endl;
      continue;
    }
    
    t=construct_edge(p,3);
    int res1=point_contain(t,C.p,3);
    double res2=100000000;
    for(int i=0;i<3;i++)
      res2=min(res2,distance_ls_p(t[i].a,t[i].b,C.p));

    if(res1 && C.r<=res2)cout <<'a'<< endl;
    else if(!res1 && C.r<res2)cout <<'d'<< endl;
    else cout <<'c'<< endl;
    
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<typename Num>
        constexpr Num mypow(Num a, long long b) {
            if(b==0)return 1;
            if (a==0)return 0;
            Num x = 1;
              while (b > 0) {
                if(b & 1)x*=a;
                a*=a;
                b >>= 1;
              }
              return x;
        }

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        vl L(n);
        rep(i,n)cin>>L[i];
        ll res=0;
        sort(all(L));
        rep(i,n-2){
            rep2(j,i+1,n-1){
                auto itr=lower_bound(all(L),L[j]+L[i]);
                ll x=itr-L.begin();
                res+=max(x-j-1,0LL);
            }
        }
        cout<<res<<endl;
    }

Measured memory_bytes: 3668
n = int(input())
dis = [list(map(int,input().split())) for _ in range(n)]
ans = 0
num = 0
from itertools import permutations
for path in list(permutations(range(n))):
  num += 1
  path = list(path)
  distance = 0
  for i in range(1,n):
    xi = dis[path[i-1]][0]
    xj = dis[path[i]][0]
    yi = dis[path[i-1]][1]
    yj = dis[path[i]][1]
    distance += (pow(xi-xj,2)+pow(yi-yj,2))**0.5
  ans = ans + distance
ans = ans/num
print(ans)

Measured memory_bytes: 8052
n = int(input())
ai = [int(e) for e in input().split()]
bi = []
for i in range(len(ai)):
    bi.append(ai[i]-i-1)
bi = sorted(bi)
b = bi[int(len(bi)/2)]
su = 0
for i in range(len(ai)):
    su += abs(ai[i] - (b+i+1))
print(su)

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

int main() {

  int N, r = 0, b = 0;
  cin >> N;
  string s;
  cin >> s;

  for (int i = 0; i < N; i++) {
if( s.at(i) == 'R' ){
r++;
}
else{
b++;
}
}

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

}

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#ifdef DEBUG
#include "./Lib/debug.hpp"
#else
#define dump(...)
template<class T>inline auto d_val(T a, T b) { return a; }
#endif

/* (=＾o＾=) */
#define int ll

/* macro */
#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define REPI2(it,b,e) for(auto it = (b); it != (e); ++it)
#define REPI(it,c) REPI2(it, (c).begin(), (c).end())
#define RREPI(it,c) REPI2(it, (c).rbegin(), (c).rend())
#define REPI_ERACE2(it, b, e) for(auto it = (b); it != (e);)
#define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end())
#define ALL(x) (x).begin(),(x).end()
#define cauto const auto&
/* macro func */
#define SORT(x) do{sort(ALL(x));}while(false)
#define RSORT(x) do{sort((x).rbegin(),(x).rend());}while(false)
#define UNIQUE(v) do{v.erase( unique(v.begin(), v.end()), v.end() );}while(false)
#define MAX(x,y) do{x = std::max(x,y);}while(false)
#define MIN(x,y) do{x = std::min(x,y);}while(false)
#define BR do{cout<<"\n";}while(false)

/* type define */
using ll = long long;
using PAIR = std::pair<ll, ll>;
using VS = std::vector<std::string>;
using VL = std::vector<long long>;
using VVL = std::vector<VL>;
using VVVL = std::vector<VVL>;
using VD = std::vector<double>;

/* using std */
using std::cout;
constexpr char endl = '\n';
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::unordered_multiset;
using std::multiset;
using std::bitset;
using std::priority_queue;

/* constant value */
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;

/* Initial processing  */
struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; }_Preprocessing;

/* define hash */
namespace std { template <>	class hash<std::pair<ll, ll>> { public:	size_t operator()(const std::pair<ll, ll>& x) const { return hash<ll>()(1000000000 * x.first + x.second); } }; }

/* input */
template<class T> std::istream& operator >> (std::istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }

//=============================================================================================

signed main() {
	string str;
	cin >> str;

	unordered_map<char, ll> mp;
	REPC(c, str) {
		mp[c]++;
	}
	ll cnt = 0;
	REPC(p, mp) {
		if (p.second == 2) { ++cnt; }
	}
	cout << ((cnt == 2) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
G=[set() for i in range(N)]
a=[0 for i in range(M)]
b=[0 for i in range(M)]
for i in range(M):
    a[i],b[i]=map(int,input().split())
    a[i]-=1;b[i]-=1
    G[a[i]].add(b[i])
    G[b[i]].add(a[i])
q=[0]
reached=[0 for i in range(N)];reached[0]=1
color=[0 for i in range(N)];color[0]=1
while(len(q)>0):
    r=q.pop()
    for p in G[r]:
        if reached[p]==1:
            continue
        reached[p]=1
        color[p]=-color[r]
        q.append(p)
flag=1
for i in range(M):
    if color[a[i]]+color[b[i]]!=0:
        flag=0
        break
if flag==1:
    X=0
    Y=0
    for i in range(N):
        if color[i]==1:
            X+=1
        else:
            Y+=1
    print(X*Y-M)
else:
    print(-M+(N*(N-1))//2)

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

struct HUT{
    long long Number;
    int size;
};

long long exor(long long a, long long b){
    long long n=1;
    long long ans=0;
    while(1){
        if(a%2 != b%2){
            ans += n;
        }
        a /= 2;
        b /= 2;
        n *= 2;
        if(a==0 && b==0) break;
    }
    return ans;
}

int main(){
    int N;
    cin >> N;
    vector<HUT> hut;
    long long inp;
    for(int i=0; i<N; i++){
        cin >> inp;
        int flag=0;
        for(int j=0; j<hut.size(); j++){
            if(hut.at(j).Number==inp){
                hut.at(j).size++;
                flag=1;
                break;
            }
        }
        if(flag==0){
            HUT appnd;
            appnd.size=1;
            appnd.Number=inp;
            hut.push_back(appnd);
        }
        if(hut.size()>=4){
            cout << "No";
            return 0;
        }
    }
    string ans = "Yes";
    if(hut.size() != 3){
        if(hut.size()==1){
            if(hut.at(0).Number==0){
                cout << "Yes";
                return 0;
            }
        }else{
            if(hut.at(0).Number==0 && hut.at(1).Number!=0){
                if(hut.at(0).size==N/3){
                    cout << "Yes";
                    return 0;
                }
            }else if(hut.at(0).Number!=0 && hut.at(1).Number==0){
                if(hut.at(1).size==N/3){
                    cout << "Yes";
                    return 0;
                }
            }
        }
        ans = "No";
    }else if(hut.at(1).size != hut.at(2).size || hut.at(2).size != hut.at(0).size){
        ans = "No";
    }else if(exor(hut.at(0).Number,hut.at(1).Number) != hut.at(2).Number){
        ans = "No";
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
	int i, N, A[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	
	long long count[200001] = {}, total = 0;
	for (i = 1; i <= N; i++) count[A[i]]++;
	for (i = 1; i <= N; i++) total += count[i] * (count[i] - 1) / 2;
	for (i = 1; i <= N; i++) printf("%lld\n", total - (count[A[i]] - 1));
	fflush(stdout);
	return 0;
}

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

int     main()
{
    string s;
    cin >> s;

    if (s.size() % 2 == 1)
    {   
        cout << "No" << endl;
        return 0;
    }   
    for (int i = 0; i <= s.size() - 2; i+=2)
    {   
        if (!(s[i] == 'h' && s[i + 1] == 'i'))
        {   
            cout << "No" << endl;
            return 0;
        }   
    }   
    cout << "Yes" << endl;
}

Measured memory_bytes: 256