akhauriyash/Code-Regression huggingface dataset:
from collections import deque
H,W=map(int,input().split())
S=[input() for i in range(H)]
table=[[0]*(W-1) for i in range(H-1)]
for i in range(W-1):
    for j in range(H-1):
        table[j][i]=(int(S[j][i]=='#')+int(S[j+1][i]=='#')+int(S[j][i+1]=='#')+int(S[j+1][i+1]=='#') +1 )%2

def get_rec(L):
    a = len(L)
    arr = L + [0]
    stack = deque()
    ans = -1
    for i in range(a + 1):
        #print(stack)
        if len(stack)==0:
            stack.append((arr[i], i))
        elif stack[-1][0] < arr[i]:
            stack.append((arr[i], i))
        elif stack[-1][0] > arr[i]:
            while len(stack) != 0 and stack[-1][0] >= arr[i]:
                x, y = stack.pop()
                ans = max((x+1) * (i - y+1), ans)
            # print(x,y,x*(i-y))
            stack.append((arr[i], y))
        #print(ans)
    return ans
dp=[[0]*(W-1) for i in range(H-1)]
for i in range(W-1):
    for j in range(H-1):
        if j==0:
            dp[0][i]=table[0][i]
            continue
        if table[j][i]==1:
            dp[j][i]=dp[j-1][i]+1
ans=max(H,W)
for j in range(H-1):
    ans=max(ans,get_rec(dp[j]))
print(ans)


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

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int ans = 0;
        for (int x = 1; x * x <= i; ++x) {
            int rest = i - x * x;
            for (int y = 1; y * y <= rest; ++y) {
                int rest2 = rest - y * y;
                for (int z = 1; z * z <= rest2; ++z) {
                    if (x * x + y * y + z * z + x * y + y * z + z * x == i) {
                        ans++;
                    } else if (x * x + y * y + z * z + x * y + y * z + z * x > i) {
                        break;
                    }
                }
            }
        }
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 3760
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;
 
#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  3e5+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   LEVEL =  log2(N)+1;

ll test = 1, sum = 0;
string s;

void solve(){
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		sum += s[i]-'0';
		if(sum >= 9) sum -= 9;
	}
	if(sum == 0) deb1("Yes")
	else deb1("No")
}

int main(){
	GODSPEED;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

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

const int nm = 100;
int n, f[nm], p[nm][11];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0, b; j < 10; j++) {
			cin >> b;
			f[i] <<= 1;
			f[i] |= b;
		}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 11; j++)
			cin >> p[i][j];

	int m = -1e9;
	for (int i = 1, prf; i < 1 << 10; i++) {
		prf = 0;
		for (int j = 0; j < n; j++) {
			prf += p[j][__builtin_popcount(i & f[j])];
		}
		m = max(m, prf);
	}
	cout << m << endl;
}


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

int main(){
    string s;
    cin >>s;
    string substr = s.substr(0,3);
     
    cout << substr << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>

int main() {
	int a,b;
	scanf("%d %d", &a, &b);
	int m = a+b;
	if (m < a-b) m = a-b;
	if (m < a*b) m = a*b;
	printf("%d", m);
	return 0;
}

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

int main()
{
	string a;
	cin >> a;
	int b = a.size(), c = 0, d = 0, e = 0, f = 0, g = 0;
	while (b > c) {
		if (a.substr(0, 1) == "N") {
			d = d + 1;
		}
		else if (a.substr(0, 1) == "W") {
			e = e + 1;
		}
		else if (a.substr(0, 1) == "S") {
			f = f + 1;
		}
		else if (a.substr(0, 1) == "E") {
			g = g + 1;
		}
		a.erase(a.begin());
		c = c + 1;
	}
	if (d == 0 && f == 0 && e != 0 && g != 0) {
		cout << "Yes" ;
	}
	else if (d != 0 && f != 0 && e != 0 && g != 0) {
		cout << "Yes" ;
	}
	else if (d != 0 && f != 0 && e == 0 && g == 0) {
		cout << "Yes";
	}
	else cout << "No" ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)
int main() { 
  int n;cin >> n;
  int sum;
  rep(i,n){
    int l,r;cin >> l >> r;
    sum += r-l;
    sum++;
  }
  cout << sum << endl;
}


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

using namespace std;

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int d[ 5 ];
  int i;

  while ( scanf ( " %d,%d,%d,%d,%d"
                , d, d + 1, d + 2, d + 3, d + 4 ) == 5 )
  {
    int c[ 13 ] = { 0 };

    sort ( d, d + 5 );
    for ( i = 0; i < 5; ++i )
    {
      ++c[ d[ i ] - 1 ];
    }
    sort ( c, c + 13, greater< int > ( ) );

    if ( c[ 0 ] == 4 )
    {
      puts ( "four card" );
    }
    else if ( c[ 0 ] == 3 && c[ 1 ] == 2 )
    {
      puts ( "full house" );
    }
    else if ( ( d[ 0 ] == d[ 1 ] - 1
             && d[ 0 ] == d[ 2 ] - 2
             && d[ 0 ] == d[ 3 ] - 3
             && d[ 0 ] == d[ 4 ] - 4 )
           || ( d[ 0 ] == 1
             && d[ 1 ] == 10
             && d[ 2 ] == 11
             && d[ 3 ] == 12
             && d[ 4 ] == 13 ) )
    {
      puts ( "straight" );
    }
    else if ( c[ 0 ] == 3 )
    {
      puts ( "three card" );
    }
    else if ( c[ 0 ] == 2 && c[ 1 ] == 2 )
    {
      puts ( "two pair" );
    }
    else if ( c[ 0 ] == 2 )
    {
      puts ( "one pair" );
    }
    else
    {
      puts ( "null" );
    }
  }

  return ( 0 );
}

Measured memory_bytes: 0
from collections import Counter
import math

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    
    if n != 1:
        a.append(n)
    
    return a

n = int(input())
a = prime_factorize(n)
count = Counter(a)

ans = 0
for cnt in count.values():
    fib = 0
    for i in range(1, 41):
        fib += i
        if cnt < fib:
            ans += i - 1
            break
print(ans)

Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long double a,b,c;
	cin>>a>>b>>c;
	
	if(4*a*b<(c-a-b)*(c-a-b) && c-a-b>0)
	cout<<"Yes";
	else
	cout<<"No";
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	string S; cin >> S;
	int N = S.length();
	int cnt[3] = {};

	rep(i, N) {
		cnt[S[i] - 'a']++;
	}
	int K = 0;
	rep(i, 3) K += min(1, cnt[i]);
	int maxchar = max({ cnt[0], cnt[1], cnt[2] });
	int minchar = min({ cnt[0], cnt[1], cnt[2] });

	if (N == 1) {
		cout << "YES" << endl;
	}
	else if (N == 2) {
		if (K == 1) {
			cout << "NO" << endl;
		}
		else {
			cout << "YES" << endl;
		}
	}
	else if (N > 2) {
		if (K == 3) {
			if (maxchar - minchar >= 2) {
				cout << "NO" << endl;
			}
			else {
				cout << "YES" << endl;
			}
		}
		else if (K == 2) {
			cout << "NO" << endl;
		}
		else if (K == 1) {
			cout << "NO" << endl;
		}
	}

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
class dice{
    public:
    int d[6];
    void input(){
        rep(i, 6) cin >> d[i];
    }
    void roll(char s){
        if (s == 'N'){
            int sub = d[0];
            d[0] = d[1];
            d[1] = d[5];
            d[5] = d[4];
            d[4] = sub;
        }
        if (s == 'S'){
            int sub = d[0];
            d[0] = d[4];
            d[4] = d[5];
            d[5] = d[1];
            d[1] = sub;
        }
        if (s == 'E'){
            int sub = d[2];
            d[2] = d[0];
            d[0] = d[3];
            d[3] = d[5];
            d[5] = sub;
        }
        if (s == 'W'){
            int sub = d[2];
            d[2] = d[5];
            d[5] = d[3];
            d[3] = d[0];
            d[0] = sub;
        }
    }
    int print(){
        return d[0];
    }
};
int main(){
    dice d;
    d.input();
    string s;
    cin >> s;
    rep(i, s.size()) d.roll(s[i]);
    cout << d.print() << endl;
}


Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {
    static Scanner sc =new Scanner(System.in);
    public static void main(String[] args) {
        int k = sc.nextInt();
        String s = sc.next();

        if (k >= s.length()){
            System.out.println(s);
        }else {
            StringBuilder sb = new StringBuilder(s);
            String tmp = sb.substring(0,k);
            sb = new StringBuilder(tmp);
            sb.append("...");
            System.out.println(sb);
        }
    }
}


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

int dist[2][100005]={};
vector<int> G[100005];

void DFS(int node, int parent, int who){
    for(auto it: G[node]){
	if(it != parent){
	    dist[who][it] = dist[who][node]+1;
	    DFS(it, node, who);
	}
    }
}

int main(){
    int N, u, v, ans=0;    
    cin >> N >> u >> v;
    
    for(int i=0; i<N-1; i++){
	int a, b;
	cin >> a >> b;
	G[a].push_back(b);
	G[b].push_back(a);
    }

    DFS(u, -1, 0);
    DFS(v, -1, 1);

    for(int i=1; i<=N; i++){
	if(dist[0][i] < dist[1][i])
	    ans = max(ans, dist[1][i]-1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))


int main(){
    int n;  cin >> n;
    vector<ll> v(n);

    ll a=0, b=0;
    REP(i, n){
        int x;  cin >> x;
        a = 10*a + x;
    }
    REP(i, n){
        int x;  cin >> x;
        b = 10*b + x;
    }
    REP(i, n)   v[i] = i+1;
    ll cnt=0, ac, bc;
    do{
        ll obj=0;
        REP(i, n) obj = obj*10+v[i];
        if(a==obj) ac = cnt;
        if(b==obj) bc = cnt;
        cnt += 1;
    }while(next_permutation(ALL(v)));
    cout << abs(bc-ac) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };

int n, m;
ll a[100001][3], max_n = -inf;

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < (1 << 3); i++) {
		vector<ll> vec;
		for (int j = 1; j <= n; j++) {
			ll s = 0LL;
			for (int k = 0; k < 3; k++) {
				if ((i / (1 << k)) % 2 == 0) {
					s += a[j][k];
				}
				else {
					s -= a[j][k];
				}
			}
			vec.push_back(s);
		}
		sort(vec.begin(), vec.end());
		reverse(vec.begin(), vec.end());
		ll ans = 0LL;
		for (int j = 0; j < m; j++) {
			ans += vec[j];
		}
		max_n = max(max_n, ans);
	}
	cout << max_n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
llong m;
llong a[10005];
llong sum;

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a[i];
        sum += a[i];
    }

    if (sum > n) {
        cout << -1 << endl;
    }
    else {
        cout << n - sum << endl;
    }
    

    return 0;
}


Measured memory_bytes: 3712
/*                    */
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
lint gcd(lint a, lint b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
lint lcm(lint a, lint b) { return a * b / my::gcd(a, b); }
}  // namespace my
/*                    */

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  bool flag = false;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) flag = true;
  }
  if (flag)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int M = 1e5+50;
char c[M];
int d[M],v[M],l[M],r[M],res[M];
int main(){
	scanf("%s",c+1);
	int n=strlen(c+1);
	for(int i=1;i<=100010;i++)d[i]+=1;
	for(int i=1;i<=n;i++){
		if(c[i]=='L'){
			v[i]=1;
			int j=i-1;
			while(j&&c[j]=='R'){
				r[i]++;
				j--; 
			} 
			j=i;
			while(j<=n&&c[j]=='L'){
				l[i]++;
				j++;
			} 
			while(i<=n&&c[i]=='L')i++;
		}
	}
	 
	for(int i=1;i<=n;i++){
		if(v[i]){
			res[i]=res[i-1]=min(l[i],r[i]); 
			 
			if(l[i]>r[i]){
				l[i]-=r[i];
				res[i]+=l[i]/2;
				res[i-1]+=l[i]/2;
				if(l[i]%2==0)continue;
				
				if((l[i]+r[i]-1)%2){ 
					res[i-1]++;
				} else {
					res[i]++;
				}
			}else{
				r[i]-=l[i]; 
				res[i]+=r[i]/2;
				res[i-1]+=r[i]/2;
				if(r[i]%2==0)continue;

				if((l[i]+r[i]-1)%2){
					res[i]++; 
				}else{
					res[i-1]++;
				}
			}
		}
	} 
	for(int i=1;i<=n;i++)printf("%d ",res[i]);
	return 0;
} 

Measured memory_bytes: 2432
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int nmax = 55555;
int prime[nmax + 10];
vector <int> a;
bool isprime(int x) {
    if (x <= 1) return 0;
    if (x == 2) return 1;
    for (int i = 2; i * i <= x; i++)
        if (x % i == 0) return 0;
    return 1;
}
int main() {
    IO;
    for (int i = 1; i <= nmax; i++) prime[i] = 1;
    prime[1] = 0;
    for (int i = 2; i <= nmax; i++) 
        if (prime[i]) {
            a.push_back(i);
            for (int j = 2; j * i <= nmax; j++)
                prime[i * j] = 0;
        }
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 0; i < a.size(); i++) 
        if (a[i] % 5 == 1) {
            cnt++;
            cout << a[i] << " ";
            if (cnt == n) break;
        }
    fflush(stdout);
    return 0;
}


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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/a.in", "r", stdin);
//  freopen("../IO/a.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int X;
  in >> X;
  out << (X >= 30 ? "Yes" : "No");
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

int main() {
  int n; cin >> n;
  vector<int> abc(3); rep(i,3) cin >> abc[i];
  vector<int> l(n); rep(i,n) cin >> l[i];

  int ans = 1e9;
  rep(bit,1<<n*2) {
    vector<int> sum(3);
    vector<int> cnt(3);
    // ppa(sum);
    rep(i,n) {
      int idx = bit >> i * 2 & 3;
      if (idx == 4) continue;
      sum[idx] += l[i];
      cnt[idx]++;
    }
    if (any_of(ALL(cnt), [](int x) { return x == 0;})) continue;
    
    int mp = 0;
    rep(i,3) mp += abs(abc[i] - sum[i]);
    rep(i,3) mp += (cnt[i] - 1) * 10;

    ans = min(ans, mp);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int a = scan.nextInt();
		int b = scan.nextInt();
		int area = a * b;
		int cir = 2 * (a + b);
		System.out.printf("%d %d\n", area, cir);
	}
}

Measured memory_bytes: 26284
from collections import deque

h, w = (int(x) for x in input().split())
ch, cw = (int(x) - 1 for x in input().split())
dh, dw = (int(x) - 1 for x in input().split())
s = [list(input()) for _ in range(h)]
d = [[-1] * w for _ in range(h)]
d[ch][cw] = 0
walk = [[0, 1], [0, -1], [1, 0], [-1, 0]]
warp = [[2, 2], [2, 1], [2, 0], [2, -1], [2, -2], [1, 2], [1, 1], [1, -1], [1, -2], [0, 2], [0, -2], [-1, 2], [-1, 1],
     [-1, -1], [-1, -2], [-2, 2], [-2, 1], [-2, 0], [-2, -1], [-2, -2]]

que = deque([(0, ch, cw)])
while que:
    count, y, x = que.popleft()
    if d[y][x] < count:
        continue
    for NY, NX in walk:
        if 0 <= y + NY < h and 0 <= x + NX < w and s[y + NY][x + NX] != '#':
            if d[y + NY][x + NX] == -1 or d[y + NY][x + NX] > count:
                d[y + NY][x + NX] = count
                que.appendleft((count, y + NY, x + NX))
    for NY, NX in warp:
        if 0 <= y + NY < h and 0 <= x + NX < w and s[y + NY][x + NX] != '#':
            if d[y + NY][x + NX] == -1 or d[y + NY][x + NX] > count + 1:
                d[y + NY][x + NX] = count + 1
                que.append((count + 1, y + NY, x + NX))

print(d[dh][dw])

Measured memory_bytes: 161712
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<"[@"<<__LINE__<<"] "<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}
template<typename T> istream& operator>>(istream& s,vector<T>& v){for(T& x:v)s>>x;return s;}

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

    string s;
    cin >> s;
    int q; cin >> q;
    int rev = 0;
    deque<char> dq;
    for(char c : s){
        dq.emplace_back(c);
    }
    rep(i, q){
        int x;
        cin >> x;
        if(x == 1){
            rev ^= 1;
        }else{
            int f; 
            char c;
            cin >> f >> c;
            --f;
            f ^= rev;
            if(f) {dq.emplace_back(c);}
            else {dq.emplace_front(c);}
        }
    }
    while(!dq.empty()){
        if(rev==0){
            cout << dq.front(); dq.pop_front();
        }else{
            cout << dq.back(); dq.pop_back();
        }
    }

    cout << '\n';
    

    
    
    return 0;
}


Measured memory_bytes: 976
use proconio::input;
use proconio::marker::*;

fn main() {
  input! {
    mut a: usize,
    mut b: usize,
    c: usize,
    mut x: usize,
    mut y: usize,
  }
  
  if x < y {
    let temp = x;
    x = y;
    y = temp;
    let temp = a;
    a = b;
    b = temp;
  }

  let pa = x * (2 * c);
  let pb = y * (2 * c) + (x - y) * a;
  let pc = x * a + y * b;
  
  let mut min = std::cmp::min(pa, pb);
  min = std::cmp::min(min, pc);
  println!("{}", min);
}

Measured memory_bytes: 2144
n, h = map(int, input().split())
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a, "a"))
    ab.append((b, "b"))

ab.sort(reverse=True, key=lambda x: x[0])
#print(ab)
count = 0
for x, y in ab:
    if h <= 0:
        break
    if y == "a":
        if h%x == 0:
            count += h//x
            h = 0
        else:
            count += h//x + 1
            h = 0
    if y == "b":
        h -= x
        count += 1

print(count)

Measured memory_bytes: 73048
main = do
    a:b:_ <- (map (\x->read x::Int) . words) <$> getLine
    putStrLn $ solve a b

solve :: Int -> Int -> String
solve a b
    | a * b <= 0 = "Zero"
    | a > 0      = "Positive"
    | (b-a) `mod` 2 == 0 = "Negative"
    | otherwise          = "Positive"

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

int main() {
    int n; cin >>n;
    int a[105];
    for(int i=1;i<=n;i++) cin >>a[i];
    int ans = 0;
    for(int i=1;i<=n-1;i++) {
        int id = i;
        for(int j=i+1;j<=n;j++) {
            if(a[j]<a[id]) {
                id = j;
            }
        }
        if(id!=i) {
            swap(a[id],a[i]);
            ans++;
        }
    }
    for(int i=1;i<=n-1;i++) cout << a[i] << " ";
    cout << a[n] <<endl << ans << endl;
    return 0;
}



Measured memory_bytes: 3088
#include<iostream>
using namespace std;
int main()
{
	string s1,s2;
	cin>>s1>>s2;
	
	for(int i=0;i<s1.size();i++)
	{
		if(s1[i]!=s2[i])
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define ll_1e9 (ll)1e9
using namespace std;


int main(){
    ll h,w;
    cin >> h >> w;
    ll cnt[26] = {};

    char a[h][w];
    rep(i,0,h) rep(j,0,w) {
        cin >> a[i][j];
        cnt[a[i][j] - 'a']++;
    }

    if(h % 2 == 0 && w % 2 == 0){
        rep(i,0,26){
            if(cnt[i] % 4){
                cout << "No" << endl;
                break;
            }
            else if(i == 25) cout << "Yes" << endl;
        }
    }
    else if(h % 2 == 0 || w % 2 == 0){
        if(w % 2 == 0) swap(h,w);
        ll temp = 0;
        rep(i,0,26){
            if(cnt[i] % 2){
                cout << "No" << endl;
                return 0;
            }
            
            temp += cnt[i] / 4;
        }

        if(temp >= (w-1)*h/4) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
        ll temp = 0;
        bool flag = false;
        rep(i,0,26){
            if(cnt[i] % 2){
                if(flag){
                    cout << "No" << endl;
                    return 0;
                }
                flag = true;
            }
            
            temp += cnt[i] / 4;
        }

        if(temp >= (h-1)*(w-1)/4){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <limits>
using namespace std;
int main() {
    int N,T;
    cin >> N >> T;
    int c[N],t[N];
    for (int i=0; i<N; i++) {
        cin >> c[i] >> t[i];
    }
    int min = numeric_limits<int>::max();
    for (int i=0; i<N; i++) {
        if (t[i]<=T && c[i]<min) {
            min = c[i];
        }
    }
    if (min == numeric_limits<int>::max()) {
        cout << "TLE" << endl;
    } else {
        cout << min << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

void fitInFrame(int numOfRow, int numOfColumn, std::vector<std::string>& mineField);
char countMine(int row, int column,const std::vector<std::string>& mineField);

int main() {
    int numOfRow = 0;
    int numOfColumn = 0;
    std::cin >> numOfRow >> numOfColumn;
    
    std::vector<std::string> mineField;
    std::string row;
    for(int i = 0; i < numOfRow; ++i) {
        std::cin >> row;
        mineField.push_back(row);
    }

    fitInFrame(numOfRow, numOfColumn, mineField);

    std::vector<std::string> convertedMineField(numOfRow);
    for (int i = 1; i <= numOfRow; ++i) {
        for(int j = 1; j <= numOfColumn; ++j) {
            if(mineField.at(i).at(j) == '.') {
                convertedMineField.at(i - 1).push_back(countMine(i, j, mineField));
            } else {
                convertedMineField.at(i - 1).push_back('#');
            }
        }
    }    
    for(std::string row : convertedMineField) {
        std::cout << row << std::endl;
    }    
}

void fitInFrame(int numOfRow, int numOfColumn, std::vector<std::string>& mineField) { 
    for(int i = 0; i < numOfRow; ++i) {
        mineField.at(i) = "." + mineField.at(i) + ".";
    }
    
    std::string frame;
    for(int i = 0; i < numOfColumn + 2; ++i) {
        frame += ".";
    }
        
    mineField.insert(mineField.begin(), frame);
    mineField.push_back(frame);
}

char countMine(int row, int column, const std::vector<std::string>& mineField) {
    int numOfMine = 0;
    for(int i = row - 1; i <= row + 1; ++i) {
        for(int j = column - 1; j <= column +1; ++j) {
            if(mineField.at(i).at(j) == '#') ++numOfMine;
        }
    }
    
    return '0' + numOfMine;
} 

Measured memory_bytes: 3616
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


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 RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

// edit

void solve() {
    ll A, B, N;
    cin >> A >> B >> N;
    ll ans = A * min(N, B - 1) / B;
    cout << ans << endl;

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 3192
#include<iostream>  
#include<cstring>  
#include<cstdio>  
#include<cmath>  
#include<algorithm>  
  
using namespace std;  
  
bool s[15][10005]= {0};  
  
int n, m;  

void reverse(int row){
    for(int i=1; i<=m; i++){
        if(s[row][i]==0) s[row][i]=1;
        else s[row][i]=0;
    }
}

int dfs(int x)  
{  
    if(x==n+1)  
    {  
        int sum=0;  
        int term=0;  
        for(int j=1;j<=m;j++)  
        {  
            for(int i=1;i<=n;i++)  
                if(s[i][j]==1)term++;  
            //sum += term > n-term ? term : n-term;  
            term>n-term?(sum+=term):(sum+=(n-term));
            term=0;  
        }  
        return sum;  
    }  
    int a=dfs(x+1);  
    reverse(x);
    //for(int i=1;i<=m;i++)  
      //  s[x][i]=!s[x][i];  
    int b=dfs(x+1);  
    return a>b?a:b;
}  
  
int main()  
{  
    //freopen("in.in","r",stdin);  
    while(scanf("%d%d",&n,&m)!=EOF)  
    {  
        if(n==0&&m==0)break;   
        for(int i=1; i<=n; i++)  
            for(int j=1; j<=m; j++)  
                cin>>s[i][j];  
        cout<<dfs(1)<<endl;  
    }  
    return 0;  
}  


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

ll n, m;
vector<int> a, b;
vector<vector<bool>> graph;
vector<bool> visited;

void dfs(ll v) {
  visited[v] = true;
  rep(nv, n) {
    if (!graph[v][nv]) continue;
    if (visited[nv]) continue;
    dfs(nv);
  }
}

int main() {
  cin >> n >> m;

  a = b = vector<int>(m);
  graph = vector<vector<bool>>(n, vector<bool>(n, false));

  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  ll ans = 0;
  rep(i, m) {
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

    visited = vector<bool>(n, false);

    dfs(0);

    bool bridge = false;
    rep(j, n) bridge |= !visited[j];
    if (bridge) ans++;

    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int n, a, ma, mi;
    cin >> n;
    ma = 0;
    mi = INT_MAX;
    
    for ( int i = 0; i < n; i++ ) {
        cin >> a;
        ma = max(ma, a);
        mi = min(mi, a);
    }
    
    cout << ma - mi << endl;
    
    return (0);
}


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

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

using namespace std;

string s;

bool check(int l,int r){
	for(int i=l;i<r;i++) if(s[i]=='#' && s[i+1]=='#') return false;
	return true;
}

bool check2(int l,int r){
	for(int i=l;i<=r;i++) if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.') return true;
	return false;
}

int main(){
	int n,a,b,c,d; cin>>n>>a>>b>>c>>d>>s;
	a--; b--; c--; d--;

	if(c<d) puts(check(a,c)&&check(b,d)?"Yes":"No");
	else    puts(check(a,c)&&check(b,d)&&check2(b,d)?"Yes":"No");

	return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    if (n < 1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
 
/* Coding Space*/


int main(){
  int n; cin >>n;
  ll ans = pow(3,n,LLINF);
  ll d = 1;
  rep(i,n){
    int in; cin >> in;
    if(in % 2)
      ;
    else
      d *= 2;
  }
  cout << ans - d << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
string s;
cin >> s;
bool ans = true;
rep(i,s.size()){
  if(s.size()%2!=0){
    ans = false;
    break;
  }
  if(s.at(i)!='h' || s.at(i+1)!='i') ans = false;
  i++;
  
}
cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define MOD (ll)(998244353)
#define MAX (ll)(1e5 + 4)
#define INF (ll)(1e17)
using namespace std;
using ll =  long long;
using ld = long double;


int main () {
	int n, m;
	cin >> n >> m;
	if (m == n) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
H = list(map(int, input().split()))+[10**18]
ans = 0
cnt = 0

for i in range(N):
    if H[i]>=H[i+1]:
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 0

print(ans)

Measured memory_bytes: 88824
#include <iostream>

using namespace std;
class MAN{
public:
	unsigned int uriage;
	int number;
};

int main(int argc, char const* argv[])
{
	MAN person[4000];
	int n;
	bool flag;

	while( cin >> n && n != 0 ){
		for( int i = 0;i < n;i++ ){
			person[i].uriage = 0;
			person[i].number = 0;
		}

		for( int i = 0;i < n;i++ ){
			int target;
			unsigned int a,b;
			cin >> target >> a >> b;

			int j;
			for( j = 0;j < i;j++ ){
				if( person[j].number == target ){
					person[j].uriage += a*b;
					break;
				}
			}
			if( j == i ){
				person[i].number = target;
				person[i].uriage = a * b;
			}
		}
		flag = false;
		for( int i = 0;i < n;i++ ){
			if( person[i].uriage >= 1000000 ){
				cout << person[i].number << endl;
				flag = true;
			}
		}
		if( flag == false ) cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 0
N=int(input())
for i in range(1,3501):
	for j in range(1,3501):
		if ((4*i*j)-(N*i)-(N*j))>0:
			if (i*j*N)%((4*i*j)-(N*i)-(N*j))==0:
				k=(i*j*N)//((4*i*j)-(N*i)-(N*j))
				print(i,j,k)
				exit()

Measured memory_bytes: 3188
def root(x):
    if uf[x] == x:
        return x
    uf[x] = root(uf[x])
    return uf[x]

def same(x, y):
    return root(x) == root(y)

def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx == ry:
        return
    uf[rx] = ry

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

cnt = 0
for i in range(M):
    uf = [i for i in range(N+1)]
    for j in range(M):
        if i != j:
            unite(edge[j][0], edge[j][1])
    for j in range(N):
        if not same(1, j+1):
            cnt += 1
            break
print(str(cnt))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    cout<<x2+y1-y2<<" "<<x2-x1+y2<<" "<<x1+y1-y2<<" "<<-x1+x2+y1;
    return 0;
}


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

void solve(string& str, long long k)
{
   int gap;
   int n = str.size();
   for(int i=0; i<n; i++)
   {
      gap = 'z' - str[i] + 1;
      if (i!=n-1)
      {
      	if (k>=gap && str[i] !='a')
      	{
      	  str[i] = 'a';
      	  k= k-gap;
      	  continue;
      	}else{
      		continue;
      	}
      }else{
      	str[i] = (str[i] - 'a' + k) % 26 + 'a';
      }
      
   }
}
int main()
{
string str;
long long k;
cin >> str;
cin >> k;
solve(str,k);
cout << str;
return 0;
  
}

Measured memory_bytes: 512
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(long long i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(long long i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll>pll;

int main() {
	int N,H,W,cnt=0;
    int a[1010],b[1010];

    cin>>N>>H>>W;
    REP(i,N){
        cin>>a[i]>>b[i];
        if(a[i]>=H&&b[i]>=W){
            cnt++;
        }
    }
	
    cout<<cnt<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  ll d,l;
  cin >> d >> l;
  ll a = d/l;
  ll b = d%l;
  cout << a+b << endl;
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    vector<ll> v(5);
    for (int i = 0; i < 5; ++i) cin >> v[i];
    vector<ll> array = {0, 1, 2, 3, 4};
    ll min_time = 10000;
    do {
        ll tmp_min_time = 0;
        for (int i = 0; i < 4; ++i) {
            tmp_min_time += v[array[i]];
            while(tmp_min_time%10 != 0) tmp_min_time++;
        }
        tmp_min_time += v[array[4]];
        min_time = min(min_time, tmp_min_time);
    }
    while (next_permutation(array.begin(), array.end()));
    cout << min_time << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
// #define MULTIPLE_TESTS 1

ll n;

void solve() {
    cin >> n;
    int ans = 0;
    for (int i = 2; i <= sqrt(n); ++i) {
        int cnt = 0;
        while (n % i == 0) {
            n /= i;
            ++cnt;
        }
        int cur = (-1 + sqrt(1 + 8*cnt))/2;
        ans += cur;
    }
    if (n != 1) {
        ans += 1; // left over is prime
    }
    cout << ans << endl;
}

int main() {
    FAST_IO;
    int t = 1;
    #ifdef MULTIPLE_TESTS
    cin >> t;
    #endif

    while (t--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3652
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    x = 7 % K
    for i in range(1, K + 1):
        if x == 0:
            print(i)
            break
        x = (x * 10 + 7) % K

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  string s;
  cin>>s;
  
  string a[]={"Sunny","Cloudy","Rainy","Sunny"};
  string t;
  if(s==a[0])t=a[1];
  else if(s==a[1])t=a[2];
  else if(s==a[2])t=a[3];
  cout<<t<<endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
#define INF 1e9
using namespace std;
using ll = long long;
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 (b<a) { a=b; return 1; } return 0; }
int main(){
    int n;
    cin >> n;
    vector<int> x(9),y(9);
    rep(i,n) cin >> x[i] >> y[i];
    float c = 0;
    rep(i,n) rep(j,n){
        c += sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
    }
    float a = n;
    cout << setprecision(20) << c/a << endl;
}


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

int main() {
  int N,K;
  cin >> N >> K;
 
  vector<long long>count(N-K+2);
  count.at(0) = 1;
  for (int i = 1; i < N-K+2; i++) {
    count.at(i) += count.at(i-1) + N - 2*(i-1);
  }
  
  long long S = 0;
  for (int i = 0; i < N-K+2; i++) {
    S += count.at(i);
    S = S % 1000000007;
  }
  cout << S << endl;
}
    
  

Measured memory_bytes: 4824
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss

using namespace std;

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

    int n; cin >> n;
    int A[n], B[n];
    for(auto &i : A) cin >> i;
    for(auto &i : B) cin >> i;
    for(int i = 1; i < n; i += 2) swap(A[i], B[i]);

    int ans = 1e9;
    int N = (1 << n);
    for(int i = 0; i < N; ++i)
    {
        pii arr[n];
        vector<pii> L, R;
        for(int j = 0; j < n; ++j)
        {
            if(i >> j & 1) L.push_back({A[j], j});
            else R.push_back({B[j], j});
        }

        if(!(L.size() == R.size() || L.size() == R.size() + 1)) continue;
        sort(L.begin(), L.end());
        sort(R.begin(), R.end());

        for(int i = 0; i < R.size(); ++i)
        {
            arr[i * 2] = L[i];
            arr[i * 2 + 1] = R[i];
        }
        if(L.size() > R.size()) arr[n - 1] = L.back();

        bool flag = true;
        for(int j = 1; j < n; ++j)
        {
            if(arr[j - 1].ff > arr[j].ff)
            {
                flag = false;
                break;
            }
        }

        if(flag)
        {
            int __ans = 0;
            for(int j = 0; j < n; ++j)
            {
                for(int k = j + 1; k < n; ++k)
                {
                    if(arr[j].ss > arr[k].ss) ++__ans;
                }
            }

            ans = min(ans, __ans);
        }
    }

    cout << (ans == 1e9 ? -1 : ans);
    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int[] rel = new int[n];
			int[] cnt = new int[n];
			Arrays.fill(rel, -1);
			for (int i = 0; i < m; i++) {
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1;
				int min = Math.min(a, b);
				int max = Math.max(a, b);
				int parent = max;
				int minparent = min;
				while (true) {
					int next = rel[parent];
					if (next == -1) {
						break;
					}
					parent = next;
				}
				while (true) {
					int next = rel[minparent];
					if (next == -1) {
						break;
					}
					minparent = next;
				}
				if (parent > minparent) {
					rel[parent] = minparent;
				} else if (parent < minparent) {
					rel[minparent] = parent;
				}
			}
			int max = 1;
			for (int i = n - 1; i >= 0; i--) {
				int parent = rel[i];
				if (parent == -1) {
					max = Math.max(max, cnt[i] + 1);
					continue;
				}
				cnt[parent] += cnt[i] + 1;
				max = Math.max(max, cnt[parent]);
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 63096
#include<stdio.h>
#include<stdlib.h>

#define MAX 100000


struct node {int parent;
             int left;
             int right;
             };

struct node t[MAX];
int n, D[MAX],H[MAX];

void setdepth(int u,int d){
  if(u==-1) return;
  D[u]=d;
  setdepth(t[u].left,d+1);
  setdepth(t[u].right,d+1);
}

int setheight(int u){
  int h1=0,h2=0;
  if(t[u].left!=-1)
    h1=setheight(t[u].left)+1;
  if(t[u].right!=-1)
    h2=setheight(t[u].right)+1;
  return H[u]=(h1>h2?h1:h2);
}

int getsibling(int u){
  if(t[u].parent==-1) return -1;
  if(t[t[u].parent].left!=u&&t[t[u].parent].left!=-1)
    return t[t[u].parent].left;
  if(t[t[u].parent].right != u&&t[t[u].parent].right!=-1)
    return t[t[u].parent].right;
  return -1;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",t[u].parent);
  printf("sibling = %d, ",getsibling(u));
  int deg=0;
  if(t[u].left!=-1) deg++;
  if(t[u].right!=-1) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(t[u].parent==-1){
    printf("root\n");
  }else if(t[u].left==-1&&t[u].right==-1){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }
}

int main(){
  int v,l,r,root=0;
  scanf("%d",&n);

  for(int i=0;i<n;i++) t[i].parent=-1;

  for(int i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    t[v].left=l;
    t[v].right=r;
    if(l!=-1) t[l].parent=v;
    if(r!=-1) t[r].parent=v;
  }

  for(int i=0;i<n;i++) if(t[i].parent==-1) root=i;
  setdepth(root,0);
  setheight(root);
  for(int i=0;i<n;i++) print(i);

  return 0;
}


Measured memory_bytes: 2104