akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a;
		String st;
		int sum;
		boolean flag;

		while (sc.hasNext()) {
			a = sc.nextInt();
			st = Integer.toBinaryString(a);
			sum = 1;
			flag = true;;

			for (int i = st.length() - 1; 0 <= i; i--) {
				if (st.charAt(i) == '1') {
					if (flag) {
						System.out.print(sum);
						flag = false;
					} else {
						System.out.print(" " + sum);
					}
				}
				sum *= 2;
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
item_num = int(input())

price_list = []
for i in range(item_num):
    price_list.append(int(input()))

highest_price = max(price_list)

for i in range(item_num - 1):
    if price_list[i] == highest_price:
        price_list[i] = int(highest_price / 2)
        break

print(sum(price_list))



Measured memory_bytes: 2940
import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        a,b = L[i], L[j]
        idx = bisect.bisect_left(L, a+b)
        ans += max(0, idx - j - 1)
print(ans)


Measured memory_bytes: 46532
import sys
 
def exec(n, s):
  r = 'No'
  if n % 2 != 0:
    return r
  hs = s[0:int(n/2)]
  if hs + hs == s:
    r = 'Yes'
  return r
    
    
if __name__ == '__main__':
  r = [input(), input()]
  n = int(r[0])
  s = r[1]
  print(exec(n, s))

Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();

            if (a >= b) {
                out.println("delicious");
            } else if (b - a <= x) {
                out.println("safe");
            } else {
                out.println("dangerous");
            }
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



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

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

    cout<<8-((x-400)/200)<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

int main() {
    int N;
    cin >> N;
    V<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.rbegin(), A.rend());

    ll ans = 0LL;
    for (size_t i = 1; i < N; i++) {
        if (i == 1)ans += A[0];
        else {
            ans += A[i/2];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4044
program AGC36_A
  integer(8)::X(2),Y(2),S
  read(*,*)S
  X(1)=10**9
  Y(1)=1
  if(mod(S,X(1))/=0) then
     Y(2)=S/X(1)+1
     X(2)=10**9-mod(S,X(1))
  else
     Y(2)=S/X(1)
     X(2)=0
  end if
  write(*,*)0,0,X(1),Y(1),X(2),Y(2)
end program AGC36_A

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

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

int main() {
	ios::sync_with_stdio(false);
	
	int n, s;
	int u, f, r, q;
	char w[6];
	
	while(cin>>n,n) {
		s=1;q=0;
		u=1;f=2;r=3;
		
		rep(i, n) {
			cin>>w;
			switch(w[0]) {
				case 'N':
					q=u;
					u=f;
					f=7-q;
					break;
				case 'E':
					q=r;
					r=u;
					u=7-q;
					break;
				case 'W':
					q=u;
					u=r;
					r=7-q;
					break;
				case 'S':
					q=f;
					f=u;
					u=7-q;
					break;
				case 'R':
					q=f;
					f=r;
					r=7-q;
					break;
				case 'L':
					q=r;
					r=f;
					f=7-q;
					break;
				default:
					break;
			}
			s+=u;
		}
		cout<<s<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    string s;
    long long k;
    cin >> s >> k;
    long long n=0;
    for(auto p = s.begin(); p != s.end(); p++){
        if(*p != '1') break;
        n++;
    }
    if(k <= n) cout << 1 << endl;
    else cout << s[n] << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    string a;
    cin >>a;

    int A = a.size();
    int ct[26]={};
    rep(i,A) ++ct[a[i]-'a'];

    ll ans = 1;
    rep(i,A)
    {
        --ct[a[i]-'a'];
        rep(j,26)if(a[i]-'a'!=j) ans += ct[j];
    }

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <time.h>
#include <assert.h>


using namespace std;



#define For(i,x,n)  for(long long i=x;i<n;i++)
#define rFor(i,x,n) for(long long i=x;i>=n;i--)
#define itFor(it,st)   for(auto it=st.begin() ; it!=st.end() ; it++)
#define MOD 1000000007
#define PI 3.141592653589793
#define INF 999999999999999999
#define N 1000005
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sp " "
#define cont continue
#define brk break

#define deb1(x)                cout<<#x<<": "<<x<<endl
#define deb2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define deb3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define deb4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define deb5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define deb6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed;
    cout<<setprecision(8);
    srand(time(NULL));

	ll a,b;
	cin>>a>>b;
	cout<<a*b;
    
    //cout<<"\nTime used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case
    return 0;
}

//s1.substr(1,3) - return 3 characters starting from position 1 as substring of string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan"
//num = atoi(s.c_str()); //convert string s to integer num
//n.erase(i,std::string::npos); //erase i th position in string n , decreasing string size
//s.find(b)!= std::string::npos - finds string b in string a - true if found
//cout<<"Time used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case                


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
const ll MOD=1000000007;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string s;
    cin>>N;
    vector<string> S(N);
    REP(i,N){
        cin>>s;
        sort(ALL(s));
        S[i]=s;
    }
    sort(ALL(S));
    string check=S[0];
    auto now=S.begin();
    ll sub=0;
    while(now!=S.end()){
        auto itr=upper_bound(ALL(S),*now);
        if(itr-now>1){
            sub+=(itr-now)*(itr-now-1)/2;
        }
        now=itr;
    }
    cout<<sub<<endl;
}

Measured memory_bytes: 5760
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int h=sc.nextInt();
    int w=sc.nextInt();
    String[] a=new String[h];
    for(int i=0;i<h;i++){
      a[i]=sc.next();
    }
    for(int i=0;i<w+2;i++){
      System.out.print("#");
    }
    System.out.println("");//改行
    for(int i=0;i<h;i++){
      System.out.print("#");
      System.out.print(a[i]);
      System.out.println("#");
    }
    for(int i=0;i<w+2;i++){
      System.out.print("#");
    }
    System.out.println("");//改行
  }
}


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

int main()
{
	string s;
	cin >> s;
	vector<int> cnt(3);
	for(auto c:s)cnt[c-'a']++;
	int n = s.size();
	sort(cnt.begin(),cnt.end());
	cnt[1]-=cnt[0];
	cnt[2]-=cnt[0];
		if(cnt[1]>1||cnt[2]>1)
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
	
	
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>


using namespace std;

int main() {

	vector<int> a(3);
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}

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

	cout << a[0] + a[1] + a[2] * 10 << endl;

	return 0;
}

Measured memory_bytes: 256
# AOJ 0208 Room Numbers of a Hospital
# Python3 2018.6.23 bal4u
# 8進数に変換して、01234567を01235789に置き換える

tbl = ('0','1','2','3','5','7','8','9')
while 1:
	n = int(input())
	if n == 0: break
	s = format(n, 'o')
	ans = ''
	for i in range(len(s)): ans += tbl[int(s[i])]
	print(ans) 



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

int n, a[200005], v[1000005], mx;

int main() {
    cin >> n;
    for(int i =1; i <= n; i++) {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    for(int i = 1; i <= n; i++)
        for(int j = a[i]; j <= mx; j += a[i])
            v[j]++;

    int ans = 0;
    for(int i = 1; i <= n; i++)
        if(v[a[i]] == 1)
            ans++;
    cout << ans;
}


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

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

	if (K >= A + B)cout << "0 0" << endl;
	else if (K < A + B && A <= K)
	{
		cout << 0 << ' ' << B - (K - A) << endl;
	}
	else if (K < A)cout << A - K << ' ' << B << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;
using ll = long long;

pair<int, int> func(int x){
    int b = x%10;
    int a = 0;
    while(x){
        a = x;
        x /= 10;
    }
    return {a, b};
}

int main()
{
    int n;
    cin >> n;
    map<pair<int, int>, int> freq;
    for(int i = 1; i<=n; i++){
        pair<int, int> p = func(i);
        freq[p]++;
    }
    ll ans = 0;
    for(int i = 1; i<=n;i++){
        pair<int, int> q = func(i);
        ans += freq[{q.second, q.first}];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int main()
{
    int n, k;
    cin >> n >> k;

    string s;
    cin >> s;

    s[k - 1] += 32;
    cout << s << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

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

    cout << max({a+b, a-b, a*b}) << endl;
}

Measured memory_bytes: 256
my ($n,$m)=+<<get.words;
my$a=(get)xx $n;
my$b=lines;
my$s=0;
for 0..$n-$m ->$i {
	for 0..$n-$m ->$j {
		my$f=1;
		for ^$m ->$k {
			if !$a[$i+$k].substr-eq($b[$k],$j) {
				$f=0;
				last;
			}
		}
        $s+=$f;
	}
}
say $s>0??"Yes"!!"No";

Measured memory_bytes: 75364
def isPrime(p):
	if p == 2: return 1
	if p < 2 or p&1 == 0: return 0
	return 1 if pow(2,p-1,p) == 1 else 0
	
n = int(raw_input())
print sum(isPrime(int(raw_input())) for i in range(n))

Measured memory_bytes: 4504
s = input()
t = input()


d ={chr(i):i for i in range(97, 97+26)}

s = [d[i]for i in s]
t = [d[i]for i in t]

def check(s,t):
  if (len(s) == 0 )& (len(t)>0) :
    return 'Yes'
  elif (len(t) == 0 )& (len(s)>=0) :
    return 'No'
  a,b = min(s), max(t)
  if a< b:
    return 'Yes'
  elif a==b :
    return a
  else :
    return 'No'
    
while True :
  x = check(s,t)
  if type(x)== int :
    s.remove(x)
    t.remove(x)
  else :
    break
print(x)

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

int main(){
  string S;
  cin >> S;
  int i=0;
  while(1){
    if(i==S.length()){
      break;
    }
    S[i]='x';
    i++;
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#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 pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;




int main(){
    int A,B;
    cin>>A>>B;
    int C=(1^2^3^A^B);
    out(C);

    return 0;
}


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

typedef unsigned long long int ll;

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

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

int main(){
   ll a,b,c,d;
   cin>>a>>b>>c>>d;
   ll r1=(b/c)-(a/c);
   ll r2=(b/d)-(a/d);
   if(a%c==0)
        ++r1;
    if(a%d==0)
        ++r2;
   ll r12=(b/lcm(c,d))-(a/lcm(c,d));
   if(a%lcm(c,d)==0)
        ++r12;
   ll r = (b-a+1)-r1-r2+r12;

    cout<<r<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <atcoder/all>
using namespace std;int main(){int N,Q;cin>>N>>Q;atcoder::fenwick_tree<long> b(N);int n=N;while(n--){long a;cin>>a;b.add(N-1-n,a);}while(Q--){int w,e,r;cin>>w>>e>>r;if(w)cout<<b.sum(e,r)<<endl;else b.add(e,r);}}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n,k;cin>>n>>k;
  vector<ll>a(n);
  rep(i, n)cin>>a[i];

  // n==k
  if(n==k){
    ll result=1;
    for(auto c:a){
      c = (c+MOD)%MOD;
      result *= c;
      result %= MOD;
    }
    cout<<result<<endl;

    return 0;
  }

  vector<ll>ma, pa;
  for(auto c:a){
    if(c<0)ma.push_back(-c);
    else pa.push_back(c);
  }

  sort(pa.begin(), pa.end());
  sort(ma.begin(), ma.end());

  // -
  if(pa.size()==0 && k%2==1){
    ll result=1;
    rep(i, k){
      result = result*ma[i]%MOD;
    }
    result = (MOD-result)%MOD;
    cout<<result<<endl;

    return 0;
  }

  // else
  vector<ll> results;
  if(k%2==1){
    results.push_back(pa.back());
    pa.pop_back();
  }
  
  while(results.size()-k){
    ll pmax=0;
    if(pa.size()>=2)pmax = pa[pa.size()-1] * pa[pa.size()-2];
    ll mmax=0;
    if(ma.size()>=2)mmax = ma[ma.size()-1] * ma[ma.size()-2];
    
    if(pmax>=mmax && pa.size()>=2){
	  results.push_back(pa.back());
      pa.pop_back();
	  results.push_back(pa.back());
      pa.pop_back();
    }else if(mmax>=pmax && ma.size()>=2){
	  results.push_back(ma.back());
      ma.pop_back();
	  results.push_back(ma.back());
      ma.pop_back();
    }
  }

//  sort(results.begin(), results.end());
//  cout<<results.size()<<endl;
//  cout<<results[0]<<' '<<results.back()<<endl;

  ll result=1;
  for(auto c:results){
    result = (result*c)%MOD;
  }
  cout<<result<<endl;

  return 0;
}



Measured memory_bytes: 9532
#include <iostream>

using namespace std;


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

	int num = N;
	int sum = 0;
	while (1) {
		sum += num % 10;
		num = num / 10;
		if (num <= 0) break;
	}

	if (N % sum) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())  # N個の品物, 容量Wのナップサック
items = [list(map(int, input().split())) for _ in range(N)]  # v, w
dp = [[0]*(W+1) for _ in range(N+1)]  # i番目までの品物を使ったときに、重さWで実現できる最大の価値
dp[0][0] = 0  # 雰囲気だけで行う初期化
for i in range(N):  # N個の品物について
    for j in range(W+1):
        # 使わない場合
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        # 使う場合
        if j + items[i][1] > W:
            continue
        dp[i+1][j+items[i][1]] = max(dp[i+1][j+items[i][1]], dp[i][j]+items[i][0])

ans = max(dp[N])
print(ans)



Measured memory_bytes: 41884
#include <bits/stdc++.h>
using namespace std;
int main () {
int y,m;
string d;
char a,b;
cin>>y>>a>>m>>b>>d;
if (y!=2018)y=2018;
if (m<10) cout<<y<<a<<"0"<<m<<b<<d;
else
cout<<y<<a<<m<<b<<d;




return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    val plist = (1..5).map { readLine()!!.toLong() }

    val min = plist.min()!!

    val c = if((n % min).toInt() == 0) n/min - 1 else n/min
    println(5 + c)
}

Measured memory_bytes: 33816
#include "bits/stdc++.h"
using namespace std;
int gcd(int a, int b){
    while(true){
        if(a<b) swap(a,b);
        if(b==0) break;
        a%= b;
    }
    return a;
}

int main(){
    int n,i,ans;
    cin >> n;
    vector<int> a(n);
    for(i=0;i<n;i++) cin >> a.at(i);
    ans = a.at(0);
    for(i=1;i<n;i++){
        ans = gcd(ans,a.at(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include"time.h"
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl

//毎回変える場所
#define N_MAX 200


//問題文のとおり

int main() {
	string s;
	cin>>s;
	if(s[0]==s[2])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

A=[list(input()) for i in range(N)]
B=[list(input()) for i in range(M)]
#print(A,B)
count=0
ep=0
flag=0
for i in range(0,N-M+1,1):
    for j in range(0,N-M+1,1):
        for k in range(0,M,1):
            for l in range(0,M,1):
                if A[i+k][j+l]==B[k][l]:
                    count=count+1
        #ep=ep+1
        #print(i,j)
        if count==M*M:
            flag=1
            break
        count=0
#print(ep)
if flag==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 40688
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

int main(){
	int n, k;
	cin>>n>>k;
	ll a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	ll dp[n];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2; i<n; i++){
		dp[i] = INT_MAX;
//		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
		for(int j=1; j<=k; j++){
			if(i-j>=0){
				dp[i] = min(dp[i-j]+ abs(a[i]-a[i-j]), dp[i]);
			}
		}
	}
	cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 5120
from collections import deque
maxv,maxe = map(int ,input().split())
level = [0 for i in range(maxv)] #sからの距離
iter = [0 for i in range(maxv)] #どこまで調べ終わったか
edge = [[] for i in range(maxv)] #edge[i][ii] = (j,k,l) iから出るii番目の辺の終点がj,コストがk,逆辺はkから出る辺のうちl番目のやつ

for i in range(maxe):
    u,v,c = map(int ,input().split())
    edge[u].append((v,c,len(edge[v])))
    edge[v].append((u,0,len(edge[u])-1))

def bfs(s): #sからの最短距離
    global level
    level = [-1 for i in range(maxv)]
    q = deque([])
    q.append(s)
    level[s] = 0

    while len(q) > 0:
        vv = q.popleft()
        for ee in edge[vv]:
            if ee[1] > 0 and level[ee[0]] < 0:
                level[ee[0]] = level[vv]+1
                q.append(ee[0])

def dfs(v,t,f): #増加パスをdfsで探索
    global level,iter
    if v == t : return f
    for inde  in range(iter[v], len(edge[v])):
        ee = edge[v][inde]
        iter[v] = inde
        if (ee[1] > 0) and (level[v] < level[ee[0]]):
            d = dfs(ee[0],t,min(f,ee[1]))
            if d>0:
                lledge = list(edge[v][inde])
                lledge[1] -= d
                edge[v][inde] = tuple(lledge)
                ledge = list(edge[ee[0]][ee[2]])
                ledge[1] += d
                edge[ee[0]][ee[2]] = tuple(ledge)
                return d

    return 0

#sからtへのmaximal flowを求める
flow = 0
while True :
    bfs(0)
    if (level[maxv-1] < 0):
        break
    iter = [0 for i in range(maxv)]
    f =dfs(0,maxv-1,float('inf'))
    while f>0:
        flow += f
        f = dfs(0,maxv-1,float('inf'))

print(flow)


Measured memory_bytes: 6124
<?php
$N  = fgets(STDIN);
$bStr = fgets(STDIN);
$nums = explode(" ", $bStr);

$run = 0;
$result = [];
$findResult = true;
while ($run < $N) {
    $found = false;
    for ($i = count($nums) - 1; $i >=0; $i--) {
        $currentNum = (int)$nums[$i];
        if ($currentNum == $i + 1) {
            $result[] = $currentNum;
            unset($nums[$i]);
            $nums = array_values($nums);
            $found = true;
            break;
        }
    }
    if (false == $found) {
        $findResult = false;
        break;
    }

    $run++;
}

if ($findResult) {
    for ($i = count($result) - 1; $i >= 0; $i--) {
        echo $result[$i] . "\n";
    }
} else {
    echo "-1\n";
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 200001
#define int ll
int L,R,d;
int ans = 0;
int32_t main(){
	fast;
	
	cin>>L>>R>>d;
	
	FOR(i,L,R) if (i % d == 0) ans++;
	cout<<ans;
		
	
	
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<long long> vll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int a, b, c;
  cin >> a >> b >> c;
  if (a==b && a!= c && b!=c )
    {
    cout<<"2"<<endl;
    }
    else if (a==c && a!= b && c!=b )
    {
    cout<<"2"<<endl;
    }   
 else if (b==c && b!= a && c!=a )
    {
    cout<<"2"<<endl;
    }
     else if (a!=b && b!= c && a!=c )
     {
    cout<<"3"<<endl;
    }
     else if (a == b && b == c )
     {
    cout<<"1"<<endl;
    }
}


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル

	ll A, B, N;
	cin >> A >> B >> N;

	if(B == 1){
		cout << 0 << endl;
	}
	else{
		if(N < B){
			cout << A * N / B - A * (N / B) << endl;
			return;
		}
		ll x = B - 1;
		cout << A * x / B - A * (x / B) << endl;
	}

}

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

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> h(n);
    rep(i,n) cin>>h[i];
    vector<int> path[n];
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        path[a].push_back(b);
        path[b].push_back(a);
    }
    int cnt = 0;
    rep(i,n){
        //cout<<i<<"start"<<endl;
        //cout<<h[i]<<endl;
        bool ok = 1;
        //cout<<endl;
        for(auto u : path[i]){
            //cout<<u<<" "<<h[u]<<endl;
            if(h[i]<=h[u]){
                ok = 0;
                break;
            }
        }
        if(ok){
            //cout<<"Yes"<<endl;
            cnt++;
        }
        //cout<<"end"<<endl;
    }
    cout<<cnt<<endl;
    return 0;
}

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


int main() {
  int N; cin >> N;
  for(int i = 1; i <= 50000; i++){
    ll y = i * 1.08;
    if(y == N){
      cout << i << endl;
      return 0;
    } 
  }

  cout << ":(" << endl;
	return 0;
}


Measured memory_bytes: 3640
import scala.io.StdIn._

object Main extends App {


  val n = readInt()
  val A = readLine().split(" ").map(_.toInt)

  def solve() = {
    val isValid = A.map { num =>
      if(num % 2 == 0 && num % 5 != 0 && num % 3 != 0) false else true
    }.forall(identity)
    if(isValid) "APPROVED" else "DENIED"
  }

  println(solve())

}



Measured memory_bytes: 54708
s=input()

l=len(s)-1

sums=[]

for i in range(2**l):

    inds=[0]

    for j in range(l):
      
        if (i>>j) & 1==1:
            inds.append(j+1)
            
    if len(inds)==1:
        sums.append(int(s))
    else:
        nums=[]
        
        for j in range(len(inds)-1):
            nums.append(int(s[inds[j]:inds[j+1]]))

        nums.append(int(s[inds[-1]:]))

        total=0
        for  n in nums:
            total+=n
        
        sums.append(total)
      
res=0
for n in sums:
    res+=n
  
print(res)

Measured memory_bytes: 3064
#include <iostream>  
using namespace std; 
// Recursive function to return gcd of a and b  
class gfg 
{ 
 public : long long gcd(long long a, long long b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
  
   
// Function to return LCM of two numbers  
  long long lcm(long long a, long long b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
} ; 
// Driver program to test above function  
int main()  
{  
    gfg g; 
    long long a,b;
  cin>>a>>b;
    cout<<g.lcm(a, b);  
    return 0;  
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <iostream>
typedef long long ll;
typedef int64_t in;
using namespace std;
#define INF 1000000007


int main() {
	int n;
    int j,v;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(i==n-1) cout << a[i] << endl;
        else cout << a[i] << " ";
    }
    for(int i=1; i<n; i++){
        v = a[i];
        j = i - 1;
        while(j >= 0 && a[j] > v){
            a[j+1] = a[j];
            j--;
            a[j+1] = v;
        }
        for(int k=0; k<n; k++){
            if(k==n-1) cout << a[k] << endl;
            else cout << a[k] << " ";
        }
    }
}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

ll IN()
{
    ll a,b;
    scanf("%lld.%lld",&a,&b);
    return a*100 + b;
}

int main()
{
    ll A;
    cin >> A;

    ll B = IN();

    OUT0((A*B)/100LL);

    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
main(){
	int h1,m1;
	while(~getII(h1,m1)){
		VgetIII(h2,m2,k);
		m1+=h1*60;
		m2+=h2*60;
		int ans=m2-m1-k;
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 3828
import sys
input = sys.stdin.readline

n = int(input())
lia = list(map(int,input().split()))
lib = list(map(int,input().split()))

ans = 0

for i in range(n):
    a = min(lia[i],lib[i])
    ans += a
    lib[i] -= a
    b = min(lia[i+1],lib[i])
    ans += b
    lia[i+1] -= b

print(ans)


Measured memory_bytes: 18624
n, w = map(int, input().split())
V = [0] * n
W = [0] * n
for i in range(n):
    vi, wi = map(int, input().split())
    V[i] = vi
    W[i] = wi
    
dp = [[0]*(w+1) for _ in range(n+1)]
dp[0] = [0]*(w+1)


for i in range(1, n+1):
    for j in range(w+1):
        if j-W[i-1]>=0:
            dp[i][j] = max(dp[i-1][j-W[i-1]] + V[i-1], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]
        #print(i, j , dp[i][j])
            
print(dp[n][w])


Measured memory_bytes: 41888
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    long int W;
    cin>>n>>W;
    long long int w[n+1],v[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    long long int dp[n+1][W+1];
    for(int i=0;i<n+1;i++)
    {
        for(int j=0;j<W+1;j++)
        {
            if(i==0||j==0)
            {
                dp[i][j]=0;
            }else
            {
                if(j>=w[i])
                    dp[i][j]=max(v[i]+dp[i-1][j-w[i]],dp[i-1][j]);
                else
                    dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W];
}


Measured memory_bytes: 79104
#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>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#include <math.h>

int r;
double solve(){
   return 2*M_PI*r;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>r;
    cout<<setprecision(23)<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,ten=1,o=0;
  cin >> n;
  for(int i=0;i<3;i++){
    if((n/ten)%10==1) a=9;
    else a=1;
    //cout << "a is " << a << endl;
    o+=a*ten;
    ten*=10;
  }
  cout << o <<endl;
}


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

int main(){
    int N;
    int a[10009];
    cin >> N;
    int count = 0;
    for (int i = 0; i < N; i++){
        cin >> a[i];
        while(a[i] % 2 == 0){
            count++;
            a[i] /= 2;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int q;cin>>q;
	while(q--){
		int n,k;
		cin>>n>>k;
		vi in(n);
		rep(i,n)cin>>in[i];
		vi t;
		rep(i,n-1)t.pb(in[i+1]-in[i]);
		sort(all(t));
		int sum=in[n-1]-in[0];
		rep(i,k-1)if(n-2-i>=0)sum-=t[n-2-i];
		cout<<sum<<endl;
	}
}










Measured memory_bytes: 4080
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 a;
    std::cin >> a;
    i64 ret = 0, n = 1;
    while (a) {
        a /= 2;
        ret += n;
        n *= 2;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define int long long
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 3e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;
int arr[LIM][65]; 
int sum[LIM][65]; 
int pw[65];

int32_t main()
{
	IOS;
	cin>>n;
	forn(i,n){
		ll x;
		cin>>x;
		forn(j,62){
			arr[i][j] = x%2;
			if(i==0){
				sum[i][j]=arr[i][j];
			}
			else{
				sum[i][j]=sum[i-1][j]+arr[i][j];
			}
			x/=2;
		}
	}
	ll ans=0;
	pw[0]=1;
	forn(i,64){
		pw[i+1]=(pw[i]*2)%MOD;
	}
	for(int i=1;i<n;i++){
		forn(j,62){
			int f;
			if(arr[i][j]){
				f=i-sum[i-1][j];
			}
			else
				f=sum[i-1][j];
			ans = (ans  + 1LL*f*pw[j])%MOD;
		}
		// dbg(ans);	
	}
	// forn(j,65){
	// 	int ones=0;
	// 	forn(i,n){
	// 		ones+=arr[i][j];
	// 	}
	// 	ans = (ans + (ones*(n-ones)%MOD) *(1LL<<j % MOD))%MOD;
	// }
	cout<<ans<<ln;
}

Measured memory_bytes: 304896
#include <cstdio>
#include <queue>
using namespace std;
int N, M; priority_queue<int> A;
long long ans;
int main() {
    scanf("%d %d", &N, &M);
    for(int i = 1, t; i <= N; ++i) {
        scanf("%d", &t);
        A.push(t);
    }
    for(int i = 1, t; i <= M; ++i) {
        t = A.top(), A.pop();
        A.push(t/2);
    }
    for(int i = 1; i <= N; ++i) {
        ans += A.top(), A.pop();
    }
    printf("%ld\n", ans);
}


Measured memory_bytes: 892
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T) { (args[0], args[1]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let (h, w) = toTuple(readInts())
var si: [[String]] = []
for _ in 0..<h {
  let s = readLine()!.map { String($0) }
  si.append(s)
}
var ans: [[String]] = []
for i in 0..<h {
  var row: [String] = []
  for j in 0..<w {
    guard si[i][j] != "#" else {
      row.append("#")
      continue
    }
    var count = 0
    if i - 1 >= 0 , j - 1 >= 0 , si[i-1][j-1] == "#" {
      count += 1
    }
    if i - 1 >= 0 , si[i-1][j] == "#" {
      count += 1
    }
    if i - 1 >= 0 , j + 1 < w , si[i-1][j+1] == "#" {
      count += 1
    }
    if j + 1 < w , si[i][j+1] == "#" {
      count += 1
    }
    if i + 1 < h , j + 1 < w , si[i+1][j+1] == "#" {
      count += 1
    }
    if i + 1 < h , si[i+1][j] == "#" {
      count += 1
    }
    if i + 1 < h , j - 1 >= 0 , si[i+1][j-1] == "#" {
      count += 1
    }
    if j - 1 >= 0 , si[i][j-1] == "#" {
      count += 1
    }
    row.append(String(count))
  }
  ans.append(row)
}
ans.forEach {
  print($0.joined())
}

Measured memory_bytes: 13672
import sys

input = lambda: sys.stdin.readline().rstrip()

INF = 10 ** 5 + 1


def solve():
    N = int(input())
    B = list(map(int, input().split()))
    A = [INF] * N

    for i in range(N - 1):
        A[i] = min(A[i], B[i])
        A[i + 1] = min(A[i + 1], B[i])

    print(sum(A))


if __name__ == '__main__':
    solve()


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

#define F first
#define S second
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(int i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << endl;}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]";cout<<endl;}

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

	string s; cin >> s;
	int n = s.length();
	vi pos; int cur = 0;
	FOR (i, 0, n - 1) {
		if (s[i] - '0' != cur) pos.push_back(i), cur ^= 1;
	}
	if (cur) pos.push_back(n);

	int ans = n;
	for (int i : pos) {
		ans = min(ans, max(i, n-i));
	}
	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main() {
	string s;
	cin >> s;
	if(s[0] != 'A' || isupper(s[1]) || isupper(s[s.size() - 1])){
		cout << "WA" << endl;
		return 0;
	}
	bool isFoundC = false;
	for(int i = 2; i < s.size() - 1; i++){
		if(!isFoundC && s[i] == 'C') isFoundC = true;
		else if(s[i] == 'C'){
			cout << "WA" << endl;
			return 0;
		}else if(isupper(s[i])){
			cout << "WA" << endl;
			return 0;
		}
	}
	cout << (isFoundC ? "AC" : "WA") << endl;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans[n];
  for(int i=0;i<n;i++) ans[i]=0;
  for(int i=1;i<n;i++){
    if(s[i]=='E'){
      ans[0]++;
    }
  }
  for(int i=1;i<n;i++){
    ans[i]=ans[i-1];
    if(s[i]=='E'){
      ans[i]--;
    }
    if(s[i-1]=='W'){
      ans[i]++;
    }
  }
  sort(ans,ans+n);
  cout << ans[0] << endl;
}

Measured memory_bytes: 1796
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
using namespace std;
 int main(){
   int x,y;
   cin >> x >>y;
   cout << x+y/2 <<endl;
 }
   

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

int main() {
	int H,W;
  	cin >> H >> W;
  
  	vector<vector<char>> vec(H,vector<char>(W));
  
  	for(int i = 0; i < H; i++) {
    	for(int j = 0; j < W; j++) {
        	cin >> vec.at(i).at(j);
        }
    }
  
  	vector<int> hor(H,0);
  	vector<int>	ver(W,0);
  
  	for(int i = 0; i < H; i++) {
      bool can = true;
    	for(int j = 0; j < W; j++) {
        	if(vec.at(i).at(j) == '#') {
            	can = false;
            }
        }
          if(can) hor.at(i)++;
    }
  
  	  
  	for(int i = 0; i < W; i++) {
      bool can = true;
    	for(int j = 0; j < H; j++) {
        	if(vec.at(j).at(i) == '#') {
            	can = false;
            }
        }
          if(can) ver.at(i)++;
    }
  	
  	for(int i = 0; i < H; i++) {
      if(hor.at(i) == 0) {
    	for(int j = 0; j < W; j++) {
        	if(ver.at(j) == 0) {
            cout << vec.at(i).at(j);
            }
        }
        cout << endl;
      }
    }
  	
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  int x, y;
  cin >> x >> y;

  if(x == 2){
    if(y == 2){
      cout << "Yes";
      return 0;
    }
    else cout << "No";
    return 0;
  }

  if(y == 2){
    cout << "No";
    return 0;
  }

  int a[7] = {1, 3, 5, 7, 8, 10, 12};
  int c = 0;
  REP(i, 7){
    if(x == a[i] || y == a[i]) c++;
  }
  cout << ((c == 1) ? "No" : "Yes") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;

vector<int> g[100005];
int ans[100005];

int solve(int src){
    if(ans[src]!=-1) return ans[src];
    int leaf=1;
    int t=0;
    for(auto child: g[src]){
        leaf=0;
        t=max(solve(child),t);
    }
    return ans[src]=(leaf) ? 0 : t+1;
}


void addEdge(int x, int y){
    g[x].push_back(y);
}

int main(){
    
    int n,m; cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        addEdge(x,y);
    }
    
    memset(ans,-1,sizeof(ans));
    int ansi=0;
    
    for(int i=1;i<=n;i++){
        ansi=max(ansi,solve(i));
    }
    cout<< ansi;
    
}


Measured memory_bytes: 11444
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t
 
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
const ll MOD=1000000007,INF=1e18;

int A,B,Q;

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    //MOD同士の引き算に注意
    cin>>A>>B>>Q;
    vint s(A+1),t(B+1),x(Q);
    rep(i,0,A){
        cin>>s[i];
    }
    s[A]=INF;
    rep(i,0,B){
        cin>>t[i];
    }
    t[B]=INF;
    rep(i,0,Q){
        cin>>x[i];
        int a=lower_bound(all(s),x[i])-s.begin();
        int b=lower_bound(all(t),x[i])-t.begin();
        int ans=INF;
        chmin(ans,max(s[a]-x[i],t[b]-x[i]));
        if(a&&b)chmin(ans,max(abs(x[i]-s[a-1]),abs(x[i]-t[b-1])));
        if(a)chmin(ans,2*(t[b]-x[i])+abs(x[i]-s[a-1]));
        if(b)chmin(ans,2*(s[a]-x[i])+abs(x[i]-t[b-1]));
        if(a)chmin(ans,2*abs(x[i]-s[a-1])+t[b]-x[i]);
        if(b)chmin(ans,2*abs(x[i]-t[b-1])+s[a]-x[i]);
        cout<<ans<<endl;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>

int main(void) {
    int a, b;

    scanf("%d %d\n", &a, &b);
    if (a >= 10 || b >= 10) {
        fprintf(stdout, "-1\n");
    } else {
        fprintf(stdout, "%d\n", a * b);
    }

    return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		ArrayList<Integer> ans = new ArrayList<Integer>();
		
		while(true) {
			
			String s = br.readLine();
			if (s == null) break;
			StringTokenizer st = new StringTokenizer(s," ");
			ans.add(String.valueOf(Integer.parseInt(st.nextToken()) + 
					Integer.parseInt(st.nextToken())).length());
		}
		for (int a : ans)
			System.out.println(a);
	}
	
}

Measured memory_bytes: 10000