akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main() {
   int N, ans = 0; cin >> N;
   rep(i, 1, N + 1) {
     int a; cin >> a;
     if (i % 2 == 1 && a % 2 == 1) ans++;
   }

   cout << ans << endl;
 }


Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
	int a,x,y,z,i;
	
	scanf("%d",&a);
	for(i=0;i<a;i++) {
		scanf("%d",&x);
		scanf("%d",&y);
		scanf("%d",&z);
		
		if(x*x==y*y+z*z||y*y==z*z+x*x||z*z==x*x+y*y) {
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}		
	}
	return 0;
}
	
	
	
	


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

int main()
{
	int s;
	int hour, minute, second;
	cin >> s;
	hour = s / 3600;
	minute = (s % 3600) / 60;
	second = (s % 3600) % 60;
	cout << hour << ":" << minute << ":" << second << endl;
}

Measured memory_bytes: 1168
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

n = int(input())

for _ in range(1,10):
    for __ in range(_,10):
        if _*__ == n:
            print("Yes")
            n = 0
            break
if n:
    print("No")


Measured memory_bytes: 3060
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;

#define MN (100000)

int N, L;
int I[MN];
typedef pair<int, int> P;
int main() {
    int cnt = 0;
    int ctime = 0;
    scanf("%d %d", &N, &L);
    for (int i = 0; i < N; i++) {
        scanf("%d", &I[i]);
    }
    priority_queue< P, vector<P>, greater<P> > Q;
    for (int i = 0; i < N; i++) {
        if ( (i == 0 && I[i] > I[i+1]) || 
             (i == N-1 && I[i] > I[i-1]) ||
             (I[i] > I[i+1] && I[i] > I[i-1]) ) {
            Q.push(P(L - I[i], i));
        }
    }
    while (!Q.empty()) {
        P p = Q.top(); Q.pop();
        ctime = p.first;
        //printf("\t%d\n", ctime);
        I[p.second] = 0;
        int i = p.second - 1;
        int j = p.second + 1;
        if ( (0 <= i && i < N) &&
                ((i == 0 && I[i] > I[i+1]) || 
                 (i == N-1 && I[i] > I[i-1]) ||
                 (I[i] > I[i+1] && I[i] > I[i-1])) ) {
            Q.push(P(L - I[i] + ctime, i));
        }
        if ( (0 <= j && j < N) &&
                ((j == 0 && I[j] > I[j+1]) || 
                 (j == N-1 && I[j] > I[j-1]) ||
                 (I[j] > I[j+1] && I[j] > I[j-1])) ) {
            Q.push(P(L - I[j] + ctime, j));
            I[j] = 0;
        }
    }
    printf("%d\n", ctime);
    return 0;
}

Measured memory_bytes: 1892
#! python3
# 118_C 体力の最小値を表示
#体力の最小値は体力の最大公約数

import math

N = int(input())
st_list = list(map(int,input().split()))

ans = st_list[0]

for i in range(N):
    ans = math.gcd(ans,st_list[i])
    
print(ans)

Measured memory_bytes: 20260
n = int(input())
ws = list(map(int, input().split()))

s = sum(ws)

acs = [0]
for i in range(n-1):
  acs.append(acs[-1]+ws[i])
acs = acs[1:]

acs = [abs(s - 2 * x) for x in acs]
print(min(acs))



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int n;
    cin >> n;
    vector<int> pi(n);
    rep(i, n) cin >> pi.at(i);
    sort(pi.begin(), pi.end());

    int sum = 0;
    for (size_t i = 0; i < pi.size() - 1; i++) {
        sum += pi.at(i);
    }
    sum += pi.back() / 2;
    cout << sum << endl;
}


Measured memory_bytes: 3508
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var abc = S.ToCharArray();
            Array.Sort(abc);
            Console.WriteLine(abc[0] == 'a' && abc[1] == 'b' && abc[2] == 'c' ? "Yes" : "No");
        }
    }
}

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

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int x = int.Parse(s[0]);
            int y = int.Parse(s[1]);

            s = Console.ReadLine().Split(' ');
            int r = int.Parse(s[0]);
            int c = int.Parse(s[1]);

            Console.WriteLine(x * y - x * c - y * r + c * r);
        }
    }
}

Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int N = NextInt();
        double ans = 0;
        double u = 0;
        for (int i = 0; i < N; i++)
        {
            double v = NextDouble();
            string s = NextString();
            if (s == "JPY")
            {
                ans += v;
            }
            else
            {
                u += v;
            }
        }
        Console.WriteLine(ans + u* 380000.0);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

Measured memory_bytes: 11220
#include<stdio.h>

int main()
{
    char s[4];
    scanf("%s",s);
    int R=0;
    for(int i=0; i<3; i++)
        if(s[i]=='R') R++; 
    if(R!=2) printf("%d\n",R);
    else if(s[1]=='R') printf("%d\n",2);
    else printf("1\n");
}

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

int main(){
	int n, cnt, rec;
	scanf("%d",&n);
	if (n == 3) printf("2 5 63\n");
	else if (n == 4) printf("2 5 20 63\n");
	else if (n > 15000){
		for (int i = 1; i <= 30000; i++){
			if ((i % 2 == 0 || i % 3 == 0) && i % 6 != 0) printf("%d ", i);
		}
		for (int i = 1; i <= n - 15000; i++){
			printf("%d", i * 6);
			if (i == n - 15000) printf("\n");
			else printf(" ");
		}
	}
	else{
		printf("2 4 3 9");
		n -= 4;
		rec = min(4999, n / 2);
		for (int i = 1; i <= rec; i++)
			printf(" %d %d", i * 6 + 2, i * 6 + 4);
		for (int i = rec + 1; i <= n / 2; i++)
			printf(" %d %d", (i - rec) * 12 + 3, (i - rec) * 12 + 9);
		if (n & 1) printf(" 30000\n");
		else printf("\n");
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
#define INF  0x7fffffffffff//ffff
#define M 112300
ll a[M],ans = 0,n,m;
bool check(ll x){
	if(x==2)
	return true;
	for(ll i = 2;i*i <=x;i++){
		if(x %i==0)
		return false;
	}
	return true;
}
int main(void){
	cin>>n>>m;
	if(n < m)
	swap(n,m);
	ll j = 0;
	for(ll i = 1;i *i <= m;i++){
		if(m %i==0){
			a[j] = i;
			j++;
			if(i*i!=m){
			a[j] = m/i;
			j++;
		}
		}
	}
	for(ll i = 0;i < j;i++){
		if(n % a[i]==0&&check(a[i]))
		ans++;
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
#include <queue>
#include <functional>
using namespace std;

using Weight = int;
struct Edge {
	int src, dst; Weight weight;
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

const int INF = 1 << 25;
int dp[100][1100];
typedef pair<int, int> Pii;
typedef pair<int, Pii> P;

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

	int n, m, c;
	while(cin >> n >> m >> c, n | m | c) {
		Graph G(n);
		for(int i = 0; i < m; i++) {
			int a, b, w;
			cin >> a >> b >> w;
			a--, b--;
			G[a].push_back(Edge(a, b, w));
		}

		fill((int*)begin(dp), (int*)end(dp), INF);

		priority_queue<P, vector<P>, greater<P> > q;
		q.push(P(0, Pii(0, 0)));
		while(q.size()) {
			int u = q.top().second.first, use = q.top().second.second;
			int w = q.top().first;
			q.pop();
			if(dp[u][use] != INF) continue;
			dp[u][use] = w;

			for(Edge e : G[u]) {
				if(w + e.weight <= c && dp[e.dst][use] > w + e.weight) {
					//dp[e.dst][use] = w + e.weight;
					q.push(P(w + e.weight, Pii(e.dst, use)));
				}
				if(use + 1 <= n && dp[e.dst][use + 1] > w) {
					//dp[e.dst][use + 1] = w;
					q.push(P(w, Pii(e.dst, use + 1)));
				}
			}
			cout << "";
		}

		int ans = m;
		for(int i = 0; i < m; i++) {
			if(0 <= dp[n - 1][i] && dp[n - 1][i] <= c) {
				ans = i;
				break;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 4568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define REP(i, n) for (ll i = 1; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 5000000000000000000;

constexpr int mod = 1000000007;
struct ModInt {
    ll x;
    ModInt (ll a) : x((a % mod + mod) % mod) {}
    ModInt operator- () const {
        return ModInt(-x);
    }
    ModInt &operator+= (const ModInt &a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-= (const ModInt &a) {
        if ((x -= a.x) < 0) x += mod;
        return *this;
    }
    ModInt &operator*= (const ModInt &a) {
        (x *= a.x) %= mod;
        return *this;
    }
    ModInt operator+ (const ModInt &a) const {
        ModInt res(*this);
        return res += a;
    }
    ModInt operator- (const ModInt &a) const {
        ModInt res(*this);
        return res -= a;
    }
    ModInt operator* (const ModInt &a) const {
        ModInt res(*this);
        return res *= a;
    }
    ModInt pow(ll t) const {
        if (!t) return 1;
        ModInt a = pow(t / 2);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    ModInt inv() const {
        return pow(mod - 2);
    }
    ModInt &operator/= (const ModInt &a) {
        return (*this) *= a.inv();
    }
    ModInt operator/ (const ModInt &a) const {
        ModInt res(*this);
        return res /= a;
    }
    friend istream &operator>> (istream &is, ModInt &a) {
        is >> a.x;
        return is;
    }
    friend ostream &operator<< (ostream &os, const ModInt &a){
        os << a.x;
        return os;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    
    ModInt xsum(0), ysum(0);
    rep(i, n - 1) {
        ModInt M(x[i + 1] - x[i]);
        ModInt N((i + 1) * (n - i - 1));
        xsum += M * N;
    }
    rep(i, m - 1) {
        ModInt M(y[i + 1] - y[i]);
        ModInt N((i + 1) * (m - i - 1));
        ysum += M * N;
    }
    cout << xsum * ysum << "\n";
    return 0;
    
}


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

int gcd(int a, int b){
  if(b == 0)return a;
  else return gcd(b, a%b);
}

int main(){
  int K;
  cin >> K;
  int sum = 0;
  for(int i = 1; i <= K; i++){
    for(int j = 1; j <= K; j ++){
      for(int j2 = 1; j2 <= K; j2++){
        sum += gcd(i,gcd(j,j2));
      }
    }
  }
  cout << sum <<endl;
}
 

Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    string T;
    cin >> T;

    for(int i=0;i<T.size();i++){
        if(T[i]!='?'){
            cout << T[i];
        }else{

            cout << 'D';
        }
    }

    cout << endl;
}

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


int main(){
	
	string str;
	cin>>str;
	int a=0;
	int b=str.size()-1;
	
	while(true){
		if(str[a]!='A'){
			a++;
		}
		else{
			break;
		}
	}
	while(true){
		if(str[b]!='Z'){
			b--;
		}
		else{
			break;
		}
	}
	
	cout<<b-a+1<<endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>

using namespace std;
int main() {
  int X, Y, Z, S, K;
  int ans = 0;
  cin>>K>>S;
  for(X = 0; X <= K; X++) {
	for(Y = 0; Y <= K; Y++) {
	  Z = S - X - Y;
	  if(Z < 0) break;
	  if(Z <= K) ans++;
	}
  }
  cout << ans << endl;
  return 0;
}


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



int main(){
	for(int n;cin>>n,n;){
		vector <int>d;
		for(int i=0,j;i<n;i++){
			cin>>j;
			d.push_back(j);
		}
		sort(d.begin(),d.end());
		if(d[n-1]<2)cout<<"NA\n";
		else{
			int tmp=1;
			for(int i=0;i<d.size();i++){
				if(d[i]>=1)tmp++;
			}
			cout<<tmp<<endl;
		}
	}
	
	return 0;
}


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

// #define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (stderr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 1e9, MOD = INF + 7 /* INF - 1755647 */;

/////////////////////////////////////////////////////////////////////

const int N = 3e5 + 20;

int32_t main() {

    sync;

    int a, b, c; cin >> a >> b >> c;
    if (a > b) swap(a, b);
    cout << (a <= c && c <= b ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;

const int f[5]={3,5,7};
const int INF=1e9;
int n,ans;

void DFS(LL p);
int main()
{
	ios::sync_with_stdio(false);
	while(cin>>n){
		ans=0;
		for(int i=0;i<3;++i)
			DFS(f[i]);
		cout<<ans<<endl;
	}
	
	return 0;
}

void DFS(LL p)
{
	if(p>n)	return;
	for(int i=0;i<3;++i)
		DFS(p*10+f[i]);
	int t1=0,t2=0,t3=0;
	while(p){
		if(p%10==3)	t1=1;
		else	if(p%10==5)	t2=1;
		else	if(p%10==7)	t3=1;
		p/=10;
	}
	if(t1&&t2&&t3)	++ans;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
pos = 1
path = [1]
TF = [False] + [True] * (n-1)
for i in range(k):
    pos = a[pos - 1]
    if TF[pos - 1]:
        path.append(pos)
        TF[pos - 1] = False
    else:
        break
first = path.index(pos)
ans = (k - first) % (len(path) - first) + first
print(path[ans])

Measured memory_bytes: 32380
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,k,ans=0;
  cin>>h>>w>>k;
  vector<string> s(h);
  for(int i=0;i<h;i++) cin>>s[i];
  for(int i=0;i<(1<<h);i++){
    for(int j=0;j<(1<<w);j++){
       int cnt=0;
      for(int l=0;l<h;l++){
        for(int m=0;m<w;m++){
           if(i&(1<<l)) continue;
           if(j&(1<<m)) continue;
           if(s[l][m]=='#') cnt++;
        }
      }
        if(cnt==k) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int main(){
    int d, t, s;
    cin >> d >> t >> s;
    if(t*s>=d) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <math.h>
 
int main(){
  int N, A, B;
  scanf("%d %d %d", &N, &A, &B);
  int sum = 0;
  int i;
  for (i = 1; i <= N; i++) {
    int sub_sum = 0;
    int k = i;
    int j;
    for (j = 0; j < 5; j++) {
      sub_sum += k % 10;
      k = k / 10;
    }
      if (A <= sub_sum && sub_sum <= B) {
        sum += i;
      }
  }
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 128
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}

	std::string S;
	std::cin >> S;

	char mode = '<';
	long count = 0;
	long cur = 0;
	long result = 0;
	while (cur < S.size()) {
		long first = cur;
		for (; cur < S.size(); ++cur) {
			if (S[cur] != '<') {
				break;
			}
		}
		long up = cur - first;
		long second = cur;
		for (; cur < S.size(); ++cur) {
			if (S[cur] != '>') {
				break;
			}
		}
		long down = cur - second;
std::cerr << up << " " << down << "\n";
		result += (up * (up - 1) / 2) + (down * (down - 1) / 2) + std::max(up, down);
	}
	std::cout << result << "\n";
}


Measured memory_bytes: 900
#ABC126-C
import numpy as np
n,k = map(int,input().split())
cnt = 0
#1/サイコロの目の総数 = m
m =  1/n
for i in range(1,n+1):
    #i*2^t >= k → t >= (log2k - log2i)
    t = np.ceil((np.log2(k) - np.log2(i)))  
    #print("t:",t)
    if i < k:
        cnt += m * (0.5)**t
    else:
        cnt += m
print(cnt)

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

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

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

const double eps = 1e-5;

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

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

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

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

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

const int64 mod = 1e9+7;

int main(void) {
	int64 N;
	cin >> N;
	int64 A, B;
	cin >> A >> B;
	REP(i, N-1) {
		int64 a, b;
		cin >> a >> b;
		int64 mul = max((A+a-1)/ a, (B+b-1)/ b);
		A = a*mul; B = b*mul;
	}
	cout << A+B << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> //ABC 166_b
#define ll long long
using namespace std;
int a[110],n,k,x,y,ans;
int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++){
		cin>>x;
		for(int j=1;j<=x;j++){
			cin>>y;
			a[y]++;
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i]==0) ans++;
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

#define maxn 999999 + 5
typedef long long ll;

int prime[maxn];

void init(){
    for(int i=2;i<maxn-4;i++)
        prime[i] = i % 2;
    prime[2]=1;
    prime[1]=0;
    for(int i=2;i*i<=maxn;i++){
        if(!prime[i])continue;
        for(int j=i;j*i<=maxn;j++)
            prime[i*j]=0;
    }
    for(int i=2;i<=maxn;i++)
        prime[i] += prime[i-1];
}
int main(){
    int n;
    init();
    
    while(~scanf("%d",&n))
        printf("%d\n",prime[n]);
    return 0;
}

Measured memory_bytes: 5088
from collections import deque
import bisect
import sys
sys.setrecursionlimit(500000)

n = int(input())
a = list(map(int, input().split()))
to=[list() for _ in range(n)]

for i in range(n-1):
    u,v = map(int, input().split())
    u-=1
    v-=1
    to[u].append(v)
    to[v].append(u)

INF=1001001001
dp = [INF]*n
dp[0]=a[0]
ansls=[0]*n
ansls[0]=1
history=deque()
def dfs(u,p,rank):
    for v in to[u]:
        if v==p:
            continue
        idx=bisect.bisect_left(dp,a[v])
        prv=dp[idx]
        dp[idx]=a[v]       
        history.append((idx,prv))
        ansls[v]=bisect.bisect_left(dp,INF)
        dfs(v,u,rank+1)
        while len(history)>rank:
            idx,prv =history.pop()
            dp[idx] = prv

dfs(0,-1,0)

print(*ansls,sep='\n')

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

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

using namespace std;

int main(){
	int d; scanf("%d",&d);
	vector c(26,0);
	rep(j,26) scanf("%d",&c[j]);
	vector a(d,vector(26,0));
	rep(i,d) rep(j,26) scanf("%d",&a[i][j]);
	vector t(d,0);
	rep(i,d) scanf("%d",&t[i]), t[i]--;

	int ans=0;
	vector last(26,0);
	rep(i,d){
		ans+=a[i][t[i]];
		last[t[i]]=i+1;
		rep(j,26) ans-=c[j]*(i+1-last[j]);
		printf("%d\n",ans);
	}

	return 0;
}


Measured memory_bytes: 3804
import java.util.Scanner;

// ABC173-B
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		String[] S = new String[N];
		for (int i = 0; i < N; i++) {
			S[i] = sc.next();
		}

		int AC = 0;
		int WA = 0;
		int TLE = 0;
		int RE = 0;

		for (String s : S) {
			if (s.equals("AC")) {
				AC++;
			}
			if (s.equals("WA")) {
				WA++;
			}
			if (s.equals("TLE")) {
				TLE++;
			}
			if (s.equals("RE")) {
				RE++;
			}
		}

		System.out.println("AC x " + AC);
		System.out.println("WA x " + WA);
		System.out.println("TLE x " + TLE);
		System.out.println("RE x " + RE);

		sc.close();
	}

}


Measured memory_bytes: 65044
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
 
using namespace std;
 
typedef long long ll;

struct Edge {
  int u, v, w;
  Edge(int u, int v, int w) : u(u), v(v), w(w) {}
  bool operator <(const Edge &other) const {
    return w > other.w;
  }
};

const int N = 2e5 + 7;

int p[N];
int phi[N];

int get(int a) {
  return (a == p[a] ? a : p[a] = get(p[a]));
}

bool join(int a, int b) {
  a = get(a);
  b = get(b);
  if (a != b && phi[a] + phi[b] - 1 >= 0) {
    p[a] = b;
    phi[b] = phi[a] + phi[b] - 1;
    return true;
  } else if (a == b && phi[a] - 1 >= 0) {
    --phi[a];
    return true;
  } else {
    return false;
  }
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int k, n, m;
  cin >> k >> n >> m;
  vector <int> x(k), y(k), a(k);
  vector <Edge> E;
  for (int i = 0; i < k; ++i) {
    cin >> x[i] >> y[i] >> a[i];
    --x[i], --y[i];
    E.emplace_back(x[i], n + y[i], a[i]);
  }
  sort(E.begin(), E.end());
  for (int i = 0; i < n + m; ++i) {
    p[i] = i;
    phi[i] = 1;
  }
  ll ans = 0;
  for (auto e : E) {
    if (join(e.u, e.v)) {
      ans += e.w;
    }
  }
  cout << ans << '\n';
}



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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int N, M; cin >> N >> M;
	int l = 0, r = INF;
	rep(i, N) {
		int L, R; cin >> L >> R;
		l = max(l, L);
		r = min(r, R);
	}
	cout << max(r - l + 1, 0) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
int a,b;
int main(){
	std::cin>>a>>b;
	std::cout<<a/b<<" "<<a%b<<" "<<std::fixed<<std::setprecision(8)<<static_cast<double>(a)/static_cast<double>(b)<<std::endl;
	return 0;
}

Measured memory_bytes: 1240
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll h,n;
	cin>>h>>n;
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
	    ll tmp;
	    cin>>tmp;
	    sum+=tmp;
	}
	if(sum>=h)
	    cout<<"Yes";
	else
	    cout<<"No";
    return 0;
}


//252908XL

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 3e5 + 10;
int t[MAXN << 2];
int n, k;

void upd(int pos, int val, int v = 1, int tl = 0, int tr = 3e5) {
    if(tl == tr) {
        t[v] = val;
        return;
    }
    int tm = tl + tr >> 1;
    if(pos <= tm) upd(pos, val, v << 1, tl, tm);
    else upd(pos, val, v << 1 | 1, tm + 1, tr);
    t[v] = max(t[v << 1], t[v << 1 | 1]);
}

int get(int l, int r, int v = 1, int tl = 0, int tr = 3e5) {
    if(l <= tl && tr <= r) return t[v];
    if(l > tr || r < tl) return 0;
    int tm = tl + tr >> 1;
    return max(get(l, r, v << 1, tl, tm), get(l, r, v << 1 | 1, tm + 1, tr));
}

void solve() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        upd(x, get(x - k, x + k) + 1);
    }
    cout << t[1];
}


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}


Measured memory_bytes: 7740
N= int(input())
E = [input().split()[2:] for _ in [0]*N]
Q = [0]
L = [0] + [-1]*N
def func(ide):
    global Q
    for i in E[ide]:
        i = int(i) - 1
        if L[i] < 0 :L[i] = L[ide] +1 ;Q.append(i)
    

while Q:top = Q.pop(0);func(top)

for i in range(N):print(i + 1 ,int(L[i]))



Measured memory_bytes: 5624
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll r,d,x;
            cin>>r>>d>>x;
            for(int i=2001;i<=2010;++i)
            {
                x=r*x-d;
                cout<<x<<endl;
            }
        }
        return 0;
    }


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.array;

void main()
{
    ulong N = readln.split[0].to!ulong;
    char[] S = readln.chomp.to!(char[]);
    ulong K = readln.split[0].to!ulong;

    foreach (i; 0..N) if (S[i] != S[K - 1]) S[i] = '*';
    writeln(S.to!string);
}



Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc072
// status:
// tag:

#define SUBMIT
//#define DEBUG

#include <bits/stdc++.h>

using namespace std;
using ui64 = uint64_t;

int p[100000 + 10];

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    stringstream stream(R"(5
1 4 3 5 2
)");
#endif
    int N;
    stream >> N;
    for (int i = 1; i <= N; ++i) stream >> p[i];

    int ans = 0;
    for (int i = 1; i <= N; ++i) {
        if (p[i] == i) {
            if (i != N) swap(p[i + 1], p[i]);
            else swap(p[i - 1], p[i]);
            ans++;
        }
    }

    cout << ans << endl;
#ifdef DEBUG
    for (int i = 1; i <= N; ++i) cout << p[i] << " ";
    cout << endl;
#endif
    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;

  if (((A % 2) == 1) && ((B % 2) == 1)) {
    cout << "Odd" << endl;
  }
  else{
    cout << "Even" << endl;
  }

}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

    int n;
    cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;

}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+9;
int x,n,m,s,ans;
map<int,int>mp;
main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&x);x%=m;s+=x;s%=m;
		ans+=mp[s];mp[s]++;if(!s)ans++;
	}cout<<ans;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
char a[20060811];
int n,i,sum,la;
int main()
{
    cin>>a;
    la=strlen(a);
    for(i=1;i<la;i++)
    {
        if(a[i]!=a[i-1])
            sum++;
        else
            continue;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

const LL MOD = 1e9 + 7;
template<class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
// 0: dummy, 1: A, 2:G 3: C, 4: T
LL solve(int n) {
    auto dp = make_vec<LL>(n + 1, 5, 5, 5);
    dp[0][0][0][0] = 1;
    rep(x, n) rep(i, 5) rep(j, 5) rep(k, 5) loop(l, 1, 5) {
        if (i == 1 && j == 2 && l == 3) continue;
        if (i == 1 && k == 2 && l == 3) continue;
        if (j == 1 && k == 2 && l == 3) continue;
        if (j == 2 && k == 1 && l == 3) continue;
        if (j == 1 && k == 3 && l == 2) continue;

        dp[x + 1][j][k][l] = (dp[x + 1][j][k][l] + dp[x][i][j][k]) % MOD;
    }
    LL res = 0;
    loop(i, 1, 5) loop(j, 1, 5) loop(k, 1, 5) {
        res = (res + dp[n][i][j][k]) % MOD;
    }
    return res % MOD;
}
int main() {
    int n;
    cin >> n;
    cout << solve(n) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define drep(i,cc,n) for(int i=cc;i>n;--i)
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; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

ll choose2(ll n){
    return n*(n-1)/2;
}

ll cnt = 0;
ll n;

void dfs(ll cur){
    if(cur > n) return;

    ll tmp = cur;
    bool sev = false, fiv = false, thr = false;
    while(tmp!=0){
        if(tmp % 10 == 7) sev = true;
        if(tmp % 10 == 5) fiv = true;
        if(tmp % 10 == 3) thr = true;
        tmp = tmp / 10;
    }

    if(sev && fiv && thr) cnt++;

    dfs(cur * 10 + 7);
    dfs(cur * 10 + 5);
    dfs(cur * 10 + 3);
}

int main() {
    cin>>n;
    dfs(0);
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a="CODEFESTIVAL2016";
    string s;
    cin>>s;
    int res=0;
    for(int i=0;i<16;i++){
        if(s[i]!=a[i])res++;
    }
    cout<<res<<endl;
}

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

using namespace std;

int main(){
    #ifdef HOME
    freopen("input.txt", "rt", stdin);
    #endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    if (n % 2 == 0)
        cout << n;
    else
        cout << 2 * n;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000010
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
vector<int> num(200);
vector<int> num_odd(200);
vector<int> dp(1000011,INF);
vector<int> dp_odd(1000011,INF);
int main()
{
	int i = 0;
	while(i <= 185)
	{
		long tmp = i*(i+1)*(i+2)/6;
		num[i] = tmp;
		if(num[i] % 2) num_odd.push_back(tmp);
		i++;
	}
	dp[0] = dp_odd[0] = 0;
	for(int i=0; i<num.size(); i++)
	{
		for(int j=num[i]; j<=1000000; j++)
		{
			dp[j] = min(dp[j], dp[j - num[i]] + 1);
		}
	}
	for(int i=0; i<num_odd.size(); i++)
	{
		for(int j=num_odd[i]; j<=1000000; j++)
		{
			dp_odd[j] = min(dp_odd[j], dp_odd[j - num_odd[i]] + 1);
		}
	}
	int N;
	while(cin >> N, N)
	{
		cout << dp[N] << " " << dp_odd[N] << endl;
	}
	return 0;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
int64_t C[50][2];
int N, K;
bool inner(int64_t l, int64_t r, int64_t u, int64_t b, int64_t x, int64_t y) {
	return l <= x && x <= r && b <= y && y <= u;
}

int solve(int l, int r, int u, int b) {
	int k = 0;
	for(int i = 0; i < N; i++) {
		if(inner(l, r, u, b, C[i][0], C[i][1])) {
			k++;
		}
	}
	return k;
}

int main() {
	cin >> N >> K;
	for(int i = 0; i < N; i++) {
		cin >> C[i][0] >> C[i][1];
	}
	int64_t S = -1;
	int64_t L, R, U, B;
	for(int l = 0; l < N; l++) {
		for(int r = 0; r < N; r++) {
			for(int u = 0; u < N; u++) {
				for(int b = 0; b < N; b++) {
					L = C[l][0]; R = C[r][0];
					U = C[u][1]; B = C[b][1];
					if(R < L || U < B) continue;
					int k = solve(L, R, U, B);
					if(k >= K) {
						int64_t tmp = (R - L) * (U - B);
						if(tmp < 0) tmp *= -1;
						if(tmp < S || S < 0) S = tmp;
					}
				}
			}
		}
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
use std::cmp::{max, min};

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let k: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let x: i32 = read(&mut stdin_lock, &mut buf, b'\n');

    for i in max(-1_000_000, x - k + 1)..min(x + k - 1, 1_000_000) {
        print!("{} ", i);
    }
    println!("{}", min(x + k - 1, 1_000_000));
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>

using namespace std;
typedef long long ll;
ll h,w;
ll sum=0;
ll field[510][510];
ll count=0;
int main(){
  cin>>h>>w;
ll memo[h+1][w+1];
  for(ll i=0;i<h;i++){
  for(ll j=0;j<w;j++){
  cin>>field[i][j];
memo[i][j]=field[i][j];
sum+=field[i][j];
  }
  }
ll count=0;
    for(ll i=0;i<h;i++){
if(i%2==0){
  for(ll j=0;j<w-1;j++){
  if(memo[i][j]%2==1){
count++;
memo[i][j+1]++;
}
  }
if(memo[i][w-1]%2==1){
memo[i+1][w-1]++;
count++;
}
}
else{
  for(ll j=w-1;j>0;j--){
    if(memo[i][j]%2==1){
count++;
memo[i][j-1]++;
}
  }
if(memo[i][0]%2==1){
memo[i+1][0]++;
count++;
}
}
  }
if(sum%2==0)
cout<<count<<endl;
else
cout<<count-1<<endl;
  for(ll i=0;i<h;i++){
  for(ll j=0;j<w;j++){
memo[i][j]=field[i][j];
  }
  }
    for(ll i=0;i<h;i++){
if(i%2==0){
  for(ll j=0;j<w-1;j++){
  if(memo[i][j]%2==1){
cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
count++;
memo[i][j+1]++;
}
  }
if(memo[i][w-1]%2==1){
if(i!=h-1)
cout<<i+1<<" "<<w<<" "<<i+2<<" "<<w<<endl;
memo[i+1][w-1]++;
count++;
}
}
else{
  for(ll j=w-1;j>0;j--){
    if(memo[i][j]%2==1){
cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j<<endl;
count++;
memo[i][j-1]++;
}
  }
if(memo[i][0]%2==1){
memo[i+1][0]++;
if(i!=h-1)
cout<<i+1<<" "<<1<<" "<<i+2<<" "<<1<<endl;
count++;
}
}
  }
  return 0;
}



Measured memory_bytes: 6016
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
  a, b = map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)

points = [0 for _ in range(N)]
for i in range(Q):
  p, x = map(int, input().split())
  points[p-1] += x
  
def dfs(v, pv):
  for nv in G[v]:
    if nv != pv:
      points[nv] += points[v]
      dfs(nv, v)

dfs(0, 0)
print(*points)

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

 
int main() {
	int n;
	cin >> n;
	vector<int> b(n-1);
	for(int i=0; i<n-1; i++){
		cin >> b.at(i);
	}
	long long sum = b.at(0);
	for(int i=1; i<n-1; i++){
		sum += min(b.at(i-1), b.at(i));
	}
	sum += b.at(n-2);

	cout << sum << endl;
}

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

int main(){
  int n,ans;
  cin>>n;
  vector<int> d(n);
  ans=n;
  for (int i=0;i<n;i++){
    cin>>d.at(i);
    for (int j=0;j<i;j++){
      if (d.at(i)==d.at(j)){
        ans--;
        break;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;

int main(){
    string s;
    cin>>s;
    int tmp=0,ans=0;
    for(int i=0;i<3;i++){
        if(s[i]=='R') tmp++;
        else ans=max(ans,tmp),tmp=0;
    }
    ans=max(ans,tmp);
    printf("%d",ans);
}


Measured memory_bytes: 3712
#include <iostream>
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define li long ll
#define pp pair<ll, ll> 
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
#define pb push_back
#define llp(i, x, n) for (ll i = x; i < n; i++)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define fr first
#define ss second
#define mod 1000000007
using namespace std;
int main()
{
	fast;
    int n;
    cin>>n;
    ll a[n];
    llp(i,0,n)
    cin>>a[i];
    priority_queue<ll> pq;
    ll sum=0;
    pq.push(a[0]);
    for(int i=0;i<n;i++)
    {
    	if(pq.top()>=a[i])
    	sum=sum+pq.top()-a[i];
    	else
    	pq.push(a[i]);
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 6720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

int main(){
  double D, S,T; cin >> D >> T >> S;
  double T1 = D/S;
  if(T1 <= T) cout << "Yes" <<endl;
  else cout << "No" <<endl;
  return 0;
}

Measured memory_bytes: 3724
// AtCoder Beginner Contest 074
// B - Collecting Balls (Easy Version)
#include <bits/stdc++.h>
using namespace std;

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

  int x;
  int total = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x < k - x) {
      total += x * 2;
    } else {
      total += (k - x) * 2;
    }
  }

  cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef long long ll;
typedef vector<int> vi;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const int maxN = 5005;
 
int a, n;
 
int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	int fst = 1;
	REP(i, n) {
		cin >> a;
		if (a == fst) fst++;
	}
	if (fst == 1) {
		cout << "-1";
	} else {
		cout << n - fst + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
s=input()
z=[]
c=1
if n==1:
    print(1)
    exit()
for i in range(1,n):
    if s[i]==s[i-1]:
        c+=1
    else:
        z+=[c]
        c=1
z+=[c]
if s[0]=="0":
    z=[0]+z
if s[-1]=="0":
    z=z+[0]
lz=len(z)
pre=sum(z[0:2*k+1])
mx=pre
for i in range(2,lz-2*k,2):
    pre=pre-z[i-2]-z[i-1]+z[i+2*k-1]+z[i+2*k]
    if pre>mx:
        mx=pre
print(mx)


Measured memory_bytes: 4864
#include <stdio.h>

int i, j, k, n, A[100];

void pr(){ for(j=0;j<n;j++)printf("%d%c",A[j],j==n-1?'\n':' ');}
int main(){
	scanf("%d", &n);
	while(i < n) scanf("%d", &A[i++]);
	for(i = 0; i < n; i++){
		for(j = i, k = A[i]; j > 0 && k < A[j-1]; j--) A[j] = A[j-1];
		A[j] = k;
		pr();
	}
	return 0;
}

Measured memory_bytes: 600
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    int n;
    cin >> n;

    vec<ll> A(n);
    vec<ll> B(n);

    for (auto &e : A)
        cin >> e;
    for (auto &e : B)
        cin >> e;

    if (accumulate(A.cbegin(), A.cend(), 0ll) < accumulate(B.cbegin(), B.cend(), 0ll))
    {
        cout << -1 << endl;
        return 0;
    }

    ll minus{};
    ll minusCount{};

    vec<ll> diffs;
    for (int i = 0; i < n; ++i)
    {
        auto d = A[i] - B[i];
        if (d > 0)
        {
            diffs.push_back(d);
        }
        else if(d < 0)
        {
            minus += d;
            ++minusCount;
        }
    }

    sort(diffs.begin(), diffs.end(), std::greater<ll>());

    int index{};
    while (minus < 0)
    {
        minus += diffs[index];
            ++index;
    }

    cout << index + minusCount << endl;

    return 0;
}

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    ll H;
    cin >> H;
    int i = 0;
    ll ans = 0;
    while(H > 0){
        ans += 1ll<<i;
        H /= 2;
        i++;
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    int N, T;
    cin >> N >> T;
    set<pair<int, int>> costAndTimePairs;
    for (int i = 0; i < N; ++i)
    {
        int cost, time;
        cin >> cost >> time;
        costAndTimePairs.insert({ cost, time });
    }
    for (const auto &pair : costAndTimePairs)
    {
        if (pair.second <= T)
        {
            cout << pair.first << endl;
            return 0;
        }
    }
    cout << "TLE" << endl;
}

Measured memory_bytes: 256