akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
	int n, m, ans[100] ={0}, A[100][100], b[100];
	cin >> n >> m;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cin >> A[i][j];
		}
	}
	for(int k=0; k<m; k++){
		cin >> b[k];
	}
	for(int x=0; x<n; x++){
		for(int y=0; y<m; y++){
			ans[x] += A[x][y]*b[y];
		}
	}
	
	for(int z=0; z<n; z++)
		cout << ans[z] << endl;
		
	return 0;
}


Measured memory_bytes: 3104
N = int(input())
s = input()
lp = [0] * N
rp = [0] * N
for i in range(N):
    if i != 0:
        lp[i] = lp[i-1]
        if s[i-1] == 'W':lp[i]+=1
for j in range(N-1,-1,-1):
    if j != N-1:
        rp[j] = rp[j+1]
        if s[j+1] == 'E':rp[j]+=1
g = 9999999999999999
for i in range(N):g=min(g,lp[i]+rp[i])
print(g)

Measured memory_bytes: 17616
def divisors(N):
    res = []
    i = 1
    while i * i <= N:
        if N % i == 0:
            res.append(i)
            if i * i != N:
                res.append(N // i)
        i += 1
    res.sort()
    return res

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    int n,ans=0 ;
    scanf ("%d",&n) ;
    for (int i=0 ; i<n; i++){
        int a[i] ;
        scanf ("%d",&a[i]) ;
        int tmp=0;
        if (i==0){
            ans = a[i] ;
        }        
        while (a[i]%2==0){
            a[i] /= 2 ;
            tmp++ ;
        }
        if (ans>tmp){
            ans = tmp ;
        }
    }
    printf ("%d\n",ans) ;
    return 0 ;
}

Measured memory_bytes: 128
N = int(input())
S = list(input())

# W[-1], E[-1]を許容するため、1つ多く箱を用意
W = [0] * (N + 1)
E = [0] * (N + 1)

# W, Eの累積和を算出
for i in range(N):
    if S[i] == "W":
        W[i] += W[i-1] + 1
        E[i] += E[i-1]
    else:
        W[i] += W[i-1]
        E[i] += E[i-1] + 1

# リーダーを左から1つずつずらした場合の向きを変える人の数を総当たり
ans = 3 * 10 **5
for i in range(N):
    # ①i番目のリーダーよりも左に位置し、WESTを向いている人の数
    change_west_to_east = W[i-1]
    # ②i番目のリーダーよりも右に位置し、EASTを向いている人の数
    change_east_to_west = E[N-1] - E[i]
    # 向きを変える必要があるのは①と②の和
    change = change_east_to_west + change_west_to_east
    # changeが最小値の場合、答えを更新
    ans = min(ans, change)

print(ans)


Measured memory_bytes: 29176
#include <iostream>
#include <vector>


using namespace std;

int main(){
	int n;
	cin>>n;	
	vector<int> v(n);
	int sum = 0;
	for(int i = 0; i < n; i++){
		cin>>v[i];
		sum += v[i];
	}
	int m;
	cin>>m;
	for(int i = 0; i < m; i++){
		int p, x;
		cin>>p>>x;
		p--;
		int ans = sum;
		ans -= v[p];
		ans += x;
		cout<<ans<<endl;
	}
}

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

int main() {
  string c;
  cin >> c;
  
  if(c=="a" || c=="i" || c=="u" || c=="e" || c=="o"){
    cout << "vowel" <<  endl;
  }
  
  else{
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
const int inf=0x7fffffff;
const int mod=1e9+7;
const int eps=1e-6;
typedef long long ll;
typedef unsigned long long ull;
#define ls p<<1
#define rs p<<1|1
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
int st[N][N];
signed main()
{
    IOS;
    string s;
    cin>>s;
    if(s[0]!=s[1]&&s[2]==s[3]&&s[4]==s[5])
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
}


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

int main () {
  long long N,M;
  string S,T;
  cin >> N >> M >> S >> T;
  long long n = N;
  long long m = M;
  long long ans1 = 1;
  
  for (long long i = 2; i <= min(N,M); i++) {
    if (n % i == 0 && m % i == 0){
      for (int j = 0; j < 20; j++) {
        if (n % i == 0 && m % i == 0){
          n /= i;
          m /= i;
          ans1 *= i;
        }
        else {
          break;
        }
      }
    }
    if (n == 1 || m == 1){
      break;
    }
  }
  
  long long ans2 = N * M / ans1;
  long long A = ans2 / M;
  long long B = ans2 / N;
  
  for (int i = 0; i < ans1; i++) {
    if (S.at(i*A) != T.at(i*B)){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans2 << endl;
}
          
    

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N;
  A = 0;
  
  for (int i = 0; i <= N; i++) {
     for (int j = 0; j <= N; j++) {
        if (4 * i + 7 * j == N) {
          cout << "Yes";
          A = 1;
          break;
        }
     }
     if (A == 1){
       break;
     }
  }
  if (A == 0)
      cout << "No";
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
        int N,T,i,m=0,cost;
        scanf("%d %d",&N,&T);
        int c[N],t[N];
 
        for (i=0;i<N;i++)
                scanf("%d %d",&c[i],&t[i]);
 
        cost = c[0];
        for (i=0;i<N;i++)
                if ((t[i]<=T)&&(c[i]<=cost)){
                        cost = c[i];
                        m++;
        }
 
        if (m==0)printf("TLE\n");
        else printf("%d\n",cost);
 
        return 0;
}

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

using namespace std;

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	
	for (int i = 0; i < m; i++) {
		int x;
		scanf("%d", &x);
		n -= x;
	}
	
	if (n < 0) n = -1;
	
	printf("%d\n", n);
}


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

int main()
{
	string s;
	cin >> s;
	ll tot=0LL;
	for(ll i=0;i<(ll)s.size();i++)
	{
		tot+=(s[i]-'0');
	}
	if(tot%9LL)
	{
		cout << "No";
	}
	else
	{
		cout << "Yes";
	}
}

Measured memory_bytes: 3728
from collections import Counter
n = int(input())
lst = [0]*n
for i in range(n):
    s = input()
    lst[i] = s

c = Counter(lst)
max_num = max(c.values())
most_lst = sorted([k for k, v in c.items() if v == max_num])
for x in most_lst:
    print(x)

Measured memory_bytes: 35560
N = int(input())
P = list(map(int,input().split()))
Q = list(range(1,N+1))
w = 0
for i in range(N):
    if P[i] != Q[i]:
        w += 1
if w == 2 or w == 0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
s = input()

a = []
pnt = 0
num = 0

for i in range(len(s)):
    if i==0:
        num = 1
    elif s[i]!=s[i-1]:
        a.append(num)
        num = 1
    else:
        num += 1
else:
    a.append(num)
# print(a) #連続で続いている文字数を数えている


ans = [0] * len(s)
idx = 0

for i in range(len(a)//2):
    idx += a[2*i]
    ans[idx] += a[2*i]//2
    ans[idx-1] += a[2*i]//2 + (a[2*i]%2)
    ans[idx-1] += a[2*i+1]//2
    ans[idx] += a[2*i+1]//2 + (a[2*i+1]%2)
    idx += a[2*i+1]

for i in range(len(ans)):
    if i==len(ans)-1:
        print(ans[i])
    else:
        print(ans[i],end=' ')

Measured memory_bytes: 5616
#include<algorithm>
#include<functional>
#include<cstdio>

int main(void){
	int n, a, b, c[110]={0}, i;
	scanf("%d%d%d", &n, &a, &b);
	for(i=0; i<=n; ++i){ scanf("%d", c+i); }
	std::sort(c+1, c+1+n, std::greater<int>());
	for(i=1; (i<=n)&&((double)(c[0]+c[i])/(a+b)>(double)c[0]/a); c[0]+=c[i], a+=b, ++i);
	printf("%d\n", c[0]/a);
	return(0);
}


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

int main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
 
  for (int i = 0; i < N-1; i++) {
    if ((S.at(i) == 'A') && (S.at(i+1)) == 'C') {
      S.at(i) = 'a';
    }
  }
  
  //cout << S.at(0) << endl;
  
  vector<int> a_sum(N+1);
  int n = 0;
  a_sum.at(0) = 0;
  
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'a') {
      n += 1;
      a_sum.at(i+1) = n;
    }
    else {
      a_sum.at(i+1) = n;
    }
  }
  
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << a_sum.at(r-1) - a_sum.at(l-1) << endl;
  }
}

    

Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define ll long long
#define PI 3.1415926535897932384626433832795l
#define MAX_NUM 1000000000
using namespace std;
template <typename T> inline T __lcm(T a,T b)
{
    return (a*b)/__gcd(a,b);
}

ll h[1000000];
ll dp[1000000];
ll n;
ll fun(ll i)
{
    if(i>=n)
    {
        return MAX_NUM;
    }
    if(i==n-1)
    {
        return 0;
    }
    if(dp[i]!=-1)
    {
        return dp[i];
    }
    return dp[i]=min(fabs(h[i]-h[i+1])+fun(i+1),fabs(h[i]-h[i+2])+fun(i+2));
}

int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    memset(dp,-1,sizeof(dp[0])*1000000);
    ll ans=fun(0);
    printf("%lld\n",ans);
}

Measured memory_bytes: 12800
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;
int main ()
{
     long long a[200050],sum = 0;
     int i, n, k;
     cin >> n >> k;
     for(i = 0;i < n;i++)
     {
         cin  >> a[i];
     }
     if(k >= n)
     {
         cout  << 0 <<endl;
         return 0;
     }
     else
     {
         sort (a,a+n);
         for(i = 0;i < n-k;i++)
         {
             sum += a[i];
         }
         cout << sum <<endl;
     }
     return 0;


}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;
typedef long long ll;
#define rep(a, n) for (int i = a; i < n;i++)

ll gcd(ll n1, ll n2)
{
    return n2 == 0 ? n1 : gcd(n2, n1 % n2);
}

int main(){
    ll N, ans = 0;
    cin >> N;
    vector<ll> A(N), R(N+1), L(N+1);
    rep(0, N) cin >> A[i];
    L[1] = A[0], R[N - 1] = A[N - 1];

    rep(0,N-1){
        L[i + 2] = gcd(A[i + 1], L[i + 1]);
        R[N - 2 - i] = gcd(R[N - i - 1], A[N - 2 - i]);
    }
    L[0] = R[N-1],R[N] = L[1];
    rep(0,N){
        ans = max(ans, gcd(L[i], R[i + 1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, h;
    cin >> N;
    vector<int> Hs(N);
    for(int i = 0; i < N; ++i){
        cin >> h;
        Hs[i] = h;
    }
    int table[N];
    table[0] = 0;
    table[1] = abs(Hs[1]-Hs[0]);
    int tmp[2];
   
    for(int i = 2; i < N; ++i){
        for(int j = 0; j < 2; ++j){
            tmp[j] = table[i-j-1] + abs(Hs[i] - Hs[i-j-1]);
        }
        table[i] = min(tmp[0], tmp[1]);
    }
    cout << table[N-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>


using namespace std;

int main() {


	int M, N;
	cin >> M >> N;
	if (N == M) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;


}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

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

    vector<vector<int>> table(10,vector<int>(10));
    int t,l;
    for(int i=1;i<=N;i++){
        l=i%10;
        t=i;
        while(t>=10){
            t/=10;
        }

        table[t][l]++;
    }
/*
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cout<<table[i][j]<<" ";
        }
        cout<<endl;
    }
    //*/

    ll ans=0;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            ans+=table[i][j]*table[j][i];
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3612
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long x=0;
		int count=0;
		while(h>0) {
			h/=2;
			count++;
		}
		for(int i=0;i<count;i++) {
			x+=Math.pow(2, i);
		}

		  		System.out.print(x);

	}
}

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

int main() {
	long long i,j,r,g,b,k;
	cin>>r>>g>>b;
	cin>>k;
	int k1=0;
	while(g<=r)
	{
	    g*=2;
	    k1++;
	}
	if(k1>k)
	
	{
	    cout<<"No";
	    return 0;
	}
	while(b<=g)
	{
	    b*=2;
	    k1++;
	}
	if(k1>k)
	
	{
	    cout<<"No";
	    return 0;
	}
	cout<<"Yes";
	
	
}


Measured memory_bytes: 3600
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
using namespace std;
int main(){
	
	long long s=0;
	int n;
	
	for(int i=0;i<10;i++){
		cin>>n;
		s+=n;
	}
	
	cout<<s<<endl;



}

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

using namespace std;
#define ll long long

ll INF = 1e9 + 7;
const int N = 1e6 + 5;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;

    vector<int>len(n);
    int res = 0;
    for(int i=0;i<n;i++) cin>>len[i];

    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            for(int k=j+1;k<n;k++)
            {
                vector<int> arr{len[i],len[j],len[k]};
                sort(arr.begin(), arr.end());

                if((arr[2] > arr[1]) && ( arr[1] > arr[0]) && ( arr[2] < arr[0] + arr[1]))
                    res++;
            }

    cout<<res<<endl;
}


Measured memory_bytes: 3652
S = input()
al=[chr(ord('a') + i) for i in range(26)]

if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

if len(S) != 26:
    check =[[0] * 2 for _ in range(26)]
    for i in range(len(S)):
        for a in range(26):
            if S[i] == al[a]:
                check[a][0] = 1
                check[a][1] = i
    for i in range(26):
        if check[i][0] == 0:
            used_al = al[i]
            break
    print(S + used_al)
    exit()
ans = ""
lst = []
for i in range(24, -1, -1):
    if S[i] > S[i+1]:
        lst.append(S[i+1])
    else:
        lst.append(S[i+1])
        tmp = S[i]
        lst.append(S[i])
        ans += S[:i]
        lst.sort()
        for j in range(len(lst)):
            if tmp == lst[j]:
                ans += lst[j+1]
                break
        print(ans)
        exit()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<vector<int> > vec(N,vector<int>(3));
    rep(i,N){
        cin >> vec[i][0];
        cin >> vec[i][1];
        cin >> vec[i][2];
    }
    int ans_x;
    int ans_y;
    int ans_h;
    int h;
    rep(i,101){
        rep(j,101){
            rep(k,N){
                if (vec[k][2] != 0){
                    h = max(i - vec[k][0], vec[k][0] - i) + max(j - vec[k][1], vec[k][1] - j) + vec[k][2];
                    break;
                }
            }
            bool ans = true;
            rep(k,N){
                if (max(i - vec[k][0], vec[k][0] - i) + max(j - vec[k][1], vec[k][1] - j) + vec[k][2] != h){
                    if (h - max(i - vec[k][0], vec[k][0] - i) - max(j - vec[k][1], vec[k][1] - j) <= 0 && vec[k][2] == 0){
                        continue;
                    }
                    else{
                        ans = false;
                    }
                }
            }
            if (ans){
                ans_x = i;
                ans_y = j;
                ans_h = h;
                break;
            }
        }
    }
    cout << ans_x << " " << ans_y << " " << ans_h << endl;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 2818.cc: Imagawayaki Man
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10000;

/* typedef */

/* global variables */

int ps[MAX_N][2], q0s[MAX_N][2], q1s[MAX_N][2];
int as[MAX_N];

/* subroutines */

void readpos(int n, int st, int qs[][2]) {
  memset(ps, -1, sizeof(ps));
  ps[0][0] = st;

  int maxd1 = 0, maxd2 = 0;
  for (int i = 0; i < n; i++)
    if (i != st) {
      printf("? %d %d\n", st + 1, i + 1);
      fflush(stdout);

      int d;
      scanf("%d", &d);

      if (ps[d][0] < 0) {
	ps[d][0] = i;
	if (maxd1 < d) maxd1 = d;
      }
      else {
	ps[d][1] = i;
	if (maxd2 < d) maxd2 = d;
      }
    }

  qs[st][0] = maxd2;
  qs[st][1] = -1;
  for (int d = 1; d <= maxd2; d++)
    for (int j = 0; j < 2; j++) {
      qs[ps[d][j]][0] = maxd2 - d;
      qs[ps[d][j]][1] = maxd2 + d;
    }
  for (int d = maxd2 + 1; d <= maxd1; d++) {
    qs[ps[d][0]][0] = maxd2 + d;
    qs[ps[d][0]][1] = -1;
  }
  //fprintf(stderr, "maxd1=%d, maxd2=%d\n", maxd1, maxd2);
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  readpos(n, 0, q0s);
  readpos(n, 1, q1s);

  if (q0s[0][0] != q1s[0][0] && q0s[0][0] != q1s[0][1])
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 2; j++)
	if (q1s[i][j] >= 0) q1s[i][j] = n - 1 - q1s[i][j];

  //for (int i = 0; i < n; i++)
  //fprintf(stderr, "(%d,%d)", q0s[i][0], q0s[i][1]);
  //fputc('\n', stderr);
  //for (int i = 0; i < n; i++)
  //fprintf(stderr, "(%d,%d)", q1s[i][0], q1s[i][1]);
  //fputc('\n', stderr);

  for (int i = 0; i < n; i++) {
    int k = 
      (q0s[i][0] == q1s[i][0] || q0s[i][1] == q1s[i][0]) ?
      q1s[i][0] : q1s[i][1];
    as[k] = i;
  }

  putchar('!');
  for (int i = 0; i < n; i++) printf(" %d", as[i] + 1);
  putchar('\n');
  fflush(stdout);

  return 0;
}



Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) throws Exception {
	    Scanner sc = new Scanner(System.in);   
	    
	    if (sc.nextInt() + sc.nextInt() >= sc.nextInt()) {
	    	System.out.println("Yes");
	    } else {
	    	System.out.println("No");
	    }
	}    
}	

Measured memory_bytes: 22612
//=================================
// Created on: 2018/07/03 03:45:40
//=================================
#include <bits/stdc++.h>
using namespace std;
int main()
{
    for (int W, H;;) {
        cin >> W >> H;
        if (W == 0 and H == 0) { break; }
        vector<vector<int>> f(H, vector<int>(W, 0));
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                char c;
                cin >> c, f[i][j] = c == '.' ? 0 : c == 'B' ? 1 : 2;
            }
        }
        int wans = 0, bans = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (f[i][j] != 0) { continue; }
                vector<vector<bool>> used(H, vector<bool>(W, false));
                using P = pair<int, int>;
                constexpr int d[] = {-1, 0, 1, 0, -1};
                queue<P> q;
                used[i][j] = true, q.push({i, j});
                auto in = [&](const int y, const int x) { return 0 <= y and y < H and 0 <= x and x < W; };
                bool w = false, b = false;
                while (not q.empty()) {
                    const int y = q.front().first, x = q.front().second;
                    q.pop();
                    for (int i = 0; i < 4; i++) {
                        const int newy = y + d[i], newx = x + d[i + 1];
                        if (not in(newy, newx) or used[newy][newx]) { continue; }
                        if (f[newy][newx] == 1) {
                            b = true;
                            continue;
                        } else if (f[newy][newx] == 2) {
                            w = true;
                            continue;
                        } else {
                            used[newy][newx] = true, q.push({newy, newx});
                        }
                    }
                }
                if (w and not b) { wans++; }
                if (b and not w) { bans++; }
            }
        }
        cout << bans << " " << wans << endl;
    }
    return 0;
}



Measured memory_bytes: 3076
#include<stdio.h>
#include<vector>
#include<queue>
#include<iostream>

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

using namespace std;

const int INF = 1000000000;
typedef pair<int,int> P;

int main(){
  int h,w,cnt=0;
  char c;
  bool fl = false;
  scanf("%d%d",&h,&w);
  int gx = h-1, gy = w-1;
  vector<vector<bool>> vvb(h,vector<bool>(w));
  vector<vector<int>> d(h,vector<int>(w,INF));
  REP(i,h){
    REP(j,w){
      cin >> c;
      if(c=='.'){
        vvb[i][j] = true;
        ++cnt;
      }else vvb[i][j] = false;
    }
  }

  int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
  queue<P> que;
  que.push({0,0});
  d[0][0] = 0;
  while(que.size()){
    P p = que.front(); que.pop();
    //printf("%d %d\n",p.first,p.second);
    if(p.first==gx && p.second == gy){
      fl = true;
      break;
    }
    REP(i,4){
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(0<=nx && nx<h && 0<=ny && ny<w && vvb[nx][ny] && d[nx][ny] == INF){
        que.push({nx,ny});
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  //printf("%d\n",d[gx][gy]);
  if(fl) printf("%d\n",cnt-d[gx][gy]-1);
  else printf("-1\n");
  /*
  REP(i,h){
    REP(j,w){
      if(vvb[i][j]) printf(".");
      else printf("#");
    }
    printf("\n");
  }*/
  return 0;
}


Measured memory_bytes: 256
import math


def main():
    ans = 0
    t = []
    for _ in range(5):
        x = input()
        if x[-1] == '0':
            ans += int(x)
        else:
            t.append(int(x))
    if len(t) > 0:
        t.sort(key=lambda x: str(x)[-1])
        for i in range(1, len(t)):
            ans += math.ceil(t[i] / 10) * 10
        ans += t[0]
    print(ans)


main()


Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	string	s;
	cin >> n >> k;
	vector<ll>	aa(n),ans(n);
	for(i=0;i<n;i++) cin >> aa[i];

	for(x=0;x<k;x++) {
		for(i=0;i<n;i++) ans[i] = 0;
		for(i=0;i<n;i++) {
			if (i-aa[i] >= 0) ans[i-aa[i]]++;
			else ans[0]++;
		}
		for(i=0;i<n;i++) {
			if (i+1+aa[i] < n) ans[i+1+aa[i]]--;
		}
		for(i=1;i<n;i++) {
			ans[i] += ans[i-1];
		}
		for(i=0;i<n;i++) aa[i] = ans[i];
		a = 1;
		for(i=0;i<n;i++) if (aa[i]!=n) a = 0;
		if (a) break;
	}

	for(i=0;i<n;i++) {
		if (i>0) cout << " ";
		cout << aa[i];
	}

	cout << endl;
	return 0;
}


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

#define fi              first
#define se              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll              vector<int>
#define mll             map<ll,ll>
#define pqg             priority_queue<ll>
#define pqs             priority_queue<ll,vll,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define md             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x

void hi()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
}
 
int main()
{
    //hi();
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s,t;
    cin>>s>>t;
    s==t.substr(0,s.length())?cout<<"Yes\n":cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
static const int64_t MAX_N = 1e5, MAX_M = 1e5;
int64_t n, m, a[MAX_N];
pair<int64_t, int64_t> p[MAX_M];
int main()
{
	int64_t result = 0;
	cin >> n >> m;
	for (int64_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int64_t i = 0; i < m; i++)
	{
		cin >> p[i].second >> p[i].first;
	}
	int64_t counta = 0, countp = 0;
	sort(a, a + n, greater<int64_t>());
	sort(p, p + m, greater<pair<int64_t, int64_t>>());
	for (int64_t i = 0; i < n; i++)
	{
		if (counta >= n)
		{
			result += p[countp].first;
			--p[countp].second;
			if (p[countp].second == 0)
			{
				countp++;
			}
		}
		else if (countp >= m)
		{
			result += a[counta];
			counta++;
		}
		else if (a[counta] > p[countp].first)
		{
			result += a[counta];
			++counta;
		}
		else
		{
			result += p[countp].first;
			--p[countp].second;
			if (p[countp].second == 0)
			{
				countp++;
			}
		}
	}

	cout << result << endl;
}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int k,s;

int main()
{
    cin>>k>>s;
    int ans=0;
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<=k;j++)
        {
            int a=s-i-j;
            if(a<=k && a >=0)ans++;

        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();

		double area = (double)w * (double)h / 2.0;
		System.out.printf("%f %d\n", area, x*2 == w && y*2 == h ? 1 : 0 );
	}
}


Measured memory_bytes: 35896
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])
b = np.array([int(x) for x in input().split()])

c = np.sort(a - b).tolist()
c_minus = [x for x in c if x < 0]
c_plus = sorted([x for x in c if x > 0], reverse=True)

cnt = len(c_minus)
cnt_sum = -sum(c_minus)

while cnt_sum > 0:
    if len(c_plus) <= 0:
        cnt = -1
        break
    cnt_sum -= c_plus.pop(0)
    cnt += 1
print(cnt)


Measured memory_bytes: 31684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a,b) printf(a,b);
#define o(s) cout<< s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    char c; int cnt=0;
    rep(i,4){
        cin>>c;
        if(c=='2')cnt++;
    }
    o(cnt);
}


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

typedef long long ld;

int W, H, x, y;

int main()
{
    cin >> W >> H >> x >> y;
    cout << fixed << setprecision(8) << ld(W) * H / 2.0l << " " << (2 * x == W && 2 * y == H? 1: 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll
void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    vector<ll> d(n);
    rep(i,n) cin >> d[i];
    d.emplace_back(0);n++;
    sort(all(d));
    rep(i,n){
        if(i & 1)d[i] = 24 - d[i];
    }
    // print(d);
    ll ans = INF;
    rep(i,n)rep(j,n){
        if(i <= j)continue;
        chmin(ans, abs(d[i] - d[j]));
        chmin(ans, 24 - abs(d[i] - d[j]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <string>
#include<string.h>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<iostream>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fuck(x) cout<<x<<endl
#define mem(a,b) memset(a,b,sizeof a)
#define lowbit(x) (x&-x)
const int MAX=1e5*2+10;
int main()
{
    string str;
    string str2;
    while(cin>>str)
    {
        if(str[0]==str[2])
            puts("Yes");
        else
            puts("No");
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, D;
	cin >> N >> D;
	int pre = -100;
	int ans = 0;
	REP(i, N) {
		if (pre + D < i) {
			pre = i + D;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int c[501];
int s[501];
int f[501];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int x;
    cin>>x;
    for (int i=1;i<x;i++)
        cin>>c[i]>>s[i]>>f[i];
    for (int i=1;i<x;i++){
        int t=0;
        for (int j=i;j<x;j++){
            if (t<s[j])
                t=s[j];
            if (t%f[j]!=0){
                t+=f[j]-t%f[j];
            }
            t+=c[j];
        }
        cout<<t<<endl;
    }
    cout<<0<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;

constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

typedef vector<pii> vpii;

int N, M;
multimap<int,int> E;
multimap<pii,pii> E3;

map<pii,int> bfs(pii s) {
    queue<pair<pii,pii>> Q;
    map<pii,int> dist;
    map<pii,int> visit;
    
    dist[s] = 0;
    visit[s]++;
    auto r = E3.equal_range(s);
    for (auto itr = r.first;itr != r.second;itr++) {
        Q.push(make_pair(s,itr->second));
        dist[itr->second] = dist[s] + 1;
        visit[itr->second]++;
    }

    while (!Q.empty()) {
        pii i = Q.front().first, j = Q.front().second;
        // cout << i << "," << j << endl;
        Q.pop();
        auto r = E3.equal_range(j);
        for (auto itr = r.first;itr != r.second;itr++) {
            if (visit[itr->second]<1) {
                Q.push(make_pair(j,itr->second));
                dist[itr->second] = dist[j] + 1;
                visit[itr->second]++;
            }
        }
    }
    return dist;
}


int main(void) {
    int S, T;
    cin >> N >> M;
    for (int i=0;i<M;i++) {
        int x, y;
        cin >> x >> y;
        E.insert(make_pair(x,y));
    }
    cin >> S >> T;

    for (auto itr = E.begin(); itr != E.end(); itr++) {
        for (int i=0;i<3;i++) E3.insert(make_pair(make_pair(itr->first,i%3),make_pair(itr->second,(i+1)%3)));
    }

    map<pii,int> dist = bfs(make_pair(S,0));
    // for (auto itr = dist.begin(); itr != dist.end(); itr++) {
    //     cout << itr->first.first << "," << itr->first.second << ": " << itr->second << endl;
    // }
    if (dist[make_pair(T,0)] != 0) cout << dist[make_pair(T,0)]/3 << endl;
    else cout << -1 << endl;
    
    return 0;
}


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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N, X, Y;
    cin >> N >> X >> Y;

    vector<ll> ans(N - 1);
    for(int i = 1; i <= N - 1; i++) {
        for(int j = i + 1; j <= N; j++) {
            auto unuse = j - i;
            auto use = abs(i - X) + abs(j - Y) + 1;
            ans[min(use, unuse) - 1]++;
        }
    }

    for(const auto& v : ans) {
        cout << v << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
h2 = [0] * n

for _ in range(m):
    a, b = map(int, input().split())
    h2[a-1] = max(h2[a-1], h[b-1])
    h2[b-1] = max(h2[b-1], h[a-1])

ans = 0
for i in range(n):
    if h[i] > h2[i]:
        ans += 1

print(ans)

Measured memory_bytes: 86032
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
using namespace std;
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  int n;
  while(cin>>n,n){
    map<char,char> mp;
    for(int i=0;i<n;i++){
      char b,c;cin>>b>>c;
      mp[b]=c;
    }
    string ans="";
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
      char a;cin>>a;
      auto ite=mp.find(a);
      if(ite!=mp.end()){
        ans+=mp[a];
      }else{
        ans+=a;
      }
    }
    cout<<ans<<"\n";
  }
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 3364
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

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

  string s;
  cin>>s;

  if(s[2]==s[3] && s[4]==s[5]){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;

  
}

Measured memory_bytes: 256
#include <sstream>
#include <iostream>
#include <cstdio>

using namespace std;

int dataset,aiju;

int main(int argc,char **argv){
  cin >> dataset;
  for(int rupu=0;rupu<dataset;rupu++)
    {
      printf("Case %d:",++aiju); cout << endl;
      int s;
      cin >> s;
      for(int itiToJuu=0;itiToJuu<10;itiToJuu++)
	{
	  s = s * s;
	  stringstream ss;
	  ss << s;
	  string sutoring;
	  ss >> sutoring;

	  s = 0;
	  int leading_zero = 114;
	  int nanikadasita = 194;
	  for(int aaa=(int)sutoring.size()-6;aaa<(int)sutoring.size()-2;aaa++)
	    {
	      if( aaa < 0 )
		{
		  continue;
		}
	      else 
		{
		  s = s * 10;
		  s = s + sutoring[aaa] - '0';
		  if( sutoring[aaa] != '0' ) leading_zero = 514;
		  if(leading_zero == 114 && sutoring[aaa] == '0' ) 
		    {

		    }
		  else
		    {
		      nanikadasita = 11111;
		      cout << sutoring[aaa];
		    }
		}
	    }
	  if( nanikadasita == 194 ) cout << 0;
	  cout << endl;
	}
    }
  return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,Y;
  cin>>N>>Y;
  int A=-1,B=-1,C=-1;
  int limA,limB,limC;
  int flag=0;


    limA=Y/10000;
    for(int i=0;i<=limA;i++){
      limB=(Y-10000*i)/5000;
      for(int j=0;j<=limB;j++){
        limC=(Y-10000*i-5000*j)/1000;
        if(N==i+j+limC){
          A=i;
          B=j;
          C=limC;
          flag=1;
          break;
        }
      }
      if(flag==1){
        break;
      }
        
    }
cout<<A<<' '<<B<<' '<<C<<endl;
}

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

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

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

const int MAX = 2 * 1e3 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

    vector<int> L(N);
    rep(i, N) {
        cin >> L[i];
    }

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

    int ans = 0;
    rep(i, N) {
        rep(j, i) {
            int a = L[j];
            int b = L[i];
            int res = lower_bound(L.begin() + i + 1, L.end(), a + b) - (L.begin() + i + 1);
            ans += res;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int INF = 100000000;
int c[10][10] = {0};
int d[10] = {0};

void bellman_ford(int s) {
    d[s] = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                if (j == k) continue;
                int cost = c[k][j];
                // cout << c[j][k];
                if (d[j] != INF && d[k] > d[j] + cost) {
                    d[k] = d[j] + cost;
                }
            }
        }
    }
}

int main() {
    int H, W;
    int A[201][201] = {0};
    int ans = 0;

    cin >> H >> W;

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }
    for (int i = 0; i < 10; i++) {
        d[i] = INF;
    }

    bellman_ford(1);

    for (int i = 0; i < W; i++) {
        for (int j = 0; j < H; j++) {
            cin >> A[i][j];
            if (A[i][j] != -1) {
                ans += d[A[i][j]];
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
typedef pair<ll, ll>P;
ll n,m,ans=0;
ll a[30],b[30];
int c[9];
bool f[9][9];
signed main() {
	cin>>n>>m;
	rep(i,m){
		cin>>a[i]>>b[i];
		f[a[i]][b[i]]=true;
		f[b[i]][a[i]]=true;
	}
	rep(i,n)c[i]=i+1;
	do{
		bool ok=true;
		for(int i=1;i<n;i++){
			if(!f[c[i-1]][c[i]])ok=false;
		}
		if(ok)ans++;
	}while(next_permutation(c+1,c+n));
	cout<<ans<<endl;
	ggr
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back

using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }

int R, C, K, a[3100][3100], v[3100][3100][4]; ll f[3100][3100][4];
ll F(int x, int y, int z) {
    if(x <= 0 || x > R || y <= 0 || y > C || z < 0) return -1e18;
    if(v[x][y][z]) return f[x][y][z];
    v[x][y][z] = 1; f[x][y][z] = max(f[x][y][z], F(x, y - 1, z));
    f[x][y][z] = max(f[x][y][z], F(x, y - 1, z - 1) + a[x][y]);
    for(int i = 0; i <= 3; i++) f[x][y][z] = max(f[x][y][z], F(x - 1, y, i) + (z ? a[x][y] : 0));
    // printf("f[%d, %d, %d] = %lld\n", x, y, z, f[x][y][z]);
    return f[x][y][z];
}
signed main() {
    scanf("%d %d %d", &R, &C, &K);
    for(int i = 1; i <= K; i++) {
        int x, y, v; scanf("%d %d %d", &x, &y, &v);
        a[x][y] = v;
    }
    v[1][1][0] = v[1][1][1] = v[1][1][2] = v[1][1][3] = 1;
    f[1][1][0] = 0, f[1][1][1] = f[1][1][2] = f[1][1][3] = a[1][1];
    ll ans = 0;
    for(int i = 0; i <= 3; i++) ans = max(ans, F(R, C, i));
    printf("%lld\n", ans);
    fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
    return 0;
    /* 取模直接除，爆零两行泪
     * 不开ll见祖宗
     */
}

Measured memory_bytes: 476424
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <list>
#include <set>
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
using namespace std;
using ll = long long;
ll MOD = 1e9+7;
ll dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
ll dy[9] = {-1,  0,  1,-1, 0, 1,-1, 0, 1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W, N;
    cin >> H >> W >> N;
    vector<ll> a(N), b(N);
    set<pair<ll, ll>> st;
    set<pair<ll, ll>> used;

    REP(i, N){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        st.insert(make_pair(a[i],b[i]));
    }
    vector<ll> ans(9,0);
    set<pair<ll,ll>>::iterator it_used, it_set;
    REP(i, N){
        it_used = used.find(make_pair(a[i],b[i]));
            REP(j, 9){
                //cout << a[i]+dy[j] << "," << b[i]+dx[j] << endl;
                ll nx = a[i]+dx[j];
                ll ny = b[i]+dy[j];
                it_used = used.find(make_pair(nx,ny));
                if(it_used == used.end() && nx >= 1 && ny >= 1 && nx < H-1 && ny < W-1){
                    int blk = 0;
                    REP(k, 9){
                        blk += (st.find(make_pair(nx+dy[k], ny+dx[k])) != st.end());
                    }
                    ans[--blk]++;
                }
                used.insert(make_pair(nx,ny));
            }
            used.insert(make_pair(a[i],b[i]));
    }
    ll ans0 = (H-2)*(W-2);
    REP(i, 9){
        ans0 -= ans[i];
    }
    cout << ans0 << endl;
    REP(i, 9){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 64384
#include <iostream>

int main(){
    int A,B,X;
    
    scanf("%d %d %d", &A, &B, &X);

    if(A == X){
        printf("YES");
    }else if(A > X){
        printf("NO");
    }else if(A < X){
        if((A + B) >= X){
            printf("YES");
        }else{
            printf("NO");
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>

using namespace std;

typedef vector<string> StringList;

void exeOrder(string &src, const StringList &order)
{
    int a = stoi(order[1]);
    int b = stoi(order[2]);
    if(order[0] == "print")
    {
        cout << src.substr(a,  b - a + 1) << endl;
    }
    else if(order[0] == "reverse")
    {
        string rev = src.substr(a, b - a + 1);
        reverse(rev.begin(), rev.end());
        src = src.substr(0, a) + rev + src.substr(b+1);

    }
    else if(order[0] == "replace")
    {
        src = src.substr(0, a) + order[3] + src.substr(b+1);
    }
}

int main()
{
    string str;
    getline(cin, str);

    string buf;
    getline(cin, buf);
    int n = stoi(buf);
    for(int i = 0; i < n; i++)
    {
        getline(cin, buf);
        stringstream ss(buf);

        StringList list;
        string tmp;
        while(getline(ss, tmp, ' '))
        {
            list.push_back(tmp);
        }
        exeOrder(str, list);

    }

    return 0;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
struct Node{
  int key;
  Node *right,*left,*parent;
};
Node *root,*NIL;

Node * tmin(Node *x){
  while(x->left!=NIL)x=x->left;
  return x;
}
Node * treeSuccessor(Node *x){
  if(x->right!=NIL)return tmin(x->right);
  Node *y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void tdel(Node *z){
  Node *y;
  Node *x;

  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
  if(y->left!=NIL){
    x=y->left;
  }
  else{
    x=y->right;
  }
  if(x!=NIL){
    x->parent = y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }
  else{
    if(y==y->parent->left){
      y->parent->left=x;
    }
    else{
      y->parent->right=x;
    }
  }
  if(y!=z){
    z->key = y->key;
  }
  free(y);
}

Node * find(Node *u,int k){
  while(u != NIL && k!=u->key){
    if(k<u->key)u=u->left;
    else u = u -> right;
  }
  return u;
}
void insert(int k){
    Node *y = NIL;
  Node *x = root;
  Node *z;
  z=(Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent = y;
  if(y==NIL){
    root = z;
  }else{
    if(z->key < y->key){
      y->left = z;
    }else{
      y->right = z;
    }
  }
}
void inorder(Node *u){
  if(u==NIL)return;
  inorder(u->left);
  cout << " " << u->key;
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL)return;
  cout << " " << u->key;
  preorder(u->left);
  preorder(u->right);
}
int main(){
  int n,m;
  string func;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> func;
    if(func=="find"){
      cin >> m;
      Node *t=find(root,m);
      if(t!=NIL)cout << "yes" << endl;
      else cout << "no" << endl;
    }
    else if(func=="insert"){
      cin >> m;
      insert(m);
    }
    else if(func=="print"){
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
    else if(func=="delete"){
      cin >> m;
      tdel(find(root,m));
    }
  }
  return 0;
  
}

Measured memory_bytes: 21752
def keta(n):
    cnt = 0
    while n>0:
        n=n//10
        cnt+=1
    return cnt
n = int(input())
minans = 10**10
i=0
while i**2<=n:
    i+=1
    if n%i!=0:
        continue
    j = n/i
    ans = max(keta(i),keta(j))
    minans=min(minans,ans)
    i+=1
print(minans)

Measured memory_bytes: 3064