akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
    long long n,m; 
    scanf("%lld %lld", &n, &m);

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

    for(i=0;i<m;i++){
        n=n-a[i];
    }
    if(n>=0)printf("%lld\n",n);
    else printf("-1\n");
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<signed, null_type, less_equal<signed>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//find_by_order();
//order_of_key();
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x) << ' '; cerr << endl;

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

const double PI = 3.141592653589793238;

int32_t main() {
	FAST_IO;
	
	int k;
	cin >> k;
	string s;
	cin >> s;
	
	if ((int)s.size() <= k) cout << s << endl;
	else cout << s.substr(0, k) << "..." << endl;
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    // ll ll=0;
    // cout << ll;
    ll n;
    cin >> n;
    cout << n*(n-1)/2 << endl;
    return 0;
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t a,b;
  int64_t n;
  cin >> a >> b >> n;
  
  int64_t value = 0;
  int64_t max = 0;

  max = (int64_t)(a*n/(double)b) - a*(int64_t)(n/(double)b);
  
  if((b-1)<n){
    max = (int64_t)(a*(b-1)/(double)b) - a*(int64_t)((b-1)/(double)b);
  }
  cout << max << endl;
  
  return 0;
}

Measured memory_bytes: 3684
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]
import math

n,d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]

ans = 0
for i in range(n):
    for j in range(i+1, n):
        tmp = 0
        for k in range(d):
            tmp += abs(x[j][k] - x[i][k]) ** 2
        tmp = math.sqrt(tmp)
        if (tmp.is_integer()):
            ans+=1
print(ans)




Measured memory_bytes: 9104
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(ll i = z; i < n; i++)
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<char> c(N);
    int R = 0, W = 0, ans = 0;
    rep(i, 0, N){
        cin >> c.at(i);
        if(c.at(i) == 'R') R++;
        if(c.at(i) == 'W') W++;
    }
    rep(i, 0, R){
        if(c.at(i) != 'R') ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
#include <set>
#include<cmath>
#include <stdio.h>
#include <cstdio>
#include<string.h>
#include <string>
#include <iostream>
using namespace std;


int main()
{
    int n,num1=0,num2=0;
    string s1;
    string s2;
    long long int result=3;
    cin>>n;
    cin>>s1;
    cin>>s2;
    if (n<3)
    printf("%d",3*n);
    else
    {
        if (s1[0]!=s2[0])
        result=6;
        for (int i=0;i<n-1;i++)
        {
            if (s1[i]==s2[i])
            num1++;
			if ((s1[i]!=s2[i])&&(s1[i+1]!=s2[i+1])&&(s1[i]!=s1[i+1])&&(s2[i]!=s2[i+1]))
            num2++; 
        }
        if(num1!=0)
        {
        for (int i=1;i<=num1;i++)
        {
            result=result*2%1000000007;
        }
        }
        if(num2!=0)
        {
        for (int i=1;i<=num2;i++)
        {
            result=result*3%1000000007;
        }
        }
        printf("%lld",result);
    }
    return 0;
}



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

const int INF = 1e5;

int main()
{
  double N;
  double T, A;
  std::cin >> N >> T >> A;

  int ans = 1;
  double min_diff = INF;
  for (int i = 1; i <= N; i++) {
    int H;
    std::cin >> H;
    double t = T - H * 0.006;
    if (std::fabs(t - A) < min_diff) {
      ans = i;
      min_diff = std::fabs(t - A);
    }
  }

  std::cout << ans << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
 
int main(void){
  string src, dest;
  cin >> src >> dest;
  src += src;
  bool answer = false;
  for(int i = 0; i < src.length() - dest.length(); i++){
    string sub = src.substr(i, dest.length());
    //cout << sub << endl;
    if(dest == sub) answer = true;
  }
  if(answer) cout << "Yes\n"; else cout << "No\n";
}

Measured memory_bytes: 256
def main():
    N = int(input())
    plan = [[int(a) for a in input().split()] for i in range(N)]
    possible = True

    for i in range(N):
        d = 0
        dt = 0

        if i == 0:
            d = abs(plan[i][1] - 0) + abs(plan[i][2] - 0)
            dt = plan[i][0] - 0
        else:
            d =  abs(plan[i][1] - plan[i-1][1]) + abs(plan[i][2] - plan[i-1][2])
            dt = plan[i][0] - plan[i-1][0]

        if d == dt or ( d < dt and d % 2 == dt % 2 ):
            pass
        else:
            possible = False
            break

    if possible:
        print("Yes")
    else:
        print("No")
if __name__ == "__main__":
    main()

Measured memory_bytes: 21052
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int N, L; cin >> N >> L;
    vector<string> S(N);
    rep(i, 0, N) cin >> S[i];

    sort(S.begin(), S.end());
    rep(i, 0, N) cout << S[i];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

map<ll,ll> S;

ll ryuka(ll N) {
if(N==1) {
return 1;
}
  if(N==0) {
return 2;
  }
  
  if(!S.count(N-1)) {
    S[N-1]=ryuka(N-1);
  }

    if(!S.count(N-2)) {
S[N-2]=ryuka(N-2);
    }
  ll s=S[N-2]+S[N-1];
  return s;
}
 
int main() {
  ll N;
  cin>>N;
  cout<<ryuka(N)<<endl;
}
  


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
string S;
int main() {
    cin >> S;
    int slen = S.length();
    long long ans = 0;
    for(int s = 0; s < (1 << slen-1); ++s) {
        string now = "";
        now += S.at(0);
        for(int i = 0; i < slen-1; ++i) {
            if(s & (1<<i)) now += "+";
            now += S.at(i+1);
        }
        now += "=";

        long long sum = 0;
        int nowlen = now.length();
        int pos = 0;
        for(int j = 0; j < nowlen; ++j) {
            if(now.at(j) == '+') {
                sum += stoll(now.substr(pos, (j-pos)));
                pos = j+1;
            }else if(now.at(j) == '=') {
                sum += stoll(now.substr(pos, (j-pos)));
            }
        }
        ans += sum;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

type deque struct {
	front, back []byte
}

func (deq *deque) isEmptyFront() bool {
	return len(deq.front) == 0
}
func (deq *deque) isEmptyBack() bool {
	return len(deq.back) == 0
}

func (deq *deque) pushBack(v byte) {
	deq.back = append(deq.back, v)
}
func (deq *deque) pushFront(v byte) {
	deq.front = append(deq.front, v)
}
func (deq *deque) popBack(v *byte) bool {
	r := true
	if !deq.isEmptyBack() {
		*v = deq.back[len(deq.back)-1]
		deq.back = deq.back[:len(deq.back)-1]
	} else if !deq.isEmptyFront() {
		*v = deq.front[0]
		deq.front = deq.front[1:]
	} else {
		r = false
	}
	return r
}
func (deq *deque) popFront(v *byte) bool {
	r := true
	if !deq.isEmptyFront() {
		*v = deq.front[len(deq.front)-1]
		deq.front = deq.front[:len(deq.front)-1]
	} else if !deq.isEmptyBack() {
		*v = deq.back[0]
		deq.back = deq.back[1:]
	} else {
		r = false
	}
	return r
}

func (deq *deque) get(idx int) byte {
	tot := len(deq.front) + len(deq.back)
	var v byte
	if idx < tot {
		if idx < len(deq.front) {
			v = deq.front[len(deq.front)-1-idx]
		} else {
			v = deq.back[idx-len(deq.front)]
		}
	}
	return v
}

type op struct {
	rev, front bool
	c          byte
}

func rev(s string) string {
	r := make([]byte, len(s))
	i, j := len(s)-1, 0
	for i >= 0 {
		r[j] = s[i]
		j++
		i--
	}
	return string(r)
}

func main() {
	var S string
	fmt.Scan(&S)
	var Q int
	fmt.Scan(&Q)
	ops := make([]op, Q)
	for i := 0; i < Q; i++ {
		var q int
		fmt.Scan(&q)
		if q == 1 {
			ops[i].rev = true
		} else {
			var f int
			fmt.Scanf("%d %c", &f, &ops[i].c)
			if f == 1 {
				ops[i].front = true
			}
		}
	}
	sum := make([]int, Q+1)
	for i := Q - 1; i >= 1; i-- {
		if ops[i].rev {
			sum[i-1] = sum[i] + 1
		} else {
			sum[i-1] = sum[i]
		}
	}
	// fmt.Println("S", S, "Q", Q, "ops", ops, "sum", sum)
	if sum[0]%2 == 1 {
		S = rev(S)
	}
	var deq deque
	for i := 0; i < Q; i++ {
		if !ops[i].rev { // 反転ではない(文字列追加)
			if ops[i].front {
				if sum[i]%2 == 1 {
					deq.pushBack(ops[i].c)
				} else {
					deq.pushFront(ops[i].c)
				}
			} else {
				if sum[i]%2 == 1 {
					deq.pushFront(ops[i].c)
				} else {
					deq.pushBack(ops[i].c)
				}
			}
		}
	}
	wtr := bufio.NewWriter(os.Stdout)
	// fmt.Printf("%q %q %q\n", string(deq.front), S, string(deq.back))
	for i := len(deq.front) - 1; i >= 0; i-- {
		fmt.Fprint(wtr, string(deq.front[i]))
	}
	for i := 0; i < len(S); i++ {
		fmt.Fprint(wtr, string(S[i]))
	}
	for i := 0; i < len(deq.back); i++ {
		fmt.Fprint(wtr, string(deq.back[i]))
	}
	fmt.Fprintln(wtr)
	wtr.Flush()
}


Measured memory_bytes: 7424
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define REP(i,a,n) for(int i = (a); i < (n); i++)
#define ALL(v) v.begin(), v.end()
struct edge {
	int to;
	ll weight;
	edge(int to, ll weight = 1) :to(to), weight(weight) {}
};
vector<vector<edge>> G;
vector<vector<edge>> rG;
vector<int> vs;
vector<bool> used;
vector<int> cmp;
void add_edge(int from, int to) {
	G[from].emplace_back(to);
	rG[to].emplace_back(from);
}
void dfs(int v) {
	used[v] = true;
	for (edge e : G[v]) {
		if (!used[e.to]) dfs(e.to);
	}
	vs.push_back(v);
}
void rdfs(int v, int k) {
	used[v] = true;
	cmp[v] = k;
	for (edge e : rG[v]) {
		if (!used[e.to]) rdfs(e.to, k);
	}
}
int scc() {
	used.resize(G.size());
	cmp.resize(G.size());
	fill(ALL(used), false);
	vs.clear();
	rep(v, G.size()) {
		if (!used[v]) dfs(v);
	}
	fill(ALL(used), false);
	int k = 0;
	for (int i = vs.size() - 1; i >= 0; i--) {
		if (!used[vs[i]]) rdfs(vs[i], k++);
	}
	return k;
}
int main() {
	int V, E;
	cin >> V >> E;
	G.resize(V);
	rG.resize(V);
	rep(i, E) {
		int s, t;
		cin >> s >> t;
		add_edge(s, t);
	}
	int k = scc();
	int Q;
	cin >> Q;
	rep(i, Q) {
		int u, v;
		cin >> u >> v;
		if (cmp[u] == cmp[v]) cout << 1 << endl;
		else cout << 0 << endl;
	}
}


Measured memory_bytes: 5052
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, d, cnt = 0;
  cin >> n >> k;
  int a[101] = {0}, ans[101] = {0};
  for (int i = 0; i < k; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) cin >> a[j];
    for (int j = 0; j < d; j++) {
      ans[a[j]-1]++;
    }
  }
  for (int i = 0; i < n; i++) {
   if (ans[i] > 0) cnt++;
  }
  cout << n - cnt;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,n) cin>>a[i];


    while(k--){
        vector<int> imos(n+1,0);
        rep(i,n){
            int l=max(0,i-a[i]);
            int r=min(n,i+a[i]+1);
            //cout<<l<<" "<<r<<endl;;
            imos[l]++;
            imos[r]--;
        }
        for(int i=1;i<n;i++) imos[i]+=imos[i-1];
        //rep(i,n) cout<<a[i]<<" ";
        //cout<<endl;
        imos.pop_back();
        if(a==imos) break;
        a=imos;
        //rep(i,n) cout<<a[i]<<" ";
        //cout<<endl;
    }

    rep(i,n) cout<<a[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 4740
#include<bits/stdc++.h>
#define ll long long 
#define P pair<int,int>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
const ll INF = 100100100100;
/*
dp[i][v]
i番目までの品物で
価値の総和がv以上となるような
選び方の重さの最小値
i:1~N, v:0~10000
*/
int main(){
    ll N,W;
    cin >> N >> W;
    vector<ll> w(N+1),v(N+1);  //w = weight, v = value
    rep(i,N) cin >> w[i+1] >> v[i+1];
    ll vl = 100100;
    vector<vector<ll>> dp(N+1,vector<ll>(vl+10,INF));
    dp[0][0] = 0;
    for(ll i=1;i<=N;i++){  //i番目の品物
        for(ll j=0;j<=vl;j++){  //価値の総和をjまで
            dp[i][j] = dp[i-1][j];  //i番目の品物を使わない
            if(j-v[i]>=0)
                dp[i][j] = min(dp[i][j],   
                    dp[i-1][j-v[i]]+w[i] );  //使う
        }
    }

    ll ans = 100000;
    while(dp[N][ans]>W) ans--;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
  int N;
  char ch;

  while(cin >> N, N){
    bool found[26];
    map<char,map<string,int> > data;
    string str,word;
    set<string> st;

    cin.ignore();
    memset(found, false, sizeof(found));
    for(int i = 0 ; i < N ; i++){
      getline(cin,str);
      stringstream s(str);
      while(s >> word){
        if(st.find(word) == st.end()){
          st.insert(word);
          data[word[0]][word] = 1;
          found[word[0]-'a'] = true;
        }else{
          ++data[word[0]][word];
        }
      }
    }
    cin >> ch;
    if(!found[ch-'a']){
      cout << "NA" << endl;
    }else{
      bool space = false;
      map<string,int> m = data[ch];
      map<string,int>::iterator it;
      vector<pair<int,string> > vec;
      for(it = m.begin() ; it != m.end() ; ++it){
        vec.push_back(pair<int,string>(-it->second,it->first));
      }
      sort(vec.begin(),vec.end());
      for(int i = 0 ; i < vec.size(); i++){
        if(i == 5) break;
        if(space) cout << " ";
        cout << vec[i].second;
        space = true;
      }
      cout << endl;
    }    
  }

  return 0;
}

Measured memory_bytes: 1252
from fractions import gcd
from bisect import bisect_left
 
N, M = map(int, input().split())
S = input()
T = input()
 
if N > M:
    N, M = M, N
    S, T = T, S

G = N*M // gcd(N, M)
 
a = G//N
b = G//M
 
X = [a*i for i in range(N)]
Y = [b*j for j in range(M)]
 
for i, x in enumerate(X):
    j = bisect_left(Y, x)
    if j < M and Y[j] == x:
        if S[i] != T[j]:
            print(-1)
            break
else:
    print(G)

Measured memory_bytes: 12124
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c, d, e, f;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	if (a > b) {
		e = b * c;
		f = (a - b) * d;
		cout << e + f << endl;
	}
	else{
		cout << a*c << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int main(){
	
	string s;
	int cnt=0;
	while(cin>>s){
		int a = 0;
		
		bool ok = true;
		rep(i,s.size())if(s[i]!=s[s.size()-i-1])ok=false;
		
		if(ok)cnt++;
	}
	printf("%d\n",cnt);
	
	
}

Measured memory_bytes: 1176
#include <stdio.h>
int main(void){
    int n;
    int i;
    int n5=0;
    int n7=0;

    for(i=0;i<3;i++){
        scanf("%d",&n);
        if(n==5){
            n5++;
        }
        if(n==7){
            n7++;
        }
    }

    if(n5==2&&n7==1){
        printf("YES\n");
    }else{
        printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int a, b, x;
    cin >> a >> b >> x;
    
    cout << fixed << setprecision(8);
    double ans = 0;
    if (2 * x == a * a * b) {
        ans = atan(a / b);
    } else if (x >= 1.0 * a * a * b / 2) {
        ans = atan(2.0 / a / a / a * (a * a * b - x));
    } else {
        ans = atan(2.0 * x / a / b / b);
        ans -= M_PI / 2;
        ans = -ans;
    }
    ans = ans / 2 / M_PI;
    ans *= 360;
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

ll dp[100010][13];

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

	string S;
	cin >> S;

	dp[0][0] = 1;
	for (int i = 0; i < (int)S.size(); i++) {
		int c;
		if (S[i] == '?') c = -1; else c = S[i] - '0';
		for (int number_pos = 0; number_pos <= 9; number_pos++) {
			if (c != -1 && c != number_pos) continue;
			for (int mod_prev = 0; mod_prev < 13; mod_prev++) {
				int mod_pos = (mod_prev * 10 + number_pos) % 13;
				dp[i+1][mod_pos] += dp[i][mod_prev];
				dp[i+1][mod_pos] %= MOD;
			}
		}
	}

	cout << dp[(int)S.size()][5] << endl;
    return 0;
}


Measured memory_bytes: 10704
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll K;
  cin >> K;
  ll a = K / 50;
  ll b = K % 50;
  cout << 50 << endl;

  REP(i, 50) {
    if (i < b)
      cout << 49 + a - b + 51 << " ";
    else
      cout << 49 + a - b << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(Scanner())
	tree := make([][]int, n)
	for i := 0; i < n-1; i++ {
		a, _ := strconv.Atoi(Scanner())
		b, _ := strconv.Atoi(Scanner())
		a--
		b--
		tree[a] = append(tree[a], b)
		tree[b] = append(tree[b], a)
	}
	fq := []int{0}
	fd := make([]int, n)
	for i := 1; i < n; i++ {
		fd[i] = -1
	}
	for {
		v := fq[0]
		fq = fq[1:]
		for _, j := range tree[v] {
			if fd[j] == -1 {
				fq = append(fq, j)
				fd[j] = fd[v] + 1
			}
		}
		if len(fq) == 0 {
			break
		}
	}
	sq := []int{n - 1}
	sd := make([]int, n)
	for i := 0; i < n-1; i++ {
		sd[i] = -1
	}
	for {
		v := sq[0]
		sq = sq[1:]
		for _, j := range tree[v] {
			if sd[j] == -1 {
				sq = append(sq, j)
				sd[j] = sd[v] + 1
			}
		}
		if len(sq) == 0 {
			break
		}
	}
	path := []int{0}
	tmp := 0
	for {
		if tmp == n-1 {
			break
		} else {
			for _, i := range tree[tmp] {
				if sd[i] == sd[tmp]-1 {
					path = append(path, i)
					tmp = i
					break
				}
			}
		}
	}
	fok := make(map[int]struct{})
	sok := make(map[int]struct{})
	for i := 0; i < len(path); i++ {
		if _, ok := sok[path[i]]; !ok {
			fok[path[i]] = struct{}{}
		}
		if _, ok := fok[path[len(path)-1-i]]; !ok {
			sok[path[len(path)-1-i]] = struct{}{}
		}
	}
	fq = []int{0}
	fd[0] = 1
	for i := 1; i < n; i++ {
		fd[i] = -1
	}
	fc := 1
	for {
		v := fq[0]
		fq = fq[1:]
		for _, j := range tree[v] {
			if _, ok := sok[j]; fd[j] == -1 && !ok {
				fq = append(fq, j)
				fd[j] = 1
				fc++
			}
		}
		if len(fq) == 0 {
			break
		}
	}
	sq = []int{n - 1}
	sd[n-1] = 1
	for i := 0; i < n-1; i++ {
		sd[i] = -1
	}
	sc := 1
	for {
		v := sq[0]
		sq = sq[1:]
		for _, j := range tree[v] {
			if _, ok := fok[j]; sd[j] == -1 && !ok {
				sq = append(sq, j)
				sd[j] = 1
				sc++
			}
		}
		if len(sq) == 0 {
			break
		}
	}
	if fc > sc {
		fmt.Println("Fennec")
	} else {
		fmt.Println("Snuke")
	}
}


Measured memory_bytes: 14464
s = int(input())


a = [s]
for n in range(2, 1000001):
    if a[-1] % 2 == 0:
        a.append(int(a[-1]/2))
    else:
        a.append(3*a[-1]+1)

    try:
        a.index(a[-1], 0, -1)
        print(n)
        break
    except ValueError:
        continue


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	static int p[][];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();

		if(n == 0) {
			System.out.println(s);
			return;
		}

		String ans = "";
		for(int i = 0; i < s.length(); i++) {
			char c = (char) (s.charAt(i) + n);
			while(c > 'Z') {
				c -= 'Z' - 'A' + 1;
			}
			ans += c;
		}

		System.out.println(ans);

        return;
    }
}



Measured memory_bytes: 148092
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def count_choices(n, nums):
    if n & 1 == 1:
        return 0

    nums.sort()

    mid = n // 2

    if nums[mid] == nums[mid - 1]:
        return 0

    return nums[mid] - nums[mid - 1]


def main():
    n = int(input())
    nums = list(map(int, input().split()))

    ans = count_choices(n, nums)
    print(ans)


main()


Measured memory_bytes: 14396
#include<iostream>
#include<vector>

int main(void)
{
        unsigned M,N;
        std::vector<unsigned> remains,remains_new;

        std::cin >> N >> M;

        for(unsigned m = 1;m <= M;m++){
                remains.push_back(m);
        }
        for(unsigned n = 0;n < N;n++){
                unsigned K;
                std::cin >> K;
                remains_new.clear();
                for(unsigned k = 0;k < K;k++){
                        unsigned A;
                        std::cin >> A;
                        for(auto itr = remains.begin();itr != remains.end();itr++){
                                if(*itr == A){
                                        remains_new.push_back(A);
                                        break;
                                }
                        }
                }
                remains = remains_new;
        }
        std::cout << remains.size() << std::endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,m,k,i,j,c,d,mx,s,x,y,a[200001],b[200001],a1[200001],b1[200001];
int main() {
    cin >> n >> m >> k;
    for (i=1; i<=n; i++)
        cin >> a[i];
    for (i=1; i<=m; i++)
        cin >> b[i];

    for (i=1; i<=n; i++)
    {
        s+=a[i];
        a1[i]=s;
    }
    s=0;
    for (i=1; i<=m; i++)
    {
        s+=b[i];
        b1[i]=s;
    }

a1[0]=0; b1[0]=0;
    for (i=0; i<=n; i++)
    {
        if (k>=a1[i])
        x=k-a1[i];
        else
        break;
        d=1;
        c=m;

        while ( d<=m && c>=0 && c>d)
        {

            j=(c+d)/2;
            if (b1[j]==x){c=j;break;}
            if (b1[j]>x)
            c=j-1;
            else
            d=j+1;

        }
        if (b1[c]>x)j=c-1;else j=c;

        if (b1[1]>x)
            j=0;
        if (i+j>mx)
            mx=i+j;

    }
    cout<<mx;


}


Measured memory_bytes: 9892
#include <iostream>
#include <cstdio>
#include <cstdlib> 
#include <cstring> 
#include <cmath> 
#include <algorithm>
#include <vector> 
using namespace std; 
inline int gi() { 
    register int data = 0, w = 1;
    register char ch = 0;
    while (!isdigit(ch) && ch != '-') ch = getchar(); 
    if (ch == '-') w = -1, ch = getchar(); 
    while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); 
    return w * data; 
} 
const int MAX_N = 2e5 + 5; 
int N, M, a[MAX_N], nxt[41][MAX_N];
long long K; 
int fir[MAX_N], lst[MAX_N]; 
int stk[MAX_N], top; 
bool exist[MAX_N]; 
int main () { 
	N = gi(); cin >> K; 
	for (int i = 1; i <= N; i++) a[i] = gi(); 
	for (int i = 1; i <= N; i++) if (!fir[a[i]]) fir[a[i]] = i; 
	nxt[0][N + 1] = 1; 
	for (int i = N; i; i--) { 
		if (!lst[a[i]]) nxt[0][i] = fir[a[i]] + 1; 
		else nxt[0][i] = nxt[0][lst[a[i]] + 1]; 
		lst[a[i]] = i; 
	} 
	for (int i = 1; i <= 40; i++) 
	    for (int j = 1; j <= N + 1; j++) nxt[i][j] = nxt[i - 1][nxt[i - 1][j]]; 
	int st = 1;
	K--; 
	for (int i = 40; ~i; i--) 
		if ((K >> (1ll * i)) & 1ll) st = nxt[i][st]; 
	for (int i = st; i <= N; i++) { 
		if (!exist[a[i]]) stk[++top] = a[i], exist[a[i]] = 1; 
		else while (top && exist[a[i]]) exist[stk[top]] = 0, --top; 
	} 
	for (int i = 1; i <= top; i++) printf("%d ", stk[i]); 
    return 0; 
} 

Measured memory_bytes: 36864
#include "iostream"
#include "algorithm"
#include "string"
#include "set"
#include "vector"

using namespace std;

const long long int MOD = 1000000007;

int N, M, K, H, W;

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

	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		cin >> H >> W;
		if (N == 1) {
			cout << min(H, W) << endl;
			continue;
		}
		if (H < W) {
			swap(H, W);
		}
		while (H != W) {
			H = (H - 2) / N + 1;
			if (H < W) {
				swap(H, W);
			}
		}
		cout << H << endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main(){
  
  fastIO
  int n;
  cin>>n;
  int a=n%10;
  string str;
  if(a==3)
    str="bon";
  else if(a==0||a==1||a==6||a==8)
    str="pon";
  else
    str="hon";
  
  cout<<str<<endl;  
  
return 0;
}


Measured memory_bytes: 3640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

typedef struct{
  short x,y;
  int cost;
  short ch;
}mouse;

short maxch[1000][1000];
char ku[1000][1000];

main(){
  int h,w,n;
  cin>>h>>w>>n;
  
  rep(i,h)scanf(" %s ",ku[i]);

  int sx,sy;
  rep(i,h)rep(j,w){
    if(ku[i][j]=='S')sx=i,sy=j;
    maxch[i][j]=-1;
  }

  queue<mouse> Q;

  Q.push((mouse){sx,sy,0,0});
  maxch[sx][sy]=0;


  int ans=0;
  while(!Q.empty()){
    //    cout<<Q.size()<<endl;
    mouse t=Q.front();Q.pop();
    int cx=t.x,cy=t.y,cost=t.cost;
    int ch=t.ch;
    if(ch==n){
      ans=cost;
      break;
    }



    rep(i,4){
      int nx=cx+dx[i],ny=cy+dy[i];
      if(nx<0 || nx>=h || ny<0 || ny>=w)continue;
	 if(ku[nx][ny]=='X')continue;
	 int nch=ch;
	 if(ku[nx][ny]<='9' && ku[nx][ny]>='1'){
	   int num=ku[nx][ny]-'0';
	   if(num==t.ch+1){
	     nch=ch+1;
	   }
	 }
	 if(maxch[nx][ny]>=nch)continue;
	 maxch[nx][ny]=nch;

	 Q.push((mouse){nx,ny,cost+1,nch});
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    REP(i, n) cin >> a.at(i);
    REP(i, n) a.at(i) = 1 / a.at(i);
    double sum_a = 0;
    REP(i, n) sum_a += a.at(i);
    double ans;
    ans = 1 / sum_a;
    cout << ans << endl;
}
    

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

int main(){
    int H,W;
    vector<vector<char>> A;
    cin >> H >> W;
    A.resize(H);
    for(int i=0;i<H;i++){
        A[i].resize(W);
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> A[i][j]; 
        }
    }
    for(int i=0;i<A.size();i++){
        if(A[i][0]!='#'){
            for(int j=0;j<A[i].size();j++){
                if(A[i][j]=='#'){
                    break;
                }
                if(j==A[i].size()-1){
                    for(int k=0;k<A[i].size();k++){
                        A[i][k]='B';
                    }
                }
            }
        }
    }
    for(int j=0;j<A[0].size();j++){
        if(A[0][j]!='#'){
            for(int i=0;i<A.size();i++){
                if(A[i][j]=='#'){
                    break;
                }
                if(i==A.size()-1){
                    for(int k=0;k<A.size();k++){
                        A[k][j]='B';
                    }
                }
            }
        }
    }
    for(int i=0;i<A.size();i++){
        for(int j=0;j<A[i].size();j++){
            if(A[i][j]!='B'){
                cout << A[i][j];
            }
        }
        cout <<"\n";
    }
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

#define R 0
#define L 1

lli data[500100];
bool vis[500100];

signed main(){

	string s;
	cin>>s;

	lli size = s.size();
	lli sum=0;
	lli dir = R;
	lli right = 0;
	lli left  = 0;
	/*
	if(s.at(size-1) == '<')s.push_back('>');
	else {
		s.push_back('<');
	}
	*/
	REP(i,0,s.size()){
		if(dir==R){
			if(s.at(i) == '<')
			{
				right++;
			}
			else{
				dir = L;
				left++;
			}
		}
		else{
			if(s.at(i) == '>'){
				left++;
			}
			else{
				dir = R;
				sum += (left+1)*(left)/2;
				sum += (right+1)*(right)/2;

				sum -= min(left,right);
				right=1;
				left =0;
			}
		}
	}
	if(dir==L){
		sum += (left+1)*(left)/2;
		sum += (right+1)*(right)/2;
		sum -= min(left,right);
	}
	else{
		sum += (right+1)*(right)/2;
	}

	cout<<sum<<endl;


	return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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; }
typedef long long ll;
int main()
{
  ll k,q; cin >> k >> q;
  vector<ll> d(k);
  rep(i,k) cin >> d[i];
  vector<ll> n(q),x(q),m(q);
  rep(i,q) {
    cin >> n[i] >> x[i] >> m[i];
  }

  rep(i,q) {
    vector<ll> cnt(k+1);
    vector<ll> sum(k+1);
    sum[0] = 0;
    cnt[0] = 0;
    rep(j,k) {
      sum[j+1] += sum[j] + d[j] % m[i];
      cnt[j+1] += cnt[j] + (d[j] % m[i] == 0 ? 1 : 0);
    }
    ll su = sum[k] * ((n[i] - 1) / k) + sum[(n[i] - 1) % k];
    ll cn = cnt[k] * ((n[i] - 1) / k) + cnt[(n[i] - 1) % k];
    ll res = n[i] - 1 - (x[i] + su) / m[i] + x[i] / m[i] - cn;
    cout << res << "\n";
  }
  
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#define fi first
#define se second
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int main() {
	double w;
	while(true){
		cin>>w;
		if (cin.eof())break;
		if(w<=48.00){
			cout<<"light"<<" "<<"fly"<<endl;
		}
		if(48.00<w&&w<=51.00){
			cout<<"fly"<<endl;
		}
		if(51.00<w&&w<=54.00){
			cout<<"bantam"<<endl;
		}
		if(54.00<w&&w<=57.00){
			cout<<"feather"<<endl;
		}
		if(57.00<w&&w<=60.00){
			cout<<"light"<<endl;
		}
		if(60.00<w&&w<=64.00){
			cout<<"light"<<" "<<"welter"<<endl;
		}
		if(64.00<w&&w<=69.00){
			cout<<"welter"<<endl;
		}
		if(69.00<w&&w<=75.00){
			cout<<"light"<<" "<<"middle"<<endl;
		}
		if(75.00<w&&w<=81.00){
			cout<<"middle"<<endl;
		}
		if(81.00<w&&w<=91.00){
			cout<<"light"<<" "<<"heavy"<<endl;
		}
		if(91.00<w){
			cout<<"heavy"<<endl;
		}
	}
}

Measured memory_bytes: 3128
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#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 rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    
    ll ans1=100*a,ans2=0;
    double dist=0;
    double rec=0;
    rep(i,31)rep(k,31)rep(l,301)rep(m,301){
        double w=100*(a*i+b*k);
        double s=c*l+d*m;
        if(w==0)continue;
        if(w+s>f) continue;
        else{
            if(s*100<=e*w){
              chmax(dist,s/(w+s));
              if(dist==rec){}else{ans1=s+w;ans2=s;}
              chmax(rec,s/(s+w));
            }
        }
    }

    cout<<ans1<<" "<<ans2<<endl;
}

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

struct UnionFind {
    vector<int> par;
    UnionFind(int N):par(N) {
        for (int i=0; i<N; i++) par[i]=i;
    }
    int root (int x) {
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y) {
        int rx=root(x);
        int ry=root(y);
        if (rx==ry) return;
        par[rx]=ry;
    }
    bool same (int x,int y) {
        int rx=root(x);
        int ry=root(y);
        return rx==ry;
    }
};

int main() {
   int V,E;
   cin >> V >> E;
   priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>> G;
   for (int i=0; i<E; i++) {
       int s,t,w;
       cin >> s >> t >> w;
       G.push(make_tuple(w,s,t));
   }
   UnionFind tree(V);
   int count=0;
   for (int i=0; i<E; i++) {
       tuple<int,int,int> a=G.top();
       G.pop();
       if (tree.same(get<1>(a),get<2>(a))) continue;
       tree.unite(get<1>(a),get<2>(a));
       count+=get<0>(a);
   }
   cout << count << endl;
}


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

int a[100010], b[100010];

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++){
		scanf("%d", &b[i]);
	}
	long long sum = 0;
	int ans = 0;
	vector <int> all;
	for (int i = 0; i < n; i++){
		if (a[i] >= b[i]) all.push_back(a[i] - b[i]);
		else sum += b[i] - a[i], ans++;
	}
	sort(all.begin(), all.end()), reverse(all.begin(), all.end());
	int now = 0;
	while (now < all.size() && sum > 0) sum -= all[now], now++;
	if (now == all.size() && sum > 0) printf("-1\n");
	else printf("%d\n", ans + now);
	return 0;
}


Measured memory_bytes: 1660
def abc053c(cards):
    counts = {}
    for card in cards:
        if card not in counts:
            counts[card] = 0
        counts[card] = counts[card] + 1
    # safety remove
    for card in counts:
        if counts[card] > 2:
            counts[card] = 2 - (counts[card] % 2)

    len_counts = len(counts.keys())
    dup_cards = len(list(card for card in counts if counts[card] > 1))
    return len_counts - (dup_cards % 2)


if __name__ == '__main__':
    _ = input()
    a = map(int, input().split(" "))
    print(abc053c(a))

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

using pii = pair<int, int>;

int N;

vector<vector<pii>> make_initial() {
    vector<vector<pii>> res(N, vector<pii>(N));
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            res[i][j] = make_pair(i, j);
        }
    }
    return res;
}

vector<vector<pii>> eval(vector<vector<pii>> const& A, vector<vector<pii>> const& x) {
    auto res = A;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            res[i][j] = A[x[i][j].first][x[i][j].second];
        }
    }
    return res;
}

vector<vector<pii>> sequence(string const& s, int& p);
vector<vector<pii>> repetition(string const& s, int& p);
vector<vector<pii>> operation(string const& s, int& p);
int number(string const& s, int& p);

vector<vector<pii>> sequence(string const& s, int& p) {
    auto res = make_initial();
    while(p < s.size() && (s[p] == '(' || isalpha(s[p]))) {
        vector<vector<pii>> f;
        if(s[p] == '(') {
            f = repetition(s, p);
        } else if(isalpha(s[p])) {
            f = operation(s, p);
        } else {
            cout << "error pos: " << p << endl;
            assert(false); // error
        }
        res = eval(res, f);
    }
    return res;
}

vector<vector<pii>> repetition(string const& s, int& p) {
    auto x = sequence(s, ++p);
    ++p;
    assert(isdigit(s[p]));
    int n = number(s, p);
    auto res = make_initial();
    while(n > 0) {
        if(n & 1) {
            res = eval(res, x);
        }
        x = eval(x, x);
        n >>= 1;
    }
    return res;
}

vector<vector<pii>> operation(string const& s, int& p) {
    auto res = make_initial();
    char op = s[p++];
    int i = number(s, p) - 1;
    if(op == 'L') {
        for(int j = 0; j < N; ++j) {
            res[i][j].second = (j + 1) % N;
        }
    } else if(op == 'R') {
        for(int j = 0; j < N; ++j) {
            res[i][j].second = (j - 1 + N) % N;
        }
    } else if(op == 'U') {
        for(int j = 0; j < N; ++j) {
            res[j][i].first = (j + 1) % N;
        }
    } else if(op == 'D') {
        for(int j = 0; j < N; ++j) {
            res[j][i].first = (j - 1 + N) % N;
        }
    } else {
        assert(false);
    }
    return res;
}

int number(string const& s, int& p) {
    int res = 0;
    while(isdigit(s[p])) {
        res *= 10;
        res += (s[p++] - '0');
    }
    return res;
}

int main() {
    int L;
    string S;
    cin >> N >> L >> S;
    int p = 0;
    auto ans = sequence(S, p);
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            cout << (ans[i][j].first * N + ans[i][j].second + 1) << " \n"[j + 1 == N];
        }
    }
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

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

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

void dfs(int pos, int sum);

vector< int > tree[SIZE];
int c[SIZE];
bool visit[SIZE];

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

    int n, q;
    cin >> n >> q;
    for( int i = 0; i < n - 1; ++i ) {
        int a, b;
        cin >> a >> b;
        tree[a].pb(b);
        tree[b].pb(a);

    }

    while( q-- ) {
        int p, x;
        cin >> p >> x;
        c[p] += x;

    }
    dfs(1, 0);
    for( int i = 1; i <= n; ++i ) {
        cout << c[i] << " ";

    }
    cout << endl;

    return 0;
}

void dfs(int pos, int sum) {
    if( visit[pos] ) return;
    c[pos] += sum;
    visit[pos] = true;

    for( int i = 0; i < tree[pos].size(); ++i ) {
        dfs(tree[pos][i], c[pos]);

    }

    return;
}


Measured memory_bytes: 24192
def mod_pow(a, n, mod):
    """
    二分累乗法による a^n (mod m)の実装
    :param a: 累乗の底
    :param n: 累乗の指数
    :param mod: 法
    :return: a^n (mod m)
    """

    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


class ModCombination:
    """
    nCk (mod m)を扱うクラス
    """

    def __init__(self, mod, n_max):
        """
        イニシャライザ
        予め 1~nの階乗と階乗の逆元を計算しておく
        :param mod: 法
        :param n_max: nの最大値(100,000で約1秒)
        """
        self.mod = mod
        self.n_max = n_max
        self.facts = [1, 1]
        self.inverses = [None, 1]
        self.fact_inverses = [1, 1]

        for i in range(2, self.n_max + 1):
            self.facts.append(self.facts[i - 1] * i % self.mod)
            self.inverses.append(
                self.mod - self.inverses[self.mod % i] *
                (self.mod // i) % self.mod
            )
            self.fact_inverses.append(
                self.fact_inverses[i - 1] * self.inverses[i] % self.mod
            )

    def mod_combination(self, n, k):
        """
        nCk (mod m)を計算する
        :param n: n
        :param k: k
        :return: nCk (mod m)
        """

        if k == 0:
            return 1
        if n == 0:
            return 0

        denominator = self.fact_inverses[k] * self.fact_inverses[n - k] % self.mod
        return self.facts[n] * denominator % self.mod


MOD = 998244353

N, M, K = map(int, input().split(' '))

ans = 0
comb = ModCombination(mod=MOD, n_max=N)
for k in range(0, K + 1):
    ans += (M * comb.mod_combination(N - 1, k)) % MOD * mod_pow(M - 1, N - 1 - k, MOD)
    ans %= MOD

print(ans)


Measured memory_bytes: 32860