akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
using namespace std;
using ll = 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 (a>b) { a=b; return 1; } return 0; }
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
#define all(x) (x).begin(),(x).end()
void mincat(ll &a,ll b){if(a > b)a=b;}
int main(){
  ll a,b;
  cin >> a >> b;
  if(b % a == 0){
    cout << a+b;
  }else{
    cout << b-a;
  }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}


const int MAX_N = 212345;
int A[61][MAX_N];

int main2() {
  int N = nextInt();
  ll K = nextLong();
  REP(i, N) A[0][i] = nextInt() - 1;
  for (int b = 1; b < 61; b++) {
    REP(i, N) A[b][i] = A[b-1][A[b-1][i]];
  }

  int m = 0;
  REP(b, 60) {
    if (K >> b & 1) {
      m = A[b][m];
    }
  }
  cout << m + 1 << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 51552
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, t, a, b, res = 1<<30;

signed main() {
	cin >> n >> t;
	rep(i,n) {
		cin >> a >> b;
		if (b<=t) chmin(res, a);
	}
	if (res==1<<30) cout << "TLE" << endl;
	else cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  char c[1101];
  int i=0,ans=0,b=1;
  do{
    for(i=0; i<1100; i++){
      scanf("%c",&c[i]);
      if(i==0&&c[0]=='0'){
        b=0;
        break;
      }
      if(c[i]=='\n')break;
      ans+=(c[i]-'0');
    }
    if(b)printf("%d\n",ans);
    ans=0;
  }while(b);
  return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N; cin>>N;
  long long ans=0;
  vector<int>count(100001);
  for(int i=0;i<N;i++){
    int a;cin>>a;
    if(a>100000)ans++;
    else count[a]++;
  }
  for(int i=0;i<100001;i++){
    if(count[i]<i)ans+=count[i];
    else ans+=count[i]-i;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3752
#include<stdio.h>
int N;
char stone[200000];
int Rn[200000];
int R=0;
int count=0;
void swap(int a, int b){
  if(a==b)return;
  char w = stone[a];
  stone[a]=stone[b];
  stone[b]=w;
  count++;
}
int main(void){
  int c;
  int i;
  int j;
  int k;
  if(scanf("%d",&N)==1);
  i=0;j=0;
  c=getchar();
  while(c!=EOF){
    if( c=='R' || c=='W'){
      stone[i]=c;
      if(c=='R'){
        R++;
        Rn[j++]=i;
      }
      i++;
    }
    c=getchar();
  }
  stone[i]='\0';
  k=j; j=0;
  for(i=0;i<R;i++){
    if(stone[i]=='R')
      j++;
   }
  if(j==k){
    printf("%d\n",count);
    return 0;
  }
  for(i=0;i<N;i++){
    if(stone[i]='W'){
      swap(i,Rn[j++]);
    }
    if(j==k)break;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 2592
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] map = new int[N];
		for (int i = 0; i < N; i++) {
			map[i] = sc.nextInt() - (i + 1);
		}

		Arrays.sort(map);

		//平均値でやっていたのが問題だった、中央値を求める
		int val = map[N / 2];

		long ans = 0;
		for (int i = 0; i < N; i++) {
			ans += Math.abs(map[i] - val);
		}
		System.out.println(ans);
	}
}

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

int main()
{
  int a, b;
  cin >> a >> b;

  if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0){
    cout << "Possible" << endl;
  }

  else cout << "Impossible" << endl;

  return 0;

}


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

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  int use = y + 2 * z;
  int num = 1;
  while (true) {
    use += y + z;
    num++;
    if (use > x) {
      num--;
      break;
    }
    if (use == x) break;
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;cin >> s;
    string tmp = s;
    reverse(s.begin(),s.end());

    if (tmp == s){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

int main() {
    int h, w;
    while (cin >> h >> w && h) {
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cout << ((i + j) % 2 ? '.' : '#');
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v) for (auto &&V : v)
#define all(x) (x).begin(), (x).end()
using lint = long long;
const int INF = 1 << 29;
const double EPS = 1e-9;
using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> lr(m);
  rep(i, m) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    lr[i] = {l, r};
  }
  int dl = 0, dr = n - 1;
  allrep(x, lr) {
    dl = max(dl, x.first);
    dr = min(dr, x.second);
  }
  int ans = dr - dl + 1;
  cout << (ans > 0 ? ans : 0) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << "\n"
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];
char field[200][200];

int main(){
  cin >> n >> m;
  l = 0;
  rep(i,0,n)cin >> d[i],l += d[i];
  sort(d,d+n);
  print(n + ((m - l) / d[0]));
  return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h> // Ishaan Gupta
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifdef IG_PC
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
#define pb push_back
using ll = long long;
using ld = long double;
const ll MOD = 1e9l + 7;
const ll INF = 1e18l + 5;
inline ll add(ll a,ll b){return (a%MOD+b%MOD)%MOD;}
inline ll sub(ll a,ll b){return (a%MOD-b%MOD+MOD)%MOD;}
inline ll mult(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll power(ll a,ll b){a%=MOD;ll r=1;while(b){if(b&1)r=mult(r,a);a=mult(a,a);b>>=1;}return r;}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
#ifdef IG_PC
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif
    ll n;
    cin >> n;
    vector<ld>dp(n+1, 0);
    dp[0]=1;
    for(ll coin=0;coin<n;++coin)
    {
        ld p_heads;
        cin >> p_heads;
        for(ll i = coin + 1; i>=0; --i)
        {
            dp[i] = (i == 0 ? 0 : dp[i-1]*p_heads) + dp[i] * (1-p_heads);
        }
    }
    ld ans = 0;
    for(ll heads = 0; heads <=n; ++heads)
    {
        ll tails = n - heads;
        if(heads > tails)
            ans+=dp[heads];
    }
    cout<<ans;

    
    return 0;
}

Measured memory_bytes: 384
N, K = map(int, input().split())
a = list(map(int, input().split()))

d = {}
s_list = []
count = 0
idx = 1
while count < N:
    idx = a[idx-1]
    if idx in d.keys():
        break
    else:
        d[idx] = count
    s_list.append(idx)
    count += 1
loop_idx = len(s_list) - d[idx]

if d[idx] > K:
    print(s_list[K-1])
elif loop_idx != 0:
    t_idx = (K - d[idx])% loop_idx
    print(s_list[d[idx]:][t_idx-1])
else:
    t_idx = K % N
    print(s_list[t_idx-1])

Measured memory_bytes: 38832
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val o, e = sc.next()
  if (o.length == e.length) {
    o.zip(e).foreach(x => print(x._1.toString + x._2.toString))
  } else {
    o.zip(e).foreach(x => print(x._1.toString + x._2.toString))
    println(o.last)
  }
}
  

Measured memory_bytes: 55436
fn main() {
    let n = read::<i32>();

    let mut ans = 0;
    for i in 1..(n + 1) {
        if i % 2 == 1 && check(i) {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn check(value: i32) -> bool {
    let mut count = 0;
    for i in 1..(value + 1) {
        if value % i == 0 {
            count += 1;
        }
    }

    count == 8
}


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner  sc = new Scanner(System.in);
		int N = sc.nextInt(), A = sc.nextInt(), B = sc.nextInt();
		int pay = Math.min(A*N, B);
		System.out.println(pay);
	}
}

Measured memory_bytes: 23892
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define int long long
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,len;
int cev,carp=1,say;
string s;
vector<int> v;

main(void){
	fio();
	cin>>n;
	for(int i=1;i<=n;i++){
		carp*=26;
		say+=carp;
		len++;
		if(say>=n){
			say-=carp;
			carp/=26;
			break;
		}
	}
	n-=say;
	n--;
	for(int i=1;i<=len;i++){
		for(int j=25;j>=0;j--){
			if(j*carp<=n){n-=j*carp;s+='a'+(j);carp/=26;break;}
		}
	}
	cout<<s<<endl;
	return 0;
}



Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main() {
    string s;
    cin >> s;
    ll n = s.size();
    const ll mod = 1000000000 + 7;
    vector<ll> dp1(n+10, 0), dp2(n+10, 0);
    dp1[0] = 1;
    rep(i, 0, n) {
        // smaller => smaller
        dp2[i+1] += 3 * dp2[i];
        // exact => smaller
        if(s[i] == '1') dp2[i+1] += dp1[i];
        // exact => exact
        if(s[i] == '1') dp1[i+1] += 2 * dp1[i]; 
        else dp1[i+1] += dp1[i];
        dp1[i+1] %= mod;
        dp2[i+1] %= mod;
    }
    cout << (dp1[n] + dp2[n]) % mod << endl;
    return 0;
}

Measured memory_bytes: 5088
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
 int a,b,mx=0,i,mn;
 cin>>a;
 int arr[a];
 for(int i=0;i<a;i++)
 cin>>arr[i];
 for(int i=0;i<a;i++)
 {
   mx=max(mx,arr[i]);
   mn=min(mn,arr[i]);
    }
    cout<<mx-mn;
 system("pause");
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

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

    cout << max(0, A-B*2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int k; cin >> k;
	int n = 1;
	for (int i = 0; i < k; i++)n *= 2;
	for (int i = 0; i < n; i++) {
		int p = i;
		cout << p << ':';
		for (int j = 0; j < k; j++) {
			if (p % 2 == 1)cout << ' ' << j;
			p /= 2;
		}
		cout << endl;
	}
}


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

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

    int t;
    int start[N + 2] = {};
    int goal[N + 2] = {};
    for (int i = 1; i <= N; i++)
    {
        cin >> t;
        goal[i] = start[i] + 2 * t;
        start[i + 1] = goal[i];
    }
    goal[N + 1] = goal[N];

    int v[N + 2] = {};
    for (int i = 1; i <= N; i++)
    {
        cin >> v[i];
        v[i] *= 2;
    }

    vector<int> x(goal[N] + 1, INT_MAX);
    x[0] = 0;
    int ans = 0;
    for (int i = 1; i < goal[N] + 1; i++)
    {
        for (int j = 0; j < N + 2; j++)
        {
            if (i < start[j])
            {
                x[i] = min(x[i], v[j] + start[j] - i);
            }
            else if (goal[j] < i)
            {
                x[i] = min(x[i], v[j] + i - goal[j]);
            }
            else
            {
                x[i] = min(x[i], v[j]);
            }
        }
        ans += x[i - 1] + x[i];
    }
    cout << setprecision(10) << ((double)ans) / 8 << endl;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**9)


def main():
    for _ in [0]*int(input()):
        N, A, B, C, D = map(int, input().split())
        S = {}

        def dfs(n):
            if n == 0:
                return 0
            if n == 1:
                return D
            if n in S:
                return S[n]

            cost = n*D
            r = n % 2
            if r == 0:
                cost = min(cost, dfs(n//2)+A)
            else:
                cost = min(cost, dfs(n//2)+A+D)
                cost = min(cost, dfs(n//2+1)+A+D)
            r = n % 3
            if r == 0:
                cost = min(cost, dfs(n//3)+B)
            else:
                cost = min(cost, dfs(n//3)+B+D*r, dfs(n//3+1)+B+D*(3-r))
            r = n % 5
            if r == 0:
                cost = min(cost, dfs(n//5)+C)
            else:
                cost = min(cost, dfs(n//5)+C+D*r, dfs(n//5+1)+C+D*(5-r))

            S[n] = cost
            return cost

        print(dfs(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10900
#include<stdio.h>
#include<stdlib.h>
int main(void){
int n;
  scanf("%d",&n);
  int p[n],q[n];
  for(int i=0;i<n;i++){
    	scanf("%d",&p[i]);
  }
  for(int i=0;i<n;i++){
    	scanf("%d",&q[i]);
  }
  int a=0,b=0;
  for(int i=0;i<n;i++){
    int order=0;
    for(int j=i+1;j<n;j++){
		if(p[i]>=p[j])order++;
    }
    	for(int k=n-i-1;k>=2;k--){
          order*=k;
        }
    a+=order;
  }
  for(int i=0;i<n;i++){
    int order=0;
    for(int j=i+1;j<n;j++){
		if(q[i]>=q[j])order++;
    }
    	for(int k=n-i-1;k>=2;k--){
          order*=k;
        }
    b+=order;
  }
  printf("%d",abs(a-b));
  return 0;
}

Measured memory_bytes: 128
def dfs(n):
    global b,check,d
    #ttfは235、chaはabc
    for ttf,cha in zip([2,3,5],b):
        #-1ずつしていく場合
        check[0]=min(check[n]+n*d,check[0])

        #最寄りまで-してく場合
        x1,x2=n//ttf,n%ttf
        if x1 in check:
            if check[x1]>check[n]+x2*d+cha:
                check[x1]=check[n]+x2*d+cha
                dfs(x1)
        else:
            check[x1]=check[n]+x2*d+cha
            dfs(x1)

        #最寄りまで+1してく場合
        x1,x2=n//ttf+1,ttf-n%ttf
        if x1 in check:
            if check[x1]>check[n]+x2*d+cha:
                check[x1]=check[n]+x2*d+cha
                dfs(x1)
        else:
            check[x1]=check[n]+x2*d+cha
            dfs(x1)

t=int(input())
for i in range(t):
    N,*b,d=map(int,input().split())
    check={N:0,0:N*d}
    dfs(N)
    print(check[0])


Measured memory_bytes: 115452
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int k = sc.nextInt();

		if (Math.abs(a - b) > k || Math.abs(a - c) > k || Math.abs(a - d) > k || Math.abs(a - e) > k
				|| Math.abs(b - c) > k || Math.abs(b - d) > k || Math.abs(b - e) > k || Math.abs(c - d) > k
				|| Math.abs(c - e) > k || Math.abs(d - e) > k) {
			System.out.println(":(");
		} else {
			System.out.println("Yay!");
		}

	}

}


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

int main() {
  string s;
  cin>>s;
  bool yes = false;
  if(s[0]==s[1]&&s[2]==s[3])yes=true;
  if(s[0]==s[2]&&s[1]==s[3])yes=true;
  if(s[0]==s[3]&&s[1]==s[2])yes=true;
  if(s[0]==s[1]&&s[2]==s[3]&&s[0]==s[2])yes=false;
  yes ? cout << "Yes" : cout << "No" ;
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100001];
long long f[100001];
int main()
{
	int n,m,u,i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
	{
		scanf("%d",&u);
		a[u]=1;
	}
	f[0]=1;
	f[1]=(a[1]?0:1);
	for(i=2;i<=n;i++)
	{
		if(a[i])
			continue;
		f[i]=(f[i-2]+f[i-1])%1000000007;
	}
	printf("%lld",f[n]);
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

using P = pair<int, int>;

P f(P a, P b) {
    return (a.first > b.first ? a : a.first < b.first ? b : a.second < b.second ? a : b);
}

void _main() {
    int n;
    while (cin >> n, n) {
        vector<int> p(n);
        REP (i, n) cin >> p[i];
        const int INF = 1 << 30;
        vector<vector<P>> dp(n + 1, vector<P>(50000, P(-INF, INF)));
        dp[0][0] = P(0, 0);
        REP (i, n) REP (j, 50000) if (dp[i][j].first != -INF) {
            dp[i + 1][j] = f(dp[i + 1][j], dp[i][j]);
            int q = p[i] % 1000;
            if (q >= 1 && q <= 500) {
                dp[i + 1][j + 500 - q] = f(dp[i + 1][j + 500 - q], P(dp[i][j].first + 1, dp[i][j].second + p[i]));
            } else {
                int r = (q + 500) % 1000;
                if (j >= r) dp[i + 1][j - r] = f(dp[i + 1][j - r], P(dp[i][j].first + 1, dp[i][j].second + p[i]));
                if (q != 0) dp[i + 1][j + 1000 - q] = f(dp[i + 1][j + 1000 - q], P(dp[i][j].first, dp[i][j].second + p[i]));
            }
        }
        int x = 0, y = INF;
        REP (i, 50000) {
            if (dp[n][i].first > x) {
                tie(x, y) = dp[n][i];
            } else if (x == dp[n][i].first) {
                y = min(y, dp[n][i].second);
            }
        }
        cout << x << " " << y << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 82780
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        if (500 * k >= x) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}

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

int main()
{
    char c;
    cin >> c;

    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    {
        cout << "vowel";
    }
    else
    {
        cout << "consonant";
    }
}

Measured memory_bytes: 384
#include <cstdio>

bool line(int x1, int y1, int x2, int y2, int x, int y){
	return (x2 - x1) * (y - y1) > (y2 - y1) * (x - x1);
}

bool triangle(int x1, int y1, int x2, int y2, int x3, int y3, int x, int y){
	return	line(x1, y1, x2, y2, x, y) == line(x1, y1, x2, y2, x3, y3) &&
			line(x2, y2, x3, y3, x, y) == line(x2, y2, x3, y3, x1, y1) &&
			line(x3, y3, x1, y1, x, y) == line(x3, y3, x1, y1, x2, y2);
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; ++i){
		int x1, y1, x2, y2, x3, y3, ax, ay, bx, by;
		scanf("%d%d%d%d%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3, &ax, &ay, &bx, &by);
		if(triangle(x1, y1, x2, y2, x3, y3, ax, ay) != triangle(x1, y1, x2, y2, x3, y3, bx, by)){
			printf("OK\n");
		}
		else{
			printf("NG\n");
		}
	}
	return 0;
}

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

int main() {
  int a,b,c;
  cin >>a>>b>>c;
  if(a==5&&b==5&&c==7){
    cout << "YES"<<endl;
  }
  else if(a==5&&b==7&&c==5){
    cout << "YES"<<endl;
  }
  else if(a==7&&b==5&&c==5){
    cout << "YES"<<endl;
  }
  else{
    cout <<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j;

  for ( ; ; )
  {
    int dn[ N ], dm[ N ];
    int rn = 1024, rm = 1024;
    int diff = 0;
    int n, m;

    scanf ( "%d%d", &n, &m );
    if ( !( n | m ) ) break ;

    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d", dn + i );
      diff += dn[ i ];
    }
    for ( i = 0; i < m; ++i )
    {
      scanf ( "%d", dm + i );
      diff -= dm[ i ];
    }

    for ( j = 0; j < n; ++j )
    for ( i = 0; i < m; ++i )
    {
      if ( ( dn[ j ] - dm[ i ] ) * 2 == diff
        && dn[ j ] + dm[ i ] < rn + rm )
      {
        rn = dn[ j ];
        rm = dm[ i ];
      }
    }

    if ( rm == 1024 && rn == 1024 )
    {
      puts ( "-1" );
    }
    else
    {
      printf ( "%d %d\n", rn, rm );
    }
  }

  return ( 0 );
}

Measured memory_bytes: 0
n,k = map(int,input().split())
lst = sorted(list(map(int,input().split())))

if k > lst[-1]:
    print('IMPOSSIBLE')
elif k in lst:
    print('POSSIBLE')
else:
    dif = 10**5
    a = lst[0]
    b = lst[1]
    
    while True:
        dif = b-a
        if dif in lst or dif <= 0:
            break
        else:
            lst.append(dif)
            b = max(dif, a)
            a = min(dif, a)
    
    mn = min(lst)
    for l in lst:
        if l>k and (l-k)%mn==0:
            print('POSSIBLE')
            exit()
    print('IMPOSSIBLE')

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

#define IS_EVEN(a) ( ((a)&0x01) == 0 )

int main() {
    int a,b,c,x;
    cin >> a; //500
    cin >> b; //100
    cin >> c; // 50
    cin >> x;

    int cnt=0;
    for(int i = 0 ; i < a+1 ; i++) {
        for(int j = 0 ; j < b+1 ; j++) {
            for(int k = 0 ; k < c+1 ; k++) {
               if(x == 500*i + 100*j + 50*k) {
                   cnt++;
               }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    list<int> dl_list;

    cin >> n;

    string ope;
    int x;
    for (int i = 0; i < n; i++){
        cin >> ope;

        if (ope == "insert"){
            cin >> x;
            dl_list.push_front(x);
        } else if (ope == "delete"){
            cin >> x;
            list<int>::iterator it = dl_list.begin();
            for (int val : dl_list){
                if (val == x) break;
                it++;
            }
            if (it != dl_list.end()) dl_list.erase(it);
        }
        else if (ope == "deleteFirst") dl_list.pop_front();
        else if (ope == "deleteLast") dl_list.pop_back();
    }

    bool first = true;
    for (int val : dl_list){
        if (first) first = false;
        else cout << " ";
        
        cout << val;
    }
    cout << endl;

    return 0;
}




Measured memory_bytes: 34444
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextLong

  case class X(sum: Long, cur: Long, i: Int)
  def seq: Stream[Long] = 1L #:: seq.map(_ * -2)
  def scan(s: Stream[(Long, Int)]): Stream[X] = s.scanLeft(X(0L, 0L, 0)){
    case (x, (n, i)) => X(x.sum + n, n, i)
  }
  def minuses: Stream[X] = scan(seq.zipWithIndex.filter(_._1 < 0))
  def pluses: Stream[X] = scan(seq.zipWithIndex.filter(_._1 > 0))


  def exec(result: Long, n: Long): Long = {
    n match {
      case n if n < 0 =>
        val x = minuses.find(_.sum <= n).get
        exec(result | 1L << x.i, n - x.cur)
      case n if n > 0 =>
        val x = pluses.find(_.sum >= n).get
        exec(result | 1L << x.i, n - x.cur)
      case _ => result
    }
  }

  println(exec(0L, N).toBinaryString)
}

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  
  if (a>=b && a>=c) cout << b+c << endl;
  else if (b>=c && b>=a) cout << c+a << endl;
  else cout << a+b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int solve(string t, char target) {
    int m = t.length();
    bool ok=true;
    rep(i,m) if (t[i]!=target) ok=false;
    if (ok) return 0;

    string ret;
    rep(i,m-1) {
        if (t[i]==target || t[i+1]==target) ret.push_back(target);
        else ret.push_back(t[i]);
    }
    return solve(ret,target)+1;
}

int main(int argc, char const *argv[]) {
    string s;
    cin >> s;
    int n = s.length();

    int ans = INF;
    for (char i = 'a'; i <= 'z'; ++i) {
        ans = min(ans, solve(s,i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC097_A solver = new ABC097_A();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC097_A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a, b, c, d;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();

            if (Math.abs(c - a) <= d) {
                out.print("Yes");
                return;
            }

            if (Math.abs(c - b) <= d && Math.abs(b - a) <= d) {
                out.print("Yes");
                return;
            }

            out.print("No");
        }

    }
}



Measured memory_bytes: 22996
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define foreach(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define all(c) begin(c),end(c)
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(char trump;cin>>trump,trump!='#';){
		vector<string> s(4);
		vvi n(4,vi(13));
		rep(i,4) rep(j,13){
			string c; cin>>c;
			switch(c[0]){
			case 'T': n[i][j]=10; break;
			case 'J': n[i][j]=11; break;
			case 'Q': n[i][j]=12; break;
			case 'K': n[i][j]=13; break;
			case 'A': n[i][j]=14; break;
			default:  n[i][j]=c[0]-'0';
			}
			s[i]+=c[1];
		}
		int lead=0;
		int ns=0,ew=0;
		rep(i,13){
			int mx=0;
			rep(j,4){
				if(s[j][i]==trump){
					if(s[mx][i]!=trump || n[j][i]>n[mx][i])
						mx=j;
				}
				else if(s[j][i]==s[lead][i]){
					if(s[mx][i]!=trump && (s[mx][i]!=s[lead][i] || n[j][i]>n[mx][i]))
						mx=j;
				}
			}
			if(mx==0 || mx==2) ns++;
			else               ew++;
			lead=mx;
		}
		if(ns>ew) cout<<"NS "<<ns-6<<endl;
		else      cout<<"EW "<<ew-6<<endl;
	}
}

Measured memory_bytes: 1204
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
   int n,m;
 
   cin >> n >> m;
  
   int ans = n-2*m;
  
   if(ans < 0){
     cout << 0 << endl;
   }else{
     cout << ans << endl;
   }
   
   
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; 

int main(){
  string s,t;
  cin >> s >> t;
  int a,b;
  cin >> a >> b;
  string u;
  cin >> u;
  if(s == u){
    cout << a-1 << " " << b << endl;
  }
  else{
    cout << a << " " << b-1 << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var allXor = a.Aggregate((x, y) => x ^ y);

        Console.WriteLine(string.Join(" ", a.Select(x => allXor ^ x)));
    }
}

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

int main() {
  ll A, V, B, W, T; cin >> A >> V >> B >> W >> T;
  ll D = abs(A-B); ll ps = V-W;
  if (ps * T >= D) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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


int main() {
	int n;
	cin >> n;
	
	rep(i, n/4) {
		rep(j, n/7) {
			if (i * 4 + j * 7 == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
	return 0;

}


Measured memory_bytes: 256
N = int(input())
if N < 600:
    print(8)
elif N < 800:
    print(7)
elif N < 1000:
    print(6)
elif N < 1200:
    print(5)
elif N < 1400:
    print(4)
elif N < 1600:
    print(3)
elif N < 1800:
    print(2)
else:
    print(1)

Measured memory_bytes: 9172
/*
  AtCoder Beginner Contest 082
  C - Good Sequence
*/

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

int N;
vector<int> a;

int main() {
  scanf("%d", &N);
  a = vector<int>(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
  }

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

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int cnt = 1;
    int buf = a[i];
    for (int j = i + 1; j < N; ++j) {
      if (a[j] != buf) break;
      ++cnt;
      i = j;
    }

    if (cnt < buf) ans += cnt;
    else if (cnt > buf) ans += (cnt - buf);
  }

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

i64 dp[110][100010];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  rep(i, 110) rep(j, 100010) dp[i][j] = 1e18;
  int n, W;
  cin >> n >> W;
  vi32 w(n), v(n);
  rep(i, n) cin >> w[i] >> v[i];
  dp[0][0] = 0;
  rep(i, n) rep(j, 100001) {
    if (dp[i][j] == 1e18) continue;
    amin(dp[i + 1][j], dp[i][j]);
    if (j + v[i] > 100000) continue;
    amin(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
  }
  rrep(i, 100001) {
    if (dp[n][i] <= W) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 86272
x,y = 0.0,0.0
theta = 90
while true
    a,b = gets.split(",").map(&:to_i)
    break if (a == 0) and (b == 0)
    x += a * Math::cos(Math::PI * theta / 180.0)
    y += a * Math::sin(Math::PI * theta / 180.0)
    theta -= b
end
printf("%d\n%d\n",x,y)

Measured memory_bytes: 8984
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

static const long long MOD = 1000000007;

long long N;
string S1, S2;

long long CalcComb() {

	long long ans;

	long long bef;//1つ前のドミノが縦向きなら0，横向きなら1

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

		if (i == N - 1) {//最後に1個残ったら絶対縦
			if (i == 0) ans = 3;
			else if (bef == 1) ans *= 1;
			else if (bef == 0) ans = (ans * 2) % MOD;
			bef = 0;
		}
		else if (S1[i] == S1[i + 1]) {//横向き
			if (i == 0) ans = 6;
			else if (bef == 1) ans = (ans * 3) % MOD;//横横
			else ans = (ans * 2) % MOD;//横縦
			i++;
			bef = 1;
		}
		else {//縦向き
			if (i == 0) ans = 3;
			else if (bef == 1) ans *= 1;//縦横
			else ans = (ans * 2) % MOD;//縦縦
			bef = 0;
		}


	}

	return ans;
}

int main() {
	cin >> N >> S1 >> S2;

	cout << CalcComb() << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
int main() {
	double A;
	double ans = 0;
	int n;
	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		std::cin >> A;
		ans += (1 / A);
	}
	std::cout << 1 / ans << std::endl;
	return 0;
}

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

int64_t gcd(int64_t a, int64_t b) {
  while (b != 0) {
    auto t = b;
    b = a % b;
    a = t;
  }
  return a;
}

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

int main() {
  int64_t n, m;
  string s, t;
  cin >> n >> m >> s >> t;
  auto result = lcm(n, m), size = lcm(result / n, result / m);
  for (int64_t i = 0; i < result; i += size) {
    if (s[i / (result / n)] != t[i / (result / m)]) {
      result = -1;
      break;
    }
  }
  cout << result;
  return 0;
}


Measured memory_bytes: 3264
import random
from collections import defaultdict


def atoi(s):
    return ord(s) - ord("a") + 1


N = int(input())
S = input()

mod = (1 << 61) - 1
b = random.randint(10000, mod - 1)


l = 0
r = (N + 1) // 2 + 1
while r - l > 1:
    d = (r + l) // 2
    memo = defaultdict(int)
    isok = False
    h = 0
    t = pow(b, d, mod)
    for i in range(d):
        h = (h * b + atoi(S[i])) % mod
    memo[h] = 1
    for i in range(1, N - d + 1):
        h = (h*b + atoi(S[i+d-1]) - t * atoi(S[i-1])) % mod
        if not memo[h]:
            memo[h] = i + 1
        elif memo[h] and i - memo[h] + 1 >= d:
            isok = True
    if isok:
        l = d
    else:
        r = d

print(l)

Measured memory_bytes: 10356
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
  ll int n,m;
  cin>>n>>m;
  vl h(n);
  rep(i,n)cin>>h[i];
  vl a(m),b(m);
  rep(i,m)cin>>a[i]>>b[i];
  vector<vector<int>> net(n);

  rep(i,m){
    net[a[i]-1].push_back(b[i]-1);
    net[b[i]-1].push_back(a[i]-1);
  }

  rep(i,n){
    sort(all(net[i]));
  }

  int ans=0;
  rep(i,n){
    ll int hi=h[i];
    int flag=0;
    int ini;
    if(net[i].size()>0){
      ini=net[i][0];
      for(long unsigned int j=0;j<net[i].size();j++){
      if(j!=0 && ini==net[i][j])continue;
      if(hi<=h[net[i][j]]){
        ini=net[i][j];
        flag=1;
        }
      }
    }
    
    if(flag==0)ans++;
  }
  cout<<ans<<endl;
  
}




Measured memory_bytes: 10652
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}
func main() {
	var N int
	fmt.Scanf("%d\n", &N)
	fmt.Println(N * (N - 1) / 2)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long K, std::string S){
  ll cnt=1;
  REP(N-1){
    if(S[i]!=S[i+1]){
      ++cnt;
    }
  }
  cnt=max(1LL,cnt-K*2);
  cout<<N-cnt<<endl;
}

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


Measured memory_bytes: 512
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

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

  int a, b; 
  while (cin >> a >> b) {
    if (a == 0 && b == 0) {
      return 0;
    } else {
      a < b ? cout << a << " " << b << '\n' : cout << b << " " << a << '\n';
    } 
  }

  return 0;
}


Measured memory_bytes: 3172
import numpy as np
N = int(input())
h = np.array(list(map(int, input().split())))

from collections import deque
queue = deque([])

queue.append(h)

ans = 0

while(len(queue) > 0):
    new_h = queue.popleft()
    ans += np.min(new_h)
    new_h -= np.min(new_h)
    
    R = np.where(new_h == 0)[0][0]
    new_L = new_h[:R]
    new_R = new_h[R+1:]
    
    if new_L.size > 0:
        queue.append(new_L)
    if new_R.size > 0:
        queue.append(new_R)
    
print(ans)

Measured memory_bytes: 27228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll X;
  cin >> X;
  for(ll i=-120;i<120;i++){
    for(ll j=-120;j<120;j++){
      if(j*j*j*j*j - i*i*i*i*i == X){
        cout<< j << " " << i;
        return(0);
      }
    }
  }
  return(0); 
}


Measured memory_bytes: 3588
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<stdlib.h>
#include<math.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1ll << 30ll)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, S, a[100100];

signed main(){
    cin >> N >> S;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    int l = 0, r = 0, s = 0;
    int ans = INF;
    for(r = 0; r < N; r++){
        s += a[r];
        if(s < S){
            continue;
        }
        while(l <= r && s - a[l] >= S){
            s -= a[l];
            l++;
        }
        ans = min(ans, r - l + 1);
    }
    cout << ans % INF << endl;

    return 0;
}

/*


*/


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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

set<int> used;
vector<ii> vals;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	ll r=0;
	int n;
	cin >> n;
	used.insert(-1);
	used.insert(n);
	for (int i=0;i<n;i++) {
		int a;cin >> a;
		vals.emplace_back(a,i);
	}
	sort(vals.begin(),vals.end());
	for (int i=0;i<n;i++) {
		int idx=vals[i].y;
		auto it=used.lower_bound(idx);
		ll w=*it-*prev(it);
		r+=(ll)(idx-*prev(it))*(*it-idx)*vals[i].x;
		used.insert(idx);
	}

	cout << r << endl;

}

Measured memory_bytes: 11248
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdlib.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    long a[3*n];
    for(int i = 0; i < 3*n; i++) {
        cin >> a[i];
    }
    sort(a, a+3*n);
    long int sum = 0;
    for(int i = n; i < 3*n; i++) {
        if(n % 2 == 0) {
            if(i % 2 == 0) {
            sum += a[i];
            }
        }else {
            if(i % 2 == 1) {
                sum += a[i];
            }
        }
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 2560