akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <cmath>
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <set>

using namespace std;

int n;

bool cmp(pair<int, int> a, pair<int, int> b) {

    return a.first > b.first;
}
int main() {
    int h1, s1, h2, s2;
    cin >> h1 >> s1 >> h2 >> s2;

    int coin = 1;
    while(true) {
        if(coin) {
            h2 = h2 - s1;
        } else {
            h1 = h1 - s2;
        }

        if(h1 <= 0) {
            cout << "No\n";
            return 0;
        } else if(h2 <= 0) {
            cout << "Yes\n";
            return 0;
        }
        coin = !coin;
    }

    return 0;
}

Measured memory_bytes: 3640
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

typedef vector<vector<ll>> Mat;

Mat createMat(int N, int A, int B, int C) {
  Mat mat;

  for (int i=0; i<N; i++) {
    mat.push_back(vector<ll>(N));
    if (0 <= i-1) mat[i][i-1] = A;
    mat[i][i] = B;
    if (i+1 < N) mat[i][i+1] = C;
  }

  return mat;
}

Mat mul(Mat &A, Mat &B, int M) {
  int N = A.size();
  Mat res(N, vector<ll>(N));

  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      for (int k=0; k<N; k++) {
        res[i][j] += A[i][k] * B[k][j];
        res[i][j] %= M;
      }
    }
  }

  return res;
}

Mat power(Mat &A, int n, int M) {
  Mat res, p = A;

  int N = A.size();
  for (int i=0; i<N; i++) {
    res.push_back(vector<ll>(N));
    res[i][i] = 1;
  }


  while(n) {
    if (n % 2) {
      res = mul(res, p, M);
    }
    p = mul(p, p, M);
    n /= 2;
  }

  return res;
}

int main() {
  int S[100];

  while(1) {
    int N, M, A, B, C, T;

    scanf("%d%d%d%d%d%d", &N, &M, &A, &B, &C, &T);

    if (N == 0) break;

    Mat mat = createMat(N, A, B, C);

    Mat res = power(mat, T, M);

    for (int i=0; i<N; i++) {
      scanf("%d", S+i);
    }

    for (int i=0; i<N; i++) {
      ll ans = 0;

      for (int j=0; j<N; j++) {
        ans += res[i][j] * S[j] % M;
      }

      printf("%lld%c", ans % M, " \n"[i == N-1]);
    }
  }
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
typedef long long ll;

int main() {
    int m1,m2,d1,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    int ans = m1 == m2 ? 0 : 1;
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

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

  int food[m + 1];
  for (int i = 0; i < m + 1; ++i) food[i] = 0;

  for (int i = 0; i < n; ++i) {
    int k, tmp;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      cin >> tmp;
      ++food[tmp];
    }
  }

  int res = 0;
  for (int i = 1; i < m + 1; ++i) {
    if (food[i] == n) ++res;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

ll C[51][51];

void comb_table(int n){
	rep(i,n+1)rep(j,i+1){
		if(j == 0 || j == i){
			C[i][j] = 1LL;
		}
		else{
			C[i][j] = (C[i-1][j-1] + C[i-1][j]);
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, A, B;
	cin >> n >> A >> B;
	vector<ll> v(n);
	rep(i,n) cin >> v[i];
	comb_table(n);
	sort(v.rbegin(), v.rend());
	double ma = 0.0;
	rep(i,A) ma += v[i];
	ma /= A;
	int a_th_val_num = 0, a_th_val_pos = 0;
	rep(i,n){
		if(v[i] == v[A-1]){
			a_th_val_num++;
			if(i < A){
				a_th_val_pos++;
			}
		}
	}
	ll cnt = 0LL;
	if(a_th_val_pos == A){
		for(a_th_val_pos = A; a_th_val_pos <= B; a_th_val_pos++){
			cnt += C[a_th_val_num][a_th_val_pos];
		}
	}
	else{
		cnt += C[a_th_val_num][a_th_val_pos];
	}
	cout << fixed << setprecision(12) << ma << endl;
	cout << cnt << endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> V(25);
  vector<int> C(25);
  
  int sum=0;
  
  for(int i=0;i<N;i++){
    cin >> V.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> C.at(i);
  }
  for(int i=0;i<N;i++){
    if(V.at(i)-C.at(i)>0){
    sum += V.at(i)-C.at(i);
    }
  }
  cout << sum << endl;
}

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

//Kitchen Garden
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			int[] a = new int[n+1];
			for(int i=0;i<=n;i++)a[i]=sc.nextInt();
			for(int i=0;i<=n;i++){
				boolean f = true;
				int d = i==0?a[2]-a[1]:i==1?a[2]-a[0]:a[1]-a[0];
				int pre = i==0?a[1]:a[0];
				for(int j=i==0?2:i==1?2:1;j<=n&&f;j++){
					if(j==i)continue;
					f&=pre+d==a[j];
					pre = a[j];
				}
				if(f){
					System.out.println(a[i]); break;
				}
			}
		}
	}

	void debug(Object...o){
		System.out.println(Arrays.deepToString(o));
	}

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

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s=sc.next();
		//String t= sc.next();
		int n = sc.nextInt();
		int m = sc.nextInt();
		//int k = sc.nextInt();
		long count=0;
		long count1=0;
		int[] array = new int[3];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		Arrays.sort(array);

		/*for(int i=0;i<3;i++) {
			if(s.substring(i,i+1).equals(t.substring(i,i+1))) {
				count++;
			}
		}*/

		/*if(n-m*2<0) {
			System.out.println(0);
		}else {
			System.out.println(n-m*2);
		}*/

		System.out.println(Math.max(0, n-m*2));
	}
}




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

int main() {
string S,T;
  cin >> S >> T;
  int count = 0;
  for(int i = 0; i < S.length(); i++){
  	if(S[i] != T[i]){
    	count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  map<pii, int> mp;
  int a[100010], b[100010];
  vector<int> E[100010];
  rep(i, n - 1)
  {
    cin >> a[i] >> b[i];
    int ma = a[i], mb = b[i];
    if (ma > mb)
      swap(ma, mb);
    mp[MP(ma, mb)] = i;
    E[a[i]].push_back(b[i]);
    E[b[i]].push_back(a[i]);
  }

  int par_color[100010] = {};
  par_color[1] = -1;
  int ans[100010];
  queue<int> que;
  que.push(1);
  while (!que.empty())
  {
    int q = que.front();
    que.pop();

    int color = 1;
    for (auto to : E[q])
    {
      if (par_color[to] != 0)
        continue;
      if (color == par_color[q])
        color++;

      par_color[to] = color;
      int ma = q, mb = to;
      if (ma > mb)
        swap(ma, mb);
      ans[mp[MP(ma, mb)]] = color;
      que.push(to);

      color++;
    }
  }

  int k = 0;
  rep(i, n - 1) k = max(k, ans[i]);

  cout << k << endl;
  rep(i, n - 1) cout << ans[i] << endl;

  return 0;
}


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

int main(){
  int N, K;
  cin >> N>>K;
  int a=1;
  rep(i, N){
    if (2*a>=a+K){
      a+=K;
    }
    else{
      a*=2;
    }
  }
  cout <<a<<endl;
}

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

int main()
{
    std::string S;
    std::cin >> S;

    int N = S.size();
    int count = 1;
    bool two = false;
    for(int i=1; i<N; i++){
        if(two == true){
            two = false; count++; continue;
        }
        if(S[i] != S[i-1]){
            count++; continue;
        }
        else{
            if(i == N-1) break;
            two = true;
            count++; i++;
        }
    }
    std::cout << count << std::endl;
}

Measured memory_bytes: 640
// https://atcoder.jp/contests/abc177/tasks/abc177_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll D, T, S;
  cin >> D >> T >> S;

  if (S * T >= D) drop("Yes");
  drop("No");
}


Measured memory_bytes: 3684
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct node
{
    int a;
    int b;
};
const int N=0x3f3f3f3f;
node a1[1050]={0};
int dp[10005000]={0};
int main()
{
    register int a,b;
    scanf("%d%d",&a,&b);
    for(register int i=0;i<b;i++)
    {
        scanf("%d%d",&a1[i].a,&a1[i].b);
    }
    for(register int i=1;i<=a+100000;i++)
        dp[i]=N;
    dp[0]=0;
    for(register int i=0;i<b;i++)
    {
        for(register int j=a1[i].a;j<=a+100000;j++)
        {
            dp[j]=min(dp[j],dp[j-a1[i].a]+a1[i].b);
        }
    }
    int min1=N;
    for(register int i=a;i<=a+100000;i++)
        min1=min(min1,dp[i]);
    cout<<min1<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
using namespace std;
int main(){
	int a[256] = {0};
	char ch;

	while((ch = getchar()) != EOF){
				a[ch]++;
	}
	for(int i = 97; i <=122;i++)printf("%c : %d\n",i,a[i]+a[i-32]);
}


Measured memory_bytes: 2596
from bisect import bisect_left, bisect_right, insort_left

n = int(input())
s = list(input())
q = int(input())

d = {}
flag = {}
for i in list('abcdefghijklmnopqrstuvwxyz'):
	d.setdefault(i, []).append(-1)
	flag.setdefault(i, []).append(-1)
for i in range(n):
	d.setdefault(s[i], []).append(i)
for i in range(q):
	q1,q2,q3 = map(str,input().split())
	if q1 == '1':
		q2 = int(q2) - 1
		if s[q2] != q3:
			insort_left(flag[s[q2]],q2)
			insort_left(d[q3],q2)
			s[q2] = q3
	else:
		ans = 0
		q2 = int(q2) - 1
		q3 = int(q3) - 1
		if q2 == q3:
			print(1)
			continue
		for string,l in d.items():
			res = 0
			if d[string] != [-1]:
				left = bisect_left(l,q2)
				right = bisect_right(l,q3)
			else:
				left = 0
				right = 0
			if string in flag:
				left2 = bisect_left(flag[string],q2)
				right2 = bisect_right(flag[string],q3)
			else:
				left2 = 0
				right2 = 0
			if left != right:
				if right - left > right2 - left2:
					res = 1
			ans += res
			#print(string,l,res)
		print(ans)


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

#define n 100000
#define q 50000
int s[n],S;
int binary(int);
int main (){

  int i, j, t[q], count=0, T;

  scanf("%d", &S);

  for(i=0; i<S; i++){
    scanf("%d", &s[i]);
  }

  scanf("%d", &T);

  for(j=0; j<T; j++){
    scanf("%d", &t[j]);
  }

  for(j=0; j<T; j++){
    count+=binary(t[j]);
  }

  printf("%d\n", count);

  return 0;
}

int binary(int key){

  int left=0, right, mid;

  right=S;

  while(left<right){
    mid=(right+left)/2;
    if(key==s[mid])
      return 1;
    if(key>s[mid])
      left=mid+1;
    else if(key<s[mid])
      right=mid;
  }
  return 0;
}

Measured memory_bytes: 1184
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import *

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
A = sorted(reads())
B = sorted(reads())
C = sorted(reads())

numB = [0] * N
for i in range(N):
  numB[i] = N - bisect_left(C, B[i]+1)
print(numB, file=stderr)

anumB = [0] * (N+1)
for i in range(N):
  anumB[i+1] = anumB[i] + numB[i]
print(anumB, file=stderr)

numA = [0] * N
for i in range(N):
  numA[i] = anumB[N] - anumB[bisect_left(B, A[i]+1)]
print(numA, file=stderr)

print(sum(numA))

Measured memory_bytes: 127412
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define int long long
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define mo 1000000007

signed main(){
    gok
   int n,a,b;
   cin>>n>>a>>b;
   int dd = n/(a+b);
   int an = a*dd;
   int re = n%(a+b);
   an += min(a,re);
   cout<<an;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <sstream>
#include <numeric>
#include <queue>
#include <sstream>
using namespace std;

void dp(string &s, vector<pair<char,int> > chars,bool &end,string now,int &k ,int kth){
    if (k == kth)
    {
        cout << now << endl ;
        end = 1 ;
        return ;
    }
    
    if (chars.size() == 0)
    {
        return ;
    }
    
    sort(chars.begin(),chars.end()) ;
    
    int i = 0;
    while( i < chars.size() ){
        char nextchar = chars.at(i).first ;
        string next = now + nextchar ;
        k++ ;
        vector<pair<char,int> > nextchars(0,pair<char,int>()) ;
        while (chars.at(i).first == nextchar)
        {
            if (chars.at(i).second+1 <s.size())
            {
                nextchars.push_back(make_pair( s.at(chars.at(i).second+1),chars.at(i).second+1) )  ;
            }
            i++ ;
            if (i >= chars.size())
            {
                break ;
            }
            
        }
        dp(s,nextchars,end,next,k,kth) ;
        if (end == 1)
        {
            return ;
        }
        if (i < chars.size())
        {
            nextchar = chars.at(i).first ;
        }
        
    }
    return ;
}


int main(){
    string s ;
    int kth ;
    cin >> s >> kth;
    vector<pair<char,int> > chars(s.size(),pair<int,int>()) ;
    for (size_t i = 0; i < s.size(); i++)
    {
        chars.at(i) = make_pair(s.at(i),i) ;
    }
    int k = 0 ;
    bool end = 0 ;
    dp(s,chars,end,"",k,kth) ;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int n,m;
vector<vector<bool>> g(8,vector<bool>(8));
int ans=0;

void dfs(int a,vector<bool> c){
	c[a]=true;
	bool flg=true;
	rep(i,n) if(!c[i]) flg=false;
	if(flg) ans++;
	rep(i,n) if(g[a][i] && !c[i]) dfs(i,c);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	rep(i,m){
		int x,y;
		cin >> x >> y;
		g[--x][--y]=true;
		g[y][x]=true;
	}
	vector<bool> c(n);
	dfs(0,c);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>e[1500001];
int dp[1500001];
int vis[1500001];
int dfs(int u)
{
	if(vis[u]==1){printf("-1");exit(0);}
	if(dp[u]) return dp[u];
	vis[u]=1;
	int ans=1;
	for(int i=0;i<e[u].size();i++)
	{
		//printf("%d::%d %d\n",u,e[u][i],dfs(e[u][i])+1);
		ans=max(ans,dfs(e[u][i])+1);
	}
	vis[u]=0;
	return dp[u]=ans;
}
int main() 
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int pre=0;
		for(int j=1;j<n;j++)
		{
			int x;
			scanf("%d",&x);
			int now=min(i,x)*n+max(i,x);
			e[pre].push_back(now);
			pre=now;
		}
	}
	int ans=dfs(0);
	printf("%d",ans-1);
	return 0;
}

Measured memory_bytes: 62848
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    //cant wait for holiday
//    string days[7] ={"SUN","MON","TUE","WED","THU","FRI","SAT"};
//    string s;
//    int n;
//    cin>> s;
//    for (int i = 0; i< 7; i++){
//        if (s== days[i]){
//            n = i;
//        }
//    }
//    n = 7-n;
//    cout<< n;
    //day before christmas eve
//    int a, b;
//    a = 0;
//    b = 0;
//    int n;
//    cin>> n;
//    int prices[n];
//    for (int i = 0; i< n; i++){
//        cin>> prices[i];
//    }
//    for (int i = 0; i< n; i++){
//        //find the greatest number and the index
//        if (prices[i]>=a){
//            a = prices[i];
//            b = i;
//        }
//    }
//    //b is index, a is value
//    a = 0; // a will now be the sum
//    prices[b] /=2;
//    for (int i =0 ; i< n; i++){
//        a+=prices[i];
//    }
//    cout<< a;
    //count ABC;
    int n;
    int a;
    a = 0;
    cin>> n;
    char word[n];
    for (int i = 0; i< n; i++){
        cin>> word[i];
    }
    for (int i = 0; i< n; i++){
        if (word[i] == 'A'){
            if (i+1<n && word[i+1]=='B'){
                if (i+2<n&&word[i+2] == 'C'){
                    a++;
                }
            }
        }
    }
    cout << a;
    
    return 0;
}

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

int exp_over_v(int i, int thres)
{
  int ret = 0;
  while(i < thres) {
    i *= 2;
    ret++;
  }
  return ret;
}

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

  double prob = 0.0;
  for(int i=1; i<=N; i++) {
    int e = exp_over_v(i, K);
    prob += std::pow(0.5, e);
  }
  prob /= N;

  std::cout << std::fixed << std::setprecision(15) << prob << std::endl;

  return 0;
}


Measured memory_bytes: 4280
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,t,a;cin>>n>>t>>a;
    vector<int>h(n);
    for(int i=0;i<n;i++)
        cin>>h[i];
    double cc=INF;int ans=0;
    for(int i=0;i<n;i++){
        double c=fabs(t-h[i]*0.006-a);
        if(cc>c){
            cc=c;
            ans=i;
        }
    }
    cout<<ans+1<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    ll k,n;
    cin>>k>>n;
    V<ll> a(n);
    cinf(n,a);
    ll ans=k;
    ll cnt=0;
    rep(i,n){
        if(i<n-1){
            chmax(cnt,a[i+1]-a[i]);
        }else{
            chmax(cnt,k-a[n-1]+a[0]);
        }
    }
    cout<<ans-cnt<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
*/

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

int main() {
    char c;
    cin >> c;
    if((int)c > 64 && (int)c <91) {
        cout << "A" << endl;
    }else if((int)c > 96 && (int)c < 123){
        cout << "a" << endl;
    }
   //cout << (int)c << endl;

    return 0;
}

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

using namespace std;

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

   int count = 0 ;

  for(int k=31;k<=n;){
    
	vector<int> x(k + 1);
	int num = k; 
	int ans = 1;

	for (int i = 2; i <= k; i++) {
		while (num%i == 0) {
        x.at(i)++;
        num /= i;
}
}

  for (int i = 2; i <= k; i++){
     ans *= (x.at(i) + 1);
	}
  
  if(ans==8){
    count++ ;
  }
  k += 2 ;
    
  }
    
  cout << count << endl ;
	return 0;
}


Measured memory_bytes: 256
/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >>d;
  int y=0;
  int n=0;
  if(c%b == 0)    y = c/b;
  else y = c/b +1;
  if(a%d == 0)    n = a/d;
  else n = a/d +1;
  if(y > n) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include <cstring>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if(a==b)
        return 0;
    int m=x-a;
    int t=x-b;
    if(t<0)
        t*=-1;
    if(m<0)
        m*=-1;
    if(m>t)
        cout<<'B'<<endl;
    else
        cout<<'A'<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
ll n, a, b;
int main() {
    cin >> n >> a >> b;
    ll k = n / (a + b);
    ll r = n % (a + b);
    if (r > a) {
        cout << k * a + a << endl;
    } else {
        cout << k * a + r << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n + 1];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		arr[n] = Integer.MAX_VALUE;
		Arrays.sort(arr); 
		long total = 0;
		int x = 2;
		for (int i = 0; i < n - 2; i++) {
		    for (int j = i + 1; j < n - 1; j++ ) {
		        int left = j;
		        int right = n;
		        while (right - left > 1) {
		            int m = (left + right) / 2;
		            if (arr[i] + arr[j] > arr[m]) {
		                left = m;
		            } else {
		                right = m;
		            }
		        }
		        total += left - j;
		    }
		}
		System.out.println(total);
	}
}


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

from collections import deque
import heapq
import math
import bisect


def main():
    S = input()

    a = int(S[:2])
    b = int(S[2:])
    if a == 0 or b == 0:
        if a == 0 and 1 <= b <= 12:
            print("YYMM")
        elif 1 <= a <= 12 and b == 0:
            print("MMYY")
        else:
            print("NA")
    elif a > 12 and b > 12:
        print("NA")
    elif 1 <= a <= 12 and 1 <= b <= 12:
        print("AMBIGUOUS")
    elif 1 <= a <= 12:
        print("MMYY")
    else:
        print("YYMM")


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import std.string;
import std.range;
import std.conv;
import std.stdio;
import std.algorithm;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;

void main()
{
	auto N = readln.chomp;
	int sum;
	foreach(i; N) sum += i.to!string.to!int;
	if(N.to!int%sum == 0){
		writeln("Yes");
	}else{
		writeln("No");
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;


// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// -------------------------------------------------------------------------------------

int main() {
  string o, e;
  cin >> o >> e;

  int o_n = o.length();
  int e_n = e.length();

  string ans = "";
  int p = 0;
  while(true) {
    if(p >= o_n) break;
    ans += o[p];
    if(p >= e_n) break;
    ans += e[p];
    p++;
  }
  cout << ans << endl;

  return 0;
}

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



ll n , a , b;

ll solve1(ll x , ll y){
    ll ans = x - 1;
    y -= (x-1);
    x  = 1;

    if((y - x)&1){
            ans ++;
            y --;
    }

    return (y - x) / 2 + ans;
}

ll solve2(ll x , ll y){

    ll ans = n - y;

    x += (n - y);
    y  = n;

    if((y - x)&1){
            ans ++;
            x ++;
    }

    return (y - x) / 2 + ans;
}

void solve(int testCase){

    scanf("%lld %lld %lld" , &n , &a , &b);

    if((a-b)&1){
            if(a > b)swap(a , b);

            ll dis1 = solve1(a , b);
            ll dis2 = solve2(a , b);

            //cout << dis1 << " " << dis2 << endl;

            printf("%lld\n" , min(dis1 , dis2));
    }
    else {
            printf("%lld\n" , abs(b - a)/2);
    }

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

bool isKai(string s) {
    bool ok = true;
    for (int i = 0; i < s.size() / 2; i++) {
        if (s[i] != s[s.size() - i - 1]) ok = false;
    }
    return ok;
}

int main() {
    string S;
    cin >> S;
    int N = S.size();
    int a = (N - 1) / 2;
    int b = (N + 3) / 2;
    if (isKai(S) and isKai(S.substr(0, a)) and
        isKai(S.substr(b, N - (b + 1)))) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, string S, string T){
	rep(i, N) {
		cout << S[i];
		cout << T[i];
	}
	cout << endl;
}

int main(){	
	long long N;
	string T;
	string S;
	scanf("%lld",&N);
	cin >> S;
	cin >> T;
	solve(N, S, T);
	return 0;
}



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

int main() {
    int N;
    cin >> N;
    char S[100];
    for(int i=0; i<N; ++i)
        cin >> S[i];
    for(int i=0; i<N; ++i) {
        if(S[i] == 'Y') {
            cout << "Four" << endl;
            return 0; 
        }
    }
    cout << "Three" << endl;
}

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

using namespace std;

int main(void)
{
    string S, T;
    int i, j, n, judge, ans=0;

    cin >> S;
    cin >> T;

    n = S.size();

    for(i=0; i<n; i++){ // 回転数
        judge = 1;
        for(j=0; j<n; j++){
            if(S[j] != T[(j+i)%n]){
                judge = 0;
            }
        }

        if(judge == 1){
            ans = 1;
        }
    }

    if(ans == 1){
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
char x[9],buf[1100000];
sz;i;
T[1<<17];
N,C,K,k;
ans,id,pre;
main()
{
	read(0,buf,1100000);
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		C=C*10+k-'0';
	}
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		K=K*10+k-'0';
	}
	for(;i<N;++i)
	{
		for(;;)
		{
			k=buf[sz++];
			if(k<'0')break;
			T[i]=T[i]*10+k-'0';
		}
	}
	qsort(T,N,4,"\x8b\7+\6\xc3");
	for(i=0;i<N;++i)
	{
		if(i-id>=C||pre<T[i])
		{
			ans+=1;
			pre=T[i]+K;
			id=i;
		}
	}
	sz=8;
	do
	{
		x[--sz]=ans%10+'0';
		ans/=10;
	}while(ans);
	write(1,x+sz,8-sz);
}


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

using namespace std;

const int inf = 2e9;

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

    int n, k;
    cin >> n >> k;
    vector<int> dp(n, inf);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k && i + j < n; j++) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(a[i + j] - a[i]));
        }
    }
    cout << dp[n - 1] << "\n";

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
long long X;
long long Y;
int main(){
  int res=1;
  rd(X);
  rd(Y);
  while(2*X <= Y){
    X *= 2;
    res++;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// ll X, Y;
// {
//   int res = 1;
//   rd(X,Y);
//   while(2X <= Y) X *= 2, res++;
//   wt(res);
// }


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

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  for (int i = 0; i < n; i++){
    cin >> x[i] >> y[i];
  }
  double ans = 0;
  for (int i = 0; i < n; i++){
    for (int j = i+1; j < n; j++){
      ans += pow(pow(x[i]-x[j], 2)+pow(y[i]-y[j], 2), 0.5);
    }
  }
  double N = n;
  cout << fixed << setprecision(7) << ans * 2.0 / N << endl;
}

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

const ll INF= 1LL << 60;

//入力
ll N;
ll K;
ll h[100010];
//dp
ll dp[100010];


void chmin(ll& a, ll b){
  if(a>b){
    a=b;
  }
}

int main(){
  cin >> N >> K;
  for(int i=0;i<N;i++) cin >>h[i];
  for(int i=0;i<100010;i++) dp[i]=INF;
  
  dp[0]=0;
  
  for(int i=0;i<N;i++){
    for(int j=i+1;j<=i+K;j++){
      chmin(dp[j],dp[i]+abs(h[i]-h[j]));
      //cout<<i<<","<<j<<":"<<dp[j]<<endl;
    }
  }
  
  cout << dp[N-1] << endl; 
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define put(n) cout<<(n)<<endl
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);++(i))
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()


int main(){
    int E,Y;
    cin>>E>>Y;
    if(E==0){
        if(Y>=1868 && Y <= 1911)cout<<"M"<<Y-1867<<endl;
        if(Y>=1912 && Y <= 1925)cout<<"T"<<Y-1911<<endl;
        if(Y>=1926 && Y <= 1988)cout<<"S"<<Y-1925<<endl;
        if(Y>=1989 && Y <= 2016)cout<<"H"<<Y-1988<<endl;
    }
    if(E == 1)cout<<1867+Y<<endl;
    if(E == 2)cout<<1911+Y<<endl;
    if(E == 3)cout<<1925+Y<<endl;
    if(E == 4)cout<<1988+Y<<endl;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N;
  int F[110] = {0};
  int P[110][11];
  int res=-INF;
  cin >> N;

  rep(i,N) {
    rep(j,10) {
      int f;
      cin >> f;
      F[i] = (F[i]<<1) | f;
    }
  }

  rep(i,N){
    rep(j,11){
      cin >> P[i][j];
    }
  }
  FOR(i, 1, 1023){
    int p = 0;
    rep(j,N){
      int c = 0;
      int f = i & F[j];
      rep(i,10){
        if( f & 1 ) c++;
        f = f >> 1;
      }
      p += P[j][c];
    }
    res = max(res, p);
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int cnt=0;
  for(int i=0;i<n-2;i++){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
        cnt++;
        i+=2;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
from collections import deque
n,m=map(int,input().split())
li=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    li[a-1].append(b)
    li[b-1].append(a)
ans=[0]*n
a=[[]  for _ in range(n)]
d=deque([1])
while len(d)>0:
    x=d.popleft()
    if ans[x-1]==0:
        ans[x-1]+=1
        for v in li[x-1]:
            if ans[v-1]==0:
                d.append(v)
                a[v-1].append(x)
if sum(ans)==n:
    print("Yes")
    for i in range(1,n):
        print(a[i][0])
else:
    print("No")



Measured memory_bytes: 44488
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    vector<char> v = {'a', 'i', 'u', 'e', 'o'};
    char c;
    cin >> c;
    cout << (find(all(v), c) != v.end() ? "vowel" : "consonant") << endl;
    return 0;
}

Measured memory_bytes: 256
/* atcoder */
#include "bits/stdc++.h"
using namespace std;

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<vector<int>> vvi;           // intの2次元vector
typedef vector<vector<double>> vvd;        // doubleの2次元vector
typedef vector<vector<ll>> vvll;           // llの2次元vector
typedef vector<vector<ld>> vvld;           // ldの2次元vector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* stringstream */
stringstream ss;
stringstream init_ss; // save default formatting

/* main */
void Main(void)
{
    string s;
    getline(cin, s);
    for (int i = 0; i < s.size(); i++)
    {
        if (isalpha(s[i]))
        {
            if (islower(s[i]))
                s[i] = toupper(s[i]);
            else
            {
                s[i] = tolower(s[i]);
            }
        }
    }
    cout << s << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();

    return 0;
}



Measured memory_bytes: 3128
#include<iostream>                                          
using namespace std;
static const int MAX=100001;
static const int NIL=-1;

typedef struct Node{
    int p,l,r;
}Node;

Node T[MAX];
int n,D[MAX];

void print(int u){
    int i,c;
    cout<<"node "<<u<<": ";
    cout<<"parent = "<<T[u].p<<", ";
    cout<<"depth = "<<D[u]<<", ";

    if(T[u].p==NIL)cout<<"root, ";
    else if(T[u].l==NIL)cout<<"leaf, ";
    else cout<<"internal node, ";

    cout<<"[";
    c=T[u].l;
    for(int i=0;c!=NIL;i++){
        if(i)cout<<", ";
            cout<<c;
            c=T[c].r;
    }
    
    
    cout<<"]"<<"\n";
}
void rec(int u,int p){
    D[u]=p;
    if(T[u].r!=NIL)rec(T[u].r,p);
    if(T[u].l!=NIL)rec(T[u].l,p+1);
}
int  main(){
    int id,k,c,l,r;
    cin>>n;
    for(int i=0;i<n;i++)T[i].p=T[i].l=T[i].r=NIL;
    for(int i=0;i<n;i++){
        cin>>id>>k;
        for(int j=0;j<k;j++){
            cin>>c;
            if(j==0)T[id].l=c;
            else  T[l].r=c;
            l=c;
            T[c].p=id;
                       
                
        }
    }
    for(int i=0;i<n;i++){
        if(T[i].p==NIL)
            r=i;
    }
    rec(r,0);
    for(int i=0;i<n;i++)
        print(i);
    return 0;    
}                                                           



Measured memory_bytes: 7632
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
  char S[2000];
  int i, j, N, D1, D2, ans = 0;
  scanf("%d", &N);
  for (i = 1; i < N; i++) {
    for (j = 1; i * j < N; j++) ans++;
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 1732
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	int [] changeM = {20 * 20 * 18 * 20, 20 * 18 * 20, 18 * 20, 20, 1};
	int [] day = {-1,31,28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	
	private void doit(){
		long day20121221 = getdays(2012, 12, 21);
		while(true){
			String s = sc.next();
			if(s.equals("#")) break;
			String [] data = s.split("\\.");
			if(data.length == 3){
				int [] num = new int[3];
				for(int i = 0; i < 3; i++){
					num[i] = Integer.parseInt(data[i]);
				}
				long nowdays = getdays(num[0], num[1], num[2]);
				long diff = nowdays - day20121221;
				diff = diff % (changeM[0] * 13);
				String res = getM(diff);
				System.out.println(res);
			}
			else{
				int [] num = new int[5];
				for(int i = 0; i < 5; i++){
					num[i] = Integer.parseInt(data[i]);
				}
				long res = getdaysfromM(num);
				String ans = getyear(res);
				System.out.println(ans);
			}
		}
	}
	
	private String getyear(long res) {
		if(res <= 10){
			long d = 21 + res;
			return "2012.12." + d;
		}
		res = res - 11;
		int y = 2013,m = 1, d = 1;
		while(true){
			int add = isleapYear(y) ? 1 : 0;
			if(res / (add + 365) == 0){
				break;
			}
			else{
				y++;
				res -= add + 365;
			}
		}
		for(int i = 1; i <= 12;i++){
			if(res < day[i] + (isleapYear(y) && i == 2 ? 1 : 0)){
				d += res;
				break;
			}
			else{
				res -= day[i] + (isleapYear(y) && i == 2 ? 1 : 0);
				m++;
			}
		}
		return y + "." + m + "." + d ;
	}
	
	private boolean isleapYear(int i) {
		if(i % 4 != 0){
			return false;
		}
		else if(i % 400 == 0){
			return true;
		}
		else if(i % 100 == 0){
			return false;
		}
		else{
			return true;
		}
	}

	private long getdaysfromM(int[] num) {
		long sum = 0;
		for(int i = 0; i < 5; i++){
			sum += (long)num[i] * changeM[i];
		}
		return sum;
	}

	private String getM(long diff) {
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < 5; i++){
			sb.append("." + (diff / changeM[i]));
			diff = diff % changeM[i];
		}
		return sb.substring(1);
	}

	long getdays(int y, int m, int d) {
		if (m <= 2) {
			y--;
			m += 12;
		}
		long dy = (long)365 * (y - 1);
		long c = y / 100;
		long dl = (y >> 2) - c + (c >> 2);
		long dm = (m * 979 - 1033) >> 5;
		return dy + dl + dm + d - 1;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 26264
K, S = list(map(int, input().split()))
K += 1
cnt = 0
for i in range(K):
    if i+K*2<=S : continue
    if i>S : continue
    for j in range(min(K, S-i+1)):
        if i+j+K<=S : continue
        if i+j>S : break
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
typedef unsigned long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    cin>>s;
    for(int i = 0; i<s.size(); i++){
        if(s[i]=='?'){
            s[i]='D';
        }
    }
    cout<<s<<endl;
//    int curr = 0;
//    int ans_num = 0;
//    string pt = "";
//    string ans = "";
//    int size = s.size();
//    for(int i =0; i<size; i++){
//        if(s[i]=='P'){
//            if(i!=size-1 && s[i+1]=='P'){
//                if(curr>ans_num){
//                    ans_num=curr;
//                    pt = ans;
//                }
//                curr = 0;
//            }else if(i!=size-1){
//                ans.push_back('P');
//                curr++;
//            }
//        }else{
//            ans.push_back('D');
//            curr++;
//        }
//    }
    
//    if(curr>ans_num){
//        cout<<ans<<endl;
//    }else{
//        cout<<pt<<endl;
//    }
    
    return 0;
}

Measured memory_bytes: 3740
n = gets.chomp.to_i
s = gets.chomp
countb = 0
countw = 0
abs = 0
pos = n - 1

while pos >= 0
  if s[pos] == '.' then
    break
  end
  pos -= 1
end

while pos >= 0
  if s[pos] == '.' then
    countw += 1
  else
    countb += 1
  end

  if countw < countb then
    abs += countw
    countb = 0
    countw = 0
  end
  pos -= 1
end

puts abs + [countw, countb].min


Measured memory_bytes: 2172
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        
        int N=sc.nextInt();
        int X=sc.nextInt();
        int[] m=new int[N];
        
        for(int i=0;i<N;i++){
            m[i]=sc.nextInt();
        }
        int rest=X;
        int min=X;
        for(int i=0;i<N;i++){
            rest-=m[i];
            if(min>m[i]){
                min=m[i];
            }
        }
        
        System.out.println(N+rest/min);
    }
}

Measured memory_bytes: 23124