akhauriyash/Code-Regression huggingface dataset:
///God is great

#include <bits/stdc++.h>
using namespace std;

/************************** definations *******************************/
#define pi              2*acos(0.0)
#define ll              long long int
#define llu             unsigned long long int
#define sc(a)           scanf("%d",&a)
#define scc(a,b)        scanf("%d %d",&a,&b)
#define sccc(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define sc1(a)          scanf("%lld",&a)
#define sc2(a,b)        scanf("%lld %lld",&a,&b)
#define sc3(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define sc4(a,b,c,d)    scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define pf1(a)          printf("%lld\n",a)
#define pf2(a,b)        printf("%lld %lld\n",a,b)
#define Case(a)         printf("Case %d: ",a)
#define Casel(a)        printf("Case %lld: ",a)
#define mem(a,x)        memset(a,x,sizeof(a))
#define INF             1<<29
#define Inf             10000
#define inf             INT_MAX
#define INFL            1e18
#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair
#define NL              cout << endl;
#define DONE            cerr << "Done" << endl
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << endl
#define READ            freopen("input.txt", "r", stdin)
#define WRITE           freopen("output.txt", "w", stdout)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pii             pair<int,int>
#define ii              pair<ll,int>
#define M               10000007
#define mod             100000007
#define Mod             1000000007
#define MAX             1001
#define qk              5000000
#define REP(i,x,m)      for(i=x;i<m;i++)
#define vi              vector<int>
/************************** definations *******************************/
int main()
{
    /*#ifndef ONLINE_JUDGE
    READ;
    WRITE;
    #endif*/
    int a,b,c;
    sccc(a,b,c);
    printf("%d %d %d",c,a,b);
}

Measured memory_bytes: 256
// めんどくさかったのでコピペAC
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef pair<int, int> P;
#define INF 1e9 + 7

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

    ll N;
    cin >> N;
    string ans = "";
    ll time   = 1;
    while (N != 0) {
        if (N % (time * 2) == 0) {
            ans = "0" + ans;
        } else {
            ans = "1" + ans;
            N -= time;
        }
        time *= -2;
    }
    if (ans.empty())
        ans = "0";
    cout << ans << endl;

    return 0;
}

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

int chk(int n)
{
	int cnt = 0;
	while (n % 100 == 0) {
		n /= 100;
		++cnt;
	}
	return cnt;
}

int main()
{
	int d, n;
	cin >> d >> n;
	int start =(int)pow(100, d);
	int cnt = 0;
	int ans = 0;
	for (int i = start;; i++) {
		if (chk(i) == d)
			cnt++;
		if (cnt == n) {
			ans = i;
			break;
		}

	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	N, A, B, C = NMI()
	L = [NI() for _ in range(N)]

	def dfs(bamboo, a, b, c):
		if bamboo == N:
			if a*b*c == 0:
				return 10**100
			a, b, c = sorted([a, b, c], reverse=True)
			res = abs(A-a) + abs(B-b) + abs(C-c)
			return res

		res = 10**100

		res = min(res, dfs(bamboo + 1, a + L[bamboo], b, c) + 10) if a > 0 else min(res, dfs(bamboo + 1, a + L[bamboo], b, c))
		res = min(res, dfs(bamboo + 1, a, b + L[bamboo], c) + 10) if b > 0 else min(res, dfs(bamboo + 1, a, b + L[bamboo], c))
		res = min(res, dfs(bamboo + 1, a, b, c + L[bamboo]) + 10) if c > 0 else min(res, dfs(bamboo + 1, a, b, c + L[bamboo]))
		res = min(res, dfs(bamboo + 1, a, b, c))
		return res

	print(dfs(0, 0, 0, 0))



if __name__ == "__main__":
	main()

Measured memory_bytes: 3316
import math

A, B, H, M = map(int, input().split())
Mth = 6*M
Hth = 30*H + M/2
th = math.pi*abs(Mth-Hth)/180

x = A**2+B**2-2*A*B*math.cos(th)
result = math.sqrt(x)
print(result)

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



int main()
{
    int hit[4]={},blow[4]={};
    while(cin>>hit[0]){
        int ans1=0,ans2=0;
        for(int i=1; i<4; i++){
            cin>>hit[i];
        }
        for(int i=0; i<4; i++){
            cin>>blow[i];
        }
        for(int i=0; i<4; i++){
            for(int j=0; j<4; j++){
                if(hit[i]==blow[j]){
                    (i==j)?ans1++:ans2++;
                }
            }
        }
        cout<<ans1<<" "<<ans2<<endl;
    }
    return 0;
}

Measured memory_bytes: 3076
#include<stdio.h>
int main()
{
  int n,x[400],y[400],i,m,j,k,x1,y1,l,t;
  char d;
  while(1){
    x1=10;
    y1=10;
    t=0;
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      scanf("%d%d",&x[i],&y[i]);
    }
    scanf("%d",&m);
    for(j=0;j<m;j++){
      scanf("%c",&d);
      scanf("%c",&d);
      scanf("%d",&l);

      for(k=0;k<l;k++){
	if(d=='N'){y1=y1+1;}
	else if(d=='E'){x1=x1+1;}
	else if(d=='S'){y1=y1-1;}
	else if(d=='W'){x1=x1-1;}


	for(i=0;i<n;i++){
	  if(x[i]==x1&&y[i]==y1){
	    t=t+1;
	    x[i]=-100;
	    y[i]=-100;
	}
      }	
    
  
      }
     
     
    }
    if(t==n){printf("Yes\n");}
    else{printf("No\n");}
  }
  return 0;
  }

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    string S, T; cin >> S >> T;
    if(S.size() < T.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    else {
        string s = S;
        bool judge = false;
        for(int i = S.size() - T.size(); i >= 0; i--) {
            bool can = true;
            for(int j = 0; j < T.size(); j++) {
                if(S[i + j] != T[j] && S[i + j] != '?') {
                    can = false;
                    break;
                }
            }
            if(can) {
                judge = true;
                for(int j = 0; j < S.size(); j++) {
                    if(s[j] == '?') s[j] = 'a';
                }
                for(int j = 0; j < T.size(); j++) {
                    s[i + j] = T[j];
                }
                break;
            }
        }
        if(judge) cout << s << endl;
        else cout << "UNRESTORABLE" << endl;
        return 0;
    }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define modulo 1000000007
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
string s;
ll d,n;
ll dp[100002][101][2];
ll solve(int ind, int sum, int flag){
	if(ind>=n){
		if(!sum)
			return 1;
		return 0;
	}
	if(dp[ind][sum][flag]!=-1)
		return dp[ind][sum][flag];
	int limit=9;
	if(!flag)
		limit=(s[ind]-'0');
	ll res=0;
	for (int i = 0; i <= limit; ++i){
		if(!flag && i==limit)
			res=(res+solve(ind+1,(sum+i)%d,0))%modulo;
		else
			res=(res+solve(ind+1,(sum+i)%d,1))%modulo;
	}
	dp[ind][sum][flag]=res;
	return dp[ind][sum][flag];
}
int main(){
	fast_io;
	cin>>s>>d;
	n=s.length();
	memset(dp,-1,sizeof(dp));
	ll ans=(solve(0,0,0)-1+modulo)%modulo;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 162220
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	ll a,v,b,w,t;
	cin>>a>>v>>b>>w>>t;
	if(a<=b){
		a=a+v*t;
		b=b+w*t;
		if(a>=b){
			cout<<"YES";
		}
		else{
			cout<<"NO";
		}
	}
	else{
		a=a-v*t;
		b=b-w*t;
		if(a<=b){
			cout<<"YES";
		}
		else{
			cout<<"NO";
		}
	}
	
	re 0;
}

Measured memory_bytes: 3620
package main

import (
	"fmt"
	"sort"
)

func main() {
	var Count int
	fmt.Scan(&Count)
	Results, Max := make(map[string]int, Count), 0

	Loop(0, Count, func(i int) {
		var s string
		fmt.Scan(&s)
		v := Results[s]
		Results[s] = v + 1
		Max = max(v+1, Max)
	})

	FinalResults := make([]string, 0, Count)
	for k, v := range Results {
		if v == Max {
			FinalResults = append(FinalResults, k)
		}
	}
	sort.Strings(FinalResults)
	//fmt.Println("###############")
	for _, v := range FinalResults {
		fmt.Println(v)
	}
}

/////////////////////////////////////////

//func readLineInt() []int {
//	result := make([]int, 0)
//	for _, v := range strings.Split(readLine(), " ") {
//		i, _ := strconv.Atoi(v)
//		result = append(result, i)
//	}
//	return result
//}
//
//var reader = bufio.NewReaderSize(os.Stdin, 1e6)
//
//func readLine() string {
//	result := make([]byte, 0, 1e6)
//	for {
//		line, remains, e := reader.ReadLine()
//		if e != nil {
//			panic(e)
//		}
//		result = append(result, line...)
//		if !remains {
//			break
//		}
//	}
//	return string(result)
//}

func Loop(start, end int, f func(i int)) {
	for i := start; i < end; i++ {
		f(i)
	}
}

//
//func min(a ...int) int {
//	result := int(^uint(0) >> 1)
//
//	for _, i := range a {
//		if result > i {
//			result = i
//		}
//	}
//
//	return result
//}
//
func max(a ...int) int {
	result := -int(^uint(0) >> 1)

	for _, i := range a {
		if result < i {
			result = i
		}
	}

	return result
}

Measured memory_bytes: 22400
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();

        int t = 0;
        int x = 0;
        int y = 0;

        for(int i=0; i<N; i++){
            int tmpT = scanner.nextInt();
            int tmpX = scanner.nextInt();
            int tmpY = scanner.nextInt();

            int distance = Math.abs(tmpX - x) + Math.abs(tmpY - y);
            int timeDiff = tmpT - t;

            // 時間
            if(distance <= timeDiff){
                if(distance%2 != timeDiff%2){
                    System.out.println("No");
                    return;
                }
            }else{
                System.out.println("No");
                return;
            }

            // 更新
            t = tmpT;
            x = tmpX;
            y = tmpY;
        }

        System.out.println("Yes");

    }
}


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

#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;

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

  if (S[0] != S[1] || S[0] != S[2] || S[1] != S[2]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

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

int main(void)
{
    int x,n;
    int p[101],sa_pl[101]={},sa_mi[101]={};
    cin >> x >> n;
    for(int i=0;i<n;i++)
    {
        cin >> p[i];
        if(x>=p[i])
        {
            sa_pl[x-p[i]]=1;
        }
        else
        {
            sa_mi[p[i]-x]=1;
        }        
    }
    for(int i=0;i<101;i++)
    {
        if(sa_pl[i]==0)
        {
            cout << x-i << endl;
            return 0;
        }
        else if(i!=0 && sa_mi[i]==0)
        {
            cout << x+i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3632
/*
 © 2020-02-19 19:47:11 crystaalroo All Rights Reserved
*/
#include <bits/stdc++.h>
#define fore(i, a, b) for(int i = (a); i <(b); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
#define sz(x) (int) (x).size()
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long lli;
typedef pair<lli,lli > ii;
#define ENDL '\n'
#define deb(x) cout << #x": " << (x) << endl;
const lli INF=1e14;
const lli mod = 1e6;
const lli N = 1e4;


int main(){_
  int n,k;
  cin>>n>>k;
  vector<int>v(n);
  fore(i,0,n)cin>>v[i];
  sort(all(v));
  bool dp[k+1];
  fore(i,0,k+1)dp[i]=0;
  fore(i,v[0],k+1)
    fore(j,0,n){
      if(i-v[j]<0)break;
      if(dp[i-v[j]]==0)dp[i]=1;
    }
    if(dp[k])cout<<"First"<<ENDL;
    else cout<<"Second"<<ENDL;

}


Measured memory_bytes: 384
n, k = map(int, input().split())
A = list(map(int, input().split()))

A = [a-1 for a in A]

g = [[] for i in range(n)]
for i, a in enumerate(A):
    g[i].append(a)

s = []
visit = [-1]*n
s.append(0)
visit[0] = 0
while s:
    v = s.pop()
    for u in g[v]:
        if visit[u] == -1:
            visit[u] = visit[v]+1
            s.append(u)
        else:
            temp = visit[u]
#print(temp)
#print(visit)
d = max(visit)-temp+1
#print(d)
if k < temp:
    for i in range(n):
        if visit[i] == k:
            print(i+1)
            exit()
else:
    q, r = divmod(k-temp, d)
    for i in range(n):
        if visit[i]-temp == r:
            print(i+1)
            exit()


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

int main(){
    int n;
    cin >> n;
    int w[100];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        sum += w[i];
    }
    int ts = 0;
    int minw = 10001;
    for (int i = 0; i < n; i++) {
        ts += w[i];
        if (abs(sum - ts*2) < minw) {
            minw = abs(sum - ts*2);
        }
    }
    cout << minw << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    char S[200];
    int i, N=0;
    int count=0;

    scanf("%s",S);

    while(S[N] != '\0') N++;

    for(i=0; i<N/2; i++){
        if(S[i] != S[N-i-1]) count++;
    }

    printf("%d\n",count);
    
    return 0;
}

Measured memory_bytes: 128
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim H As Integer = NextInt()
        Dim W As Integer = NextInt()
        Dim S As String() = New String(H - 1) {}
        For i As Integer = 0 To H - 1
            S(i) = NextString()
        Next
        Dim ans As Integer(,) = New Integer(H - 1, W - 1) {}

        For i As Integer = 0 To H - 1
            For j As Integer = 0 To W - 1
                If S(i)(j) = "#" Then
                    ans(i, j) = 9
                    For x As Integer = -1 To 1
                        For y As Integer = -1 To 1
                            If 0 <= i + y AndAlso i + y < H AndAlso
                                0 <= j + x AndAlso j + x < W Then
                                ans(i + y, j + x) += 1
                            End If
                        Next y
                    Next x
                End If
            Next j
        Next i

        For i As Integer = 0 To H - 1
            For j As Integer = 0 To W - 1
                If ans(i, j) >= 9 Then
                    Write("#")
                Else
                    Write(ans(i, j))
                End If
            Next
            WriteLine()
        Next
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 20432
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size
#define se second
#define fe first
#define mper make_pair
#define all(x) x.begin(), x.end()
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define saken string
#define erba continue
#define vl vector<ll>
#define vi vector<int>
#define vli vector <pair <ll, int> >
#define vll vector <pair <ll, ll> >
using namespace std;

ll n, a[110];

int main(){

cin >> n;

for(int i = 1; i <= n; ++i) {
    cin >> a[i];
}

ll ct = 1;

ll ans = 0;

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

    if(a[i] != a[i - 1]) {ans += ct / 2; ct = 1;}
    else {ct++;}

}

ans += ct / 2;

cout << ans;

return 0;
}



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

int main()
{
    string str, str_tail, str_top;
    int h, m;
    while (cin >> str)
    {
        // cout << "str = " << str << endl;
        if (str == "-")
        {
            break;
        }

        cin >> m;
        for (int i = 0; i < m; ++i)
        {
            cin >> h;
            string s1;
            str_top = str.substr(0, h);
            str_tail = str.substr(h, str.length() - h);
            str = str_tail + str_top;
        }
        cout << str << endl;
    }
    return 0;
}


Measured memory_bytes: 3224
def f(num):
    mn = 20000
    for y in c:
        if y > num/2:
            break
        mn = min(mn, yen[y]+yen[num-y])
    return mn

n, m = map(int, input().split())
c = list(map(int, input().split()))
c = sorted(c)
yen = [0 for i in range(n+1)]
yen[1] = 1
for num in range(2, n+1):
    if num in c:
        yen[num] = 1
    else:
        yen[num] = min(yen[num-1]+1,f(num))

print(yen[n])


Measured memory_bytes: 7380
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define For(I,N) for(int I=0;I<N;I++)
#define cinone(N) int N;cin>>N;
#define scanfone(N) int N;cin>>N;
#define cinng(N,M) int N[M];for(int yiuytvnm=0;yiuytvnm<M;yiuytvnm++) cin>>N[yiuytvnm];
#define scanfng(N,M) int N[M];for(int qrwuoiq=0;qrwuoiq<M;qrwuoiq++) scanf("%d",&N[qrwuoiq]);
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
int n;
int a[100005];
int b[100005];
int c[100005];

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n;
	ll s=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
		s+=a[i];
	}
	for(int i=0;i<n;i++)
	{
		scanf("%d",b+i);
		s-=b[i];
	}
	if(s<0) over("-1");
	s=0;
	for(int i=0;i<n;i++)
	{
		c[i]=b[i]-a[i];
		if(c[i]>0) s-=c[i];
	}
	sort(c,c+n);
	int i;
	int res=0;
	if(s<0)
	{
		for(i=0;i<n;i++)
		{
			s-=c[i];
			if(s>=0) break;
		}
		res=i+1;
	}
	else res=0;
	for(int i=0;i<n;i++)
	{
		if(c[i]>0) res++;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (c - (a-b)>0) {
			System.out.println(c - (a-b));
		} else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 21588
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define LINF 1LL<<60
struct edge {
	ll u;
	ll v;
	ll cost;
	edge() {}
	edge(ll u, ll v, ll cost) :u(u), v(v), cost(cost) {}
};
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, M, s, t; cin >> N >> M >> s >> t;
	s--; t--;
	vector<ll> d(N);
	for (int i = 0; i < N;i++) cin >> d[i];
	vector<vector<edge>> G(N);
	for (int i = 0; i < M;i++) {
		ll a, b;cin >> a >> b;
		a--; b--;
		G[a].push_back(edge(a, min(b, t), d[b]));
	}
	for (int i = t; i >= 1;i--) {
		G[i].push_back(edge(i, i - 1, 0));
	}

	vector<ll> dist(N, LINF);
	queue<pair<ll,ll>> q;
	q.push({ s,s });
	dist[s] = 0;
	if (t < s) {
		cout << 0 << endl;
		return 0;
	}
	while (!q.empty()) {
		auto p = q.front(); q.pop();
		ll n = p.first; ll maxn = p.second;
		for (auto e : G[n]) {
			if (e.v < maxn) {
				if (dist[e.v] > dist[e.u]) {
					dist[e.v] = dist[e.u];
					q.push({ e.v, maxn });
				}
			}
			else {
				if (dist[e.v] > dist[e.u] + e.cost) {
					dist[e.v] = dist[e.u] + e.cost;
					q.push({ e.v, max(maxn, e.v) });
				}
			}
		}
	}
	cout << dist[t] << endl;
	return 0;
}

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

using namespace std;

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

int h, w;
vector<string> g;

int bfs() {
	vector<vector<int>> dist(h, vector<int>(w));
	queue<pair<int, int>> que;
	que.emplace(0, 0);

	g[0][0] = '#';
	while (!que.empty()) {
		int x = que.front().second;
		int y = que.front().first;
		que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];

			if (nx < 0 || nx >= w || ny < 0 || ny >= h) {
				continue;
			} else if (g[ny][nx] == '#') {
				continue;
			} else if (nx == w - 1 && ny == h - 1) {
				dist[ny][nx] = dist[y][x] + 1;
				return dist[h - 1][w - 1];
			}

			dist[ny][nx] = dist[y][x] + 1;
			g[ny][nx] = '#';
			que.emplace(ny, nx);
		}
	}

	return dist[h - 1][w - 1];
}

int main() {

	cin >> h >> w;

	g.resize(h);
	for (int i = 0; i < h; i++) {
		cin >> g[i];
	}

	int safe = 0;
	for (auto s : g) {
		for (auto c : s) {
			safe += c == '.';
		}
	}

	int cnt = bfs();
	cout << (cnt == 0 ? -1 : (safe - 1) -cnt) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer a[] = new Integer[n];
		long sum = 0;
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a , Comparator.reverseOrder());

		for(int i = 1 ; i < n ; i++) {
			sum += a[i / 2];
		}

		System.out.println(sum);
		sc.close();

	}
}



Measured memory_bytes: 63564
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  string s;
  cin >> n >> s;

  vll dp(n + 2, 0);
  dp[1] = 1;
  vll csum;
  repLRE(ii, 1, n) {
    vll ndp(n + 2, 0);
    csum.assign(ii + 2, 0);
    rep(i, ii) csum[i + 1] = (dp[i + 1] + csum[i]) % mod;
    repLRE(i, 1, ii + 1) {
      if (s[ii - 1] == '<') {
        ndp[i] = csum[i - 1];
      } else {
        ndp[i] = (csum[ii] - csum[i - 1] + mod) % mod;
      }
    }
    dp = ndp;
  }

  cout << csum[n] << endl;

  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int A = s.indexOf("A");
		int Z = 0;
		for(int i = 0; i < s.length(); i++){
			if(s.charAt(i) == 'Z')
				Z = i;
		}
		System.out.println(Z - A + 1);
	}
}

Measured memory_bytes: 26660
/*
 蟻本 例題 2-1-1　部分和問題 の類題
 ABC 104 C - All Green
 
 問題を解く組み合わせを全部調べるには時間が足りない(ノ)•̥ૅㅁ•̥(ヾ)
 そこで,
 ある難易度の問題を全問解く(or 解かない) + 解き切っていない問題で一番得点の高い問題をいくつか解く
 場合に限って調べる٩(๑❛ᴗ❛๑)۶
 */
// bit全(?)探索
let DG: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
let pc: [[Int]] = (1...DG[0]).map { _ in readLine()!.split(separator: " ").map { Int($0)! }}
var res: Int = 1100 // 問題数は最大で 10 * 100 問

let w: Int = Array(repeating: 2, count: DG[0]).reduce(1, *)  // 各難易度の問題を解き切るかどうかの場合の数

for i in 0..<w {
    var num2 = String(i, radix: 2)  // 2進数へ変換
    num2 = String(repeating: "0", count: DG[0]-num2.count) + num2   // 001 みたいになるように0埋め

    var score: Int = 0
    var count: Int = 0
    var idx0: Int = 0   // 解き切ってない難易度で最大の難易度

    for (j, k) in num2.enumerated() {
        if k=="1" { // 難易度 j+1 の問題を解き切る
            score += 100*(j+1)*pc[j][0] + pc[j][1]
            count += pc[j][0]
        } else {
            idx0 = j    // 難易度 j+1 を解ききらない
        }
    }
    if score >= DG[1] { // 目標達成しているか(・・？)
        res = min(res, count)
    }
    
    // 解き切っていない難易度のうち最高難易度の問題を1問ずつ解く
    for j in 1...pc[idx0][0] {
        score += 100*(idx0+1)
        count += 1
        if j==pc[idx0][0] { score += pc[idx0][1] }  // 解き切ったとき
        if score >= DG[1] { // 目標達成しているか(・・？)
            res = min(res, count)
            break
        }
    }
}
print(res)   // (๑•ૅㅁ•๑)

Measured memory_bytes: 8272
n = input()
i,j = map(int, n.split())
a = []
b = []
c = 0

count = 0
while count < i:
    x = input()
    x = [s for s in map(int, x.split())]
    a.append(x)    
    count += 1

count = 0
while count < j:
    x = input()
    x = [s for s in map(int, x.split())]
    b.append(x)
    count += 1

# print('###################')
for x in range(i):
    for y in range(j):
        c += a[x][y] * b[y][0]
    print(c)
    c = 0




Measured memory_bytes: 5980
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define ll long long

int compare(const void *a, const void *b)
{
  return strcmp((char *)a, (char *)b);
}

int main(void)
{
  int n, m;
  int h[110000];
  int ha[110000] = {0};
  int count = 0;
  int a, b, c, d, i;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++)
  {
    scanf("%d", &h[i]);
    ha[i] = 1;
  }
  for (i = 0; i < m; i++)
  {
    scanf("%d %d", &a, &b);
    if (h[a - 1] < h[b - 1])
    {
      ha[a - 1] = 0;
    }
    else if (h[a - 1] > h[b - 1])
    {
      ha[b - 1] = 0;
    }
    else
    {
      ha[a - 1] = 0;
      ha[b - 1] = 0;
    }
  }
  for (i = 0; i < n; i++)
  {
    if (ha[i])
      count++;
  }

  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>

int main()
{
  char a, b;

  std::cin >> a >> b;

  if ((a == 'H' && b == 'H') ||
      (a == 'D' && b == 'D')) {
      std::cout << "H" << std::endl;
  } else {
      std::cout << "D" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int64_t i = 0;i < n;i++)
using ll = int64_t;
template<class T> bool chmin(T& a,T b){
    if(a > b){ a = b; return true; }else return false;
}
template<class T> bool chmax(T& a,T b){
    if(a < b){ a = b; return true; }else return false;
}


class CColorfulLeaderboard {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);

        vector<int64_t > col(9,0);

        int64_t n;cin >> n;
        rep(i,n){
            int64_t foo;cin >> foo;
            if(foo >= 3200)col[8]++;
            else col[foo / 400]++;
        }

        int64_t mn = 0,mx = 0;

        rep(i,8) mn += (col[i] >= 1);
        mx = mn + col[8];
        if(mn == 0) mn = 1;

        cout << mn << ' ' << mx << '\n';

        //int t;cin >> t;rep(i,t)main2(cin,cout);
	}
	void main2(istream& cin,ostream& cout){

	}
};


int main() {
	CColorfulLeaderboard solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N; cin >> N;
  vector<ll> A(N),B(N);

  for(int i = 0; i < N; i++){
    cin >> A[i] >> B[i];
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  if( N % 2 == 1){
    int mid = N / 2;
    cout << B[mid] - A[mid] + 1 << endl;
  } else { 
    int mid1 = N/2-1;
    int mid2 = N/2;

    ll min_val = (A[mid1] + A[mid2]);
    ll max_val = (B[mid1] + B[mid2]);

    cout << max_val - min_val + 1 << endl;

  }

}


Measured memory_bytes: 6420
def solve(n, a):
    for a_i in a:
        if a_i % 2 == 1:
            continue
        if a_i % 3 != 0 and a_i % 5 != 0:
            print("DENIED")
            return
    print("APPROVED")

if __name__ == "__main__":
    n = int(input().strip())
    a = list(map(int, input().strip().split(" ")))

    solve(n, a)

Measured memory_bytes: 3060
a,b,n = map(int,input().split())
import math
def f(x):
    return math.floor(a*x/b)-a*math.floor(x/b)

if a<= 2 and  b <= 2:
    print(0)
elif a <= b and n >=b:
    print(f(b-1))
elif a<= b and n < b:
    print(f(n))
elif a>b and n >= b:
    print(f(b-1))
elif a>b and n < b:
    print(f(n))

Measured memory_bytes: 9200
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

#define INF 0xc0c0c0c0
#define NINF 0x3f3f3f3f

#define FOR(i, a, b) for((i)=a; i<b; ++(i))
#define EFOR(i, a, b) for((i)=a; i>b; --(i))

#define MLC(n, type) (type*)malloc(n*sizeof(type))
#define CLC(n, type) (type*)calloc(n, sizeof(type))

#define MAXN 200000+1

void solver(int nStrLen, char *pcStr) {
	if (pcStr == NULL) {
		return;
	}

	int i = 0;
	int nLeftBlack = 0;
	int nRightWhite = 0;

	FOR(i, 0, nStrLen) {
		if (pcStr[i] == '.') {
			++nRightWhite;
		}
	}

	int nCount = nRightWhite;
	int nCountTmp = 0;

	FOR(i, 0, nStrLen) {
		if (pcStr[i] == '#') {
			++nLeftBlack;
		}
		else {
			--nRightWhite;
		}

		nCountTmp = nLeftBlack + nRightWhite;

		if (nCountTmp < nCount) {
			nCount = nCountTmp;
		}
	}

	printf("%d\n", nCount);
	return;
}

int main() {
	int i,n;
	char a[MAXN] = {0};

	scanf("%d", &n);

	scanf("%s", a);

	solver(n, a);
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll K,A,B;
	scan(K);scan(A);scan(B);
	if(A>=K) prin(1);
	else{
		ll sa=A-B;
		if(sa<=0) prin(-1);
		else{
			prin(((K-A)/sa+((K-A)%sa!=0))*2+1);
		}
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            var s = ReadLine().Split(' ');
            WriteLine(s[1]+s[0]);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

struct SegmentTree {
    struct Node {
        Node operator*(const Node& o) const {
            return { v + o.v };
        }
        int v;
    };

    SegmentTree(int n) : e({ 0 }), n(n) {
        for (m = 2; m < n; m *= 2);
        t = vector<Node>(m + n + n % 2, e);
    }
    Node& operator[](int i) {
        return t[m + i];
    }
    const Node& root() const {
        return t[1];
    }
    void build() {
        for (int i = (n - 1 + m) / 2; i > 0; i--) {
            t[i] = t[i * 2] * t[i * 2 + 1];
        }
    }
    void update(int i, const Node& o) {
        for (t[i += m] = o; i /= 2, i > 0;) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    Node query(int l, int r) {
        Node o[2] = { e, e };
        for (l += m, r += m; l < r; l /= 2, r /= 2) {
            if (r & 1) o[1] = t[--r] * o[1];
            if (l & 1) o[0] = o[0] * t[l++];
        }
        return o[0] * o[1];
    }
    vector<Node> t;
    const Node e;
    int n, m;
};

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

    int n, q;
    cin >> n >> q;

    SegmentTree st(n);
    for (int i = 0; i < q; i++) {
        int c, x, y;
        cin >> c >> x >> y;
        x--;

        if (c == 0) {
            st.update(x, st[x] * SegmentTree::Node{ y });
        } else {
            cout << st.query(x, y).v << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;


int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    ll x;
    cin >> x;
    //ll n = floor(log10(x/100)/log10(1.01));
    ll n = 100;
    ll count = 0;
    while(1){
        count ++;
        n*=1.01;
        if(n>=x) break;
    }
    cout << count;

}
 

Measured memory_bytes: 3636
#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> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    ll n,k;
    cin >> n >> k;
    priority_queue<pll> pq;
    rep(i,n){
        ll t,d;
        cin >> t >> d;
        --t;
        pq.push(pll(d,t));
    }

    priority_queue<pll,vector<pll>,greater<pll>> used;
    vector<int> cnt(n,0);
    ll c = 0;
    ll res = 0;
    rep(i,k){
        res += pq.top().first;
        if(cnt[pq.top().second] == 0) ++c;
        cnt[pq.top().second] ++;
        used.push(pq.top());
        pq.pop();
    }

    ll ans = res + c * c;

    while(!pq.empty() && !used.empty()){
        bool ok = true;
        while(cnt[pq.top().second]>0){
            pq.pop();
            if(pq.empty()){
                ok = false;
                break;
            }
        }
        while(cnt[used.top().second]==1){
            used.pop();
            if(used.empty()){
                ok = false;
                break;
            }
        }

        if(!ok) break;

        res -= used.top().first;
        cnt[used.top().second] --;
        used.pop();

        res += pq.top().first;
        cnt[pq.top().second] ++;
        pq.pop();

        c++;
        ans = max(ans,res + c * c);
    }

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

Measured memory_bytes: 5232
fun main(arg: Array<String>) {
    val (N, T) = listOfInt()
    val A = listOfInt()
    val M = A.toIntArray()
    for (n in N - 2 downTo 0) {
        if (M[n] <= M[n + 1]) M[n] = M[n + 1]
    }
    var max = 0
    var ans = 0
    for (n in 0 until N - 1) {
        if (A[n] < M[n + 1]) {
            val m = M[n + 1] - A[n]
            if (max == m) ans += 1
            else if (max < m) {
                max = m; ans = 1
            }
        }
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


Measured memory_bytes: 53740
#include <bits/stdc++.h>
#include <stdio.h>
#include <string>
using namespace std;
     
int main() {
    string   S;
    cin >> S;
    string saa = S.substr(0,2);
    string sbb = S.substr(2,2);
  if (saa.substr(0,1) == "0"){
      saa == saa.substr(1,1);
  }
    if (sbb.substr(0,1) == "0"){
      sbb == sbb.substr(1,1);
  }	
  	int aa = atoi(saa.c_str());
  	int bb = atoi(sbb.c_str());
  

  
    if (12 < aa){
        if (bb <= 12 && 0 < bb){
            cout << "YYMM" <<endl;
        }
      else if (bb <= 0){
        cout << "NA" << endl;
      }
        else
        {
            cout << "NA" << endl;
        }
        
    }
    else {
        if (aa != 0) {
            if (bb <= 12 && bb != 0){
                cout << "AMBIGUOUS" <<endl;
            }
            else {
                cout << "MMYY" << endl;
            }
        }
        else {
            if (bb <= 12 && 0 < bb){
                cout << "YYMM" << endl;
            }
            else {
                cout << "NA" << endl;

            }
            
        }
    }  
}

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

using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a))
#define mp make_pair
#define All(a) (a).begin(), (a).end()
template <typename T=long long>
inline T IN(){T x; cin>>x; return(x);}
inline void CIN(){}
template <class Head,class... Tail>
inline void CIN(Head&& head,Tail&&... tail){
    cin>>head;
    CIN(move(tail)...);
}
#define CINT(...) int __VA_ARGS__;CIN(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CIN(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CIN(__VA_ARGS__)
 
typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int,V,greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int N,Q,K;
const int NMAX=1e5;
struct edge{int to; ll cost;};
vector<vector<edge>> G(NMAX);
vector<ll> d(NMAX); 

int main(){
    cin>>N;
    REP(i,N-1){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        G[--a].push_back({--b,c});
        G[b].push_back({a,c});
    }
    cin>>Q>>K;
    d.assign(N+1,LINF);
    d[--K]=0;
    priority_queue<PL, vector<PL>, greater<PL>>gq;
    gq.push({d[K],K});
    while(!gq.empty()){
        PL target=gq.top(); gq.pop();
        ll dt=target.first, t=target.second;
        if(d[t]<dt) continue;
        REP(i,G[t].size()){
            edge e=G[t][i];
            if(d[e.to]>d[t]+e.cost){
                d[e.to]=d[t]+e.cost;
                gq.push({d[e.to],e.to});
            }
        }
    }
    REP(i,Q){
        int x,y;
        scanf("%d%d",&x,&y);
        ll ans=d[--x]+d[--y];
        printf("%lld\n",ans);
    }
    return 0;
}

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

int  main(){

int a=700;
string s;
cin >> s;
if(s[0]=='o'){
	a += 100;
}
if(s[1]=='o'){
	a += 100;
}
if(s[2]=='o'){
	a += 100;
}
cout << a <<endl;


	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func in_range(ss []string, i, j int) bool {
	return i >= 0 && j >= 0 && i < len(ss) && j < len(ss[i])
}

func count(ss []string, i, j int) int {
	cnt := 0
	for y := i - 1; y <= i+1; y++ {
		for x := j - 1; x <= j+1; x++ {
			if in_range(ss, y, x) && ss[y][x] == '#' {
				cnt++
			}
		}
	}
	return cnt
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	ss := make([]string, h)
	for i := range ss {
		fmt.Scan(&ss[i])
	}

	for i := range ss {
		for j := 0; j < len(ss[i]); j++ {
			if ss[i][j] == '#' {
				fmt.Print("#")
			} else {
				fmt.Print(count(ss, i, j))
			}
		}
		fmt.Println("")
	}
}


Measured memory_bytes: 512
#include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int n;
int a, b;
int A, B;

int main(void) {
  while(1) {
    cin >> n;
    if(n == 0) break;

    A = 0;
    B = 0;

    REP(i, 0, n) {
      cin >> a >> b;
      if(a > b) A += a + b;
      if(a < b) B += a + b;
      if(a == b) A += a, B += b;
    }

    cout << A << " " << B << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
a,b = map(int,input().split())
c,d = (a-1)//50, (a-1)%50
e,f = (b-1)//50, (b-1)%50

print(100,100)
res = [['#']*100 for _ in range(50)] + [['.']*100 for _ in range(50)]

# white
for i in range(c):
    for j in range(0,100,2):
        res[i*2][j] = '.'
for i in range(d):
    res[c*2][c%2+i*2] = '.'
# black
for i in range(e):
    for j in range(0,100,2):
        res[99-i*2][j] = '#'
for i in range(f):
    res[99-e*2][e%2+i*2] = '#'

for i in range(100):
    print(''.join(res[i]));


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

ll fx[] = {0, 0, 0, 1, -1, 1, 1, -1, -1};
ll fy[] = {0, 1, -1, 0, 0, 1, -1, -1, +1};
map< ll, bool >mp;
vector<ll>a, b, v;
ll ar[ 2000005 ], br[ 2000005 ], ans[ 200005 ], per[ 2000005 ];

ll bs(ll key, ll n)
{
    ll l = 0, r = n - 1;

    while( l <= r )
    {
        ll m = ( l + r ) / 2;
        if( ar[ m ] >= key )
        {
            r = m-1;
        }
        else
        {
            l = m+1;
        }
    }
    return l;
}

string s[ 8 ] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
int main()
{
    ll n, m, k;
    string ss ;
    cin>>ss ;
    for(int i = 0; i < 8; i++)
    {
        if( ss == s[ i ])
        {
            cout<<8 - i - 1<<"\n";
            return 0;
        }
    }
    return 0;
}
/*7 5
12 444 876 1309 1740 2174 2604
*/


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

int main(){
    int n;
    cin>>n;
    if(n%2==0){
        cout<<0.5<<endl;
    }
    else{
        int x=n/2+1;
        double y=x;
        printf("%lf\n",y/n);
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
const int MAX_V=10000;
int prime[MAX_V+1];
int main(){
  int i,k,n,p,q,v;
  for(i=2;i<=MAX_V;i++){
    prime[i]=1;
  }
  for(i=2;i*i<=MAX_V;i++){
    if(prime[i]){
      for(k=2*i;k<=MAX_V;k+=i){
        prime[k]=0;
      }
    }
  }
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(v=2;v<=n-2;v++){
      int isprime=prime[v]*prime[v+2];
      if(isprime)p=v,q=v+2;
    }
    printf("%d %d\n",p,q);
  }
  return 0;
}

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

int w, h;
int c[50][50];
int dx[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dy[8] = {1, 0, -1, -1, -1, 0, 1, 1};

int dfs(int x, int y) {
  if (x < 0 || y < 0 || x >= w || y >= h) return 0;
  if (c[y][x] == 0) return 0;
  c[y][x] = 0;
  for (int i = 0; i < 8; i++) dfs(x + dx[i], y + dy[i]);
  return 1;
}

int main() {
  while (1) {
    scanf("%d%d", &w, &h);
    if (w == 0) break;
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++) scanf("%d", &c[i][j]);
    int counter = 0;
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++) counter += dfs(j, i);
    printf("%d\n", counter);
  }
}



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

int main(){
    int n, h, w, a, b, ans=0;
    cin >> n >> h >> w;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        if(h<=a && w<=b){
            ans++;
        }
    }
    cout << ans << endl;   
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

//Matrix exponentiation
struct Matrix {
	int n; vector<vector<ll>> v; Matrix() {}
	Matrix(vector<vector<ll>> &_v) : n(_v.size()) { v = move(_v); }
	Matrix(int _n, ll _x) : n(_n), v(n, vector<ll>(n, _x)) {}
	Matrix(int _n) : n(_n), v(n, vector<ll>(n, 0)) {
		for (int i = 0; i < _n; i++) { v[i][i] = 1; }
	}
	vector<ll>& operator[](int idx) { return v[idx]; }

	Matrix operator *(Matrix &rhs) {
		Matrix res(n, 0);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				for (int k = 0; k < n; k++)
					res[i][j] = (res[i][j] + v[i][k] * rhs[k][j]) % mod;
		return move(res);
	}

	Matrix operator ^(ll x) {
		Matrix res(n), a(v);
		for (; x; x >>= 1, a = a * a)
			if (x & 1) { res = res * a; }
		return move(res);
	}
};

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

	ll n, k; cin >> n >> k;
	vector<vector<ll>> v(n, vector<ll>(n, 0));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> v[i][j];

	Matrix M(v);
	M = M ^ (k);
	
	ll ans = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			ans = (ans + M[i][j]) % mod;

	cout << ans << '\n';
}

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

void solve() {

   string s;
   cin >> s;
   if (s == "RSR" || s == "SRS" || s == "RSS" || s == "SSR")
      cout << "1\n";
   else if (s == "RRR")
      cout << "3\n";
   else if (s == "SSS")
      cout << "0\n";
   else
      cout << "2\n";
}

int main() {
#ifndef ONLINE_JUDGE
   freopen("inp.txt", "r", stdin);      freopen("outp.txt", "w", stdout);
#endif
   ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
   solve();


   return 0;
}

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

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

  if (S == "Sunny") {
    cout << "Cloudy" << '\n';
  } else if (S == "Cloudy") {
    cout << "Rainy" << '\n';
  } else {
    cout << "Sunny" << '\n';
  }

}


Measured memory_bytes: 256