akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define spn setprecision
using namespace std;
ll multiply(ll num1, ll num2, ll mod) { // with mod > 1e9
	ll ans = 0;
	num1 %= mod;
	num2 %= mod;
	while (num2) {
		if (num2&1) {
			ans += num1;
			ans %= mod;
		}
		num1 *= 2;
		num1 %= mod;
		num2 /= 2;
	}
	return ans;
}
ll powmod2(ll base,ll exponent,ll mod){ // with mod > 1e9
	ll ans = 1;
	while (exponent) {
		if (exponent&1) {
			ans = multiply(ans, base, mod);
		}
		base = multiply(base, base, mod);
		exponent /= 2;
	}
	return ans;
}
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
struct data
{
	int ind,val;
};
bool cmp(data &a,data &b){
	return(a.val<b.val);
}
const int upperlimit = 1e5;
const int limit = 2e5;
int main() {
	int a,b;
	sd(a);
	sd(b);
	if(a>b){
		pd(a-1);
	}
	else{
		pd(a);
	}
	return 0;
}

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

using namespace std;
#define BUF (1000)
#define ll long long 

int N;
std::string S;

int zalgo(std::string& s){
	int ret = 0;
	int n = s.length();
	vector<int> z(n,0);

	int L=0, R=0;

	for(int i=1;i<n;i++){
		if(i>R){
			L=R=i;
			while(R<n && s[R-L] == s[R]) R++;
			z[i] = R-L;
			R--;
		}else{
			int k=i-L;
			if(z[k]<R-i+1) z[i] = z[k];
			else{
				L=i;
				while(R<n && s[R-L] == s[R]) R++;
				z[i] = R-L;
				R--;
			}
		}
		//ret = std::max(ret, z[i]);
	}

	for(int i=1;i<n;i++){
		ret = std::max(ret, std::min(z[i],i));
	}
	return ret;
}

int main(void){
	cin >> N;
	cin >> S;
	int ret = 0;
	for(int i=0;i<N;i++){
		std::string sub = S.substr(i,N-i);
		ret = std::max(ret, zalgo(sub));
	}

	if(ret<=0) cout << 0 << endl;
	else cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val Array(n, m) = sc.nextLine.split(" ").map(_.toInt)
    val roads = List.fill(m)(sc.nextLine.split(" ").map(_.toInt)).flatten
    (1 to n).map{city => roads.count(_ == city)}.foreach(println)
  }
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];

  sort(h.begin(), h.end(), greater<int>());

  int mn = INT_MAX;
  for (int i = 0; i < n; i++) {
    if (i <= n - k) {
      int diff = h[i] - h[i + k - 1];
      if (mn > diff) { mn = diff; }
    }
  }
  cout << mn << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

int depth[1000] = { 0 };
std::string s[1000];

int main() {
	int n;
	while (std::cin >> n && n) {
		int lastDepth = 0;
		for (int i = 0; i < n; i++) {
			std::string ss; std::cin >> ss;
			int p = 0;
			if (i) {
				p = ss.find_last_of('.') + 1;
				depth[i] = p;
			}
			s[i] = ss.substr(p);
		}

		bool isThereReplay[1001] = {false};
		for (int i = 0; i < n; i++) {
			isThereReplay[depth[i]] = false;//??´??\??????????????????

			// | ?????????
			for (int j = 1; j < depth[i] && i; j++) {
				if (isThereReplay[j]) std::cout << "|";
				else std::cout << " ";
			}
			if (i) std::cout << "+";
			std::cout << s[i] << (i != n - 1 ? "\n" : "");

			//??????????¨???????????????´??\?????????????????????????????????
			for (int j = i + 1; j < n; j++) {
				if (j == i + 1 && depth[i] >= depth[j]) break; //??????
				else if (depth[i] > depth[j]) break; //??????
				else if (depth[i] == depth[j]) { //??????
					isThereReplay[depth[i]] = true;
					break;
				}
			}
		}
		std::cout << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3128
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){

    int n, MAX, m;

    scanf("%d", &n);

    int a[n];

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

        scanf( "%d", &a[i] );

    }

    m = 2000000000;
    MAX = -2000000000;

    for( int i = 0 ; i < n-1 ; i++ ){

        m = min( m, a[i] );

        MAX = max( MAX, a[i+1] - m );

    }

    printf("%d\n", MAX);

}

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

int main() {
    int n, l, temp = INT_MAX, r, ans = 0;
    cin >> n >> l;
    rep(i, n) {
        ans += l + i;
        if(temp > abs(l + i)) {
            temp = abs(l + i);
            r = l + i;
        }
    }
    ans -= r;
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
H_LIST = input().split(" ")
H = []

for i in H_LIST:
    H.append(int(i))
   
count = 0
max_count = 0
for i in range(0, N-1):
    if H[i] >= H[i + 1]:
        count += 1
    else:
        count = 0 #メモリの動き
        
    if max_count < count:
        max_count = count


print(max_count)

Measured memory_bytes: 14224
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(long long N){
    long long ret = 0;
    vector<long long> l;
    l.push_back(1);
    long long e = 1;
    while (pow(9, e) <= 100000) {
        l.push_back(pow(9, e));
        e++;
    }
    e = 1;
    while (pow(6, e) <= 100000) {
        l.push_back(pow(6, e));
        e++;
    }
    sort(l.rbegin(), l.rend());
    vector< vector<long long> > dp(13, vector<long long> (100001, -1));
    dp[0][N] = 0;
    for (int i = 1; i < 13; i++) {
        for (int j = 0; j < 100001; j++) {
            if (dp[i-1][j] < 0) {
                continue;
            }
            for (int k = 0; k < 9 && j-l[i-1]*k >= 0; k++) {
                if(dp[i][j-l[i-1]*k] < 0) {
                    dp[i][j-l[i-1]*k] = dp[i-1][j] + k;
                } else {
                    dp[i][j-l[i-1]*k] = min(dp[i-1][j] + k, dp[i][j-l[i-1]*k]);
                }
            }
        }
    }
    std::cout << dp[12][0] << std::endl;
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long N;
    scanf("%lld",&N);
    solve(N);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <string>
using namespace std;
int main() {
	string str,fnd;
	int N,res=0;
	cin>>fnd>>N;
	for(int i=0;i<N;i++) {
		cin>>str;
		str+=str;
		if(str.find(fnd.c_str())!=str.npos)res++;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 1216
import sys
def input() : return sys.stdin.readline().strip()

def main():
    N, A, B, C = map(int, input().split())
    s = tuple(input() for _ in range(N))
    d = {}
    d["A"] = A
    d["B"] = B
    d["C"] = C
    ans = []
    for i in range(N-1):
        l1, r1 = s[i]
        l2, r2 = s[i+1]

        if d["A"]*d["B"]*d["C"]:
            temp = [d[l1], d[r1]]
            max_val = max(temp)
            max_index = temp.index(max_val)
            
            if max_index == 0:
                ans.append(r1)
                d[l1] -= 1
                d[r1] += 1
            else:
                ans.append(l1)
                d[l1] += 1
                d[r1] -= 1
        else:
            if d[l1] * d[r1]:
                if l1 == l2 and r1 == r2:
                    ans.append(l1)
                    d[l1] += 1
                    d[r1] -= 1
                else:
                    for c in [l1, r1]:
                        if [l1, r1, l2, r2].count(c) == 1:
                            d[c] -= 1
                        else:
                            ans.append(c)
                            d[c] += 1
            else:
                temp = [d[l1], d[r1]]
                max_val = max(temp)
                max_index = temp.index(max_val)
            
                if max_index == 0:
                    ans.append(r1)
                    d[l1] -= 1
                    d[r1] += 1
                else:
                    ans.append(l1)
                    d[l1] += 1
                    d[r1] -= 1
        if any([d[c] < 0 for c in "ABC"]):
            print("No")
            exit()

    l1, r1 = s[N-1]
    temp = [d[l1], d[r1]]
    max_val = max(temp)
    max_index = temp.index(max_val)
            
    if max_index == 0:
        ans.append(r1)
        d[l1] -= 1
        d[r1] += 1
    else:
        ans.append(l1)
        d[l1] += 1
        d[r1] -= 1

    if any([d[c] < 0 for c in "ABC"]):
            print("No")
    else:
        print("Yes")
        print(*ans, sep="\n")

if __name__ == "__main__":
    main()

Measured memory_bytes: 18644
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#ifndef U_L_LONG
typedef unsigned long long U_L_LONG;
#endif
#ifndef L_LONG
typedef long long L_LONG;
#endif

#ifndef LL_ABS
#define LL_ABS(x) (((((x) < 0) ? ((x) * (-1)) : (x))))
#endif

static void A_problem();

int main()
{
	A_problem();
	
	fflush(stdout);
	return 0;
}

static void A_problem()
{
	int A, B, T;

	scanf(" %d %d %d", &A, &B, &T);

	printf("%d\n", (T / A) * B);
}


Measured memory_bytes: 256
n,k = map(int,input().split())
ab = []
for _ in range(n):
    a,b = map(int,input().split())
    ab.append([a, b])
ab.sort()
s = 0
for i in range(n):
    s += ab[i][1]
    if s >= k:
        print(ab[i][0])
        exit()


Measured memory_bytes: 20104
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;

int main(){
   int W,H,i,j;
   int map[200*200],flag[200*200];
   int answ,ansh,now;
   
   for(;;){
      cin>>W>>H;
      if(W==0&&H==0) break;
      memset(flag,0,sizeof(flag));
      answ=0;ansh=0;now=0;
      
      for(i=0;i<W;i++){
         for(j=0;j<H;j++){
            map[i*H+j] = getchar();
            if(map[i*H+j]=='\n')
               map[i*H+j] = getchar();
         }
      }
      
      while(flag[now]==0){
         flag[now]++;
         
         if(map[now]=='>'){
            answ++;
            now++;
         }
         else if(map[now]=='<'){
            answ--;
            now--;
         }
         else if(map[now]=='^'){
            ansh--;
            now-=H;
         }
         else if(map[now]=='v'){
            ansh++;
            now+=H;
         }
         else if(map[now]=='.'){
            flag[now]=0;
            break;
         }
      }
      if(flag[now] == 0)
         cout<<answ<<" "<<ansh<<endl;
      else
         cout<<"LOOP"<<endl;
   }
   return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC121
{
    class B
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int[] B = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = a[0], M = a[1], C = a[2];
            int counter = 0;
            for(int i = 0; i < N; i++)
            {
                int sum = 0;
                int[] h = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                for(int j = 0; j < M; j++)
                {
                    sum += h[j] * B[j];
                }
                sum += C;
                if (sum > 0) counter++;
            }
            Console.WriteLine(counter);
        }

    }
}


Measured memory_bytes: 13268
// AOJ 1019: Vampirish Night
// 2017.8.17 bal4u@uu
// 2017.12.15

#include <stdio.h>
#include <string.h>

int s[101], b[101];
char buf[703], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int n, k, i, j;

	while (fgets(p=buf, 10, stdin) && *p != '0') {
		n = getint(), k = getint();
		memset(b, 0, sizeof(b));
		fgets(p=buf, sizeof(buf), stdin);
		for (i = 0; i < k; i++) s[i] = getint();
		for (j = 0; j < n; j++) {
			fgets(p=buf, sizeof(buf), stdin);
			for (i = 0; i < k; i++) b[i] += getint();
		}
		for (i = 0; i < k; i++) if (b[i] > s[i]) break;
		puts(i == k ? "Yes" : "No");
	}
	return 0;
}

Measured memory_bytes: 1740
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

a,b,c = map(int, input().split())

print(a+b+c - max(a,b,c))





Measured memory_bytes: 8996
N = gets.to_i
a = 0
b = 0
ba = 0
ans = 0
N.times { 
  str = gets.chop
  ans += str.scan(/AB/).count
  a += 1  if str[-1] == "A"
  b += 1  if str[0] == "B"
  ba += 1 if str[0] == "B" and str[-1] == "A"
}

if ba > 0
  if a == ba and b == ba
    a -= 1
    b -= 1
  end
end

ans += a > b ? b : a


puts ans

Measured memory_bytes: 3836
#include<iostream>
using namespace std;
int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size()-1;i++)
    {
        if(s[i]=='A' && s[i+1]=='C')
        {
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";


return 0;}


Measured memory_bytes: 256
import sys
S = list(input())
x, y = map(int, input().split())
c = 0
p = 0
q = 0
now = 0
R = []
L = []
for i in range(len(S)):
    if S[i] == "T":
        if p != 0:
            R.append(p)
            p = 0
        elif q != 0:
            L.append(q)
            q = 0
        c += 1
    elif c == 0:
        now += 1
    elif c % 2 == 0:
        p += 1
    else:
        q += 1
if p != 0:
    R.append(p)
if q != 0:
    L.append(q)

A = 2*(sum(R)+now)
B = 2*(sum(L))
dp_x = [[0]*(A+2) for _ in range(len(R)+2)]
dp_y = [[0]*(B+2) for _ in range(len(L)+1)]
c = 0
dp_x[0][sum(R)+now] = 1
dp_y[0][sum(L)] = 1
for i in range(1, len(R)+2):
    for j in range(A+2):
        if i == 1:
            if j - now >= 0:
                if dp_x[i-1][j-now] == 1:
                    dp_x[i][j] = 1
        else:
            if j - R[i-2] >= 0:
                if dp_x[i-1][j-R[i-2]] == 1:
                    dp_x[i][j] = 1
            if j + R[i-2] <= A+1:
                if dp_x[i-1][j+R[i-2]] == 1:
                    dp_x[i][j] = 1

for i in range(1, len(L)+1):
    for j in range(B+2):
        if j - L[i-1] >= 0:
            if dp_y[i-1][j-L[i-1]] == 1:
                dp_y[i][j] = 1
        if j + L[i-1] <= B+1:
            if dp_y[i-1][j+L[i-1]] == 1:
                dp_y[i][j] = 1

if A + 1 < x+sum(R)+now or x+sum(R)+now < 0:
    print("No")
    sys.exit()

if B + 1 < y+sum(L) or y+sum(L) < 0:
    print("No")
    sys.exit()

if dp_x[len(R)+1][x+sum(R)+now] == 1 and dp_y[len(L)][y+sum(L)] == 1:
    print("Yes")
else:
    print("No")

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int ans = 0;
  for (int a = 0; a <= A; a++) {
    for (int b = 0; b <= B; b++) {
      for (int c = 0; c <= C; c++) {
        if (X == 500 * a + 100 * b + 50 * c) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import collections

n = int(input())
a = list(map(int, input().split()))
q = int(input())
b_c = [list(map(int,input().split())) for i in range(q)]

summ = sum(a)
cc = collections.Counter(a)
for i in range(q):
  b = b_c[i][0]
  c = b_c[i][1]
  if b in cc:
    buf = cc[b]
    cc[b] = 0
    if c in cc:
      cc[c] = cc[c] + buf
    else:
      cc[c] = buf
    summ = summ - b*buf + c*buf
    print(summ)
  else:
    print(summ)
    

Measured memory_bytes: 36364
#include <iostream>
#include <cstdio>

using namespace std;

const int P=1000000007;
const int N=2000000;

int fact[N+5],invf[N+5];
int f[4][3],g[4][3];
int X1,X2,X3,X4,X5,X6,Y1,Y2,Y3,Y4,Y5,Y6,ans;

inline int C(int n,int m){return 1ll*fact[n+m]*invf[n]%P*invf[m]%P;}

inline void add(int &x,int y){(x+=y)%=P;}

int quick_power(int x,int y)
{
	int ret=1;
	for (;y;y>>=1,x=1ll*x*x%P) if (y&1) ret=1ll*ret*x%P;
	return ret;
}

void pre()
{
	fact[0]=1;
	for (int i=1;i<=N;++i) fact[i]=1ll*fact[i-1]*i%P;
	invf[N]=quick_power(fact[N],P-2);
	for (int i=N;i>=1;--i) invf[i-1]=1ll*invf[i]*i%P;
}

int calc(int x1,int y1,int sig1,int x2,int y2,int sig2)
{
	int ret=0;
	for (int x=X3;x<=X4;++x) add(ret,P-1ll*C(x-x1,Y3-1-y1)*(x+Y3)%P*C(x2-x,y2-Y3)%P),add(ret,1ll*C(x2-x,y2-Y4-1)*(x+Y4+1)%P*C(x-x1,Y4-y1)%P);
	for (int y=Y3;y<=Y4;++y) add(ret,P-1ll*C(y-y1,X3-1-x1)*(y+X3)%P*C(y2-y,x2-X3)%P),add(ret,1ll*C(y2-y,x2-X4-1)*(y+X4+1)%P*C(y-y1,X4-x1)%P);
	return ((ret*=sig1*sig2)+=P)%=P;
}

int main()
{
	pre();
	//freopen("sightseeing.in","r",stdin),freopen("sightseeing.out","w",stdout);
	scanf("%d%d%d%d%d%d",&X1,&X2,&X3,&X4,&X5,&X6),scanf("%d%d%d%d%d%d",&Y1,&Y2,&Y3,&Y4,&Y5,&Y6),ans=0;
	f[0][0]=1,f[0][1]=X1-1,f[0][2]=Y1-1;
	f[1][0]=-1,f[1][1]=X1-1,f[1][2]=Y2;
	f[2][0]=-1,f[2][1]=X2,f[2][2]=Y1-1;
	f[3][0]=1,f[3][1]=X2,f[3][2]=Y2;
	g[0][0]=1,g[0][1]=X6+1,g[0][2]=Y6+1;
	g[1][0]=-1,g[1][1]=X6+1,g[1][2]=Y5;
	g[2][0]=-1,g[2][1]=X5,g[2][2]=Y6+1;
	g[3][0]=1,g[3][1]=X5,g[3][2]=Y5;
	for (int i=0;i<4;++i)
		for (int j=0;j<4;++j)
			add(ans,calc(f[i][1],f[i][2],f[i][0],g[j][1],g[j][2],g[j][0]));
	printf("%d\n",ans);
	//fclose(stdin),fclose(stdout);
	return 0;
}

Measured memory_bytes: 15872
#include <iostream>
using namespace std;
int s,i;
int num[1000000];
int main(){
    cin>>s;
    num[s]=1;
    for(i=2;;i++){
        if(s%2==0) s/=2;
        else s=3*s+1;
        if(num[s]!=0) break;
        num[s]=i;
    }
    cout<<i;
}

Measured memory_bytes: 256
from collections import deque
d = deque(input())
q = int(input())
reverse = False
for _ in range(q):
    query = list(input().split())
    if query[0] == '1':
        if reverse:
            reverse = False
        else:
            reverse = True
        continue
    else:
        if query[1] == '1':
            if reverse:
                d.append(query[2])
            else:
                d.appendleft(query[2])
        else:
            if reverse:
                d.appendleft(query[2])
            else:
                d.append(query[2])

if reverse:
    d = list(reversed(d))

print(''.join(map(str, d)))


Measured memory_bytes: 8612
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
map<ll, ll> mp;

int main() {
  ll n,p;cin >>n>>p;
  ll val = (ll)pow((double)p,1.0d/(double)n);
  ll out = 1;
  for (ll i = val; i>= 2; --i) {
    if(p<i) break;
    ll dval = (ll)pow((double)i,(double)n);
    if(p%dval == 0){
      out *= i;
      p = p/dval;
    }
  }
  cout << out << endl;
  return 0;
}


Measured memory_bytes: 512
///
// File:  b.cpp
// Author: ymiyamoto
//
// Created on Thu Sep 28 20:38:14 2017
//

#include <cstdint>
#include <iostream>

using namespace std;

struct point_t {
  int32_t x;
  int32_t y;
  point_t(int32_t _x, int32_t _y)
  {
    x = _x;
    y = _y;
  }
};

int32_t main()
{
  int32_t W, H, N;
  cin >> W >> H >> N;

  point_t upper_right(W, H);
  point_t lower_left(0, 0);

  bool all_black = false;
  for (int32_t _ = 0; _ < N; _++) {
    int32_t x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      lower_left.x = max(lower_left.x, x);
    } else if (a == 2) {
      upper_right.x = min(upper_right.x, x);
    } else if (a == 3) {
      lower_left.y = max(lower_left.y, y);
    } else if (a == 4) {
      upper_right.y = min(upper_right.y, y);
    }
    int32_t width = upper_right.x - lower_left.x;
    int32_t height = upper_right.y - lower_left.y;
    if ((width <= 0) || (height <= 0)) {
      all_black = true;
    }
  }

  if (all_black) {
    cout << 0 << endl;
  } else {
    int32_t width = upper_right.x - lower_left.x;
    int32_t height = upper_right.y - lower_left.y;
    cout << width * height << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>

using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912

const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
int main(){
    int N; cin >> N;
    string s;
    int cnt_B_be = 0,cnt_A_en=0,AB=0;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        cin >> s;
        int n = s.size();
        if(s[0] == 'B' && s[n-1] == 'A') AB++;
        else if(s[0] == 'B') cnt_B_be++;
        else if(s[n-1] == 'A') cnt_A_en++;
        for(int j = 0; j < n-1; j++){
            if(s[j] == 'A' && s[j+1] == 'B') cnt++;
        }
    }
    if(AB){
        cnt += (AB-1);
        if(cnt_B_be){
            cnt++;
            cnt_B_be--;
        } 
        if(cnt_A_en){
            cnt++;
            cnt_A_en--;
        }
        cnt += (min(cnt_B_be,cnt_A_en));
    } else {
        cnt += min(cnt_B_be,cnt_A_en);
    }
    cout << cnt << endl;
}



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

using namespace std;

int main()
{
		int a,b,c;
		cin>>a>>b>>c;
		
		if(a==b || b==c || c==a)
		{
			if(a==b && b==c)
			{
				cout<<"No";
			}
			else
			{
				cout<<"Yes";
			}
		}
		else
		{
			cout<<"No";
		}
	return 0;
}

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

int main(){
  int a, b, sum=0;
  string n;
  cin >> a >> b;
  
  for(int i=a; i <= b; i++){
    n = to_string(i);
    if((n[0] == n[4]) && (n[1] == n[3])) sum++;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n ; ++i)
const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int k;
    cin >> k;
    vector<string> vec;
    rep(i,s.size()) {
        for (int j = 1; j <= k; ++j) {
            string temp = s.substr(i, j);
            vec.push_back(temp);
        }
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    cout << vec[k - 1] << endl;
    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

void QA(bool x){
  if(x) cout<<"Yes";
  else cout<<"No";
  return;
}


int main() {
  bool finish=true;
  int N; cin>>N;
  vector<string> S(N);
  rep(i,N) cin>>S.at(i);
  for(int i=1;i<N;i++) if(S.at(i-1).at(S.at(i-1).size()-1)!=S.at(i).at(0))finish=false;
  sort(S.begin(),S.end());
  for(int i=1;i<N;i++) if(S.at(i-1)==S.at(i)) finish=false;
  QA(finish);
}



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

int main(void){
    long long N;cin>>N;
    vector<long long>A(3*N);
    for(long long i=0;i<3*N;i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    long long ans=0;
    for(long long i=3*N-2;i>=N;i-=2){
        ans+=A[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5480
n,d = map(int,input().split())
Dot = [list(map(int,input().split())) for _ in range(n)]
count = 0
for dot in Dot:
    x,y = dot[0],dot[1]
    dist = x*x + y*y
    d2 = d*d
    if dist <= d2:
        count+=1
print(count)


Measured memory_bytes: 45444
import math
def pri(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False

    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            return False
        i += 2
    return True

l=[i for i in range(110000)if pri(i) ]

while True:
    n = int(input())
    if n == 0: break
    print(sum(l[:n]))

Measured memory_bytes: 7228
import sys

N,M = (int(a) for a in input().split())
SC = []
for i in range(M) :
    sc = list(map(int,input().split()))
    SC.append(sc)

for j in range(1000) :
    num = list(str(j))
    if N == len(num) :
        check = 0
        for k in range(M) :
            if int(num[SC[k][0]-1]) == SC[k][1] :
                check += 1
        if check == M :
            print(j)
            sys.exit()
print(-1) 




Measured memory_bytes: 9184
import sys
n,k=map(int,input().split())
A=[]
tmp=k
for i in range(n):
    a,b=map(int,input().split())
    A.append([a,b])
A.sort(key=lambda x:x[0])
for i in range(n):
    tmp-=A[i][1]
    if tmp<=0:
        print(A[i][0])
        sys.exit()

Measured memory_bytes: 21248
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int N; cin >> N;
  int x[N], y[N];
  rep(i, N){
    cin >> x[i] >> y[i];
  }
  double ans = 0;
  rep(i, N){
    rep(j, N){
      ans += (double) sqrt((pow)(x[i]-x[j], 2)+ (pow)(y[i]-y[j], 2));
    }
  }
  ans /= N;
  printf("%.12lf\n", ans);
}     

Measured memory_bytes: 256
#回数, 味の素ち?を入力
n, l = gets.split.map(&:to_i)
#taste_list = 味の配列, この中の最小値のリンゴを食べる
taste_list = Array.new
taste_list2 = Array.new
injecter = 0
for i in 1..n do
  #味 = i + l -1
  taste = i + l -1
  taste_list.push(taste.abs)
  taste_list2.push(taste)
end
#print(taste_list, "\n")
a = taste_list.index(taste_list.min)
taste_list.delete_at(a)
taste_list2.delete_at(a)
p taste_list2.inject(:+)

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

typedef long long ll;

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

  int n;
  cin >> n;

  string ans = "No";
  if (n < 10){
    ans = "Yes";
  }else {
    for(int i = 2; i < 10; i++){
      if (n % i == 0 && n / i < 10){
        ans = "Yes";
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    int ans = 1;
    while (ans * (ans + 1) / 2 < n) ans++;
    int max = ans * (ans + 1) / 2;
    for (int i = 1; i <= ans; i++)
        if (i != max - n) cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iomanip>
#include <cmath>
#include <iostream>
using namespace std;
typedef struct { int x, y, r; } bar;

bar ps[1002];

double cost(int i, int j) {
    double dx = ps[i].x - ps[j].x, dy = ps[i].y - ps[j].y;
    return max(0e0, sqrt(dx * dx + dy * dy) - ps[i].r - ps[j].r);
}

int main() {
    int x, y, r, n;
    double d[1002];
    cin >> x >> y; ps[0] = { x, y, 0 };
    cin >> x >> y; ps[1] = { x, y, 0 };
    cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y >> r; ps[i+2] = { x, y, r}; }
    d[0] = 0;
    fill(d+1, d+n+2, 1e10);
    bool used[1002] = {};
    while (true) {
        int v = -1;
        for (int i = 0; i <= n+1; i++)
            if (!used[i] && (v == -1 || d[v] > d[i])) v = i;
        if (v == -1) break;
        used[v] = true;
        for (int i = 1; i <= n+1; i++)
            d[i] = min(d[i], d[v] + cost(i, v));
    }
    cout << setprecision(12) << d[1] << endl;
}


Measured memory_bytes: 256
#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;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n,k;
vector<int> v(100100,inf);
int main(){
    cin>>n>>k;
    vector<int> h(n,0);
    rep(i,n) cin>>h[i];
    v[0]=0;
    rep(i,n-1){
        for(int j = 1;j <= k; j++){
            if(i+j<n){
                v[i+j]=min(v[i+j],v[i]+abs(h[i+j]-h[i]));
            }
        }
    }
    cout<<v[n-1]<<endl;
    return 0;
}

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

int main(){
int n;
cin >> n;
vector<int> vec(n);
for(int i=0;i<n;i++){
cin >> vec.at(i);
}

int sum=0;

for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
sum += vec.at(i)*vec.at(j);
}
}

cout << sum << endl;
return 0;
}




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

int main() {
	int n; scanf("%d", &n);
	map<string, int> s_map;
	for (int i = 0; i < n; ++i) {
		string s; cin >> s;
		++s_map[s];
	}

	int m; scanf("%d", &m);
	map<string, int> t_map;
	for (int i = 0; i < m; ++i) {
		string t; cin >> t;
		++t_map[t];
	}

	int ans = 0;
	for (auto sm_itr = s_map.begin(); sm_itr != s_map.end(); ++sm_itr) {
		string blue_str = sm_itr->first;
		int str_cnt = sm_itr->second;
		int diff = str_cnt - t_map[blue_str];
		ans = max(ans, diff);
	}
	
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int c[9],a[2],b[2],repro[9],tmp,flg;
void verif_a(int diff,int start){
  for(int i=0;i<2;++i){
    if(diff!=c[start+i]-c[start+i+3]){
      flg=1;
    }
  }
}
void verif_b(int diff,int start){
  for(int i=0;i<2;++i){
    if(diff!=c[start+(3*i)]-c[start+(3*i)+1]){
      flg=1;
    }
  }
}

int main(){
  for(int i=0;i<9;++i){
    scanf("%d",&tmp);
    c[i]=tmp;
  }
  a[0]=c[0]-c[3];
  a[1]=c[3]-c[6];
  verif_a(a[0],1);
  verif_a(a[1],4);

  b[0]=c[0]-c[1];
  b[1]=c[1]-c[2];
  verif_b(b[0],3);
  verif_b(b[1],4);

  flg!=0 ? puts("No"):puts("Yes");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}
int main(){
init();
long long t,tp,a,ap;
cin>>t>>tp>>a>>ap;
while(t>=0||a>=0){
            a=a-tp;
            if(a<=0){
                break;
            }
    t=t-ap;
}
if(t>0)
cout<<"Yes";
else cout<<"No";
}


Measured memory_bytes: 3640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans = 1;
  
  sort(all(a));
  reverse(all(a));
  int top = a[0];
  //rep(i,n) dunk(a[i]);
  //dunk(a[1]);
  //dunk(top);
  for(int i = 1; i < n; i++){
    if( a[i] < top){
      //dunk(a[i]);
      top = a[i];
      ans++;
      //dunk(ans);
      //dunk(top);
    }
  }
  dunk(ans);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		long ans = 0;

		long anti_c = (long)(b/c) - (long)((a-1)/c);
		long anti_d = (long)(b/d) - (long)((a-1)/d);

		if(c==d) {
				System.out.println(b-a+1-anti_c);
				return;
		}

		long cd = c*d/gcd(c,d);
		long anti_cd = (long)(b/cd) - (long)((a-1)/cd);

		System.out.println(b-a+1-anti_c-anti_d+anti_cd);

	}

	public static long gcd(long c, long d) {
		long temp=0;
		while(d%c!=0) {
			temp = d%c;
			d = c;
			c = temp;
		}
		return c;
	}

}


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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
    ifstream t("/proc/self/status");
    cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = (int) 2e5;

int n;

int a[MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= n; ++i) a[i] = read<int>() - i;
}

inline void solve()
{
	sort(a + 1, a + n + 1);

	int mid = (n + 1) / 2;
	LL ans = 0;
	for(int i = 1; i <= n; ++i) ans += abs(a[i] - a[mid]);
	printf("%lld\n", ans);
}

int main()
{
//#ifndef ONLINE_JUDGE
//	freopen("C.in", "r", stdin);
//	freopen("C.out", "w", stdout);
//#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n,d,x;
    cin>>n>>d>>x;
    
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    rep(i,d){
        rep(j,n){
            if(i%v[j]==0)x++;
        }
    }
    cout<<x<<endl;
}


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

using namespace std;
using ll = long long;

int main() {
    int n = 0;
    cin >> n;
    map<int,int> v;
    bool flag = true;

    for(int i = 0;i < n;i++){
        int tmp = 0;
        cin >> tmp;
        if(v[tmp - 1] == 1){
            flag = false;
            break;
        }
        v[tmp - 1] = 1;
    }

    if(flag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
ll n, q;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> q;
  string s;
  cin >> s;
  vll ac(n + 1);
  for (int i = 1; i < n; i++) {
    ac[i + 1] = ac[i];
    if (s[i] == 'C' && s[i - 1] == 'A') {
      ac[i + 1]++;
    }
  }
  for (int i = 0; i < q; i++) {
    ll l, r;
    cin >> l >> r;
    cout << ac[r] - ac[l] << endl;
  }
  return 0;
}


Measured memory_bytes: 1872
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 int main(){
  string s ; cin>> s ;
  ll k= s.size() ;
  string t ="" ;
  rep(i,k){
   if(s[i]!='x') t+= s[i] ;
  }
  ll z = t.size() ;
  bool ok=1 ;
  rep(i,z/2){
    if(t[i]!=t[z-1-i]) ok= 0 ;
  }
  if(!ok) cout<<-1<<endl ;
  else{
    ll x= z+1 ;
    vector<ll> A(x) ;
    ll j= 0 ;
    rep(i,k){
     if(s[i]=='x') A[j] ++ ;
     else j++ ;
    }
    ll ans=0 ;
    rep(i,x/2){
     ans+= max(A[i],A[x-1-i]) - min(A[i],A[x-1-i]) ;
    }
    cout<<ans<<endl ;
  }
   return 0 ;
 }

Measured memory_bytes: 4284
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String line = br.readLine();
            String[] strArray = new String[2];
            
            while(line.equals("0 0") == false){
            	strArray = line.split("\\s");
            	if(Integer.parseInt(strArray[0]) > Integer.parseInt(strArray[1])){
            		System.out.println(strArray[1] + " " + strArray[0]);
            	}else{
            		System.out.println(strArray[0] + " " + strArray[1]);
            	}
            	
                line = br.readLine();
            }
            br.close();
        } catch (IOException e) {
            System.err.println(e);
        }
    }
}

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

#define Cpy(a, b) memcpy(a, b, sizeof (a))
#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)
#define Travel(i, u) for (int i = beg[u], v = to[i]; i; v = to[i = nex[i]])

using namespace std;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * p;
}

inline void File() {
	freopen("cpp.in", "r", stdin);
	freopen("cpp.out", "w", stdout);
}

const int N = 6e5 + 10;
int e = 1, beg[N], nex[N], to[N], vis[N];
int rt1, rt2, deg[N], used[N], ans[N], n, cur[N];

inline void add(int x, int y) {
	to[++ e] = y, nex[e] = beg[x], beg[x] = e;
	to[++ e] = x, nex[e] = beg[y], beg[y] = e;
}

int sta[N], tp;

inline void dfs1(int u) {
	for (int &i = beg[u], v = to[i]; i; v = to[i = nex[i]]) 
		if (!used[i >> 1]) used[i >> 1] = 1, dfs1(v);
	sta[++ tp] = u;
}

inline void dfs_init(int u, int f) {
	Travel(i, u) if (v ^ f) 
		dfs_init(v, u), deg[u] ^= 1;
	deg[u] ^= 1;
}

int main() {

	n = read();
	For(i, 1, n) {
		int f = read();
		if (f == -1) rt1 = i; else add(i, f);
	}

	For(i, 1, n) {
		int f = read();
		if (f == -1) rt2 = i + n; else add(i + n, f + n);
	}

	dfs_init(rt1, 0), dfs_init(rt2, 0);

	For(i, 1, n) if (deg[i] ^ deg[i + n]) return puts("IMPOSSIBLE"), 0;

	puts("POSSIBLE");

	add(0, rt1), add(0, rt2);

	For(i, 1, n) if (deg[i]) add(i, i + n);

	dfs1(0);
	For(i, 1, n) if (deg[i]) ans[i] = -1;
	For(i, 1, tp - 1) if (sta[i] > 0 && sta[i] <= n && sta[i + 1] == sta[i] + n) ans[sta[i]] = 1;
	For(i, 1, n) printf("%d ", ans[i]); cout << endl;
	return 0;
}


Measured memory_bytes: 22784
#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
    int a,b;
    while(scanf("%d %d",&a,&b)!=EOF)
    {
        if(b%a==0)
            printf("%d\n",a+b);
        else
            printf("%d\n",b-a);
    }


    return 0;
}


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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<int> > c(10, vector<int>(10, 0)), a(H, vector<int>(W, 0));
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            cin >> a[h][w];
        }
    }

    vector<int> min_cost(10, INT_MAX);
    vector<int> start, end;
    min_cost[1] = 0;
    for (int i = 0; i <= 9; i++) {
        if (i != 1) { 
            start.push_back(i);
        }
        min_cost[i] = c[i][1];
    }
    while (end.size() != 9) {
        int min_index = -1, min_value = INT_MAX;
        for (int i : start) {
            if (min_cost[i] < min_value) {
                min_value = min_cost[i];
                min_index = i;
            }
        }

        start.erase(find(start.begin(), start.end(), min_index));
        end.push_back(min_index);
        for (int i : start) {
            min_cost[i] = min(min_cost[i], min_cost[min_index] + c[i][min_index]);
        }
    }

    long long ans = 0;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            if (a[h][w] == -1) {
                continue;
            }
            ans += min_cost[a[h][w]];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
import sys
from collections import Counter
import itertools
import copy

def solve(N: int, D: "List[int]"):
    counter = dict(Counter(D+[0]))
    time = [False]*25
    once = []
    # 枝狩り処理
    for i in range(13): 
        if counter.get(i) == None:
            continue
        if counter[i] == 2:
            if i == 0:
                print(0)
                return
            time[12+i] = True
            time[12-i] = True
        elif counter[i] >= 3: #どう頑張っても時刻のさの最大値は0
            print(0)
            return
        else:
            # if i != 0:
            once.append(i)

    LEN = len(once)
    bit_list = list(itertools.product([0, 1], repeat=LEN))

    if LEN == 0:
        min_dif = 12        
        time = [i for i,t in enumerate(time) if t]
        for first,second in list(itertools.combinations(time,2)):
            min_dif = min(min_dif,min(abs(first-second),24-abs(first-second)))
        print(min_dif)
        return

    answer = 0

    # onceを進んでるか戻ってるかのどちらかに振り分けていく
    for bit in bit_list:
        tmp = copy.deepcopy(time)
        
        for i in range(LEN): # 1なら進んでる0なら戻ってる
            if bit[i] == 1:
                tmp[12+once[i]] = True
            else:
                tmp[12-once[i]] = True

        # Trueのものだけ抜き出す
        tmp = [i for i,t in enumerate(tmp) if t]
        min_dif = 12
        for first,second in list(itertools.combinations(tmp,2)):
            min_dif = min(min_dif,min(abs(first-second),24-abs(first-second)))
        answer = max(min_dif,answer)

    print(answer)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)

if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
  long long n;
  cin >> n;
  string ans = "";
  while (n > 0) {
    --n;
    ans += (n % 26 + 'a');
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll inf = 1000000001;

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

    int n; cin>>n;
    vector<int>a;
    rep(i,n){
        int b; cin>>b;
        a.push_back(b);
    }
    int max = *max_element(all(a));

    int max_cnt = 0;
    rep(i,n){
        if(a[i]==max) max_cnt++;
    }
    if(max_cnt>=2){
        rep(i,n) cout << max << ln;
        return 0;
    }

    int sec_max = 0;
    rep(i,n){
        if(sec_max < a[i] && a[i] != max){
            sec_max = a[i];
        }
    } 

    rep(i,n){
        if(a[i] != max) cout << max << ln;
        else cout << sec_max << ln;
    }
    return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
using T = tuple<int, int, int, int>;

map<T, int> dp;
char is[20][20];
int H, W;

int find(int I, int J, int K, int L) {
	if (I == J || K == L) {
		return 0;
	}
	if (dp[make_tuple(I, J, K, L)]) {
		return dp[make_tuple(I, J, K, L)] - 1;
	}
	vector<int> ko;
	for (int i = I; i < J; i++) {
		for (int j = K; j < L; j++) {
			if (is[i][j] == '.') {
				ko.push_back(find(I, i, K, j) ^ find(i + 1, J, K, j) ^ find(I, i, j + 1, L) ^ find(i + 1, J, j + 1, L));
			}
		}
	}
	sort(ko.begin(), ko.end());
	ko.erase(unique(ko.begin(), ko.end()), ko.end());
	int res = 0;
	while (res < (int)ko.size() && ko[res] == res) {
		res++;
	}
	dp[make_tuple(I, J, K, L)] = res + 1;
	return res;
}

int main()
{
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> is[i][j];
		}
	}
	cout << (find(0, H, 0, W) ? "First" : "Second") << endl;
	return 0;
}

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


int main(void){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1;i<=n;i++){
        int j = n-i;
        if(i>=j){
            break;
        }
        else{
            ans++;
        }
    }
    cout << ans <<endl;
    
    
    return 0;
}





























































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

#define BLANK 0
#define STORE 1
#define CHARGER 2

int main()
{
  int n;
  char s,t,b;

  cout<<setprecision(8);
  cout<<setiosflags(ios::fixed);

  while(cin>>n,n){
    int room[3+2][3+2]={0};
    double dp[16][3+2][3+2]={0};
    int dx[4]={-1,1,0,0};
    int dy[4]={0,0,-1,1};
    int i,j,y,x;

    cin>>s>>t>>b;
    s-='A';
    t-='A';
    b-='A';
    for(i=0;i<3+2;i++){
      room[0][i]=STORE;
      room[i][0]=STORE;
      room[3+2-1][i]=STORE;
      room[i][3+2-1]=STORE;
    }
    room[(t/3)+1][(t%3)+1]=CHARGER;
    room[(b/3)+1][(b%3)+1]=STORE;
    dp[0][(s/3)+1][(s%3)+1]=1.0;

    for(i=1;i<=n;i++){
      for(y=1;y<=3;y++){
	for(x=1;x<=3;x++){
	  for(j=0;j<4;j++){
	    int yy=y+dy[j],xx=x+dx[j];
	    if(room[yy][xx]==STORE){yy=y;xx=x;}
	    dp[i][yy][xx]+=dp[i-1][y][x]/4.0;
	  }
	}
      }
    }
    cout<<dp[n][(t/3)+1][(t%3)+1]<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    string n;
    cin >> n;
    
    ll ans = 0;
    for (int i = 0; i < n.size(); i++) {
        ans += n[i] - '0';
    }

    ll res = 0;
    res = n[0] - '0' + 9 * (n.size()-1) -1;

    ans = max(ans , res);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596