akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e,ans = 0,n;
  string s,ss,sss;
  vi A(5);
  for(auto &a:A){cin>>a;}
  for(int i=0;i<5;i++){
    if(i+1 != A[i])cout<<i+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
using namespace std;
 
int main() 
{
  int h,w;
  int i,j;
  while(true){
    cin >> h >> w;
    if(h == 0 && w == 0){
      return 0;
    }
    for(i = 0;i < h;i++){
      if(i == 0 || i == h-1){
        for(j = 0;j < w;j++){
          cout << '#';
        }
        cout << "\n";
      }else{
        for(j = 0;j < w;j++){
          if(j == 0||j == w-1){
            cout << '#';
          }else{
            cout << '.';
          }
        }
        cout << "\n";
      }
    }
    cout << "\n";
  }
}


Measured memory_bytes: 3068
perimeter, n = map(int, input().split())
houses = list(map(int, input().split()))

e = []
max = 0

for i in range(n-1) :
  e.append(houses[i + 1] - houses[i])
e.append(perimeter - houses[n-1] + houses[0])

for i in range(n):
  if e[i] > max:
    max = e[i]

print(perimeter - max)


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

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    int dpl[n + 1], dpr[n + 1];
    dpl[0] = 0;
    dpr[0] = 0;
    int last = -10000000;
    for (int i = 1; i <= n; ++i) {
        if (s[i - 1] == 'x') dpl[i] = dpl[i - 1];
        else if (last + c < i) {
            last = i;
            dpl[i] = dpl[i - 1] + 1;
        }
        else dpl[i] = dpl[i - 1];
    }
    last = -10000000;
    for (int i = 1; i <= n; ++i) {
        if (s[n - i] == 'x') dpr[i] = dpr[i - 1];
        else if (last + c < i) {
            last = i;
            dpr[i] = dpr[i - 1] + 1;
        }
        else dpr[i] = dpr[i - 1];
    }
    //for (int i = 0; i <= n; ++i) cout << dpr[i] << " ";
    for (int i = 0; i < n; ++i) {
        int left = i;
        int right = n - i - 1;
        if (s[i] == 'o'  && dpl[left] + dpr[right] + 1 == k) cout << i + 1 << endl;
    }
    return 0;
}

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

int main()
{
	char str[10];
	char arr[6];
	while(gets(str)!=NULL)
	{

		strncpy(arr,str,4);
		if(strcmp(arr,"YAKI")==0)
			printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << '\n';
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll a, b, c;
  cin >> a >> b >> c;
  if(c-b-a <= 0) Pr(0);
  Pr(4*a*b < (c-b-a)*(c-b-a));
}


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

int main() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    vector<ll> l(n,-1),r(n,-1);
    l[0]=a[0];
    r[0]=a[n-1];
    rep(i,n-1){
        l[i+1]=max(a[i+1],l[i]);
        r[i+1]=max(a[n-2-i],r[i]);
    }
    rep(i,n){
        if(i==0){
            cout<<r[n-2]<<endl;
        }else if(i==n-1){
            cout<<l[n-2]<<endl;
        }else{
            cout<<max(l[i-1],r[n-2-i])<<endl;
        }
    }
}

Measured memory_bytes: 6272
import numpy as np

X, N = map(int, input().split())
P = np.array(list(map(int, input().split())))

P = P - X

for i in range(0, X + 1):
    if i not in P or -i not in P:
        if -i not in P:
            ans = X - i
        else:
            ans = X + i
        break

print(ans)


Measured memory_bytes: 27348
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int X; cin >> X;
    int x = sqrt(X);
    int ans = 1;
    for(int i=2; i<=x; i++){
        int count = 1;
        while(true){
            if(pow(i, count) > X) break;
            if(pow(i, count) >= ans) ans = pow(i,count);
            count++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll m;
    cin >> n >> m;
    vl a(n);
    vd p(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        cin >> p[i];
    }
    double two[21];
    two[0] = 1.0;
    rep(i,20){
        two[i+1] = two[i] * 2;
    }
    double ans = 0;
    srep(i,1,(1 << n)){
        double res = 1.0;
        ll val = 1;
        bool flag = true;
        rep(j,n){
            if((i >> j) & 1){
                res *= p[j]/100.0;
                if(flag){
                    ll g = gcd(val,a[j]);
                    double ch = val;
                    if(ch/g*a[j] > m+1000000LL){
                        flag = false;
                        break;
                    }else{
                        val = val/g*a[j];
                    }
                }
            }
        }
        if(flag){
            // show(val);
            int num = __builtin_popcount(i);
            res *= m/val;
            // show(res);
            // res *= two[n-num];
            if(num % 2){
                ans += res;
            }else{
                ans -= res;
            }
        }
    }
    printf("%.12f\n",ans);
    return 0;
}

Measured memory_bytes: 3312
class BiteEat:
    def __init__(self):
        self.N, self.L = map(int, input().split())

    def __taste(self, i):
        return self.L + i - 1

    def cal(self):
        first = self.__taste(1)
        last = self.__taste(self.N)
        total = (first + last) * self.N // 2

        if first >= 0:
            print(total - first)
        elif last <= 0:
            print(total - last)
        else:
            print(total)


biteEat = BiteEat()
biteEat.cal()


Measured memory_bytes: 3060
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const n = Number(stdin.split('\n')[0])

const [, ...rest] = stdin.split('\n').filter(e => e)

const txy = rest.map(e => e.split(' ').map(Number))

let target = [0, 0]

const res = _ => {
  for (let i = 0; i < txy.length; i++) {
    const reachable = evalPlan(target, txy[i])

    if (reachable) {
    } else {
      return 'No'
    }
  }
  return 'Yes'
}

const evalPlan = (prev, [t, x, y]) => {
  const mDiff = Math.abs(x - prev[0]) + Math.abs(y - prev[1])
  const tDiff = t - prev[0]

  if (mDiff > tDiff) return false

  return (tDiff - mDiff) % 2 === 0
}

console.log(res())


Measured memory_bytes: 57332
N, T = map(int, input().split())
t = list(map(int, input().split()))

open = [t[0] + T]
ans = T
for n in range(N):
    if n == 0:
        continue
    else:
        if t[n] >= open[-1]:
            ans += T
            open.append(t[n] + T)
        else:
            ans += t[n] - t[n-1]
            open.append(t[n] + T)

print(ans)

Measured memory_bytes: 98000
#include <bits/stdc++.h>//Carefully Crafted by hetp111
    using namespace std;
    #define int long long
    #define double long double
    #define all(v) (v).begin(),(v).end()
    #define vi vector<int>
    #define vvi vector<vi>
    #define pii pair<int,int>
    #define vii vector<pii>
    #define MOD (1000000007)
    #define MOD2 (998244353)
    #define MOD3 (1000000009)
    #define PI acos(-1)
    #define eps (1e-8)
    #define INF (1e18)
    #define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
    template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
    template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
    template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
    template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
    ifstream cinn("in.txt");ofstream coutt("out.txt");
    int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
    int ceil(const int &a,const int &b){return (a-1)/b+1;}
    //Read:
    //Use __builtin_popcountll for ll
     
    signed main(){
        int n;cin>>n;
        vi v(n);cin>>v;
        sort(all(v));
        int ans=1;
        for(int i:v){
            if(i>0 && ans>(int)1e18/i){
                cout<<-1;
                return 0;
            }
            ans*=i;
        }
        cout<<ans;
    }

Measured memory_bytes: 4036
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  200007
std::vector<ll> adj[N];
int main()
{
    
    io
    ll n;
    cin>>n;
    rep(i,2,n+1)
    {
        ll x;
        cin>>x;
        adj[x].pb(i);
        adj[i].pb(x);
    }
    rep(i,1,n+1)
    {
        if(i==1)
            cout<<adj[i].size()<<endl;
        else
            cout<<adj[i].size()-1<<endl;
    }
    
}

Measured memory_bytes: 16232
N,M=map(int,input().split())
L=[list(map(int,input().split()))[1:] for _ in range(M)]
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
  lit=[0]*M
  for j,switch in enumerate(L):
    cnt=0
    for s in switch:
      if i>>(s-1)&1:
        cnt+=1
    if cnt%2==P[j]:
      lit[j]=1
    else:
      lit[j]=0
  if all(lit): ans+=1 
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;


int main()
{
    int m[50],d[50];
    int x = 0;
    string Day[7] = {"Thursday", "Friday","Saturday","Sunday","Monday", "Tuesday", "Wednesday"};
    int BanyakHari[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
    string ThatDayIs[50];

    do
    {
        int DayinBetween = 0;
        cin >> m[x] >> d[x];
        if((m[x] == 0) && (d[x] == 0))
        {
            break;
        }
        //Check banyak hari antara 1 Januari - Input
        for(int y = 0; y < m[x]-1; y++)
        {
            DayinBetween = DayinBetween + BanyakHari[y];
        }
        DayinBetween = DayinBetween + d[x] - 1;

        //Kurangi sampai < 7
        while(true)
        {
            if(DayinBetween >= 7)
            {
                DayinBetween = DayinBetween - 7;
            }
            else
            {
                break;
            }
        }

        ThatDayIs[x] = Day[DayinBetween];

        x++;
    }
    while(x < 50);

    for(int z = 0; z < x; z++)
    {
        cout << ThatDayIs[z] << endl;
    }


}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;

signed main(){
    int n,x,y;cin>>n>>x>>y;
    int ln[n]={};
    for(int i=1;i<=n-1;i++)for(int j=i+1;j<=n;j++){
        ln[min({j-i,abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y)})]++;
    }
    for(int i=1;i<n;i++){
        cout<<ln[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}
Int tmpi = 0;
double tmpd = 0.0;


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

    Int l, r;
    cin >> l >> r;

    Int min = pow(10, 18);
    for(Int i=l; i<r; i++){
        for(Int j=i+1; j<=r; j++){
            if(i*j%2019==0){
                cout << '0' << endl;
                return 0;
            }
            min = i*j%2019 < min ? i*j%2019 : min;
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20190315_08 {
    class Program {
        static void Main(string[] args) {
            var line = Console.ReadLine().Split(' ').Select(d => int.Parse(d)).ToArray();
            var s = line[0];
            var a = new List<int>() { s };
            for (int i = 0; i < int.MaxValue; i++) {
                var a_i = f(a[i]);
                if (a.Any(x => x == a_i)) {
                    Console.WriteLine(i + 2);
                    return;
                }
                a.Add(a_i);
            }
        }

        static int f(int n) {
            if ((n & 1) == 0) {
                return n >> 1;
            }
            return 3 * n + 1;
        }
    }
}


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

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll s;
    vector<bool> table(1e9+1,false);
    for(int i=0;i<n;i++){
        cin >> s;
        table[s]=true;
    }
    int q;
    cin >> q;
    ll t;
    int cou=0;

    for(int i=0;i<q;i++){
        cin >> t;
        if(table[t])cou++;
    }

    cout << cou << endl;

}



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

int main() {
  int x, sum;
  cin >> x;
  sum = 0;
  sum += x/500*1000;
  x %= 500;
  sum += x/5*5;
  cout << sum << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  int n;cin>>n;
  int p[n+10];
  int q[n+10];
  REP(i,n) {
    int r;cin>>r;
    p[i]=r;
    q[i]=r;
  }

  // REP(i,n) pr(p[i]);

  sort(q,q+n);

  int cnt = 2;

  REP(i,n) {
    if(p[i]!=q[i]) {
      cnt-=1;
    }
  }
  if(cnt>=0) {
    pr("YES");
  } else {
    pr("NO");
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll x,y; cin >> x >> y;
    ll ans = 0;
    while(x <= y){
        x *= 2;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// E - All-you-can-eat

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int dp[3001][3001]; // dp[i][j]: i番目の料理までを考慮した時に時間jまでに達成できる満足度の最大値

pair<int, int> dishes[3001];

int main() {
	int N, T;
	cin >> N >> T;

	for (int i=1; i<=N; i++) {
		int A, B;
		cin >> A >> B;
		dishes[i].first = A;  // 食べるのにかかる時間
		dishes[i].second = B; // 美味しさ
	}

	sort(dishes+1, dishes+N+1);

	for (int i=0; i<N; i++) {
		int A = dishes[i+1].first;
		int B = dishes[i+1].second;

		for (int j=0; j<=T; j++) {
			// i+1番目の料理を注文しない場合
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);

			// i+1番目の料理を注文する場合
			if (j+A <= T) {
				dp[i+1][j+A] = max(dp[i+1][j+A], dp[i][j] + B);
			}
		}
	}

	int ans = 0;
	for (int i=1; i<=N; i++) {
		ans = max(ans, dp[i-1][T-1] + dishes[i].second);
	}

	cout << ans << endl;

	// **** debug ****
	/*
	for (int i=1; i<=N; i++) {
		cout << "(" << dishes[i].first << ", " << dishes[i].second << "), ";
	}
	cout << endl;
	for (int i=0; i<=N; i++) {
		for (int j=0; j<=T; j++) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/

	return 0;
}

Measured memory_bytes: 35456
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;

int main() {
	int s;
	cin >> s;
	vector<int> f(1, s);
	for (int i = 0; i < 1000000; i++) {
		if (f[i] % 2 == 0) {
			f.push_back(f[i] / 2);
		}
		else {
			f.push_back(3 * f[i] + 1);
		}
		for (int j = 0; j < f.size()-1; j++) {
			if (f[i+1] == f[j]) {
				cout << i + 2 << endl;
				return 0;
			}
        }
	}
}

Measured memory_bytes: 256
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right
from heapq import heappush, heappop

import re
# import numpy as np
from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e30)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    # a = i_inpl()
    # s = input()

    # if 3200 <= a:
    #     print(s)
    # else:
    #     print("red")
    N = i_inpl()
    A = l_inpl()

    ans = 0
    for Ai in A:
        ans += 1/Ai
    
    print(1/ans)

if __name__ == "__main__":
    main()


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

using namespace std;
#define rep(i,n) for(int i = 0;i < (int)n;i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int,int>;
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};
//const int INF = (1 << 29);


int main(){

  ll n,a,b,res;
  cin >> n >> a >> b;
  if(!(b-a & 1))res = (b-a)/2;
  else res = min(a+(b-a-1)/2,n-b+1+(b-a-1)/2);
  cout << res;


  return 0;
}


Measured memory_bytes: 256
A_1=[int(x) for x in input().rstrip().split()]
A_2=[int(x) for x in input().rstrip().split()]
A_3=[int(x) for x in input().rstrip().split()]

N=int(input())
for i in range(N):
  b=int(input())
  if b in A_1:
    A_1[A_1.index(b)]=0
  if b in A_2:
    A_2[A_2.index(b)]=0
  if b in A_3:
    A_3[A_3.index(b)]=0


if A_1[0]==A_1[1]==A_1[2]==0:
  print("Yes")
elif A_1[0]==A_2[1]==A_3[2]==0:
  print("Yes")
elif A_1[0]==A_2[0]==A_3[0]==0:
  print("Yes")
elif A_2[0]==A_2[1]==A_2[2]==0:
  print("Yes")
elif A_3[0]==A_3[1]==A_3[2]==0:
  print("Yes")
elif A_1[1]==A_2[1]==A_3[1]==0:
  print("Yes")
elif A_1[2]==A_2[2]==A_3[2]==0:
  print("Yes")
elif A_1[2]==A_2[1]==A_3[0]==0:
  print("Yes")
else:
  print("No")

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

template<typename T>
struct BIT{
    int n;
    vector<T> dat;
    BIT(int n) : n(n), dat(n+1,0){}
    void add(int x, T val){
        for(int i = x+1; i <= n; i += (i & -i)) dat[i] += val;
    }
    T sum(int x){
        T ret = 0;
        for(int i = x+1; i > 0; i -= (i & -i)) ret += dat[i];
        return ret;
    }
    T sum(int a, int b){
        return sum(b) - sum(a-1);
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n,m; cin >> n >> m;
    vector<tuple<int,int,int>> t;
    rep(i,n){
        int l,r; cin >> l >> r;
        t.emplace_back(r-l,l,r);
    }
    t.emplace_back(m+1,-1,-1);
    sort(all(t));

    auto bit = BIT<int>(m+2);
    int i = 0;
    REP(d,1,m+1){
        while(get<0>(t[i]) < d){
            int l = get<1>(t[i]);
            int r = get<2>(t[i]);
            bit.add(l, 1);
            bit.add(r+1, -1);
            i++;
        }
        int ans = n-i;
        for(int di=0; di<m+1; di+=d){
            ans += bit.sum(di);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 8560
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	string s;
	cin >> s;
	int ans = 700;
	rep(i, 3) {
		if (s[i] == 'o') ans += 100;
	}
	cout << ans << endl;
}

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

int main() {
  ll a, b;
  cin >> a >> b;
  int sign = +1;
  if (a < 0) {
    if (b < 0) {
      if ((b - a + 1) % 2 != 0) {
        sign = -1;
      }
    }
    else {
      sign = 0;
    }
  }
  if (sign > 0) {
    cout << "Positive" << endl;
  }
  else if (sign < 0) {
    cout << "Negative" << endl;
  }
  else {
    cout << "Zero" << endl;
  }
  return 0;
}


Measured memory_bytes: 3576
program main
      implicit none
      integer(8) :: n, a, b, i, j

      read(*,*) n, a, b

      i = mod(n, a+b)
      j = n/(a+b)

      if ( i < a ) then
        print *, j*a + i
      else
        print *, j*a + a
      end if

end program main



Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def readln():
    _res = list(map(int,str(input()).split(' ')))
    return _res
# n-c m-s
a = readln()
m,n = a[0],a[1]
k = m
if k * 2 > n: k = n // 2
n = n - k * 2
m = m - k
k = k + (n // 4)
print(k)


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.ABC042
{
    class ProblemC
    {
        static void Main()
        {
            var nk = ReadIntArray();
            var n = nk[0];
            var k = nk[1];
            var ds = ReadIntArray();
            for (var i = n; i < 100000; i++)
            {
                if (EnumerateDigt(i).Any(v => ds.Contains(v)))
                    continue;
                Console.WriteLine(i);
                break;
            }
        }

        static IEnumerable<int> EnumerateDigt(int value)
        {
            while (value > 0)
            {
                yield return value % 10;
                value /= 10;
            }
        }

        public static string ReadLine() => Console.ReadLine();

        public static int ReadInt() => int.Parse(ReadLine());

        public static int[] ReadIntArray() => ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
    }
}


Measured memory_bytes: 15424
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;

set<long long int>aset;
long long int ahash(vector<int>&v) {
	long long int k=0;
	for (auto a : v) {
		k*=5;
		k+=a;
	}
	return k;
}
vector<int> solve(vector<int>&v,int rest) {
	if (rest == 0)return vector<int>{-1};
	auto ha=ahash(v);
	if (aset.find(ha) == aset.end()) {
		aset.emplace(ha);
	}
	else {
		return vector<int>();
	}
	for (int i = 0; i < 13; ++i) {
		if (rest % (i + 1)==0 && v[i]) {
			v[i]--;
			auto k=solve(v, rest-i-1);
			if(!k.empty()){
				k.push_back(i+1);
				return k;
			}
			v[i]++;
		}
	}
	return vector<int>();
}

int main() {
	while (true) {
		aset.clear();
		int N;cin>>N;
		if(!N)break;
		int sum=0;
		vector<int>nums(13);
		for (int i = 0; i < N; ++i) {
			int a;cin>>a;a--;
			sum+=a+1;
			nums[a]++;
		}
		vector<int> oks=solve(nums,sum);
		if (!oks.empty()) {
			for (int i = 0; i < N; ++i) {
				cout<<oks[i+1];
				if(i==N-1)cout<<endl;
				else cout<<" ";
			}
		}
		else {
			cout<<"No"<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3288
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
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;

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

    int ans = 0;

    rep(i,n-2){
        if(s.at(i) == 'A'){
            if(s.at(i+1)== 'B'){
                if(s.at(i+2) == 'C'){
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Node{
	int depth=0,parent=-1,i,id,k;
	int[] c;
	public Node(int Id,int K,int[] C){
		int i;
		id=Id;
		k=K;
		c=C;
		for(i=0;i<k;i++) {

		}
	}
	public void Show() {
		int i;
		System.out.print("node "+id+": parent = "+parent+", depth = "+depth+", ");
		if(parent==-1) {
			System.out.print("root, [");
		}else if(k>0) {
			System.out.print("internal node, [");
		}else {
			System.out.print("leaf, [");
		}
		for(i=0;i<k;i++) {
			System.out.print(c[i]);
			if(i<k-1) {
				System.out.print(", ");
				}
		}
			System.out.println("]");
	}
}
public class Main {
	static Node[] node=new Node[100000];
	public static void depth(int i) {
		int j,n;
		n=node[i].k;
		for(j=0;j<n;j++) {
			node[node[i].c[j]].depth=node[i].depth+1;
			depth(node[node[i].c[j]].id);
		}
	}
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int i,j,id,n,k;
		n=scan.nextInt();
		for(i=0;i<n;i++) {
			id=scan.nextInt();
			k=scan.nextInt();
			int[] c=new int[k];
			for(j=0;j<k;j++) {
				c[j]=scan.nextInt();
			}
			node[id]=new Node(id,k,c);
		}
		for(i=0;i<n;i++) {
			for(j=0;j<node[i].k;j++) {
				node[node[i].c[j]].parent=node[i].id;
			}
		}
		for(i=0;i<n;i++) {
			if(node[i].parent==-1) {
				depth(i);
			}
		}
		for(i=0;i<n;i++) {
			node[i].Show();
		}
		scan.close();
	}
}


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

int main(){
	int N = 0, x = 0, sum = 0;
	vector<int> len;

	cin >> N;
	for (int i = 0; i < (N * 2); i++) {
		cin >> x;
		len.push_back(x);
	}

 	sort(len.begin(), len.end());

	for (int i = 0; i < (N * 2); i += 2) {
		sum += len.at(i);
	}

	cout << sum << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
d = {}

max1 = 0
max2 = 0

for i in range(n):
    if a[i] in d:
        if d[a[i]] == 1 or d[a[i]] == 3:
            if a[i] > max2:
                if a[i] > max1:
                    max2 = max1
                    max1 = a[i]
                else:
                    max2 = a[i]
        d[a[i]] += 1
    else:
        d[a[i]] = 1

print(max1*max2)

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

int main() {
	int a ,b , x;
	cin >> a >> b;
	if(((a+b) % 2) != 0) cout << ((a + b) / 2) + 1 << endl;
	else cout << (a + b) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a;
	cin >> a;
	int sum = a;
	char op;
	for (int i = 1;; i++) {
		if (i % 2 == 0) {
			int n;
			cin >> n;
			if (op == '+') {
				sum += n;
			}
			else if (op == '-') {
				sum -= n;
			}
			else if (op == '*') {
				sum *= n;
			}
			else if (op == '/') {
				sum /= n;
			}
		}
		else {
			cin >> op;
			if (op == '=') {
				cout << sum << endl;
				return 0;
			}
		}
	}
	return 0;
}


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

int main() {
  string s;
  cin>>s;
  set<char> table;
  if (s.length() == 26) {
    bool y = true;
    for (int i=24; i >= 0; i--) {
      if (s[i] < s[i+1]) {
        cout<<s.substr(0,i);
        for (int j = 25; j > i; j--) {
          if(s[j] > s[i]) {
            cout<<s[j]<<endl;
            exit(0);
          }
        }
      }
    }
    cout<<-1<<endl;
  } else {
    for (int i = 0; i < s.length(); i++) {
      table.insert(s[i]);
    }
    for (char c = 'a'; c <= 'z'; c++) {
      if (table.count(c) == 0) {
      cout<<s<<c<<endl;
      break;
      }
    }
  }
  
  
  return 0;
}


Measured memory_bytes: 384
N = int(input())
S = input()
whites = S.count('.')
stones = [0, whites]
ans = sum(stones)
for char in S:
    if char == '.':
        stones[1] -= 1
    else:
        stones[0] += 1
    if ans > sum(stones):
        ans = sum(stones)
print(ans)


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

int main(){

    int N, K;
    cin >> N >> K;

    vector<int> A(N);

    for (int i=0; i<N; i++){
        cin >> A.at(i);
    }

    sort(A.begin(), A.end());

    int count = 0;
    if (N>=K){
        for (int i=N-1; count<K; i--){
            A.at(i) = 0;
            count++;
        }
    }
    else{
        for (int i=0; i<N; i++){
            A.at(i) = 0;
        }
    }

    int64_t ans = 0;
    for (int i=0; i<N; i++){
        ans += A.at(i);
    }

    cout << ans << endl;
    return 0;
}

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



int N, M;
vector<int> A;



int main()
{
	cin >> N;
	cin >> M;

	priority_queue< int> q;


	A = vector<int>(N,0);


	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		
		q.push(A.at(i));
	}



	for (int i = 0; i < M; i++) {
		int tmp = q.top();
		q.pop();

		q.push(tmp / 2);

	}

	long long ans = 0;

	while (!q.empty()) {
		ans += q.top();
		q.pop();
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1276
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,m,cnt[200111],a[200111],x,y,t[200111],cur;
void inc(int x)
{
	int pos=x-cnt[x];
	if(pos>0)
	{
		if(t[pos]==0)cur--;
		t[pos]++;
	}
	cnt[x]++;
}
void dec(int x)
{
	int pos=x-cnt[x]+1;
	if(pos>0)
	{
		if(t[pos]==1)cur++;
		t[pos]--;
	}
	cnt[x]--;
}
int main()
{
	get2(n,m);
	cur=n;
	for(int i=1;i<=n;i++)
	{
		get1(a[i]);
		inc(a[i]);
	}
	for(int i=1;i<=m;i++)
	{
		get2(x,y);
		dec(a[x]);
		inc(y);
		a[x]=y;
		printendl(cur);
	}
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;vector<ll> a;
	cin>>n>>k;
	ll ans=INF;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	for(int i=0;i+k-1<n;i++){
		ll now=a[i+k-1]-a[i];
		ans=min(ans,now);
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<cstdio>
#include<cstring>
char s[200010];
int n,ans,cnt;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	cnt=ans=0;
	for(int i=1;i<=n;i++)
		if(s[i]=='S')cnt++;
		else if(cnt)cnt--;
		else ans++;
	printf("%d\n",ans+cnt);
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  int x = 0;
  for (char c : s) {
    x += (c-'0');
  }
  x %= 9;
  if (x == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3704
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	int n,pos,x=0,y=0;
	cin>>n;
	vi a(n);
	for0(i,n) cin>>a[i];
	for0(i,n){
		if(a[i]>x){
			x = a[i];
			pos=i;
			}
		}
	for0(i,n){
		if(i==pos) continue;
		y = max(y,a[i]);
		}
	for0(i,n){
		if(a[i]==x) cout<<y<<nw;
		else cout<<x<<nw;
		}
	
	
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

//
// Knuth-Morris-Pratt
//   fail[i] := pat[0:i) の suffix と pat の prefix がどれだけ一致するか (長さ i 未満で)
//   O(N) で構築できる
//   これを利用して以下を求められたる
//     ・pat[0:i) の最小周期 ("abcabcab" は "abc" の繰り返しを区切ることでできるので 3)
//     ・文字列 S において S[i:] の prefix が pat と一致するような i をすべて求める
//
// verified:
//   ABC 150 F - Xor Shift
//     https://atcoder.jp/contests/abc150/tasks/abc150_f
//
//   ARC 060 F - 最良表現
//     https://atcoder.jp/contests/arc060/tasks/arc060_d
//

// T = string or vector<long long>
template<class T> struct KMP {
    T pat;
    vector<int> fail;

    // construct
    // O(N)
    KMP(const T &p) { init(p); }
    void init(const T &p) {
        pat = p;
        int m = (int)pat.size();
        fail.assign(m+1, -1);
        for (int i = 0, j = -1; i < m; ++i) {
            while (j >= 0 && pat[i] != pat[j]) j = fail[j];
            fail[i+1] = ++j;
        }
    }

    // the period of S[0:i]
    int period(int i) { return i - fail[i]; }

    // the index i such that S[i:] has the exact prefix p
    // O(N)
    vector<int> match(const T &S) {
        int n = (int)S.size(), m = (int)pat.size();
        vector<int> res;
        for (int i = 0, k = 0; i < n; ++i) {
            while (k >= 0 && S[i] != pat[k]) k = fail[k];
            ++k;
            if (k >= m) res.push_back(i - m + 1), k = fail[k];
        }
        return res;
    }
};


void solve(int N, const vector<long long> &a, const vector<long long> &b) {
    vector<long long> da(N*2), db(N);
    for (int i = 0; i < N*2; ++i) {
        int j = i % N;
        int k = (i + 1) % N;
        da[i] = a[j] ^ a[k];
        if (i < N) db[i] = b[j] ^ b[k];
    }
    KMP<vector<long long> > kmp(db);
    auto v = kmp.match(da);
    for (auto k : v) {
        if (k < N) cout << k << " " << (a[k] ^ b[0]) << endl;
    }
}

int main() {
    int N;
    cin >> N;
    vll a(N), b(N), da(2*N), db(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];

    rep(i, N) {
        da[i] = a[i] ^ a[(i+1) % N];
        db[i] = b[i] ^ b[(i+1) % N];
        da[i+N] = da[i];
    }

    KMP<vll> kmp(db);
    auto v = kmp.match(da);
    for(auto k : v) {
        if(k < N) cout << k << " " << (a[k] ^ b[0]) << endl;
    }
}

Measured memory_bytes: 14580
inLine = list(map(int,input().split()))
ret = 0
inLine.sort(reverse = True)
if (inLine[1]-inLine[2]) % 2 != 0 :
    inLine[0] += 1
    inLine[2] += 1
    ret += 1
while inLine[0] != inLine[1]:
    inLine[1] += 1
    inLine[2] += 1
    ret += 1
while inLine[0] != inLine[2]:
    inLine[2] += 2
    ret += 1
print(ret)


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll A, B;
    cin >> A >> B;
    bool ok = false;
    for (ll i = 0; i < 100000; i++) {
        if (i * 8 / 100 == A && i / 10 == B) {
            cout << i << endl;
            ok = true;
            break;
        }
    }

    if (!ok) cout << -1 << endl;
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
 
int main()
{
    long long x,a,b;
    while(scanf("%lld%lld%lld",&x,&a,&b)!=EOF){
        if(a>=b) printf("delicious\n");    
        else if((b-a)>x)printf("dangerous\n");
        else printf("safe\n");
        
    }
    return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"

#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define LINF ((ll)1 << 60)
#define INF (1 << 28)
template<typename T>
void chmax(T& a, T b) {
        if (a < b) a = b;
}
template<typename T>
void chmin(T& a,T b) {
        if (a > b) a = b;
}
bool debug = false;
//.....................
ull mod = (int)1e9 + 7;
const int MAX = (int)2e5 + 5;

ll x, y;

void solve() {
        cin >> x >> y;
        int res = INT_MAX;
        rep(i, 2) rep(j, 2) {
                int cnt = 0;
                int start = x;
                int end = y;
                if (i == 1) {
                        start *= -1;
                        cnt++;
                }
                if (j == 1) {
                        end *= -1;
                        cnt++;
                }
                if (end - start < 0) continue;
                chmin(res, cnt + end - start);
        }
        cout << res << endl;
}

signed main(int argc, char *argv[]) {
        int T = 1;
        cout << fixed << setprecision(20);
        rep(i, argc) {
                if (argv[i] == "-debug"s) {
                        debug = true;
                }
        }
        rep(i, T) {
                solve();
        }
        return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    b.append([a[i],i])
b.sort()
b = b[::-1]
#print(b)
dp = [[0]* (n+1) for i in range(n+1)]
cnt = 0
for i,j in b:
    for k in range(cnt+1):
        dp[cnt-k][k+1] = max(dp[cnt-k][k] + abs(n-1-j-k)*i,dp[cnt-k][k+1])
        dp[cnt-k+1][k] = max(dp[cnt-k][k] + abs(j-(cnt-k))*i,dp[cnt-k+1][k])
    cnt+=1
ans = 0
for k in range(n):
    ans = max(ans,dp[n+1-k-1][k])
print(ans)

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> p(N);
	
	for(size_t i = 0; i < N; i++)
	{
		cin >> p[i];
	}
	auto max_it = std::max_element(p.begin(),p.end());
	*max_it /=2;
	cout << accumulate(p.begin(),p.end(),0);
	return 0;
}

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

using namespace std;

int main() {
  int a, b, d;
  cin >> a >> b >> d;
  
  set<int> s;
  for (int i = 0; i < min(d, b - a + 1); ++i) {
    s.insert(a + i);
    s.insert(b - i);
  }
  
  for (int p : s) {
    cout << p << endl;
  }
  
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

def main():
    n, m, l = map(int, input().split())
    d = [[float("inf") for _ in range(n)] for _ in range(n)]
    for i in range(n):
        d[i][i] = 0
    
    for _ in range(m):
        a, b, c = map(int, input().split())
        d[a-1][b-1] = c
        d[b-1][a-1] = c
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
    
    dl = [[float("inf") for _ in range(n)] for _ in range(n)]
    for i in range(n):
        d[i][i] = 0

    for i in range(n):
        for j in range(i+1, n):
            if i != j and d[i][j] <= l:
                dl[i][j] = 1
                dl[j][i] = 1
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if dl[i][j] > dl[i][k] + dl[k][j]:
                    dl[i][j] = dl[i][k] + dl[k][j]
    
    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        if dl[s-1][t-1] == float("inf"):
            print(-1)
        else:
            print(dl[s-1][t-1] - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68828