akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
    string an;
    int men[6],A,n,m1,m2;
    while(1){
        A=1;
        for(int i=0;i<6;i++){
            men[i]=i+1;
        }
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>an;
            if(an[0]=='N'){
                m1=men[0];men[0]=men[1];
                m2=men[4];men[4]=m1;
                m1=men[5];men[5]=m2;men[1]=m1;
                 A+=men[0];
            }else if(an[0]=='E'){
                m1=men[0];men[0]=men[3];
                m2=men[2];men[2]=m1;
                m1=men[5];men[5]=m2;men[3]=m1;
                 A+=men[0];
            }else if(an[0]=='W'){
                m1=men[0];men[0]=men[2];
                m2=men[3];men[3]=m1;
                m1=men[5];men[5]=m2;men[2]=m1;
                 A+=men[0];
            }else if(an[0]=='S'){
                m1=men[0];men[0]=men[4];
                m2=men[1];men[1]=m1;
                m1=men[5];men[5]=m2;men[4]=m1;
                A+=men[0];
            }else if(an[0]=='R'){
                m1=men[2];men[2]=men[4];
                m2=men[1];men[1]=m1;
                m1=men[3];men[3]=m2;men[4]=m1;
                 A+=men[0];
            }else if(an[0]=='L'){
                m1=men[2];men[2]=men[1];
                m2=men[4];men[4]=m1;
                m1=men[3];men[3]=m2;men[1]=m1;
                 A+=men[0];
            }
        }
        cout<<A<<"\n";
    }
}

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

int max(int i){
  int c = 0;
  while(i>1){
    i /= 2;
    c++;
  }
  return c;
}

int main() {

  int n;
  cin >> n;
  int m = 0;

  for(int i = n; i > 0; i--){
    if(m  < max(i)){
      m = max(i);
    }
  }

  cout << pow(2,m) << endl;
}


Measured memory_bytes: 256
def is_ok(X):
    cnt = 0
    for a in A:
        cnt += (a-1)//X
    if cnt <= k:
        return True
    else:
        return False


def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n, k = map(int,input().split())
A = list(map(int,input().split()))

print(meguru_bisect(0,max(A)+1))

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

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    if(n < 1000){
        cout << 1000 - n << "\n";
    }
    else if(n % 1000 == 0){
        cout << 0 << "\n";
    }
    else cout << 1000 - n % 1000 << "\n";
}


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

typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false);

    string s;
    cin >> s;

    int n = s.size(), suf = 0;
    vector<int> cnt(2020);
    cnt[0]++;

    int ans = 0, p = 1;

    for(int i = n - 1; i >= 0; i--) {
        suf += ((s[i] - '0') * p);
        suf %= 2019;

        p *= 10;
        p %= 2019;

        for(int j = 0; j <= 2018; j++) {
            if((suf - j + 2019) % 2019 == 0) {
                ans += cnt[j];
            }
        }

        cnt[suf]++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3736
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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


int main() {

	int a,b;
	cin >> a >> b;

	int c;
	c = b - a;

	int h;
	h = 0;

	REP(i, c) {
		h += i;
	}

	cout << h - a << endl;

	int end;
	cin >> end;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll inf = 1000000000;
typedef pair<ll, ll> P;
int main() {
	int n;
	string s;
	cin >> n >> s;
	ll count = 0;
	for (int i = 0; i < 1000; i++) {
		int c[3] = { i / 100,(i / 10) % 10,i % 10 };
		int f = 0;
		for (int j = 0; j < n; j++) {
			if (s[j] == ('0' + c[f])) {
				f++;
			}
			if (f == 3) {
				count++;
				break;
			}
		}
		
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

struct coin {
	ll gold, silver, bronze;
	bool operator < (const coin &other) {
		return silver - bronze > other.silver - other.bronze;
	}
};

typedef pair<ll, coin> C;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int x, y, z;
	cin >> x >> y >> z;
	int n = x + y + z;
	vector<coin> p(n);
	rep(i, n) cin >> p[i].gold >> p[i].silver >> p[i].bronze;
	sort(all(p));
	vector<ll> ab(n, -INF), ac(n, -INF);
	ll sum = 0;
	priority_queue<ll> que;
	rep(i, y) {
		sum += p[i].silver;
		que.push(p[i].gold - p[i].silver);
	}
	ab[y - 1] = sum;
	for (int i = y; i < x + y; i++) {
		que.push(p[i].gold - p[i].silver);
		ll q = que.top(); que.pop();
		sum += q + p[i].silver;
		ab[i] = sum;
	}
	ll sum2 = 0;
	priority_queue<ll> que2;
	for (int i = n - 1; i >= n - z; i--) {
		sum2 += p[i].bronze;
		que2.push(p[i].gold - p[i].bronze);
	}
	ac[n - z] = sum2;
	for (int i = n - z - 1; i >= n - x - z; i--) {
		que2.push(p[i].gold - p[i].bronze);
		ll q = que2.top(); que2.pop();
		sum2 += q + p[i].bronze;
		ac[i] = sum2;
	}
	ll ans = 0;
	rep(i, n - 1) chmax(ans, ab[i] + ac[i + 1]);
	cout << ans << '\n';
}

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

using namespace std;
typedef long long ll;

ll n,a[200010]={0};
vector<ll>b;

int main(){
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    b.resize(n);
    for(int i=0;i<n;++i){
        cin>>b[i];
    }

    
    ll ans=0;
    for(int i=0;i<29;++i){
        vector<ll>c;
        ll key=(1<<i);
        for(int k=0;k<n;++k){
            c.push_back(b[k]%(2*key));
        }
        sort(c.begin(),c.end());
        ll cnt=0;
        for(int j=0;j<n;++j){
            ll d=a[j]%(2*key);
            cnt+=(ll)(lower_bound(c.begin(),c.end(),2*key-d)-lower_bound(c.begin(),c.end(),key-d));
            cnt+=(ll)(lower_bound(c.begin(),c.end(),4*key-d)-lower_bound(c.begin(),c.end(),3*key-d));
        }
        ans+=(cnt%2)*key;
    }

    cout<<ans<<endl;

    return 0;
}

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

using namespace std;

int main(){
    string S, T;
    cin >> S >> T;

    int S_len = (int)S.size();
    int T_len = (int)T.size();

    if ((S_len + 1 == T_len) and (S == T.substr(0, T_len - 1))){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 3628
#include <cstdio>
#include <stack>
using namespace std;

int n, m;
stack<int> s;
bool dp[200001] = { false };

int main(){
	int tmp;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d", &tmp);
		s.push(tmp);
	}
	while (!s.empty()) {
		tmp = s.top(); s.pop();
		if (!dp[tmp]) {
			dp[tmp] = true;
			printf("%d\n", tmp);
		}
	}
	for (int i = 1; i <= n; i++) {
		if (!dp[i]) {
			printf("%d\n", i);
		}
	}

	return 0;
}

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

int main()
{
	string s;
	while( cin >> s && s != "0" ){
		int point[ 'Z' ] = { 0 };
		for( int i = 1; i < (int)s.size(); ++i ){
			++point[ s[ i ] ];
		}
		point[ 'A' ] > point[ 'B' ] ? ++point[ 'A' ] : ++point[ 'B' ];
		cout << point[ 'A' ] << " " << point[ 'B' ] << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
    using namespace std;
     
    int dp[100005];
    int cost(int* arr,int a,int n)
    {
    	if(dp[a]!=-1)
    	return dp[a];
    	if(a==n-1)
      	return 0;
    	if(a==n-2)
    	return dp[a]=abs(arr[a]-arr[a+1]);
    	else return dp[a]=min(abs(arr[a]-arr[a+1])+cost(arr,a+1,n),abs(arr[a]-arr[a+2])+cost(arr,a+2,n));
    }
     
    int main()
    {
      int n;
      cin>>n;
      int arr[n];
      for(int i=0;i<n;i++)
      {
        cin>>arr[i];
      }
      memset(dp,-1,sizeof(dp));
      cout<<cost(arr,0,n);
      
      return 0;
    }

Measured memory_bytes: 4864
## coding: UTF-8
N,M = map(int,input().split())
H = list(map(int,input().split()))

'''
path = []
for i in range(M):
    path.append(list(map(int,input().split())))
'''
path = [list(map(int,input().split())) for i in range(M)]  # 二次元配列入力　二次元マップみたいな入力のとき

'''
l = [] 
for i in range(N):
    l.append([0] * N + [H[i]])
'''


highest = [0] + [1] * N
#print(highest)
#print(H)
for i in range(M):
    #print('path[i][0] = {}, path[i][1] = {}'.format(path[i][0], path[i][1]))
    #print('H[path[i][0]-1]:{}, H[path[i][1]-1]:{}'.format(H[path[i][0]-1], H[path[i][1]-1]))
    pa = path[i]
    p = pa[1]-1
    q = pa[0]-1
    x = H[p]
    y = H[q]
    if( x >= y ):
        #print('deny at {}'.format(path[i][0]))
        highest[q+1] = 0
    if(  x <= y  ):
        #print('deny at {}'.format(path[i][1]))
        highest[p+1] = 0
    #print('highest:{}'.format(highest))

print(sum(highest))

'''
for i in range(M):
    print('path[i][0] = Ai = {}, path[i][1] = Bi = {}'.format(path[i][0], path[i][1]))
    l[ path[i][0]-1 ][ path[i][1]-1 ] = H[path[i][1]-1]
    l[ path[i][1]-1 ][ path[i][0]-1 ] = H[path[i][0]-1]
    print(l)
'''



'''
m_neigh = []
for i in range(N):
    print(l[i][:N])
    m_neigh.append(  max(l[i][:N] )  )
    print(m_neigh)
'''
'''
cnt = 0
for i in range(N):
    
'''

Measured memory_bytes: 32752
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <cmath>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int N = pow(2,n);
    vector<int> t(2*N-1);
    multiset<int> st;
    for (int i=0;i<N;i++)
    {
        int s;
        cin>>s;
        st.insert(s);
    }
    t[0]=*st.rbegin();
    st.erase(st.find(t[0]));
    int k = 1;
    for (int i=0;i<N-1;i=2*i+1)
    {
        for (int j=i;j<=2*i;j++)
        {
            t[2*j+1]=t[j];
            multiset<int>::iterator it=st.lower_bound(t[j]);
            if (it==st.begin())
            {
                cout<<"No"<<endl;
                return 0;
            }
            else
            {
                t[2*j+2]=*(--it);
                st.erase(it);
            }
            k++;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 14720
from operator import add
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class SegmentTree:
    def __init__(self, N, arr=None, op=None, unit=None):
        self.N = N
        self.unit = unit
        self.op = op
        self.tree = [unit] * (2 * N + 1)
        if arr is not None:
            self._build(arr)

    def _build(self, arr):
        op = self.op
        N = self.N
        for i, a in enumerate(arr, N):
            self.tree[i] = a
        for i in reversed(range(1, N)):
            self.tree[i] = op(self.tree[i << 1], self.tree[i << 1 | 1])

    def update(self, i, x):
        """
        arr[i]の値をxに変更する
        i: 0-indexed
        """
        i += self.N
        op = self.op
        self.tree[i] += x
        while i > 1:
            i >>= 1
            self.tree[i] = op(self.tree[i << 1], self.tree[i << 1 | 1])

    def query(self, L, R):
        """
        L,R: 0-indexed
        半開区間[L,R)の累積演算した値を返す
        """
        op = self.op
        res = self.unit
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                res = op(res, self.tree[L])
                L += 1
            if R & 1:
                R -= 1
                res = op(res, self.tree[R])
            L >>= 1
            R >>= 1
        return res


if __name__ == "__main__":
    N, Q = map(int, input().split())
    query = tuple(tuple(map(int, input().split())) for _ in range(Q))
    seg = SegmentTree(N, [0]*N, add, 0)

    ans = []
    for f, x, y in query:
        if f:
            ans.append(seg.query(x-1, y))
        else:
            seg.update(x-1, y)
    print(*ans, sep="\n")


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

public class Main {
	public static void main(String[] args) {
		FastScanner br = new FastScanner();
		PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
		int n1 = br.ni();
		int n2 = br.ni()-1;
		String m = br.nt();
		System.out.println(m.substring(0,n2)+m.substring(n2,n2+1).toLowerCase()+m.substring(n2+1,m.length()));
		pw.close();
	}
}

class FastScanner {
	BufferedReader br;
	StringTokenizer st;

	public FastScanner(String s) {
		try {
			br = new BufferedReader(new FileReader(s));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public FastScanner() {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	ArrayList<Integer>[] ng(int n, int e) {
		ArrayList<Integer>[] adj = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			adj[i] = new ArrayList<Integer>();
		}
		for (int i = 0; i < e; i++) {
			int a = ni() - 1;
			int b = ni() - 1;
			adj[a].add(b);
			adj[b].add(a);
		}
		return adj;
	}

	Integer[] nIa(int n) {
		Integer[] arr = new Integer[n];
		for (int i = 0; i < n; i++) {
			arr[i] = ni();
		}
		return arr;
	}

	int[] nia(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = ni();
		}
		return arr;
	}

	Long[] nLa(int n) {
		Long[] arr = new Long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nl();
		}
		return arr;
	}

	long[] nla(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nl();
		}
		return arr;
	}

	String[] nsa(int n) {
		String[] arr = new String[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nt();
		}
		return arr;
	}

	String nt() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	int ni() {
		return Integer.parseInt(nt());
	}

	long nl() {
		return Long.parseLong(nt());
	}

	double nd() {
		return Double.parseDouble(nt());
	}

}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, c, k;
    cin >> n >> c >> k;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans = 0, now = -1, cnt = 0;
    rep(i, 0, n){
        if(now == -1){
            now = a[i];
            cnt = 1;
            ans++;
        }else{
            if(a[i] <= now + k && cnt < c){
                cnt++;
            }else{
                now = a[i];
                cnt = 1;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main () {
  int A, B;
  cin >> A >> B;
  if (A < 6) {
    cout<<0<<endl;
  } else if (A < 13) {
    cout<<B/2.<<endl;
  } else {
    cout<<B<<endl;
  }

  return 0;
}


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

using namespace std;

typedef unsigned long long ull;
ull K;

double s(ull n) {
	ull x = n, y = 0;

	while (x > 0) {
		y += x % 10;
		x /= 10;
	}

	return (double)n / y;
}

int main() {
	cin >> K;
	ull n = 1;
	ull x = 1;

	for (ull i = 0; i < K; i++) {
		cout << n << endl;

		if (s(n + x) > s(n + x * 10)) x *= 10;

		n += x;
	}

	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define ALF "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define LLBIG 1999999999999999999
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

int main() {
	string s, s1, s2; cin >> s;
	s1 = s2 = s;
	int a1 = 0, a2 = 0;
	a1++; s1[0] = (s1[0] == '0' ? '1' : '0');
	for (int i = 1; i < s.size(); i++) {
		if (s1[i] == s1[i - 1]) {
			a1++; s1[i] = (s1[i] == '0' ? '1' : '0');
		}
		if (s2[i] == s2[i - 1]) {
			a2++; s2[i] = (s2[i] == '0' ? '1' : '0');
		}
	}

	cout << min(a1, a2) << endl;
	return 0;
}


Measured memory_bytes: 512
import java.util.*

fun main(args:Array<String>){
    val (n,k,q) = readLine()!!.split(" ").map{it.toInt()}
    var a = Array<Int>(n){0}
    for(i in 1 .. q){
        val b = readLine()!!.toInt()
        a[b - 1]++
    }
    var ans = Array<Boolean>(n){false}
    for(i in 0 until n){
        if(q - a[i] < k) ans[i] = true
    }
    val sb = StringBuilder()
    ans.forEach{
        sb.append((if(it) "Yes" else "No") + "\n")
    }
    println(sb.toString())
}

Measured memory_bytes: 44820
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



ll N,K;

bool is_OK(ll first){

	ll rest = K-first; //残りの予算
	ll pre = first; //前の人の割り当て額
	ll index,tmp;

	for(index = 1; index < N; index++){
		tmp = pre/2;
		if(tmp == 0){

			index = N;
			break;

		}else{

			if(rest < tmp){

				break;
			}
			rest -= tmp;
		}
		pre = tmp;
	}

	return index == N;
}


int main(){

	scanf("%lld %lld",&N,&K);

	if(N == 1){

		printf("%lld\n",K);
		return 0;
	}

	ll left = 0,right = K,mid = (left+right)/2;

	ll ans = 0;

	while(left <= right){

		if(is_OK(mid)){

			ans = mid;
			left = mid+1;
		}else{

			right = mid-1;
		}
		mid = (left+right)/2;
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 3216
n=int(input())
a=[int(i) for i in input().split()]
dic={}
check8=0
for i in a:
    check=i//400
    if check not in dic and check <8:
        dic[check]=1
    if check>=8:
        check8+=1

mi=max(1,len(dic))
ma=len(dic)+check8
print(mi,ma)

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

int main(){
  int K,S; cin >>K >>S;
  int ans=0;
  for(int x=0; x<=K; x++){
    if(x>S) break;
    for(int y=0; y<=K; y++){
      if(x+y>S) break;
      int z = S-x-y;
      if(z<=K) ans++;
    }
  }

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


Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let mut v = vec![0, 0];
    for i in buf.trim().chars().map(|c| c.to_digit(10).unwrap() as usize) {
        v[i] += 1;
    }
    println!("{}", std::cmp::min(v[0], v[1]) * 2);
}


Measured memory_bytes: 4352
def ls_devider(num):
    fs = set()
    fs.add(1)

    if num > 1:
        for i in range(2, num+1):
            if num % i == 0:
                fs.add(i)

    return fs


a, b, k = map(int, input().split(' '))
a_dvs = ls_devider(a)
b_dvs = ls_devider(b)

print(sorted(a_dvs&b_dvs, reverse=True)[k-1])




Measured memory_bytes: 3060
#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>;

struct Csf {
  int c, s, f;
};

int main() {
  int n;
  cin >> n;
  vector<Csf> csfs(n - 1);
  rep(i, n - 1) {
    int c, s, f;
    cin >> c >> s >> f;
    csfs.at(i) = {c, s, f};
  }

  for (int i = 0; i < n - 1; i++) {
    Csf cur = csfs.at(i);
    int t = cur.s;
    for (int j = i; j < n - 1; j++) {
      Csf csf = csfs.at(j);
      int tmp = max(t, csf.s);
      if (tmp % csf.f == 0) {
        t = tmp;
      } else {
        t = (tmp / csf.f + 1) * csf.f;
      }
      t += csf.c;
    }
    cout << t << endl;
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 3592
S_number = [int(i) for i in range(1,14)]
H_number = [int(i) for i in range(1,14)]
C_number = [int(i) for i in range(1,14)]
D_number = [int(i) for i in range(1,14)]


n = int(input())

for i in range(1,n+1):
    cord = input().split()
    if cord[0] == "S":
        S_number.remove(int(cord[1]))
        #print(cord)
    elif cord[0] == "H":
        H_number.remove(int(cord[1]))
        #print(cord)
    elif cord[0] == "C":
        C_number.remove(int(cord[1]))
        #print(cord)
    elif cord[0] == "D":
        D_number.remove(int(cord[1]))

if len(S_number) != 0:
    for i in range(len(S_number)):
        print("S {0}".format(S_number[i]))
if len(H_number) != 0:
    for i in range(len(H_number)):
        print("H {0}".format(H_number[i]))
if len(C_number) != 0:
    for i in range(len(C_number)):
        print("C {0}".format(C_number[i]))
if len(D_number) != 0:
    for i in range(len(D_number)):
        print("D {0}".format(D_number[i]))

Measured memory_bytes: 7776
from sys import stdin

def main():
    N = int(input())
    P = list(map(int, input().split()))

    ans = 0
    for i in range(1, N - 1):
        ans += all((min(P[i-1], P[i], P[i+1]) < P[i],
                    max(P[i-1], P[i], P[i+1]) > P[i]))
    print(ans)

input = lambda: stdin.readline()
main()


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

struct XL
{
  int X;
  int L;
};

int main()
{
  int N;
  cin >> N;
  vector<XL> xl(N);
  for (auto & _xl: xl)
    cin >> _xl.X >> _xl.L;
  sort(xl.begin(), xl.end(), [](auto & l, auto & r){return l.X < r.X;});
  int nr = 0, nl = 0;
  int l, r;
  for (l = 0, r = 1; r < N; ++r)
  {
    if ((xl[l].X + xl[l].L) <= (xl[r].X - xl[r].L))
      l = r;
    else
    {
      ++nr;
      if ((xl[r].X + xl[r].L) < (xl[l].X + xl[l].L))
        l = r;
    }
  }
  for (l = N - 2, r = N - 1; 0 <= l; --l)
  {
    if ((xl[l].X + xl[l].L) <= (xl[r].X - xl[r].L))
      r = l;
    else
    {
      ++nl;
      if ((xl[r].X - xl[r].L) < (xl[l].X - xl[l].L))
        r = l;
    }
  }
  cout << N - ((nr < nl) ? nr : nl);
  return 0;
}


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

public class Main{
	static void main() throws Exception{
		int h1=sc.nextInt(),m1=sc.nextInt(),h2=sc.nextInt(),m2=sc.nextInt(),k=sc.nextInt();
		if(m2<m1) {
			m2+=60;
			h2--;
		}
		int ans=m2-m1;
		int difh=(h2-h1+24+24)%24;
		ans+=difh*60;
		pw.println(ans-k);
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
//		int tc=sc.nextInt();
//		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}

Measured memory_bytes: 32484
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Prim(g):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v.keys()))
    V = list(set(V))

    used = set([])
    q = []
    heapq.heappush(q, (0, V[0]))

    ret = 0
    while q:
        c, v = heapq.heappop(q)

        if v in used:
            continue
        used.add(v)
        ret += c
        for u in g[v]:
            heapq.heappush(q, (g[v][u], u))
    return ret


@mt
def slv(N, A, B, H):
    H.sort(reverse=True)

    def e(t):
        b = B*t
        a = A-B
        for h in H:
            h -= b
            if h > 0:
                t -= int(math.ceil(h/a))
        return t >= 0

    l = 0
    r = max(H)
    while r - l > 1:
        m = (r+l)//2
        if e(m):
            r = m
        else:
            l = m

    return r


def main():
    N, A, B = read_int_n()
    H = [read_int() for _ in range(N)]

    print(slv(N, A, B, H))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9960
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int n[3] , K;
    for(int i = 0; i < 3; i++) cin >> n[i];
    cin >> K;

    sort(n, n+3);

    cout << n[0] + n[1] + pow(2, K) * n[2] << endl;

    return 0;

}

Measured memory_bytes: 256
import heapq as hq

def D_stra(N,connections,st):
    mxc=2**29
    cost =[mxc for i in range(N)]
    visited =[False for i in range(N)]
    flx = [mxc for i in range(N)]
    cost[st]=0
    q=[]

    hq.heappush(q,(0,st))

    while q:
        c,node=hq.heappop(q)
        if visited[node]:
            continue
        visited[node]=True

        for connection in connections[node]:
            target,mc=connection
            if cost[target]>c+mc:
                cost[target]=c+mc
                hq.heappush(q,(c+mc,target))
                flx[target]=node
    
    return cost,flx


    

def resolve():
    N,M = map(int,input().split())

    connections = [[] for i in range(N)]
    for i in range(M):
        a,b = map(int,input().split())
        connections[a-1].append([b-1,1])
        connections[b-1].append([a-1,1])
    ans,ans2 = D_stra(N,connections,0)

    if 2**29 in ans:
        print("No")
        return
    print("Yes")
    for i in ans2[1:]:
        print(i+1)

resolve()

Measured memory_bytes: 71324
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int match(string& a, string& b)
{
    int ans = 0;
    while(a[ans] == b[ans] && a[ans] != '\0' && b[ans] != '\0') ans++;
    return ans;
}

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

    vector<string> sa;
    
    for(int i=0; i<N; i++){
        sa.push_back(S.substr(i, N));
    }

    sort(sa.begin(), sa.end());
    // for(int i=0; i<N; i++) cout << sa[i] << endl;

    int ans = 0;
    vector<int> len;
    for(int i=0; i<N-1; i++){
        int cmp = match(sa[i], sa[i+1]);
        // cout << cmp << endl;
        int u = sa[i].size();
        int v = sa[i+1].size();
        
        len.push_back(u);
        // for(int& l: len) cout << l << " ";
        // cout << "\n";
        if(cmp != u){
            int M = len.size();
            for(int j=0; j<M-1; j++){
                for(int k=j; k<M; k++)
                    ans = max(min(len[j], len[k]-len[j]), ans);
            }
            len.clear();
        }
        cmp = min(cmp, abs(u - v));
        ans = max(cmp, ans);
    }
    len.push_back(sa[N-1].size());
    int M = len.size();
    for(int j=0; j<M-1; j++){
        for(int k=j; k<M; k++)
            ans = max(min(len[j], len[k]-len[j]), ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 16256
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/7/ITP1_7_B


def solve(n, x):

    result = 0
    for i in range(1, n+1):
        for j in range(i, n+1):
            for k in range(j, n+1):
                # 重複はダメ
                if i == j or j == k or k == i:
                    continue

                if i + j + k == x:
                    result += 1

    return result


if __name__ == "__main__":
    while True:
        n, x = map(int, input().split())
        if n == 0 and x == 0:
            break

        print(solve(n, x))



Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(6) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;

signed main(){
    cin >> n;
    vec(a,n);
    REP(i,n){
        cin >> a[i];
    }
    int m;
    cin >> m;
    REP(i,m){
        int t;
        cin >> t;
        if(t==n && a[n-1]<2019){
            a[n-1]++;
        }
        else if(t!= n && a[t]-a[t-1]>1){
            a[t-1]++;
        }
    }
    REP(i,n){
        cout << a[i] << endl;
    }
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



Measured memory_bytes: 3124
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>
#include<stack>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int n,d[10],f;
	stack<int> a,b,*p,*q;
	scanf("%d",&n);
	rep(i,n){
		rep(j,10)scanf("%d",d+9-j);
		while(!a.empty())a.pop();
		while(!b.empty())b.pop();
		a.push(11);
		b.push(11);
		f=0;
		rep(j,10){
			p=a.top()>b.top()?&a:&b;
			q=a.top()<=b.top()?&a:&b;
			if(q->top()>d[j])q->push(d[j]);
			else if(p->top()>d[j])p->push(d[j]);
			else {
				f=1;break;
			}
		}
		puts(f?"NO":"YES");
	}
	return 0;
}

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

int main(void){
  string s;

  cin >> s;

  int c = 999, f = 999;

  for(int i = 0; i < s.size(); i ++)
    if(s.at(i) == 'C'){
      c = i;
      break;
    }

  for(int i = s.size() - 1; i >= 0; i --)
    if(s.at(i) == 'F'){
      f = i;
      break;
    }

  if(c < f && c != 999 && f != 999) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class abc125b{
  static void Main(){
    var n=int.Parse(Console.ReadLine());
    var vs=Console.ReadLine().Split().Select(int.Parse).ToArray();
    var cs=Console.ReadLine().Split().Select(int.Parse).ToArray();

    var X=0;
    var Y=0;

    for(int i=0;i<n;i++){
      if(vs[i]>cs[i]){
        X+=vs[i];
        Y+=cs[i];
      }
    }
    int result=X-Y;
    
    Console.WriteLine(result);
    
    return;
  }
}

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

int ary[30];
int main(){
	int t=0;
	while(cin>>ary[t]){
		t++;
	}
	int res=0;
	for(int i=0;i<t;i++){
		res=0;
		for(int j=0;j<600;j+=ary[i]){
			res+=ary[i]*j*j;
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
//#include"atcoder/all"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
//using namespace atcoder;
int main(){
  int N,M,i;scanf("%d%d",&N,&M);
  pair<int,int> P[N];
  for(i=0;i<N;i++){
    scanf("%d%d",&P[i].second,&P[i].first);
    P[i].second = -P[i].second;
  }
  sort(P,P+N,greater<pair<int,int>>());
  int ans = 0;
  set<int> st;
  for(i=1;i<=M;i++) st.insert(i);
  for(i=0;i<N;i++){
    auto itr = st.lower_bound(-P[i].second);
    if(itr != st.end()){
      ans += P[i].first;
      st.erase(*itr);
    }
    if(st.empty()) break;
  }
  printf("%d\n",ans);
}

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

using namespace std;

struct Packet {
  int t, s, d;

  Packet() = default;
  Packet(int t, int s, int d): t(t), s(s), d(d) { }

  bool operator<(const Packet& p) const {
    return t < p.t;
  }
};

int main() {
  while (true) {    
    int N, M;
    cin >> N >> M;

    if (N + M == 0) {
      break;
    }

    bool infected[20001] = { true };

    vector<Packet> packet(M);
    for (int i = 0; i < M; i++) {
      int t, s, d;
      cin >> t >> s >> d;
      packet[i] = Packet(t, s - 1, d - 1);
    }
    sort(packet.begin(), packet.end());

    for (int i = 0; i < M; i++) {
      if (infected[packet[i].s]) {
        infected[packet[i].d] = true;
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (infected[i]) {
        ans++;
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3344
#include<stdio.h>
int main(void)
{
  int n,count=0;
  scanf("%d",&n);
  if(n%10==7)
    count++;
  if((n/10)%10==7)
    count++;
  if((n/100)%10==7)
    count++;
  if(count>0)
    puts("Yes");
  else
    puts("No");
  return 0;
}
  

Measured memory_bytes: 1644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[100010];
ll base[60];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%lld",a+i);
	ll sum=0;
	rep(i,0,n)sum^=a[i];
	{
		int rank=0;
		rep(k,0,60){
			int idx=-1;
			rep(i,rank,n)if(bit(a[i],59-k)){
				idx=i;
				break;
			}
			if(idx!=-1){
	//			printf("%d %d\n",59-k,idx);
				ll t=a[idx];a[idx]=a[rank];a[rank]=t;
				base[59-k]=t;
				rep(i,0,n)if(i!=rank&&bit(a[i],59-k))a[i]^=a[rank];
				rank++;
	//			rep(i,0,n)printf("%d ",a[i]);puts("");
			}
		}
	}
//	rep(i,0,60)printf("%d %d\n",i,base[i]);

//baseの元だけでsumが0のところについて掃き出し法する
	ll temp=0;
	for(int k=59;k>=0;k--)if(!bit(sum,k)){
		int idx=-1;
		rep(i,0,60)if(bit(base[i],k)){
			idx=i;
			break;
		}
		if(idx!=-1){
			if(!bit(temp,k))temp^=base[idx];
			rep(i,0,60)if(i!=idx&&bit(base[i],k))base[i]^=base[idx];
			base[idx]=0;
		}
	}
	printf("%lld",sum+(temp&~sum)*2);
}

Measured memory_bytes: 896
X, Y = map(int, input().split())

ans1, ans2, ans3=X+Y, X-Y, X*Y
if (ans1>=ans2 and ans1>=ans3):
  print(X+Y)

elif(ans2>=ans1 and ans2>=ans3):
  print(X-Y)

else:
  print(X*Y)


Measured memory_bytes: 2940
import numpy as np

if __name__ == "__main__":
    N = int(input())
    num_ls = np.arange(1, N+1)
    n = num_ls[(num_ls % 5 != 0) & (num_ls % 3 != 0) & (num_ls % 15 != 0)].astype(np.float64)
    ret = 0
    ret = sum(n)
    print(int(ret))


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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

vector<vector<int>> combination (vector<int> nums, int k) {
    vector<vector<int>> ret;
    if (k == 1) {
        REP (i, nums.size())
        ret.push_back (vector<int> (1, nums[i]));
    } else {
        REP (i, nums.size() - k + 1) {
            vector<int> cur (&nums[i + 1], &nums[nums.size()]);
            vector<vector<int>> rows = combination (cur, k - 1);
            REP (j, rows.size()) {
                rows[j].insert (rows[j].begin(), nums[i]);
                ret.push_back (rows[j]);
            }
        }
    }
    return ret;
}

int main() {
    int N;
    cin >> N;
    vector<int> d (N, 0);
    REP (i, N) cin >> d[i];
    int ans = 0;
    for (auto&& lst : combination (d, 2)) {
        ans += lst[0] * lst[1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#define endl '\n'
typedef long long ll;
using namespace std;
ll a[201];
int main()
{
    ll n;
    cin>>n;
    bool flag = true;
    ll turn = 0;
    for(ll i = 0; i<n; i++){
            cin>>a[i];
            if(a[i]%2){
                    //cout<<"0"<<endl;
                    flag = false;
                    break;
            }
    }
    while(flag){
            turn++;
        for(ll i = 0; i<n; i++){
            a[i] = a[i]/2;
            if(a[i]%2)flag = false;
        }
    }
    cout<<turn;
    return 0;

}


Measured memory_bytes: 256
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for x1, x2 in zip(range(H), range(H - 1, -1, -1)):
        for y1, y2 in zip(range(W), range(W - 1, -1, -1)):
            if S[x1][y1] == ".":  # left and upper sides of S[i][j]
                U[x1][y1] = 1 if x1 == 0 else U[x1 - 1][y1] + 1
                L[x1][y1] = 1 if y1 == 0 else L[x1][y1 - 1] + 1

            if S[x2][y2] == ".":  # right and under sides
                D[x2][y2] = 1 if x2 == H - 1 else D[x2 + 1][y2] + 1
                R[x2][y2] = 1 if y2 == W - 1 else R[x2][y2 + 1] + 1
    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W)
    )
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 176520
#!/usr/bin/env python3
import sys

inf = float('inf')

def solve(H: int, W: int, A: "List[str]"):
    dist = [[inf] * W for h in range(H)]
    for h in range(H):
        for w in range(W):
            hh = max(h-1, 0)
            ww = max(w-1, 0)            
            if A[h][w] == '#':
                dist[h][w] = 0
            else:
                dist[h][w] = min(dist[hh][w], dist[h][ww]) + 1
    
    dmax = 0
    for h in range(H-1, -1, -1):
        for w in range(W-1, -1, -1):
            hh = min(h+1, H-1)
            ww = min(w+1, W-1)
            dist[h][w] = min(dist[h][w], dist[h][ww] + 1, dist[hh][w] + 1)
            dmax = max(dist[h][w], dmax)
    print(dmax) 
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 87772
#include <iostream>
#include <algorithm> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
//#include <unordered_map> //ハッシュ関数
#include <fstream> //ifstream, ofstream


using namespace std;

//デバッグ時はTESTを定義する。本番時はこの行をコメントアウトする
#define TEST //*******************************************************************************************************************************************
//そうすることで、以下に定義する、デバッグ時にのみ標準出力する、doutコマンドが実現できる。本番時はダミーストリームに出力
//ただダミーストリームに出力する処理も結構CPU時間食うようなので、TLEを引き起こす原因になる可能性には注意
#ifdef TEST
#define dout cout
#else
stringstream dummy; //デバッグ時のdoutコマンドのダミー出力先
#define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummyを毎回リセットしておかないとメモリ溢れちゃう。
//どうせ表示しないからgoodbitしなくていいけど、表示する場合はこれしておかないとバグるらしいので、勉強のために。詳しくは http://d.hatena.ne.jp/linden/20060427/p1
#endif

//標準出力先をテキストファイルにしたい場合はOUTPUT2TEXTFILEを定義する。本番時はこの行をコメントアウトする
//#define OUTPUT2TEXTFILE //*******************************************************************************************************************************************
#ifdef OUTPUT2TEXTFILE
#define dout outputfile //というのはTLE問題でどうせdoutを全部コメントアウトしなくちゃいけなくなるので上記方式は却下して、代わりに出力先を標準出力からファイルに切り替えできるようにする
//TESTが定義されていると、outputfileに出力するようになる
#define OUTPUTFILENAME "output.txt"
ofstream outputfile(OUTPUTFILENAME);
#define OutputFilePath "/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/output.txt"
#endif



#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << (A) << " "
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl


int main(){
 
    int N;
    cin >> N;
    
    int A;
    cin >> A;
    
    
    cout << (N*N - A) << endl;
    
    
    
    
#ifdef OUTPUT2TEXTFILE
    outputfile.close();
    cout << "\"" << OutputFilePath << "\"" << endl;
#endif
    
    return 0;
}

Measured memory_bytes: 256
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		as[i] = nextInt(sc)
	}
	exec(as, n)
}

func exec(as []int, n int) {
	diffMax := -1000000000
	min := as[0]
	for i := 1; i < n; i++ {
		a := as[i]
		diff := a - min
		if diff > diffMax {
			diffMax = diff
		}
		if min > a {
			min = a
		}
	}
	fmt.Println(diffMax)
}



Measured memory_bytes: 5396
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << "No\n";
    return 0;
  }
  if (n == 2) {
    cout << "Yes\n";
    cout << 1 << ' ' << 2 << ' ' << 3 << endl;
    return 0;
  }
  {
    deque <int> ans = {2 * n - 1, x, x - 1, x + 1};
    set <int> q;
    for (int x : ans) q.insert(x);
    for (int i = 1; i < 2 * n; i++) {
      if (!q.count(i)) { 
        if (i % 2 == 0) ans.push_back(i);
        else ans.push_front(i);
        q.insert(i);
      }
    }
    if (ans.size() == 2 * n - 1 && *q.begin() == 1 && *q.rbegin() == 2 * n - 1) {
      cout << "Yes\n";
      for (int t : ans) cout << t << '\n';
      return 0;
    }
  }
  {
    deque <int> ans = {1, x, x + 1, x - 1};
    set <int> q;
    for (int x : ans) q.insert(x);
    for (int i = 1; i < 2 * n; i++) {
      if (!q.count(i)) { 
        if (i % 2 == 0) ans.push_back(i);
        else ans.push_front(i);
        q.insert(i);
      }
    }
    if (ans.size() == 2 * n - 1 && *q.begin() == 1 && *q.rbegin() == 2 * n - 1) {
      cout << "Yes\n";
      for (int t : ans) cout << t << '\n';
      return 0;
    }
  }
}



Measured memory_bytes: 11776
#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>;
int main() {
  ll n,k;
  cin >> n >> k;
  ll t = n%k;
  ll ans = min(t,k-t);
  cout << ans << endl;
}

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

vector<int> calc_reach(int N, int D, const vector<int> &ds){
    vector<int> rs(N, D);
    for (int i = 0; i != N - 1; ++i) rs[i + 1] = min(rs[i], abs(rs[i] - ds[i]));
    return rs;
}

vector<int> calc_fence(int N, int D, const vector<int> &ds){
    vector<int> fs(N, 0);
    for (int i = N - 1; i != 0; --i) fs[i - 1] = fs[i] + ((fs[i] * 2 + 1 >= ds[i]) ? ds[i]: 0);
    return fs;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, D;
    cin >> N >> D;
    vector<int> ds(N);
    for (auto & d : ds) cin >> d;
    auto rs = calc_reach(N, D, ds);
    auto fs = calc_fence(N, D, ds);
    int Q;
    cin >> Q;
    while (Q--){
        int q;
        cin >> q;
        cout <<  ((rs[q - 1] > fs[q - 1]) ? "YES\n" : "NO\n");
    }
    return 0;
}

Measured memory_bytes: 7808
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        int indexA = s.indexOf("A");
        int indexZ = s.lastIndexOf("Z");
        int result = indexZ - indexA + 1;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 26068