akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include "Local_Debug.h"
using namespace std;
#define Endl endl
#define debug(x) cout << #x << " = " << (x) << endl
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 5;
ll n, a, b, color[MAXN];
struct node
{
	ll a, b, c, pos;
}tmp;
bool cmp1(const node& a, const node& b)
{
	if (a.a != b.a)
		return a.a < b.a;
	return a.b < b.b;
}
bool cmp2(const node& a, const node& b)
{
	return a.pos < b.pos;
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> n)
	{
		vector<node> v;
		memset(color, 0, sizeof(color));
		for (ll i = 1; i < n&&cin >> tmp.a >> tmp.b; ++i)
			tmp.c = 0, tmp.pos = i, v.emplace_back(tmp);
		sort(v.begin(), v.end(), cmp1);
		ll root = 1, mx = 1, cnt = 1;
		for (auto& i : v)
		{
			if (i.a != root)
				cnt = 1, root = i.a;
			if (color[i.a] == cnt)
				cnt++;
			color[i.b] = i.c = cnt++;
			mx = max(mx, cnt - 1);
		}
		sort(v.begin(), v.end(), cmp2);
		cout << mx << endl;
		for (auto i : v)
			cout << i.c << endl;
	}
}
/*
3
1 2
2 3

8
1 2
2 3
2 4
2 5
4 7
5 6
6 8

6
1 2
1 3
1 4
1 5
1 6
*/

Measured memory_bytes: 6640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt() - 1;
        int y = sc.nextInt() - 1;
        
        // dist[i][j] = 点i→jの直接距離
        // i→jとj→iの距離が同じとは限らない
        int[][] dist = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                dist[i][j] = Math.abs(j-i);
            }
        }
        
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if (i <= x && y <= j) {
                    dist[i][j] -= ((y - x) - 1);
                }
                
                dist[i][j] = Math.min(dist[i][j], dist[i][y] + dist[j][y]);
            }
        }
        
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                dist[i][j] = Math.min(dist[i][j], dist[i][y] + dist[j][y]);
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                dist[i][j] = Math.min(dist[i][j], dist[i][x] + dist[x][j]);
            }
        }
        
        int[] hindo = new int[n];
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                hindo[dist[i][j]]++;
            }
        }
        
        for (int i = 1; i < n; i++) {
            System.out.println(hindo[i]);
        }
        
    }
}

Measured memory_bytes: 52560
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define inf INT_MAX/3
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
#define sz size()
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
map<int,int>mp;
set<int> s;
int ar[N];
int main()
{
    fast;
    ll n;cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int a;cin>>a;a--;
        ar[a]++;
    }
    for(int i=0;i<n;i++)
    {
        cout<<ar[i]<<endl;
    }
}




Measured memory_bytes: 4440
A, B, C, X, Y = [int(x) for x in input().split()]
if A + B < 2 * C:
    print(A * X + B * Y)
else:
    money = 0
    if X == Y:
        money = 2 * X * C
    elif X > Y:
        money = 2 * Y * C
        if 2 * C < A:
            money += 2 * (X - Y) * C
        else:
            money += (X - Y) * A
    else:
        money = 2 * X * C
        if 2 * C < B:
            money += 2 * (Y - X) * C
        else:
            money += (Y - X) * B
    print(money)


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

#define INF ((1<<31)-1)  //int32_t
#define MOD 1000000007
#define MOD2  

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

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



int main(){
    bool flag=true;
    ll ans=0,sum=0;
    int h,w;
    cin >>h>>w;

    vector<string> grid(h);
    vector<vector<bool>> pri(h,vector<bool>(w));

    for (int i = 0; i < h; i++)
    {
        cin >>grid[i];
        for (int j = 0; j < w; j++)
        {
            pri[i][j]=true;
        }
        
    }
    

    for (int i = 0; i < h; i++)
    {
        bool same=true;
        for (int j = 0; j < w; j++)
        {
            if(grid[i][j]=='#')same=false;
        }


        if(!same)continue;
        //cout << "row" <<i+1<<endl;
        for (int k = 0; k < w; k++)
        {
            pri[i][k] = false;
        }
    }
    
    for (int i = 0; i < w; i++)
    {
        bool same=true;
        for (int j = 0; j < h; j++){
            if(grid[j][i]=='#')same=false;
        }

        if(!same)continue;

        //cout << "col" <<i+1<<endl;
        for (int k = 0; k < h; k++){
            pri[k][i] = false;
        }
    }

    for (int i = 0; i < h; i++)
    {
        bool printed=false;
        for (int j = 0; j < w; j++)
        {
            if(!pri[i][j])continue;
            cout << grid[i][j];
            printed=true;
        }
        if(printed)cout << endl;
    }
    



    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, C;
long long w[101];
int v[101];

long long dp[101][1000001];

long long solve(int i, int value){
	if(value <= 0) return 0;
	if(i == n) return 1000000000;
	if(dp[i][value] != -1) return dp[i][value];
	
	dp[i][value] = solve(i+1, value);
	dp[i][value] = min(dp[i][value], solve(i+1, value-v[i]) + w[i]);	
	return dp[i][value];
}

int main(){
	cin>>n>>C;
	long long v_sum = 0;
	for (int i = 0; i < n; ++i){
		cin>>w[i]>>v[i];
		v_sum += v[i];
	}

	memset(dp, -1, sizeof dp);
	for(int i = v_sum; i>=0; i--){
		if(solve(0, i) <= C){
			cout<<i<<endl;
			return 0;	
		}
	}
}

Measured memory_bytes: 789248
import sys
sys.setrecursionlimit(10 ** 9)
 
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
 
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
 
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
 
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
 
    
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
 
n, m = map(int, input().split())
uf = UnionFind(n)
 
for i in range(m):
    a, b = map(int, input().split())
    uf.Unite(a, b)
 
ans = 0
 
for i in range(n):
    ans = max(ans, uf.Count(i))
 
print(ans)

Measured memory_bytes: 81840
#include <bits/stdc++.h>
 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define MAX 500005
 #include<iomanip>
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define x first
 #define y second
using namespace std;

 int32_t main()
{
    Need_for_speed(activated);
//    satisfy
//    {
//
//    }
    ll n;cin>>n;
    ll arr[300005]={0};
    fore(i,0,n)cin>>arr[i];
    ll ans=0;
    set<ll>a;
    for(ll i=0;i<n;i++)
    {
        a.insert(arr[i]);
        auto it=a.lower_bound(arr[i]);
      if(it==a.begin())ans++;
    }cout<<ans<<endl;
    return 0;
}
















Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define MOD 1000000007
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define OTP(s) cout<<s<<endl;
#define FOR(i,j,k,l) for(int i=j;i<k;i+=l)
#define REP(i,j) FOR(i,0,j,1)
inline ll add(ll a, ll b){a += b; if(a >= MOD)a -= MOD; return a;}
inline ll sub(ll a, ll b){a -= b; if(a < 0)a += MOD; return a;}
inline ll mul(ll a, ll b){return (ll)((ll) a * b %MOD);}
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

ll min(ll a,ll b)
{
    return a>b?b:a;
}
ll max(ll a,ll b)
{
    return a>b?a:b;
}

int main()
{
    IOS
    ll a;
    cin>>a;
    ll ans=0;
    if(a%2==0)
    {
        while(a)
        {
            ans+=a/10;
            a/=5;
            // trace(ans)
        }
        cout<<ans<<endl;
    }   
    else
    {
        cout<<0<<endl;
    }
    
}

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

int main()
{
    ll a, b, k;
    cin >> a >> b >> k;
    if (k > a) {
        k -= a;
        a = 0;
    } else {
        a -= k;
        printf("%lld %lld\n", a, b);
        return 0;
    }
    if (k > b) {
        b = 0;
        printf("%lld %lld\n", a, b);
        return 0;
    } else {
        b -= k;
        printf("%lld %lld\n", a, b);
        return 0;
    }
}


Measured memory_bytes: 256
// Created by new_sm
//
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
int n,k;
cin>>n>>k;
int a[n];
for(auto &x:a)
cin>>x;
for(int i=k;i<n;i++)
{
	if(a[i]>a[i-k])
	cout<<"Yes";
	else
	cout<<"No";
	cout<<endl;
}

}
int main()
{
//code
fastio
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}




Measured memory_bytes: 4432
def readinput():
    sx,sy,tx,ty=list(map(int,input().split()))
    return sx,sy,tx,ty

def main(sx,sy,tx,ty):
    ans=''
    ans=ans+'U'*(ty-sy)
    ans=ans+'R'*(tx-sx+1)
    ans=ans+'D'*(ty-sy+1)
    ans=ans+'L'*(tx-sx+1)
    ans=ans+'U'+'L'
    ans=ans+'U'*(ty-sy+1)
    ans=ans+'R'*(tx-sx+1)
    ans=ans+'D'*(ty-sy+1)
    ans=ans+'L'*(tx-sx)
    return ans

if __name__=='__main__':
    sx,sy,tx,ty=readinput()
    ans=main(sx,sy,tx,ty)
    print(ans)


Measured memory_bytes: 9160
<?php

    fscanf(STDIN,"%d%d",$A,$B);
    
    $ans=0;
    $i=0;
    while($ans<$B){
        
       $ans = ($A*$i) - $i + 1;
    //   echo $ans;
       $i++;
    }
    echo $i-1;
?>

Measured memory_bytes: 16132
# encoding:utf-8
def main():
	A, B = list(map(int, input().split()))
	ptrs = [A, B, A + B]
	res = [x % 3 for x in ptrs]
	if 0 in res:
		print("Possible")
	else:
		print("Impossible")

if __name__ == '__main__':
	main()

Measured memory_bytes: 2940
import java.util.Scanner;

class Main {
	int[][] c;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}
	Main(Scanner sc){
		c = new int[3][3];
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				c[i][j] = sc.nextInt();
			}
		}
	}
	void solve(){
		int[] a = new int[3];
		int[] b = new int[3];
		int min = Math.min(c[0][0], Math.min(c[0][1], c[0][2]));
		for(int i=0;i<=min;i++){
			a[0] = i;b[0] = c[0][0] - a[0];b[1] = c[0][1] - a[0];b[2] = c[0][2];
			a[1] = c[1][0] - b[0];a[2] = c[2][1] - b[1];
			//System.out.printf("a1=%-2d a2=%-2d a3=%-2d b1=%-2d b2=%-2d b3=%-2d\n",a[0],a[1],a[2],b[0],b[1],b[2]);
			if(c[0][0]==a[0]+b[0]&&c[0][1]==a[0]+b[1]&&c[0][2]==a[0]+b[2]){
				if(c[1][0]==a[1]+b[0]&&c[1][1]==a[1]+b[1]&&c[1][2]==a[1]+b[2]){
					if(c[2][0]==a[2]+b[0]&&c[2][1]==a[2]+b[1]&&c[2][2]==a[2]+b[2]){
						System.out.println("Yes");
						System.exit(0);
					}
				}
			}
		}
		System.out.println("No");
	}
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

int main(){
   ll N; cin >> N;
   vector<ll> L(N);
   REP(i, N) cin >> L[i];
   SORT(L);
   ll temp = 0;
   REP(i, N - 1) temp += L[i];
   cout << ((temp > L[N - 1]) ? "Yes" : "No") << endl;
}


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

int T[2],R[2];
int main(){
    cin >> T[0] >> T[1] >> R[0] >> R[1];
    if(R[0]>-1 && R[1]>-1){
        if(R[0]==R[1]) cout << "Draw" << endl;
        else cout << (R[0]>R[1]? "Alice":"Bob") << endl;
    }else{
        if(T[0]==T[1]) cout << "Draw" << endl;
        else cout << (T[0]>T[1]? "Bob":"Alice") << endl;
    }
}


Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int k;
    string s;
    cin >> k >> s;
    if (s.size() <= k) {
        cout << s << endl;
    } else {
        for (int i = 0; i < k; i++) cout << s[i];
        cout << "..." << endl;
    }
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
const int MOD=1e9+7;



int main(){
    int h,w;
    cin>>h>>w;
    char **grid=new char*[h];
    for(int i=0;i<h;i++){
      grid[i]=new char[w];
    }

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin>>grid[i][j];
      }
    }

    int **dp=new int*[h];
    for(int i=0;i<h;i++){
      dp[i]=new int[w];
    }

    dp[h-1][w-1]=0;
    if(grid[h-1][w-2]=='.'){
      dp[h-1][w-2]=1;
    }
    else{
      dp[h-1][w-2]=0;
    }
    for(int i=w-3;i>=0;i--){
      if(grid[h-1][i]=='#'){
        dp[h-1][i]=0;
      }
      else
      dp[h-1][i]=dp[h-1][i+1];
    }

    if(grid[h-2][w-1]=='.'){
      dp[h-2][w-1]=1;
    }
    else{
      dp[h-2][w-1]=0;
    }

    for(int i=h-3;i>=0;i--){
      if(grid[i][w-1]=='#'){
        dp[i][w-1]=0;
      }
      else{
        dp[i][w-1]=dp[i+1][w-1];
      }
    }


    for(int i=h-2;i>=0;i--){
      for(int j=w-2;j>=0;j--){
        if(grid[i][j]=='#'){
          dp[i][j]=0;
        }
        else{
          dp[i][j]=(dp[i+1][j]%MOD +dp[i][j+1]%MOD)%MOD;
        }
      }
    }















































    cout<<dp[0][0]<<endl;


    return 0;
}


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

using namespace std;
vector<long long int> t(200001, 0);
int main()
{
	long long int during = 0;
	long long int total = 0;
	long long int nowtime = 0;
	long long int input;
	long long int  N, T;
	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		cin >> input;

		if (during <= input) {
			total += T;
			during = input + T;
		}
		else {

			total += T - (during - input);
			during = input + T;
		}

	}

	cout << total << endl;


	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "
#define F           first
#define S           second
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll i;
    for(i=0;i<b;i++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    ll n,k,i;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<ll> v;
    ll c=0;
    ll cc=0; // abhi ka answer;
    c=1;
    map<char,vector<ll> >m;
    for(i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            {c++;
            cc++;
            }
        else
        {   m[s[i-1]].pb(2LL);
            v.pb(c);
            c=1;
        }
    }
    m[s[i-1]].pb(2LL);
    map<char,vector<ll> >::iterator it;
    for(it=m.begin();it!=m.end();it++)
        sort(all(it->S));
    vector<ll> v1=m[s[0]];
    v1[v1.size()-1]--;
    sort(all(v1));
    m[s[0]]=v1;
     v1=m[s[n-1]];
    v1[v1.size()-1]--;
    sort(all(v1));
    m[s[n-1]]=v1;
    ll s1=0;
    ll maxi=-1;
    for(it=m.begin();it!=m.end();it++)
        {
            vector<ll> g=it->S;
            reverse(all(g));
            for(i=0;i<min((ll)g.size(),k);i++)
                s1+=g[i];
            maxi=max(maxi,s1);
            s1=0;
        }
    cout<<cc+maxi;
    return 0;
}




Measured memory_bytes: 2876
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define all(v) (v).begin(),(v).end()
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using int32 = int32_t; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
#define FASTCIN() cin.tie(0);ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
#define DEBUG_IMPORT(file) vs args(argv, argv+argc);str sample = make_sample(args, file);ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#else
#define DEBUG_IMPORT(file)
#endif
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}

bool first_greater(const tiii& left, const tiii& right) {
    return tv(left, 0) > tv(right, 0);
}

int greedy_bit_fs(vector<tiii>& item, int LowLimit) {
    sort(all(item), first_greater);
    int N = item.size();
    int res = INF;
    REP(p, 1<<N) {
        int ptn = p;
        int scr = 0;
        int cnt = 0;
        REP(i,N) {
            int vi = tv(item[i], 0);
            int ci = tv(item[i], 1);
            if (ptn & 0b01) {
                scr += vi * ci + tv(item[i], 2);
                cnt += ci;
                if (scr >= LowLimit)
                    res = min(res, cnt);
            } else {
                for(int j = ci-1; j >= 0; j--) {
                    if (scr + vi * j >= LowLimit) {
                        res = min(res, cnt + j);
                    } else {
                        break;
                    }
                }
            }
            ptn >>= 1;
        }
    }
    return res;
}


int32 main(int32 argc, char* argv[]) {
    FASTCIN();
    DEBUG_IMPORT("sample-1");


    int D, G; cin>>D>>G;
    vi P(D), C(D); REP(i,D) cin>>P[i]>>C[i];

    vector<tiii> item(D);
    REP(i,D)
        item[i] = mktp((i+1)*100, P[i], C[i]);

    int ans = greedy_bit_fs(item, G);

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
    vector<int> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;

      v[0]=v[1]=false;
    for(int i = 2;i<1000;i++){
      if(v[i]){
        for(int j=i*i;j<MAX;j+=i){
         v[j]=false;
       }
      }
    }
    for(int i = 2;i<MAX;i++)v[i]+=v[i-1];
    while(true){
      int a;
      cin >> a;
      if(cin.eof())break;;
      cout << v[a] << endl;
    }
    return 0;
}



Measured memory_bytes: 6580
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

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

    int n;
    cin >> n;
    VI a(n*3);
    REP(i,3*n) cin >> a[i];
    MinHeap<int> qL;
    LL sumL=0;
    REP(i,n) {
        qL.push(a[i]);
        sumL+=a[i];
    }
    MaxHeap<PII> qR;
    MinHeap<PII> cand;
    LL sumR=0;
    vector<bool> used(3*n,0);
    for ( int i=n; i<3*n; i++ ) {
        qR.push(make_pair(a[i],i));
        sumR+=a[i];
        used[i]=1;
        if ( qR.size()>n ) {
            sumR-=qR.top().first;
            used[qR.top().second]=0;
            cand.push(qR.top());
            qR.pop();
        }
    }
    LL ans=sumL-sumR;
    for ( int i=n; i<2*n; i++ ) {
        sumL+=a[i];
        qL.push(a[i]);
        sumL-=qL.top();
        qL.pop();      
        if ( used[i] ) {
            sumR-=a[i];
            used[i]=0;
            while ( cand.size() && cand.top().second<=i ) {
                cand.pop();
            }
            sumR+=cand.top().first;
            used[cand.top().second]=1;
            cand.pop();
        }
        chmax(ans, sumL-sumR);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4212
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 1000000001
#define PI 3.14159265358979323846
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	int a[4];
	for(int i = 0; i < 4; i++)
		a[i]=0;
	for(int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		if(s=="AC")
			a[0]++;
		else if(s=="WA")
			a[1]++;
		else if(s=="TLE")
			a[2]++;
		else
			a[3]++;
	}
	cout << "AC x " << a[0] << '\n';
	cout << "WA x " << a[1] << '\n';
	cout << "TLE x " << a[2] << '\n';
	cout << "RE x " << a[3] << '\n';
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    string t;
    cin >> t;
    rep(i,t.size()) tolower(t.at(i));
    int cnt = 0;
    while(true){
        string s;
        cin >> s;
        if(s.at(s.size()-1) == '.'){
            s.pop_back();
        }
        if(s == "END_OF_TEXT") break;
        rep(i,s.size()){
            if(s.at(i) <= 'Z' && s.at(i >= 'A')) s.at(i) -= 'A' - 'a';
        }
        if(s == t) cnt++;
        
    }
    cout << cnt<< endl;

return 0;
}


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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 85;

int arr[maxr];
int32_t main()
{
	GO;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];

	int yan = 1000;
	int stock = 0;
	for (int i = 1; i < n; i++) {
		if (arr[i - 1] < arr[i]) {
			// int times = 0;
			// while (arr[i - 1] * times <= yan)
			// 	times++;
			int times = (yan / arr[i - 1]);
			yan -= arr[i - 1] * times;
			stock += times;
			// while (stock > 0)
			// 	yan += arr[i], stock--;
			yan += (arr[i] * stock);
			stock = 0;
		}
	}
	cout << yan << endl;
	return 0;
}

//!

Measured memory_bytes: 3604
import scala.io.StdIn.readLine

object Main {
  def main(args:Array[String]):Unit = {
    println {
      Iterator.continually(readLine).takeWhile(_.toInt!=0).map { s=>
        var n = s
        var cnt = 0
        if(n.sortWith(_>_).toInt - n.sorted.toInt == 0) "NA"
        else {
          while(n!="6174") {
            n = "%04d".format((n.sortWith(_>_).toInt - n.sorted.toInt))
            cnt += 1
          }
          cnt
        }
      }.mkString("\n")
    }
  }
}

Measured memory_bytes: 163024
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
ll keta(ll x) {
	ll res = 0;
	while (x > 0) {
		x /= 10; res++;
	}
	return res;
}
ll test[12345678], res[12345678];
signed main() {
	map<ll, ll> cost;
	ll n, m, a = 0, b, c, x, cnt = 0, ans = 0; string s, t, u;
	cin >> n; a = sqrt(n);
	for (ll h = a + 1; h >= 1; h--) {
		if (n % h == 0) {
			cout << max(keta(n / h), keta(h)) << endl; return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#damedatta..
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ms = 0
    ps = 0
    mr = 0
    pr = 0
    for i, v in enumerate(a):
        if i % 2:
            if ms + v < 0:
                ms += v
            else:
                mr += abs(-1 - ms - v)
                ms = -1
            if ps + v > 0:
                ps += v
            else:
                pr += abs(1-ps-v)
                ps = 1
        else:
            if ms + v > 0:
                ms += v
            else:
                mr += abs(1-ms-v)
                ms = 1
            if ps + v < 0:
                ps += v
            else:
                pr += abs(-1-ps-v)
                ps = -1
    return min(mr, pr)
print(main())


Measured memory_bytes: 14468
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line1 = sc.nextLine();
        int n = Integer.parseInt(line1);
        String[] lines = new String[n];
        for(int i = 0; i < n; i++) {
            lines[i] = sc.nextLine();
        }
        int[] nums = new int[3];
        for(int i = 0; i < n; i++) {
            String[] line = lines[i].split(" ");
            nums[0] = Integer.parseInt(line[0]);
            nums[1] = Integer.parseInt(line[1]);
            nums[2] = Integer.parseInt(line[2]);
            Arrays.sort(nums);
            if(Math.pow(nums[0], 2) + Math.pow(nums[1], 2) == Math.pow(nums[2], 2)) {
                System.out.println("YES");                
            }else {
                System.out.println("NO");
            }
        }
        
    }
 } 


Measured memory_bytes: 31492
/*
      author  : nishi5451
      created : 15.08.2020 21:40:59
*/

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


int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n),c(n);
    rep(i,n) cin >> p[i];
    rep(i,n) p[i]--;
    rep(i,n) cin >> c[i];

    ll ans = -1e18;
    rep(i,n){
        int ini = i;
        int now = i;
        vector<int> s;
        ll tot = 0;
        while(1){
            now = p[now];
            tot += c[now];
            s.push_back(c[now]);
            if(now == ini) break;
        }
        int len = s.size();
        ll score = 0;
        rep(i,len){
            score += s[i];
            if(i+1 > k) break;
            if(tot > 0){
                ll e = (k-i-1)/len;
                ans = max(ans,score+e*tot);
            }
            else{
                ans = max(ans,score);
            }
        }
    }
    cout << ans << endl;
        
    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    ll ans=0;
    ll a,min,max,now;
    sort(be(v));
    vector<ll>::iterator itr;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            a=v[i]+v[j];
            min=0;
            max=n;
            now=(min+max)/2;
            while(now!=min){
                if(v[now]<a){
                    min=now;
                }else{
                    max=now;
                }
                now=(min+max)/2;
            }
            ans+=min-j;
        }
    }
    cout << ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
a = []
for i in range(n-1):
    a.append(1) if s[i:i+2] == 'AC' else a.append(0)
b = [0] * 100000
b[0] = a[0]
for i in range(1,n-1):
    b[i] = b[i-1] + a[i]

for i in range(q):
    l, r = map(int, input().split())
    print(b[r-2] - b[l-2])

Measured memory_bytes: 10124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <sstream>
#include <math.h>
#include <functional>

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007

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

int main() {
	int a, b;
	cin >> a >> b;
	if (b == 1) {
		cout << 0 << endl;
		return 0 ;
	}
	int ko = 1;
	int result = 0;
	rep(i, 100) {
		if (b <= (a - 1) * (i - 1) + a) {
			result = i;
			break;
		}
	}
	cout << result << endl;


}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;
//emplace_back next_permutation tie get

typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define OUT(a) cout<<(a)<<endl;
#define M__ 100010

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL w,h,ans=0;
    vector<pair<int,char>> a;

    cin >> w >>h;
    REP(i,w){
        LL tmp;
        cin >> tmp;
        ans+=tmp;
        a.push_back(make_pair(tmp,'p'));
    }
    REP(i,h){
        LL tmp;
        cin >> tmp;
        ans+=tmp;
        a.push_back(make_pair(tmp,'q'));

    }
    sort(a.begin(),a.end());

    REP(i,a.size()){
        LL x=a[i].first;
        char y=a[i].second;
        //a.erase(a.begin());
        if(y=='p'){
            ans+=h*x;
            w--;
        }else{
            ans+=w*x;
            h--;
        }
        //OUT(ans)
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& e : v)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;

    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }

    ll find(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool merge(ll x, ll y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return find(x) == find(y);
    }

    ll size(ll x) {
        return siz[find(x)];
    }
};

int main(){
    ll N,M,K;cin >> N >> M >> K;
    vvl fri(N, vl());
    vvl teki(N, vl());
    vl a(M),b(M);rep(i,M) cin >> a[i] >> b[i];
    vl c(K),d(K);rep(i,K) cin >> c[i] >> d[i];

    UnionFind uf(N);
    rep(i,M){
        uf.merge(--a[i],--b[i]);
    }
    rep(i,M){
        fri[a[i]].push_back(b[i]);
        fri[b[i]].push_back(a[i]);
    }
    rep(i,K){
        teki[--c[i]].push_back(--d[i]);
        teki[d[i]].push_back(c[i]);
    }
    rep(i,N){
        ll br = 0;
        rep(j,teki[i].size()){
            if (uf.issame(i,teki[i][j])) br++;
        }
        cout << uf.size(i) - fri[i].size() - br -1<< " ";
    }
    cout << endl;
    return 0;
}

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

int INF=1000000;
queue<pair<int,int> > que;
vector<int> dx(4,0),dy(4,0);

void bfs(vector<vector<char> > &map,vector<vector<int> > &d){
    pair<int,int> p;
    while(que.size()>0){
        p=que.front();
        que.pop();
        for(int i=0;i<4;i++){
            int nx=p.first+dx.at(i),ny=p.second+dy.at(i);
            if(0<=nx&&nx<map.size()&&0<=ny&&ny<map.at(0).size()&&map.at(nx).at(ny)!='#'&&d.at(nx).at(ny)==INF){
                pair<int,int> np;
                np.first=nx;
                np.second=ny;
                que.push(np);
                d.at(nx).at(ny)=d.at(p.first).at(p.second)+1;
            }
        }
    }
    return;
}
int main(){
    int H,W;
    cin>>H>>W;
    vector<vector<char> > map(H,vector<char> (W));
    vector<vector<int> > d(H, vector<int>(W,INF));
    dx.at(0)=1;
    dx.at(2)=-1;
    dy.at(1)=1;
    dy.at(3)=-1;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>map.at(i).at(j);
            if(map.at(i).at(j)=='#'){
                pair<int,int> p;
                p.first=i;
                p.second=j;
                que.push(p);
                d.at(i).at(j)=0;
            }
        }
    }
    bfs(map,d);
    int fintime=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            fintime=max(d.at(i).at(j),fintime);
        }
    }
    cout<<fintime<<endl;
    
}

Measured memory_bytes: 13328
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int h[n],cost[n],i,j;
  for(i=0;i<n;i++)
    cin>>h[i];
  cost[0]=0;
  cost[1]= abs(h[1] - h[0]);
  if(n>2)
  {
    for(i=2;i<=k;i++)
    {
    cost[i] = cost[i-1] + abs(h[i]-h[i-1]);
    
      for(j=1;j<=i;j++)
      {
        cost[i] = min(cost[i], cost[i-j] + abs(h[i]-h[i-j]));
      }
    }
  
  for(i=k+1;i<n;i++)
  {
    cost[i] = cost[i-1] + abs(h[i]-h[i-1]);
    for(j=2;j<=k;j++)
    cost[i] = min(cost[i],cost[i-j] + abs(h[i]-h[i-j]));
  }
  }
  cout<<cost[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 
#define P 998244353
#define G 3
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
#define fuck printf("FUCK!!\n");
using namespace std;

int n, cnt, tot;
pair<int,int> e[100000], ans[1000000];

int main()
{
    scanf("%d", &n);
    for(rint i=1; i<=n/2; ++i) e[++cnt]=make_pair(i, n-i+(n%2==0));
    for(rint i=1; i<=cnt; ++i)
    {
        for(rint j=i+1; j<=cnt; ++j)
        {
            ans[++tot]=make_pair(e[i].first, e[j].first);
            ans[++tot]=make_pair(e[i].first, e[j].second);
            ans[++tot]=make_pair(e[i].second, e[j].first);
            ans[++tot]=make_pair(e[i].second, e[j].second);
        }
        if(n&1)
        {
            ans[++tot]=make_pair(e[i].first, n);
            ans[++tot]=make_pair(e[i].second, n);
        }
    }
    printf("%d\n", tot);
    for(rint i=1; i<=tot; ++i) printf("%d %d\n", ans[i].first, ans[i].second);
    return 0;
}

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

using namespace std;

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

// 素集合データ構造
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

// 頂点a, bをつなぐコストcostの（無向）辺
struct Edge
{
  int a, b, cost;

  // コストの大小で順序定義
  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
  int n;  // 頂点数
  vector<Edge> es;  // 辺集合

  // クラスカル法で無向最小全域木のコストの和を計算する
  // グラフが非連結のときは最小全域森のコストの和となる
  int kruskal() {
    // コストが小さい順にソート
    sort(es.begin(), es.end());

    UnionFind uf(n);
    int min_cost = 0;

    rep(ei, es.size()) {
      Edge& e = es[ei];
      if (!uf.same(e.a, e.b)) {
        // 辺を追加しても閉路ができないなら、その辺を採用する
        min_cost += e.cost;
        uf.unite(e.a, e.b);
      }
    }

    return min_cost;
  }
};


int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> x(N);
  vector<pair<int,int>> y(N);

  rep(i,N){
    cin >> x[i].first >> y[i].first;
    x[i].second = i;
    y[i].second = i;
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());

  Graph g;
  g.n = N;
  Edge e;
  rep(i,N-1){
    e.a = x[i].second;
    e.b = x[i+1].second;
    e.cost = x[i+1].first - x[i].first;
    g.es.push_back(e);
  }
  rep(i,N-1){
    e.a = y[i].second;
    e.b = y[i+1].second;
    e.cost = y[i+1].first - y[i].first;
    g.es.push_back(e);
  }
  cout << g.kruskal() << endl;

  return 0;

}


Measured memory_bytes: 6516
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> aabs(n);
    vector<bool> s(n);
    REP(i, n) {
        cin >> a[i];
        aabs[i] = abs(a[i]);
        s[i] = a[i] < 0;
    }

    // accumulation
    ll asum = accumulate(ALL_OF(aabs), 0LL);

    // simulation
    REP(i, n-1) {
        if (s[i]) {
            s[i  ] = !s[i  ];
            s[i+1] = !s[i+1];
        }
    }

    // answer
    ll ans;
    if (s[n-1]) {
        ans = asum - 2 * *min_element(ALL_OF(aabs));
    } else {
        ans = asum;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 1792
#include<stdio.h>
#define INF 1000000000
int main(){
  int N, p, sum, i, min;
  int unused __attribute__((unused));
  int x[100];

  unused = scanf("%d", &N);
  for(i=0; i<N; i++) unused = scanf("%d", &x[i]);

  min = INF;
  for(p=1; p<=100; p++){
    sum = 0;
    for(i=0; i<N; i++) sum += (x[i] - p)*(x[i] - p);
    if(sum < min) min = sum;
  }

  printf("%d", min);

  return 0;
}

Measured memory_bytes: 128