akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
const int N = 100005;
using std::cin;
using std::cout;

inline void up(int &x, int y) { x < y ? x = y : 0; }
inline void down(int &x, int y) { x > y ? x = y : 0; }
inline int max(const int x, const int y) { return x > y ? x : y; }
inline int min(const int x, const int y) { return x < y ? x : y; }

int n, a[100005], b[100005], c[100005];
namespace bit {
	int s[200010];
	inline void init() { memset(s, 0, sizeof s); }
	inline int lowbit(int x) { return x & -x; }
	inline void insert(int x) { for (; x <= 200010; x += lowbit(x) ) ++s[x]; }
	inline int query(int x, int ret = 0) { for (; x; x -= lowbit(x)) ret += s[x]; return ret; }
}

inline bool check(int x) {
	bit::init();
	ll s0 = 0;
	for (int i = 1; i <= n; ++i) c[i] = (a[i] >= x) ? 1 : -1;
	for (int i = 1; i <= n; ++i) c[i] = c[i - 1] + c[i];
	for (int i = 1; i <= n; ++i) bit::insert(c[i - 1] + 100005), s0 += bit::query(c[i] + 100005);
	s0 = s0 << 2;
	if (s0 >= 1ll * n * (n + 1)) return true;
	else return false;
}
inline int binary(int ret = 0) {
	int l, r;
	std::sort(b + 1, b + n + 1);
	r = std::unique(b + 1, b + n + 1) - b - 1;
	l = 1;
	while (l <= r) {
		int mid = l + r >> 1;
		if (check(b[mid])) ret = mid, l = mid + 1;
		else r = mid - 1;
	}
	return b[ret];
}
int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i], b[i] = a[i];
	cout << binary() << '\n';
	return 0;
}

Measured memory_bytes: 5524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) cerr << #v << ":"; rep(i, v.size()) cerr << " " << v[i]; cerr<<endl
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

template<typename T>
struct BinaryIndexedTree {
    /* 0-indexed */
    vector<T> data;

    BinaryIndexedTree(int sz) {
        data.assign(++sz, 0);
    }

    T sum(int k) {
        T ret = 0;
        for (++k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }

    void add(int k, T x) {
        for (++k; k < data.size(); k += k & -k) data[k] += x;
    }
};

vector<pii> Q[505050];

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> C(n);
    rep(i, n) {
        cin >> C[i];
        C[i]--;
    }
    vector<int> ans(q);
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        Q[r].pb({l, i});
    }
    BinaryIndexedTree<int> BIT(n);
    vector<int> R(n + 1, -1);
    rep(i, n) {
        if (R[C[i]] != -1) BIT.add(R[C[i]], -1);
        BIT.add(i, 1);
        R[C[i]] = i;
        for(auto query : Q[i]) {
            int l = query.fi, r = i;
            int idx = query.se;
            ans[idx] = BIT.sum(r) - BIT.sum(l - 1);
        }
    }
    rep(i, q) {
        cout << ans[i] << endl;
    }
}

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


Measured memory_bytes: 33332
#include <bits/stdc++.h>
using namespace std;
#define LEN 100005

int main(){
 int N,Q;
  cin>>N;
  vector<int> A(100005,0);
  int64_t S=0;
  for(int i=0;i<N;i++){
    int ts;
    cin>>ts;
    S+=ts;
    A[ts]++;
  }
  cin>>Q;
  int B[Q],C[Q];
  for(int i=0;i<Q;i++){
    scanf("%d %d",&B[i],&C[i]);
  }
  for(int i=0;i<Q;i++){
    int kw;
    kw=A[B[i]];
    A[B[i]]=0;
    A[C[i]]+=kw;
    S=S+kw*(C[i]-B[i]);
    printf("%lld\n",S);
  }
}

Measured memory_bytes: 4676
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-05-30(Sat)
   note   
**********************************************************************/

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

int main() {
  string T;
  cin >> T;
  rep(i, T.size()){
      if (T.at(i) == '?'){
          T.at(i) = 'D';
      }
  }
  cout << T << endl;
  return 0; 
}

Measured memory_bytes: 3724
n = gets.to_i

edges = []
g = Array.new(n+1){ [] }
(n-1).times do |i|
  a, b = gets.split.map(&:to_i)
  a, b = b, a if a > b # 辺は頂点 i < j の形で入れる。
  g[a] << b # 隣接リストに
  g[b] << a # 反対向きにも隣接リストに.無向グラフなので
  # gに隣接頂点だけでなく、何番目の辺の情報をいれることもある。
  edges << a+b*100_000 # 辺リストにいれる。辺が識別されてて、最後に辺リストから辺を回して色をとりだす。
end

colors = Hash.new() # Esge => color # 辺についてO(1)で使った色を見れる。O(1)はホントに?
colors_used = Hash.new # 頂点と色についてO(1)で使ったか確かめられる。
used = Array.new(n){false} # 頂点について探索済みかどうかO(1)でわかる。
que = [1] # 頂点1から見ていくので0が入っている # 探索待ちの未探索の頂点リスト

k = g.map(&:size).max # 答えとなる色の数
while v = que.shift # queにある頂点を取り出す. 破壊的メソッドなので先頭は削除される。なければnilを返す
  # k = g[v].size if k < g[v].size  # 隣接する頂点数より色数が小さければ色数を更新
  cur = 1 # 使ってない色がわからないので、とりあず色1から見ていく。
  g[v].each do |w| # vの隣接頂点wを見ていく。
    next if used[w] #trueで、探索済みの頂点なら見ない。
    v<w ? (i,j = v,w) : (i,j = w,v) # i < jの並びで頂点を捉える。
    cur += 1 while colors_used[v+cur*100_000] == true # v周りの頂点で色をつかっていれば次の色に更新していく。塗る前に使ってない色にする。
    colors_used[v+cur*100_000] = true # vに色を使ったので記録する。
    colors_used[w+cur*100_000] = true # wに色を使ったので記録する。
    colors[i+j*100_000] = cur # 辺に使った色をいれる。
    que.push(w) #探索待ちの未探索頂点リストに頂点wを入れる。
  end
  used[v] = true # 頂点vを探索済みにする。
end

puts k
edges.each{ |e| puts colors[e] }


Measured memory_bytes: 33788
N, K, Q = map(int,input().split())

A = [int(input()) for _ in range(Q) ]

L = [0 for _ in range(N) ]

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

for i in range(N):
    L[i] = K - Q + L[i]
    if(L[i]>0):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 56536
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<vector<int>> a(2,vector<int>(N));
  vector<vector<int>> sum(2,vector<int>(N,0));
  
  for(int i=0;i<2;++i){
    for(int j=0;j<N;++j){
      cin >> a.at(i).at(j);
      if(j!=0)
	sum.at(i).at(j)=sum.at(i).at(j-1)+a.at(i).at(j);
      else sum.at(i).at(j)=a.at(i).at(j); 
    }
  }

  int ans=0;
  int temp;
  for(int i=0;i<N;++i){
    temp=sum.at(0).at(i)+sum.at(1).at(N-1)-sum.at(1).at(i)+a.at(1).at(i);
    ans=max(ans,temp);
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin>>n;
	int ans=0;
		while(n)
		{
			ans+=n%10;
			n/=10;
		}
		if(ans==1)
		{
			cout<<"10";
			return 0;
		}
		cout<<ans;
		
	
	
	return 0;
}

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

typedef long long ll;
#define ten5 100000+10
#define MOD 1000000007
#define rep(i,a,n) for (int i=a;i<n;i++)
#define iif(c,t,f) ((c)?(t):(f))
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair

int intcmp(const void *v1,const void *v2){return *(int *)v1-*(int *)v2;}

int k;
void op(int v1,int v2){
  int ret =v1;
  rep(i,0,k){
    ret*=2;
  }
  cout<<ret+v2<<endl;
}

int main(){
  int a,b,c;
  cin>>a>>b>>c>>k;
  if(a>=b && a>=c)
    op(a,b+c);
  else if(b>=a && b>=c)
    op(b,a+c);
  else
    op(c,a+b);


  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		while (true){
			int n = scanner.nextInt();
			if (n == 0) break;
			int s[] = new int[n];
			int sum = 0;
			for (int i = 0; i < n; i++) {
				s[i] = scanner.nextInt();
				sum += s[i];
			}
			double m = sum / (double)n;
			double sum2 = 0;
			for (int i = 0; i < n; i++) {
				sum2 += (s[i] - m) * (s[i] - m);
			}
			double a = Math.sqrt(sum2 / (double)n);
			System.out.println(a);
		}
	}
}


Measured memory_bytes: 31552
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main () {
	int N;
	scanf("%d", &N);
	char **S = malloc((N + 1) * sizeof(char*));
	int c_ac = 0;
	int c_wa = 0;
	int c_tle = 0;
	int c_re = 0;
	for (int i = 1; i <= N; i++)
	{
		S[i] = malloc(4 * sizeof(char));
		scanf("%s", S[i]);
		if(strcmp(S[i], "AC") == 0) {
			c_ac++;
		} else if (strcmp(S[i], "WA") == 0) {
			c_wa++;
		} else if (strcmp(S[i], "TLE") == 0) {
			c_tle++;
		} else {
			c_re++;
		}
	}
	printf("AC x %d\n", c_ac);
	printf("WA x %d\n", c_wa);
	printf("TLE x %d\n", c_tle);
	printf("RE x %d\n", c_re);

	return (0);
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K; cin >> K;
  cout << v[K - 1 ] << endl;
}


Measured memory_bytes: 256
ans_list = []

def make_tanka(num, w_list, i):
    #print(num, w_list, i)
    cnt = 0
    while cnt < num:
        cnt += len(w_list[i])
        i += 1
    return [cnt, i]

while True:
    n = int(input())
    if n == 0:
        break
    w_list = []
    for i in range(n):
        w_list.append(input())

    f1 = 0
    s1 = 0
    f2 = 0
    s2 = 0
    s3 = 0
    i = 0
    ans = -1
    while True:
        #print(i)
        j = i
        f1, j = make_tanka(5, w_list, j)
        if f1 == 5:
            s1, j = make_tanka(7, w_list, j)
            if s1 == 7:
                f2, j = make_tanka(5, w_list, j)
                if f2 == 5:
                    s2, j = make_tanka(7, w_list, j)
                    if s2 == 7:
                        s3, j = make_tanka(7, w_list, j)
                        if s3 == 7:
                            ans = i
                            break
                    if ans != -1:
                        break
                if ans != -1:
                    break
            if ans != -1:
                break
        if ans != -1:
            break
        i += 1
    ans_list.append(ans + 1)

for i in ans_list:
    print(i)


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

public class Main {
    public static void main(final String[] args) {
        final FastReader s=new FastReader();
        String n = s.next();
        int sum =0;
        for(char c:n.toCharArray()){
            sum+=c-'0';
        }
        if(sum%9==0)
            System.out.println("Yes");
        else
            System.out.println("No");
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try { st = new StringTokenizer(br.readLine()); }
                catch (final IOException  e) { e.printStackTrace(); }
            }
            return st.nextToken();
        }
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }
        String nextLine() {
            String str = "";
            try { str = br.readLine(); }
            catch (final IOException e) { e.printStackTrace(); }
            return str;
        }
    }
}

Measured memory_bytes: 29884
n = int(input())
cards = {}
for i in range(n):
    card = input()
    cards[card] = 1
      
#print(cards)
  
for c in ['S', 'H', 'C', 'D']:
    for n in range(1, 14):
        key = c + ' ' + str(n)
        if not key in cards:
            print(key)


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

#define N 200123
#define mod 1000000007

int gcd(int a, int b){
	int c;
	while(b){
		c = a%b; a = b; b = c;
	}
	return a;
}

int lcm(int a, int b){
	return a/gcd(a, b)*b;
}

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    long long pem = 1, pen = 0, a[100];
    cin >> n;
    for(int i = 0 ; i < n ; i++){
    	cin >> a[i];
    	pem = lcm(pem, a[i]);
    }

    for(int i = 0 ; i < n ; i++){
    	pen += (pem/a[i]);
    }
    printf("%.6lf\n", pem/(double)pen);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)  {
    int n,r,p,c;
 
    while(1)    {
        scanf("%d %d", &n, &r);
        if(n == 0) break;
 
        int card[n];
        int temp[n];
        for(int i = 0;i <= n - 1;i++)   card[i] = n - i;
 
        for(int i = 0;i <= r - 1;i++)   {
            scanf("%d %d", &p, &c);
 
            int count = 0;
            for(int i = p - 1;i <= p + c - 2;i++)   {
                temp[count] = card[i];
                count++;
            }

            for(int i = 0;i <= p - 2;i++)   {
                temp[count] = card[i];
                count++;
            }
 
            for(int i = p + c - 1;i <= n - 1;i++)   {
                temp[count] = card[i];
                count++;
            }

            for(int i = 0;i <= n - 1;i++)   {
                card[i] = temp[i];
            }
        }
 
        printf("%d\n", card[0]);
    }
     
    return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int tot = 0;
	for (int i = 1 ; i <= n ; i++)
	{
		int ta;
		cin >> ta;
		tot ^= ta;
	}
	if (tot == 0)
		cout << "Yes\n";
	else
		cout << "No\n";
}

Measured memory_bytes: 256
i = int(input())
s1 = input()
s = list(s1)
ans  = []

for k in range(len(s1)):
    a = ord(s1[k])
    #print(a)
    b = a + i
    #print(b)
    if b > 90:
        b = b - 26
    ans.append(chr(b))

print(''.join(ans)) 

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef long long ll;
#define ALL(V) V.begin(), V.end()
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}


string Main(string S, int Q, VVS& queries)
{
  string left = S;
  string right = "";
  bool flipped = false;
  for (VS q : queries) {
    if(q[0] == "1") {
      if(!flipped) flipped = true;
      else flipped = false;
    }
    else {
      if(q[1] == "1") {
        if(flipped) left += q[2];
        else {
          string a = q[2] + right;
          right = a;
        }
      }
      else {
        if(!flipped) left += q[2];
        else {
          string a = q[2] + right;
          right = a;
        }
      }
    }             
  }
  string ans = right + left;
  if(flipped) {
    reverse(ans.begin(), ans.end());
  }
  return ans;

}

int main(void){
  	std::cin.tie(nullptr);
	  std::ios_base::sync_with_stdio(false);
	  std::cout << std::fixed << std::setprecision(15);
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    VVS queries(Q);
    REP(i, Q) {
      VS query(3);
      cin >> query[0];
      if(query[0] == "2") {
        cin >> query[1] >> query[2];
      }
      queries[i] = query;
    }
    cout << Main(S, Q, queries) << endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<tuple<string, int, int>> vec(N);
    int p;
    for (int i = 0; i < N; i++)
    {
        get<2>(vec.at(i)) = i + 1;
        cin >> get<0>(vec.at(i));
        cin >> p;
        get<1>(vec.at(i)) = 100 - p;
    }
    sort(vec.begin(), vec.end());
    for (int i = 0; i < N; i++)
    {
        cout << get<2>(vec.at(i)) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1

int main() {
  	int N, N1,  M, M1;
  cin >> N >> N1 >> M >> M1;
  if(N == M)
    cout << 0 << endl;
  else
    cout << 1 << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long a,b,r;
    cin >>a>>b;
    if(a%2==0 && b%2==0){
        r=abs(a-b)/2;
        if(a<b){
            r=r+a;
        }
        else{
            r=r+b;
        }
        cout<<r<<"\n";

    }
    else if(a%2!=0 && b%2!=0){
        r=abs(a-b)/2;
        if(a<b){
            r=r+a;
        }
        else{
            r=r+b;
        }
        cout<<r<<"\n";
    }
    else{
        cout<<"IMPOSSIBLE\n";
    }

    return 0;
}


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

int main(){
    bool flag=false;
    string s;
    cin >> s;
    if(s[0]==s[1]&&s[1]==s[2]) flag=true;
    if(s[1]==s[2]&&s[2]==s[3]) flag=true;
    if(flag) cout << "Yes" <<endl;
    else cout << "No" <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
using namespace std;
typedef long long int ll;

int N;
ll a[100010][3];
ll dp[100010][3];

void chmax(ll &a, ll b){
  if (a < b) a = b;
}

int main(){
  cin >> N;
  
  for (int i = 0; i < N; i++){
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 3; j++){
      for (int k = 0; k < 3; k++){
        if (j == k) continue;
        chmax(dp[i+1][k],dp[i][j] + a[i][k]);
      }
    }
  }
  
  ll res = 0;
  
  for (int i = 0; i < 3; i++){
    chmax(res, dp[N][i]);
  }
  
  cout << res;
  
  return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>

int Abs(int x){
  if( x > 0 ) return x;
  else return -x;
}

int main(void){
  int a,b,c,d;
  
  scanf("%d %d %d %d",&a,&b,&c,&d);
  
  if( Abs(a-c) <= d ) printf("Yes\n");
  else if( Abs(a-b) <= d && Abs(b-c) <= d ) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double d1=6*m,d2=30*h+m/2;
	d1=abs(d2-d1);
	d1=min(d1,abs(360-d1));
	double ans=a*a+b*b-2*a*b*cos((d1/180)*M_PI);
	ans=sqrtl(ans);
	cout<<fixed;
	cout<<setprecision(20)<<ans;
}



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

int main(){
  int ans=0;
  string s;
  cin >> s;
  for(int i=0;i<s.size()/2;i++){
    if(s[i]!=s[s.size()-1-i]) ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  for (int i = 0;; i++) {
    if (i % 2) {
      a -= d;
      if (a <= 0) {
        cout << "No" << endl;
        return 0;
      }
    } else {
      c -= b;
      if (c <= 0) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int d, n;
    cin >> d >> n;
    if (n == 100) n++;
    int res = 1;
    rep(i, d) res *= 100;
    res *= n;
    cout << res << endl;
    return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	long N;
	cin >>N;
	if (1==N%2) {
		cout <<0 <<endl;
		return 0;
	}
	long S=0;
	for (long i=10; i<=9223372036854775807/5; i*=5) {
		S +=N/i;
	}
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define setbits __builtin_popcount 
#define big 1e9+7
using namespace std;
ll n,k,m,mod,cnt;
ll a[500005], flag[500005];
string s[500005];
int main()
{
	IOS
	ll x,y;
	cin>>n>>m;
	for(int i = 0; i < m; ++i)
	{
		cin>>x>>s[i];
		if((s[i] == "WA") and (!flag[x]))
		{
			a[x]++;
			// if(flag[x])
			// 	mod--;
		}
		else
		{ 
			cnt += a[x];
			mod += !flag[x];
			a[x] = 0,flag[x] = 1;
		}
	}
	cout<<mod<<" "<<cnt<<endl;
    return 0;
}

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

using namespace std;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define MP make_pair
#define PB push_back
#define X first
#define Y second

typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    cin >> s;

    s[1] = (s[1] == 'B' ? 'R' : 'B');

    cout << s << '\n';

    return 0;
}

// g++ sol.cpp -o sol.out -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17

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

int main(void) {
    long long N;
    cin >> N;
    long long ans = 0;
    for (long long i = 1; i <= N; i++) {
        long long n = N / i;
        ans += i * n + i * n * (n - 1) / 2L;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3692
var
	s,c:double;
	ans,T,nx,ny:int64;
	N,i,r:Longint;
	x,y:array[1..100]of Longint;
begin
	read(N);
	for i:=1 to N do read(x[i],y[i]);
	for r:=0 to 99 do begin
		s:=sin(r);
		c:=cos(r);
		nx:=0;
		ny:=0;
		for i:=1 to N do begin
			if x[i]*s+y[i]*c>=0 then begin
				inc(nx,x[i]);
				inc(ny,y[i]);
			end;
		end;
		T:=nx*nx+ny*ny;
		if ans<T then ans:=T;
	end;
	writeln(sqrt(ans):0:16);
end.

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int main(){
  int A,B;
  string s;
  cin >> A >> B >> s;
  for(int i = 0; i < A; i++){
    if( '0' <= s[i] && '9' >= s[i]) continue;
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  if( '-' != s[A]) {
    cout << "No" << endl;
    return 0;
  }
  for(int i = A + 1; i < B + A + 1; i++){
    if( '0' <= s[i] && '9' >= s[i]) continue;
    else{
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


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

int main() 
{   
  

 
long long int n,k;
scanf("%lld",&n);
long long int a[n],b[n],c[n];

    for(long long int i = 0; i <n; i++){
   
scanf("%lld %lld %lld",&a[i],&b[i],&c[i]);
}


    for(long long int i = 1; i <n; i++){
 
a[i]=a[i]+max(b[i-1],c[i-1]);
 
b[i]=b[i]+max(a[i-1],c[i-1]);
 
c[i]=c[i]+max(b[i-1],a[i-1]);


}
long long int ans=max(a[n-1],b[n-1]);
ans=max(ans,c[n-1]);
printf("%lld\n",ans);



}

  
 

Measured memory_bytes: 2560
def solve():
    from math import gcd
    
    # Post-order tree traversal
    def traversal(bar_id):
        if bar_id == 0:
            return 1
        p, q, r, b = nodes[bar_id]
        r_w = traversal(r)
        b_w = traversal(b)
        cf = gcd(p * r_w, q * b_w)
        
        return r_w * b_w * (p + q) // cf
    
    from sys import stdin
    file_input = stdin
    
    while True:
        n = int(file_input.readline())
        if n == 0:
            break
        
        root_id = n * (n + 1) // 2
        nodes = [None]
        for i in range(1, n + 1):
            p, q, r, b = map(int, file_input.readline().split())
            g = gcd(p, q)
            nodes.append((p // g, q // g, r, b))
            root_id -= (r + b)
        
        print(traversal(root_id))

solve()


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

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

    vector<int> A;
    int a;

    for(int i=0;i<N;i++){
        cin >> a;
        A.push_back(a);
    }
    long long ans=1e15,sum=0;
    for(int i=-100;i<=100;i++){
        sum=0;
        for(int j=0;j<N;j++){
            sum+=(A[j]-i)*(A[j]-i);
        }
        ans=min(ans,sum);
    }
    cout << ans << endl;
}

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

//    int n=132;
//    bitset<16>binar(n);
//    int a = bitset<16>(binar).to_ulong();
//    cout<<a;

#define int long long
#define pb push_back
#define rep(i,b) for ( int i = 0; i < b; i++)
#define all(c) (c).begin(),(c).end()

using namespace std;

signed main()
{
 int n,k;
 cin>>n>>k;
 vector<int> a(n+1);
 
 while(k--){
 	int d; cin>>d;
 	while(d--){
 		int val;
 		cin>>val;
 		a[val]++;
	 }
 }
 int A=0;
 for(int i=1; i<n+1; i++){
 	if(a[i]==0){
 		A++;
	 }
 }
 cout<<A;
  
}
        
        
    

    





Measured memory_bytes: 3604
'use strict';
const main = input => {
  const n = parseInt(input[0]);
  const s = input[1];
  let ans = 0;
  for(let i=0; i<n/2; i++) {
    if (s[i] !== s[i+n/2]) {
      ans = 1;
    }
  }
  console.log(ans==1?'No':'Yes');
  
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 7628
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n; cin >> n;
	int a[n];
	rep(i, n) cin >> a[i];

	int ans = INF2;

	rep(j, 2) {
		int tmp = 0, sum = 0;
		int flag;
		if (j == 0) flag = -1;
		else flag = 1;
		rep(i, n) {
			sum += a[i];
			tmp += max(0LL, flag * sum + 1);
			sum += -flag * max(0LL, flag * sum + 1);
			flag = (-1) * flag;
			//cout << sum << endl;
		}
		ans = min(ans, tmp);
		
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
            var n = int.Parse(Console.ReadLine());
            var numArray = new int[n];
            for(int i=0; i<n; i++) {
                numArray[i] = int.Parse(Console.ReadLine());
            }
            var sortArray = numArray.OrderByDescending(s=>s).ToArray();

            var first = sortArray[0];
            var second = sortArray[1];

            foreach(int num in numArray) {
                Console.WriteLine(num == first ? second : first);
            }
    }
}


Measured memory_bytes: 22484
#include <stdio.h>
  
int main(void) {
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if(x >= r && y >= r && (H - r) >= y && (W - r) >= x) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2108
isPrime=[1 for i in range(10**6+1)]
isPrime[0]=0;isPrime[1]=0
for i in range(2,10**6+1):
    if isPrime[i]==0:
        continue
    for j in range(2*i,10**6+1,i):
        isPrime[j]=0
X=int(input())
for i in range(X,10**6+1):
    if isPrime[i]==1:
        print(i)
        exit()


Measured memory_bytes: 16896
# 初期入力
S_str,T_str = (x for x in input().split(" "))
A_S_num,B_T_num = list(map(int, input().split()))
U_S_or_T = input()

#
if U_S_or_T ==S_str:
    A_S_num -= 1
elif U_S_or_T == T_str:
    B_T_num -= 1
print(A_S_num,B_T_num)

Measured memory_bytes: 2940
#include<cstdio>
#include<algorithm>
using namespace std;
int a[101]; 
int main()
{
	scanf("%d%d%d",&a[1],&a[2],&a[3]);
	sort(1+a,a+4);
	printf("%d",a[3]*10+a[2]+a[1]);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int h,w,d;
    cin>>h>>w>>d;
    vector<int> x(h*w),y(h*w);
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int w;
            cin>>w;
            x[w-1]=i;
            y[w-1]=j;
        }
    }
    int q;
    cin>>q;
    vector<int> dp(h*w);
    for(int i=0;i<d;i++){
        for(int j=d+i;j<h*w;j+=d){
            dp[j]=dp[j-d]+abs(x[j]-x[j-d])+abs(y[j]-y[j-d]);
        }
    }
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;
        cout<<dp[r-1]-dp[l-1]<<endl;
    }

    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0;i < (n); ++i)

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

Measured memory_bytes: 3624
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nCells := scanInt(sc)
	heights := make([]int64, nCells+1)
	for i := 0; i < nCells; i++ {
		heights[i] = int64(scanInt(sc))
	}
	heights[nCells] = 1000000000 + 1

	max := 0
	nMoves := 0
	prev := heights[0]
	for i := 1; i <= nCells; i++ {
		if prev >= heights[i] {
			nMoves += 1
		} else {
			if nMoves > max {
				max = nMoves
			}
			nMoves = 0
		}
		prev = heights[i]
	}

	fmt.Println(max)
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


Measured memory_bytes: 3072
k = 0
m,d  = (int(i) for i in input().split()) 
listm = range(1,m + 1)
listd = range(1,d + 1)
for a in listm:
 for b in listd:
  if len(str(b)) >= 2:
   if int(str(b)[0]) >= 2:
    if int(str(b)[1]) >= 2:
       #print(a,"y",b,"d")
       if a == int(str(b)[0]) * int(str(b)[1]):
         #print(a,"y",b,"d")
         k = k + 1
print(k)
      

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

class inputFile
{
	//変数
	bool b_testMode;
	List<string> list_s_line;
	int i_index;

	//コンストラクタ
	public inputFile()
	{
		//変数初期化
		b_testMode = false;
		list_s_line = new List<string>();
		i_index = 0;

		//ファイル読み込み
		read_file();
	}

	//ファイル読み込み
	void read_file()
	{
		//テストモードの場合のみ
		if (b_testMode == true)
		{
			// StreamReader の新しいインスタンスを生成する
			System.IO.StreamReader cReader =
				new System.IO.StreamReader(@"C:\000\VisualStudio-workspace\paiza\inputFile.txt", Encoding.Default);

			// 読み込みできる文字がなくなるまで繰り返す
			while (cReader.Peek() >= 0)
			{
				// ファイルを 1 行ずつ読み込む
				string s_temp = cReader.ReadLine();
				// 読み込んだものを追加で格納する
				list_s_line.Add(s_temp);
			}

			// cReader を閉じる (正しくは オブジェクトの破棄を保証する を参照)
			cReader.Close();
		}
	}

	//1行ずつ取得
	public string get()
	{
		//テストモードの場合
		if (b_testMode == true)
		{
			if (i_index >= list_s_line.Count)
			{
				return "";
			}

			return list_s_line[i_index++];
		}
		//本番モードの場合
		else
		{
			string s_temp = Console.ReadLine();
			if(s_temp == null || s_temp == "")
			{
				return "";
			}
			else
			{
				return s_temp;
			}
		}
	}
}

class Program
{
	//クラス変数
	static inputFile input;

	//Main
	static void Main(string[] args)
	{
		//ファイル読み込み
		input = new inputFile();

		//データ作成
		PRM = new Param();
		make_data();

		//メインロジック
		main_logic();
	}

	//データ作成
	static Param PRM;
	class Param
	{
		//==================================================
		public List<int> cl_list_i_57 { set; get; }
		//==================================================
		public Param()
		{
			string[] a_s;
			//==================================================
			cl_list_i_57 = new List<int>();
			//入力
			//入力は以下の形式で標準入力から与えられる。
			//A B C
			a_s = input.get().Split(' ');
			foreach(string in_s in a_s)
			{
				cl_list_i_57.Add(int.Parse(in_s));
			}
			//==================================================
		}
	}
	//==================================================

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

	static void make_data()
	{
		//==================================================

		//==================================================
	}

	//メインロジック
	static void main_logic()
	{
		//==================================================
		//出力
		//文節の並びを五七五にすることができるなら YES 、そうでないなら NO を出力せよ。
		bool b_check_5_1 = false;
		bool b_check_5_2 = false;
		bool b_check_7 = false;
		foreach (int in_i in PRM.cl_list_i_57)
		{
			if(in_i == 5)
			{
				if (b_check_5_1 == false)
				{
					b_check_5_1 = true;
				}
				else
				{
					b_check_5_2 = true;
				}
			}
			else if(in_i == 7)
			{
				b_check_7 = true;
			}
		}
		if(b_check_5_1==true && b_check_5_2==true && b_check_7 == true)
		{
			Console.WriteLine("YES");
		}
		else
		{
			Console.WriteLine("NO");
		}
		//==================================================
	}

}

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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e5+5; 

int main(){
	fast;
	ll n; cin >> n;
	string s,t; cin >> s >> t;
	string ans = "";
	
	rep(i,0,n-1){
	    ans += s[i];
	    ans += t[i];
	}
	
	cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
 
int main() {
  int a,b,c=INT_MAX,d=0,count=0,e,f;
  cin>>a>>b;
  for(int i=0;i<a;i++){
    cin>>e>>f;
    d=max(e,d);
    c=min(f,c);
  }
  count=c-d+1;
  if(count<=0){
    cout<<0;
    return 0;
  }
  cout<<count;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanInit()

	n := nextInt()
	d := map[int]int{}
	for i := 0; i < n; i++ {
		d[nextInt()]++
	}
	m := nextInt()
	t := map[int]int{}
	for i := 0; i < m; i++ {
		t[nextInt()]++
	}

	for k, v := range t {
		if d[k] < v {
			fmt.Println("NO")
			return
		}
	}

	fmt.Println("YES")
	return
}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 21532
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int h, w, k;
int ans=9999999, tmp;
vector<int> bi, cnt, pcnt;
vector< vector<int> > board;

//0~pa-1を長さnで生成、合計pa^n個生成
void bitgen(int n) {

	//生成完了時の処理
	if (n == 0) {

		//for (int i = 0;i<bi.size();i++) cout << bi[i] << "  ";
		//cout << endl;

		int bsz = 1;
		for (int i = 0;i < bi.size();i++) bsz += bi[i];

        if(ans<=bsz) return;
      
		cnt.resize(bsz);
		pcnt.resize(bsz);
		int p, flag;
		tmp = 0;
		for (int j = 0;j < bsz;j++) cnt[j] = 0;
		
		for (int i = 0;i < w;i++) {
			//cout << i << " " << bsz << endl;
			p = 0;
			flag = 0;
			for (int j = 0;j < bsz;j++) pcnt[j] = 0;

			for (int j = 0;j < h;j++) {
				cnt[p] += board[j][i];
				pcnt[p] += board[j][i];
				if (bi[j]) p++;
			}

			for (int j = 0;j < bsz;j++) {
				if(cnt[j] > k) flag = 1;
				if (pcnt[j] > k) return;
			}

			//cout<< "w=" << i << " " << cnt[0] << " " << pcnt[0] << endl;
			if(flag){
				//cout << i << endl;
				for (int j = 0;j < bsz;j++) {
					//cout << cnt[j] << " dd " << pcnt[j] << endl;
					cnt[j] = pcnt[j];
				}
				tmp++;
			}

		}

		tmp += bsz-1;
		ans = min(ans, tmp);
		return;
	}

	//再帰部分
	for (int i = 0;i<2;i++) {
		bi[n - 1] = i;
		bitgen(n - 1);
	}
}

int main() {

	string s;
	cin >> h >> w >> k;

	board.resize(h);
	for (int i = 0;i<h;i++) board[i].resize(w);

	for (int i = 0;i<h;i++) {
		cin >> s;
		for (int j = 0;j<w;j++) {
			board[i][j] = (int)(s[j] - '0');
		}
	}

	/*for (int i = 0;i<h;i++) {
		for (int j = 0;j<w;j++) {
			cout << board[i][j];
		}
		cout << endl;
	}*/

	bi.resize(h-1);
	bitgen(h-1);

	cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<string>
#include <iostream>
#include <cmath>
using ll = long long;
using namespace std;
  
  
int main() { 
  ll n; cin >> n;
  if(n%10 == 2 || n%10 == 4 ||n%10 == 5 || n%10 == 7 || n%10 ==9)
    cout << "hon" <<endl;
  if(n%10 == 0 || n%10 == 1 ||n%10 == 6 || n%10 == 8)
    cout << "pon" <<endl;
  if(n%10 ==3)
    cout << "bon" <<endl;
  return 0;
}

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

int m, x, y;
int check(int a[15][15]){
	int f = 1;
	if(x == m)x -= m, f = 0;
	if(y == m)y -= m, f = 0;
	if(x == -1)x = m-1, f = 0;
	if(a[y][x]){x--;y++;f = 0;}
	if(f)return 0;
	check(a);
}

int func(int a[15][15], int n){
	a[y++][x++] = n;
	int f = 0;
	for(int i = 0;i < m;i++)
	for(int j = 0;j < m;j++)if(!a[i][j])f = 1;
	if(!f)return 0;
	check(a);
	func(a, n+1);
}

int main(){
	int a[15][15];
	while(scanf("%d", &m)){
		if(!m)break;
		fill((int*)a, (int*)(a+15), 0);
		x =  m/2, y = m/2+1;
		func(a, 1);
		for(int i = 0;i < m;i++){
			for(int j = 0;j < m;j++)printf("%4d", a[i][j]);
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 3228
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 705
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,m,mp[maxn][maxn],cnt,vis[maxn],col[maxn],f;
int t[maxn][2],dp[maxn][maxn];
bitset <maxn*4> s;

inline void dfs(int u)
{
	t[cnt][col[u]]++; vis[u]=1;
	for(int i=1;i<=n;i++)
	{
		if(i==u) continue;
		if(mp[u][i]==0&&vis[i]==0) col[i]=col[u]^1,dfs(i);
		else if(mp[u][i]==0&&col[i]==col[u]) {f=1; return;}
	}
}

inline int cal(int x,int y){return x*(x-1)/2+y*(y-1)/2;}

int main()
{
	n=read(); m=read();
	for(int i=1;i<=m;i++) {int u=read(),v=read(); mp[u][v]=mp[v][u]=1;}
	for(int i=1;i<=n;i++) if(!vis[i]) cnt++,dfs(i);
	s[0]=1; dp[0][0]=1;
	for(int i=1;i<=cnt;i++)
	{
		s=(s<<t[i][0])|(s<<t[i][1]);
		for(int j=n;j>=0;j--)
		{
			if(j>=t[i][0]) dp[i][j]|=dp[i-1][j-t[i][0]];
			if(j>=t[i][1]) dp[i][j]|=dp[i-1][j-t[i][1]];
		}
	}
	//for(int i=0;i<=n;i++) cout<<dp[nw][i]<<" "; cout<<endl;
	int ans=inf;
	for(int i=0;i<=n;i++) if(dp[cnt][i]) ans=min(ans,cal(i,n-i));
	if(f==1) puts("-1"); else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4096
/*
@Date    : 2019-08-20 10:13:37
@Author  : Adscn (adscn@qq.com)
@Link    : https://www.cnblogs.com/LLCSBlog
*/
#include<bits/stdc++.h>
using namespace std;
#define IL inline
#define RG register
#define gi getint()
#define gc getchar()
#define File(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
IL int getint()
{
	RG int xi=0;
	RG char ch=gc;
	bool f=0;
	while(ch<'0'||ch>'9')ch=='-'?f=1:f,ch=gc;
	while(ch>='0'&&ch<='9')xi=(xi<<1)+(xi<<3)+ch-48,ch=gc;
	return f?-xi:xi;
}
template<typename T>
IL void pi(T k,char ch=0)
{
	if(k<0)k=-k,putchar('-');
	if(k>=10)pi(k/10,0);
	putchar(k%10+'0');
	if(ch)putchar(ch);
}
#define int long long
const int N=2000+7;
const int mod=1e9+7;
inline void exgcd(int a,int b,int &x,int &y)
{
	if(!b){
		x=1,y=0;
		return;
	}
	exgcd(b,a%b,y,x);
	y-=a/b*x;
}
inline int inv(int qwq){
	int x,y;
	exgcd(qwq,mod,x,y);
	return (x%mod+mod)%mod;
}
long long invf[N*N],fac[N*N];
long long f[N][N];
inline int C(int n,int m){
//	if(n>m)return 0;
	return (1ll*fac[m]*invf[n]%mod*invf[m-n])%mod;
}
signed main(void)
{
	#ifndef ONLINE_JUDGE
//	File("");
	#endif
	int n=gi,k=gi;
	if(k==1)return pi(1),0;
	fac[0]=1;
	for(int i=1;i<=N*N;++i)fac[i]=(1ll*fac[i-1]*i)%mod;
	invf[N*N]=inv(fac[N*N]);
	for(int i=N*N-1;~i;--i)invf[i]=(1ll*invf[i+1]*(i+1))%mod;
	f[0][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=i;++j)
		{
			f[i][j]=f[i-1][j];
			if(j)(f[i][j]+=f[i][j-1]*(n-j+1)%mod*C(k-2,n-i+(n-j+1)*(k-1)-1)%mod)%=mod;
		}
	cout<<f[n][n];
	return 0;
}

Measured memory_bytes: 93184
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	al := make([]int, n+1)
	Lim := 100

	// loop回す
	for x := 1; x <= Lim; x++ {
		for y := 1; y <= Lim; y++ {
			for z := 1; z <= Lim; z++ {
				p := f(x, y, z)
				if p <= n {
					al[p]++
				}
			}
		}

	}

	for i := 1; i <= n; i++ {
		fmt.Println(al[i])
	}

}
func f(x int, y int, z int) int {
	return x*x + y*y + z*z + x*y + y*z + x*z
}

func isInteger(x float64) bool {
	return math.Floor(x) == x
}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1924
a, b, c, x, y = map(int, input().split())

ans = a*x + b*y
ans = min(ans, 2*c*max(x, y))
if x < y:
    ans = min(ans, c*2*x + b*(y-x))
else:
    ans = min(ans, c*2*y + a*(x-y))
print(ans)

Measured memory_bytes: 3064
#include<iostream>

int main() {
	int a = 0;
	int b = 0;
	int c = 0;
	std::cin >> a >> b >> c;
	int d = b * c;
	if (a<=d) {
		std::cout<<"Yes"<<std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
}

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

int main()
{
    int R, G , B , K ;
    cin>>R>>G>>B>>K;
    while(G<=R && K>0)
    {
        G = G*2 ;
        K--;
    }
    while(B<=G && K>0)
    {
        B = B*2;
        K--;
    }
    if(B>G && G>R && K>=0)
        cout<<"Yes";
    else
        cout<<"No";
        
    return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n;
    cin >> n;

    vector<ll> a(n);
    rep (i, n) {
        cin >> a[i];
    }

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

    double ans1 = a[n-1];
    double ans2 = INF;
    double th = ans1/2;
    double memo = INF;
    rep (i, n-1) {
        if (abs(a[i]-th) < memo) {
            memo = abs(a[i]-th);
            ans2 = a[i];
        }
    }

    cout << ll(ans1) << " " << ll(ans2) << endl;
    return 0;
}

Measured memory_bytes: 1024
// Problem: B - Multiple of 9
// Contest: AtCoder - AtCoder Beginner Contest 176
// URL: https://atcoder.jp/contests/abc176/tasks/abc176_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>inline void read(T &FF){
	T RR=1;FF=0;char CH=getchar();
	for(;!isdigit(CH);CH=getchar())if(CH=='-')RR=-1;
	for(;isdigit(CH);CH=getchar())FF=(FF<<1)+(FF<<3)+(CH^48);
	FF*=RR;
}
int main(){
	string a;
	int s=0;
	cin>>a;
	for(int i=0;i<a.size();i++)
		s+=a[i]-48;
	if(s%9==0)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  deque<char> dq;
  int n = s.size();
  rep(i, 0, n) { dq.push_back(s[i]); }

  bool dir = true;
  int q;
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      dir = !dir;
    } else {
      int f;
      char c;
      cin >> f >> c;

      if (dir) {
        if (f == 1)
          dq.push_front(c);
        else
          dq.push_back(c);
      } else {
        if (f == 1)
          dq.push_back(c);
        else
          dq.push_front(c);
      }
    }
  }

  if (!dir)
    reverse(dq.begin(), dq.end());
  for (auto d : dq) {
    cout << d;
  }
  cout << endl;
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define ll long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define inf 1e18
#define vll vector<ll>
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define flr(i,a,b) for(ll i=a;i>b;i--)
#define db(x) cout << '>' << #x << ':' << x << endl;
#define print(v) for(auto i=v.begin();i!=v.end();i++){cout<<*i<<" ";}cout<<"\n";
#define MOD 1000000007
const ll N = 2e5;

int main()
{
    speed;
    ll n,m; cin>>n>>m;
    ll sum=0;
    forn(i,m) {
    	ll x; cin>>x;
    	sum+=x;
    }
    if(sum<=n) cout<<n-sum<<endl;
    else cout<<-1<<endl;
    return 0;
}


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

using namespace std;
long long mods[200001];
int main() {
    long long N;
    long long X, M;
    cin >> N >> X >> M;

    int loop = 1;
    int loopbegin = -1;
    mods[0] = X;
    set<long long> st;
    st.insert(X);

    long long x = X;
    while (1) {
        x = (x * x) % M;
        if (st.find(x) != st.end()) {
            for (int i=0; i<loop; i++) {
                if (x == mods[i]) {
                    loopbegin = i;
                    break;
                }
            }
            break;
        }
        mods[loop++] = x;
        st.insert(x);
    }

    long long answer = 0;
    long long loopsum = 0;
    long long looplen = loop - loopbegin;
    for (int i=loopbegin; i<loop; i++) loopsum += mods[i];
    long long rest = N;
    for (int i=0; i<loopbegin; i++) {
        rest--;
        answer += mods[i];
    }

    answer += (rest / looplen) * loopsum;

    rest = rest % looplen;
    for (int i=0; i<rest; i++) {
        answer += mods[loopbegin+i];
    }
    cout << answer << endl;
    return 0;
}



Measured memory_bytes: 6272
import copy

N = int(input())
S = list(input())

lst = []
lst.append({"W": 0, "E": 0})
for i in range(1,len(S)+1):
  res = {"W": 0, "E": 0}
  if S[i-1] == "W":
    res["W"] += lst[i-1]["W"] + 1
    res["E"] += lst[i-1]["E"]
  else:
    res["W"] += lst[i-1]["W"]
    res["E"] += lst[i-1]["E"] + 1
  lst.append(res)
ans = N
for i in range(1,len(lst)):
  n = 0
  if (i != len(lst)-1):
    n = lst[i-1]["W"] + (lst[-1]["E"] - lst[i]["E"])
  else:
    n = lst[i-1]["W"]
  if (n < ans):
    ans = n
print(ans)

Measured memory_bytes: 116684