akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  vector<bool> D(10,false);
  for(int i=0;i<K;i++){
    int d;
    cin >> d;
    D.at(d)=true;
  }

  for(int i=N;i<1000000;i++){
    int x=i;
    bool flag=true;
    while(x>0){
      int y=x%10;
      x/=10;
      if(D.at(y)==true) flag=false;
    }
    if(flag){
      cout << i << endl;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
use std::io;

fn div_count(mut x: u64, div: u64) -> usize {
    let mut count = 0;
    while x % div == 0 {
        x /= div;
        count += 1;
    }
    count
}

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n: usize = buf.trim_end().parse().unwrap();
    let a: Vec<f64> = (0..n)
        .map(|_| {
            buf.clear();
            io::stdin().read_line(&mut buf).unwrap();
            buf.trim_end().parse().unwrap()
        })
        .collect();
    let a_proc: Vec<_> = a.into_iter().map(|x| (x * 10f64.powi(9)).round() as u64).collect();
    let div: Vec<_> = a_proc
        .iter()
        .map(|&x| (div_count(x, 2), div_count(x, 5)))
        .collect();
    let mut imos = [[0usize; 100]; 100];
    for (x, y) in div.iter().cloned() {
        imos[x][y] += 1;
    }
    for i in 0..100 {
        for j in (0..99).rev() {
            imos[i][j] += imos[i][j + 1];
        }
    }
    for i in (0..99).rev() {
        for j in 0..100 {
            imos[i][j] += imos[i + 1][j];
        }
    }
    let result: usize = div
        .into_iter()
        .map(|(x, y)| {
            if x >= 9 && y >= 9 {
                imos[18usize.saturating_sub(x)][18usize.saturating_sub(y)] - 1
            } else {
                imos[18usize.saturating_sub(x)][18usize.saturating_sub(y)]
            }
        })
        .sum();
    assert!(result % 2 == 0);
    println!("{}", result / 2);
}


Measured memory_bytes: 7192
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;
typedef long long ll;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin>>N;
    vector<ll> a(N),b(N);
    ll suma = 0, sumb = 0;
    rep(i,N){
        cin>>a[i];
        suma += a[i];
    }
    rep(i,N){
        cin>>b[i];
        sumb += b[i];
    }
    print(a);print(b);
    cerr<<suma<<" "<<sumb<<endl;
    if(a!=b&&suma>=sumb){
        cout<<"No"<<endl;
        return 0;
    }
    ll cnta = 0;
    ll cntb = 0;
    rep(i,N){
        if(a[i]==b[i])continue;
        else if(a[i]<b[i]){
            if(b[i]-a[i]%2 == 0){
                cnta += (b[i]-a[i])/2;
            }
            else{
                cnta += (b[i]-a[i])/2 + 1;
                cntb += 1;
            }
        }
        else{
            cntb += a[i]-b[i];
        }
    }
    if(cnta-cntb<0){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}

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

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

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

   
int n;ll dp[3][3005][3005];ll a[3005];

ll f(int st,int l,int r)
{  //cout<<"visit "<<st<<" "<<l<<" "<<r<<endl;
	if(dp[st][l][r]!=-1)
	{
//	cout<<"already "<<st<<" "<<l<<" "<<r<<" "<<dp[st][l][r]<<endl;
	return dp[st][l][r];
}
	
	if(l==r)
	{     if(st==0)
		dp[st][l][r]=a[l];
		else
		dp[st][l][r]=-a[l];
	//	 cout<<"base "<<st<<" "<<l<<" "<<r<<" "<<dp[st][l][r]<<endl;
		return a[l];
	}
	f((st+1)%2,l+1,r);
	f((st+1)%2,l,r-1);
	
	if(st==0)
	dp[st][l][r]= max(a[l]+dp[(st+1)%2][l+1][r],a[r]+dp[(st+1)%2][l][r-1]);
	if(st==1)
	dp[st][l][r]= min(dp[(st+1)%2][l+1][r]-a[l],dp[(st+1)%2][l][r-1]-a[r]);
/*	if(st==1 and l==2 and r==4)
	cout<<a[l]<<" "<<dp[(st+1)%2][l+1][r]<<" "<<a[r]<<" "<<dp[(st+1)%2][l][r-1]<<" "<<a[l]-dp[(st+1)%2][l+1][r]<<" "<<a[r]-dp[st+1][l][r-1]<<
	endl;*/
	
//	cout<<"first time "<<st<<" "<<l<<" "<<r<<" "<<dp[st][l][r]<<endl;
	
	
	return dp[st][l][r];
}



main()
{ fastread
	cin>>n;
	
	for(int i=1;i<=n;i++)
	cin>>a[i];
	
	for(int i=0;i<3;i++)
	for(int j=0;j<3003;j++)
    for(int k=0;k<3003;k++)
	dp[i][j][k]=-1;
		
	f(0,1,n);
	cout<<dp[0][1][n];
	
}

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

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;

int main(){
    string S;
    cin >> S;
    if(S.find("N")!=string::npos&&S.find("S")==string::npos) cout << "No" << endl;
    else if(S.find("S")!=string::npos&&S.find("N")==string::npos) cout << "No" << endl;
    else if(S.find("E")!=string::npos&&S.find("W")==string::npos) cout << "No" << endl;
    else if(S.find("W")!=string::npos&&S.find("E")==string::npos) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
    
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 998244353
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

//power_mod
inline int Pow_mod(int x, int pow){
    if(pow==0) return 1;
    int a=Pow_mod(x, pow/2);
    a=a*a%mod;
    if(pow%2==1) a*=x;
    return a%mod;
}

//factorial_mod
int* fact_mod;
inline void init_fact_mod(int x){
    fact_mod = new int[x];
    fact_mod[0]=1;
    rep(i,x-1)fact_mod[i+1]=fact_mod[i]*(i+1)%mod;
}

//permutation_mod
inline int nPr_mod(int n, int r){
    return fact_mod[n]*Pow_mod(fact_mod[n-r]%mod, mod-2)%mod;
}

//combination_mod
inline int nCr_mod(int n, int r){
    return fact_mod[n]*Pow_mod(fact_mod[n-r]*fact_mod[r]%mod, mod-2)%mod;
}

signed main(void){
    
    int n,a,b,k; cin>>n>>a>>b>>k;
    init_fact_mod(300100);
    
    int ans=0;
    for(int i=0; i<=n; i++){
        int B=k-a*i;
        if(B%b==0 and B/b>=0 and B/b<=n){
            ans=(ans+(nCr_mod(n,i)*nCr_mod(n,B/b))%mod)%mod;
        }
    }
    
    cout<<ans<<endl;
    return 0;
    
}

Measured memory_bytes: 2560
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
#input = sys.stdin.readline
X = I()
five_l = [-1]*200
f=0
for a in range(200):
    five_l[a]=pow(a,5)
    now = five_l[a]
    for i in range(a+1):
        search = five_l[i]
        if search+now==X:
            f = 1
            print(a,-i)
            break
        elif now-search == X:
            print(a,i)
            f = 1
            break
    if f==1:
        break


Measured memory_bytes: 77396
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 998244353ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    s64 n, s;
    cin >> n >> s;
    vs64 a(n);
    rep (i, n) cin >> a[i];

    s64 dp[s + 1][3];
    rep (i, s + 1) rep (j, 3) dp[i][j] = 0;
    dp[0][0] = 1;

    rep (i, n)
    {
        for (int j = s; j >= 0; --j)
        {
            if (j >= a[i])
            {
                dp[j][0] = dp[j][0];
                dp[j][1] = (dp[j][1] + (dp[j - a[i]][1] + (i + 1) * dp[j - a[i]][0] % MOD)) % MOD % MOD;
                dp[j][2] = (dp[j][2] + ((n - i) * dp[j - a[i]][1] % MOD + (i + 1) * (n - i) * dp[j - a[i]][0] % MOD) % MOD) % MOD;
            }
            else
            {
                dp[j][0] = dp[j][0];
                dp[j][1] = dp[j][1];
                dp[j][2] = dp[j][2];
            }
        }
    }

    cout << dp[s][2] << "\n";
    return 0;
}



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

int main(){
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int ans = 0;
    for(int i = 1;i < n + 1;i++){
        if(i <= k)ans += x;
        else ans += y;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int main()
{
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;
	char	str[256];
	
	scanf("%d %d", &a, &b);

	ans = (a+b) / 2;
	if ( (a+b) % 2 != 0) printf("IMPOSSIBLE\n");
	else printf("%d\n",ans);


	return 0;
}

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

int main() {
  cout << fixed << setprecision(15);
  double pi=3.141592653589793;
  double a,b,h,m;
  cin>>a>>b>>h>>m;
  double p,q;
  p=30*(h+m/60);
  q=6*m;
  double d=max(p,q)-min(p,q);
  d=min(d,360-d);
  double c_=a*a+b*b-2*a*b*cos(d*pi/180);
  double c=pow(c_,0.5);
  cout<<c;
}

      

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,a) for(int i=0;i<(a);i++)
#define MOD 1000000007

int main(){
  int N;
  cin>>N;
  vector<pair<int,bool>> v(2*N);
  for(int i=0;i<2*N;i++){
    int x;
    cin>>x;
    bool y=(i<N);
    v[i]={x,y};
  }
  sort(v.begin(),v.end());
  ll ans=1;
  int cnt=0;
  for(int i=0;i<2*N;i++){
    int tmp=cnt+(v[i].second?1:-1);
    if(abs(tmp)<abs(cnt)) (ans*=cnt)%=MOD;
    cnt=tmp;
  }
  cout<<abs(ans)<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  int ans_w = 100 * a, ans_s = 0;
  // wx: 操作1を行う回数, wy: 操作2を行う回数
  for (int wx = 0; 100 * a * wx <= f; wx++) {
    for (int wy = 0; 100 * b * wy <= f; wy++) {
      int water = 100 * a * wx + 100 * b * wy;
      if (water > f) {
        continue;
      }
      // sx: 操作3を行う回数, sy: 操作4を行う回数
      int su_lim = f - water;
      for (int sx = 0; sx * c <= su_lim; sx++) {
        for (int sy = 0; sy * d <= su_lim; sy++) {
          int sugar = sx * c + sy * d;
          if (water + sugar > f) {
            continue;
          }
          if (sugar * 100 <= e * water) {
            if (ans_s * (sugar + water) <= sugar * (ans_s + ans_w)) {
              ans_s = sugar;
              ans_w = water;
            }
          }
        }
      }
    }
  }
  cout << ans_s + ans_w << " " << ans_s << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N=sc.nextInt();
        Set<String> presents=new HashSet<>();
        for (int i = 0; i < N; i++) {
            presents.add(sc.next());
        }
        System.out.println(presents.size());
    }
}

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  

int ipow(int base, int pow)
{
    int ans =1;
    while(pow)
    {
        if(pow&1)
            ans = (ans*base)%M;
        base = (base*base)%M;
        pow >>= 1;
    }
    return ans;
}
int modinv(int a)
{
    return ipow(a, M-2);
}
const int N = (int)1e6 + 5; 
vector<int> primes(N, 0);
void f()
{   
    primes[1] = 1;
    for(int i=2;i<N;i++)
    {
        if(primes[i] == 0)
        {
            for(int j=2*i;j<N;j+=i)
            {
                if(primes[j] == 0)
                    primes[j] = i;
            }
            primes[i] = i;
        }
    }
}


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    f();
    map<int, int> highest_power;
    for(int i=0;i<n;i++)
    {
        map<int, int> tmp;
        int t = v[i];
        while(t>1)
        {
            tmp[primes[t]]++;
            t/= primes[t];
        }
        for(auto& j:tmp)
        {
            highest_power[j.first] = max(highest_power[j.first], j.second);
        }
    }
    int ans = 0, lcm =  1;
    for(auto& i: highest_power)
    {
        lcm = (lcm*(ipow(i.first, i.second)))%M;
    }

    for(int i=0;i<n;i++)
    {
        ans = (ans + (lcm*modinv(v[i]))%M)%M;
    }
    cout << ans << "\n";
    
    return 0;
}



Measured memory_bytes: 8832
n,k = map(int,input().split())
a = [int(input()) for _ in range(n)]
"""
b := ruisekiwa
b[r]-b[l] >= (r-l)k
b[r]-rk >= b[l]-lk (1-indexed)
c := b[i]-ik
"""
b = [0 for _ in range(n)]
b[0] = a[0]
for i in range(1, n):
	b[i] = b[i-1] + a[i]

c = [b[i]-(i+1)*k for i in range(n)]

"""
cr >= cl なる ペア(l, r)の個数を求めたい.
for i in range(n), find (i,j)
"""

class BIT:
	"""
	<Attention> 0-indexed.
	query ... return the sum [0 to m]
	sum ... return the sum [a to b]
	sumall ... return the sum [all]
	add ... 'add' number to element (be careful that it doesn't set a value.)
	search ... the sum version of bisect.right
	output ... return the n-th element
	listout ... return the BIT list
	"""
	def query(self, m):
		res = 0
		while m > 0:
			res += self.bit[m]
			m -= m&(-m)
		return res
	
	def sum(self, a, b):
		return self.query(b)-self.query(a)
	
	def sumall(self):
		bitlen = self.bitlen-1
		return self.query(bitlen)

	def add(self, m, x):
		m += 1
		bitlen = len(self.bit)
		while m <= bitlen-1:
			self.bit[m] += x
			m += m&(-m)
		return
	
	def search(self, a):
		tmpsum = 0
		i = 0
		k = (self.bitlen-1).bit_length()
		while k >= 0:
			tmpk = 2**k
			if i+tmpk <= self.bitlen-1:
				if tmpsum + self.bit[i+tmpk] < a:
					tmpsum += self.bit[i+tmpk]
					i += tmpk
			k = k - 1
		return i+1
	
	def output(self, a):
		return self.query(a+1)-self.query(a)
	
	def listout(self):
		return self.bit
	
	def __init__(self, a):
		self.bitlen = len(a)+1
		self.bit = [0]*(len(a)+1)
		for i, j in enumerate(a):
			self.add(i, j)

def compress(arr):
	*XS, = set(arr)
	XS.sort()
	target = {e: i for i, e in enumerate(XS)}
	rtl = []
	for i in range(n):
		rtl.append(target[arr[i]])
	return rtl

d = compress(c)

bit = BIT([0 for _ in range(n)])
ans = 0
for i in range(n):
	bit.add(d[i], 1)
	ans += bit.sum(0, d[i]+1)
	if c[i] < 0:
		ans -= 1
print(ans)

Measured memory_bytes: 109336
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

//x vs y
//の試合の数字を返す
vector<vector<ll> > memo(1001,vector<ll>(1001,INF));
ll cnt=0;
ll game(ll x,ll y){
    if(x>y) swap(x,y);
    
    if(memo[x][y]!=INF) return memo[x][y];
    else return memo[x][y]=++cnt;
}

vector<ll> G[500050];//辺
//v:足跡
//c:cからのdfsの終了証明
vector<ll> visited(500050);
vector<ll> calculated(500050);
//d:c済みのとき、そのdfsの深さ
vector<ll> d(500050);

//最長経路を返す,閉路あれば-1
ll dfs(ll x){
    if(visited[x]){
        //dfs終わってないくせにまた訪れた = 閉路
        if(!calculated[x]) return -1;
        
        else return d[x];
    }
    
    //あしあと
    visited[x]=true;
    
    //枝先のmaxをとる
    ll ret=0;
    rep(i,sz(G[x])){
        ll tmp=dfs(G[x][i]);
        //-1は即伝搬
        if(tmp==-1) return -1;
        
        //更新作業
        chmax(ret,tmp);
    }
    
    //dfs終了!
    calculated[x]=true;
    
    return d[x]=ret+1;
}

int main(){
    //dの初期化
    rep1(i,500049) d[i]=INF;
    
    //入力
    ll N; cin>>N;
    ll ans=0;
    vector<vector<ll> > A(N+1,vector<ll>(N,0));
    rep1(i,N){
        rep1(j,N-1){
            cin>>A[i][j];
        }
    }
    
    //初日にやる試合をリストへ
    vector<ll> dfs_list;
    //iとjが初日のペアなら初日にやって良い
    //inする
    rep1(i,N-1){
        FOR(j,i+1,N+1){
            if(A[A[i][1]][1]==i) dfs_list.pb(game(i,j));
        }
    }
    
    //試合の前後を表す辺を張る
    rep1(i,N){
        //iは、A[i][j]との試合の後にしかA[i][j+1]との試合をできない
        rep1(j,N-2){
            G[game(i,A[i][j])].pb(game(i,A[i][j+1]));
        }
    }
    
    if(sz(dfs_list)==0) cout<<-1<<endl;
    else{
        rep(i,sz(dfs_list)){
            ll tmp=dfs(dfs_list[i]);
            //閉路発見
            if(tmp==-1){
                cout<<-1<<endl;
                return 0;
            }
            
            chmax(ans,tmp);
        }
        
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 61832
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int main()
{
    long long ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        if(i%3&&i%5)ans+=i;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;

  ll power = 1;
  for (int i = 1; i <= N; i++) {
    power *= i;
    power %= MOD;
  }

  // 解答
  cout << power << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define _LIBCPP_DEBUG 0
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;
//g++ -std=c++1z main.cpp
//.\a.exe
///////////////////////////////////////////////////////////
int main(){
    int a,b;
    cin >> a >> b;
    if(a<=9 && a>=1 && b<=9 && b>=1){
            cout << a*b << endl;
    }
    else{
        cout << -1 << endl;
    }
}
//////////////////////////////////////////////////////////

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
#define LINEY "YES\n"
#define Liney "Yes\n"
#define LINEN "NO\n"
#define Linen "No\n"

int main(){
  int N; cin>>N;
  char s[N]; scanf("%s",s);
  sort(s,s+N);
  bool r = false;
  REP(i,N/2+(N%2)){
    if(s[i]=='R'){r=true;break; }
  }
  cout <<(r?Liney:Linen);
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
total = 0

values = []
for s in (1, -1):
    xs = a[::]
    signs = [s * (-1) ** i for i in range(N)]
    total = 0
    for i in range(N):
        if (total + xs[i]) * signs[i] <= 0:
            xs[i] = signs[i] - total
        total += xs[i]
    values.append(sum(abs(a[i] - xs[i]) for i in range(N)))
print(min(values))

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = 0x3c3c3c3c;
const ll INFL = 0x3c3c3c3c3c3c3c3c;
const int MAX_N = 1e5 + 9;

int arr[MAX_N];
int numCount[MAX_N];

int main(){
	cin.sync_with_stdio(false);
	cin.tie(NULL);
	int N;
	cin >> N;
	for(int i = 0; i < N; i++) cin >> arr[i];
	for(int i = 0; i < N; i++) numCount[arr[i]]++;
	int ans = 0;
	for(int i = 0; i < MAX_N - 1; i++){
		int w = 0;
		if(i - 1 >= 0) w += numCount[i - 1];
		w += numCount[i + 1];
		ans = max(ans, w + numCount[i]);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#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() {
  int N;
  cin >> N;
  vector<int> H(N);
  rep(i,N) cin >> H[i];
  int ans = 1;
  for (int i = 1; i < N; ++i) {
    bool ok = true;
    for (int j = 0; j < i; ++j) {
      if (H[j] > H[i]) ok = false;
    }
    if (ok) ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3180
using System;
class Program
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int D = int.Parse(input[1]);
    
    // 入力の格納
    int[, ] X = new int[N, D];
    for(int n = 0; n < N; n++)
    {
      input = Console.ReadLine().Split(' ');
      for(int d = 0; d < D; d++)
      {
        X[n, d] = int.Parse(input[d]);
      }
    }
    
    // 全探索
    int count = 0;
    
    for(int i = 0; i < N - 1; i++)
    {
      for(int j = i + 1; j < N; j++)
      {
        long dist = 0;
        for(int e = 0; e < D; e++)
        {
          dist += (long)Math.Pow(X[i, e] - X[j, e], 2);
        }
        if (Math.Pow((long)Math.Sqrt(dist), 2) == dist)
          count++;
      }
    }
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 11092
n, y = map(int, input().split())
res10000, res5000, res1000 = -1, -1, -1
for i in range(n+1):
  if res10000 != -1:
    break
  for j in range(n-i+1):
    if res10000 != -1:
      break
    a = i
    b = j
    c = n - a - b
    total = 10000*a + 5000*b + 1000*c
    if total == y:
      res10000, res5000, res1000 = a, b, c
     
    

print(str(res10000) + " " + str(res5000) + " " + str(res1000))

Measured memory_bytes: 3188
import collections

h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
x=[]

for i in range(h):
    x+=a[i]

c = collections.Counter(x)
c = c.most_common()


if h%2==0 and w%2==0:
    for i in range(len(c)):
        if c[i][1]%4!=0:
            print('No')
            exit()

elif h%2==1 and w%2==0:
    for i in range(len(c)):
        if c[i][1]%4==0:
            continue
        elif c[i][1]%4==2:
            w-=2
            if w<0:
                print('No')
                exit()
        else:
            print('No')
            exit()
    

elif h%2==0 and w%2==1:
    for i in range(len(c)):
        if c[i][1]%4==0:
            continue
        
        elif c[i][1]%4==2:
            h-=2
            if h<0:
                print('No')
                exit()
        else:
            print('No')
            exit()

else:
    v=h+w-2
    r=1
    for i in range(len(c)):
        if c[i][1]%4==0:
            continue
        
        elif c[i][1]%4==3:
            v-=2
            r-=1
            if v<0 or r<0:
                print('No')
                exit()
                
        elif c[i][1]%4==2:
            v-=2
            if v<0:
                print('No')
                exit()
        
        else:
            r-=1
            if r<0:
                print('No')
                exit()
print('Yes')
            


        


                    
                    
                    

    




    
    
        



Measured memory_bytes: 39024
n, m = map(int, input().split())
s_c = [list(map(int, input().split())) for i in range(m)]

for i in range(0, 10**n):
    if len(str(i)) == n:
        tmp = '@' + str(i) # '@' Dummy 
        for j in range(m):
            if tmp[s_c[j][0]] != str(s_c[j][1]):
                break
        else:
            print(i)
            exit()
else:
    print(-1)

Measured memory_bytes: 3064
def abc042_c():
    price, len_hate_set = map(int, input().split())
    hate_set = set([int(i) for i in input().split()])
    usable_set = set(range(0, 10)) - hate_set
    
    while True:
        if all(map(lambda x: int(x) in usable_set,
                   [int(str(price)[i]) for i in range(len(str(price)))])) and price >= price:
            return price

        price += 1


if __name__ == '__main__':
    print(abc042_c())

Measured memory_bytes: 3188
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = int(arr_data[0][0])
arr = arr_data[1]

arr2 = list(map(int, arr))

#print(n, arr, arr2)


mycnt = 0

chkflg = True

while chkflg:

    arr_temp=[]
    for v in arr2:

        if(v % 2 == 1):

            chkflg = False

        else:

            arr_temp.append(v / 2)

    else:
        
        if chkflg:
            
            mycnt+=1
        
        arr2 = arr_temp
        
print(mycnt)

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

int func(ll n){
  int res = 0;
  while(n>0){
    ++res;
    n /= 10;
  }
  return res;
}

int main(){
  ll n;
  int   ans = 10;
  cin >> n;
  for(ll i = 1;i*i<=n; i++){
    if(n%i!=0) continue;
        ll a = i;
        ll b = n/i;
        int tmp = (func(a),func(b));
        ans = min(ans, tmp);
      }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

int main(int argc, char *argv[]){
    int A1,A2,A3;
    std::cin >> A1 >> A2 >> A3;
    int result = A1+A2+A3;
    if(result >= 22){
        std::cout << "bust" << std::endl;
    }else{
        std::cout << "win" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int		main()
{
	int		K;
	int		nbrs[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1,
						2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

	scanf("%d\n", &K);
	printf("%d\n", nbrs[K - 1]);
	return (0);
}


Measured memory_bytes: 128
#very important question
n,k=map(int,input().split())
L=list(map(int,input().split()))

visit=[False]*(n+1)

town=[]

next=1
while 1:
    next = L[next-1]
    if not visit[next]:
        town.append(next)
        visit[next] = True
    else:
        town.append(next)
        break
#print(town)
for i in range(n):
    if town[i]==town[-1]:
        mod=i
        index=i
        loop=len(town)-i-1
        loop_array = town[i:-1]
        break

fin_len = (k-mod)%loop
if k<=mod:
    print(town[k-1])
else:
    print(loop_array[fin_len-1])


Measured memory_bytes: 32300
#include<bits/stdc++.h>
using namespace std;
const int N=1010;
int n,t,cnt[N];bool flag=0;char a[N][N];
int b[4][10][10]={
{
{ 1, 2, 3, 3},

{ 1, 2, 4, 4},

{ 5, 5, 6, 7},

{ 8, 8, 6, 7}
},
{
{ 0, 0, 1, 2, 3},

{ 0, 0, 1, 2, 3},

{ 4, 4, 5, 6, 6},

{ 7, 7, 5, 0, 8},

{ 9, 9,10,10, 8}
},
{
{ 0, 0, 0, 1, 2, 3},

{ 0, 0, 0, 1, 2, 3},

{ 4, 0, 5, 5, 0, 6},

{ 4, 7, 7, 0, 0, 6},

{ 8, 8, 9, 0,10,10},

{11,11, 9,12,12, 0}
},
{
{ 0, 0, 0, 0, 1, 2, 3},

{ 0, 0, 0, 0, 1, 2, 3},

{ 0, 0, 0, 0, 4, 5, 6},

{ 0, 0, 0, 0, 4, 5, 6},

{ 7, 7, 8, 8, 0, 0, 9},

{10,10,11,11, 0, 0, 9},

{12,12,13,13,14,14, 0}
}
};
// void check(){
//     if(!t)return;
//     for(int i=0;i<n;i++){
//         int nn=0;
//         for(int j=0;j<n;j++)
//             if(a[j][i]&&(!j||a[j][i]!=a[j-1][i]))nn++;
//         if(nn!=cnt[0])return;
//     }
//     for(int i=0;i<n;i++){
//         putchar('{');
//         for(int j=0;j<n;j++){printf("%2d",a[i][j]);if(j<n-1)putchar(',');}
//         puts("},\n");
//     }
//     flag=1;
// }
// void dfs(int id){
//     if(flag)return;
//     int x=id/n,y=id%n;
//     if(x&&!y){
//         int xx=x-1;cnt[xx]=0;
//         for(int i=0;i<n;i++)if(a[xx][i]&&(!i||a[xx][i]!=a[xx][i-1]))cnt[xx]++;
//         if(cnt[xx]!=3)return;
//     }
//     if(id==n*n){check();return;}
//     if(a[x][y]){dfs(id+1);return;}
//     dfs(id+1);
//     if(x<n-1&&!a[x+1][y]){
//         t++,a[x][y]=a[x+1][y]=t;
//         dfs(id+1);
//         a[x][y]=a[x+1][y]=0;t--;
//     }
//     if(y<n-1&&!a[x][y+1]){
//         t++,a[x][y]=a[x][y+1]=t;
//         dfs(id+1);
//         a[x][y]=a[x][y+1]=0;t--;
//     }
// }
int main(){
    scanf("%d",&n);
    if(n<3)puts("-1"),exit(0);
    if(n==3)puts("aa.\n..b\n..b"),exit(0);
    int x=(n-4)/4,y=n%4+4;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)a[i][j]='.';
    for(int i=0;i<x;i++)
        for(int j=0,p=i*4;j<4;j++)
            for(int k=0;k<4;k++)
                if(b[0][j][k])
                    a[j+p][k+p]=b[0][j][k]+'a'-1;
    for(int i=0,p=x*4;i<y;i++)
        for(int j=0;j<y;j++)if(b[y-4][i][j])
            a[i+p][j+p]=b[y-4][i][j]+'a';
    for(int i=0;i<n;i++)puts(a[i]);
    return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(b>=a)
        printf("%d",a);
    else
        printf("%d",a-1);
    return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())

g_cards = list(map(int, input().split()))

# key-valueデータで管理
dict_cards = []
for card in g_cards:
	dict_cards.append([card, 1])

# 操作
for i in range(M):
	# sizeと同じ枚数のカードが増えたと考える
	size, val = map(int, input().split())
	dict_cards.append([val, size])

# 降順にする
s_dict_cards = sorted(dict_cards, key=lambda x: -x[0])

s_cards = []
for data in s_dict_cards:
	s_cards += [data[0]] * data[1]
	if(len(s_cards) >= N):
		break
# 出力
sum_val = sum(s_cards[:N])
print(sum_val)

Measured memory_bytes: 45632
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}

int main() {
    long long n, d, max = -1, c = 0, ans = 0;
    cin >> n;
    vector<long> as(n);
    for (int i = 0; i < n; i++){
        cin >> as[i];
    }
    for (int i = 0; i < n; i++){
        c = 0;
        d = as[i];
        while (2 * (d / 2) == d){
            d = d / 2;
            c++;
        }
        max = max + c;
//        if (c > max && c > 0){
//            max = c;
//        }
    }
    cout << max + 1 << endl;
}

Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let l = read::<i64>();
    let r = read::<i64>();
    let mut ans = 2020;
    for i in l..std::cmp::min(r + 1, l + 2020) {
        for j in (i + 1)..std::cmp::min(r + 1, i + 2020) {
            ans = std::cmp::min(ans, i * j % 2019);
        }
    }
    println!("{}", ans);
}


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

int main()
{
  std::string a, b;
  std::cin >> a >> b;
  int num = atoi((a+b).c_str());
  auto root = std::sqrt(num);
  if(static_cast<int>(root)==root) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll n, k, m, M = 1e9 + 7;

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

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

    ll a, b;
    cin >> a >> b;

    ll d = gcd(a, b);

    ll num = 1;
    if(d % 2 == 0) {
        num++;
        while(d % 2 == 0) d /= 2;
    }
    for(ll i = 3; i * i < d; i++) {
        if(d % i == 0) {
            num++;
            while(d % i == 0) d /= i;
        }
    }
    if(d != 1) num++;

    cout << num << endl;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int d[35][35];
int c[505][505];
int cost[5][35];

int main(){
  int N, C; cin >> N >> C;
  for(int i = 1; i<=C;i++){
    for(int j = 1; j<=C;j++){
      cin >> d[i][j];
    }
  }

  for(int i = 1; i<=N;i++){
    for(int j = 1; j<=N;j++){
      cin >> c[i][j];
    }
  }
  for(int i = 1; i <=N; i++){
    for(int j = 1; j <=N; j++){
      for(int k = 1; k <=C; k++){
          cost[(i+j)%3][k] += d[c[i][j]][k];
      }
    }
  }
  int ans = 1 << 30;
  for(int i=1;i<=C;i++){
    for(int j=1;j<=C;j++){
      for(int k=1;k<=C;k++){
        if(i==j||i==k||j==k) continue;
        chmin(ans,cost[0][i]+cost[1][j]+cost[2][k]);
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}

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

int main(){
  int n;
  long long count=0,answer=0;
  cin >> n;
  vector<string> data(n);
  
  for(int i=0; i<n; i++){
    string tmp;
    cin >>tmp;
    sort(tmp.begin(),tmp.end());
    data.at(i) = tmp;
  }
  
  sort(data.begin(),data.end());
  
  for(int i=0; i<n-1; i++){
    if(data.at(i) == data.at(i+1)){
      answer++;
      count++;
    }else{
      while(count > 0){
        answer += count-1;
        count--;
      }
    }
  }
  
  if(count == n-1){
    while(count > 0){
      answer += count-1;
      count--;
    }
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 5760
#include <stdio.h>

int main (void)
{
	//変数宣言
	int x,y,z,ans;//入力
	char str[8]; //標準入力読み取り用
	
	//標準入力読み込み
	fgets(str,8,stdin);
	sscanf(str,"%d %d %d",&x,&y,&z);
	
  	ans = 100*x + 10*y + z;
	
	//出力
	if((ans % 4) == 0)
	{
		puts("YES");
	}else
	{
		puts("NO");
	}
	
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


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


def main():
    a, b, c, d = map(int, input().split())
    if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):
        print(Yes)
    else:
        print(No)


if __name__ == '__main__':
    main()


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

int H, W;
int wall;
int M[102][102];
bool vis[102][102];

/* 
   テヲツュツ」テ・ツ?ュティツァツ津・ツスツ「テ」ツ?ョテァツオツ古ィツキツッテヲツ篠「テァツエツ「
   テ・ツ?・テ・ツ環崚」ツ?ィテ・ツ崢ウテ」ツ?ィテ」ツ?ョテ・ツッツセテ・ツソツ愿」ツつ津ィツェツュテ」ツ?ソテ・ツ渉姪」ツつ甘」ツ??・ツ青古」ツ??テ」ツ?ォテ・ツッツセテ」ツ?凖」ツつ及テ」ツ?ョテ・ツ・ツ?ヲツ閉ーテァツ閉ェテァツ崢ョテ」ツ?ィテ・ツ?カテヲツ閉ーテァツ閉ェテァツ崢ョテ」ツ?ョ
   2テ」ツδ榲」ツつケテ」ツつ津・ツ渉づィツ?ε」ツ?ォテ・ツ?ィテヲツ鳴ケテ・ツ青妥ヲツ篠「テァツエツ「テ」ツ?ァテ」ツ?催」ツつ凝」ツつ暗」ツ??」ツ?ェテァツァツサテ・ツ仰陛・ツキツョテ・ツ按?」ツつ津ィツィツュテ・ツョツ堙」ツ??
   テ・ツ?・テ・ツ環崚」ツ?ィテ・ツ崢ウテ」ツ?ィテ」ツ?ョテ・ツッツセテ・ツソツ愿ゥツ鳴「テ、ツソツづ」ツ?ッテ」ツ??・ツ崢ウテ、ツクツ甘」ツ?ォテゥツ?ゥテ・ツスツ禿」ツ?ェyティツサツクテ、ツクツヲティツ。ツ古」ツ?ョテァツ崢エテァツキツ堙」ツつ津・ツシツ陛」ツ?湘」ツ?ィテァツ崢エテ」ツ?ォテ」ツつ湘」ツ?凝」ツつ?
 */
const int dx[2][6] = {{ 1,-1, 0, 0,-1,-1},{ 1,-1, 0, 0, 1, 1}};
const int dy[6]    =  { 0, 0, 1,-1,-1, 1};

bool isInField(int x, int y) {
  return 0<=x&&x<=W+1 && 0<=y&&y<=H+1;
}

void dfs(int x, int y){

  vis[y][x] = true;

  for(int i=0; i<6; i++) {
    int nx = x+dx[y%2][i], ny = y+dy[i];
    if(isInField(nx, ny)) {
      if(vis[ny][nx]) continue;
      if(M[ny][nx]) wall ++;
      else dfs(nx, ny);
    }
  }
}

int main(){

  fill(M[0], M[102], 0);
  fill(vis[0], vis[102], false);

  cin >> W >> H;

  for(int i=1; i<=H; i++) {
    for(int j=1; j<=W; j++) {
      cin >> M[i][j];
    }
  }
  
  wall = 0; dfs(0, 0);
  cout << wall << endl;
  
  return 0;
}

Measured memory_bytes: 1456
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val x = List.fill(n)(sc.nextLong())
  val y = List.fill(m)(sc.nextLong())

  val mod = 1000000007

  def plus(a: Long, b: Long): Long = (a + b) % mod
  def times(a: Long, b: Long): Long = (a * b) % mod

  val c = x.sliding(2).map{
    case List(x1, x2) => x2 - x1
  }.zipWithIndex.map{
    case (e, idx) => times(times(e, idx+1), n-idx-1)
  }.reduceLeft(plus)

  val d = y.sliding(2).map{
    case List(y1, y2) => y2 - y1
  }.zipWithIndex.map{
    case (e, idx) => times(times(e, idx+1), m-idx-1)
  }.reduceLeft(plus)

  println(times(c, d))
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i];

    }

    for(int i = n - 2; i >= 0; --i) {
        if(v[i] > v[i + 1]) v[i]--;

    }

    int mn = v[n - 1];
    for(int i = n - 2; i >= 0; --i) {
        mn = min(mn, v[i]);
        if(mn < v[i]) {
            cout << "No" << endl;
            return 0;

        }
    }
    cout << "Yes" << endl;

    return 0;
}



Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <climits>
using namespace std; 
#define ll long long int


int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m), b(m), c(m);
    for(int i = 0; i < m; ++i){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
    }

    vector<ll> d(n, -1e18);
    vector<bool> used(n, false);
    d[0] = 0;
    used[0] = true;
    for(int i = 0; i <= 5 * m; ++i){
        for(int j = 0; j < m; ++j){
            if(used[a[j]]){
                if(!used[b[j]]){
                    used[b[j]] = true;
                    d[b[j]] = d[a[j]] + c[j];
                }
                else{
                    if(d[b[j]] < d[a[j]] + c[j]){
                        if(b[j] == n - 1 && i > 2 * n){
                            cout << "inf\n";
                            return 0;
                        }
                        d[b[j]] = d[a[j]] + c[j];
                    }
                }
            }
        }
    }
    cout << d[n - 1];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
const int MAX = 1e5 + 10;
const double exps = 1e-8;
#define swap(a, b)            \
    {                         \
        register int tmp = a; \
        a = b;                \
        b = tmp;              \
    }

inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a > b ? b : a; }
int n, k, c;
vector<int> L, R;
string s;
int main() {
    cin >> n >> k >> c >> s;
    for (int i = 1; i <= s.size();) {
        if (s[i - 1] == 'o') {
            L.push_back(i);
            i += c;
        }
        i++;
        if (L.size() == k) break;
    }
    for (int i = s.size(); i >= 1;) {
        if (s[i - 1] == 'o') {
            R.push_back(i);
            i -= c;
        }
        --i;
        if (R.size() == k) break;
    }
    for (int i = 0; i < k; ++i) {
        if (L[i] == R[k - 1 - i]) printf("%d\n", L[i]);
    }
}

Measured memory_bytes: 3448
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,K;
  cin>>N>>K;
  int ans=1;
  while(N>0 and ans<K){
    ans*=2;
    N--;
  }
  ans+=K*N;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256