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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll C[51][51]; // C[n][k] -> nCk
void comb_table(int N){
 for(int i=0;i<=N;++i){
  for(int j=0;j<=i;++j){
   if(j==0 or j==i){
    C[i][j]=1LL;
   }else{
    C[i][j]=(C[i-1][j-1]+C[i-1][j]);
   }
  }
 }
}

void solve(){
    ll n,p;
    cin>>n>>p;
    Array a(n);
    REP(i,n) cin>>a[i];
    ll odd=0;
    REP(i,n)if(a[i]%2) odd++;
    ll even=n-odd;

    comb_table(50);

    ll ans = 1LL<<even;
    ll temp=0;
    for(int i=p;i<=odd;i+=2){
        temp+=C[odd][i];
    }
    ans*=temp;
    cout<<ans<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 256
#pragma GCC Optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lp(i,begin,end) for (int i=begin;i<end;i++)
const int N=30,M=N*N,OO=0x3f3f3f3f;
int main(){
    ll n,x,y,sum=0, k;
    scanf("%lld%lld%lld%lld",&n,&k,&x,&y);
    sum+=min(n,k)*x;
    n-=k;
    if(n>0)sum+=n*y;
    printf("%lld",sum);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef double db;
int main(){
    ll n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);
    if(a>b) swap(a,b);
    if((b-a)%2!=0){
        printf("%lld\n",min(a-1+(b-a)/2+1,(n-b)+(b-a)/2+1));
    }
    else{
        printf("%lld\n",(b-a)/2);
    }
    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,k = map(int,readline().split())
lst1 = list(map(int,readline().split()))
#print("k=",0,":",*lst1)
for i in range(k):
    res = [0]*(n+2)
    for j in range(n):
        l = max(-1,j - lst1[j])
        r = min(n,j + lst1[j] + 1)
        res[l+1] += 1
        res[r+1] -= 1
    for j in range(1,n+1):
        res[j] += res[j-1]
    lst1 = res[1:n+1]
    if lst1[0] == lst1[-1] == n:
        break
    #print("k=",i+1,":",*lst1)

print(*lst1)

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

int main() {
  int h, w;
  cin >> h >> w;
  string board[110];
  rep(i,h) cin >> board[i];
  rep(i,w + 2) cout << '#';
  cout << endl;
  rep(i,h) {
    cout << '#';
    cout << board[i];
    cout << '#' << endl;
  }
  rep(i,w + 2) cout << '#';
  cout << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split(' ')]
result = 0
max_height = 0

for i in range(n):
  an = a[i]
  if i == 0:
    max_height = an
    max_height_idx = 0
    continue

  if an >= max_height:
    max_height = an
    max_height_idx = i
    continue

  result += (max_height - an)

print(result)

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

int main()
{
    string s;
    cin >> s;
    for(int i=0; i<s.length()-1; i++) if(s[i] == 'A' && s[i+1] == 'C') return !printf("Yes");
    printf("No");
    return 0;
}

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 reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;

int main(void) {

  string s; cin >> s;
  if (s[sz(s)-1] == 's' ) cout << s << "es" << endl;
  else cout << s << "s" << endl;
  return 0;
}


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

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORED(i, s, n) for (int i = (s); i >= (int)(n); i--)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define debugs(s) cerr << s << "\n"
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

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

#define fst first
#define snd second
#define pb push_back
#define mk(x,y) make_pair((x),(y))

// http://ehafib.hatenablog.com/entry/2015/12/23/164137
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qpm(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
// gcd : O(logN)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define sz(v) int(v.size())

// x1, x2ライブラリとの被りを避ける
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789

// typo
#define itn int
#define reutrn return
#define reutnr return
#define srting string

#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;

int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}

#define uniq(v) (v).erase(unique(ALL((v))), (v).end());

// area of (0, 0)(a, b)(c, d)
double area(double a, double b, double c, double d){
    return abs(a * d - b * c) / 2.0;
}

const int PREC = 10;
#define coutf(val) cout << fixed << setprecision(PREC) << (val) << endl;

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

signed main() {
    make2(string, S, T);
    string yes = "Yes";
    string no = "No";

    if (S.size() + 1 != T.size()) {
        cout << no << endl;
        return 0;
    }

    if (S == T.substr(0, S.size())) {
        cout << yes << endl;
        return 0;
    }


    cout << no << endl;
        return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >>m;
    string arr[n];
    for(int i = 0;i < n;i++)
    {
        cin >> arr[i];
    }
    int dist[n * m][n * m];
    for(int i= 0; i< n * m;i++)
    {
        for(int j = 0;j < n * m;j++)
        {
            dist[i][j] = INT_MAX/3;
            if(i == j)
            {
                dist[i][j] = 0;
            }
        }
    }
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            if(arr[i][j] == '#')
            {
                continue;
            }
            if(i > 0 and arr[i - 1][j] == '.')
            {
                dist[i * m +  j][(i - 1) * m +  j] = 1;
            }
            if(i < n - 1 and arr[i + 1][j] == '.')
            {
                dist[i * m +  j][(i + 1) * m +  j] = 1;
            }
            if(j > 0 and arr[i][j - 1]  == '.')
            {
                dist[i * m + j][i * m + (j - 1)] = 1;
            }
            if(j < m - 1 and arr[i][j + 1] == '.')
            {
                dist[i * m + j][i * m +  (j + 1)] = 1;
            }
        }
    }
    
    for(int k  = 0;k < n * m;k++)
    {
        for(int j = 0;j < n * m;j++)
        {
            for(int i = 0;i < n * m;i++)
            {
                if(dist[i][k] + dist[k][j] < dist[i][j])
                {
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
    }
    int sol = 0;
    for(int i =0; i < n * m;i++)
    {
        for(int j = 0;j < n * m;j++)
        {
            if(dist[i][j] == INT_MAX/3)
                continue;
            sol = max(sol, dist[i][j]);
        }
    }
    cout << sol;
    return 0;
    
}

Measured memory_bytes: 896
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    n = I()
    print(n*800-200*(n//15))

#B
def B():
    k = I()
    ans = 0
    for i in range(1,k):
        for j in range(i+1,k+1):
            if (i%2)^(j%2):
                ans += 1
    print(ans)

#C
def C():
    x,t = LI()
    print(max(0,x-t))

#D
def D():
    n = I()
    ans = 1
    for i in range(1,n+1):
        ans *= i
        ans %= mod
    print(ans)

#E
def E():
    x,y,s,t = LI()
    return

#F
def F():
    n = I()
    x = LI()
    a = sorted(x)
    for i in range(n):
        j = bisect.bisect_left(a,x[i])
        if j >= n//2:
            print(a[n//2-1])
        else:
            print(a[n//2])

#G
def G():
    n,m = LI()
    if m <= 2*n:print(m//2)
    else:
        ans = n
        m -= 2*n
        ans += m//4
        print(ans)

#H
def H():
    n,k = LI()
    ans = 0
    fact
    for i in range(1,3*n+1):
        if i%k == 0:
            return

def J():
    n = I()
    d = defaultdict(int)
    for i in range(n):
        a = I()
        if d[a]:
            d[a] -= 1
        else:
            d[a] += 1
    print(sum(d.values()))

def K():
    n,h = LI()
    v = LIR(n)
    s = 0
    i = 0
    v.sort()
    m = v[-1][0]
    v.sort(key = lambda x:-x[1])
    for a,b in v:
        if b > m:
            s += b
            i += 1
            if s >= h:break
    ans = i+(max(0,h-s)//m)
    if max(0,h-s)%m>0:
        ans += 1
    print(ans)
#Solve
if __name__ == "__main__":
    K()


Measured memory_bytes: 57904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

const int MAXH=300001;
const int MAXW=300001;
int main(){
    int H,W,M;cin >> H >> W >> M;
    int tate[MAXW];
    int yoko[MAXH];
    bool onw[MAXW];
    bool onh[MAXW];

    memset(onw, false, sizeof(onw));  
    memset(onh, false, sizeof(onh));  
    memset(tate, 0, sizeof(tate));
    memset(yoko, 0, sizeof(yoko));
    int h[MAXH];
    int w[MAXW];
    rep(i,M){
        cin >> h[i] >> w[i];
        tate[w[i]]++;
        yoko[h[i]]++;
    }
    ll ans = 0;
    int maxw=0,maxh=0;
    ll x=0,y=0;
    Rep(i,W){
        maxw = max(tate[i],maxw);
    }
    Rep(i,W){
        if(maxw==tate[i]){
            onw[i] = true;
            x++;
        }
    }

    Rep(i,H){
        maxh = max(maxh,yoko[i]);
    }

    Rep(i,H){
        if(maxh==yoko[i]){
            onh[i] = true;
            y++;
        }
    }

    ans = x*y;
    rep(i,M){
        if(onw[w[i]] && onh[h[i]]){
            ans--;
        }
    }

    if(ans>0)cout << maxh+maxw << endl;
    else cout << maxh+maxw-1 << endl;

    return 0;
}

Measured memory_bytes: 8908
import sys

#+++++
		
def main():
	a = int(input())
	ret = 'YES' if ii(a) else 'NO'
	print(ret)
	
def ii(val):
	return val in [7,5,3]
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
N = int(input())
aList = list(map(int, input().split()))
loopB = True
ans = 0
while loopB:
    for i in range(len(aList)):
        tmp = aList[i] % 2
        if tmp == 0:
            aList[i] = aList[i] // 2
        else:
            loopB = False

    if loopB:
        ans += 1

print(ans)

Measured memory_bytes: 3060
dic={}
n=int(input())
d=[]
for i in range(n):
  d.append(input())
  if d[-1] in dic:
  	dic[d[-1]]+=1
  else:
    dic[d[-1]]=1
mx=max(dic.values())
for k,v in sorted(dic.items(),key=lambda x:(-x[1],x[0])):
  if mx==v:
    print(k)
    	


Measured memory_bytes: 123588
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb puah_back

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

int main(){
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll bb = b / c + b / d - b / (lcm(c, d));
    ll aa = (a-1) / c + (a-1) / d - (a-1) / (lcm(c,d));
    cout << b - a + 1 - (bb - aa) << endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int main()
{
	int tmp = 1, i;
	for(i = 1; i < 10; i++)
	{
		printf("%dx%d=%d\n", tmp, i, tmp*i);
		if(i == 9 && tmp < 9)	i = 0, tmp++;
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    int n; cin >> n;
    ll Arr[n+1];
    for(int i = 1 ;i <= n; i++)
        cin >> Arr[i];
    
    if(n == 1){
        cout << Arr[1] << endl;
        return 0;
    }

    ll dp[n+1][n+1];
    memset(dp , 0 , sizeof(dp));

    for(int i = 1 ;i <= n; i++)
        dp[i][i] = Arr[i];

    for(int l = 2 ;l <= n ;  l++){
        for(int i = 1; i<= n-l+1 ; i++){
            int j = i+l-1;
            ll a = Arr[i] + min( dp[i+1][j-1] , dp[i+2][j] );
            ll b = Arr[j] + min( dp[i+1][j-1] , dp[i][j-2] );
            dp[i][j] = max(a , b);
            
        }
    }
    cout << dp[1][n] - min( dp[2][n] , dp[1][n-1] ) << endl;

    return 0;
} 

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
long long x[1000010],y[1000010];
#define int long long
signed main(){
  
  cin.tie(0);
  ios::sync_with_stdio(false);

  string a,b;
  cin>>a>>b;
  
  if(a=="H" && b=="H") cout<<"H"<<'\n';
  else if(a=="D" && b=="D") cout<<"H"<<'\n';
  else cout<<"D"<<'\n';
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n,i,d=0;
  scanf("%d",&n);
  int p[n];
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  for(i=1;i<n-1;i++){
    if((p[i]<=p[i+1]&&p[i]>=p[i-1])||(p[i]>=p[i+1]&&p[i]<=p[i-1])){
      d=d+1;
    }
  }
  printf("%d",d);
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	defer writer.Flush()
	M, K := ReadInt(), ReadInt()
	if K == 0 {
		for i := 0; i < 1<<M; i++ {
			Printf("%d %d ", i, i)
		}
		Println()
		return
	}
	if M < 2 {
		Println(-1)
		return
	}
	if K >= 1<<M {
		Println(-1)
		return
	}
	for i := 0; i < 1<<M; i++ {
		if i != K {
			Printf("%d ", i)
		}
	}
	Printf("%d ", K)
	for i := 1<<M - 1; i >= 0; i-- {
		if i != K {
			Printf("%d ", i)
		}
	}
	Println(K)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }

var writer = bufio.NewWriter(os.Stdout)

func Printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }
func Println(a ...interface{})               { fmt.Fprintln(writer, a...) }


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

int main() {
  int R, G, B, N;
	cin >> R >> G >> B >> N;

	int g, b = 0, n = 0;

	for (g = 0; N - G * g >= 0; g++) {
		for (b = 0; N - G * g - B * b >= 0; b++) {
			if ((N - G * g - B * b) % R == 0) {
				n++;
			}
		}
	}
	cout << n;            //B
}

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

int main() {
	int n, maxv, minv;
	maxv = -2000000000; //???????°??????????????????????????¨????
	cin >> n;
	cin >> minv;
	int r;
	for (int i = 1; i < n; ++i) {
		cin >> r; //R[i]??????????????????????????°????????????????±???????r??????????????????
		maxv = max(maxv, r - minv); //?????§????????´??°
		minv = min(minv, r); //???????????§???????°?????????????????????????
	}
	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double


int main() {
    ll n,w,val=0,sum=0;
    cin>>n>>w;
    ll a[n],b[n];
    ld x,y;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        sum+=b[i];
    }
    ll dp[n+1][sum+1];
    for(int i=0;i<=sum;i++) dp[0][i]=INT_MAX;
    for(int i=0;i<=n;i++) dp[i][0]=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=sum;j++){
            if(b[i-1]<=j){
                dp[i][j]=min(dp[i-1][j],a[i-1]+dp[i-1][j-b[i-1]]);
            }
            else dp[i][j]=dp[i-1][j];
        }
    }
    for(int i=0;i<=sum;i++){
        if(dp[n][i]<=w){
            val=i;
        }
    }
    cout<<val;
}

Measured memory_bytes: 82456
import collections

h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]

INF = 10 ** 8
dist = [[INF] * w for _ in range(h)]
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]


def bfs():
    q = collections.deque()
    for i in range(h):
        for j in range(w):
            if grid[i][j] == '#':
                q.append((i, j))
                dist[i][j] = 0
                # grid[i][j] = str(0)

    while len(q):
        py, px = q.popleft()
        for i in range(4):
            ny = py + dy[i]
            nx = px + dx[i]
            if -1 < ny < h and -1 < nx < w and grid[ny][nx] == '.' and dist[ny][nx] == INF:
                q.append((ny, nx))
                dist[ny][nx] = dist[py][px] + 1
                # grid[ny][nx] = str(dist[py][px] + 1)

    return max(max(dist, key=lambda x: max(x)))


if __name__ == '__main__':
    print(bfs())
    # for g in grid:
    #     for s in g:
    #         print(s,end='')
    #     print()
    # print()
    # for d in dist:
    #     for i in d:
    #         print(i,end='')
    #     print()


Measured memory_bytes: 121692
#include<iostream>
#include<string>
#include <algorithm>
#include<vector>
using namespace std;

/* Many Requirements */

int main(){
    // 入力スタンダード
    int n, m, q;
    cin >> n >> m >> q;

    vector<int> a;
    vector<int> b;
    vector<int> c;
    vector<int> d;

    a.push_back(0);
    b.push_back(0);
    c.push_back(0);
    d.push_back(0);

    for(int i=0; i<q; i++) {
        int ai,bi,ci,di;
        cin >> ai >> bi >> ci >> di;
        a.push_back(ai);
        b.push_back(bi);
        c.push_back(ci);
        d.push_back(di);
    }
    // ***************************************

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

  long long sumd = 0;
    long long maxsum = 0;
    bool flag = true;

    while(flag){
        for(int i=1; i<q+1; i++){

            if(A[b[i]]-A[a[i]] == c[i]){
                sumd += d[i];
            }
        }

        if(maxsum < sumd){
            maxsum = sumd;
        }

       
        A[n] += 1;
        for(int j=n; j>0; j--){
            
            if(A[j]>m){
                A[j-1] += 1;
                for(int k=j; k<n+1; k++){
                    A[k] = A[j-1];
                }
                if(A[0]==2){
                    flag = false;
                }
            }
        }
        
        sumd = 0;

    }    

    cout << maxsum << endl;

    return 0;
}

Measured memory_bytes: 3596
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

signed main() {
	int h, w; cin >> h >> w;
	rep(i, h) rep(j, w) {
		string s; cin >> s;
		if (s == "snuke") {
			cout << (char)(j + 'A') << i + 1 << endl;
		}
	}
	system("pause");
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
#define newline std::cout<<'\n';
#define newlinedx(num) for(int i=0;i<num;i++)std::cout<<'\n';
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ui = uint64_t;

//----------------library in this time--------------------------------
template <class T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <class T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <class T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}

long long squareTwo(const long long a,const long long b) {
    return (b == 1) ? a : squareTwo(a * 2, b - 1);
}

template <class T>
inline T Max(const T a,const T b) {
    return (a >= b) ? a : b;
}

template <class T>
inline T Min(const T a,const T b) {
    return (a <= b) ? a : b;
}


//------------------------main function-------------------------------
//sum of 5n+2 5n+4 (1 <= n <= 19)
//

void Main(){
    ll n ,ans = 0; cin >> n;
    vector<ll> a(n+1), b(n);
    rep(i, n+1) cin >> a[i];
    rep(i, n) cin >> b[i];
    for(ll i = n - 1; i >= 0; i--){
        ll temp = min(a[i + 1], b[i]);
        ans += temp;
        a[i+1] -= temp;
        b[i] -= temp;
        ll temp2 = min(a[i], b[i]);
        ans += temp2;
        a[i] -= temp2;
        b[i] -= temp2;
     }
    cout << ans << endl;
}

//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
     
    Main();
    return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a = II(), II()
    print(n * n - a)
    return

#B
def B():
    n = II()
    k = II()
    x = LI()
    ans = 0
    for xi in x:
        ans += min(xi, k - xi)
    print(ans * 2)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


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

#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
typedef pair<int, int> PII;

int main() {
    int N, X, T;
    cin >> N >> X >> T;
    if(N % X == 0) cout << (N / X) * T<< endl;
    else cout << (N / X) * T + T<< endl;
    return 0;

}

Measured memory_bytes: 3628
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *

H,W,N=map(int,input().split())
sr,sc=map(int,input().split())
S=input()
T=input()


st=0
end=W-1
sttate=0
endtate=H-1
for i in range(N-1,-1,-1):
    if T[i]=="L":
        if end<W-1:
            end+=1
    if T[i]=="R":
        if st>0:
            st-=1
    if T[i]=="U":
        if endtate<H-1:
            endtate+=1
    if T[i]=="D":
        if sttate>0:
            sttate-=1

    if S[i]=="L":
        st+=1
    if S[i]=="R":
        end-=1
    if S[i]=="U":
        sttate+=1
    if S[i]=="D":
        endtate-=1
    if st>end or sttate>endtate:
        print("NO")
        exit()

if st<=sc-1<=end and sttate<=sr-1<=endtate:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 47280
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;

string S;
int z[4], t;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> S;
    F0R(i,4) z[i] = S[i]-'0';
    t = 7-z[0];
    if (z[1]+z[2]+z[3] == t) {
        cout << z[0] << "+" << z[1] << "+" << z[2] << "+" << z[3];
    } else if (-z[1]+z[2]+z[3] == t) {
        cout << z[0] << "-" << z[1] << "+" << z[2] << "+" << z[3];
    } else if (z[1]-z[2]+z[3] == t) {
        cout << z[0] << "+" << z[1] << "-" << z[2] << "+" << z[3];
    } else if (-z[1]-z[2]+z[3] == t) {
        cout << z[0] << "-" << z[1] << "-" << z[2] << "+" << z[3];
        
    } else if (z[1]+z[2]-z[3] == t) {
        cout << z[0] << "+" << z[1] << "+" << z[2] << "-" << z[3];
        
    } else if (-z[1]+z[2]-z[3] == t) {
        cout << z[0] << "-" << z[1] << "+" << z[2] << "-" << z[3];
        
    } else if (z[1]-z[2]-z[3] == t) {
        cout << z[0] << "+" << z[1] << "-" << z[2] << "-" << z[3];
        
    } else if (-z[1]-z[2]-z[3] == t) {
        cout << z[0] << "-" << z[1] << "-" << z[2] << "-" << z[3];
        
    }
    cout << "=7";
}

// read!
// ll vs. int!

Measured memory_bytes: 384
S=int(input())
n=1
while n>0.001:
    if S//(1000*n)==(S-(1000*n)*(S//(1000*n)))//(100*n):
        print("Bad")
        break
    else:
        S=S-(1000*n)*(S//(1000*n))
        n=n/10
else:
    print("Good")

Measured memory_bytes: 3060
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)
#include <queue>

using namespace std;
#define ll long long

bool isAllBlack(vector<vector<char> > A, int H, int W) {
  for(int i=0; i<H; i++)
    for(int j=0; j<W; j++)
      if(A[i][j] == '.')
	return false;
  return true;
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char> > A(H, vector<char>(W));
  vector<queue<pair<int, int> > > B(2);
  for(int i=0; i<H; i++)
    for(int j=0; j<W; j++) {
      cin >> A[i][j];
      if(A[i][j] == '#')
	B[0].push(make_pair(i, j));
    }
  int tmp = 0;
  int ans = 0;
  while(!isAllBlack(A, H, W)) {
    int next = (tmp + 1) % 2;
    while(!B[tmp].empty()) {
      pair<int, int> p = B[tmp].front();
      if(p.first-1 >= 0 && A[p.first-1][p.second] == '.') {
	A[p.first-1][p.second] = '#';
	B[next].push(make_pair(p.first-1, p.second));
      }
      if(p.first+1 < H && A[p.first+1][p.second] == '.') {
	A[p.first+1][p.second] = '#';
	B[next].push(make_pair(p.first+1, p.second));
      }
      if(p.second-1 >= 0 && A[p.first][p.second-1] == '.') {
	A[p.first][p.second-1] = '#';
	B[next].push(make_pair(p.first, p.second-1));
      }
      if(p.second+1 < W && A[p.first][p.second+1] == '.') {
	A[p.first][p.second+1] = '#';
	B[next].push(make_pair(p.first, p.second+1));
      }
      B[tmp].pop();
    }
    tmp = next;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

const int INF = 1e9;

int main(void){

	string s; cin >> s;

	REP(i,s.length()){
		if(s[i] == '7'){
			cout << "Yes" << endl;
			return 0;
		}


	}

	cout << "No" << endl;

	return 0;

}


Measured memory_bytes: 3620
#S=input()
#N=int(input())
x1,y1,x2,y2=map(int,input().split())
x3=x2-(y2-y1)
y3=y2+(x2-x1)
x4=x3-(y3-y2)
y4=y3+(x3-x2)
print(x3," ",y3," ",x4," ",y4)

Measured memory_bytes: 38384
#第六回ドワンゴからの挑戦状　A

N=int(input())

largelist=[]

for i in range(N):
    S=input().split()
    #print(S)
    largelist.append(S)

#print(largelist)

X=input()
answer=0

for i in range(N):
    if X==largelist[i][0]:
        for j in range(i+1,N):
            #print("now j")
            #print(j)
            answer+=int(largelist[j][1])
        
    else:
        temp=0

print(answer)

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

using namespace std;

string s;

int main() {
	cin >> s;
	int ans = 1;
	string be;
	be += s[0];
	string now;
	int i = 1;
	while (i < s.length()) {
		now += s[i];
		if (now != be) {
			be = now;
			now = "";
			ans++;
		}
		i++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
b = [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]
k = int(input())
print(b[k-1])


Measured memory_bytes: 2940
#include<stdio.h>

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

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

int main() {
    int N;
    string S ,T;
    cin >> N >> S >> T;
    
    rep(i, N){
        cout << S.at(i) << T.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	X, N := getInt(), getInt()
	p := make([]int, 102)
	for i := 0; i < N; i++ {
		pos := getInt()
		p[pos] = 1
	}
	if p[X] == 0 {
		out(X)
		return
	}
	p0 := 101
	for i := X; i <= 101; i++ {
		if p[i] == 0 {
			p0 = i
			break
		}
	}
	p1 := 0
	for i := X; i >= 0; i-- {
		if p[i] == 0 {
			p1 = i
			break
		}
	}
	if abs(p0-X) < abs(p1-X) {
		out(p0)
	} else {
		out(p1)
	}
}


Measured memory_bytes: 1756
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void) {
	int x, ans = 0;

	cin >> x;

	ans = x / 500 * 1000 + x % 500 - (x % 500) % 5;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define MAXN 105
#define MAXVALUE 100005
#define ll long long

using namespace std;
 
ll peso[MAXN];
ll value[MAXN];
ll dp[MAXN][MAXVALUE];
int n, w;

int main()
{

	cin >> n >> w;  
	for (int i = 0; i < n; ++i)
	{
		cin >> peso[i] >> value[i];
	}
	
	for (int i = 0; i <= n; ++i)
	{
		for (int j = 0; j <= 100000; ++j)
		{
			dp[i][j] = 10000000000000LL;
		}

	}

	ll ans = 0;
	dp[0][0] = 0;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j <= 100000; ++j)
		{
		
			dp[i][j] = dp[i-1][j];
			if(j >= value[i-1])
			{
				dp[i][j] = min(dp[i][j], peso[i-1] + dp[i-1][j-value[i-1]]);

			}
			if(dp[i][j] <= w)
			{
				ans = max(ans, (ll)j);
			}


		}

	}


	cout << ans << endl;


 
 














 
    return 0;
}

Measured memory_bytes: 82552
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int,int>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;

#define M 200010

int a[M],cnt[21][M];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	
   	int n;cin>>n;
   	rep(i,0,n){
   		cin>>a[i];
   		rep(j,0,21)if(a[i]&(1<<j))cnt[j][i]++;
   		if(i)rep(j,0,21)cnt[j][i]+=cnt[j][i-1];
   	}
   	int ans=0;
   	rep(i,0,n){
   		int st=0;
   		rep(j,0,21){
   			int it=lower_bound(cnt[j],cnt[j]+i+1,cnt[j][i]-1)-cnt[j];
   			if(cnt[j][it]==cnt[j][i]-1 and cnt[j][it]>0)it++;
   			st=max(st,it);
   		}
   		ans+=(i-st+1);
   	}
   	cout<<ans;

    return 0;
}


Measured memory_bytes: 38016
n = int(input())
s = [input() for i in range(n)]
AC,WA,TLE,RE = 0,0,0,0

for i in s:
    if i == "AC":
        AC += 1
    elif i == "WA":
        WA += 1
    elif i == "TLE":
        TLE += 1
    else:
        RE += 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
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;
}
// dp[i+1][j]:i番目までの魔法で体力をj以上減らすための魔力の最小値
int main()
{
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++)
        cin >> A[i] >> B[i];

    vector<vector<ll>> dp(N + 1, vector<ll>(H + 1, INF_64));
    dp[0][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= H; j++) {
            chmin(dp[i + 1][j], dp[i][j]);
            chmin(dp[i + 1][min(j + A[i], H)], dp[i + 1][j] + B[i]);
        }
    }
    cout << dp[N][H] << endl;
    return 0;
}

Measured memory_bytes: 81644
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                sc.nextLine();
                for (int i = 0; i < N; i++) {
                        System.out.println(sc.nextLine().replace("Hoshino", "Hoshina"));
                }
        }
}

Measured memory_bytes: 26332
import queue
K = int(input())
q = queue.Queue()
for i in range(1, 10):
    q.put(i)
for _ in range(K):
    x = q.get()
    d = x%10
    t = x*10
    if d != 0:
        q.put(t-1+d)
    q.put(t+d)
    if d != 9:
        q.put(t+1+d)
print(x)

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

class Cube{
public:
    int f[6];
    Cube(){}
    void roll_z(){roll(1,2,4,3);} //
    void roll_y(){roll(0,2,5,3);} // West
    void roll_x(){roll(0,1,5,4);} // North
    void roll(int i, int j, int k, int l){
        int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
    }
};

bool eq(Cube c1, Cube c2){
    for(int i = 0; i < 6; i++){
        if(c1.f[i] != c2.f[i]) return false; //１面でも異なる面が存在すれば２つのサイコロは異なる.
    }
    return true;
}

bool equal(Cube c1, Cube c2){
    for(int i = 0; i < 6; i++){
        for(int j = 0; j < 4; j++){ //6 * 4 = 24通りをすべて試すと良い. 連続２面を調べればサイコロが一致するかどうか判定できるから.
            if(eq(c1, c2)) return true;
            c1.roll_z();
        }
        if(i % 2 == 0) c1.roll_y();
        else c1.roll_x();
    }
    return false;
}

int main(){
    Cube c1, c2;
    
    for(int i = 0; i < 6; i++) cin >> c1.f[i];
    for(int i = 0; i < 6; i++) cin >> c2.f[i];
    
    if(equal(c1, c2)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

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

    vector<pll> e;
    vector<pll> v;
    if (N % 2 == 1) {
        v.push_back(pll(N, 0));
        N--;
    }

    REP(i, N / 2) {
        v.push_back(pll(i + 1, N - i));
    }

    REP(i, v.size() - 1) {
        FOR(j, v.size(), i + 1) {
            ll a = v[i].first;
            ll b = v[i].second;
            ll c = v[j].first;
            ll d = v[j].second;
            if (a > 0) {
                if (c > 0)
                    e.push_back(pll(a, c));
                if (d > 0)
                    e.push_back(pll(a, d));
            }
            if (b > 0) {
                if (c > 0)
                    e.push_back(pll(b, c));
                if (d > 0)
                    e.push_back(pll(b, d));
            }
        }
    }

    cout << e.size() << endl;
    REP(i, e.size()) {
        cout << e[i].first << " " << e[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int N,M,C;

int B[21];
int A[21][21];

int ans;

int tans;

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

    for(int i=0;i<M;i++)
    {
        cin >> B[i];
    }

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

        for(int j=0;j<M;j++)
        {
            cin >> A[i][j];
        }

    }

    int cnt=0;

    while(cnt<N)
    {
        for(int i=0;i<M;i++)
        {
            ans+=A[cnt][i]*B[i];
        }

        ans+=C;

        // cout << ans << endl;

        if(ans>0)tans++;

        ans=0;

        cnt++;
    }

    cout << tans << endl;

    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define forx(i, n) for(int i = 1 ; (i) <= (n) ; ++i)
#define ll long long
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x) * (x)
#define debug(x) cout << #x <<" = " << x << endl
#define printvpair(v) for(auto x : v) cout << x.first  <<" " << x.second << endl;
#define printv(v) for(auto x : v) cout << x << " "; cout << endl;

const int N = 1e5 + 7;
int n;
map<string,int> m;
string order[N];
int main() {
    cin >> n;
    forn(i,n){
        string s;
        cin >> s;
        if (m[s]){
            cout << "No" << endl;
            return 0;
        }
        m[s] = 1;
        order[i] = s;
        if (i > 0 && order[i - 1].back() != order[i][0]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1024
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	ll a, b , c;
	cin>> a>> b >> c ;
	ll gap=a-b;
	ll ans=max(0LL , c-gap);
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
int main() {
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  int n, m;
  cin >> n >> m;
  vector<string> str(n);
  for (int i = 0; i < n; i++) {
    cin >> str[i];
  }
  queue<pair<int, int> > que;
  vector<vector<int> > dis(n, vector<int>(m, INT_MAX));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (str[i][j] == '#') {
        que.emplace(i, j);
        dis[i][j] = 0;
      }
    }
  }
  while (!que.empty()) {
    int x = que.front().first, y = que.front().second;
    que.pop();
    for (int i = 0; i < dx.size(); i++) {
      int new_x = x + dx[i], new_y = y + dy[i];
      if (new_x >= 0 && new_x < n && new_y >= 0 && new_y < m && dis[new_x][new_y] > dis[x][y] + 1) {
        dis[new_x][new_y] = dis[x][y] + 1;
        que.emplace(new_x, new_y);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = max(ans, dis[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13456
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int N = sc.nextInt();
    		int[] h = new int[N];
    		for (int i=0; i<N; i++) {
    			h[i] = sc.nextInt();
    		}
    		int[] costs = new int[N];
    		costs[0] = 0;
    		costs[1] = Math.abs(h[1] - h[0]);
    		for (int i=2; i<N; i++) {
    			costs[i] = Math.min(costs[i-1] + Math.abs(h[i] - h[i-1]), costs[i-2] + Math.abs(h[i] - h[i-2]));
    		}
    		System.out.println(costs[N-1]);

    	} finally {
    		sc.close();
    	}
    }
}



Measured memory_bytes: 49128
// Created by sz
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int a,b,c;
    cin >> a >> b >>c;
    cout << c << " "<< a << " " << b << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll x;
ll a[300010];
int main() {
  cin >> n >> x;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a,a+n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (x >= a[i]) {
      x -= a[i];
      cnt++;
    }
  }
  if (cnt == n && x > 0) cnt--;
  cout << cnt << endl;
}

/*　【提出前に確認すること】
・コンパイルできるか
・テストケース試したか
・オーバーフローあるか
*/

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

int main(){
  int N, K;
  cin >> N >> K;
  int l[N];
  for(int i = 0; i < N; i++){
    cin >> l[i];
  }
  sort(l, l + N, greater<int>());
  int ans = 0;
  for(int i = 0; i < K; i++){
    ans += l[i];
  }
  cout << ans << endl;
}

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

int n;
int a[3];
int l[10];
int res_mp=1000*1000*1000;

void solve(string s) {
  if(s.size()!=n){
    solve(s+'a');
    solve(s+'b');
    solve(s+'c');
    solve(s+'d');
  }else{
    int t_res=0;
    int t[3];
    int mp[3];
    for(int i=0;i<3;i++){t[i]=0;mp[i]=0;}
    for(int i=0;i<n;i++){
      if(s[i]=='a'){
        t[0]+=l[i];
        mp[0]++;
      }else if (s[i]=='b'){
        t[1]+=l[i];
        mp[1]++;
      }else if (s[i]=='c'){
        t[2]+=l[i];
        mp[2]++;
      }
    }
    for(int i=0;i<3;i++){
      if(mp[i]==0)return;
      t_res+=(mp[i]-1)*10;
    }
    for(int i=0;i<3;i++){
      t_res+=abs(t[i]-a[i]);
    }
    res_mp=min(t_res, res_mp);
  }
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  cin>>n;cin>>a[0]>>a[1]>>a[2];
  for(int i=0;i<n;i++)cin>>l[i];
  solve("");
  cout<<res_mp<<endl;

  return 0;
}


Measured memory_bytes: 256