akhauriyash/Code-Regression huggingface dataset:
//
// Created by ?????°?????? on 2016/04/14.
//


#include <iostream>
#include <algorithm>
using namespace std;

const int MAX = 1000;
const int VMAX = 100000;

int n,A[MAX],s;
int B[MAX],T[VMAX +1];

int solve(){
    int ans = 0;
    bool V[MAX];
    for (int i = 0; i < n ; ++i) {
        B[i] = A[i];
        V[i] = false;
    }
    sort (B,B+n);
    for (int i = 0; i < n ; ++i) T[B[i]] = i;
    for (int i = 0; i < n ; ++i) {
        if(V[i]) continue;
        int cur = i, S = 0, m = VMAX,an =0;
        while(1){
            V[cur] = true;
            an ++;
            int v = A[cur];
            m = min (m,v);
            S += v;
            cur = T[v];
            if(V[cur]) break;
        }
        ans += min(S + (an -2) *m ,m + S + (an + 1)*s);
    }
    return ans;
}

int main (){
    cin >> n;
    s = VMAX;
    for (int i = 0; i < n ; ++i) {
        cin >> A[i];
        s = min(s,A[i]);
    }
    int ans = solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	string ans = "Christmas";
	if( n != 25 ) {
		for(int i = 0; i < 25 - n; ++i) {
			ans += " Eve";
		}	
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
Var b:Array[0 .. 200000] of Longint;
    a,n,i:Longint;
Begin
    Readln(n);
    For i:=2 to n do begin
        Read(a);
        Inc(b[a]);
    End;
    For i:=1 to n do writeln(b[i]);
End.

Measured memory_bytes: 1384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int d1[4] = { 1,0,-1,0 };
int d2[4] = { 0,1,0,-1 };

int main() {
	while (true) {
		int n; cin >> n;
		if (n == 0)break;

		vector<VI> a(29, VI(29));

		rep(i, n) {
			int X, Y;
			cin >> X >> Y;
			a[X][Y] = 1;
		}

		int x = 10, y = 10;
		int m; cin >> m;
		rep(i, m) {
			char d; int l, D;
			cin >> d >> l;
			if (d == 'N')D = 1;
			if (d == 'E')D = 0;
			if (d == 'S')D = 3;
			if (d == 'W')D = 2;
			
			rep(j, l) {
				x += d1[D];
				y += d2[D];
				a[x][y] = 0;
			}
		}

		bool flag = true;
		rep(i, 20)rep(j, 20) {
			if (a[i][j] == 1)flag = false;
		}
		puts(flag ? "Yes" : "No");
	}
}


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

typedef long long ll;

int main()
{
    int N, K;
    cin >> N >> K;
    if(K > (N - 1) * (N - 2) / 2){
        cout << "-1" << endl;
        return 0;
    }
    vector<vector<int>> edges(N + 1, vector<int>(0));
    for(int i = 2; i <= N; i++)
    {
        edges.at(1).push_back(i);
    }
    int oneDistanceEdges = (N - 1) * (N - 2) / 2 - K;
    int M = N - 1 + oneDistanceEdges;
    for(int i = 2; i <= N; i++){
        for(int j = i + 1; j <= N; j++){
            if(oneDistanceEdges == 0){
                break;
            }
            edges.at(i).push_back(j);
            oneDistanceEdges--;
        }
        if(oneDistanceEdges == 0){
            break;
        }
    }
    cout << M << endl;
    for(int i = 1; i <= N; i++)
    {
        for(int node : edges.at(i)){
            cout << i << " " << node << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(i) cout<<i<<endl;
const int mod=1e9 +7;
int main(){
IOS;
lli n,a,b;
cin>>n>>a>>b;
lli ans=min(n*a,b);
cout<<ans<<endl;
}


Measured memory_bytes: 256
fun main() {
    val n = readLine()!!.toInt()

    val aList = IntArray(n)
    val bList = IntArray(n)
    val cList = IntArray(n)
    for (i in 0 until n) {
        val (a, b, c) = readLine()!!.split(" ").map { it.toInt() }
        aList[i] = a
        bList[i] = b
        cList[i] = c
    }

    val dp = Array(n) { IntArray(3) }
    dp[0][0] = aList[0]
    dp[0][1] = bList[0]
    dp[0][2] = cList[0]

    for (i in 1 until n) {
        dp[i][0] = dp[i - 1][1].coerceAtLeast(dp[i - 1][2]) + aList[i]
        dp[i][1] = dp[i - 1][0].coerceAtLeast(dp[i - 1][2]) + bList[i]
        dp[i][2] = dp[i - 1][0].coerceAtLeast(dp[i - 1][1]) + cList[i]
    }

    var answer = dp[n - 1][0].coerceAtLeast(dp[n - 1][1]).coerceAtLeast(dp[n - 1][2])

    print(answer)
}



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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    vector<string> text;
    string W, T;
    cin >> W;

    transform(ALL(W), W.begin(), ::tolower);

    while (cin >> T)
    {
        if (T == "END_OF_TEXT")
            break;
        transform(ALL(T), T.begin(), ::tolower);
        text.push_back(T);
    }
    int cnt = 0;
    rep(i, text.size())
    {
        if (text[i] == W)
            cnt++;
    }

    OP(cnt)

    return 0;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int mod = 1000000007;
typedef long long LL;
int n, m, u[N], v[N], du[N], a[N];
set<int> G[N];
set<pair<int, int>> s;
pair<int, int> ans[N];
int main() {
#ifdef TEST
	freopen("input.txt", "r", stdin);
#endif
	scanf("%d%d", &n, &m);
	for (int i = 0, u, v; i < m; ++i) {
		scanf("%d%d", &u, &v);
		u--;
		v--;
		G[u].insert(v);
		G[v].insert(u);
		du[u]++;
		du[v]++;
	}
	for (int i = 0; i < n; ++i) {
		s.insert(make_pair(du[i], i));
	}
	int id = 0;
	for (int T = 0; T + 1 < n; ++T) {
		auto x = s.begin()->second;
		s.erase(make_pair(du[x], x));
		if (a[x]) {
			int y = *G[x].begin();
			G[y].erase(x);
			s.erase(make_pair(du[y], y));
			du[y]--;
			s.insert(make_pair(du[y], y));
			ans[id++] = make_pair(x, y);
			G[x].erase(G[x].begin());
			a[x] = 0;
		}
		for (auto &y : G[x]) {
			G[y].erase(x);
			s.erase(make_pair(du[y], y));
			du[y]--;
			a[y] ^= 1;
			ans[id++] = make_pair(y, x);
			s.insert(make_pair(du[y], y));
		}
	}
	for (int i = 0; i < n; ++i) {
		if (a[i]) {
			printf("-1\n");
			return 0;
		}
	}
	for (int i = 0; i < id; ++i) {
		printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
	}
	return 0;
}

Measured memory_bytes: 21760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a , b;
  cin >> a >> b;
  
  int c = a + b;
  if(c % 2 == 0 ){
    cout << c / 2 << endl;
  }
  else{
    cout << c / 2 + 1 << endl;
  }
 
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
int par[100009], sz[100009]; long long cur, ans[100009];
int root(int x) {
	if (x == par[x]) return x;
	return par[x] = root(par[x]);
}
void unite(int x, int y) {
	x = root(x);
	y = root(y);
	cur -= 1LL * sz[x] * sz[y];
	sz[x] += sz[y];
	sz[y] = 0;
	par[y] = x;
}
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; ++i) {
		cin >> A[i] >> B[i];
		--A[i], --B[i];
	}
	for (int i = 0; i < N; ++i) par[i] = i, sz[i] = 1;
	cur = 1LL * N * (N - 1) / 2;
	for (int i = M - 1; i >= 0; --i) {
		ans[i] = cur;
		if (root(A[i]) != root(B[i])) {
			unite(A[i], B[i]);
		}
	}
	for (int i = 0; i < M; ++i) {
		cout << ans[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	unsigned long n, a[100];
	unsigned long i, j;
	unsigned long m = 1000;

	cin >> n;
	cin >> a[0];
	for (i = 1; i < n; i++) {
		cin >> a[i];
		if (a[i] > a[i - 1]) {
			unsigned long kabu = m / a[i - 1];
			m = m + kabu * a[i];
			m = m - kabu * a[i - 1];
		}
	}

	cout << m << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int N = 2100;
const int P = 924844033;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)

int n,m;

inline int pow_mod(int x,int k){
   int res = 1,base = x;
   while(k){
      if(k&1)res = 1LL*res*base%P;
      k >>= 1; base = 1LL*base*base%P;
   }
   return res;
}

int fact[N],inv[N];
void init(){
   fact[0] = inv[0] = 1;
   fr(i,1,N-1){
      fact[i] = 1LL*fact[i-1]*i%P;
   }
   inv[N-1] = pow_mod(fact[N-1],P-2);
   nfr(i,N-2,1)inv[i] = 1LL*inv[i+1]*(i+1)%P;
}

inline int c(int n,int m){
   return 1LL*fact[n]*inv[(n-m)]%P*inv[m]%P;
}

int f[N][N];

int g[N][N][4];

inline int add(int &x,int y){
   x += y; if(x >= P)x -= P;
}

int main(){
   int n,m;
   scanf("%d%d",&n,&m);
   init();

   int totsiz = 0;
   f[1][0] = 1;
   fr(i,1,m){
      fr(j,0,n/m+1){
         fr(k,0,n/m+1)memset(g[j][k],0,sizeof g[j][k]);
      }

      g[0][0][1] = 1;
      int lst;
      for(int j = 0;j*m+i <= n; ++j){
         ++totsiz;
         lst = j;
         int w = j*m+i;
         fr(q,0,j){
            fr(z,0,3){
               if(g[j][q][z]){
                  if((j+1)*m+i <= n)add(g[j+1][q+1][(z>>1)|2],g[j][q][z]);
                  if((z&1) == 0)add(g[j+1][q+1][z>>1],g[j][q][z]);
                  add(g[j+1][q][z>>1],g[j][q][z]);
               }
            }
         }
      }

      fr(j,0,totsiz-(lst+1)){
         fr(c,0,lst+1){
            int w = 0;
            fr(z,0,3)add(w,g[lst+1][c][z]);
            add(f[i+1][j+c],1LL*f[i][j]*w%P);
         }
      }
   }

   int ans = 0;
   fr(i,0,n){
      if(i%2 == 0)add(ans,1LL*f[m+1][i]*fact[n-i]%P);
      else add(ans,P-1LL*f[m+1][i]*fact[n-i]%P);
   }
   printf("%d\n",ans);
   return 0;
}


Measured memory_bytes: 69888
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k ; cin>>n>>k;
    vector <int> cost(n);
    for(int i=0;i<n;i++){
        cin>>cost[i];
    }
    sort(cost.begin(),cost.end());
    reverse(cost.begin(),cost.end());
    int ans =0 ;
    for(int i=0;i<k;i++){
        ans+=cost[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,ary[N][N];
int color[N],pary[N],eary[N],time;

void dfs(int i){
  int j;
  color[i]=GRAY;
  pary[i]=++time;
  for(j=0;j<n;j++){
    if(ary[i][j]==0)continue;
    if(color[j]==WHITE){
      dfs(j);
    }
  }
  color[i]=BLACK;
  eary[i]=++time;
}

void dfs_init(){
  int i;
  for(i=0;i<n;i++){
    color[i]=WHITE;    
  }
  time=0;
  for(i=0;i<n;i++){
    if(color[i]==WHITE)dfs(i);
  }
}

int main(){
  int i,j,k,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      ary[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      ary[u][v]=1;
    }
  }
  dfs_init();
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,pary[i],eary[i]);
  }
  return 0;
}
  



Measured memory_bytes: 2112
import heapq as h;I=lambda:list(map(int,input().split()));n,k=I();z=[i*2+1for i in range(n)];s=sorted([I()for _ in[0]*n],key=lambda x:-x[1]);q=[];v=A=0;l=[0]*-~n
for a in s[:k]:
 if l[a[0]]:h.heappush(q,a[1])
 else:A+=z[v];v+=1
 l[a[0]]=1;A+=a[1]
T=A
for a in s[k:]:
 if not q:break
 if l[a[0]]^1:l[a[0]]=1;t=h.heappop(q);T=T-t+a[1]+z[v];v+=1;A=max(A,T)
print(A)

Measured memory_bytes: 36960
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class CIncrementalScoring {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int d; cin >> d;
      vector<int> c(26);
      rep(i, 26) {
        cin >> c[i];
      }
      vector<vector<ll>> s(d, vector<ll>(26));
      rep(i, d) rep(j, 26) {
          cin >> s[i][j];
        }
      ll ret = 0;
      set<int> last[26];
      rep(i, 26) {
        last[i].insert(0);
        last[i].insert(d+1);
      }
      vector<ll> last2(26);
      vector<int> contests(d);
      rep(i, d) {
        int t; cin >> t;
        t--;
        contests[i] = t;
        ret += s[i][t];
        last[t].insert(i+1);
        last2[t] = i+1;
        rep(j, 26) {
          ret -= c[j]*(i+1-last2[j]);
        }
      }

      int m; cin >> m;
      while(m--) {
        int day, q; cin >> day >> q;
        q--;
        day--;
        int before = contests[day];
        contests[day] = q;
        ret += s[day][q];
        ret -= s[day][before];

        day++;
        last[before].erase(day);
        auto it = last[before].upper_bound(day);
        int right = (*it);
        it--;
        int left = (*it);
        ret -= c[before]*(day-left)*(right-day);

        it = last[q].upper_bound(day);
        right = (*it);
        it--;
        left = (*it);
        ret += c[q]*(day-left)*(right-day);

        last[q].insert(day);

        cout << ret << '\n';
      }

    }
};

signed main() {
  CIncrementalScoring solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3764
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
lastday=[0 for j in range(26)]
points=[0 for i in range(D)]
t=[0 for i in range(D)]

# first day
lastday=[lastday[i]+1 for i in range(26)]
firstday=s[0].index(max(s[0]))
lastday[firstday]=0
t[0]=firstday+1

for days in range(1,D):
    temp=[s[days][i]-c[i]*lastday[i] for i in range(26)]
    today=temp.index(min(temp))
    lastday=[lastday[i]+1 for i in range(26)]
    lastday[today]=0
    t[days]=today+1

for ts in t:
    print(ts)

Measured memory_bytes: 9516
#include<bits/stdc++.h>
#define GO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
const int Max = 3e5 + 5;
const int Mod = 1e9 + 7;

int main()
{
	GO;
	string a;
	cin >> a;
	cout << string(a.size() ,'x') << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int n;
long long a[500],q[500];
long long dp[500][500];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		q[i]=q[i-1]+a[i];
	}
	memset(dp,63,sizeof(dp));
	for(int i=1;i<=n;i++){
		dp[i][i]=0;
		dp[0][i]=0;
	}
	long long S;
	for(int l=1;l<=n-1;l++){
		for(int i=1;i+l<=n;i++){
			int j=i+l;
			S=q[j]-q[i-1];
			for(int k=i;k<j;k++){
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+S);
			}
		}
	}
	cout<<dp[1][n]<<endl;
	return 0;
}


Measured memory_bytes: 2176
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import math

a, b, c = map(int, input().split())
if c - a - b < 0:
    print("No")
    exit()
if a * b * 4 < (c - a - b)**2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <map>
#include <vector>
#include <iostream>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N[2];
const int MOD = 1000000007;

int main() {
  while (cin >> N[0] >> N[1]) {
	sort(N, N+2);
	if (N[1] - N[0] > 1) {
	  cout << "0" << endl;
	  continue;
	}
	long long res = 1;
	if (N[0] == N[1]) res = 2;
	for (long long i = 1; i <= N[0]; ++i) res *= i, res %= MOD;
	for (long long i = 1; i <= N[1]; ++i) res *= i, res %= MOD;
	cout << res << endl;
  }
}
















Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
B=[0]*n
for i in range(n):
    now=(n-i)*2
    cnt=A[n-i-1]
    while now<=n:
        cnt+=B[now-1]
        now+=n-i
    if cnt%2==1:
        B[n-i-1]=1
print(sum(B))
for i in range(n):
    if B[i]:
        print(i+1,end=" ")

Measured memory_bytes: 67036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int n;

void solve(int s, char t, string u){
    if(s==n){
        cout << u << endl;
    }else{
        for(char i='a'; i<=t; i++){
            solve(s+1, t, u+i);
        }
        if(s > 0){
            solve(s+1, t+1, u+(char)(t+1));
        }
    }

}

int main(void){
    cin >> n;
    solve(0,'a', "");
}

Measured memory_bytes: 1536
#include<iostream>
#include<cmath>
#include<string.h>
using namespace std;

int memo[1001][1001]={0};

int f(int n,int m){
	if(n==1){
		return 0;
	}
	else if(memo[n][m]!=0){
		return memo[n][m];
	}
	else{
		return memo[n][m]=(f(n-1,m)+m)%n;
	}
}

int main(){
	int n,m,ans;	
	while(cin>>n>>m,n&&m){
		ans=f(n,m);
		ans++;
		cout<<ans<<endl;
		memset(memo,0,sizeof(memo));
	}
}

Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
int N, M, Q;
signed main() {
    cin >> N >> M >> Q;
    int a[Q], b[Q], c[Q], d[Q];
    rep(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    vector<int> V;
    rep(i, M - 1) V.push_back(0);
    rep(i, N) V.push_back(1);
    sort(all(V));
    int ans = 0;
    do {
        vector<int> A(N);
        int now = 0;
        int s = 1;
        rep(i, N + M - 1) {
            if(V[i] == 0)
                s++;
            else {
                A[now] = s;
                now++;
            }
        }
        //rep(i, N) cout << A[i] << ' ';
        //cout << endl;
        int sum = 0;
        rep(i, Q) {
            if(A[b[i]] - A[a[i]] == c[i]) sum += d[i];
        }
        chmax(ans, sum);
    } while(next_permutation(all(V)));
    cout << ans << endl;
}


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

int main() {
  int N, K, x, a;
  cin >> N >> K;
  a = 0;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x < K - x) {
      a += 2 * x;
    }
    else {
      a += 2 * (K - x);
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 764
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);

		List<String> list = new ArrayList<String>();
        
		while (true) {
			String num = scan.next();
			
			if (num.equals("0")) {
				break;
			}
			
			list.add(num);
		}

		for (String s : list) {
			int sum = 0;
			for (int i = 0; i < s.length(); i++) {
				sum += Integer.parseInt(s.substring(i, i+1));
			}
			System.out.println(sum);
		}    	
	}
}

Measured memory_bytes: 17440
import heapq


class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign


def main():
    N, M = map(int, input().split())
    an = list(map(int, input().split()))

    q = Heapq(an, True)

    for _ in range(M):
        value = q.pop() / 2.0
        q.push(value)

    res = sum(list(map(lambda x: int(x * -1), q.hq)))

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15176
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

pint a[105];
int ans[105];
int main(){
    int n,w,d,p,s;
    while(cin>>n>>w>>d,n|w|d){
        a[0]={w,d};
        int cnt=1;
        rep(i,n){
            cin>>p>>s;
            --p;
            pint c=a[p];
            s%=c.first+c.second;
            if(s<c.first){
                a[cnt]={min(s,c.first-s),c.second};
                ++cnt;
                a[cnt]={max(s,c.first-s),c.second};
            }
            else{
                s-=c.first;
                a[cnt]={c.first,min(s,c.second-s)};
                ++cnt;
                a[cnt]={c.first,max(s,c.second-s)};
            }
            FOR(i,p,cnt) a[i]=a[i+1];
        }
        rep(i,cnt) ans[i]=a[i].first*a[i].second;
        sort(ans,ans+cnt);
        rep(i,cnt) cout<<ans[i]<<(i==cnt-1?"":" ");
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 2984
n = gets.strip.to_i
abc = (n-1).times.map { gets.strip.split.map(&:to_i) }
q, k = gets.strip.split.map(&:to_i)
xy = readlines.map {|line| line.strip.split.map(&:to_i) }

graph = Array.new(n+1) { [] }
abc.each do |s, g, cost|
  graph[s] << [g, cost]
  graph[g] << [s, cost]  
end

#p graph

def tree_distance_from(start, graph)
  distance = Array.new(graph.length, -1)

  q = [[start, 0]]

  until q.empty? do
    current, current_cost = q.shift
    distance[current] = current_cost
    graph[current].each do |to, cost|
      q << [to, current_cost + cost] if distance[to] == -1
    end
  end

  distance
end

distance_from_k = tree_distance_from(k, graph)

xy.each do|x, y|
  p distance_from_k[x]+distance_from_k[y]
end



Measured memory_bytes: 58972
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll n,a,b;cin >> n >> a >>b;
    vl v(n);
    rep(i,n)cin >>v[i];
    ll ans=0;
    rep(i,n-1){
        ans+=min(b,a*(v[i+1]-v[i]));
    }
    cout << ans <<endl;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import heapq

[N, M] = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

# ヒープキューでpopしたときに最大値を取得できるよう、全要素に-1を掛ける
minus_A = [i * -1 for i in A]

# Aをヒープキューリストに変換
heapq.heapify(minus_A)

# 最大価格の商品をM回割引していく
for i in range(M):
    val = heapq.heappop(minus_A)
    val /= 2
    val = int(val)
    heapq.heappush(minus_A, val)

# 割引券適用後の価格をまとめる
total = sum(minus_A)
print(total * -1)

Measured memory_bytes: 14180
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.nextLine().toCharArray();
		for (int i = 0; i<arr.length; i=i+2)
			System.out.print(arr[i]);
	}
}


Measured memory_bytes: 47840
def dictionary():
    n = int(input())
    dic = {}
    for i in range(n):
        line = input().split()
        order, key = line[0], line[1]
        if order == "insert":
            dic[key] = i
        else:
            if key in dic:
                print("yes")
            else:
                print("no")

if __name__ == "__main__":
    dictionary()


Measured memory_bytes: 41820
#include<cstdio>
#include<cstring>
using namespace std;
char ch[110];
long long n[110],len;
long long k;
long long ans;
long long f[110][4][2];
long long dfs(long long now,long long last,bool check)
{
	if(last==k+1)
		return 0;
	if(now==len+1)
		return last==k;
	if(f[now][last][check]!=-1)
		return f[now][last][check];
	long long ret=0,p=check? n[now]:9;
	for(long long i=0;i<=p;i++)
		ret+=dfs(now+1,last+(i!=0),check&&(i==p));
	return f[now][last][check]=ret;
}
int main()
{
	scanf("%s",ch+1);
	scanf("%lld",&k);
	memset(f,-1,sizeof(f));
	len=strlen(ch+1);
	for(long long i=1;i<=len;i++)
		n[i]=ch[i]-'0';
	ans=dfs(1,0,1);
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int m,d,i,sum=0,x;
		int manth[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
		while(true){
			m=s.nextInt();
			d=s.nextInt();
			if(m==0 && d==0) break;
			
			for(i=1;i<m;i++){
				sum+=manth[i];
			}
			sum=sum+(d-1);
			x=sum%7;
			if(x==0)
				System.out.println("Thursday");
			if(x==1)
				System.out.println("Friday");
			if(x==2)
				System.out.println("Saturday");
			if(x==3)
				System.out.println("Sunday");
			if(x==4)
				System.out.println("Monday");
			if(x==5)
				System.out.println("Tuesday");
			if(x==6)
				System.out.println("Wednesday");
			sum=0;
		}
	}

}

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

typedef long long ll;

const int kN = 1e5 + 5;
const int kInf = 0x3f3f3f3f;

int p[kN], q[kN], r[kN]; ll ans = 0;

int main() {
	int x, y, a, b, c;
	scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
	p[0] = q[0] = kInf;
	for(int i = 1; i <= a; ++i) scanf("%d", p + i);
	for(int i = 1; i <= b; ++i) scanf("%d", q + i);
	for(int i = 1; i <= c; ++i) scanf("%d", r + i);
	std::sort(p + 1, p + a + 1, [](int z1, int z2) { return z1 > z2; });
	std::sort(q + 1, q + b + 1, [](int z1, int z2) { return z1 > z2; });
	std::sort(r + 1, r + c + 1, [](int z1, int z2) { return z1 > z2; });
	for(int i = 1; i <= x; ++i) ans += p[i];
	for(int i = 1; i <= y; ++i) ans += q[i];
	for(int i = 1; i <= c; ++i) {
		if(p[x] > q[y] && r[i] > q[y]) ans += r[i] - q[y], --y;
		else if(p[x] <= q[y] && r[i] > p[x]) ans += r[i] - p[x], --x;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1408
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    int n = nxt(), k = nxt();
    vector<double> a(n);
    REP(i, n) a[i] = nxt();
    REP(i, n) a[i] = (a[i]+1)/2;
    double best = 0, temp = 0;
    REP(i, k) temp += a[i];
    best = temp;
    for(int i = k; i < n; i++){
        temp += a[i];
        temp -= a[i-k];
        best = max(best, temp);
    }
    printf("%.7f", best);
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n, mn = 1000000, mx, cnt;
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int main()
{
	n = read();
	for (int i = 1; i <= n; i++)
	{
		int num = read();
		if (num < mn)mn = num, cnt = 1;
		else if (num == mn)cnt++;
		mx = max(mx, num);
	}
	if (mx - mn > 1)
	{
		cout << "No" << endl;
		return 0;
	}
	if (mx == mn)
	{
		if (mx == n - 1)
			cout << "Yes" << endl;
		else if (2 * mx <= n)
			cout << "Yes" << endl;
		else cout << "No" << endl;
		return 0;
	}
	if (mn >= cnt && 2 * (mx - cnt) <= n - cnt)
		cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<map>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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 T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1000000000 + 7, INF = 1e18;

lint N;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N;
	cout << "ABC" << N << endl;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  if (A <= C && C <= B) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll a;
  cin >> a;
  cout << a*a*a+a*a+a << "\n";
  return 0;
}


Measured memory_bytes: 3644
n = gets.chomp.split(' ').map(&:to_i)
if n[1] == 0 
    puts n[0]
    exit
end
i = gets.chomp.split(' ').map(&:to_i)
 
 
 
arr = Array.new(100,0)
i.each{|t|
    arr[t-1]+=1
}
ans = 101
kotae = 101
1.times{|t|
    t -=1
        if (n[0]-(t+1)).abs < ans
            ans = (n[0]-(t+1)).abs
            kotae = t+1
        end
}

arr.each_with_index{|item,t|
    if item == 0
        if (n[0]-(t+1)).abs < ans
            ans = (n[0]-(t+1)).abs
            kotae = t+1
        end
    end
}
1.times{|t|
    t = 100
        if (n[0]-(t+1)).abs < ans
            ans = (n[0]-(t+1)).abs
            kotae = t+1
        end
}

puts kotae

Measured memory_bytes: 14316
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		long A[] = new long[N];
		for(int i=0;i<N;i++){
			A[i] = scan.nextLong();
		}

		long res = 0;
		long min = 0;

		for(int i=0;i<N;i++){
			if(i==0){
				res += A[i]-1;
				min = 1;
				continue;
			}
			if(min+1==A[i]){
				min = A[i];
			}else if(min+1<A[i]){
				res += (A[i]-1)/(min+1);
			}
		}
		System.out.println(res);
	}

}

Measured memory_bytes: 34176
N=int(input()) 
a = list(map(int, input().split()))
sum=0
a.sort()
a.reverse()
if(N>2 and N%2 == 0):
  for i in range(0,N-1,2):
    sum=sum+a[i]-a[i+1]
if(N>2 and N%2 != 0):
  for i in range(0,N-1,2):
    sum=sum+a[i]-a[i+1]
  sum=sum+a[N-1]
elif(N==1):
  sum=a[0]
elif(N==2):
  sum=a[0]-a[1]
print(sum)

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

void solve()
{
    char a, b;
    cin >> a >> b;
    if (a == 'H' && b == 'H')
        cout << "H" << endl;
    else if (a == 'D' && b == 'D')
        cout << "H" << endl;
    else
        cout << "D" << endl;
}

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

Measured memory_bytes: 3612
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>
using namespace std;


int main(){

    int a,p;
    cin>>a>>p;

    cout<<(3*a+p)/2;
    //cin>>a>>b>>x;
    //scanf("%d%s%d",&i,&x,&j);


       // printf("%d",i+j);
       //cout<<i+j<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main (){
  long long A,V,B,W,T;
  cin>>A>>V>>B>>W>>T;
  long long dis;
  dis=abs(A-B);
  if(V-W>0){
    if((V-W)*T>=dis){
      cout<<"YES";
    }
    else{
      cout<<"NO";
    }
  }
  else{
    cout<<"NO";
  }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int n,m;
int dp[305][305][305];
int he[100005],to[100005],ne[100005],cost[100005],e;
void add(int x,int y,int z){
     to[++e]=y;
	 ne[e]=he[x];
	 he[x]=e;
	 cost[e]=z;
}
const int mod=1e9+7;
int main () {
#ifndef ONLINE_JUDGE
//file("AT2567");
#endif
     n=read();
	 m=read();
     F(i,1,m){
	     int x=read(),y=read(),z=read();
		 if(y-x+1<z){
		    puts("0");
			return 0;
		 }
       add(y,x,z);
	 } 
	 dp[1][0][0]=1;
	 F(i,1,n-1){
	   F(j,0,i){
	      F(k,j,i){
		     if(dp[i][j][k]){
			    if(j||k){
				    dp[i+1][k][i]=(dp[i+1][k][i]+dp[i][j][k])%mod;
					dp[i+1][j][i]=(dp[i+1][j][i]+dp[i][j][k])%mod;
				}
				else dp[i+1][0][i]=(dp[i+1][0][i]+dp[i][j][k])%mod;
					dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k])%mod;
				
			 }
		  }
	   }
	   for(int u=he[i+1];u;u=ne[u]){
	      int v=to[u];
		  F(j,0,i){
		    F(k,j,i){
			   int r=1;
			   if(j>=v)r++;
			   if(k>=v)r++;
			   if(r!=cost[u])dp[i+1][j][k]=0;
			}
		  }
	   }
	 }
	 int ans=0;
	 F(j,0,n){
	    F(k,j,n){
		     int r=1;
            if(j)r++;
            if(k)r++;
            if (r==1)(ans+=1ll*dp[n][j][k]*3%mod)%=mod;
            else (ans+=1ll*dp[n][j][k]*6%mod)%=mod;
		}
	 }
	 printf("%d\n",(ans+mod)%mod);
    return 0;
}

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

int main(){

  cin.tie(0); //cin高速化
  ios::sync_with_stdio(false); //cin高速化
  
  int n;
  cin >> n;
  if(n<=999){
    cout << "ABC" << endl;
  }else{
    cout << "ABD" << endl;
  }
  return 0;
}
    

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	Scanner sc;
	
	void solve(int n){
		int[][] square=new int[n][n];
		for(int i=0;i<n;++i)Arrays.fill(square[i],0);
		int i=n/2+1,j=n/2,k=1;
		
		while(k<=n*n){
			if(j>=n){j=0;}
			else if(j<0){j=n-1;}
			
			if(i>=n){i=0;}
			if(square[i][j]!=0){++i;--j;continue;}
			square[i++][j++]=k++;
		}
		for(int r=0;r<n;++r){
			for(int c=0;c<n;++c){
				System.out.format("%4d",square[r][c]);
			}
			System.out.println();
		}
	}
	
	void io(){
		int n;
		sc=new Scanner(System.in);
		while((n=sc.nextInt())!=0){
			solve(n);
		}
	}

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

}

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

ll gcd(ll x,ll y){
    if(x%y==0){
        return y;
    }else{
        return(gcd(y,x%y));
    }
}
bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; ll(i) <= ll(sqrtNum); i += 2)
    {
        if (num % ll(i) == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

vector<ll> divi(ll x){
    vector<ll> d;
    for(int i = 1;ll(i)*ll(i)<=x;i++){
        if(x%ll(i)==0) {
            d.push_back(i);

            if(i != x/ll(i)) d.push_back(x/ll(i));
        }
    }
    sort(d.begin(),d.end());
    return d;
}

int main(){
    ll a,b;
    cin >> a >> b;
    ll x = gcd(a,b);
    //cout << x << endl;
    vector<ll> d = divi(x);
    int ans = 0;
    
    for(auto a:d){
        if(IsPrime(a)) ans++;
    }
    
   cout << ans + 1 << endl;

}

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	string s,t;
	cin >> n >> s >> t;
	for(int i = 0;i < 2*n; ++i){
		if(i&1){
			cout << t[i/2];	
		}
		else{
			cout << s[i/2];	
		}
	}
	cout << '\n';
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
    
      	Scanner sc = new Scanner(System.in);
      	int N = Integer.parseInt(sc.nextLine());
      	String[] strA = sc.nextLine().split("\\s");
      	String[] strB = sc.nextLine().split("\\s");
      	String[] strC = sc.nextLine().split("\\s");
      	
      	int[] A = new int[N];
      	int[] B = new int[N];
      	int[] C = new int[N-1];
       	
      	for(int i = 0; i < N; i++){
      	    A[i] = Integer.parseInt(strA[i]);
      	    B[i] = Integer.parseInt(strB[i]);
      	    if(i != N-1) C[i] = Integer.parseInt(strC[i]);
      	}
      	
      	int total = Arrays.stream(B).sum();
      	
      	for(int i = 0; i < N; i++){
      	    if( (i > 0) && (A[i-1] + 1 == A[i]) ){
      	        total += C[A[i-1] -1];
      	    }
      	}
      	
      	System.out.println(total);
      	
      	
    }
}

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

int n,m;
int l[100005];
int r[100005];
int cl,cr;

int main(){

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

    cin>>n>>m;
    cl=1;cr=n;
    for(int i=1;i<=m;i++){
        cin>>l[i]>>r[i];
        cl=max(cl,l[i]);
        cr=min(cr,r[i]);
    }
    cout<<max(cr-cl+1,0)<<endl;

    return 0;
}

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

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        // long N = Long.parseLong(sc.next());
        String N = sc.next();
        int all9 = 0;
        for (int i = N.length() - 1; i > 0; i--) {
            if (N.charAt(i) != '9') {
                all9 = 1;
                break;
            }
        }

        int ans = 0;
        for (int i = 0; i < N.length(); i++) {
            if (i == 0) {
                ans += (Integer.parseInt(N.substring(0, 1)) - all9);
            } else {
                ans += 9;
            }
        }
        out.printf("%d\n", ans);
        out.flush();
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    if(n < 1200) cout << "ABC" << endl;
    else if(n < 2800) cout << "ARC" << endl;
    else {
        cout << "AGC" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')

s = input()
n = int(input())

if s[0] != s[-1]:
    g = gb(list(s))
    res = 0
    for k, v in g:
        a = len(list(v))
        res += a // 2
    print(res * n)
else:
    l = []
    g = gb(list(s))
    for k, v in g:
        a = len(list(v))
        l.append(a)
    if len(l) == 1:
        print((l[0] * n) // 2)
    else:
        rst = 0
        for i in range(1, len(l) - 1):
            rst += (l[i]) // 2
        sm = (l[0] + l[-1]) // 2
        pp = (l[0] // 2) + (l[-1] // 2)
        print(rst * n + sm * (n - 1) + pp)

Measured memory_bytes: 5592
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


class Bisect:
    def __init__(self, func):
        self.__func = func

    def bisect_left(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if self.__func(mid) < x:
                lo = mid+1
            else:
                hi = mid
        return lo

    def bisect_right(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if x < self.__func(mid):
                hi = mid
            else:
                lo = mid+1
        return lo

def f(n):
    r = 1
    for i in range(1, n+1):
        r *= i
    return r

@mt
def slv(N, K, A, F):
    A.sort()
    F.sort(reverse=True)

    def f(x):
        y = 0
        for a, f in zip(A, F):
            b = a - x//f
            if b > 0:
                y += b
        if y <= K:
            return 1

        return 0

    return Bisect(f).bisect_left(1, 0, 10**18)






def main():
    N, K = read_int_n()
    A = read_int_n()
    F = read_int_n()
    print(slv(N, K, A, F))


if __name__ == '__main__':
    main()


Measured memory_bytes: 106952
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
p = readl()
k = 0
for i in range(1, n - 1):
    if (p[i - 1] > p[i] > p[i + 1]) or (p[i - 1] < p[i] < p[i + 1]):
        k += 1
print(k)


Measured memory_bytes: 6864
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
const double PI = 3.14159265358979323846;
using namespace std;
int main()
{
  double R;
  cin >> R;
  //cout << 2 * PI * R << endl;
  printf("%.12lf", 2 * PI * R);
  return 0;
}

Measured memory_bytes: 3784
function Main(input){
	input = input.split(" ");
  	var left = Number(input[0]) + Number(input[1]);
  	var right = Number(input[2]) + Number(input[3]);
  	if(left > right) {
    	console.log('Left')
    } else if(left < right) {
      	console.log('Right')
    } else {
      	console.log('Balanced')
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7372