akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int A,B,Q;
    cin >> A >> B >> Q;
    vector<ll> s(A), t(B), x(Q);
    REP(i, A) cin >> s[i];
    REP(i, B) cin >> t[i];
    REP(i, Q) cin >> x[i];

    REP(i, Q){
        ll s11, s12, t11, t12;
        int it = lower_bound(ALL(s), x[i]) - s.begin();
        if(it == 0){
            s11 = -MAXINF;
            s12 = s[it];
        }else if(it == A){
            s11 = s[it-1];
            s12 = MAXINF;
        }else{
            s11 = s[it-1];
            s12 = s[it];
        }
        it = lower_bound(ALL(t), x[i]) - t.begin();
        if(it == 0){
            t11 = -MAXINF;
            t12 = t[it];
        }else if(it == B){
            t11 = t[it-1];
            t12 = MAXINF;
        }else{
            t11 = t[it-1];
            t12 = t[it];
        }
        ll ans = MAXINF;
        if(s11 < t11 && t11 < x[i]) ans = min(ans, x[i] - s11);
        if(t11 < s11 && s11 < x[i]) ans = min(ans, x[i] - t11);
        if(s11 < x[i] && x[i] < t12) ans = min(ans, t12 - s11 + min(t12 - x[i], x[i] - s11));
        if(t11 < x[i] && x[i] < s12) ans = min(ans, s12 - t11 + min(s12 - x[i], x[i] - t11));
        if(x[i] < s12 && s12 < t12) ans = min(ans, t12 - x[i]);
        if(x[i] < t12 && t12 < s12) ans = min(ans, s12 - x[i]);
        pr(ans);
    }
}

Measured memory_bytes: 3712
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        a: usize, b: usize, c: usize,
    }
    let mut sum = a;
    let mut ans = false;

    for _ in 0..10000 {
        if sum % b == c {
            ans = true;
            break
        }
        sum += a;
    }

    if ans {
        println!("YES");
    } else {
        println!("NO");
    }
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


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

int main(){
	int a,b,m,ans=1e9;
	cin>>a>>b>>m;
	int aa[100000],bb[100000];
	for(int i=0;i<a;++i)cin>>aa[i];
	for(int i=0;i<b;++i)cin>>bb[i];
	for(int i=0,pa,pb,minus;i<m;++i){
		cin>>pa>>pb>>minus;
		ans=min(ans,aa[pa-1]+bb[pb-1]-minus);
	}
	sort(aa,aa+a);
	sort(bb,bb+b);
	ans=min(ans,aa[0]+bb[0]);
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 1024
N=int(input())
C=[0]*4
for i in map(int, input().split()):
    if i==1:
        C[1]+=1
    elif i==2:
        C[2]+=1
    else:
        C[3]+=1
dp = [[[.0] * (N + 2) for _ in range(N + 2)] for _ in range(N + 2)]
for i in range(C[3] + 1):
    for j in range(N - C[1] - i + 1):
        for k in range(N - i - j + 1):
            if i + j + k != 0:
                dp[i][j][k] = (
                    N +
                    i * dp[i - 1][j + 1][k] +
                    j * dp[i][j - 1][k + 1] +
                    k * dp[i][j][k - 1]
                ) / (i + j + k)
print(dp[C[3]][C[2]][C[1]])

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

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  int max_num = max(A, B);
  max_num = max(max_num, C);
  int X = max_num - A;
  int Y = max_num - B;
  int K = A + B + C;
  int ans = 0;
  if ((3 * max_num - K) % 2 == 1)
  {
    ans = (3 * max_num - K + 1) / 2 + 1;
  }
  else
  {
    ans = (3 * max_num - K) / 2;
  }

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

Measured memory_bytes: 256
//  -- ILSH -- //
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define viii vector < vii >
#define vlll vector < vll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=200000+6;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int aa;
    int val=1;
    for ( int i=0;i<n;i++)
    {
        cin>>aa;
        if ( aa==val)
            val++;
    }
    if ( val==1)
        cout<<-1<<'\n';
    else
        cout<<n-val+1<<'\n';

}

Measured memory_bytes: 256
a = []
tmp = []
A,B = map(int,input().split())
b = B-(A-1)
for i in range(A*2-1):
  if A == 1:
    a.append(B) 
  else:
    a.append(b+i)
while a:
  e = a.pop()
  if e <= 10000000 and e>=-10000000:
    tmp.append(e)
tmp = sorted(tmp)
tmp = [str(n) for n in tmp]
p =' '.join(tmp)
print(p)

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

int main() {
  string Atcoder, s, Contest;

  cin >> Atcoder >> s >> Contest;

  cout << Atcoder.substr(0, 1) + s.substr(0, 1) + Contest.substr(0, 1) << endl;
  return 0;
}

Measured memory_bytes: 256
/// meowa 

#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")

#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
#define all(z) (z).begin(), (z).end()
 
using namespace std;

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

const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
  
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void fin() {
#ifdef AM
    freopen(".in", "r", stdin);
#endif        
}                   

const bool flag = 0;

void ma1n() {
    int x;
    cin >> x;
    cout << (x^1);
} 

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), fin();
    int ts = 1;
    if (flag) {
        cin >> ts;
    }
    while (ts--) {
        ma1n(); 
    }
    return 0;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int search(vector<LL> &v, LL x) {
    int left = 0;
    int right = v.size() - 1;
    if(v[right] < x) {
        return right;
    }
    if(x < v[left]) {
        return left;
    }
    for(;1 < right - left;) {
        int mid = (left + right)/2;
        if(v[mid] < x) {
            left = mid;
        }else{
            right = mid;
        }
    }
    return left;
}

int main() {
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<LL> s(A);
    vector<LL> t(B);

    REP(i, A) {
        cin >> s[i];
    }
    REP(i, B) {
        cin >> t[i];
    }

    REP(q, Q) {
        LL x;
        cin >> x;

        int ls = search(s, x);
        int rs = min(A - 1, ls + 1);
        int lt = search(t, x);
        int rt = min(B - 1, lt + 1);
        vector<vector<LL>> v = {{s[ls], s[rs]}, {t[lt], t[rt]}};
        LL res = LINF;
        REP(i, 2) {
            REP(j, 2) {
                LL a = abs(v[0][i] - x) + abs(v[1][j] - v[0][i]);
                LL b = abs(v[1][i] - x) + abs(v[0][j] - v[1][i]);
                res = min({res, a, b});
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,M,ac,A[1<<17],B[1<<17];
vector<pair<int,int> >G[1<<17];
bool used[2<<17],vis[1<<17];
bool dfs(int u)
{
	vis[u]=true;
	for(pair<int,int>e:G[u])
	{
		int v=e.first;
		if(!vis[v]&&dfs(v))
		{
			B[u]++,B[v]++,ac++;
			used[e.second]=true;
		}
	}
	return B[u]%=2;
}
main()
{
	cin>>N>>M;
	vector<pair<int,int> >AB(N);
	for(int i=0;i<N;i++)cin>>AB[i].first>>AB[i].second;
	sort(AB.begin(),AB.end());
	bool pb=false;
	for(int i=0;i<N;i++)
	{
		A[i]=AB[i].first;
		B[i]=pb;
		B[i]^=pb=AB[i].second;
	}
	B[N]=pb;
	for(int i=0;i<M;i++)
	{
		int L,R;cin>>L>>R;
		L=lower_bound(A,A+N,L)-A;
		R=upper_bound(A,A+N,R)-A;
		G[L].push_back({R,i});
		G[R].push_back({L,i});
	}
	for(int i=0;i<=N;i++)if(!vis[i]&&dfs(i))
	{
		cout<<-1<<endl;
		return 0;
	}
	cout<<ac<<endl;
	for(int i=0;i<M;i++)if(used[i])cout<<i+1<<endl;
}

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

int main()
{
   int n,i,l,j,val;
   long long int count=0;
   cin>>n;
   vector<int> v;
   for(i=0;i<n;i++)
   {
       cin>>l;
       v.push_back(l);
   }
   sort(v.begin(),v.end());
   for(i=0;i<n-1;i++)
   {
       for(j=i+1;j<n-1;j++)
       {
           val=v[i]+v[j];
           vector<int>::iterator it;
           it=lower_bound(v.begin()+j+1,v.end(),val);
           count+=((it-v.begin()-1)-j);
       }
   }
   cout<<count<<"\n";
   return 0;
}

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

using namespace std;

long long n, a[3010];
pair<long long, long long> memo[3010][3010];

pair<long long, long long> dp(long long l, long long r) {
	if(l > r) {
		return make_pair(0, 0);
	}
	if(memo[l][r] != make_pair((long long)-1, (long long)-1)) {
		return memo[l][r];
	}
	memo[l][r] = make_pair(0, 0);
	if((n - (r - l + 1)) % 2 == 0) {
		pair<long long, long long> ret, temp;
		ret = make_pair(0, 0);
		temp = dp(l + 1, r);
		ret.first = ret.first + a[l] + temp.first;
		ret.second = ret.second + temp.second;
		memo[l][r] = ret;
		ret = make_pair(0, 0);
		temp = dp(l, r - 1);
		ret.first = ret.first + a[r] + temp.first;
		ret.second = ret.second + temp.second;
		if(ret.first - ret.second > memo[l][r].first - memo[l][r].second) {
			memo[l][r] = ret;
		}
	}
	else {
		pair<long long, long long> ret, temp;
		ret = make_pair(0, 0);
		temp = dp(l + 1, r);
		ret.first = ret.first + temp.first;
		ret.second = ret.second + a[l] + temp.second;
		memo[l][r] = ret;
		ret = make_pair(0, 0);
		temp = dp(l, r - 1);
		ret.first = ret.first + temp.first;
		ret.second = ret.second + a[r] + temp.second;
		if(ret.first - ret.second < memo[l][r].first - memo[l][r].second) {
			memo[l][r] = ret;
		}
	}
	return memo[l][r];
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	for(long long i = 0; i < 3010; i++) {
		for(long long j = 0; j < 3010; j++) {
			memo[i][j] = make_pair(-1, -1);
		}
	}
	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> a[i];
	}
	pair<long long, long long> ans = dp(1, n);
	cout << ans.first - ans.second << endl;
}

Measured memory_bytes: 141952
h,w=map(int,input().split())
s=[input() for _ in range(h)]

paint=((1,0),(0,1))
dp=[[0]*(w) for _ in range(h)] # そのマスにたどり着くまでに何回色の変更を経験するか

dp[0][0]=0
for i in range(h-1):
    dp[i+1][0]=dp[i][0]+(s[i][0]!=s[i+1][0])

for i in range(h):
    for j in range(1,w):
        if i==0:
            dp[i][j]=dp[i][j-1]+(s[i][j-1]!=s[i][j])
        else:
            dp[i][j]=min(dp[i][j-1]+(s[i][j-1]!=s[i][j]), dp[i-1][j]+(s[i][j]!=s[i-1][j]))
        
if dp[h-1][w-1]==0:
    if s[0][0]=='.':
        print(0)
    else:
        print(1)
    exit()

if s[0][0]=='.' and s[h-1][w-1]=='.':
    print(dp[h-1][w-1]//2)
    exit()
    
if (s[0][0]=='#' and s[h-1][w-1]=='.') or (s[0][0]=='.' and s[h-1][w-1]=='#'):
    print((dp[h-1][w-1]+1)//2)
    exit()

if s[0][0]=='#' and s[h-1][w-1]=='#':
    print(dp[h-1][w-1]//2+1)
    exit()

Measured memory_bytes: 41328
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

const ll mod = 1000000007LL;
ll dp[10001][2][100];

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

    string s;
    int D;
    cin >> s >> D;

    int l = s.size();
    dp[0][0][0] = 1;
    for (int i = 0; i < l; i++) {
        for (int j = 0; j < 2; j++) {
            int x = j ? 9 : s[i] - '0';
            for (int d = 0; d <= x; d++) {
                for (int k = 0; k < D; k++) {
                    dp[i+1][j || d < x][(k+d)%D] += dp[i][j][k];
                    dp[i+1][j || d < x][(k+d)%D] %= mod;
                }
            }
        }
    }

    cout << (dp[l][0][0] + dp[l][1][0] - 1 + mod) % mod << "\n";
    return 0;
}

Measured memory_bytes: 15872
"""
import bisect
N = int(input())
ans = 0
hikidashi_list = [1, 6, 9]
tmp_6 = 6
tmp_9 = 9
while tmp_6 < N:
    tmp_6 *= 6
    hikidashi_list.append(tmp_6)

while tmp_9 < N:
    tmp_9 *= 9
    hikidashi_list.append(tmp_9)

hikidashi_list.sort()
while N > 0:
    now = bisect.bisect_left(hikidashi_list, N)
    if now == 0:
        N -= 1
    else:
        N -= hikidashi_list[now-1]
    ans += 1
print(ans)

# 貪欲に大きいお金から取るのでは無理
# N = 13 解3 (6, 6, 1)  本法5 (9, 1, 1, 1, 1)
"""

# DP
N = int(input())
dp = [100000000] * (N+1)
dp[0] = 0
dp[1] = 1
ans = 0
hikidashi_list = [1, 6, 9]
tmp_6 = 6
tmp_9 = 9
while tmp_6 < N:
    tmp_6 *= 6
    hikidashi_list.append(tmp_6)

while tmp_9 < N:
    tmp_9 *= 9
    hikidashi_list.append(tmp_9)
hikidashi_list.sort()
for i in range(N+1):
    for k in hikidashi_list:
        if i + k > N :
            break
        dp[i+k] = min(dp[i] + 1, dp[i+k])

print(dp[N])

Measured memory_bytes: 41708
def calcotoshidama(n,y):
    for ichiman in range(n+1):
        for gosen in range(n-ichiman+1):
            if 10000*ichiman + 5000*gosen + 1000*(n-ichiman-gosen) == y:
                return [ichiman,gosen,n-ichiman-gosen]
    return [-1,-1,-1]

if __name__ == "__main__":
    n,y = map(int,input().split())
    print(' '.join(map(str,calcotoshidama(n,y))))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>

using namespace std;

int n;
vector<int> s;

int main(){
  cin >> n;
  int tmp;
  for(int i = 0; i < n; i++) {
    cin >> tmp;
    s.push_back(tmp);
  }
  sort(s.begin(), s.end());
  int sum = accumulate(s.begin(), s.end(), 0);
  for(int i = 0; i < n; i++) {
    if(sum%10 != 0 || sum == 0) {
      break;
    } else if (s[i]%10 != 0) {
      sum -= s[i];
    }
  }
  if(sum%10 == 0 ) sum = 0;
  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 3616
N = int(input())
P = [tuple(map(int, input().split())) for i in range(N)]

s = set(P)

ans = 0
for i in range(N):
    xi, yi = P[i]
    for j in range(N):
        if i == j:
            continue
        xj, yj = P[j]
        dx = xi - xj; dy = yi - yj
        cnt = 0
        for x, y in P:
            if (x+dx, y+dy) in s:
                cnt += 1
        ans = max(ans, cnt)
print(N - ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000


int main(){
	
	int N;
	cin>>N;
	
	vector<int> C(N+1,0);
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		C[a]++;
	}
	sort(C.begin(),C.end());
	C.insert(C.begin(),0);
	auto S = C;
	for(int i=1;i<C.size();i++)S[i]+=S[i-1];
	
	vector<int> ans(N+1,0);
	
	for(int i=1;i<=N;i++){
		int ind = distance(C.begin(),lower_bound(C.begin(),C.end(),i));
		int cnt = 0;
		if(ind!=0)cnt += S[ind-1];
		cnt += i*(C.size()-ind);
		cnt/=i;
		cnt = min(cnt,N);
		if(cnt>=0)ans[cnt] = i;
	}
	
	for(int i=N-1;i>=0;i--)ans[i] = max(ans[i],ans[i+1]);
	for(int i=1;i<=N;i++)cout<<ans[i]<<endl;

	
	return 0;
}

Measured memory_bytes: 6692
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;



int main(){
    int N,M;cin>>N>>M;
    int k[15],s[15][15],p[15];
    rep(i,0,M){
        cin>>k[i];
        rep(j,0,k[i]){
            cin>>s[i][j];
        }
    }
    rep(i,0,M)cin>>p[i];
    int sw[15],anscn=0,tmpcn=0,ok=1;
    
    for(int i=0;i<(1<<N);i++){
        ok=1;
        rep(j,0,N){
            if(i&(1<<j))sw[j]=1;
            else sw[j]=0;
        }
        rep(j,0,M){
            tmpcn=0;
            rep(m,0,k[j]){
                tmpcn+=sw[s[j][m]-1];
            }
            if(tmpcn%2!=p[j])ok=0;
        }
        if(ok)anscn++;
        
    }
    cout<<anscn<<endl;
}






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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    long long a,b;
    cin>>a>>b;

    if((b-a)%2==0)
        cout<<(b-a)/2;
    else{
        cout<<1+(b-a-1)/2+min(a-1,n-b);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <queue>
using namespace std;
typedef pair<int,int> pa;
typedef pair<int,pair<int,int> > pip;

queue<pip> q;
int maze[170][172];
int visited[170][172];

int main(){
    int w,h;
    while(1){
        int suc=0;
        while (!q.empty())
            q.pop();
        cin>>w>>h;
        if(w==0)break;
        memset(maze,0,sizeof(maze));
        memset(visited,0,sizeof(visited));
        
        for(int i=0;i<2*h+1;i++){
            maze[i][0]=1; maze[i][2*w]=1;
        }
        for(int i=0;i<2*w+1;i++){
            maze[0][i]=1; maze[2*h][i]=1;
        }
        for(int i=1;i<h*2;i++){
            if(i%2==1)
                for(int j=1;j<w;j++)
                    cin>>maze[i][2*j];
            else
                for(int j=1;j<w+1;j++)
                    cin>>maze[i][2*j-1];
        }
        q.push(pip(1,pa(1,1)));
        while(q.size()>0){
            pip tem=q.front(); q.pop(); int f=tem.first; pa p=tem.second;
            int x=p.first,y=p.second;
            if(x==2*w-1&&y==2*h-1){
                cout<<f<<endl;
                suc=1;
                break;
            }
            maze[y][x]=8;
            if(maze[y][x-1]==0&&visited[y][x-2]==0&&x-2>=0){
                q.push(pip(f+1,pa(x-2,y)));
                visited[y][x-2]=1;
            }
            if(maze[y][x+1]==0&&visited[y][x+2]==0&&w+2<=w*2+2){
                q.push(pip(f+1,pa(x+2,y)));
                visited[y][x+2]=1;
            }
            if(maze[y-1][x]==0&&visited[y-2][x]==0&&y-2>=0){
                q.push(pip(f+1,pa(x,y-2)));
                visited[y-2][x]=1;
            }
            if(maze[y+1][x]==0&&visited[y+2][x]==0&&y+2<=h*2+2){
                q.push(pip(f+1,pa(x,y+2)));
                visited[y+2][x]=1;
            }
        }
        if(suc==0)
            cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 1444
#include <iostream>
#include <vector>
#include <stdlib.h>
using namespace std;
int main()
{
	vector<int> v;
	int n, bnum,sum = 0;
	int s1 = 0, s2 = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> bnum;
		sum += bnum;
		v.emplace_back(bnum);
	}
	double half = sum / 2.0;
	for (int i = 0; i < n; i++) {
		if ((s1 + v[i]) < half) {
			s1 += v[i];
		}
		else {
			s2 = s1 + v[i];
			break;
		}
	}
	if (abs(2 * s1 - sum) > abs(2 * s2 - sum)) {
		cout << abs(2 * s2 - sum);
	}
	else {
		cout << abs(2 * s1 - sum);
	}
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int ans;
  if (B <= C || D <= A) ans = 0;
  else ans = min(B, D) - max(A, C);
  cout << ans << endl;
}


Measured memory_bytes: 3608
import sys
input = sys.stdin.readline
N, K, Q = map(int, input().split())
A = [int(input().rstrip()) for i in range(Q)]
#print(A)
score =[0]*(N)


for i in range(Q):
    score[A[i]-1] += 1
#print(score)

for i in range(N):
    if K+score[i]-Q >0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 77528
#include <iostream>
using namespace std;
int main() {
  int n;
  double a;
  double ret = 0.0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    ret += 1.0 / a;
  }
  cout << 1.0 / ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>
  
using namespace std;
  
typedef long long ll;
typedef ll li;
typedef pair<ll,ll> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i,m,n) for(int i=m; i<=(int)(n); ++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
  
double pro[11][200];
  
typedef vector<vector<double> > mat;
  
  
mat matmul(const mat& a,const mat& b){
  int n = SZ(a);
  mat c(n,vector<double>(n));
  
  rep(i,n)rep(j,n)rep(k,n)
    c[i][j] += a[i][k] * b[k][j];
  return c;
}
  
mat powmat(mat a, int p){
  int n=SZ(a);
  mat ret(n,vector<double>(n));
  rep(i,n) ret[i][i] = 1;
  while(p){
    if(p&1) ret=matmul(ret,a);
    a=matmul(a,a);
    p >>= 1;
  }
  return ret;
}
  
vector<double> gausu(mat A, vector<double> b){
  int n=SZ(A);
  vector<double> ret(n);
  
  rep(i,n){
    double maxv=abs(A[i][i]);
    int idx = i;
    for(int j=i+1;j<n;++j){
      if(maxv<abs(A[j][i])){
        maxv = abs(A[j][i]);
        idx = j;
      }
    }
    swap(A[i],A[idx]);
    swap(b[i],b[idx]);
    maxv = A[i][i];
    for(int j=0;j<n;++j){
      if(j==i) continue;
      double mul = A[j][i]/maxv;
      b[j] -= mul * b[i];    
      for(int k=i;k<n;++k)
        A[j][k] -= mul * A[i][k];
    }
  }
  rep(i,n) ret[i] = b[i]/A[i][i];
  return ret;
}
  
int main(){
  int s,n,k;
  cin >> s >> n >> k;
  s=abs(s);
  if(n==1){
    if(s%k) cout << -1 << endl;
    else cout << s/k << endl;
    return 0;
  }
  
  pro[0][0] = 1;
  for(int i=0;i<k;++i)
    for(int j=1;j<=n;++j)
      for(int idx=0;idx<=n*k;++idx)
        pro[i+1][idx+j] += pro[i][idx]/n;
    
  mat E(n*k+1,vector<double>(n*k+1));
  vector<double> eb(n*k+1,-1);
  eb[0] = 0;
  
  rep(x,n*k+1){
    if(x==0){
      E[0][0]=1;
      continue;
    }
    E[x][x] -= 1;
    rep(i,n*k){
      int idx=abs((x)-(i+1));
      E[x][idx] += pro[k][i+1];
    }
  }
  vector<double> ex(gausu(E,eb));
    
  if(n*k>=s){
    printf("%.8f\n",ex[s]);
    return 0;
  }
  
  
  double dp[10000]={0};
  for(int i=0;i<=n*k;++i)
    dp[i] = ex[i];
  
  for(int j=n*k+1;j<10000;++j)
    for(int i=k;i<=n*k;++i)
      dp[j] += (dp[j-i]+1) * pro[k][i];
  
  /*
  if(s<8000){
    cout << dp[s] << endl;
    return 0;
  }
  */
    
  mat A(n*k+1,vector<double>(n*k+1));
  rep(i,n*k) A[0][i] = pro[k][i+1];
  rep(i,n*k-1) A[i+1][i] = 1;
  A[0][n*k]=1;
  A[n*k][n*k]=1;
  
  vector<double> b(n*k+1);
  b[0] = b[n*k] = 1;
  
  
      
  
  A=powmat(A,s-n*k);
    
  double ans = 0;
  ex[0] = 1;
  rep(i,n*k+1)
    ans += ex[n*k-i] * A[0][i];
  printf("%.8f\n",ans);
  
}

Measured memory_bytes: 1592
#include <stdio.h>

int main (void) 

{

int a, b, c;

scanf("%d""%d""%d",&a,&b,&c);

   if(a<b&&b<c){   printf("%d %d %d\n",a,b,c);

 }

 else if(a<c&&c<b){

  printf("%d %d %d\n",a,c,b);

 }

 else if(b<c&&c<a){ 

  printf("%d %d %d\n",b,c,a);

 }

 else if(b<a&&a<c){

  printf("%d %d %d\n",b,a,c);

 }

 else if(c<a&&a<b){

  printf("%d %d %d\n",c,a,b);

 }

 else if(c<b&&b<a){

  printf("%d %d %d\n",c,b,a);

 }

 else if(b==c&&b<a){

  printf("%d %d %d\n",c,b,a);

 }

 else if(b==a&&b<c){

  printf("%d %d %d\n",b,a,c);

 }

 else if(a==b&&b<c){

  printf("%d %d %d\n",a,b,c);

 }

 else if(a==c&&c<b){

  printf("%d %d %d\n",a,c,b);

 }

 else if(c==a&&a<b){

  printf("%d %d %d\n",a,c,b);

 }

 else{

  printf("%d %d %d\n",a,b,c);

 }


return 0; }

Measured memory_bytes: 2696
# p (0..6).to_a.map{|j| [6 ** j, 9 ** j] }.flatten.uniq
a = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 59049, 46656, 531441].freeze

m, dp = gets.to_s.to_i, [0]
(1..m).each {|i|
  cans = a.select {|j| i - j >= 0 }.map{|j| i - j }.uniq
  dp.push(cans.map{|j| dp[j] }.min + 1)
}
p dp.last

Measured memory_bytes: 2940
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>

using i32 = int32_t;

int main() {
    std::ios_base::sync_with_stdio(false);
    constexpr size_t kMaxN = 100000 + 5;

    i32 n, k;
    std::cin >> n >> k;

    static i32 a[kMaxN];

    for (size_t i = 0; i < n; ++i) {
        std::cin >> a[i];
    }

    auto cnt = (n-1) / (k-1);
    if ((n-1) % (k-1) != 0) {
        ++cnt;
    }

    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 640
N = gets.to_i

if N == 0
  puts '0'
  exit
end

bits = N.odd? ? ['1'] : ['0']
cur = bits.join.to_i

k = 1
while N != cur
  v = 2 ** (k + 1)
  a = N % v

  if k.odd?
    a -= v
  end

  if a == cur + (-2) ** k
    cur = a
    bits << '1'
  else
    bits << '0'
  end

  k += 1
end

puts bits.reverse.join


Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n,m;cin>>n>>m;
  vector<vector<int>> s(m);
  rep(i,m){
    int k;cin>>k;
    rep(j,k){
      int tmp;cin>>tmp;
      s[i].pb(tmp);
    }
  }
  vector<int> p(m);rep(i,m)cin>>p[i];
  int ans = 0;
  rep(bit,1<<n){
    bitset<10> bs(bit);
    bool ok = true;
    rep(i,m){
      int on = 0;
      rep(j,s[i].size()){
        on += bs[s[i][j]-1];
      }
      if(on%2 != p[i]){
        ok = false;
        break;
      }
    }
    ans += ok;
  }
  print(ans);
  return 0;
}



Measured memory_bytes: 256
open Printf
open Scanf

let prod h w =
    if w = 1 then 1
    else if h = 1 then 1
    else if w mod 2 = 0 then (w/2)*h
    else if h mod 2 = 0 then (w/2)*(h/2)+(w+1)/2*(h/2)
    else (w/2)*(h/2)+(w+1)/2*(h+1)/2

let() = 
    scanf "%d %d" prod |> printf "%d\n"

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

typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007

void solve(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)cout<<k;
    else if(k>a&&k<=a+b)cout<<a;
    else cout<<a-(k-a-b);


return ;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
   int t=1;
   //cin>>t;
   rep(i,0,t){
     solve();
  }
return 0;
}

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

ll mixi(ll a,ll b)
{
  if(a>b) return b;
  else return a;
}

int main()
{
  ll n,a,b,c,d,e,ans;
  cin>>n>>a>>b>>c>>d>>e;

  ll mi=mixi(a,mixi(b,mixi(c,mixi(d,e))));

  if(n%mi==0) ans=n/mi+4;
  else ans=n/mi+5;

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */
const int MAX_N = 200001;
char takas[4][MAX_N], aokis[4][MAX_N]; //LRUDの順

int main() {
    int H, W, N; cin >> H >> W >> N;
    P start; cin >> start.first >> start.second;
    string taka, aoki; cin >> taka >> aoki;
    map<char, int> m;//(h, w)
    m['L'] = -1, m['R'] = 1, m['U'] = -1, m['D'] = 1, m['x'] = 0;
    char c[4][2] = {{'L', 'R'}, {'R', 'L'}, {'U', 'D'}, {'D', 'U'}};
    rep(i, 4) {
        rep(j, N) {
            if(taka[j] == c[i][0]) takas[i][j] = c[i][0];
            else takas[i][j] = 'x';
            if(aoki[j] == c[i][1]) aokis[i][j] = c[i][1];
            else aokis[i][j] = 'x';
        }
    }
    P peni[4] = {mp(1, W), mp(W, 1), mp(1, H), mp(H, 1)};
    rep(i, 4) {
        int score = ((i < 2) ? start.second : start.first);
        bool ok = false;
        rep(j, N) {
            score += m[takas[i][j]];
            if(i % 2 == 0) if(peni[i].first > score) ok = true;
            if(i % 2 == 1) if(peni[i].first < score) ok = true;
            if(score != peni[i].second) score += m[aokis[i][j]];
        }
        if(ok) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


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

int main() {
int x,n;
cin >> x >> n;
vector<int> d(102);
for(int i=0;i<n;i++){
	int p;
	cin >> p;
	d[p]=1;
}
P ans(99999,-1);
for(int i=0;i<=101;++i){
	if(d[i] == 1)continue;
	int dif = abs(x-i);
	ans = min(ans,P(dif,i));
}
cout << ans.second<<endl;
return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
#define INF 100000000;
bool comp[10];
int d, g, p[10], c[10], ans=INF;

void dfs(int i, bool s){
  comp[i]=s;
  if(i==d-1){
    int sc=0, num=0;
    REP(j,d){
      sc += comp[j]*c[j];
      num += comp[j]*p[j];
    }
    if(sc<g){
      for(int ii=d-1; ii>=0; ii--){
        if(comp[ii]) continue;
        else{
          if((g-sc)/((ii+1)*100) < p[ii]) num+=max(1,(g-sc)/((ii+1)*100));
          else num=INF;
          break;
        }
      }
    }    
    ans=min(ans,num);
  }else{
    dfs(i+1, 1); dfs(i+1, 0);
  }
}

int main(){
  REP(i,10) {comp[i]=0; p[i]=0; c[i]=0;}
  cin >> d >> g;
  REP(i,d) cin >> p[i] >> c[i];
  REP(i,d) c[i]=(i+1)*100*p[i]+c[i];
  dfs(0,1); dfs(0,0);
  cout << ans << endl;
}


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

using namespace std;

int main(){
    vector<int>v(3);
    
    for(int i = 0;i < 3;i++)
        cin >> v[i];
    sort(v.begin(),v.end());

    cout << v[0]+v[1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

int main() {

    int y,m,d;
    scanf("%d/%d/%d", &y,&m,&d);
    
    if(m<5){
        puts("Heisei");
    }else{
        puts("TBD");
    }
    

    return 0;

}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << "\n";

    return 0;
}


Measured memory_bytes: 256
object Main {

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

    val N = sc.nextInt()
    val A = Array.fill(N)(sc.nextInt())

    // 一つ選んで書き換えた際の
    // 最大公約数の最大値
    // ある数を選択した時, その数を書き換えて最大の公約数を作る場合
    // それ以外の数で作られる最大公約数のよりも大きな最大公約数を作ることが
    // できないので、それ以外の数で作られる最大公約数がその数を選択した
    // 場合における最大公約数となる

    // 選んだ場合と選ばなかった場合
    // 単に計算すると, N - 1個の整数について最大公約数を求め
    // それをN回繰り返すことになる。
    // のでO(N^2)以上にはなる.　これでは間に合わない
    // Ai を選択する時
    // A0 - Ai-1 の最大公約数
    // Ai+1 - AN の最大公約数
    // がわかっていれば, A0 - Ai-1 の最大公約数 と Ai+1 - ANの最大公約数の
    // 最大公約数を求めれば求めたい数になる
    def gcd(a: Long, b: Long): Long =
      if (a % b == 0) b
      else gcd(b, a % b)

    def solve(N: Int, A: Array[Int]): Long = {
      def calcLeftGCD(): Array[Long] = {
        val left = new Array[Long](N)
        def loop(i: Int, acm: Long): Unit =
          if (i < N - 1) {
            left(i) = gcd(acm, A(i).toLong)
            loop(i + 1, left(i))
          }
        left(0) = A(0)
        loop(1, A(0))
        left
      }
      def calcRightGCD(): Array[Long] = {
        val right = new Array[Long](N)
        def loop(i: Int, acm: Long): Unit =
          if (i > 0) {
            right(i) = gcd(acm, A(i).toLong)
            loop(i - 1, right(i))
          }
        right(N - 1) = A(N - 1)
        loop(N - 2, right(N - 1))
        right
      }
      val left = calcLeftGCD()
      val right = calcRightGCD()

      def loop(i: Int, max: Long): Long =
        if (i < N) {
          loop(i + 1, max max {
            if (i > 0 && i < N - 1) gcd(left(i - 1), right(i + 1))
            else if (i > 0) left(i - 1)
            else right(i + 1)
          })
        } else max
      loop(0, 0)
    }

    println(solve(N, A))
  }

}


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

int main(){
  ll n, m, k;
  cin >> n >> m >> k;
  vl a(n), b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  
  //ーーーー累積和ーーーー//
  
  vl A(n), B(m);
  A[0] = a[0], B[0] = b[0];
  ll ans = 0;
  rep(i,n-1) A[i+1] = A[i] + a[i+1];
  rep(i,m-1) B[i+1] = B[i] + b[i+1];
  
  rep(i,m) if (B[i] <= k) ans = max(ans,i+1);
  
  //ーーーー二分探索ーーーー//
  
  rep(i,n) {
    ll key = k - A[i];
    ll l = -1, r = m;
    if (key < 0) continue;
    if (key < A[0]) {
      ans = max(ans,i+1);
      continue;
    }
    
    ll it = upper_bound(B.begin(), B.end(), key) - B.begin();
    ans = max(i+1+it,ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 9564
// By Atul Rathore
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	n = n % 10;
	if (n == 3)cout << "bon";
	else if (n == 0 || n == 1 || n == 6 || n == 8)cout << "pon";
	else cout << "hon";

}


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

int main(){
    int a=0;
    int b=0;
    cin >>a>>b;
    vector<int> list(3);
    int sum=0;
    int minus=0;
    int kakeru=0;
    sum = a+(b);
    minus=a-(b);
    kakeru =a*(b);
    list.at(0)=sum;
    list.at(1)=minus;
    list.at(2)=kakeru;
    sort(list.begin(),list.end());
    cout << list.at(2)<< endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

#define valid(x) (0<=x && x<5)
int main(){
    int n;
    int cse=1;
    while(scanf("%d",&n), n){
        if(cse!=1)puts("");
        printf("Case %d:\n",cse++);
        int g[7][7][7];
        rep(z,5){
            rep(y,5){
                char s[10];
                scanf("%s",s);
                rep(x,5)g[z][y][x]=s[x]=='1';
            }
        }
        set<int> a,b;
        int x;scanf("%d",&x);
        rep(i,x){
            int t;scanf("%d",&t);
            a.insert(t);
        }
        scanf("%d",&x);
        rep(i,x){
            int t;scanf("%d",&t);
            b.insert(t);
        }
        rep(i,n){
            int ng[7][7][7];
            rep(z,5)rep(y,5)rep(x,5){
                int c=0;
                rep(k,27){
                    int tx=k%3-1+x;
                    int ty=k/3%3-1+y;
                    int tz=k/9%3-1+z;
                    if(tx==x && ty==y && tz==z) continue;
                    if(valid(tx) && valid(ty) && valid(tz) && g[tz][ty][tx]){
                        c++;
                    }
                }
                if(g[z][y][x]==1){
                    ng[z][y][x]=b.count(c);
                }else if(g[z][y][x]==0){
                    ng[z][y][x]=a.count(c);
                }
            }
            rep(z,5)rep(y,5)rep(x,5)g[z][y][x]=ng[z][y][x];
        }
        rep(z,5){
            rep(y,5){
                rep(x,5)printf("%d",g[z][y][x]);
                puts("");
            }
            if(z!=4)puts("");
        }
    }
}

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

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;}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<mint> integ(n+2, 0);

  for(int i = 0; i <= n; ++i){
    integ[i+1] = integ[i] + i;
  }

  mint ans = 0;
  for(int i = k; i <= n+1; ++i){
    mint left = integ[i];
    mint right = integ[n+1] - integ[n+1-i];
    ans += right - left + 1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4844
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    cnt = 0
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            if i == j:
                continue
            for k in range(1, n + 1):
                if i == k or j == k:
                    continue
                if (i + j + k) == x:
                    cnt += 1
    print('%d' % (cnt / 6))



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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {

	VI v;
	int k, x;
	cin >> k >> x;
	int y = x;

	FOR(i, 1, k) {
		v.push_back(x + i);
		v.push_back(x - i);
	}
	v.push_back(x);
	sort(ALL(v));

	REP(i, v.size()) {
		cout << v[i] << ' ';
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long long
using namespace std;

signed main() {
 	int N,L;
 	cin >> N >> L;
 	vector<int> vec(N);
 	for(int i = 0;i < N;i++) {
 		vec.at(i) = L + ( i + 1 ) - 1;
 	}

 	int count = 0;
 	for(int i = 0;i < N;i++) {
 		count += vec.at(i);
 	}

 	int Min = 10000;
 	int minium;
 	for(int i = 0;i < N;i++) {
 		int A;
 		if(vec.at(i) < 0) {
 			A = vec.at(i) * -1;
 		}
 		else {
 			A = vec.at(i);
 		}
 		if(Min > A){
 			minium = vec.at(i);
 			Min = A;
 		}
 	}
 	cout << count - minium << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1000000007;
#define Sort(a) sort(a.begin(), a.end())

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  ll m = min({a,b,c,d,e});
  ll ans = (n+m-1) / m + 4;
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
 
    long int a, b, r, x, tmp;
 
    scanf("%ld", &a);
    scanf("%ld", &b);
 
    x = a * b;
 
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
 
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
 

    printf("%ld", x/b);
 
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args){
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
    
        String[] strArr = str.split("");
        int count = 0;
        
        for(int i = 0; i <= (str.length() - 1); i++){
            if(strArr[i].equals("1")){
                count++;
            }   
        }
        System.out.println(count);

    }
}


Measured memory_bytes: 26892
X = int(input())
#Y = int(X**(1/5))

for i in range(10001):
    for j in range(10001):
        if i**5 + j**5 ==X:
            x=max(i,j)
            y=min(i,j)
            print(x, -y)
            exit()
        if i**5 - j**5 ==X:
            x=max(i,j)
            y=min(i,j)
            print(x, y)
            exit()

Measured memory_bytes: 67916
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int sum (int N) {
	int ret = 0;
	while (N != 0) {
		ret += N % 10;
		N /= 10;
	}
	return ret;
}

int main() {

	int N;
	cin >> N;

	int ans = 1e9;
	for (int i = 1; i <= N - 1; i++) {
		int A = i;
		int B = N - i;
		int sumt = sum(A) + sum(B);
		ans = min(ans, sumt);
	}	

	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N; cin >> N;
	bool ans = false;
	for(int i = 1; i < 10; i++){
		for(int j = 1; j < 10; j++){
			if(i * j == N){
				ans = true;
				break;
			}
		}
	}
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
time = []

for _ in range(5):
    time.append(int(input()))

cr = 0
mr = 0
ans = 0
for t in time:
    r = t % 10
    if r != 0:
        cr += 1
        if mr == 0:
            mr = r
        else:
            mr = min(mr, r)
    ans += (t-r)

if cr == 0:
    print(ans)
else:
    ans += (10*(cr-1)+mr)
    print(ans)

Measured memory_bytes: 3064