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

int main(){
  int n,k;
  cin>> n >> k;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin>> a[i];
  
  //全丸太の長さをx以下にするのに必要な回数がk以下になる最小のxを二分探索
  double left=0, right=1e9; //left:不可能 right:可能
  int64_t count=0;
  while(right-left>1){ //ループ終了時に解は floor(right) または ceil(right) とわかる
    double x=(left+right)/2.0;
    count=0;
    for(int i=0; i<n; i++){
      double cut=a[i]/x;
      if(cut==(int)cut) cut-=1;
      count+=(int)cut;
    }
    if(count<=k) right=x;
    else left=x;
  }
  
  int ans=(int)right; //ここで right<1 だと ans=0 で divided by 0 になる
  if(ans==0){
    cout<< 1 << endl;
    return 0;
  }
  count=0;
  for(int i=0; i<n; i++){
    count+=(a[i]-1)/ans;
  }
  if(count>k) ans++;
  cout<< ans << endl;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

ll n, m, s, t;
vector<vector<ll>> to;
deque<ll> ans;
vector<bool> seen;

void dfs(ll cv) {
  FOREACH(nv, to[cv]) {
    if (seen[nv]) continue;
    seen[nv] = true;
    ans.push_back(nv);
    t = nv;
    dfs(nv);
    break;
  }
}

bool isOK(ll cv, bool isLeft) {
  FOREACH(nv, to[cv]) {
    if (seen[nv]) continue;
    if (isLeft) {
      ans.push_front(nv);
      s = nv;
    } else {
      ans.push_back(nv);
      t = nv;
    }
    seen[nv] = true;
    return false;
    break;
  }
  return true;
}
int main() {
  cin >> n >> m;
  to.resize(n);
  seen.resize(n, false);
  REP(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  s = 0;
  seen[s] = true;
  ans.push_back(s);
  dfs(s);
  // s--tパスができた

  // s,tは条件を満たすか確認
  while (!isOK(s, true))
    ;
  while (!isOK(t, false))
    ;

  ll sz = SZ(ans);
  cout << sz << endl;
  REP(i, sz) { cout << ans[i] + 1 << " \n"[i == sz - 1]; }
}

Measured memory_bytes: 7680
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for (auto p : mp) mx = max(mx, p.second);
    for (auto p : mp) {
        if (p.second != mx) continue;
        cout << p.first << endl;
    }
    return 0;
}


Measured memory_bytes: 19236
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define cin1(x) scanf("%d",&x)
#define cin2(x,y) scanf("%d %d",&x,&y)
#define cin3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define rr read()
#define ll long long
#define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n+5];
	rep(i,0,n)
		cin>>a[i];
	double ans=0;
	rep(i,0,n)
		ans+=1.0/a[i];
	ans=1.0/ans;
	printf("%0.6lf\n",ans);
    return 0;  
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
const int INF=1e9;
//const int MOD=998244353;
const long long LINF=1e18;
#define int long long
//template
int black[2005][2005],ver[2005][2005],wid[2005][2005];
//main
signed main(){
  int N,M,Q;cin>>N>>M>>Q;
  std::vector<string> s(N+1);
  for(int i=0;i<N;i++)cin>>s[i];
  s[N]=(string(M,'#'));
  for(int i=0;i<=N;i++)s[i]+="#";
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      if(s[i][j]=='1')black[i+1][j+1]++;
      if(s[i][j]=='1'&&s[i][j+1]=='1')ver[i+1][j+1]++;
      if(s[i][j]=='1'&&s[i+1][j]=='1')wid[i+1][j+1]++;
    }
  }
  for(int i=0;i<=N;i++){
    for(int j=0;j<=M;j++){
      black[i][j+1]+=black[i][j];
      ver[i][j+1]+=ver[i][j];
      wid[i][j+1]+=wid[i][j];
    }
  }
  for(int i=0;i<=N;i++){
    for(int j=0;j<=M;j++){
      black[i+1][j]+=black[i][j];
      ver[i+1][j]+=ver[i][j];
      wid[i+1][j]+=wid[i][j];
    }
  }
  std::vector<int> ans(Q);
  for(int i=0;i<Q;i++){
    int x1,x2,y1,y2;cin>>x1>>y1>>x2>>y2;
    int B=black[x2][y2]+black[x1-1][y1-1]-black[x2][y1-1]-black[x1-1][y2];
    int E1=ver[x2][y2-1]+ver[x1-1][y1-1]-ver[x2][y1-1]-ver[x1-1][y2-1];
    int E2=wid[x2-1][y2]+wid[x1-1][y1-1]-wid[x2-1][y1-1]-wid[x1-1][y2];
    ans[i]=B-E1-E2;
  }
  for(int i=0;i<Q;i++)cout<<ans[i]<<endl;
}
/*
解説AC
連結成分の個数は森なら頂点の個数と辺の数から数えられるというもの
森じゃなくても各連結成分の頂点の数と辺の数に何かしら関係があれば使えるテクだね
数えやすい成分に言い換えてしまうテクニック
あとそもそも今回の問題の設定を閉路がないとしか思わなかったけど閉路がない＝木（森）を忘れていた
*/


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

int main()
{
  int N,ans=0;scanf("%d",&N);
  int a[N];
  for(int i=0;i<N;i++)scanf("%d ",&a[i]);
  for(int i=0;i<N;i++)while(a[i]%2==0){a[i]/=2;ans++;}
  printf("%d\n",ans);
}

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

int main(){
  int x,a,b; cin>>x >>a >>b;
  if(a>=b){
    cout<<"delicious"<<endl;
  }else if(a+x >= b){
    cout<<"safe"<<endl;
  }else{
    cout<<"dangerous"<<endl;
  }
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc174
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
            solve_abc174B();
            Console.Out.Flush();
        }

        public static void solve_abc174C()
        {
        }

        public static void solve_abc174B()
        {
            int[] nd = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nd[0];
            int d = nd[1];
            int cnt = 0;
            for (int i = 0; i < n; i++)
            {
                long[] xy = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
                double dis = Math.Sqrt(xy[0] * xy[0] + xy[1] * xy[1]);
                if (dis <= d)
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }

        public static void solve_abc174A()
        {
            int x = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(x >= 30 ? "Yes" : "No");
        }
    }
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

typedef pair<int,int> P;
typedef vector<int> V;
typedef vector<V> VV;
VV g;
V X;
bool ret=true;
P dfs(int v,int p){
    V dp(5001,1e8);
    dp[0]=0;
    for(auto &u:g[v]){
        if(p==u)continue;
        V nxt(5001,1e8);
        auto child=dfs(u,v);
        FOR(i,child.fi,5001)
            chmin(nxt[i],dp[i-child.fi]+child.se);
        FOR(i,child.se,5001)
            chmin(nxt[i],dp[i-child.se]+child.fi);
        swap(dp,nxt);
        
    }
    FOR(i,1,5001)chmin(dp[i],dp[i-1]);
    if(dp[X[v]]==1e8)ret=false;
    return {X[v],dp[X[v]]};

}
int main(){
    int N;
    cin>>N;
    g.assign(N,V());
    X.assign(N,0);

    FOR(i,1,N){
        int p;
        cin>>p;
        p--;
        g[p].pb(i);
        g[i].pb(p);
    }
    cin>>X;
    dfs(0,0);
    if(ret)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 N, M;
  cin >> N >> M;
  vector<int64> G[112345];
  vector<int64> H(N);
  REP(i, N) {
    cin >> H[i];
  }
  REP(i, M) {
    int64 a, b;
    cin >> a >> b; a-- ;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int64 res = 0;
  REP(i, N) {
    bool ok = 1;
    for (auto& u :G[i]) {
      if (H[u] >= H[i]) ok = 0;
    }
    res += ok;
  }
  cout << res << endl;
}


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

using namespace std;

const int MAX_N = 2e5 + 5;
const long long MOD = 1e9 + 7;

typedef long long ll;

int Q;
ll ans = 0;
priority_queue<int> lo;
priority_queue<int, vector<int>, greater<int>> hi;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> Q;
    while (Q--) {
        char c; cin >> c;
        if (c == '1') {
            int a, b; cin >> a >> b;
            ans += b;
            if (hi.empty() || a <= hi.top()) {
                ans -= a;
                lo.push(a);
            }
            else {
                ans += a;
                hi.push(a);
            }
            if (lo.size() > hi.size() + 1) {
                ans += 2 * lo.top();
                hi.push(lo.top());
                lo.pop();
            }
            if (lo.size() < hi.size()) {
                ans -= 2 * hi.top();
                lo.push(hi.top());
                hi.pop();
            }
        }
        else {
            cout << lo.top() << " " << ans + (lo.size() == hi.size() ? 0 : lo.top()) << "\n";
        }
    }
}



Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n],g=0,h=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(g<a[i])g=a[i];
    h+=a[i];
  }
  h-=g;
  if(g<h)cout << "Yes";
  else cout << "No";
}

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

string S;
vector<int> a, b;
ll ans;

int main() {
    cin >> S;
    a.push_back(1);
    for (int i = 1; i < S.size(); i++) {
        if (S[i] == S[i-1]) a.back()++;
        else a.push_back(1);
    }
    b.push_back(0);
    for (c : a) {
        if (S[b.size()-1] == '<') {
            for (int i = 1; i <= c; i++) b.push_back(i);
        }
        else {
            if (b.back() < c) b.back() = c;
            for (int i = c - 1; i >= 0; i--) b.push_back(i);
        }
    }
    ans = 0;
    for (int v : b) ans += v;
    cout << ans << endl;
}


Measured memory_bytes: 3836
#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<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

const lint MOD = pow(10, 9) + 7;

/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/


int main() {
	vector<int>V(3);
	rep(i, 3) {
		cin >> V[i];
	}
	sort(V);
	if (V[2]==V[0]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#!/usr/bin/python
import sys
if sys.version_info[0]>=3: raw_input=input

try:
	while True:
		n=int(raw_input())
		if n==0: break
		r=0
		i=1
		while 1:
			n-=i
			if n<i: break
			i+=1
			if n%i==0: r+=1
		print(r)
except EOFError:
	pass

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

int main()
{
	int N = 0, M = 0,G=0;

	cin >> N >>M;
	for (int i = 1; i <=sqrt(M) ; i++) {
		if (M % i == 0) {
			int q = M/i;

			int temp[2] = {};
			
			if (q >= N) {
				temp[0] = i;
			 if (i >= N) {
				temp[1] = q;
			 }
			}
			G = max(G,max(temp[0], temp[1]));
		}
	}

    cout << G <<endl; 
	return 0;

}

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

int main()
{
    int n, k;
    string s;
    cin >> n >> k >> s;
    int init = 0;
    if(s[0] == 'R') if(s[1] == 'R') init++;
    if(s[n - 1] == 'L') if(s[n - 2] == 'L') init++;
    for(int i = 1; i < n - 1; i++){
        if(s[i] == 'L') if(s[i - 1] == 'L') init++;
        if(s[i] == 'R') if(s[i + 1] == 'R') init++;
    }
    cout << min(n - 1, init + k * 2) << endl;
}

Measured memory_bytes: 512
a,b,m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = min(A) + min(B)
for _ in range(m):
    x,y,c = map(int, input().split())
    p = A[x-1] + B[y-1] - c
    if p < ans:
        ans = p
print(ans)



Measured memory_bytes: 18684
#include <bits/stdc++.h>
#define print(x) cout << x << '\n';

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.in", "r", stdin);
    int a, c;
    bool ans = false;
    cin >> a >> c;
    int b = 1;
    while(b < 4 && !ans){
        if((a*b*c) % 2 == 1) ans = true;
        b++;
    }
    if(ans)
        cout << "Yes";
    else
        cout << "No";
    
    return 0;
}


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

#define int long long

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))
#define upp(a,b) upper_bound(all(a),(b))
#define fill(i,n) memset(i,n,sizeof(i))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N,K;
int dp[55];
int pdp[55];
int ans=0;

void dfs(int N,int K){
    if(N==-1||K==0)return;
    if(dp[N]<=K){
        ans+=pdp[N];
        K-=dp[N];
        dfs(N,K);
    }else if(dp[N-1]+2<=K){
        ans+=pdp[N-1]+1;
        K-=dp[N-1]+2;
        dfs(N-1,K);
    }else dfs(N-1,K-1);
}

signed main() {
    IOS();
    cin>>N>>K;
    pdp[0]=dp[0]=1;
    rep(i,0,50){
        pdp[i+1]=2*pdp[i]+1;
        dp[i+1]=2*dp[i]+3;
    }
    dfs(N,K);
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    




















































    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int W, H, x, y, r;
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if(( x >= r && x + r <= W ) && ( y >= r && y + r <= H )){
  printf("Yes\n");
  }
  else{
  printf("No\n");
  }

  return 0;

}

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

int main(){
  char s[100000],s5[6],s6[7],s7[8];
  int i,n,flag;
  scanf("%s",s);
  n=strlen(s);
  s7[7]=s6[6]=s5[5]='\0';
  for(i=n-1;i>=0;i-=flag){
    for(int j=0;j<7;j++){
      s7[j]=s[i-6+j];
      if(j>0)
        s6[j-1]=s[i-6+j];
      if(j>1)
        s5[j-2]=s[i-6+j];
    }
    if(strcmp(s7,"dreamer")==0)
      flag=7;
    else if(strcmp(s6,"eraser")==0)
      flag=6;
    else if(strcmp(s5,"dream")==0||strcmp(s5,"erase")==0)
      flag=5;
    else{
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  sort(d.begin(), d.end());
  int m = n / 2;
  int l = d[m-1], r = d[m];
  cout << r - l << '\n';
  return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

  vector<vector<int>> Mat(n, vector<int>(n, -1));
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    Mat[a][b] = Mat[b][a] = 1;
  }

  vector<int> data(n - 1);
  for (int i = 0; i < n - 1; i++) {
    data[i] = i + 1;
  }

  int cnt = 0;
  do {
    bool is_ok = true;
    if (Mat[0][data[0]] == -1) {
      is_ok = false;
    }
    for (int i = 1; i < n - 1; i++) {
      int u = data[i - 1];
      int v = data[i];
      if (Mat[u][v] == -1) {
        is_ok = false;
      }
    }
    if (is_ok) {
      cnt++;
    }
  } while (next_permutation(data.begin(), data.end()));

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> penalty(n, 0);
    vector<int> is_ac(n, 0);
    for (size_t i = 0; i < m; i++)
    {
        int p;
        string s;
        cin >> p >> s;
        if(is_ac[p-1]==0)
        {
            if(s=="AC"){
                is_ac[p - 1] = 1;
            }
            else{
                penalty[p - 1] += 1;
            }
        }
    }
    int ac=0;
    int pe = 0;
    for (size_t i = 0; i < n; i++)
    {
        if(is_ac[i]==1){
            ac++;
            pe += penalty[i];
        }
    }
    cout << ac << " " << pe << endl;

    return 0;
}

Measured memory_bytes: 1024
from bisect import *
n = int(input())
A = list(map(int,input().split()))
s = {}
# d = {}
ans = 0
for i,a in enumerate(A):
    if a+i not in s.keys():s[a+i] = 0# []
    # s[a+i].append(i)
    s[a+i] += 1
    if i-a not in s:continue
    ans += s[i-a]
    # if i-a not in d.keys():d[i-a] = []
    # d[i-a].append(i)
print(ans)


Measured memory_bytes: 40408
import math

class Ufo:
  def __init__(self, x, y, r, v):
    self.dist = get_dist(x, y)
    self.angle = get_angle(y, x)
    self.rad = r
    self.v = v

def get_dist(x, y):
  return (x ** 2 + y ** 2) ** (1 / 2)

def get_angle(x, y):
  angle = math.atan2(y, x)
  if angle < 0:
    angle += math.pi * 2
  return angle

def reache(ufos, R):
  remove_lst = []
  for i , ufo in enumerate(ufos):
    ufo.dist -= ufo.v
    if ufo.dist <= R:
      remove_lst.append(i)
  for i in reversed(remove_lst):
    ufos.pop(i)
  return len(remove_lst)

def is_dead(ufo, laser, R):
  diff = abs(ufo.angle - laser)
  if diff > math.pi:
    diff = math.pi * 2 - diff
  if (diff <= math.pi / 2 and ufo.dist * math.sin(diff) <= ufo.rad) or (ufo.dist <= ufo.rad):
    if ufo.dist * math.cos(diff) + (ufo.rad ** 2 - (ufo.dist * math.sin(diff)) ** 2) ** (1 / 2) > R:
      return True
  return False

def shoot(ufos, laser, R):
  remove_lst = []
  for i, ufo in enumerate(ufos):
    if is_dead(ufo, laser, R):
      remove_lst.append(i)
  for i in reversed(remove_lst):
    ufos.pop(i)

while True:
  R, n = map(int, input().split())
  if R == 0:
    break

  ufos = []
  for _ in range(n):
    x, y, r, v = map(int, input().split())
    ufos.append(Ufo(x, y, r, v))
  
  ans = 0
  while ufos:
    ans += reache(ufos, R)
    if ufos:
      laser = min(ufos, key=lambda ufo:ufo.dist).angle
      shoot(ufos, laser, R)
  print(ans)


Measured memory_bytes: 5836
import Control.Monad (replicateM)
import Data.Array (Array,listArray,bounds,(!))
import Data.List (sort)

main = do
    d <- readLn
    if d == 0 then return () else do
        n <- readLn
        m <- readLn
        ps <- replicateM (n-1) readLn >>=
                return . listArray (0,n) . sort . ([0,d] ++)
        ks <- replicateM m readLn
        print $ sum $ map (distance ps) ks
        main

distance :: Array Int Int -> Int -> Int
distance ps d = distance' a b
    where
    (a,b) = bounds ps

    distance' a b
        | b - a == 1
            = min (d - ps ! a) (ps ! b - d)
        | d >= ps ! m
            = distance' m b
        | otherwise
            = distance' a m
        where
        m = (a+b) `div` 2

Measured memory_bytes: 72672
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vpair r(n), b(n);
    rep(i, n) cin >> r[i].fi >> r[i].se;
    rep(i, n) cin >> b[i].fi >> b[i].se;

    int ans = 0;
    vbool use(n, false);
    sort(all(b));

    rep(i, n) {
        int mx = -1;
        int id = -1;
        rep(j, n) {
            if (use[j]) continue;
            if (b[i].fi > r[j].fi && b[i].se > r[j].se && r[j].se > mx) {
                mx = r[j].se;
                id = j;
            }
        }
        if (id != -1) {
            ans++;
            use[id] = true;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int,input().split())
S = input()
L = []
t = 1
for k in range(1,N):
    if S[k-1] == S[k]:
        t += 1
    else:
        L.append(t)
        t = 1
L.append(t)
l = len(L)
A = [0 for k in range(l+2)]

for k in range(l):
    A[k+1] = A[k] + L[k]
A[l+1] = A[l]
if S[0] == "0":
    ans = A[min(l,2*K)]
    if l%2 == 1:
        for k in range(l-2*K+1):
            if k%2 == 1:
                ans = max(ans,A[k+2*K+1]-A[k])
    else:
        for k in range(l-2*K):
            if k%2 == 1:
                ans = max(ans,A[k+2*K+1]-A[k])
else:
    ans = A[min(l,2*K+1)]
    if l%2 == 1:
        for k in range(l-2*K):
            if k%2 == 0:
                ans = max(ans,A[k+2*K+1]-A[k])
    else:
        for k in range(l-2*K+1):
            if k%2 == 0:
                ans = max(ans,A[k+2*K+1]-A[k])

print(ans)


Measured memory_bytes: 47092
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}
 
typedef pair<ll,ll> Pair;
const ll inf =1000000007;

void solve(){
    ll n,k;
    cin >> n >>k;
    ll ans=0;
    ll i=1;
    while(i<n){
        i+=(k-1);
        ans++;
    }
    kaku(ans);
}

int main(){
    solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  double r;
  cin>>r;
  printf("%.10f\n",2*r*M_PI);
  return(0);
}


Measured memory_bytes: 3772
L, R = map(int, input().split())

if (R - L) >= 2019:
    print(0)
    exit()

L, R = L % 2019, R % 2019

if L >= R:
    R += 2019

ans = float('inf')

for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        ans = min(ans, (i * j) % 2019)
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        998244353
#define all(x)     x.begin(),x.end()    
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
ll power(ll x, ll y){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
ll inverse(ll a){return power(a,mod-2)%mod;}
ll pref_v1[200001];
ll pref_v2[200001];
bool check(ll mid,ll k,ll m,ll n) {
	ll i=0,j;
	while(i<=mid && i<=n) {
		if(mid-i<=m) {
			j=mid-i;
			if(pref_v1[i]+pref_v2[j]<=k) return true;
		}
		i++;
	} 
	return false;
}
void comp() {
	ll i,j,k,n,m;
	cin>>n>>m>>k;
	vector<ll>v1(n+1),v2(m+1);
	fl(i,n) {
		cin>>v1[i+1];
	}
	fl(i,m) {
		cin>>v2[i+1];
	}
	pref_v2[1]=v2[1];
	pref_v1[1]=v1[1];
	fli(i,2,n+1) pref_v1[i]=pref_v1[i-1]+v1[i];
	fli(i,2,m+1) pref_v2[i]=pref_v2[i-1]+v2[i];
	ll low=0,high=(n+m),mid;
	ll ans=0;
	while(low<=high) {
		mid=(low+high)/2;
		if(check(mid,k,m,n)) {
			low=mid+1;
			ans=mid;
		}
		else {
			high=mid-1;
		}
	}
	cout<<ans<<"\n";
}
int main() {
    speedup;
    ll i=0,t;
    t=1;
    //cin>>t;
    while(t--) {
        comp();
    }
    return 0;
}

Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long n,sum=0;
  vector<int> a,b;
  cin>>n;
  a.resize(n+1);
  b.resize(n);
  for(auto& x:a){
    cin>>x;
  }
  for(auto& x:b){
    cin>>x;
  }
  for(int i=0;i<n;i++){
    if(a[i]>=b[i]){
      sum+=b[i];
      a[i]-=b[i];
      b[i]=0;
    }
    else {
      sum+=a[i];
      b[i]-=a[i];
      a[i]=0;
      if(a[i+1]>=b[i]){
        sum+=b[i];
        a[i+1]-=b[i];
        b[i]=0;
      }
      else{
        sum+=a[i+1];
        a[i+1]=0;
        b[i]-=a[i+1];
      }
    }
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 1024
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let r = line.trim().parse::<i32>().unwrap();
    let line = gets();
    let g = line.trim().parse::<i32>().unwrap();
    println!("{}", 2 * g - r);
}


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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int M, T, P, R;

struct Team {
    Team () {}
    Team (int p) : bads(p), solved(0), score(0){}
    
    VI bads;
    int solved;
    int idx;

    int score;

    bool operator < (const Team &t) const { // greater
        if (solved != t.solved) return solved > t.solved;
        if (score != t.score) return score < t.score;
        return idx > t.idx;
    }

    bool same(const Team &t) {
        return score == t.score && solved == t.solved;
    }
};

vector<Team> teams;

int main(void) {
    while (cin >> M >> T >> P >> R, M) {
        teams.clear();
        teams.resize(T, Team(P));
        for (int i = 0; i < T; i++) {
            teams[i].idx = i + 1;
        }

        for (int i = 0; i < R; i++) {
            int time, ti, pi, judge;
            cin >> time >> ti >> pi >> judge;

            --ti;
            --pi;

            if (judge) { // ?????£?§£
                teams[ti].bads[pi]++;
            } else {    // ??£?§£
                teams[ti].solved++;
                teams[ti].score += time + teams[ti].bads[pi] * 20;
            }
        }

        sort(ALL(teams));

        // output
        for (int i = 0; i < T; i++) {
            cout << teams[i].idx;
            if (i == T - 1) {
                cout << endl;
            } else {
                cout << (teams[i].same(teams[i + 1]) ? "=" : ",");
            }
        }
    }

	return 0;
}

Measured memory_bytes: 1224
import itertools
import collections

n, m = map(int, input().split())

a = [list(sorted(map(int, input().split()))) for i in range(m)]
a.sort()

cnt = 0

#2,...,nの順列を表すイテレータ
for i in itertools.permutations(range(2, n + 1), (n - 1)):
    li = [1] + list(i)
    #順列を経路とみなし、実際に辺が存在するかをcheck.辺の本数がn-1となればよい.
    if sum(list(sorted(edge)) in a for edge in zip(li, li[1:])) == n - 1:
        cnt += 1

print(cnt)


Measured memory_bytes: 3316
n, m = [int(i) for i in input().split()]
a = []
ans = 0
for j in range(n):
  b = [int(i) for i in input().split()]
  del b[0]
  a.extend(b)
for i in range(1,m+1):
  if a.count(i) == n:
    ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

long long gcd(long long a, long long b)
{
    for (;;)
    {
        if (a == 0) return b;
        b %= a;
        if (b == 0) return a;
        a %= b;
    }
}

long long lcm(long long a, long long b)
{
    long long temp = gcd(a, b);

    return temp ? (a / temp * b) : 0;
}


int main() {
    long long a, b;
    cin >> a >> b;
    long long ans = lcm(a, b);
    cout << ans;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for( int i=0;i<N;i++ )
    cin >> A[i];

  int ans = 0;
  while(true)
    {
      sort(A.begin(), A.end());
      int pos=0;
      while(A[pos] == 0)
	pos ++;
      int base = A[pos];
      bool flg = false;
      if(pos >= N-1)
	{
	  ans = base;
	  break;
	}
      for( int i=pos+1;i<N;i++ )
	{
	  if( A[i] != base )
	    {
	      flg = true;
	      A[i] = A[i]%base;
	    }
	}
      if( !flg )
	{
	  ans = base;
	  break;
	}
    }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define FOR(t,i,n) for(t i=(t)0;(i)<(n);(i)++)
template<class T>void printarray(T a,int n){
    FOR(int,i,n) cout << a[i] << " " ;
    cout << endl;
}

main(){
    ios_base::sync_with_stdio(false) ;
    map<int,bool> num;
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i] ;
        if((i+1)&1) num[a[i]] = 1;
    }  
    sort(a,a+n) ;
    int ans=0;
    for(int i=0;i<n;i+=2){
        if( !num.count(a[i])) ans++ ;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int K;
    string s;
    cin >> s;
    cin >> K;
    vector <string> svec;
    for(ll i=0;i<s.size();i++){
      for(int j=1;j<=K&&i+j-1<s.size();j++){
        svec.push_back(s.substr(i,j));
      }
    }
    sort(svec.begin(),svec.end());
    int i=0;
    int j=0;
    string tmp=svec[0];
    while(true){
      if(tmp!=svec[i]){
        j++;
      }
      if(j==K-1){
        cout <<svec[i];
        return 0;
      }
      tmp =svec[i];
      i++;
    }
}


Measured memory_bytes: 1660
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = Integer.parseInt(sc.next());
    int y = Integer.parseInt(sc.next());
    long ans = 0;
    int tmpx = x;
    int tmpy = y;
    if((x % 3 == 0 && y % 3 == 0) || (x % 3 == 1 && y % 3 == 2) || (x % 3 == 2 && y % 3 == 1)) {
      int count = 0;
      while(tmpx > 0 && tmpy > 0) {
        if(tmpx >= tmpy) {
          count++;
          tmpx -= 2;
          tmpy -= 1;
        } else {
          tmpx -= 1;
          tmpy -= 2;
        }
      }
      if(tmpx == 0 && tmpy == 0) ans = nCk((x + y) / 3, count, 1000000007);
    }
    System.out.println(ans);
  }

  public static long nCk(int n, int k, long p) {
    long factorial = 1;
    k = Math.min(k, n - k);
    //k!(mod p)の逆元をmodPowを用いて計算
    for(int i = 2; i <= k; i++) {
      factorial = (factorial * i) % p;
    }
    factorial = modPow(factorial, p-2, p);
    //n(n-1)...(n-k+1) (mod p)の計算
    for(int i = n - k + 1; i <= n; i++) {
      factorial = (factorial * i) % p;
    }
    return factorial;
  }

  public static long modPow(long a, long b, long p) {
    long power = 1;
    while(b > 0) {
      if((1 & b) == 1) power = (power * a) % p;
      a = (a * a) % p;
      b = b >> 1;
    }
    return power;
  }
}


Measured memory_bytes: 23252
let () = Scanf.scanf "%d %d\n" @@ fun n d ->
  let xys = List.init n @@ fun _ -> Scanf.scanf "%d %d\n" @@ fun x y -> x, y in
  Printf.printf "%d\n" @@
  List.length @@
  List.filter (fun (x, y) -> x * x + y * y <= d * d) xys

Measured memory_bytes: 28044
N = int(input())
A = list(map(int,input().split()))
num = [0 for i in range(100001)]
ans = sum(A)
for a in A:
  num[a] += 1
Q = int(input())
for _ in range(Q):
  B, C = map(int, input().split())
  buf = num[B]
  num[B] = 0
  num[C] += buf
  ans += (C-B)*buf
  print(ans)

Measured memory_bytes: 20752
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
const int inf=1001001001; const long long INF=1001001001001001001;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
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 (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int to, from, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};

int n, h, w;
int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n >> h >> w;
  vii a(n), b(n);
  rep(i, 0, n) cin >> a[i] >> b[i];
  int ans = 0;
  rep(i, 0, n) {
    if (a[i] >= h && b[i] >= w) ans++; 
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
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; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
string ans;
if(n<1000){
    cout<<"ABC"<<endl;
}
else{
    cout<<"ABD"<<endl;
}
//system("pause");
return 0;
}

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

int main(void) {
  int n, m;
  priority_queue<long long> a;
  
  cin >> n >> m;
  
  for(int i = 0; i < n; i++) {
    long long temp;
    cin >> temp;
    a.push(temp);
  }
  
  while(m > 0) {
    long long max = a.top();
    a.pop();
    max /= 2;
    m--;
    a.push(max);
  }
  
  long long result = 0;
  for(int i = 0; i < n; i++) {
    result += a.top();
    a.pop();
  }
  
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 1400
S = list(input())
K = int(input())
# S = list("ccccc")
# K = 3
# S = list("aabca")
# K = 2
if S.count(S[0]) == len(S):
    print(len(S) * K // 2)
    exit()

cnt = 0
continuous = 0
chr = S[0]
for i in range(1, len(S)):
    if chr == S[i]:
        cnt += 1
    if chr != S[i] or i == len(S) - 1:
        continuous += (cnt + 1) // 2
        cnt = 0
    chr = S[i]
chr = S[0]
left = 0
idx = 0
while idx < len(S) and S[idx] == chr:
    left += 1
    idx += 1
idx = -1
right = 0
while idx < len(S) and S[idx] == chr:
    right += 1
    idx -= 1
same = right + left
if continuous == 0 and S[0] == S[-1]:
    print(K - 1)
else:
    ans = K * continuous
    if right % 2 == 1 and left % 2 == 1:
        ans += K - 1
    print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)
template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

string s;
int dp[1000005][2];
signed main() {
	cin>>s;
	rep(i,1000005)dp[i][0]=dp[i][1]=inf;
	dp[0][0]=0;
	rep(i,s.size()){
		chmin(dp[i+1][0],min(dp[i][0],dp[i][1])+(s[i]-'0'));
		chmin(dp[i+1][1],dp[i][1]+9-(s[i]-'0'));
		chmin(dp[i+1][1],dp[i][0]+11-(s[i]-'0'));
	}
	cout<<min(dp[s.size()][0],dp[s.size()][1])<<endl;
}


Measured memory_bytes: 17028
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<string> bubble_sort(vector<string> a, int n){
    vector<string> c = a;

    for (int i = 0; i < n; i++){
        for(int j = n - 1; j > i; j--){
            if(c[j][1] < c[j - 1][1]) swap(c[j], c[j - 1]); 
        }
    }

    return c;
}

vector<string> selection_sort(vector<string> a, int n){
    vector<string> c = a;

    int min;
    for (int i = 0; i < n; i++){
        min = i;
        for (int j = i; j < n; j++){
            if (c[j][1] < c[min][1]) min = j;
        }
        swap(c[i], c[min]);
    }

    return c;
}

int main (){
    int n;
    bool is_stable = true;
    cin >> n;
    vector<string> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }

    vector<string> bubble_result = bubble_sort(a, n);
    vector<string> selection_result = selection_sort(a, n);

    for (int i = 0; i < n; i++){
        if (i != 0) cout << " ";
        cout << bubble_result[i];
    }
    cout << endl << "Stable" << endl;

    for (int i = 0; i < n; i++){
        if (i != 0) cout << " ";
        cout << selection_result[i];

        if(bubble_result[i] != selection_result[i]) is_stable = false;
    }
    cout << endl;
    if(is_stable) cout << "Stable" << endl;
    else cout << "Not stable" << endl;

    

    return 0;
}


Measured memory_bytes: 3180
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()

	if N >= 1800:
		print("1")
	elif N >= 1600:
		print("2")
	elif N >= 1400:
		print(3)
	elif N >= 1200:
		print(4)
	elif N >= 1000:
		print("5")
	elif N >= 800:
		print(6)
	elif N >= 600:
		print(7)
	else:
		print(8)

	#print(N)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Measured memory_bytes: 76888
#include<iostream>
using namespace std;
int main()
{
 int k;
 cin>>k;
 int a,b,i,f=0;
 cin>>a>>b;
 for(i=a;i<=b;i++)
  if(i%k==0)
  {
    f=1;
    break;
  }

 if(f==1)
 cout<<"OK"<<endl;
 else
 cout<<"NG"<<endl;
 return 0;
}


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

int n, k;
int v[50];

void take_input()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n >> k;
    for (int i = 0; i != n; ++i)
        cin >> v[i];
}

int simulate(int l, int r)
{
    if (l + r > n)
        return 0;
    
    vector<int> tmp;
    for (int i = 0; i != l; ++i)
        tmp.push_back(v[i]);
    for (int i = 0; i != r; ++i)
        tmp.push_back(v[n - i - 1]);
    sort(tmp.begin(), tmp.end());
    int i = 0;
    while (i != tmp.size() && tmp[i] < 0 && i != k - l - r)
        ++i;
    
    int ret = 0;
    while (i != tmp.size())
        ret += tmp[i++];
    
    return ret;
}

void solve()
{
    int ans = 0;
    
    for (int i = 0; i <= k; ++i)
        for (int j = 0; j + i <= k; ++j)
            ans = max(ans, simulate(i, j));
    
    cout << ans << '\n';
}

int main()
{
    take_input();
    solve();
}

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

#define llint long long int

using namespace std;

llint mod_pow(llint a, llint n, llint p){
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        llint d = mod_pow(a, n / 2, p);

        return (d * d) % p;
    } else {
        return (a * mod_pow(a, n - 1, p)) % p;
    }
}
llint mod_inv(llint a, llint p){
    return mod_pow(a, p - 2, p);
}
int main(){
    int p;

    cin >> p;

    vector<int> a(p);

    for(int i = 0; i < p; i ++){
        cin >> a[i];
    }
    vector<int> b(p, 0);

    vector<int> inv(p), comb(p);

    for(int i = 1; i < p; i ++){
        inv[i] = (int) mod_inv(i, p);
    }
    for(int i = 0; i < p; i ++){
        if(i == 0){
            comb[i] = 1;
        }else{
            comb[i] = (comb[i - 1] * (p - i)) % p;
            comb[i] = (comb[i] * inv[i]) % p;
        }
    }
    // for(int i = 0; i < p; i ++){
    //     cout << comb[i] << endl;
    // }
    for(int i = 0; i < p; i ++){
        int temp = 1;

        for(int j = 0; j < p; j ++){
            b[p - j - 1] = (b[p - j - 1] + p - a[i] * temp) % p;
            temp = (temp * (p - i)) % p;
        }
    }
    for(int i = 0; i < p; i ++){
        b[i] = (b[i] * comb[p - i - 1]) % p;
    }
    for(int i = 0; i < p; i ++){
        b[0] = (b[0] + a[i]) % p;
    }
    for(int i = 0; i < p; i ++){
        cout << b[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256