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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
constexpr ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

int n;
void solve() {
    cin >> n;

    bool ok = false;
    reps(i, 9) reps(j, 9)
        if (i * j == n) { ok = true; break; }

    if (ok) cout << "Yes" << endn;
    else cout << "No" << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int j=0,k=100000,l=0;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(a==k)
      l++;
    else{
      j+=l/2;
      l=1;
      k=a;
    }
  }
  cout<<j+l/2<<endl;
}

Measured memory_bytes: 3536
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int L, R, d;
    cin >> L >> R >> d;
    // 出力
  if(R % d == 0){
  cout << (R-L)/d + 1 << endl;}
  else {
  cout << (R-L)/d << endl;}
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>

int main(){
	int i,j,k;
	int n;
	int b,f,r,v;
	int tenant[4][3][10];
	
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				tenant[i][j][k]=0;
			}
		}
	}
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d%d%d%d",&b,&f,&r,&v);
		tenant[b-1][f-1][r-1]+=v;
		
	}
	
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				printf(" %d",tenant[i][j][k]);
			}
			printf("\n");
		}
		if(i<3)printf("####################\n");
	}
	
	return 0;
}

Measured memory_bytes: 612
/**
 *   created: 28 April 2019  23:46:46
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) (c).begin,(c).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
// #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	// optimizeIO();
	int tc=1;
	// cin>>tc;
	for(int tt=0;tt<tc;tt++){
		string s;
		cin>>s;
		int res = 0;
		rep(i,0,s.size()){
			int temp=0;
			rep(j,i,s.size()){
				if(s[j]!='A' && s[j]!='C' && s[j]!='G' && s[j]!='T')
					break;
				else
					temp++;
			}
			res = max(res,temp);
		}
		cout<<res;
	}
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	string str, tmp;
	cin >> tmp >> str >> tmp;
	printf("A%cC\n", str[0]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int N; cin >> N;
  vector<ll> memo(N+1);
  vector<ll> A(N);
  for (auto& a : A) { cin >> a; }
  
  memo[0] = 3;
  ll res = 1;
  for (int i = 0; i < N; ++i) {
    auto a = A[i];
    res *= memo[a];
    res %= MOD;
    --memo[a];
    ++memo[a+1];
  }
  cout << res << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 1792
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, K = sc.nextInt()
    val D = Array.fill(K)(sc.nextInt())

    // N < 10^4 以下なので, 10^5 より小さい数 を使えば必ず買える金額が存在
    // 10^5 より小さい数の空間計算量は用意可能なので
    // [1,10^5)の範囲で {D_1, D_2, ..., D_k}の数が含まれないものだけを列挙する
    // そして N >= となる 最小の金額が達成する金額.

    def solve(N: Int, K: Int, D: Array[Int]): Int = {
      val MAX_DIGIT = 5
      val UPPER = 100000
      val LIKES = (0 to 9) filter (!D.contains(_))
      def dfs(stack: List[(Int, Int)], min: Int): Int =
        if (stack.nonEmpty) {
          val (digit, num) = stack.head
          if (digit <= MAX_DIGIT)
            dfs(LIKES.foldLeft(stack.tail)((stack, d) =>
              (digit + 1, num * 10 + d) :: stack), if (num >= N) min min num else min)
          else dfs(stack.tail, min)
        } else min
      dfs(LIKES.filter(_ != 0).map((1, _)).toList, UPPER)
    }

    println(solve(N, K, D))
  }

}


Measured memory_bytes: 40148
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int dp[4010][4010];
ll mod = 998244353;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	string s;
	cin >> s;
	int n = s.size();
	dp[0][0] = 1;
	rep(i, 2 * n) {
		rep(j, 2 * n + 1) {
			if (i < n) {
				int k = s[i] - '0' + j;
				if (i + 2 > k) {
					dp[i + 1][k] += dp[i][j];
					if (dp[i + 1][k] > mod) dp[i + 1][k] -= mod;
				}
				if (k > 0) {
					dp[i + 1][k - 1] += dp[i][j];
					if (dp[i + 1][k - 1] > mod) dp[i + 1][k - 1] -= mod;
				}
			}
			else {
				if (2 * n - i - j > 0) {
					dp[i + 1][j] += dp[i][j];
					if (dp[i + 1][j] > mod) dp[i + 1][j] -= mod;
				}
				if (j > 0) {
					dp[i + 1][j - 1] += dp[i][j];
					if (dp[i + 1][j - 1] > mod) dp[i + 1][j - 1] -= mod;
				}
			}
		}
	}
	cout << dp[2 * n][0] << endl;
}

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

string shuffle(string str, int h){
    string str1 = str.substr(0,h);
    string str2 = str.substr(h, str.size()-h);
    return str2 + str1;
}

int main(){
    string card;
    int i, h;
    
    while(1){
        cin>>card;
        if (card=="-") break;
        
        cin>>i;
        for(int k=0; k<i; k++){
            cin>>h;
            card=shuffle(card,h);
        }
        cout<<card<<endl;
    }
    return 0;
}


Measured memory_bytes: 3148
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
const double PI = acos(-1);  // PI = 3.141593...

int main() {
    double a, b, c, rad, s, l, h;
    cin >> a >> b >> c;
    rad = c * PI / 180;
    s = a*b*sin(rad)/2;
    h = b*sin(rad);
    l = a+b+sqrt(h*h + (a-b*cos(rad))*(a-b*cos(rad)));
    printf("%.8lf\n", s);
    printf("%.8lf\n", l);
    printf("%.8lf\n", h);
    return 0;
}


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

const int  maxn=200008;
int n,e; 
int T;
int a[maxn]; 
int q[maxn];
long long f[maxn];


int main(){
  cin>>n>>e>>T;
  for (int i=1;i<=n;i++)
    scanf("%d",&a[i]);
  long long mn=2e9;
  int r=0; int l=0;
  for (int i=1;i<=n;i++)
  {
    r++;
    q[r]=i;
    while (2*(a[i]-a[q[l]])>=T)
      {
        mn=min(mn,f[q[l]-1]-2*a[q[l]]);
        l++;
      }
    f[i]=f[q[l]-1]+T;
    f[i]=min(f[i],2*a[i]+mn);
  }
  cout<<f[n]+e<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cctype>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <complex>
#include <cstring>
#include <set>
using namespace std;
#define loop(i,a,b) for(int i=a; i<b; i++)
#define rep(i,a) loop(i,0,a)

int input[1111][3], res[1111];

int main(){
    int a,b,c;
    while(cin>>a>>b>>c && a){
        int n; cin>>n;
        rep(i,n){
            rep(j,3)cin >> input[i][j];
            cin>>res[i];
        }

        bool ok[1111]={}, bad[1111]={};
        rep(k,2){
            rep(i,n){
                int a=0,b=0;
                int x,y,z;
                tie(x,y,z)=tie(input[i][0],input[i][1],input[i][2]);
                for(int j : {x,y,z}){
                    if(ok[j])a++;
                    if(bad[j])b++;
                }
                if(res[i]){
                    if(a!=3){
                        ok[x]=ok[y]=ok[z]=true;
                    }
                }else{
                    if(a==2 && b!=1){
                        for(int j : {x,y,z}){
                            if(!ok[j])bad[j]=true;
                        }
                    }
                }
            }
        }
        for(int i=1;i<=a+b+c;i++){
            if(ok[i] && !bad[i])cout<<1;
            else if(!ok[i] && bad[i])cout<<0;
            else cout<<2;
            cout<<endl;
        }
    }
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    ll t1, t2;
    ll a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    ll dis1 = t1 * (a1 - b1);
    ll dis2 = t1 * (a1 - b1) + t2 * (a2 - b2);

    if (dis2 == 0) {
        cout << "infinity" << endl;
        return 0;
    }
    ll s1 = dis1 / llabs(dis1);
    ll s2 = dis2 / llabs(dis2);
    if (s1 * s2 > 0)
        cout << "0" << endl;
    else if (s1 * s2 < 0) {
        if (llabs(dis2) > llabs(dis1)) {
            cout << 1 << endl;
            return 0;
        }
        // cout << llabs(dis1) << endl << llabs(dis2) << endl;
        if (llabs(dis1) % llabs(dis2) == 0) {
            cout << (llabs(dis1)/llabs(dis2))*2 << endl;
        } else {
            cout << (llabs(dis1)/llabs(dis2))*2+1 << endl;
        }

    }
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
bool dp[30009][4][1009];
string S; int N;
 
int main() {
	cin >> N >> S;
	dp[0][0][0] = true;
	
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= 3; j++) {
			for (int k = 0; k < 1000; k++) {
				if (dp[i][j][k] == false) continue;
				
				dp[i + 1][j][k] = true;
				if (j <= 2) {
					dp[i + 1][j + 1][k * 10 + (S[i] - '0')] = true;
				}
			}
		}
	}
	
	int cnt = 0;
	for (int i = 0; i < 1000; i++) {
		if (dp[N][3][i] == true) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 121860
N = int(input())
A = [int(i) for i in input().split()] 
B = [int(i) for i in input().split()] 
C = [int(i) for i in input().split()] 
D = 0
for i in range(N):
	if i <= N-2:
		D += B[A[i]-1]
		if A[i+1]-1 == A[i]:
			D += C[A[i]-1]
	else:
		D += B[A[i]-1]

print(D)

Measured memory_bytes: 3064
import java.util.*;
 
class Main {
    static int H,W,N;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        H = scan.nextInt();
        W = scan.nextInt();
        N = scan.nextInt();
        int result = 0;
        if(W>H){
            for(int i=1;i<H+1;i++){
                result = W*i;
                if(result>=N){
                    result = i;
                    break;
                }
            }
        }
        else{
            for(int i=1;i<W+1;i++){
                result = H*i;
                if(result>=N){
                    result = i;
                    break;
                }
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 24020
N = int(input())
B = list(map(int,input().split()))
A = [0 for i in range(N)]

A[0] = B[0]
A[N-1] = B[N-2]

for i in range(N-2):
    A[i+1] = min(B[i],B[i+1])

print(sum(A))


Measured memory_bytes: 3060
N, A, B = map(int, input().split())
h_list = [int(input()) for _ in range(N)]
h_list.sort(reverse=True)
h_max = h_list[0]


def add_attack(t):
    attack = B * t
    for i in range(N):
        h = h_list[i]
        h -= attack
        if h > 0:
            t -= (h + (A - B) - 1) // (A - B)
            if t < 0:
                return False
    return True


t_min = 1
t_max = (h_max + B - 1) // B

while t_min < t_max - 1:
    t_mid = (t_min + t_max) // 2
    if add_attack(t_mid):
        t_max = t_mid
    else:
        t_min = t_mid
print(t_max)


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

int main(void){
	long long A,B,N,res=LLONG_MAX;
	cin>>A>>B>>N;
	rep1(i,N)rep1(j,N){
		if(B*j%i==0){
			res = min(res,abs(B*j/i - A));
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3056
import math
def main():
    N = int(input())
    info = []
    for _ in range(N-1):
        C, S, F = map(int, input().split())
        info.append([C, S, F])
    for i in range(N-1):
        t = info[i][1] + info[i][0]
        j = i+1
        while j < N-1:
            if t <= info[j][1]:
                t = info[j][1] + info[j][0]
            else:
                k = math.ceil((t-info[j][1])/info[j][2])
                t = k * info[j][2] + info[j][1] + info[j][0]
            j += 1
        print(t)
    print(0)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
import java.util.*;
public class Main {

	private static final int m = 0;
	public static void main(String[] args) {
 Scanner sc=new Scanner(System.in);
int 	n=sc.nextInt();
String s=sc.next();
char ss[]=(s+s.charAt(0)+s.charAt(1)).toCharArray();

int a[]=new int[n+2];  		// 0:sheep 1:wolf
for(int i=0;i<=1;i++) {
	for(int j=0;j<=1;j++) {
	a[0]=i;
	a[1]=j;
	for(int k=2;k<=n+1;k++) {
		if(a[k-1]==0) {
			//previous sheep
			a[k]=ss[k-1]=='o'?a[k-2]:(a[k-2]+1)%2;
		}else {
			a[k]=ss[k-1]=='x'?a[k-2]:(a[k-2]+1)%2;
		}
	}
	if(a[0]==a[n]&&a[1]==a[n+1]) {
		for(int  k=0;k<n;k++) {
			System.out.print(a[k]==0?'S':'W');
		}
		return;
	}

	}
}
System.out.println(-1);



}
	}


Measured memory_bytes: 54200
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
//============================================================================
#include <bits/stdc++.h>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace std;
const int N = 1e2 + 5, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };

int main() {
#ifdef ONLINE_JUDGE
    FAST;
#endif
	int n, mx, prv;
	ll ans = 0;
	cin >> n >> mx >> prv;
	lp(i,2,n)
	{
		int x;
		cin >> x;
		int z = max(0, (x + prv) - mx);
		x = max(0, x - z);
		ans += z;
		prv = x;
	}
	f(ans);
	return 0;
}

Measured memory_bytes: 256
s = str(input())
k = int(input())
len_s = len(s)
cnt_1 = 0
for i in range(len_s):
    if s[i] == '1':
        cnt_1 += 1
    else:
        moji = s[i]
        break
if cnt_1 >= k:
    print(1)
else:
    print(s[i])

Measured memory_bytes: 9176
#include <iostream>
using namespace std;
int main()
{
  int n,k,a[200000],b[200000],ma=0;
  cin>>k>>n;
  cin>>a[1];
  for(int i=2;i<n+1;i++){
    cin>>a[i];
    b[i-1]=a[i]-a[i-1];
    ma=max(b[i-1],ma);
    if(i==n){
      b[n]=k-a[n]+a[1];
      ma=max(b[n],ma);
      break;
    }
    
  }
  cout<<k-ma<<endl;
  return 0;
}
  
  

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {
	
	int n;
	cin >> n;
	int t = 0;
	vector<int>p;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		p.push_back(x);
		t = max(t, x);
	}
	vector<int>d;
	d = p;
	sort(d.begin(), d.end());

	for (int i = 0; i < n; i++) {
		if (p[i] == t)cout << d[n - 2] << endl;
		else cout << t << endl;;
		
	}



	return 0;

}

Measured memory_bytes: 3316
let rec range n = if n=0 then [] else n::(range (n-1)) in
let n = read_int () in
  range (int_of_float (sqrt (float_of_int n)))
  |> List.filter (fun i-> (n mod i)=0)
  |> List.map (fun i-> (max i (n / i)))
  |> List.map (fun i-> 1 + int_of_float ( log10 (float_of_int i)))
  |> List.fold_left min max_int
  |> print_int

Measured memory_bytes: 7936
N, M = map(int, input().split())
A = set(int(input()) for i in range(M))
x = [0] * (N+1)
x[0] = 1
 
for i in range(1, N+1): 
  if i in A: x[i] = 0
  else:
    x[i] = (x[i-1] + x[i-2])%(10**9+7)
    
print(x[N])

Measured memory_bytes: 11884
#include <iostream>
#include <iomanip> 
#include <cstdlib>
#include <cmath>
#include<map>
#include<string.h>
#include <algorithm>
#include <bits/stdc++.h> 
#include<vector>

using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define replb(i,a,b) for(ll i=a;i>=b;i--)
#define repl(i,a,b) for(ll i=a;i<b;i++)
#define repit(arr)  for(auto it=arr.begin();it!=arr.end();it++)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define seti set <int>
#define setl set <ll>
#define dseti set <int, greater <int> >
#define dsetl set <ll, greater <ll> >
#define mseti multiset <int>
#define msetl multiset <ll>
#define dmseti multiset <int, greater <int> >
#define dmsetl multiset <ll, greater <ll> >
#define sortA(arr)   sort(arr.begin(),arr.end())
#define ssort(arr) stable_sort(arr.begin(),arr.end())
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define castl static_cast<ll>
int gcd(int a,int b){
    if (a < b) swap(a, b);
    if (b == 0) return a;
    else return gcd(b, a % b);
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int k,n,x;cin>>n>>k;vi v;
    rep(i,0,n){
        cin>>x;v.pb(x);
    }
    sortA(v);int sum=0;
    rep(i,0,k){
        sum+=v[i];
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
struct fastio { fastio () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } _io;
template<class T, class U> bool chmax(T& a, const U &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U &b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int n;
	cin >> n;
	int a = 0, b = 0, c = 0, d = 0;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (s == "AC") a++;
		if (s == "WA") b++;
		if (s == "TLE") c++;
		if (s == "RE") d++;
	}

	cout << "AC x " << a << '\n';
	cout << "WA x " << b << '\n';
	cout << "TLE x " << c << '\n';
	cout << "RE x " << d << '\n';

	return 0;
}

Measured memory_bytes: 3664
function Main(input) {
  input = input.split("\n");
	S = input[0];
	T = input[1];

	inS = new Array(26).fill(-1);
  inT = new Array(26).fill(-1);
	var first = "a", last = "z";
  var ans="Yes";
  for(i=0;i<S.length;i++){
    Ssub=S.substr(i,1);
    Tsub=T.substr(i,1);
    if(inS[Ssub.charCodeAt(0)-first.charCodeAt(0)]!=-1){
      if(inS[Ssub.charCodeAt(0)-first.charCodeAt(0)]!=Tsub){
        ans="No";
      }
    }
    if(inT[Tsub.charCodeAt(0)-first.charCodeAt(0)]!=-1){
      if(inT[Tsub.charCodeAt(0)-first.charCodeAt(0)]!=Ssub){
        ans="No";
      }
    }
    if(inS[Ssub.charCodeAt(0)-first.charCodeAt(0)]<0){
      inS[Ssub.charCodeAt(0)-first.charCodeAt(0)]=Tsub;
    }
    if(inT[Tsub.charCodeAt(0)-first.charCodeAt(0)]<0){
      inT[Tsub.charCodeAt(0)-first.charCodeAt(0)]=Ssub;
    }
  }

	var counter = function(str,seq){
		return str.split(seq).length - 1;
  }
  
  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;

map<string,ll> cek;

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

    int n;
    cin >> n;


    for (int i=0;i<n;i++){
        string s;
        cin >> s;
        sort(s.begin(),s.end());

        cek[s]++;
    }

    ll ans=0;
    for (auto x : cek){
        ans+=(x.se)*(x.se-1)/2;
    }

    cout << ans << el;  

    return 0;
}

Measured memory_bytes: 11264
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();
		
		int y0 = sc.nextInt(); //starting pos
		int x0 = sc.nextInt();
		
		String s1 = sc.next();
		String s2 = sc.next();
		n = s1.length();
		
		int[] hor1 = new int[n];
		int[] hor2 = new int[n];
		int[] ver1 = new int[n];
		int[] ver2 = new int[n];
		
		for(int i = 0; i < n; i++)
		{
			if(s1.charAt(i)=='L')
				hor1[i] = -1;
			if(s1.charAt(i)=='R')
				hor1[i] = 1;
			if(s2.charAt(i)=='L')
				hor2[i] = -1;
			if(s2.charAt(i)=='R')
				hor2[i] = 1;
			if(s1.charAt(i)=='U')
				ver1[i] = -1;
			if(s1.charAt(i)=='D')
				ver1[i] = 1;
			if(s2.charAt(i)=='U')
				ver2[i] = -1;
			if(s2.charAt(i)=='D')
				ver2[i] = 1;			
		}
		
		//horizontal first
		int satr = w+1; //can push to right from here
		int satl = 0; //can push to left from here
		for(int i = n-1; i >= 0;)
		{
			//p1
			if(hor1[i] == 1)
				satr--;
			if(hor1[i] == -1)
				satl++;
			
			if(satr - satl <= 1)
			{
				System.out.println("NO");
				return;
			}
//			System.out.println("i " + i + "a: " + satl + " " + satr);
			i--;
			if(i<0)break;
			//p2
			if(hor2[i] == 1)
			{
				satl--;
			}
			if(hor2[i] == -1)
				satr++;
			satr = Math.min(satr, w+1);
			satl = Math.max(satl, 0);

//			System.out.println("i " + i + "b: " + satl + " " + satr);
		}
		if(satr - satl <= 1 || satl >= x0 || satr <= x0)
		{
			System.out.println("NO");
			return;
		}
//		System.out.println(satl + " " + satr);
		
		satr = h+1; //can push to right from here
		satl = 0; //can push to left from here
		for(int i = n-1; i >= 0;)
		{
			//p1
			if(ver1[i] == 1)
				satr--;
			if(ver1[i] == -1)
				satl++;
			
			if(satr - satl <= 1)
			{
				System.out.println("NO");
				return;
			}
//			System.out.println("i " + i + "a: " + satl + " " + satr);
			i--;
			if(i<0)break;
			//p2
			if(ver2[i] == 1)
			{
				satl--;
			}
			if(ver2[i] == -1)
				satr++;
			satr = Math.min(satr, h+1);
			satl = Math.max(satl, 0);

//			System.out.println("i " + i + "b: " + satl + " " + satr);
		}
		if(satr - satl <= 1 || satl >= y0 || satr <= y0)
		{
			System.out.println("NO");
			return;
		}		
		
		System.out.println("YES");
	}

}


Measured memory_bytes: 33168
#include <bits/stdc++.h>
using namespace std;
int V;
vector<int> G[111111];
int parent[111111];
int visit[111111];
int cnt,depth;
void dfs(int x){
    if(x==V)depth=cnt;
    cnt++;
    for(int i:G[x]){
        if(!parent[i]){
            parent[i]=x;
            dfs(i);
        }
    }
    cnt--;
}
int dfs2(int x){
    visit[x]++;
    int find=1;
    for(int i:G[x])
        if(!visit[i])
            find+=dfs2(i);
    return find;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin>>V;
    for(int i=0;i<V-1;i++){
        int x,y;
        cin>>x>>y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    parent[1]=-1;
    dfs(1);
    int dist = (depth+1)/2;
    int middle=V;
    while(dist--){
        middle=parent[middle];
    }
    visit[middle]++;
    int find = dfs2(V);
    if(find<V-find){
        cout<<"Fennec";
    }
    else cout<<"Snuke";
    return 0;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;



template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int N, M, K;
vector<vector <int> > graph;
vector<int> group;
vector<int> group_count;
vector<vector <int> > block;



int main() {
    cin >> N >> M >> K;
    graph.resize(N);
    block.resize(N);
    group.resize(N);
    group_count.resize(N+10);
    rp(i, 0, M) {
        int a, b;
        scanf("%d%d", &a, &b);
        a--; b--;
        graph.at(a).emplace_back(b);
        graph.at(b).emplace_back(a);
    } 
    rp(i, 0, K) {
        int c, d;
        scanf("%d%d", &c, &d);
        c--; d--;
        block.at(c).emplace_back(d);
        block.at(d).emplace_back(c);
    }

    int g = 1;
    rp(i, 0, N) {
        if(group.at(i) == 0) {
            queue<int> q;
            q.push(i);
            while(!q.empty()){
                int s = q.front(); q.pop();
                if(group.at(s) == 0) {
                    group.at(s) = g;
                    group_count.at(g) ++;
                    for(auto x: graph.at(s)) {
                        if(group[x] == 0) q.push(x);
                    }
                }
            }
            g++;
        }
    }

    rp(i, 0, N) {
        int res = group_count[group[i]] - 1 - int(graph[i].size());
        for(auto x: block[i]) {
            if(group[i] == group[x]) res --;
        }
        printf("%d ", res);
    }
    cout << endl;
    return 0;

}

Measured memory_bytes: 15204
N = int(input())
csf = [0]*(N-1)
for i in range(N-1):
    csf[i] = list(map(int,input().split()))

for i in range(N-1):
    ans = 0
    ans += csf[i][1] + csf[i][0]
    for j in range(i+1, N-1):
        if ans >= csf[j][1]:
            if ans % csf[j][2] == 0:
                ans += csf[j][0]
            else:
                ans += csf[j][2] - (ans % csf[j][2]) + csf[j][0]
        else:
            ans = csf[j][1] + csf[j][0]
    
    print(ans)
print(0)


Measured memory_bytes: 42220
def main():
  import itertools
  n,m=map(int,input().split())
  li=[list(map(int,input().split()))[1:] for _ in range(m)]
  p=tuple(map(int,input().split()))
  
  q=set(sum(li,[]))
  r=set(range(1,n+1))
  v=r-q
  
  ans=0
  
  for i in range(0,len(q)+1):
    for s in itertools.combinations(q,i):
      s=set(s)
      t=all(len(s&set(u))%2==w for u,w in zip(li,p))
      if t==True:
        ans+=2**(len(v))
   
  print(ans)
  
  
if __name__=="__main__":
  main()

Measured memory_bytes: 3064
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
p.reverse()
q = list(map(int, input().split()))
q.sort()
q.reverse()
r = list(map(int, input().split()))
r.sort()
r.reverse()

p = p[:x]
q = q[:y]


arr = p + q
arr.sort()
#print(arr)
#print(r)

for i in range(min(len(arr),len(r))):
    if arr[i] <= r[i]:
        arr[i] = r[i]

print(sum(arr))



Measured memory_bytes: 23328
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  if(K==1) cout << 0 << endl;
  else cout << N-K << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
	int N;
	scanf("%d", &N);
	vector<int> dist(9, 0);
	for (int i = 0; i < N; i++) {
		int rate;
		scanf("%d", &rate);
		if (rate < 3200) {
			for (int j = 7; j >= 0; j--) {
				if (rate >= j * 400) {
					dist.at(j)++;
					break;
				}
			}
		} else {
			dist.at(8)++;
		}
	}

	int min_col = 0;
	for (int i = 0; i < 8; i++) {
		min_col += dist.at(i) > 0;
	}
	printf("%d %d\n", min_col == 0 ? 1 : min_col, min_col + dist.at(8));
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;i++)
#define REP1(i,n) for(long long i=1;i<=n;i++)
#define REP2D(i,j,h,w) for(long long i=0;i<h;i++) for(long long j=0;j<w;j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=h;i++) for(long long j=1;j<=w;j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) (a.begin()),(a.end())
#define RANGE(a) (a),(a+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<a<<endl;
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);
#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 100000
//---------------------

string s;
int data[30];
int main(){
  	cin >>s;
  	ZERO(data);
  	REP(i,4) data[s[i]-'A']++;
  	
  	int ct=0;
  	
  	bool ret=true;
  	
  	REP(i,30){
  		if(data[i]) {ct++;if(data[i]!=2){ret=false;break;}}
  		if(ct>2){ret=false;break;}
  	}
  	YNPRT(ret);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>

using namespace std;
typedef long long int ll;

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if(n == 2)
  {
    cout << (a[1] - a[0]) << endl;
    return 0;
  }
  auto calc = [n](vector<ll> a)
  {
    deque<ll> deq;
    int r = 0;
    int l = n - 1;
    bool flag = false; 
    deq.push_front(a[l--]);
    deq.push_front(a[r++]);
    deq.push_front(a[l--]);
    while(l >= r)
    {
      if(flag)
      {
        //大きいものを追加
        if(r < l - 1)
        {
          deq.push_front(a[l--]);
          deq.push_back(a[l--]);
        }else{
          ll rc = deq.front();
          ll lc = deq.back();
          if(abs(rc - a[l]) < abs(lc - a[l]))
          {
            deq.push_back(a[l--]);
          }else{
            deq.push_front(a[l--]);
          }
        }
      }else{
        //小さいものを追加 
        if(r + 1 < l)
        { 
          deq.push_front(a[r++]);
          deq.push_back(a[r++]);
        }else{
          ll rc = deq.front();
          ll lc = deq.back();
          if(abs(rc - a[r]) < abs(lc - a[r]))
          {
            deq.push_back(a[r++]);
          }else{
            deq.push_front(a[r++]);
          }
        }
      }
      flag = !flag;
    }
    ll result = 0;
    for(int i = 0; i < n - 1; i++)
    {
      result += abs(deq[i] - deq[i + 1]);
    }
    return result;
  };
  ll result1 = calc(a);
  reverse(a.begin(), a.end());
  ll result2 = calc(a);
  ll result = result1 < result2 ? result2 : result1;
  cout << result << endl;
	return 0;
}


Measured memory_bytes: 2688
n = int(input())

print(0, flush=True)
res = input()
if res == "Vacant":
    exit()

left = 0
right = n
gen = res


while True:
    mid = (left + right) // 2
    print(mid, flush=True)
    res = input()

    if res == "Vacant":
        exit()

    if gen == res:
        if (mid - left) % 2:
            right = mid
        else:
            left = mid
    else:
        if (mid - left) % 2:
            left = mid
            gen = res
        else:
            right = mid

Measured memory_bytes: 9204
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void main(string[] args){ args ~= ["", ""]; string cmd = args[1]; if(cmd == "-debug") DEBUG = 1;
if(cmd == "-gen") gen; else if(cmd == "-jury") jury; else solve; } 
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void gen(){}
void jury(){}
void solve(){
  string s = scan;
  if(s[$ - 1] == 's') s ~= 'e';
  (s ~ 's').print;
}

Measured memory_bytes: 3256
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main()
{	
	int n;
	cin>>n;
	if(n%2)
		cout<<setprecision(20)<<ceil((double)n/2)/(double)n<<endl;
	else
		cout<<0.5<<endl;
	return 0;
}




Measured memory_bytes: 256
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)
N,M = map(int,input().split())

d = defaultdict(lambda:[])

for _ in range(M):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    d[x].append(y)

dp = [-1]*N

def dist(s):
    if dp[s] >= 0:
        return dp[s]
    if d[s] == []:
        dp[s] = 0
        return 0
    res = 0
    for t in d[s]:
        res = max(res,1+dist(t))
    dp[s] = res
    return res

ans = 0
for i in range(N):
    ans = max(ans,dist(i))

print(ans)

Measured memory_bytes: 162052
#pragma GCC optimize(2)
#pragma GCC optimize(3)   
#include<bits/stdc++.h>
#include<cstdlib>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds; 
//#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef vector < ll > vl;
typedef vector < vl > vvl;
typedef pair < ll, ll > pll;
typedef long double ld;
typedef vector < pair < ll, ll > > vpll;
#define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define forn(i,n) for (ll i = 0; i < n; i++)
#define fo(i,n) for (ll i = 1; i <= n; i++)
#define fore(i,l,r) for (ll i = l; i <= r; i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(c) c.begin(), c.end()
#define go(c,it) for(auto it=(c).begin(); it!=(c).end(); it++)
//#define back(c,it) for(auto it=(c).rbegin(); it!=(c).rend(); it++)
#define fi first
#define se second
#define MOD 998244353
#define MAX 1000000007
#define N 2000009
#define N1 100007
ll power(ll a,ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;}a=(a*a)%MOD;b>>=1;}return res;}
ll fact[500009];
ll fermat_inv(ll y){return power(y,MOD-2);}
ll nCrMod(ll n, ll r){ ll p=fact[n];ll q=(fact[r]*fact[n-r])%MOD;return (p*fermat_inv(q))%MOD;} 
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
const ld PI = acos(-1.0);
vl g[N1];


  int main(){
      #ifndef ONLINE_JUDGE
      freopen("input.cpp","r",stdin);
      freopen("output.cpp","w",stdout);
      #endif
      Boost();
      int t;
      //cin>>t;
      t=1;
      int t1=t;
      while(t--)
      {
        ll n;
        cin>>n;
        ll a[n+1];
        fo(i,n)
        cin>>a[i];
        sort(a+1,a+n+1);
        ll ans=a[n];
        int c=0;
        ll z=n-1;
        ll i;
        for(i=n-2;i>=1;i--)
        {
          ans+=a[z];
          c++;
          if(c==2)
          {
            c=0;
            z--;
          }
        }
        cout<<ans<<endl;
      }
      
      return 0;
  }

Measured memory_bytes: 7492
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

vector<int> edges[2100];

struct UnionFind {  
  vector<int> par,sizes;                     // par[i]:iの親の番号(ex)par[3]=2 : 3の親が2
  UnionFind(int n) : par(n),sizes(n,1)  {    //最初は全てが根であるとして初期化
    for(int i=0; i<n; i++){ par[i]=i; }  
  }
  int root(int x) {                       //xが属する木の根を再帰で得る:root(x)={xの木の根}
    if(par[x]==x){ return x; }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {                 // xとyの木を併合
    int rx = root(x);                        //xの根をrx
    int ry = root(y);                        //yの根をry
    if(rx == ry){ return; }                  //xとyの根が同じ(=同じ木にある)時はそのまま
    if(sizes[rx]<sizes[ry]){ swap(rx, ry); } //xの木をおおきくする
    par[ry] = rx; 
    sizes[rx] += sizes[ry];                  //sizes[ry]はもう使わない
  }
 
  bool check(int x, int y) {                 // x,yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
  
  int size(int x){                           //xが含まれる木の大きさを返す
    return sizes[root(x)];
  }
};

bool dfs(int p, set<int> &a){
  for(auto to:edges[p]){
    if(a.find(to)!=a.end()){ return true; }
    a.insert(to);
    if(dfs(to,a)){ return true; } else { a.erase(to); }
  }
  return false;
}
 
int main(){
  int n,m;
  cin >> n >> m;
  UnionFind uf(n);
  vector<P> aded;
  
  for(int i=0; i<m; i++){
    int x,y; cin >> x >> y; x--; y--;
    if(uf.check(x,y)){
      aded.emplace_back(x,y);
    } else {
      uf.unite(x,y);
      edges[x].emplace_back(y);
    }
  }
  set<int> shortest;
  int cnt=inf;
  for(auto tmp:aded){
    set<int> ans;
    ans.insert(tmp.F);
    ans.insert(tmp.S);
    if(dfs(tmp.S,ans)){
      if(ans.size()<cnt){
        cnt=ans.size();
        shortest = ans;
      }
    }
  }
  if(cnt!=inf){
      cout << shortest.size() << endl;
      for(auto anno:shortest){cout << anno+1 << endl;}
      return 0;
  }
  cout << -1 << endl;
  return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    ll Q; cin >> Q;
    REP(i,Q){
        ll A,B; cin >> A >> B;
        if(A == B){
            cout << 2*(A-1) << endl;
            continue;
        }
        if(A > B) swap(A,B);
        ll l = 1, r = 1000000000, n = (l+r) / 2;
        while(r-l > 1){
            if(A*B/n >= n) l = n;
            else r = n;
            n = (l+r)/2;
        }

        if((A*B/l)*l == A*B && l*l != A*B){
            if(A*B/l-1 == l) cout << 2*(l-1) << endl;
            else cout << 2*l-1 << endl;
        }
        else if(l*l == A*B){
            cout << 2*(l-1)-1 << endl;
        }
        else if(A*B/l == l){
            cout << 2*(l-1) << endl;
        }
        else{
            cout << 2*l-1 << endl;;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
int main(){
    int n,k,q;
    cin >> n >> k >> q;
    int a[n];
    int b;
    rep(i,n) a[i] = k - q;
    rep(i,q){
        cin >> b;
        b--;
        a[b]++;
    }
    rep(i,n){
        if(a[i] > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int x,n,ok;
int main()
{
    cin>>n;
    ok=1;
    for(int i=1;i<=n && ok==1;i++)
    {
        cin>>x;
        if(x%2==0 && x%3 && x%5)
            ok=0;
    }
    if(ok)
        cout<<"APPROVED";
    else
        cout<<"DENIED";
    return 0;
}

Measured memory_bytes: 256
def gcd(a:int, b:int):
    if b == 0:
        return a
    
    return gcd(b,a%b)

def main():
    while 1:
        try:
            a = list(map(int, input().split()))
            b = gcd(a[0],a[1])
            c = a[0]/b*a[1]
            print('%s %d' % (b,c))
        except:
            break
            
if __name__ == "__main__":
    main() 



Measured memory_bytes: 5600