akhauriyash/Code-Regression huggingface dataset:
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7

def main():
  h,w = map(int,input().split())
  for _ in range(h):
    s = input()
    print(s)
    print(s)
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }



int main() {

	double N;
	cin >> N;
	ll po = floor(sqrt(N));
	cout << po * po << endl;
}

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

using namespace std;

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

string g[1005];
int dp[1005][1005];
const int MOD = 1000000007;

void solve() {
  int r, c;
  cin >> r >> c;
  for(int i = 0; i < r; i++) {
    cin >> g[i];
  }
  dp[0][0] = 1;
  for(int i = 0; i < r; i++) {
    for(int j = 0; j < c; j++) {
      if(g[i][j] == '#') continue;
      if(i) dp[i][j] += dp[i-1][j];
      if(j) dp[i][j] += dp[i][j-1];
      dp[i][j] %= MOD;
    }
  }
  cout << dp[r-1][c-1] << endl;
}

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


Measured memory_bytes: 5248
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;
    vector<vector<int>> work(n, vector<int>(2));
    
    for (int i = 0; i < n; i++) {
        cin >> work[i][1] >> work[i][0];
    }
    
    sort(work.begin(), work.end());
    
    bool can = true;
    int now = 0;
    for (int i = 0; i< n; i++) {
        if (now + work[i][1]> work[i][0]) {
            can = false;
            break;
        }
        now += work[i][1];
    }
    
    cout << (can ? "Yes" : "No") << endl;
    
    return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

struct robot {
    ll x, l, t;

    bool operator<(const robot& other) const {
        if (t < other.t) return true;
        else return false;
    }
};

bool cmp(const pair<int, set<int> > & a, const pair<int, set<int> > & b) {
    return a.second.size() < b.second.size(); 
}

int main() {
    int N;
    cin >> N;
    vector<robot> robots(N);
    REP(i, N) {
        cin >> robots[i].x >> robots[i].l;
        robots[i].t = robots[i].x + robots[i].l;
    }
    sort(ALL(robots));

    ll max_x = robots[0].x - robots[0].l;
    vector<int> remains;
    REP(i, N) {
        if(max_x <= robots[i].x - robots[i].l) {
            remains.push_back(i);
            max_x = max(max_x, robots[i].t);
        }
    }

    cout << remains.size() << endl;

    return 0;
}

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

int main(){
	int N, X, L, i, D = 0, ans = 1;
	scanf("%d%d", &N, &X);
	for(i = 0; i < N; i++){
		scanf("%d", &L);
		D += L;
		if(D <= X){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(V) sort((V).begin(),(V).end())
#define pb push_back
#define endl '\n'
#define int long long

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

// 変数定義
int a,b,sum=1,cnt=0;
//

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b;
  while(sum < b) {
  	sum--;
    sum += a;
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち

import numpy as np
from functools import partial
array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)

ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)


def read_matrix(H, W):
    '''return np.ndarray shape=(H,W) matrix'''
    lines = []
    for _ in range(H):
        lines.append(read())
    lines = ' '.join(lines)  # byte同士の結合ができないのでreadlineでなくreadで
    return np.fromstring(lines, sep=' ', dtype=np.int64).reshape(H, W)


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import

from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce, lru_cache
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


N = a_int()
A = ints()
cnt = Counter(A)
'''
dp[i,j,k]...すべての寿司がなくなるまでの操作の期待値(寿司が1つ乗っている皿の数がi,2つがj,3つがk)

dp[i,j,k]= 1(操作回数)+ 
            i/N*(1つの皿が一つ減った場合の操作の期待値) + 
            j/N*(2つの皿が1つ減った場合の操作の期待値) + 
            k/N*(3つの皿が1つ減った場合の操作の期待値)+
            (1-i-j-k)/N * (0つの皿を選んでしまったときの期待値)

dp[i,j,k]= 1+ i/N * dp[i-1,j,k]+ 
            j/N*dp[i+1,j-1,k] + 
            k/N*dp[i,j+1,k-1]+
            (N-i-j-k)/N*dp[i,j,k]

dp[i,j,k]= N/(i+j+k) *
            (1+ i/N * dp[i-1,j,k]+ 
            j/N*dp[i+1,j-1,k] + 
            k/N*dp[i,j+1,k-1])
'''

dp = np.full((N + 1, N + 1, N + 1), -1.0)
dp[0, 0, 0] = 0
from numba import njit
# @njit('(i8,i8,i8[:])',cache=True)


@njit('f8(i8,i8,i8,i8,f8[:,:,:])', cache=True)
def dfs(i, j, k, N, dp):
    if i < 0 or j < 0 or k < 0 or i == j == k == 0:
        return 0
    if dp[i, j, k] != -1:
        return dp[i, j, k]
    ret = 1
    ret += i / N * dfs(i - 1, j, k, N, dp)
    ret += j / N * dfs(i + 1, j - 1, k, N, dp)
    ret += k / N * dfs(i, j + 1, k - 1, N, dp)
    if (i + j + k) == 0:
        dp[i, j, k] = ret
        return ret
    dp[i, j, k] = N / (i + j + k) * ret
    return dp[i, j, k]


print(dfs(cnt[1], cnt[2], cnt[3], N, dp))


Measured memory_bytes: 323816
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf')] * n
dp[0] = 0
for i in range(1, n):
    for j in range(1, k + 1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
        else:
            break
print(dp[-1])


Measured memory_bytes: 54880
import sys
input = sys.stdin.readline

N = int(input())
xy = [[int(i) for i in input().split()] for _ in range(N)]

d1 = []
d2 = []
for x, y in xy :
  d1.append(x + y)
  d2.append(x - y)

d1.sort(reverse=True)
d2.sort(reverse=True)

print(max(
  d1[0] - d1[-1],
  d2[0] - d2[-1],
))


Measured memory_bytes: 130624
using System;
using System.Collections.Generic;
namespace Test
{
	class Tenki
    {
  		static void Main()
		{
            int i;
          	i= 0;
			
            string tenkiIn;
			IList<string> list = new List<string>();
          	list.Add("Sunny");
            list.Add("Cloudy");
          	list.Add("Rainy");
			
    
			tenkiIn = Console.ReadLine();
			while (tenkiIn != list[i]) {
  				i += 1;
            }
			
			Console.WriteLine(list[(i + 1) % 3]);
		}
	}
}

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

typedef long long ll;

int n;
int h[200010];
ll a[200010];

//ll go(int pos, int last) {
//    if(pos == n) {
//        return 0;
//    }
//    ll op1 = go(pos + 1, last), op2 = 0LL;
//    if(h[pos] > last) op2 = a[pos] + go(pos + 1, h[pos]);
//
//    return max(op1, op2);
//}
//
//ll dp[2010][2010];

ll tree[200010];

void update(int p, ll x) {
    if(p < 1) return;
    while(p <= 200'000) {
        tree[p] = max(tree[p], x);
        p += p & -p;
    }
}

ll query(int p) {
    if(p < 1) return 0;
    ll ans = 0;
    while(p >= 1) {
        ans = max(ans, tree[p]);
        p -= p & -p;
    }
    return ans;
}

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

//    int t;
//    while(cin >> t) {
//        if(t == 1) {
//            int p, x;
//            cin >> p >> x;
//
//            update(p, x);
//        }
//        else {
//            int p;
//            cin >> p;
//            cout << query(p) << endl;
//        }
//    }

    cin >> n;

    int mx = 0;

    for(int i = 0; i < n; i++) cin >> h[i], mx = max(mx, h[i]);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

//    cout << go(0, 0) << endl;
//
//    for(int pos = n; pos >= 0; pos--) {
//        for(int last = 0; last <= mx; last++) {
//            if(pos == n) {
//                dp[pos][last] =  0;
//            }
//            ll op1 = dp[pos + 1][last], op2 = 0LL;
//            if(h[pos] > last) op2 = a[pos] + dp[pos + 1][h[pos]];
//
//            dp[pos][last] = max(op1, op2);
//        }
//    }
//
//    cout << dp[0][0] << endl;

    ll ans = 0LL;

    for(int i = 0; i < n; i++) {
        update(h[i], a[i] + query(h[i] - 1));
        ans = max(ans, query(h[i]));
    }

    cout << ans << endl;
}

Measured memory_bytes: 4224
S = input()
for i,(a,b) in enumerate(zip(S,S[1:])):
    if a==b:
        print(i+1,i+2)
        exit()
for i,(a,b) in enumerate(zip(S,S[2:])):
    if a==b:
        print(i+1,i+3)
        exit()
print(-1,-1)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define pb push_back
#define N 500009
#define inf 1e18
//int mod=1e9+7;
int mod=998244353;
#define P pair<int,int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(),v.end()

#define ordered_set tree<P, null_type,less<P>, rb_tree_tag,tree_order_statistics_node_update> 

ll power(ll a,ll n){
  ll ans=1;
  while(n>0){
    if(n%2)ans=(ans*a)%mod;
    n=n>>1;
    a=(a*a)%mod;
  }
  return ans;
}
int inv(int n){
	return power(n,mod-2)%mod;
}
int fact[N];
void init(){
	fact[0]=1;
	for(int i=1;i<N;i++){
		fact[i]=(i*fact[i-1])%mod;
		fact[i]%mod;
	}
}
int ncr(int n,int r){
	int ans=fact[n]*inv(fact[r])%mod;
	ans%=mod;
	ans=(ans*inv(fact[n-r]))%mod;
	return ans%mod;
}
void solve(){
	int MOD=2019;
	string s;cin>>s;
	int n=s.size();
	int suff=0;
	int po=1;
	vector<int>cnt_suff(MOD,0);
	cnt_suff[suff]++;
	int ans=0;
	for(int i=n-1;~i;i--){
		int digit=s[i]-'0';
		suff=(suff+digit*po)%MOD;
		po=(po*10)%MOD;
		ans+=cnt_suff[suff];
		cnt_suff[suff]++;
	}
	cout<<ans<<"\n";
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;//cin>>t;
	while(t--){
		solve();
	}
    return 0;
}

Measured memory_bytes: 3736
using System;
using System.Collections.Generic;
using System.Text;

namespace atCoder161
{
    class ClassC
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            long N = long.Parse(str[0]);
            long K = long.Parse(str[1]);
            long min;

            if (K == 0)
            {
                min = N;
            }
            else if (N % K == 0)
            {
                min = 0;
            }
            else
            {
                long l = N / K;
                min = N - l * K;

                while (true)
                {
                    long zettai = Math.Abs(min - K);
                    if (zettai < min)
                    {
                        min = zettai;
                        continue;
                    }
                    break;
                }
            }
            Console.WriteLine(min);
        }
    }
}


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

int main(int argc, char const *argv[]) {
    int N;
    std::cin >> N;
    std::vector<int> a(N);
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
    }
    
    int cost_min = -1;
    for (int x = -100; x <= 100; x++) {
        int cost = 0;
        for (int i = 0; i < N; i++) {
            int diff = a[i] - x;
            cost += diff * diff;
        }
        if (cost_min < 0 || cost < cost_min) {
            cost_min = cost;
        }
    }
    std::cout << cost_min << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, d, m, t;
  cin >> n;
  map<ll, ll> problem;
  rep(_, n) {
    cin >> d;
    problem[d]++;
  }
  cin >> m;
  rep(_, m) {
    cin >> t;
    problem[t]--;
    if(problem[t]<0) {cout << "NO" << newl; return 0;}
  }
  cout << "YES" << newl;
  return 0;
}

Measured memory_bytes: 12800
import fractions as ff
a,b,c,d=map(int,input().split())
if a%c==0 or a%d==0:
    cnt=1
else:
    cnt=0
if cnt==1:
    print((b-b//c-b//d+b//(c*d//ff.gcd(c,d)))-(a-a//c-a//d+a//(c*d//ff.gcd(c,d))))
else:
    print((b-b//c-b//d+b//(c*d//ff.gcd(c,d)))-(a-a//c-a//d+a//(c*d//ff.gcd(c,d)))+1)


Measured memory_bytes: 5048
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=5005,mod=998244353;
int a,b,c,d,f[N][N];
int main()
{
	RI i,j; scanf("%d%d%d%d",&a,&b,&c,&d); f[a][b]=1;
	for (i=a;i<=c;++i) for (j=b;j<=d;++j)
	if (i>a&&j>b) f[i][j]=(1LL*f[i-1][j]*j%mod+1LL*f[i][j-1]*i%mod-1LL*(i-1)*(j-1)*f[i-1][j-1]%mod+mod)%mod;
	else if (i>a) f[i][j]=1LL*f[i-1][j]*j%mod; else if (j>b) f[i][j]=1LL*f[i][j-1]*i%mod;
	return printf("%d",f[c][d]),0;
}

Measured memory_bytes: 48832
c[100][100];n,m;u,t,l,x,y;main(){for(;scanf("%d%d",&n,&m),n;printf("%d\n",l)){int d[100]={0};for(memset(c,9,40000);m--;c[u][l]=c[l][u]=t)scanf("%d%d%d",&u,&l,&t);x=y=l=0;for(u=n;u--;x=t)for(d[x]=1,l+=y,y=x[*c]=**c,m=n;m--;m[*c]<y&&(t=m,y=m[*c]))!d[m]&&c[x][m]<m[*c]&&(m[*c]=c[x][m]);}exit(0);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
string s(int n){
  string ans;
  
  if(n==2){
    ans="110";
    return ans;
  }
  if(n==1){
    ans="1";
    return ans;
  }
  if(n==0){
    ans="0";
    return ans;
  }
  if(n==-1){
    ans="11";
    return ans;
  }
  if(n==-2){
    ans="10";
    return ans;
  }
  
  int b=abs(n%2);
  string c=to_string(b);
  ans=s((n-b)/(-2))+c;
 
  return ans;
}

int main() {
  int n;
  cin >> n;
 
  cout<<s(n)<<endl;
 
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void){
	int a,b;
	char op;
	scanf("%d %c %d",&a,&op,&b);
	while(op!='?'){
		if(op=='+')printf("%d\n", a+b);
		else if(op=='-')printf("%d\n", a-b);
		else if(op=='*')printf("%d\n", a*b);
		else printf("%d\n", a/b);
		scanf("%d %c %d",&a,&op,&b);
	}
	return 0;
}


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


bool is[102][102];
int main(){
	int h,w; cin>>h>>w;
	char grid[102][102];
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>grid[i][j];
	for(int i=0;i<h;i++){
		bool z=true;
		for(int j=0;j<w;j++){
			if(grid[i][j]=='#') z=false;
		}
		if(z) for(int j=0;j<w;j++) is[i][j]=true;
	}	
	for(int j=0;j<w;j++){
		bool zz=true;
		for(int i=0;i<h;i++) if(grid[i][j]=='#') zz=false;
		if(zz) for(int i=0;i<h;i++) is[i][j]=true;
	}
		
	vector<string> v;
	for(int i=0;i<h;i++){
		string s;
		for(int j=0;j<w;j++) if(!is[i][j]){
			s.push_back(grid[i][j]);
		}
		if(!s.empty()) v.push_back(s);
	}
	for(string i:v) cout<<i<<endl;
}


Measured memory_bytes: 256
[M, D] = map(int, input().split())

count = 0
for d in range(22, D+1):
    d10 = int(d / 10)
    d1 = d - d10 * 10
    if (d1 >= 2) and (d10 >= 2) and (M >= d10 * d1):
        count += 1

print(count)


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

using pii = pair<int,int> ;
using pll = pair<long,long> ;
using umpii = unordered_map<int,int> ;
using mpii = map<int,int> ;

#define f first
#define s second

int32_t main(){
	int n;
	cin >> n ;
	int a[n] ;
	for(int i = 0 ; i < n ; i++) cin >> a[i] ;
	int best = 0 , l = 0 ;
	for(int i = 1 ; i < n  ; i++){
		if(a[i] > a[i-1]) l = i ;
		best = max(best,i-l) ;
	}
	cout << best ;
	return 0 ;
}



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

const int N=1e5+5;
int n,cnt[N];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i){
		int x;
		cin>>x;
		cnt[x]++;
	}
	int res=0;
	for(int i=0;i<100000;++i){
		int sum=cnt[i]+cnt[i+1];
		if(i) sum+=cnt[i-1];
		res=max(res,sum);
	}
	cout<<res<<'\n';
}



Measured memory_bytes: 3932
/**
 * Created by hiramekun at 21:04 on 2020-04-02.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */
// 素因数分解
map<ll, ll> prime_factor(ll n) {
    map<ll, ll> mp;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }
    if (n != 1) mp[n]++;
    return mp;
}

// 素数判定
bool is_prime(ll n) {
    for (int i = 2; i * i <= n; i++) if (n % i == 0) return false;
    return n != 1;
}

// 約数列挙
vector<ll> divisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i != n / i) res.emplace_back(n / i);
        }
    }
    return res;
}

void solve() {
    ll n;
    cin >> n;
    vl div = divisor(n);
    sort(all(div));
    ll ans = n;
    each(e, div) {
        if (e * e > n) break;
        ans = min({ans, e + n / e - 2});
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll N,M;
const ll INF = 1e12;

bool f(ll m)
{
	if(M < m * 2) return false;
	if(N + (M - m * 2) / 2 < m) return false;
	return true;
}

int main()
{
	scanf("%lld%lld",&N,&M);

	ll ok = 0,ng = INF,mid;
	while(ng - ok > 1){
		mid = (ok + ng) / 2;
		if(f(mid)){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}

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

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;

    int x = 1;
    for(int i=0; i<n; ++i)
        x = min(x * 2, x + k);
    cout << x << endl;

    return 0;
}


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

int main(){
  string s;
  cin>>s;
  if(s[0]==s[2]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

  return 0;
}


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


int main(){
  ll N, a, b; cin >> N >> a >> b;
  ll h[N];
  rep(i, N){
    cin >> h[i];
  }
  ll ok = 1e9+1, ng = 0;
  while(abs(ok-ng) > 1){
    ll mid = (ok+ng)/2;
    ll cnt = 0, sum = 0; ll c[N];
    rep(i, N){
      c[i] = max((ll)0, h[i]-b*mid);
      sum += (c[i]+a-b-1)/(a-b);
    }
    if(sum<=mid) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
  
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n;
    while(cin >>n,n){
        vector<int> a(n);
        rep(i,n) cin >>a[i];

        int s = 0;
        rep(i,n) s += a[i];

        int ans = 0;
        rep(i,n) ans += (a[i]*n <= s);
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3112
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        na: usize, nb: usize, nm: usize,
        a: [i64; na],
        b: [i64; nb],
        d: [(Usize1, Usize1, i64); nm],
    }

    let ma = a.iter().min().unwrap();
    let mb = b.iter().min().unwrap();
    let md = d.iter().map(|&(x, y, c)| a[x] + b[y] - c).min().unwrap();
    println!("{}", md.min(ma + mb));
}


Measured memory_bytes: 8752
/*
Author: Dynamic JQ

Problem:

Time & Date(start):

Verdict:

Tags:
*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;

LL fac[1000005];
LL inv(LL x)
{
	int t = MOD - 2;
	LL ret = 1LL;
	while(t > 0) {
		if(t & 1) ret = ret * x % MOD;
		x = x * x % MOD;
		t >>= 1;
	}
	return ret;
}

int main()
{
	int n;
	LL ans = 0LL;
	scanf("%d", &n);
	n --;
	fac[0] = 1LL; rep1(i, n) fac[i] = fac[i - 1] * i % MOD;
	for(int i = 0; i * 2 <= n - 3; i ++)
	ans = (ans + (n - 2 - i) * ((fac[n - 3 - i] * fac[n - 1 - i] % MOD) * inv(fac[n - 3 - 2 * i]) % MOD)) % MOD;
	ans = (fac[n] * n - ans + MOD) % MOD;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 8064
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 2e5 + 20;
int n, k, a[N], sum[N];
int ans;
map <int, int> mp;

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

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

		a[i] = (a[i] + k - 1) % k;

		sum[i + 1] = (sum[i] + a[i]) % k;
	}

	for (int i = 0; i <= n; i++)
	{
		if (!mp.count(sum[i])) mp[sum[i]] = 0;
		if (i >= k) mp[sum[i - k]]--;
		
		ans += mp[sum[i]];
		mp[sum[i]]++;
	}

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


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;
typedef long long ll;


int main(){
    string S;
    cin >> S;
    if(S[2] == S[3] && S[4] == S[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    int j = 0;
    ll x = 0;
    ll ans = 0;
    rep(i, n){
        while (j < n && (ll)(x ^ a[j]) == x + a[j]){
            x ^= a[j];
            j++;
        }
        ans += j - i;
        x ^= a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4852
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')
YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int):
    return [NO, YES][N in [i * j for i in range(1, 10) for j in range(i, 10)]]


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(f'{solve(N)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75048
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
int main()
{
    int n, k;
    vector<int> h;
    cin >> n >> k;

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

    int count = 0;
    for (int i=0; i<n; i++)
    {
        if(h[i] >= k)
        {
            count++;
        }
        
    }

    cout << count << endl;

    return 0;
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
    double a,b,h,m; cin >> a >> b >> h >> m;
    double ar = (h+m/60)/12.0*2.0*M_PI;
    double br = m/60.0*2.0*M_PI;

    double theta = ar-br;

    // printf("%.15f %.15f\n", a*sin(ar), b*sin(br));
    double ans = a*a+b*b-2.0*a*b*cos(theta);
    
    printf("%.15f\n", sqrt(ans));
} 

Measured memory_bytes: 4200
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define INF 1000000000000000LL
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl

signed main(){
	IO_STREAM;
	int N,X,Y;
	cin>>N>>X>>Y;

	int G[N+2][3]={0};
	G[1][0]=2;
	rep(i,2,N+1){
		G[i][0]=i+1;
		G[i][1]=i-1;
	}
	G[X][2]=Y;

	map<int,int>ans;
	rep(i,1,N+1){
		queue<int> q;
		q.push(i);
		int dist[N+1]={0};
		while(!q.empty()){
			int v=q.front();q.pop();
			DBG("i=",i,"v=",v);
			rep(j,0,3){
				DBG("j=",j,"G[v][j]=",G[v][j]);
				if(G[v][j]==0) continue;
				if(G[v][j]==N+1) continue;
				if(dist[G[v][j]]>0) continue;
				dist[G[v][j]]=dist[v]+1;
				DBG("dist[G[v][j]]=",dist[G[v][j]],"dist[v]=",dist[v]);
				if(i<G[v][j]){
					ans[dist[v]+1]++;
				}
				q.push(G[v][j]);
			}
		}
	}
	rep(i,1,N){
		cout<<ans[i]<<endl;
	}
	return 0;
}


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

int main(){
  int n;cin >> n;
  vector<int> x(n);
  for(int i=0;i<n;i++){
    cin >> x[i];
  }
  sort(x.begin(),x.end());
  int cnt=0;
  int amin=100000000;
  for(int j=x[0];j<=x[x.size()-1];j++){
    for(int i=0;i<n;i++){
      cnt+=(x[i]-j)*(x[i]-j);
    }
    amin=min(amin,cnt);
    cnt=0;
  }
  cout << amin << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std; typedef long long ll; const ll INF=1e18;
typedef pair<int,int> P;

int main() {
  int n,m; cin>>n>>m;
  ll l[m], r[m], d[m];
  for(int i=0;i<m;i++) cin>>l[i]>>r[i]>>d[i];
  for(int i=0;i<m;i++) l[i]--,r[i]--;

  bool able[m]; fill(able,able+m,false);
  vector<int> c[n];
  for(int i=0;i<m;i++) {
    c[l[i]].push_back(i);
    c[r[i]].push_back(i);
  }
  queue<int> que; ll p[n]; fill(p,p+n,INF);

  bool collapsed=false;

  for(int i=0;i<m;i++) {
    if (able[i]) continue;
    able[i]=true; que.push(i); p[l[i]]=0;

    while(!que.empty()) {
      int id = que.front(); que.pop();
      int L = l[id], R = r[id], D=d[id];
      if (p[L]==INF) p[L]=p[R]-D;
      else if (p[R]==INF) p[R]=p[L]+D;
      else {
        if (p[L] + D != p[R]) collapsed = true;
      }
      for(int x:c[L]) {
        if (!able[x]) able[x]=true, que.push(x);
      }
      for(int x:c[R]) {
        if (!able[x]) able[x]=true, que.push(x);
      }
      c[L].clear(); c[R].clear();
    }

    //if (collapsed) break;
  }

  if (collapsed) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 12800
# verify-helper: PROBLEM https://judge.yosupo.jp/problem/unionfind
import sys

input = sys.stdin.buffer.readline


class UnionFindTree:
    """Disjoint-Set Data Structure

    Union-Find Tree

    complexity:
        - init: O(n)
        - find, unite, same: O(alpha(n))
    """
    __slots__ = ["par", "rank"]

    def __init__(self, n: int) -> None:
        self.par = list(range(n))  # parent
        self.rank = [0] * n  # depth of tree

    def find(self, x: int) -> int:
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> None:
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def is_same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)


def main() -> None:
    N, Q = map(int, input().split())
    uft = UnionFindTree(N)
    ans = []
    for _ in range(Q):
        t, u, v = map(int, input().split())
        if t == 0:
            uft.unite(u, v)
        else:
            ans.append(int(uft.is_same(u, v)))
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()


Measured memory_bytes: 19720
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 
#include <cctype>

using namespace std;

int main() {
    int Num[3];
    int count = 0;
    for (int i = 0; i < 3; i++) {
        cin >> Num[i];
    }

    sort(Num, Num + 3);

    while (Num[2] != Num[0]) {
        if (Num[2] - Num[0] >= 2) {
            Num[0] += 2;
        } else {
            Num[0] += 1;
            Num[1] += 1;
        }
        count++;
        sort(Num, Num + 3);
    }

    cout << count << endl;
    return 0;
}



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

const int MAX_N = 1 << 17;

struct LazySegTree {
	int n;
	struct S {
		int flag;
		int sum;
		int l, r;
		S() : flag(0), sum(0), l(0), r(0) {}
	};
	S node[2 * MAX_N - 1];
	void init(int n_) {
		n = 1;
		while(n < n_) n *= 2;
	}

	void propagate(int k, int len) {
		S& t = node[k];
		if(!t.flag) return;
		if(2 * k + 1 < 2 * n - 1) {
			S& l = node[2 * k + 1];
			S& r = node[2 * k + 2];
			l.flag = r.flag = 1;
			int x = t.l;
			l.l = l.r = r.l = r.r = x;
			l.sum = r.sum = x;
		}
		t.flag = 0;
	}

	void merge(int k, int len) {
		S& t = node[k];
		S& l = node[2 * k + 1];
		S& r = node[2 * k + 2];
		t.sum = l.sum + r.sum;
		if(l.r && r.l) t.sum--;
		t.l = l.l;
		t.r = r.r;
	}

	void query(int a, int b, int x) { query(a, b, x, n, 0, 0, n); }

	void query(int a, int b, int x, int len, int k, int l, int r) {
		if(r <= a || b <= l) return;
		propagate(k, len);
		if(a <= l && r <= b) {
			node[k].flag = 1;
			node[k].l = node[k].r = x;
			node[k].sum = x;
			propagate(k, len);
			return;
		}
		query(a, b, x, len / 2, k * 2 + 1, l, (l + r) / 2);
		query(a, b, x, len / 2, k * 2 + 2, (l + r) / 2, r);
		merge(k, len);
	}
};

int n;
int b[100000];

LazySegTree st;

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

	cin >> n;
	st.init(n);
	string s;
	cin >> s;
	for(int i = 0; i < n; i++) {
		b[i] = s[i] - '0';
	}

	for(int i = 0; i < n; i++) {
		int idx = i + st.n - 1;
		auto& node = st.node[idx];
		node.l = node.r = node.sum = b[i];
	}
	for(int i = st.n - 2; i >= 0; i--) {
		st.merge(i, -1);
	}

	int q;
	cin >> q;
	for(int t = 0; t < q; t++) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		st.query(l, r, x);
		auto node = st.node[0];
		cout << node.sum << endl;
	}
}

Measured memory_bytes: 7836
import fractions
import sys

def lcm(a,b):
    return a * b // fractions.gcd(a,b)

N = int(input())

if N == 2:
    print ("4 7")
    print ("23 10")
    sys.exit()

lis = [2]

now = 3
while len(lis) <= 2 * N:

    flag = True
    for i in lis:
        if now % i == 0:
            flag = False
            break

    if flag:
        lis.append(now)
    now += 2

#print (lis)

ans = [ [1] * N for i in range(N) ]


for i in range(N):

    for j in range(N):

        if (i + j) % 2 == 0:
            ans[i][j] *= lis[(i+j) // 2]

if N % 2 == 1:

    for i in range(N):
        for j in range(N):

            if (i + abs(N-1 - j)) % 2 == 0:
                ans[i][j] *= lis[ -1 - (i + abs(N-1 - j)) // 2 ]

else:
    for i in range(N):
        for j in range(N):

            if (i + abs(N-1 - j)) % 2 == 1:
                ans[i][j] *= lis[ -1 - ((i + abs(N-1 - j) -1 ) // 2)]


#for i in range(N):
#    print (" ".join(map(str,ans[i])))


for i in range(N):
    for j in range(N):

        if (i + j) % 2 == 1:

            t = 1

            if i > 0:
                t = lcm(t,ans[i-1][j])
            
            if j > 0:
                t = lcm(t,ans[i][j-1])
            

            if i < N-1:
                t = lcm(t,ans[i+1][j])
            

            if j < N-1:
                t = lcm(t,ans[i][j+1])

            ans[i][j] = t+1
            

for i in range(N):
    print (" ".join(map(str,ans[i])))


Measured memory_bytes: 93656
#include<stdio.h>
#include<stdlib.h>
typedef struct {
	int id, score;
} team_t;

int cmp(const team_t *x, const team_t *y) {
	return y->score - x->score;
}
int main() {
	team_t team[9999];
	int n, id, i, rank, prevscore;
	for(n=0; scanf("%d,%d", &team[n].id, &team[n].score),team[n].id; n++)
		if(n==100) return 0;
	qsort(team, n, sizeof(team_t), cmp);
	while(~scanf("%d",&id)) {
		rank=0;
		prevscore=-1;
		for(i=0;i<n;i++) {
			if(team[i].score != prevscore)
				rank++;
			prevscore = team[i].score;
			if(team[i].id == id) {
				printf("%d\n", rank);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=1e17;
const ll ms=(5e5)+5;


int ar[500][500];
int ans[500][500]={0};

int main()
{
    idfc;

    int r,c,k;
    cin>>r>>c>>k;
    int i,j;char e;
    for(i=1;i<=r;i++)
    {
        for(j=1;j<=c;j++)
        {
            cin>>e;
            if(e=='#')ar[i][j]=1;
            else ar[i][j]=0;
        }
    }
    int p=1;
    int x,y;
    int kk=0;
    for(i=1;i<=r;i++)
    {
        for(j=1;j<=c;j++)
        {
            if(ar[i][j])
            {
                kk=i;
              //  cout<<i<<" "<<j<<"\n";
              int lim=0;
              for(y=j;y>=1;y--)
              {
                  if(ans[i][y])
                  {
                      lim=y;break;
                  }
                  ans[i][y]=p;
              }
              int fl=0;
              for(x=i-1;x>=1;x--)
              {
                  fl=0;
                  for(y=lim+1;y<=j;y++)
                  {
                      if(ans[x][y]){fl=1; break;}
                  }
                  if(fl)break;
                  for(y=lim+1;y<=j;y++)ans[x][y]=p;
              }
            //    cout<<i<<" "<<j<<"\n";
                p++;
             //   cout<<p<<"\n";
            }
        }
    }
    for(i=kk+1;i<=r;i++)
    {
        for(j=1;j<=c;j++)
        {
            ans[i][j]=ans[i-1][j];
        }
    }
    for(i=1;i<=r;i++)
    {
        for(j=1;j<=c;j++)
        {
            if(ans[i][j])cout<<ans[i][j]<<" ";
            else{
                if(ans[i][j-1])
                {
                    ans[i][j]=ans[i][j-1];
                }
                else{
                    ans[i][j]=ans[i-1][j];
                }
                cout<<ans[i][j]<<" ";
            }
        }
        cout<<"\n";
    }

    return 0;
}

Measured memory_bytes: 4816
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std; using namespace placeholders;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector< int > VI;
typedef vector< vector< int > > VVI;
typedef vector< string > VS;
typedef stringstream SS;
typedef pair< int, int > PII;
typedef vector< pair< int, int > > VPII;
#define VT( T ) vector< T >
#define VVT( T ) vector< vector< T > >
#define LIM( T ) numeric_limits< T >

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) ( c ).begin(), ( c ).end()
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + p, ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

string S;
int L;

int dp[ 512 ][ 512 ];

int solve( const int l, const int r )
{
	int &res = dp[l][r];
	if ( res != -1 )
	{
		return res;
	}
	if ( r <= l )
	{
		return res = 1;
	}
	if ( S[l] != 'm' && S[ r - 1 ] != 'w' )
	{
		return res = 0;
	}
	
	REP( i, l + 1, r - 1 )
	{
		if ( S[i] == 'e' && solve( l + 1, i ) && solve( i + 1, r - 1 ) )
		{
			return res = 1;
		}
	}
	return res = 0;
}

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

	cin >> S;
	L = SZ( S );
	fill( AALL( dp, int ), -1 );

	cout << ( solve( 0, L ) ? "Cat" : "Rabbit" ) << endl;

	return 0;
}

Measured memory_bytes: 2212
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define ff first
#define ss second
#define mp make_pair

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define MOD 1000000007LL
#define N 200005

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


    int n;
    cin>>n;
    cout<<n * 180 - 360;
}


Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var mod=1e9+7;
function abmod(){for(var a=arguments,r=a[0],i=1;i<a.length;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i++])%mod;return r;}

console.log(main());
function main(){
  var n=o.a();
  var k=o.a();
  var m=Math.sqrt(n)|0;
  var dp=xArray(0,k+1,m+1);
  var dp2=xArray(0,k+1,m+1);
  var a=Array(m+1);
  dp[0][1]=1;
  var x=n/m|0;
  a[m]=x-m;
  for(var i=m-1;i;i--){
    a[i]=(n/i|0)-x;
    x+=a[i];
  }
  for(var i=1;i<=k;i++){
    var x=0;
    for(var j=1;j<=m;j++){
      x+=dp[i-1][j];
      x%=mod;
      dp2[i][j]+=abmod(a[j],x);
      dp2[i][j]%=mod;
    }
    for(var j=m;j;j--){
      x+=dp2[i-1][j];
      x%=mod;
      dp[i][j]+=x;
      dp[i][j]%=mod;
    }
  }
  var ans=0;
  for(var i=1;i<=m;i++){
    ans+=dp[k][i]+dp2[k][i];
  }
  return ans%mod;
}

Measured memory_bytes: 135808
N = int(input())
D = list(map(int, input().split()))

C = [[] for _ in range(N)]
X = []
count = 0
ans = 1

for n in range(N):
    C[D[n]].append(D[n])

for i in range(1, max(D)):
    if len(C[i]) == 0:
        count += 1
        break

if count > 0:
    pass
elif D[0] != 0:
    count += 1
elif len(C[0]) != 1:
    count += 1
else:
    for j in range(1,max(D)+1):
        t = len(C[j-1]) ** len(C[j])
        X.append(t)
    for x in X:
        ans = x * ans
        ans = ans % 998244353
        
if count > 0:
    print(0)
else:
    print(int(ans))


Measured memory_bytes: 19556
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

bool isp[10009];
unordered_map<int,int> f[100009];
unordered_map<int,int> ff;

int main(){
	REPP(i,2,1009)isp[i]=1;
	REPP(i,2,1009){
		if(isp[i]){
			for(int j=i*i;j<1009;j+=i)isp[j]=0;
			for(int j=i;j<1009;j+=i){
				int x=j;
				while(x%i==0){
					f[j][i]++;
					x/=i;
				}
			}
		}
	}
	DRI(n);
	REPP(i,1,n+1){
		for(auto j:f[i]){
			ff[j.F]+=j.S;
		}
	}
	LL ans=1;
	for(auto j:ff){
		//printf("%d %d\n",j.F,j.S);
		ans=(ans*(j.S+1))%MOD;
	}
	printf("%lld",ans);
}


Measured memory_bytes: 5888
import numpy as np
import itertools

n, d = map(int, input().split())

X = []

for i in range(n):
    X.append(list(map(int, input().split())))

X = np.array(X)

cnt = 0
for i, j in itertools.combinations(range(n), 2):
    dist = np.linalg.norm(X[i] - X[j])
    if dist == int(dist):
        cnt += 1

print(cnt)

Measured memory_bytes: 12424