akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
#include <climits>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, a[110], b[110];
vector<int> vec[110];
int ans1;
ll ans2;
int ma[110];

pair<int, int> dfs(int v, int p) {
	int ma = 0, k = v;
	for (int i = 0; i < (int)vec[v].size(); i++) {
		if (vec[v][i] == p)continue;
		pair<int, int> q = dfs(vec[v][i], v);
		if (ma < q.first)ma = q.first, k = q.second;
	}
	return make_pair(ma + 1, k);
}

void dfs2(int v, int p, int k) {
	int cnt = 0;
	for (int i = 0; i < (int)vec[v].size(); i++) {
		if (vec[v][i] == p)continue;
		cnt++;
	}
	ma[k] = max(ma[k], cnt);
	for (int i = 0; i < (int)vec[v].size(); i++) {
		if (vec[v][i] == p)continue;
		dfs2(vec[v][i], v, k + 1);
	}
}

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> n;
	ans1 = n, ans2 = n;
	for (int i = 1; i < n; i++) {
		cin >> a[i] >> b[i];
		vec[a[i]].push_back(b[i]);
		vec[b[i]].push_back(a[i]);
	}
	int p = dfs(1, 0).second;
	int k = dfs(p, 0).first;
	if (k % 2) {
		for (int i = 1; i <= n; i++) {
			if (dfs(i, 0).first > (k + 1) / 2)continue;
			ans1 = (k + 1) / 2;
			dfs2(i, 0, 0);
			ll cnt = 1;
			for (int j = 0;; j++) {
				if (ma[j] == 0)break;
				cnt *= ma[j];
			}
			ans2 = cnt;
			for (int j = 0; j < (int)vec[i].size(); j++) {
				fill(ma, ma + n, 0);
				dfs2(i, vec[i][j], 0);
				dfs2(vec[i][j], i, 0);
				ll cnt = 2;
				for (int l = 0;; l++) {
					if (ma[l] == 0)break;
					cnt *= ma[l];
				}
				ans2 = min(ans2, cnt);
			}
		}
		cout << ans1 << " " << ans2 << endl;
		return 0;
	}
	for (int i = 1; i < n; i++) {
		if (dfs(a[i], b[i]).first + dfs(b[i], a[i]).first > k || dfs(a[i], b[i]).first != dfs(b[i], a[i]).first)continue;
		ans1 = k / 2;
		dfs2(a[i], b[i], 0);
		dfs2(b[i], a[i], 0);
		ll cnt = 2;
		for (int j = 0;; j++) {
			if (ma[j] == 0)break;
			cnt *= ma[j];
		}
		ans2 = cnt;
	}
	cout << ans1 << " " << ans2 << endl;
}

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

using namespace std;

int main() {
	int n; cin >> n;
	
	for (int rep = 0; rep < n; rep++) {
		
		vector<int> bar(3); cin >> bar[0] >> bar[1] >> bar[2];
		
		sort(bar.begin(), bar.end());
		if (pow(bar[2], 2) == pow(bar[1], 2) + pow(bar[0], 2)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
cnt = 0


def merge(a, left, mid, right):
    global cnt
    i = left
    j = mid+1
    b = []
    while i <= mid and j <= right:
        if a[i] <= a[j]:
            cnt+=1
            b.append(a[i])
            i += 1
        else:
            cnt+=1
            b.append(a[j])
            j += 1
    if i == mid+1:
        while j <= right:
            cnt+=1
            b.append(a[j])
            j += 1
    else:
        while i <= mid:
            cnt+=1
            b.append(a[i])
            i += 1
    a[left:right+1] = b


def merge_sort(a, left, right):
    if left == right:
        return

    mid = (left+right)//2
    merge_sort(a, left, mid)
    merge_sort(a, mid+1, right)
    merge(a, left, mid, right)

n = int(input())
l = list(map(int,input().split()))
merge_sort(l,0,n-1)
for i in range(n-1):
    print(l[i],end = ' ')
print(l[-1])
print(cnt)


Measured memory_bytes: 61652
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

int main() {
  int w;
  for(;;) {
    cin >> w;
    if(w == -1) break;
    if(w <= 10) cout << 4280 - 1150 << endl;
    if(10 < w && w <= 20) {
      int payment = 1150 + (w - 10) * 125;
      cout << 4280 - payment << endl;
    }
    if(20 < w && w <= 30) {
      int payment = 1150 + 10 * 125 + (w - 20) * 140;
      cout << 4280 - payment << endl;
    }
    if(30 < w) {
      int payment = 1150 + 10 * 125 + 10 * 140 + (w - 30) * 160;
      cout << 4280 - payment << endl;
    }
  }
}




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

int main()
{
  string str;
  cin>>str;
  int len=str.length();
  if(str[0]!='A' || isupper(str[1]) || isupper(str[len-1]) || str[len-1]=='C')
  {
    cout<<"WA"<<endl;
    return 0;
  }
  int c_count=0;
  for(int i=2 ; i<len-1 ; ++i)
  {
    if(str[i]=='C')
      ++c_count;
    if(c_count>1 || (isupper(str[i]) && str[i]!='C'))
    {
      cout<<"WA"<<endl;
      return 0;
    }
  }
  if(c_count==1)
    cout<<"AC"<<endl;
  else
    cout<<"WA"<<endl;

  return 0;
}

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

int main(){
  int X,N;
  cin >> X >> N;
  vector<int> p(N);
  for (int i=0 ; i<N ; i++)
    cin >> p.at(i);
  
  vector<int> x(102);
  for (int i=0 ;i<102 ; i++)
    x.at(i) = i;
  
  for (int i=0 ; i<N ; i++)
    x.erase(remove(x.begin(), x.end(), p.at(i)), x.end());
  
  vector<int> sa(x.size());
  for (int i=0 ; i<x.size() ; i++)
    sa.at(i) = abs(X-x.at(i));
  
  sort(sa.begin(), sa.end());
  
  int a = 0;
  for (int i=0 ; i<x.size() ; i++){
    if (x.at(i)==X-sa.at(0)){
      cout << x.at(i) << endl;
      a = 1;
      break;
    }
  }
  if (a==0)
    cout << X+sa.at(0) << endl;
}

Measured memory_bytes: 3636
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x33ffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 1e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e6 + 3;
ll po(ll a, ll b,ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a,ll b){ if(a==0){return b;}else{ return gcd(b%a,a);}}

ll a,b,c;

void solve()
{
	cin>>a>>b>>c;
	ll res;
	if(a&1)
	{
		res=b*c;
	}
	else
	{
		res=0;
	}
	if(b&1)
	{
		res=min(res,a*c);
	}
	else
	{
		res=0;
	}
	if(c&1)
	{
		res=min(res,a*b);
	}
	else
	{
		res=0;
	}
	cout<<res;
}

int main()
{
    solve();
	return 0;
}

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

using namespace std;

#define endl '\n'

int h,w,k;
vector <string> grid;
bool check(int r,int c){
  int cnt = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(r & (1 << i) || c & (1 << j))
          continue;
        if(grid[i][j] == '#')
          cnt++;
      }
    }
    return cnt == k;
}

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  cin >> h >> w >> k;

  grid.resize(h);

  for(int i=0;i<h;i++)
    cin >> grid[i];
 
  int ans  =0;
  for(int r=0;r<(1<<h);r++){
    for(int c=0;c<(1<<w);c++){
      if(check(r,c))
        ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3680
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");

		int N = Integer.parseInt(tmp[0]);
		int K = Integer.parseInt(tmp[1]);

		double ans = 0;

		for (long  i = 1; i <= N; i++) {
			// iはさいころの目

			if (i >= K) {
				ans += 1.0/N;
			} else {
				int rp = 1;
				long point = i * 2;
				while (K > point) {
					rp++;
					point *= 2;
				}

				ans += 1.0 / (Math.pow(2, rp) * N);
			}
		}

		System.out.println(ans);
	}

}

Measured memory_bytes: 19156
N = int(input())
S = [input() for _ in range(0, N)]
t = {}
for i in range(0, N):
    if S[i] in t:
        t[S[i]] += 1
    else:
        t[S[i]] = 1
vmax = max(t.values())
ans = []
for key in t.keys():
    if t[key] == vmax:
        ans.append(key)
ans.sort()
for i in ans:
    print (i)

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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int sum = 0;
    for (int i = 0; i < n-1; i++){
        if (s[i]!=s[i+1]){
            sum += 1;
        }
    }
    cout << sum+1;


    return 0;
}

Measured memory_bytes: 512
from collections import defaultdict
 
n = int(input())
a = [int(i) for i in input().split()]
 
s = 0
d = defaultdict(int)
ans = 0
d[0] = 1
 
for i in a:
    s += i
    ans += d[s]
    d[s] += 1
 
print(ans)

Measured memory_bytes: 111312
N = int(input())
C = input()

R,W = C.count("R"), C.count("W")

ans = 10**9
l,r = 0,R
for i in range(N+2):
  if 0 < i < N+1: 
    if C[i-1] == "R":
      r -= 1
    else:
      l += 1

  ans = min(ans, max(l,r))

print(ans)


Measured memory_bytes: 68932
import java.io._

object Main extends App {
  val in = new BufferedReader(new InputStreamReader(System.in))

  val Array(n,cp) = in.readLine.split(" ").map(_.toInt)

  val ans = {
    val dp = Array.ofDim[Int](n+1, cp+1)

    Iterator.continually(in.readLine)
    .take(n)
    .map(_.split(" "))
    .foldLeft(0)((i,e) => {
      val v = e(0).toInt
      val w = e(1).toInt
      for(j <- 1 to cp) {
        dp(i+1)(j) =
          if (w <= j && dp(i)(j) < dp(i+1)(j-w) + v) { dp(i+1)(j-w) + v }
          else dp(i)(j)
      }
      i + 1
    })

    dp(n)(cp)
  }

  println(ans)
}


Measured memory_bytes: 48636
#include<cstdio>
int main(){
	long long n,a,b;
	scanf("%ld%ld%ld",&n,&a,&b);
	if(n>1&&b>=a){
		long long maxans=a,minans=b;
		for(int i=1;i<n;i++)
			minans+=a;
		for(int i=2;i<=n;i++)
			maxans+=b;
		printf("%ld",maxans-minans+1);
	}
	else
		if(n==1&&a==b)
			printf("1");
		else
			printf("0");
	return 0;
}

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

int main(){
	string pre, suf;
	int N;
	cin >> N;
	cin >> pre >> suf;

	int answer = N;
	for(int i=0; i<N; i++){
		if(pre.substr(i) == suf.substr(0, N-i)){
			break;
		}else{
			answer++;
		}
	}

	cout << answer << endl;

	return 0;
}
	


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

int main()
{
	string s;
	cin >> s;
	map<char, int> mp = { {'N',0},{'W',0}, {'S',0}, {'E',0} };
	for (int i = 0; i < s.size(); i++) mp[s[i]]++;
	if (mp['N'] == 0 && mp['S'] != 0) {
		cout << "No" << endl;
		return 0;
	}
	if (mp['S'] == 0 && mp['N'] != 0) {
		cout << "No" << endl;
		return 0;
	}
	if (mp['W'] == 0 && mp['E'] != 0) {
		cout << "No" << endl;
		return 0;
	}
	if (mp['E'] == 0 && mp['W'] != 0) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    ll n,k; cin >> n >> k;
    if (n > k){
        cout << min(n%k,k-n%k) << endl;
    }else{
        cout << min(n,abs(n-k)) << endl;
    }
    
}


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

namespace _0075
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string gh = Console.ReadLine();
                if (gh == null) { break; }
                float[] a = gh.Split(',').Select(float.Parse).ToArray();
                if (a[1] / (a[2] * a[2]) >= 25)
                {
                    Console.WriteLine(a[0]);
                }
               // continue;
            }
        }
    }
}

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

using namespace std;

using ll = long long;

const ll MOD = 998244353;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll calc(int cur, const vector< vector<int> >& g, vector<int>& visited) {
    visited[cur] = true;
    ll res = 1;
    for (int nex : g[cur]) {
        if (visited[nex]) continue;
        (res *= calc(nex, g, visited)) %= MOD;
    }
    res = (res + 1) % MOD;
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> x(n), d(n);
    map<ll, int> xtoi;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> d[i];
        xtoi[x[i]] = i;
    }

    vector<int> ids(n);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i1, int i2){
        return x[i1] > x[i2];
    });

    vector< vector<int> > g(n);
    for (int i : ids) {
        if (xtoi.find(x[i]) == xtoi.end()) {
            cerr << i << " " << x[i] << " " << d[i] << endl;
            return 0;
        }
        auto it = next(xtoi.find(x[i]));
        while (it != xtoi.end() && it->first < x[i] + d[i]) {
            g[i].push_back(it->second);
            //cerr << i << " -> " << it->second << ": " << cnt[i] << ", " << cnt[it->second] << "\n";
            it = xtoi.erase(it);
        }
    }
    reverse(ids.begin(), ids.end());

    vector<int> visited(n, false);
    ll ans = 1;
    for (int i : ids) {
        if (visited[i]) continue;
        (ans *= calc(i, g, visited)) %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 34688
import java.util.Scanner;

public class Main {
    static final int NIL = -1;
    static final int MAX = 26;
    static TNode[] nodes = new TNode[MAX];
    static int[] depth = new int[MAX];
    static int[] height = new int[MAX];

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        for(int i = 0; i < n; i++) {
            nodes[i] = new TNode(NIL, NIL, NIL);
        }
        for(int i = 0; i < n; i++) {
            int id = input.nextInt();
            int left = input.nextInt();
            int right = input.nextInt();

            nodes[id].left = left;
            nodes[id].right = right;

            if( left != NIL) {
                nodes[left].parent = id;
            }
            if(right != NIL) {
                nodes[right].parent = id;
            }
        }
        int root = 0;
        for(int i = 0; i < n; i++) {
            if(nodes[i].parent == NIL) root = i;
        }

        System.out.println("Preorder");
        preOrder(root);
        System.out.println();
        System.out.println("Inorder");
        inOrder(root);
        System.out.println();
        System.out.println("Postorder");
        postOrder(root);
        System.out.println();
    }

    public static void preOrder(int id) {
        if(id == NIL) {
            return;
        }
        System.out.print(" " + id);
        preOrder(nodes[id].left);
        preOrder(nodes[id].right);
    }

    public static void inOrder(int id) {
        if(id == NIL) {
            return;
        }
        inOrder(nodes[id].left);
        System.out.print(" " + id);
        inOrder(nodes[id].right);
    }

    public static void postOrder(int id) {
        if(id == NIL) {
            return;
        }
        postOrder(nodes[id].left);
        postOrder(nodes[id].right);
        System.out.print(" " + id);
    }
}

class TNode {
    public int parent, left, right;

    public TNode(int parent, int left, int right) {
        this.parent = parent;
        this.left = left;
        this.right = right;
    }
}


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

using namespace std;

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


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
nums = [0] * (10**5+1)

for num in A:
  if num == 0:
    nums[0] += 1
    nums[1] += 1
  else:
    nums[num-1] += 1
    nums[num] += 1
    nums[num+1] += 1
print(max(nums))

Measured memory_bytes: 14008
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int N;
int a[100010];
int b[100010];
int c[100010];
int dp[3][100010];

int main ()
{
    cin >> N;
    REP(i,N) cin >> a[i] >> b[i] >> c[i];

    for (int i = 0; i < N; i++) {
        dp[0][i + 1] = max(dp[1][i] + a[i], dp[2][i] + a[i]);
        dp[1][i + 1] = max(dp[0][i] + b[i], dp[2][i] + b[i]);
        dp[2][i + 1] = max(dp[0][i] + c[i], dp[1][i] + c[i]);
    }

    int ans = 0;
    REP(i,3) ans = max(ans, dp[i][N]);
    cout << ans << endl;

    REP(i,3) cerr << dp[i][N] << " ";
    cerr << endl;

    return 0;
}


Measured memory_bytes: 2560
using System;

class Print_a_Rectangle
{
  public static void Main()
  {
    while(true)
    {
      string number_str = Console.ReadLine();
      string[] number_tmp = number_str.Split();
      int H = int.Parse(number_tmp[0]);
      int W = int.Parse(number_tmp[1]);
      
      if(H==0&&W==0) break;
      
      
      for(int i=1;i<=H;i++)
      {
        for(int j=1;j<=W;j++)
        {
            Console.Write("#");
        }
        Console.WriteLine();
      }
      
      Console.WriteLine();
     }
    }
}

Measured memory_bytes: 8952
n = int(input())
h = [int(i) for i in input().split()]

dp = [float('inf')] * n

dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 0:
        dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])

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

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> A(N);
    int i;
    int max=1, num=1;
    for(i=0;i<N;i++) cin >> S[i];
    sort(S.begin(), S.end());
    for(i=0;i<N-1;i++){
        if(S[i] == S[i+1]){
            num++;
            if(max <= num) max = num;
        }else{
            num=1;
        }
        A[i] = num;
    }
    A[i] = 1;
    for(i=0;i<N;i++){
        if(A[i] == max){
            cout << S[i] << endl;
        }
    }
    return 0;
}

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

int main()
{
    int h,n;
    int a[100005];
    cin>>h>>n;
    ll sum=0;
    for(int i=0;i<n;i++)
        {cin>>a[i];
        sum+=a[i];}
        if(sum>=h) cout<<"Yes";
        else cout<<"No";
    return 0;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <numeric>
#include <ctime>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <map>

using namespace std;
typedef long long int lint;

int min(int a, int b)
{
	if (a < b) return a;
	else return b;
}

int solve(int n)
{
	int ret = 0;

	int** a = new int*[n + 1];
	for (int i = 0; i <= n; i++){
		a[i] = new int[n + 1];
	}
	for (int i = 0; i <= n; i++){
		for (int j = 0; j <= n; j++){
			a[i][j] = 0;
		}
	}

	string buf;

	for (int i = 0; i < n; i++){
		cin >> buf;
		for (int j = 0; j < n; j++){
			if (buf[j] != '*'){
				int ni = i + 1;
				int nj = j + 1;
				a[ni][nj] = min(a[ni - 1][nj - 1], min(a[ni][nj - 1], a[ni - 1][nj])) + 1;
				if (ret < a[ni][nj]) ret = a[ni][nj];
			}
		}
	}



	for (int i = 0; i <= n; i++){
		delete[] a[i];
	}
	delete[] a;

	return ret;
}

int main()
{
	int n;
	while (1){
		cin >> n;
		if (n == 0) break;
		cout << solve(n) << endl;
	}
	return 0;
}

Measured memory_bytes: 5016
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e6 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll F[N], I[N];
ll mul(ll a, ll b) {
	return (a * b) % Mod;
}
ll sum(ll a, ll b) {
	return (a + b + Mod) % Mod;
}
ll Pow(ll a, ll b) {
	ll res = 1;
	for (; b; b >>= 1, a = mul(a, a))
		if (b & 1)	
			res = mul(res, a);
	return res;
}
ll C(ll r, ll n) {
	if (r < 0 || r > n)	
		return 0;
	return mul(F[n], mul(I[r], I[n - r]));
}
ll inv(ll x) {
	return Pow(x, Mod - 2);
}
int main () {
	ios::sync_with_stdio(0), cin.tie(0);
	F[0] = 1;
	for (int i = 1; i < N; i ++)
		F[i] = mul(i, F[i - 1]);
	I[N - 1] = Pow(F[N - 1], Mod - 2);
	for (int i = N - 2; ~i; i --)
		I[i] = mul(i + 1, I[i + 1]);
	ll ans = 0;
	ll k;
	cin >> k;
	string s;
	cin >> s;
	ll n = s.size();
	for (int i = 0; i <= k; i ++) {
		ll res = 0;
		res = C(n - 1, k + n - i - 1);
		res = mul(res, Pow(25, k - i));
		res = mul(res, Pow(26, i));
		ans = sum(ans, res);
	}
	cout << ans << endl;

}

Measured memory_bytes: 35520
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H=0,N=0,sum=0;
  cin >> H >> N;
  vector<int> vec(N);
  bool flg=false;
  
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  
  for (int i=0;i<N;i++){
    sum+=vec.at(i);
  }
  
  if(H>sum){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	int n; cin >> n;
	int a[200100];
	vector<pii>key;
	int ans = 0;
	int count = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		ans = max(ans, a[i]);
	}
	int second = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] == ans)count++;
		if (a[i] == ans)continue;
		second = max(second, a[i]);
	}
	if (count > 1) {
		for (int i = 0; i < n; ++i) {
			cout << ans << endl;
		}
	}
	else {
		for (int i = 0; i < n; ++i) {
			if (a[i] != ans) {
				cout << ans << endl;
			}
			else {
				cout << second << endl;
			}
		}
	}
	return 0;
}

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

const int N = 15;
const int INF = 1 << 25;
int dist[N][N];
void chmin(int &a, int b) {
    a = std::min(a, b);
}

int main() {
    while(1) {
        int M; scanf("%d", &M);
        if(M == 0) break;

        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if(i != j) dist[i][j] = INF;
            }
        }

        int T = 0;
        for(int i=0; i<M; i++) {
            int a, b, c; scanf("%d%d%d", &a, &b, &c);
            chmin(dist[a][b], c);
            chmin(dist[b][a], c);
            T = std::max({T, a+1, b+1});
        }

        for(int k=0; k<T; k++) {
            for(int i=0; i<T; i++) {
                for(int j=0; j<T; j++) {
                    chmin(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }

        int ans = INF, idx = 0;
        for(int i=0; i<T; i++) {
            int sum = 0;
            for(int k=0; k<T; k++) {
                sum += dist[i][k];
            }
            if(ans > sum) {
                ans = sum;
                idx = i;
            }
        }
        printf("%d %d\n", idx, ans);
    }
    return 0;
}


Measured memory_bytes: 2580
n, c = [int(i) for i in input().split()]
D = [[int(i) for i in input().split()] for j in range(c)]
C = [[int(i) for i in input().split()] for j in range(n)]
 
X = [[0]*c for i in range(3)]
 
for i in range(n):
    for j in range(n):
        X[(i+j+2)%3][C[i][j]-1] += 1
 
cost = [[0]*c for i in range(3)]
 
for i in range(c):
    for j in range(c):
        cost[0][j] += X[0][i] * D[i][j]
        cost[1][j] += X[1][i] * D[i][j]
        cost[2][j] += X[2][i] * D[i][j]
 
ans = []
 
for i in range(c):
    for j in range(c):
        for k in range(c):
            if i != j and j != k and k != i:
                ans.append(cost[0][i] + cost[1][j] + cost[2][k])
 
print(min(ans))

Measured memory_bytes: 6764
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

int main() {
	// 入力
	ll N,K;
	cin >>N>>K;
	ll A[N];
	for (ll i = 0; i < N; ++i) cin >> A[i];
 
	// 解法
	sort(A,A+N,greater<ll>());
	ll keta_A = 0;
	while (pow(2,keta_A)<A[0]){
		if (pow(2,keta_A+1)<A[0]) keta_A++;
		else break;
	}
	ll keta_K = 0;
	while (pow(2,keta_K)<K){
		if (pow(2,keta_K+1)<K) keta_K++;
		else break;
	}
	ll keta = max(keta_A, keta_K);
	// cout << keta_A << endl;
	
	ll X = 0;
	ll ans = 0;
	REP(i,keta+1){
		// REP(j,N) printf("%lld ", A[j]);
		// printf("\n");
		ll judge = pow(2,keta-i);
		ll count = 0;
		REP(j,N){
			if (A[j]/judge==1) count++;
			A[j] = A[j]%judge;
		}
		if ((count<=(N)/2) & (K>=judge)){
			X += judge;
			K -= judge;
			ans += (N-count)*judge;
		}
		else{
			ans += count*judge;
		}
		// printf("judging %lld, count %lld, X %lld ans %lld\n", judge, count,X, ans);
	}
	// printf("X %lld\n", X);
	printf("%lld\n", ans);
	
	
	
}

Measured memory_bytes: 1152
# -*- coding: utf-8 -*-
from itertools import product
def inpl(): return list(map(int, input().split()))

res = 0
S = input()
for P in product(range(2), repeat=len(S)-1):
    r = 0
    t = S[0]
    for p, s in zip(P, S[1:]):
        if p:
            t += s
        else:
            r += int(t)
            t = s
    r += int(t)
    res += r
print(res)

Measured memory_bytes: 3064
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N = int(input())
ans = 0
det = []
if N ==1:
    ans = 0
else:
    for (i, j) in factorization(N):
        max_x = pow(i, j)
        #print(max_x)
        v = i
        temp = 1
        for k in range(j):
            x = pow(v, k+1)
            #print(x)
            if x not in det and temp*x <= max_x:
                temp *= x
                ans += 1
                det.append(x)
    #print("")
print(ans)

Measured memory_bytes: 9512
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define ll long long
#define pb push_back

int main() {
	int n;
	ll a,b;
	vector<ll> x;
	cin>>n;
	ll ans=0;
	for (int i=0;i<n;i++)
	{
		cin>>a>>b;
		x.pb(a+b);
		ans-=b;
	}
	sort(x.begin(),x.end());
	int k=1;
	for (int i=x.size()-1;i>=0;i--)
	{
		if (k%2) ans+=x[i];
		k++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
// #define int long long
typedef long long ll;
#define fi first
#define se second
#define pii pair<ll,int>
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define y1 fdfbvfds
typedef long double f80;
#define all(x) x.begin(), x.end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l,ll r){
    uniform_int_distribution<ll> uid(l, r);
    return uid(rng);
}

const int mod = 998244353;
int pwr(int a,int b) {
    int ans = 1;
    while(b) {
        if(b & 1) {
            ans = (ans * 1LL * a) % mod;
        }
        a = (a * 1LL * a) % mod;
        b >>= 1;
    }
    return ans;
}

const int N = 1005;
vector<pair<int,f80>> g[N];
f80 dist[N];
ll x[N], y[N], r[N];

f80 dd(int i,int j) {
    return sqrtl((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> x[0] >> y[0] >> x[1] >> y[1];
    int n;
    cin >> n;
    fr(i, 2, n + 1) {
        cin >> x[i] >> y[i] >> r[i];
    }
    fr(i, 0, n + 1) {
        fr(j, 0, n + 1) {
            f80 d = dd(i, j);
            if(d <= r[i] + r[j]) {
                g[i].pb({j, 0});
            }
            else {
                g[i].pb({j, d - r[i] - r[j]});
            }
        }
    }
    set<pair<f80,int>> s;
    s.insert({0, 0});
    dist[0] = 0;
    fr(i, 1, n + 1) {
        dist[i] = 1e18;
    }
    while(!s.empty()) {
        auto u = *s.begin();
        s.erase(s.begin());
        if(u.fi > dist[u.se]) continue;
        for(auto v : g[u.se]) {
            if(dist[v.fi] > dist[u.se] + v.se) {
                dist[v.fi] = dist[u.se] + v.se;
                s.insert({dist[v.fi], v.fi});
            }
        }
    }
    cout << setprecision(10) << fixed << dist[1];
    return 0;
}

Measured memory_bytes: 52096
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    vector<vector<int>> s(26);
    vector<vector<int>> t(26);
    string s_, t_;
    cin >> s_ >> t_;
    REP(i, s_.size()){
        s[s_[i]-'a'].pb(i);
        t[t_[i]-'a'].pb(i);
    }

    REP(i, 26){
        if(s[i].empty()) continue;
        bool flag = false;
        REP(j, 26){
            if(t[j].empty()) continue;
            if(s[i]==t[j]){
                flag = true;
                t[j].clear();
            }
        }
        if(flag==false) {
            pr("No");
            return 0;
        }
    }
    pr("Yes");
}

Measured memory_bytes: 3080
package main
import "fmt"
const mod int64 = 1000000007
func main() {
  var n int
  fmt.Scan(&n)
  a := make([]int64,n)
  m := int64(0)
  s := int64(0)
  for i:=0;i<n;i++ {
    fmt.Scan(&a[i])
    s = (s+inv(a[i]))%mod
    if m < a[i] { m = a[i] }
  }
  for p:=int64(2);p*p<=m;p++ {
    x := 0
    for i:=0;i<n;i++ {
      y := 0
      for a[i]%p == 0 { a[i],y = a[i]/p,y+1 }
      if x < y { x = y }
    }
    s = (s*pow(p,x))%mod
  }
  set := make(map[int64]struct{})
  for i:=0;i<n;i++ {
    if a[i] != 1 { set[a[i]] = struct{}{} }
  }
  for k,_ := range set { s = (s*k)%mod }
  fmt.Println(s)
}
func pow(a int64,b int) int64 {
  p := int64(1)
  for b > 0 {
    if b&1 == 1 { p = (p*a)%mod }
    a,b = (a*a)%mod,b>>1
  }
  return p
}
func inv(n int64) int64 {
  var a,b,c,x int64 = (n%mod+mod)%mod,mod,0,1
  for b != 0 { a,b,c,x = b,a%b,x-(a/b)*c,c }
  return (x%mod+mod)%mod
}

Measured memory_bytes: 1664
#include <iostream>
#define MAX_INDX 1000

int 
main (int argc,char *argv[])
{
    int m,n;
    int a[MAX_INDX] = {0};
    int i,j;
    int tmp;
    int sum = 0;

    std::cin >>n >>m;
    
    for (i=0;i<n;i++)
    {
        std::cin >>a[i];
        sum += a[i];
    }

    for (i=0;i<n-1;i++)
    {
        for (j=0;j<n-i;j++)
        {
            if (a[j]<a[j+1])
            {
                tmp = a[j];
                a[j] = a[j+1];
                a[j+1] = tmp;
            }
        }
    }

    if (a[m-1]*(4*m) >= sum)
    {
        std::cout << "Yes";
    }
    else
    {
        std::cout << "No";
    }


}

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

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

    int a[n+1] = {0};

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                int x = (i+j+k)*(i+j+k) - (i*j+i*k+j*k);
                if(x <= n) a[x]++;
                else break;
            }
        }
    }

    for(int i = 1; i <= n; i++) cout << a[i] << '\n';

    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>
#include <array>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cassert>

#include <unordered_set>
#include <unordered_map>
#include <random>
#include <thread>
#include <chrono>

using namespace std;


int main()
{
	int P, Q, R;
	cin >> P;
	cin >> Q;
	cin >> R;
	int sum1 = P + Q;
	int sum2 = Q + R;
	int sum3 = R + P;

	if (sum1 <= sum2 && sum1 <= sum3)
		cout << sum1;
	else if (sum2 <= sum3)
		cout << sum2;
	else
		cout << sum3;
	system("pause");
	return 0;
}



Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl


void solve(std::string S, std::string T){
  cout << T+S << endl;
}

signed main(){
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  solve(S, T);
}


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

int main(){
  char s[100001]={'\0'},left[200001]={'\0'},right[200001]={'\0'},input;
  int i,q,mode=0,flip=0,direct=0,len;
  int l_in=0,r_in=0;
  
  scanf("%s",s);  
  scanf("%d",&q);
  
  for(i=0;i<q;i++){
    scanf("%d",&mode);

    if(mode==1){
      flip=flip^1;
    } else if(mode==2){
      scanf("%d %c",&direct,&input);
      
      if((flip==0 && direct==1)||(flip==1 && direct==2)){
        left[l_in]=input;
        l_in++;
      } else if ((flip==0 && direct==2)||(flip==1 && direct==1)){
        right[r_in]=input;
        r_in++;
      }
    }
  }
  
  if(flip==0){
    for(i=l_in-1;i>=0;i--){
      printf("%c",left[i]);
    }
    printf("%s",s);
    printf("%s",right);
  } else {
    for(i=r_in-1;i>=0;i--){
      printf("%c",right[i]);
    }
    len=strlen(s);
    for(i=len-1;i>=0;i--){
      printf("%c",s[i]);
    }
    printf("%s",left);
  }
}

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

int main(){
  int i,j,n,m,C[1001],D[1001],dp[1001][1001];
  cin >> n >> m;
  for( i = 1; i <= n; i++ ) cin >> D[i];
  for( i = 1; i <= m; i++ ) cin >> C[i];
  
  for( i = 0; i < 1001; i++ ) dp[i][0] = MAX;
  for( i = 0; i < 1001; i++ ) dp[0][i] = 0;
  
  for( i = 1; i <= n; i++ ){
    for( j = 1; j <= m; j++ ){
      dp[i][j] = min( dp[i][j-1],dp[i-1][j-1] + C[j] * D[i] );
    }
  }

  cout << dp[n][m] << endl;
  
  return 0;
}

Measured memory_bytes: 5080
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();

    int n;
    cin >> n;
    vi l(n);
    rep (i, n) cin >> l[i];
    sort(all(l));

    int ans = 0;
    rep (i, n) {
        REP (j, i + 1, n) {
            REP (k, j + 1, n) {
                if (l[i] == l[j] or l[j] == l[k]) continue;
                if (l[i] + l[j] > l[k]) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3660
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
long double x[100], y[100];
pair<long double, pair<long double, long double>> a[200];

signed main(){
	cin >> N;
	rep(i, N){
		cin >> x[i] >> y[i];
		a[i] = mp(atan2(y[i], x[i]), mp(x[i], y[i]));
	}
	sort(a, a+N);
	rep(i, N) a[N+i] = a[i];

	long double ans = 0;
	rep(i, N){
		rep(j, N){
			long double X = 0, Y = 0;
			rep(k, j+1){
				X += a[i+k].second.first;
				Y += a[i+k].second.second;
			}
			ans = max(ans, X*X+Y*Y);
		}
	}
	cout << fixed << setprecision(16) << sqrt(ans) << endl;
}

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

long long gcd(long x, long y)
{    if (y == 0)
        return x;
    return gcd(y, x % y);}
long long lcm(long x, long y){ return x * y / gcd(x, y);}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}


int main()
{
    int x=0,y=0;
    string S,fb="",fw="";
    cin>>S;

    for(int i=0;i<S.length();i++){
        if(i%2==0){
            fb+='0';
            fw+='1';
        }else{
            fb+='1';
            fw+='0';
        }
        if(S[i]!=fb[i])x++;
        if(S[i]!=fw[i])y++;
    }

    cout<<min(x,y)<<endl;

    return 0;
}

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

const int maxn=100+5;

struct Node
{
    int a,b;
    bool flag;
}a[maxn];

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

    int n;cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].a>>a[i].b;
        if(a[i].a==a[i].b) a[i].flag=true;
        else a[i].flag=false;
    }
    bool flag=false;
    for(int i=3;i<=n;i++)
    {
        if(a[i].flag && a[i-1].flag && a[i-2].flag)
        {
            flag=true;
            break;
        }
    }
    if(flag) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3636
import bisect
import collections
import heapq
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N = int(input())
A = lmi()

AI = [(a, i) for i, a in enumerate(A)]

heap = []

for a, i in AI:
    heapq.heappush(heap, (-a, i))  # ???

right = 0
left_ = 0
last = [0]  # index left_index left:0 right:0
for i in range(N):
    new = [0] * (i + 2)
    _a, index = heapq.heappop(heap)
    a = -_a

    # case add left:
    for l in range(i + 1):
        r = N - 1 - (i - l)
        new[l + 1] = max(new[l + 1], last[l] + abs(index - l) * a)
        new[l] = max(new[l], last[l] + abs(r - index) * a)
    last = new

print(max(last))

# Vj
# while heap:
#     _a, i = heapq.heappop(heap)
#     a = - _a
#     # multiple same val order is small to large
#     if i - left_ >= (N - 1 - right) - i:
#         print("L", i, a)
#         ans += (i - left_) * a
#         left_ += 1
#     else:
#         print("R", i, a)
#         ans += ((N - 1 - right) - i) * a
#         right += 1


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

int main() {
  int N,WW=0;
  cin >> N;
  vector<int> L(2*N);
  for(int i=0;i<2*N;i++){
  	cin >> L.at(i);
  }
  sort(L.begin(), L.end());
  for(int i=0;i<2*N;i+=2){
  	WW+=L.at(i);
  }
  cout << WW << endl;
}

Measured memory_bytes: 256
val sees: MutableSet<Int> = mutableSetOf()
val paths: MutableMap<Int, MutableList<Int>> = mutableMapOf()

fun main(args: Array<String>) {
    val line = readLine()!!.trim()
    val (n, m) = line.split(" ").map {it.toInt()}
    val hights: List<Int> = readLine()!!.trim().split(" ").map {it.toInt()}.take(n)

    (0..n).forEach {
        paths.put(it, mutableListOf())
    }

    (0..m-1).forEach {
        val (a, b) = readLine()!!.trim().split(" ").map {it.toInt()}
        paths[a - 1]!!.add(b - 1)
        paths[b - 1]!!.add(a - 1)
    }

    var yoiCount: Int = 0

    for (i in (0..n-1)) {
        // if (sees.contains(i)) {
        //     continue
        // }
        var hightGroup: MutableList<Int> = mutableListOf()

        hightGroup.add(hights[i])
        sees.add(i)
        var node: Int = i

        search(node, hightGroup, hights)

        val maxHeight = hightGroup.max()
        // println("${hightGroup} ${maxHeight}, ${hightGroup.filter {it == maxHeight}.size}")
        if (maxHeight == hights[i] && hightGroup.filter {it == maxHeight}.size == 1) {
            yoiCount += 1
        }
    }


    println("${yoiCount}")
}

fun search(node: Int, hightGroup: MutableList<Int>, hights: List<Int>) {

    var distinations: List<Int> = paths[node]!!

    for (nextNode in distinations) {
        // if (sees.contains(nextNode)) {
        //     continue
        // }

        hightGroup.add(hights[nextNode])
        sees.add(nextNode)

        // search(nextNode, hightGroup, hights)
    }
}

Measured memory_bytes: 89540
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define cont continue  
#define rep(i, n) for(int i = 0 ; i < (n) ; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 2147483646;
const double pi = 3.141592653589793;

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll K;
  cin >> K;

  ll ans = 0;

  ll cur = K;
  ll num = 1;
  ll cnt = 1;
  while(K > 0) {
    K /= 2;
    cnt++;
  }
  cout << (ll)pow(2, cnt - 1) - 1 << endl;
} 


Measured memory_bytes: 256