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

struct Edge {
  int to, id;
  Edge(int to, int id): to(to), id(id) {}
};

vector<Edge> g[55];

vector<int> es;
bool dfs(int v, int tv, int p=-1) {
  if (v == tv) return true;
  for (Edge e : g[v]) {
    if (e.to == p) continue;
    if (dfs(e.to, tv, v)) {
      es.push_back(e.id);
      return true;
    }
  }
  return false;
}

int main() {
  int n, m;
  cin >> n;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].emplace_back(b, i);
    g[b].emplace_back(a, i);
  }

  cin >> m;
  vector<ll> eset(m);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    es = vector<int>();
    dfs(a,b);
    for (int e : es) {
      eset[i] |= 1ll<<e;
    }
  }

  ll ans = 0;
  rep(i,1<<m) {
    ll mask = 0;
    rep(j,m) {
      if (i>>j&1) mask |= eset[j];
    }
    int white = __builtin_popcountll(mask);
    ll now = 1ll<<(n-1-white); // 2^(n-1-white)
    if (__builtin_popcountll(i)%2 == 0) ans += now;
    else ans -= now;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const double PI = acos(-1.0);

void solve(long long N, std::vector<long long> a) {
    auto x = 0;
    rep(i, N) x ^= a[i];
    rep(i, N) {
        cout << (a[i] ^ x);
        if (i == N-1) cout << endl;
        else cout << " ";
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 4876
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace2(a,b) cerr <<"a is " << a << " b is " << b << el;
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
vector< pair<ll , ll > > v[123456];
ll k ;
void dijkartas(ll src)
{
    priority_queue<pair<ll,ll> , vector<pair<ll,ll> > , greater<pair<ll,ll> > > pq ;
    vector<ll> dist(k+10 , 3e18);
    pq.push({0,src});
    dist[src] = 0 ;
    while(!pq.empty()){
        ll u = pq.top().second;
        pq.pop();
        for(auto &child:v[u]){
            ll v=child.first ;
            ll w = child.second ;
            if(dist[v] > dist[u] + w){
                dist[v] = dist[u] + w ;
                pq.push({dist[v] , v});
            }
        }
    }
    cout << 1 + dist[0] << el ;
}
int main()
{
    ios;
    cin >> k ;
    forn(i , 1 , k ){
       ll from = i%k ;
       ll to = (i+1)%k;
       ll w = 1 ;
       v[from].pb({to , 1});
    }
    forn(i , 1 , k ) {
       ll from = (i)%k ;
       ll to = (10*i) %k ;
       v[from].pb({to,0});
    }
    dijkartas(1);

}


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

int main()
{
    int N;
    string S;
    cin >> N >> S;
    set<int> U1, U2, U3;
    for (int i = 0; i < N; ++i) {
        int s = S.at(i) - '0';
        for (int t : U2)
            U3.insert(10 * t + s);
        for (int t : U1)
            U2.insert(10 * t + s);
        U1.insert(s);
    }
    cout << U3.size() << endl;
}


Measured memory_bytes: 3684
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String stra = sc.nextLine();
        String strb = sc.nextLine();
        String strc = sc.nextLine();

        int cntA = 0;
        int cntB = 0;
        int cntC = 0;
        int nextIda = 0;
        int nextIdb = 0;
        int nextIdc = 0;
        char next = 'a';
        char ans = 'x';

        outline: while (true) {
            switch (next) {
            case 'a':
                cntA++;
                if (cntA > stra.length()) {
                    ans = 'a';
                    break outline;
                }
                next = stra.charAt(nextIda);
                nextIda++;
                break;
            case 'b':
                cntB++;
                if (cntB > strb.length()) {
                    ans = 'b';
                    break outline;
                }
                next = strb.charAt(nextIdb);
                nextIdb++;
                break;
            case 'c':
                cntC++;
                if (cntC > strc.length()) {
                    ans = 'c';
                    break outline;
                }
                next = strc.charAt(nextIdc);
                nextIdc++;
                break;
            }
        }

        if (ans == 'a') {
            System.out.println('A');
        } else if (ans == 'b') {
            System.out.println('B');
        } else {
            System.out.println('C');
        }
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll mod = 1e9 + 7;

int main(){
  int n, x, y, z;
  cin >> n >> x >> y >> z;
  vector<vector<ll>> dp(n+1,vector<ll>(1<<(x+y+z+1),0));
  dp[0][1] = 1;
  int mask = (1<<(x+y+z+1)) -1;
  int check = (1<<(x+y+z)) | (1<<(y+z)) | (1<<z);
  rep(i,n){
    rep(j,1<<(x+y+z+1)) {
      for(int k = 1; k <= 10; k++) {
        int ns = ((j<<k) + 1) & mask;
        if((check & ns) != check) (dp[i+1][ns] += dp[i][j]) %= mod;
      }
    }
  }
  ll ans = 1;
  rep(i,n) (ans *= 10) %= mod;
  rep(i,mask+1) ans = (ans - dp[n][i] + mod) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 86400
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
 
    // Your code here!
   int a,b;
   cin >> a >> b;
   a = a*b% 2;
   if(a == 1){
       cout  << "Odd" << endl;
   }else{
       cout << "Even" << endl;
   }
    
}

Measured memory_bytes: 256
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    L = LI()

    L.sort()
    ans = 0
    for i in range(0, 2 * n, 2):
        ans += min(L[i], L[i + 1])

    return ans


print(main())


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

using namespace std;

int main(){

    int n[3], k, i, j, l = 0, m = 2, temp, maxim;

    cin >> n[0] >> n[1] >> n[2] >> k;

    int sum[100];

    for(i = 0; i < k; i++){
        for(j = 0; j < 3; j++){
            temp = n[j];
            n[j] *= m;
            sum[l] = n[0] + n[1] + n[2];
            l++;
            n[j] = temp;
        }
        m *= 2;
    }

    maxim = sum[0];

    for(i = 0; i < l; i++){
        if(maxim < sum[i]){
            maxim = sum[i];
        }
    }

    cout << maxim << endl;

    return 0;
}





Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int r,g,b,a,c;
	scanf("%d %d %d",&r,&g,&b);
	a = g*10+b;
	c = a%4;
	if(c == 0)
		printf("YES");
	else
		printf("NO");
	return 0;
}

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

main(){
	string r,g,b,x;
  	cin >> r>>g>>b;
  	x = r+g+b;
  	int i = stoi(x);  
  	if (i%4 ==0){
    	cout<<"YES"<<endl;
    }
  	else{cout<<"NO"<<endl;}
  	
  
  	return 0;

}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if (k<=a+b)
    {
        cout<<min(k,a)<<'\n';
    }
    else
    {
        k-=a+b;
        cout<<a-k;
    }





}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define N 30
#define M 200000
using namespace std;
int n,A[N];
double calc(double a,double b){return abs(a-b)/a;}

double DP(){
  vector<vector<double> > dp(N,vector<double>(M,1e9));
  dp[0][1] = 0;
  for(int i=0;i<n;i++){
    for(int num=1;num<M;num++)
      for(int j=num;j<M;j+=num)
	dp[i+1][j] = min(dp[i+1][j],max(calc(A[i],j),dp[i][num]));
  }
  
  double res=1e9;
  for(int i=0;i<M;i++) res=min(res,dp[n][i]);
  return res;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];
  printf("%.10f\n",DP());
  return 0;
}

Measured memory_bytes: 51452
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int n = sc.nextInt();
        int[] cnt = new int[n + 1];

        for (int i = 1; i <= n; i++) {
            for (int j = i; j <= n; j += i) {
                cnt[j]++;
            }
        }

        long ans = 0;
        for (int i = 0; i <= n; i++) {
            ans += 1L * i * cnt[i];
        }
        out.println(ans);

        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 75636
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=100005;
int n,place[maxn];
pin a[maxn];
map<int,int> zball;
int main(){
	read(n);rep(i,1,n)read(a[i].w1),a[i].w2=i;
	sort(a+1,a+1+n);
	rep(i,1,n)place[a[i].w2]=i;int res=0;
	rep(i,1,n)if((i&1)!=(place[i]&1))if(i&1)res++;
	cout<<res;	
    return 0;
}


Measured memory_bytes: 1536
import sys

sys.setrecursionlimit(100000)


def dfs(v, p, links):
    lv = links[v]
    if len(lv) == 1:
        return 0
    cnt0 = 0
    ret = 0
    for l in lv:
        if l == p:
            continue
        res = dfs(l, v, links)
        ret += res
        if res == 0:
            cnt0 += 1
    if cnt0:
        ret += cnt0 - 1
    return ret


def solve(n, links):
    if n == 2:
        return 1
    for i, l in enumerate(links):
        if len(l) > 2:
            return dfs(i, None, links)
    else:
        return 1


n = int(input())
links = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    links[a].add(b)
    links[b].add(a)
print(solve(n, links))


Measured memory_bytes: 85396
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a,b,c,d;
    cin>>a>>b>>c>>d;
    int sum=0;
    if(a=='2')sum++;
    if(b=='2')sum++;
    if(c=='2')sum++;
    if(d=='2')sum++;
    cout<<sum<<endl;
    return 0;
}


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

using namespace std;

int n, c=0, ac=0, bc=0, abc=0;
vector<string> s;

int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0; i < n; ++i) cin >> s.at(i);

	for (int i = 0; i < n; ++i)
	{
		if (s.at(i).at(0) == 'B') {		
			if (s.at(i).at(s.at(i).size()-1) == 'A') {
				abc++;
			} else {
				bc++;
			}
		} else {
			if (s.at(i).at(s.at(i).size()-1) == 'A') {
				ac++;
			}
		}
		
		
		for (int j = 0; j < s.at(i).size()-1; ++j)
		{
			if (s.at(i).at(j)=='A')
			{
				if (s.at(i).at(j+1)=='B')
				{
					c++;
				}
			}
		}
	}
	if (abc == 0)
	{
		cout << c + min(bc, ac) << endl;
	} else if (bc>0 && ac>0) {
		cout << c + min(bc-1, ac-1) + (abc+1) << endl;
	} else if (bc>0 || ac>0) {
		cout << c + abc << endl;
	} else {
		cout << c + (abc-1) << endl;
	}
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main() {
	s64 N;
	cin >> N;
	
	map<s64, u64> A1;
	map<s64, u64> A2;
	
	for(s64 i=0; i<N; i++) {
		s64 A;
		cin >> A;
		A1[i + A]++;
		A2[i - A]++;
	}
	
	u64 ans = 0;
	for(const auto& a : A1) {
		ans += A2[a.first] * a.second; 
	}
	
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 37716
/* AOJ 0052
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0052
 *
 */

#include <stdio.h>

/* ただし、n は 2,000,000,000 以下の正の整数とします。*/


#define DEBUG 0


int main(){
    int n, i, j;
    int twoes;
    int fives;

    while(scanf("%d", &n)==1 && n){
        if(DEBUG)
            printf("%d\n", n);
        twoes = 0;
        fives = 0;
        for(i=1; i<=n; i++){
            j = i;
            while(!(j%2)){
                j = j/2;
                twoes += 1;
            }
            while(!(j%5)){
                j = j/5;
                fives+= 1;
            }
        }
        if(twoes > fives){
            printf("%d\n", fives);
        }else{
            printf("%d\n", twoes);
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL mod = 998244353;
std::vector<LL>a;
std::vector<std::vector<LL>>memo1, memo2;

LL pow_mod(LL num, LL x, LL mod)
{
	LL res = 1;
	while (x > 0)
	{
		if (x & 1)
		{
			res = (res * num) % mod;
		}
		num = (num * num) % mod;
		x >>= 1;
	}
	return res;
}

LL dp1(LL i, LL j)
{
	if (j == 0) return pow_mod(2, i + 1, mod);
	if (i == -1 || j < 0) return 0;
	if (memo1[i][j] != -1) return memo1[i][j];
	LL res1 = dp1(i - 1, j - a[i]);
	LL res2 = dp1(i - 1, j) * 2;
	return memo1[i][j] = (res1 + res2) % mod;
}

LL dp2(LL i, LL j)
{
	if (j == 0) return 1;
	if (i == -1 || j < 0) return 0;
	if (memo2[i][j] != -1) return memo2[i][j];
	LL res1 = dp2(i - 1, j - a[i]);
	LL res2 = dp2(i - 1, j);
	return memo2[i][j] = (res1 + res2) % mod;
}

int main()
{
	LL N;
	in >> N;
	a.resize(N);
	rep(i, N) in >> a[i];

	LL sum = 0, ans = 1;
	rep(i, N) sum += a[i];
	rep(i, N) (ans *= 3) %= mod;

	memo1.resize(N, std::vector<LL>(91234, -1));
	for (LL i = sum / 2 + sum % 2; i <= sum; ++i) (ans = ans - (3 * dp1(N - 1, i)) % mod + mod) %= mod;
	if (sum % 2 == 0)
	{
		memo2.resize(N, std::vector<LL>(91234, -1));
		(ans += (3 * dp2(N - 1, sum / 2)) % mod) %= mod;
	}

	out << ans << std::endl;
}


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

#define ll long long
#define fr first
#define se second
#define pb push_back

using namespace std;

const long long N = 1e5 + 7;

long long res, n, m, cnt, ans , a , b , sum , mx , mn, c , d;
string s;
set<string>st;
int main()
{
    cin >> a >> b >> c >> d;
    while( a >= 0 and c >=0 ){
        if( !(ans % 2) )
            c-=b;
        if( c <= 0 )
        return cout << "Yes" , 0;
        else if( ans % 2 )
            a-=d;
        if( a <= 0 )
            return cout <<"No" , 0;
        ans ++;

    }
}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

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

	int ans = s.size()-2;

	printf("%c%d%c\n",s[0], ans, s[s.size()-1]);

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static int PopulationCount(int x)
    {
	x = (x & 0x55555555) + (x >> 1 & 0x55555555);
	x = (x & 0x33333333) + (x >> 2 & 0x33333333);
	x = (x & 0x0f0f0f0f) + (x >> 4 & 0x0f0f0f0f);
	x = (x & 0x00ff00ff) + (x >> 8 & 0x00ff00ff);
	return (x & 0x0000ffff) + (x >>16 & 0x0000ffff);
    }

    public static void Main()
    {
	var tmp = ReadIntArray();
	int n = tmp[0], m = tmp[1];

	var d = new int[m];
	
	for (int i = 0; i < m; i++)
	{
	    tmp = ReadIntArray();
	    int k = tmp[0];
	    d[i] = 0;
	    for (int j = 1; j <= k; j++)
	    {
		d[i] += (1 << (tmp[j] - 1));
	    }
	}

	int[] p = ReadIntArray();
	int N = (1 << n);

	int ans = 0;

	for (int b = 0; b < N; b++)
	{
	    int ct = 0;
	    
	    for (int i = 0; i < m; i++)
	    {
		int bits = d[i] & b;
		int pop = PopulationCount(bits);
		if ((pop&1) == p[i]){ ct++; }
	    }

	    if (ct == m){ ans++; }
	}

	WriteLine(ans);
    }
}


Measured memory_bytes: 13268
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn solve(a: f64, b: f64, x: f64) -> f64 {
    let threshold = b / a;
    let tan1 = 2.0 * (a * a * b - x) / (a * a * a);
    if tan1 < threshold {
        return tan1.atan();
    }
    let tan2 = a * b * b / 2.0 / x;
    if tan2 < threshold {
        return threshold.atan();
    }
    tan2.atan()
}

fn main() {
    input! {
        a: f64,
        b: f64,
        x: f64,
    }
    println!("{}", solve(a, b, x) * 180.0 / std::f64::consts::PI);
}


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

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


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

int main(){
  int n;
  cin >> n;
  n++;
  vector<int> dp(n);
  dp[0] = 1, dp[1] = 1;
  for(int i = 2; i < n; i++){
    dp[i] = dp[i-1] + dp[i-2];
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 3092
N, M, X = list(map(int, input().split()))

A = []
C = []
for _ in range(N):
    c, *row = list(map(int, input().split()))
    C.append(c)
    A.append(row)

INF = float('inf')
result = INF
for bit in range(1 << N):
    cost = 0
    spec = [0 for _ in range(M)]
    for i in range(N):
        if (bit >> i) & 1:
            cost += C[i]
            for j in range(M):
                spec[j] += A[i][j]

    # print(bin(bit), spec, cost)
    if min(spec) >= X:
        result = min(result, cost)

if result == INF:
    print(-1)
else:
    print(result)


Measured memory_bytes: 68696
n = int(input())
a = list(map(int, input().split()))

l = []
ans = 1
flag = True
for i in range(1, len(a)):
    num = a[i] - a[i - 1]
    if num > 0:
        num = 1
        l.append(num)
    elif num < 0:
        num = -1
        l.append(num)
    else:
        pass
if len(l) > 1:
    for i in range(len(l) - 1):
        if l[i] != l[i + 1]:
            if flag == True:
                ans += 1
                flag = False
            else:
                flag = True
        else:
            flag = True
print(ans)


Measured memory_bytes: 20324
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

N,K=nm()

ans = 0 
for i in range(K,N+2):
    ans = (ans + N * i - i * (i-1) + 1) % mod

print(ans)


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
int n;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}  

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key){
    return u;
  }
  if(k < u->key){
    return treeSearch(u->left,k);
  }
  else{
    return treeSearch(u->right,k);
  }
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void transplant(Node u,Node v){
  if(u->parent == NIL){
    root = v;
  }
  else if(u == u->parent->left){
    u->parent->left = v;
  }
  else{
    u->parent->right = v;
  }
  if(v != NIL){
    v->parent = u->parent;
  }
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL){
    transplant(z,z->right);
  }
  else if(z->right == NIL){
    transplant(z,z->left);
  }
  else{
    y = treeMinimum(z->right);
    if(y->parent != z){
      transplant(y,y->right);
      y->right = z->right;
      y->right->parent = y;
    }
    transplant(z,y);
    y->left = z->left;
    y->left->parent = y;
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y =x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
}

void inorder(Node u){
 
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){

  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24036
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

typedef long long ll;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

int main() {
  int n;
  cin >> n;
  unordered_map<int, int> la;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (la.find(a) == la.end()) {
      la[a] = 0;
    }
    ++la[a];
  }
  int ans = la.size();
  int num_even = 0;
  for (auto it : la) {
    if (it.second%2 == 0) ++num_even;
  }
  if (num_even%2) --ans;
  cout << ans << endl;
}



Measured memory_bytes: 4388
#pragma GCC optimize ("O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ");
//#define double long double

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int MAX = 200060;
const double pi = acos(-1);
const ll INF = 1e16;


void solve() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N)cin >> A[i];
	sort(all(A));
	ll ans = 0;
	REP(i, N - 2) {
		FOR(j, i + 1, N - 1) {
			FOR(k, j + 1, N) {
				if (A[i] + A[j] <= A[k])break;
				if (A[i] < A[j] + A[k] && A[j] < A[i] + A[k] && A[k] < A[i] + A[j])ans++;
			}
		}
	}
	print(ans);
}


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

	solve();
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static boolean[] used;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int g = sc.nextInt();
		int[] p = new int[d];
		int[] c = new int[d];
		// used[i]：i番目の問題を選択したかどうか
		used = new boolean[d];
		for(int i = 0; i < d; i++) {
			p[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		int ans = Integer.MAX_VALUE;
//		System.out.println(1<<d);
		for(int mask = 0; mask < (1<<d); mask++) {
//			System.out.println(Integer.toBinaryString(mask));
			int cnt = 0;
			long point = 0;
			for(int i = 0; i < d; i++) used[i] = false;
			for(int i = 0; i < d; i++) {
				if((mask&(1<<i)) >= 1) {
					used[i] = true;
					point += 100 * (i + 1) * p[i] + c[i];
					cnt += p[i];
				}
			}
			if(point >= g) {
				ans = Integer.min(ans, cnt);
//				System.out.println(ans + " " + point + " " + mask);
				continue;
			}
			for(int i = d - 1; i >= 0; i--) {
				// このループの内側のループからこのループの外側のループに戻るかどうかの判定
				boolean ok = false;
				if(!used[i]) {
					for(int j = 0; j < p[i]; j++) {
						point += (i + 1) * 100;
						cnt++;
						if(j == p[i] - 1) point += c[i];
						if(point >= g) {
							ans = Integer.min(ans, cnt);
							ok = true;
							break;
						}
					}
				}
				if(ok) break;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#include"bits/stdc++.h"
using ll=long long; 
using ld=long double; 
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int mod=1e9+7; 
void dfs(int s,vector<vector<int>>&v,vector<int>&f,int &c)
{
  f[s]=1; c++; 
  for(auto i:v[s])
  {
    if(!f[i]) {  dfs(i,v,f,c); }
  }
  return; 
}
int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout); 
  #endif
  int n,m; cin>>n>>m; map<pair<int,int>,int>g; int x,y;
  vector<int>p(n+1); for(int i=1;i<=n;i++) p[i]=i; vector<vector<int>>v(n+1);   
  if(m==0){ cout<<1<<"\n"; return 0; }
  for(int i=1;i<=m;i++)
  {
    cin>>x>>y; if(x>y) swap(x,y); 
    if(g[{x,y}]) continue; 
    g[{x,y}]=1; v[x].emplace_back(y); v[y].emplace_back(x); 
  }
  int ans=0; vector<int>f(n+1,0); 
  for(int i=1;i<=n;i++)
  {
    if(f[i]) continue; 
    int c=0; dfs(i,v,f,c); 
    ans=max(c,ans); 
  }
  cout<<ans<<"\n"; 
}

Measured memory_bytes: 37332
from collections import deque
N, M = map(int, input().split())
lst = [[] for _ in range(N + 1)]
dist = [float("inf")]*(N+1)
for _ in range(M):
    a, b = map(int, input().split())
    lst[a].append(b)
    lst[b].append(a)

q = deque()
d = 0
q.append([1,d])

while q:
    now, d = q.popleft()
    dist[now] = d

    for itm in lst[now]:
        if dist[itm] > d+1:
            q.append([itm,d+1])
            
print("POSSIBLE") if dist[N] <= 2 else print("IMPOSSIBLE")

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

#define Int register int
#define mod 1000000007
#define MAXN 55

template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}

int n,ans,a[MAXN << 1],dp[MAXN][MAXN << 1][MAXN << 1];
void add (int &a,int b){a += b;if (a >= mod) a -= mod;}

signed main(){
	read (n);
	for (Int i = 1;i <= 2 * n - 1;++ i) read (a[i]);sort (a + 1,a + 2 * n);
	dp[n][1][0] = 1;for (Int i = n - 1;i;-- i){
		int al = (a[i] != a[i + 1]),ar = (a[2 * n - i] != a[2 * n - i - 1]);
		for (Int l = 0;l <= 2 * n - 1;++ l)
			for (Int r = 0;l + r <= 2 * n - 1;++ r)
				if (dp[i + 1][l][r]){
					int t = dp[i + 1][l][r];
					for (Int dl = 1;dl <= l + al;++ dl) add (dp[i][l + al - dl + 1][r + ar + (dl > 1)],t);
					for (Int dr = 1;dr <= r + ar;++ dr) add (dp[i][l + al + 1][r + ar - dr],t);
				}
	}
	for (Int l = 0;l <= 2 * n - 1;++ l)
		for (Int r = 0;l + r <= 2 * n - 1;++ r)
			add (ans,dp[1][l][r]);
	write (ans),putchar ('\n');
	return 0;
} 

Measured memory_bytes: 4812
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;

    string s;
    cin >> s;

    vector <int> pref(n + 1);
    for (int i = 0; i < n; ++i)
        pref[i + 1] = pref[i] + (s[i] == '#');

    int ans = 1e9;
    for (int i = 0; i <= n; ++i) {
        ans = min(ans, pref[i] + (n - i - (pref[n] - pref[i])));
    }           
    cout << ans << endl;
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;


const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MAXN = 3e3 + 10;
const ll INF = 1e18;

str s, p;
ll dp[MAXN][MAXN];
int main(){
	IOS;
	cin >> s >> p;
	s = "." + s;
	p = "." + p;
	for (int i = 1; i < s.size(); i++){
		for (int j = 1; j < p.size(); j++){
			if (s[i] == p[j]){
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}else{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	str ans = "";
	ll pnt = s.size() - 1, pnt1 = p.size() - 1;
	while (pnt != 0 && pnt1 != 0){
		if (s[pnt] == p[pnt1]){
			ans += s[pnt];
			pnt --, pnt1 -- ;
		}else{
			if (dp[pnt][pnt1] == dp[pnt - 1][pnt1]) pnt--;
			else pnt1 --;
		}
		
	}
	for (int i = ans.size() - 1; i>=0 ;i--) cout << ans[i];
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




Measured memory_bytes: 70784
import math
A, B, H, M = map(int, input().split(' '))
deg = abs(30 * H + 0.5 * M - 6 * M)
if deg > 180:
    deg = 360 - deg
deg = math.radians(deg)
print(math.sqrt((B * math.sin(deg)) ** 2 + (B * math.cos(deg) - A) ** 2))

Measured memory_bytes: 9520
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = list(iss())

    while True:
        del S[-1]
        ln = len(S)
        if ln % 2 == 0:
            l = "".join(S[:ln // 2])
            r = "".join(S[ln // 2:])
            if l == r:
                print(len(S))
                break


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int N, K;
    read(N, K);

    int sum = 0;
    rep(i, N) {
        int x; read(x);
        sum += min(abs(x - 0), abs(x - K)) * 2;
    }

    print(sum);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const int N = 30;
const int INF = 2e9;
const double PI = acos(-1);

int cnt[N+10];

bool cmp(int lhs, int rhs){ return lhs > rhs; }

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

    memset(cnt,0,sizeof(cnt));

    int n,k;
    string str;

    cin >> n >> k;
    for(int i = 0; i < n; ++i){
        cin >> str;
        cnt[str[0]-'A']++;
    }

    // for(int i=0;i<26;++i) cout << cnt[i] << " ";
    // cout << endl;

    int ans = 0;
    while(1){
        sort(cnt,cnt+26,cmp);
        bool flag = 0;
        int temp = 0;
        for(int i = 0; i < 26; ++i){
            if(cnt[i] > 0){
                cnt[i]--;
                temp++;
            }

            if(temp == k){
                flag = 1;
                ans++;
                break;
            }
        }

        if(!flag) break;
    }

    cout << ans << endl;

    return 0;
}   

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

using namespace std;
using ll = long long;

ll gcd(ll x, ll y){
  if (y == 0) return x;
  else return gcd(y, x % y);
}


int main(){
  ll A, B;
  cin >> A >> B;
  
  cout << A/gcd(A, B)*B << endl;

  return 0;
}

Measured memory_bytes: 3552
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>

int check(int a)
{
    int t=0;
    while(a)
    {
        t+=(a%10);
        a/=10;
    }
    return t;
}

using namespace std;


int main()
{

    int n,a,b,i,sum=0;
    cin>>n>>a>>b;
    for(i=1;i<=n;++i)
    {
        if(check(i)<=b && check(i)>=a)
            sum+=i;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
abcN = [list(map(int, input().split())) for i in range(N)]

dp = [[0]*3 for _ in range(N)]
dp[0][0] = abcN[0][0]
dp[0][1] = abcN[0][1]
dp[0][2] = abcN[0][2]

for i in range(1, N):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + abcN[i][0]
    dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + abcN[i][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + abcN[i][2]

print(max(dp[-1][0], max(dp[-1][1], dp[-1][2])))

Measured memory_bytes: 70492
#include "bits/stdc++.h"
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define gcd(a,b) __gcd(a,b)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define pb(n) push_back(n)
#define pp pop_back()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define type(a) typeid(a).name();
#define print(arr) cout << "[" ;for(unsigned int i=0;i<(unsigned int) arr.size();i++){ (i==arr.size()-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define Arr(arr,l) cout << "[" ;for(unsigned int i=0;i<(unsigned int) l;i++){ (i==l-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define console(arr) cout << "["<<endl; for(ll i=0;i<(ll)arr.size();++i){cout << " [";for(ll j=0;j<(ll)arr[i].size();++j){(j==(int)arr[i].size()-1)?cout << arr[i][j]:cout << arr[i][j] << ",";}cout << "]"<<endl;} cout << "]"<<endl
#define starting() auto start = high_resolution_clock::now()
#define ending() auto stop = high_resolution_clock::now();auto duration = duration_cast<microseconds>(stop - start);cout << endl << endl << "Execution Time : "<<duration.count()/1000 << " ms" << endl
 
template <typename T1,typename T2>
void mapped(map<T1,T2>m){for(auto ite=m.begin();ite!=m.end();++ite){cout << "'" << ite->first << "'"<<" : "<<ite->second <<endl;}}
 
template <typename T1 , typename T2>
void mappedArr(map<T1,vector<T2>>m){for(auto ity=m.begin();ity!=m.end();++ity){cout << "'"<< ity->first <<"'"<<" : "<<"[";
for(int i=0;i<(int)ity->second.size();++i){(i==(int)ity->second.size()-1)?cout << ity->second[i]:cout << ity->second[i] << ",";}cout << "]"<<endl;}}
 
string int_to_string(int x){ stringstream ss; ss << x; string ni = ss.str(); return ni;}
int char_to_int(char c){ int n = (int)c - 48; return n; }
int string_to_int(string x){ int n; stringstream s(x); s >> n; return n; }
 
template <typename T1,typename T2>
void ArrPair(vector<pair<T1,T2>>vp){for(int i=0;i<(int)vp.size();++i){
cout << "(" << vp[i].first << "," << vp[i].second << ")"<<endl ;}}
 
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;
 
unordered_map<int,int> um;
unordered_set<int> us;
set<int> s;
// v.front() gives the first element of vector 
// v.back()  gives the last element of vector
// insert erase substr
 
bool isPrime(ll n) 
{ 
    if (n <= 1) 
        return false;  
    for (ll i = 2; i < n; i++) 
        if (n % i == 0) 
            return false; 
  
    return true; 
} 
int main(){
  ll n;
  cin >> n;
  for(int i=n;i<100000000000;++i){
	  if(isPrime(i)){
		  cout << i;
		  return 0;
	  }
  }
  return 0;
}  


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <map>
#include <math.h>

using namespace std;

struct Point{

    Point(int _t,int _x,int _y){
        t=_t;
        x=_x;
        y=_y;
    }
    int t;
    int x;
    int y;
};

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

    int N;scanf("%d",&N);
    vector<int> x(N);
    vector<int> y(N);
    vector<int> t(N);
    for(int i=0;i<N;i++){
        scanf("%d",&t[i]);
        scanf("%d",&x[i]);
        scanf("%d",&y[i]);
    }

    bool isOk=true;
    for(int i=0;i<N;i++){
        int z=x[i]+y[i];
        if((t[i]%2)!=(z%2)){
            isOk=false;
        }
    }

    for(int i=0;i<N;i++){
        if(i!=0){
            int tDiff=t[i]-t[i-1];
            int xyDiff=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
            if(tDiff<xyDiff){
                isOk=false;
            }
        }else{
            int tDiff=t[i];
            int xyDiff=abs(x[i]-0)+abs(y[i]-0);
            if(tDiff<xyDiff){
                isOk=false;
            }
        }
    }

    if(isOk){
        printf("Yes");
    }else{
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    s = input()
    ans = 0
    if s[0] == "1":
        ans += 1
    if s[1] == "1":
        ans += 1
    if s[2] == "1":
        ans += 1
        
    print(ans)
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
#define forn(i,n) for(int i = 0 ; i < (int)n ; ++i)
#define fi first
#define se second
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el
#define ri(n) scanf("%d",&n)
#define __USE_MINGW_ANSI_STDIO 0
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

//const ll INF = LONG_LONG_MAX;
const double PI = acos(-1);
const int MAXN = 1e5+200;
const double EPS= 1e-10;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    int b[n];
    int c[n];
    int dp[n][3];
    memset(dp, -1, sizeof(dp));
    forn(i,n){
        cin>>a[i]>>b[i]>>c[i];
    }

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for1(i,n-1){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2] = max(dp[i-1][1],dp[i-1][0])+c[i];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


Measured memory_bytes: 2560