akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>

using namespace std;
#define MAX 1000000000

int main(){
    int N;
    vector<int> L;

    cin >> N;
    for (int i = 0; i < N; i++){
        int temp;
        cin >> temp;
        L.push_back(temp);
    }
    int sum = accumulate(begin(L), end(L), 0);

    for (int ii = 0; ii < N; ii++){
        if (L[ii] >= sum - L[ii]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>> s;
  int n = s.length();
  int sum = 0;
  for(int i=0;i<n;i++){
    sum += s[i]-'0';
  }
  if(sum % 9 == 0 ) cout<< "Yes";
  else cout<< "No";
}

Measured memory_bytes: 3704
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
  int n,l;
  cin >> n >> l;
  
  vector<string> s(n);
  for(int i = 0; i < n; i++)
  {
    cin >> s[i];
  }
  
  sort(s.begin(),s.end());
  
  string ans;
  for(int i = 0; i < n; i++)
  {
    ans += s[i];
  }
  
  cout << ans;
  
  return 0;
}

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

using i64 = int64_t;

int main(){
    int r, d, x;
    cin >> r >> d >> x;
    for(int i=0;i<10;++i){
        x = r*x - d;
        cout << x << endl;
    }

    return 0;
}


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

int main(){
  int n,k,x,y,ans = 0;cin >> n >> k >> x >> y;
  for(int i=1;i<=n;++i){
    if(i <= k)ans += x;
    else ans += y;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n=gets.to_i
p=get_i
ans=0
n.times do|i|
  if p[i]==i+1 and i!=n-1
    p[i],p[i+1]=p[i+1],p[i]
    ans+=1
  end
end
if p[n-1]==n
  ans+=1
end
puts ans

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

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

int gcd_of_vector(vector<int> A, int begin, int end){
  int result = A[begin];
  for(int i=begin;i<end;i++){
    result = gcd(A[i],result);
  }
  return result;
}

int gcd_of_vector_with_skip(vector<int> A, int skip){
  int result = A[0];
  if(skip==0)result=A[1];
  for(int i=1;i<A.size();i++){
    if(i==skip)continue;
    result = gcd(A[i],result);
  }
  return result;
}

int main() {
  int gcd1,gcd2,ans,N=getint();
  vector<int> A(N);
  for(int i=0;i<N;i++)A[i]=getint();

  if(N>=100){
    ans=1000000010;
    random_shuffle(A.begin(),A.end());
    gcd1 = gcd_of_vector(A,1,N/2);
    gcd2 = gcd_of_vector(A,N/2,N);
    ans = max(gcd1,gcd2);
  }else{
    ans=0;
    for(int i=0;i<N;i++){
      ans=max(ans,gcd_of_vector_with_skip(A,i));
    }
  }

  cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 1152
n = int(input())
nums = list(map(int, input().split()))
count = 0
for i in range(1, n-1):
  if max(nums[i-1], nums[i], nums[i+1]) != nums[i] and \
     min(nums[i-1], nums[i], nums[i+1]) != nums[i]:
  	count += 1

print(count)
  

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main(){
	string s; cin >> s;
	ll ans = 0;
	ll cnt[26] = {};
	rep(i, 0, s.size()) {
		ans += i - cnt[s[i] - 'a'];
		cnt[s[i] - 'a']++;
	}
	printf("%lld", ans + 1);
	return 0;
}


Measured memory_bytes: 640
n = int(input())
l = list(map(float,input().split()))
dp = [[0 for _ in range(n+1)] for j in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
    dp[i][0] = dp[i-1][0]*(1-l[i-1])
for i in range(1,n+1):
    for j in range(1,n+1):
        dp[i][j] = dp[i-1][j]*(1-l[i-1]) + dp[i-1][j-1]*l[i-1]
ans = 0
for i in range(n//2+1,n+1):
    ans+=dp[n][i]
print(ans)

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

typedef long long ll;

int main(){
  string s;
  cin>>s;
  if(s[0]=='M')cout<<6<<endl;
  else if(s[0]=='T'&&s[1]=='U')cout<<5<<endl;
  else if(s[0]=='W')cout<<4<<endl;
  else if(s[0]=='T'&&s[1]=='H')cout<<3<<endl;
  else if(s[0]=='F')cout<<2<<endl;
  else if(s[0]=='S'&&s[1]=='A')cout<<1<<endl;
  else cout<<7<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int GetPrime(int n){
 int i;

  for(i=2;i<=sqrt(n);i++)
   if(n % i ==0)return 0;

   printf("%d",n);

return 1;
}


int main(){
 int n,i;

 while(scanf("%d",&n)!=EOF){

  for(i=n-1;i>=2;i--)
   if(GetPrime(i))break;

  printf(" ");

  for(i=n+1;i>=0;i++)
   if(GetPrime(i))break;

  printf("\n");

 }

return 0;

}


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

int main () {
    int a, b, c;
    cin >> a >> b >> c;
    // cout << (a) << endl;
    // cout << (b) << endl;
    // cout << (c) << endl;
    cout << (c >= a && c <= b ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC128A
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] n = Console.ReadLine().Split(' ');
			int a = int.Parse(n[0]);
			int b = int.Parse(n[1]);
			int c,d = 0;
			c = a * 3;
			d = c + b;

			Console.WriteLine(d / 2);
		}		
	}
}


Measured memory_bytes: 11092
n, q = map(int, input().split())
s = input()
a = [0] * n
for i in range(1, n):
    a[i] = a[i - 1]
    if (s[i - 1:i+1] == "AC"):
        a[i] += 1
for i in range(q):
    l, r = map(int, input().split())
    print(a[r-1]-a[l-1])


Measured memory_bytes: 7932
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[100005];

void solve()
{
    scanf("%s", str);
    vector<char> v0,v1;
    int n=strlen(str);
    int i;
    for (i = 0; i < n; i++) {
        v0.push_back(str[i]);
    }
    int Q;
    scanf("%d", &Q);
    for (i = 0; i < Q; i++) {
        int a;
        scanf("%d", &a);
        if (a == 1) {
            v0.swap(v1);
        }
        else {
            int b; char str0[5]={0};
            scanf("%d%s", &b, str0);
            if (b == 1) {
                v1.push_back(str0[0]);
            }
            else {
                v0.push_back(str0[0]);
            }
        }
    }
    reverse(v1.begin(),v1.end());
    for (i = 0; i < (int)v0.size(); i++) {
        v1.push_back(v0[i]);
    }
    v1.push_back('\0');
    printf("%s\n", &v1[0]);

    return;
}

int main(int argc, char* argv[])
{
    solve();

	return 0;
}


Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,a[100005],count=0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>=k)
            count++;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long N, W, w[105], v[105], ans[105][100005];
int main (){
ios::sync_with_stdio(0);
cin.tie(0);
	cin >> N >> W;
	for (int i=0;i<N;i++){
		cin >> w[i] >> v[i];
	}
	for(int i=0;i<=N;i++){
		for(int j=0;j<=W;j++){
			if(i==0 || j==0){
				ans[i][j]=0;
			}
			else if(w[i-1]<=j){
				ans[i][j]=max(v[i-1]+ans[i-1][j-w[i-1]], ans[i-1][j]);
			}
			else{
				ans[i][j]=ans[i-1][j];
			}
		}
	}
	cout << ans[N][W];
return 0;
}

Measured memory_bytes: 80128
#include "bits/stdc++.h"
#define ll long long
#define FOR(x) for(ll i = 0;i<(x);i++)
#define ALL(v) (v).begin(),(v).end()


using namespace std;


int main(){
vector<ll> n(3);
FOR(3) cin>>n[i];
sort(ALL(n));
cout<<n[0]+n[1]<<endl;
return 0;
}


Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.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 FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#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
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
string s,t;
int nxt[100001][26];
int main(){
    R(s,t);
    REP(i,26)nxt[SZ(s)][i]=SZ(s);
    for(int i=SZ(s)-1;i>=0;i--){
        REP(j,26)nxt[i][j]=nxt[i+1][j];
        nxt[i][s[i]-'a']=i;
    }
    int now=0;
    int tt=0;
    REP(i,SZ(t)){
        int c=t[i]-'a';
        if(nxt[0][c]==SZ(s)){
            W(-1);
            return 0;
        }
        int v=nxt[now][c];
        if(v==SZ(s)){
            tt++;
            now=0;
            v=nxt[now][c];
        }
        now=v+1;
        if(now==SZ(s)){
            tt++;
            now=0;
        }
    }
    W((LL)tt*SZ(s)+now);
    return 0;
}


Measured memory_bytes: 10752
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n;
int a[300001], b[300001];
string s;
signed main() {
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'E') {
			a[i + 1] = a[i] + 1;
			b[i + 1] = b[i];
		}
		else {
			b[i + 1] = b[i] + 1;
			a[i + 1] = a[i];
		}
	}
	int ans = Inf;
	for (int i = 1; i <= n; i++) {
		ans = min(ans, b[i - 1] + a[n] - a[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5372
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n; cin >> n;
	vl a(n); rep(i,n) cin >> a[i];
	ll ans = 1;
	ll t = 1e18;
	sort(all(a));
	rep(i,n){
		if(a[i] == 0){
			cout << 0 << endl;
			return 0;
		}
		if(t / a[i] < ans){
			cout << -1 << endl;
			return 0;
		}
		ans *= a[i];
	}
	if(ans > t) cout << -1 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 4048
using System;
using System.Collections.Generic;
using System.Linq;

namespace debug
{
    public static partial class Program
    {
        public static void Main()
        {
            var kx = Console.ReadLine().ToLongArray();
            var k = kx[0];
            var x = kx[1];

            var result = new List<long>();
            for (var i = -k + 1; i < k; i++)
            {
                result.Add(x + i);
            }

            Console.WriteLine(result.JoinToStr(" "));
        }
    }

    public static partial class Program
    {
        //テンプレここから
        private static long Gcd(long aaa, long bbb) => bbb == 0 ? aaa : Gcd(bbb, aaa % bbb);
        private static long Lcm(long aaa, long bbb) => aaa * bbb / Gcd(aaa, bbb);
        private static long ToLong(this double ddd) => (long) ddd;
        private static long ToLong(this string str) => long.Parse(str);
        private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
        private static long[] ToLongArray(this string str, char opr = ' ') => str.Split(opr).ToLong();
        private static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb));
        private static long Sign(this long iii) => Math.Sign(iii);
        private static bool IsEven(this long iii) => iii % 2 == 0;
        private static bool IsEven(this int iii) => iii % 2 == 0;

        private static readonly int[] _Dx =
        {
            0, -1, 0, 1
        };

        private static readonly int[] _Dy =
        {
            -1, 0, 1, 0
        };

        public const int MOD = 1000000007;
        public const string UPPER_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const string LOWER_ALPHABET = "abcdefghijklmnopqrstuvwxyz";
        private static long ToLong(this char ccc) => ccc.ToString().ToLong();
        private static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
        private static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);

        private static string JoinToStr(this IEnumerable<long> array, string sep = "") =>
            array.Select(xxx => xxx.ToString()).Join(sep);

        public static string JoinToStr(this IEnumerable<int> array, string sep = "") =>
            array.Select(xxx => xxx.ToString()).Join(sep);

        //テンプレここまで
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1e+5+5;

int n;
struct edge{
	int x,nxt;
}e[N*2];
int h[N],tot;
int ans;
int f[N];

void inse(int x,int y){
	e[++tot].x=y;
	e[tot].nxt=h[x];
	h[x]=tot;
}

bool bz[N];

void dfs(int x){
	bz[x]=1;
	int pre=0,a=0;
	for(int p=h[x];p;p=e[p].nxt)
	if (!bz[e[p].x]){
		dfs(e[p].x);
		a|=(f[e[p].x]&pre);
		pre|=f[e[p].x];
	}
	fo(i,0,17)
	if ((1<<i)>a&&(pre&(1<<i))==0){
		pre=pre^(pre&((1<<i)-1));
		pre^=1<<i;
		ans=max(ans,i);
		break;
	}
	f[x]=pre;
}

int main(){
	n=get();
	fo(i,2,n){
		int x=get(),y=get();
		inse(x,y),inse(y,x);
	}
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

int main(){
	string a,b;
  	cin>>a>>b;
  	int count=0;
  	for(int i=0;i<a.size();i++){
      	if(a[i]!=b[i]){
          count++;
        }
    }
  	cout<<count<<endl;
}

Measured memory_bytes: 3920
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int const MAXL = 2000;

bool ngAC[MAXL*5], ngBC[MAXL*5];

int main() {
  std::string a, b, c; std::cin >> a >> b >> c;
  int aL = a.size(), bL = b.size(), cL = c.size();
  int mL = std::max(aL, std::max(bL, cL));
  std::fill_n(ngAC, MAXL*5, false);
  std::fill_n(ngBC, MAXL*5, false);
  for(int i = 0; i < aL; ++i) for(int j = 0; j < cL; ++j) {
    if(a[i]!='?' && c[j]!='?' && a[i]!=c[j]) ngAC[MAXL*2+i-j] = true;
  }
  for(int i = 0; i < bL; ++i) for(int j = 0; j < cL; ++j) {
    if(b[i]!='?' && c[j]!='?' && b[i]!=c[j]) ngBC[MAXL*2+i-j] = true;
  }
  
  int ans = aL+bL+cL;
  for(int ob = -bL-cL; ob < aL+cL; ++ob) {
    int bl = std::min(0, ob), br = std::max(aL, ob+bL);
    if(br - bl > ans) continue;
    // check AB match
    bool ok = true;
    for(int x = std::max(0, ob); x < std::min(aL, ob+bL); ++x) {
      if(a[x]!='?' && b[x-ob]!='?' && a[x]!=b[x-ob]) { ok = false; break; }
    }
    if(!ok) continue;
    for(int oc = -bL-cL; oc < aL+bL; ++oc) {
      int cl = std::min(bl, oc), cr = std::max(br, oc+cL);
      if(cr - cl > ans) continue;
      if(ngAC[MAXL*2+oc]) continue;
      if(ngBC[MAXL*2+oc-ob]) continue;
      ans = cr - cl;
    }
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 384
n = int(input())
A = [int(x) for x in input().split()]
q = int(input())
M = [int(x) for x in input().split()]

ans = ["no"]*2000

for i in range(1<<n):
    a = 0
    for j in range(n):
        if (i>>j)&1 == 1:
            a += A[j]
    ans[a] = "yes"

for j in M:
    print(ans[j])


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

int main() {
    long long n, input;
    cin >> n;
    long long min = 1000000000;
    long long ans = -999999999;
    cin >> input;
    for (int i=1; i<n; i++) {
        if (input <= min) min = input;
        cin >> input;
        if (ans <= input - min) ans = input - min;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3124
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))

h.sort()

min_diff = 10**9
for i in range(n-k+1):
    diff = h[i+k-1] - h[i]
    min_diff = min(diff, min_diff)

print(min_diff)

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


#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ll long long


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    vector< pii > v(20);

    cin >> n;

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

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

    int s = 0;

    for ( int i = 0; i < n; i++ ) {
        if ( v[i].first > v[i].second ) {
            s += v[i].first - v[i].second;
        }
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
N = list(map(int, input().split()))
count = [0, 0, 0, 0]
for i in range(4):
    if N[i] == 1:
        count[0] += 1
    elif N[i] == 9:
        count[1] += 1
    elif N[i] == 7:
        count[2] += 1
    elif N[i] == 4:
        count[3] += 1
if count[0] == count[1] and count[1] == count[2] and count[2] == count[3] and count[0] == 1:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3064
//08
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int n;
  cin>>n;
  long long d[100][100];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>d[i][j];
    }
  }
  long long m=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      m+=min(d[i][j],d[j][i]);
    }
  }
  cout<<m<<endl;
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<vector<int>> data(3, vector<int>(3));
 
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data.at(i).at(j);
    }
  }
  int A = data.at(0).at(1) - data.at(0).at(0);
  int B = data.at(0).at(2) - data.at(0).at(0);
  int C = data.at(1).at(0) - data.at(0).at(0);
  int D = data.at(2).at(0) - data.at(0).at(0);
  
  if (data.at(1).at(1) - data.at(1).at(0) == A && data.at(1).at(2) - data.at(1).at(0) == B &&
     data.at(2).at(1) - data.at(2).at(0) == A && data.at(2).at(2) - data.at(2).at(0) == B &&
     data.at(1).at(1) - data.at(0).at(1) == C && data.at(2).at(1) - data.at(0).at(1) == D &&
     data.at(1).at(2) - data.at(0).at(2) == C && data.at(2).at(2) - data.at(0).at(2) == D ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;

int main (){
    int n;
    cin >> n;
    int h = n % 10;
    if (h == 9)
        return cout << "Yes", 0;
    n /= 10;
    int g = n % 10;
    if (g == 9)
        return cout << "Yes", 0;
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		// A();
		B();

	}

	private static void B() throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String S = br.readLine();

		br.close();

		String[] AR = S.split("");
		String[] BR = new String[AR.length];

		for (int i = 0, j = 0; i < AR.length; i++) {
			if (!AR[i].equals("B")) {
				BR[j] = AR[i];
				j++;

			} else if (j > 0) {
				j--;
				BR[j] = null;
			}
		}

		for (int i = 0; i < BR.length; i++) {
			if (BR[i] == null)
				break;
			System.out.print(BR[i]);

		}
		System.out.println("");

	}

	private static void A() throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());
		int kosuu = 0;
		br.close();

		for (int i = 0; i <= N; i++) {

			kosuu += i;

		}

		System.out.println(kosuu);
		;

	}

}


Measured memory_bytes: 8148
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long ll;
typedef long double ld;
typedef unsigned long long int ull;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
ll n, m, k, y,x, q, w = 1, sum = 0, ans = 0; string s;
const int MOD = 1000000007;
vector<vector<int>> Gragh;
int main(void) {
	cin >> n; Gragh.resize(n);
	rep(i, n-1) {
		cin >> x >> y;
		Gragh[x - 1].push_back(y - 1);
		Gragh[y - 1].push_back(x - 1);
	}
	vector<int> a(n, -1), b(n, -1);
	queue<int> q,qq; a[0] = 0; b[n - 1] = 0;
	q.push(0); qq.push(0);
	while (!q.empty()) {
		w = q.front(); q.pop();
		x = qq.front(); qq.pop();
		for (int i : Gragh[w]) {
			if (a[i] != -1) continue;
			a[i] = x + 1;
			q.push(i);
			qq.push(x + 1);
		}
	}q.push(n - 1); qq.push(0);
	while (!q.empty()) {
		w = q.front(); q.pop();
		x = qq.front(); qq.pop();
		for (int i : Gragh[w]) {
			if (b[i] != -1)continue;
			b[i] = x + 1; q.push(i);
			qq.push(x + 1);
		}
	}
	rep(i, n) {
		if (a[i] > b[i]) sum++;
		else ans++;
	}if (sum < ans) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
}

Measured memory_bytes: 9572
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int t = 0;
int n;

void dfs_v(v2& a, v2& b, int p){
	p--;
	if(a.at(p).at(0) == -1){
		return;
	}
	b.at(p).push_back(++t);
	a.at(p).at(0) = -1;
	rep(i, a.at(p).at(1)){
		int np = a.at(p).at(2+i);
		dfs_v(a, b, np);
	}
	b.at(p).push_back(++t);
}
void dfs(v2& a, v2& b){
	rep(i, n){
		if(a[i][0] != -1){
			dfs_v(a, b, a[i][0]);
		}
	}
}

int main(){
	cin >> n;
	v2 a(n, v1(0));
	v2 b(n, v1(0));
	rep(i, n){
		int m;
		cin >>m;
		a[i].push_back(m);
		b[i].push_back(m);
		int x;
		cin >> x;
		a.at(i).push_back(x);
		rep(j, x){
			int y;
			cin >> y;
			a.at(i).push_back(y);
		}
	}
	dfs(a, b);
	rep(i, n){
		rep(j, 3){
			cout << b[i][j];
			if(j != 2) cout << " ";
			else cout << endl;
		}
	}
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
 int n,k,i,j;
 cin >>n;
 k = n;

 for(i = 0;i < n;i++)
 {
  k -=4*i;
  for(j = 0;j < n;j++)
  {
   k -=7*j;
   if(k ==0)
   break;
  }
  if(k == 0)
  {
    break;
  }
  k = n;

 }
 if(k == 0)
 {
   cout<<"Yes"<<endl;
 }
 else
 {
   cout<<"No"<<endl;
 }


return 0;

}


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

int main() {
  std::string str;
  std::cin >> str;

  bool ans = true;
  for (int i = 0, len = str.length(); i < len && ans; ++i) {
    if (i % 2 == 0 && str[i] == 'L') ans = false;
    else if (i % 2 == 1 && str[i] == 'R') ans = false;
  }
  
  if (ans) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;

  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

struct td{
    int t;
    int d;
};

bool cmp_d   (struct td& lhs, struct td& rhs){ return lhs.d < rhs.d; }
bool cmp_gr_d(struct td& lhs, struct td& rhs){ return lhs.d > rhs.d; }

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint N, K; cin >> N >> K;
    vector<struct td> vTD(N); for(uint i=0; i<N; ++i){ cin >> vTD[i].t >> vTD[i].d; }
    sort(vTD.begin(), vTD.end(), cmp_gr_d);
    
    unordered_map<int, int> htUN; // a hash table for counting number of used types
    vector<struct td> vTD_rm;     // for remove
    vector<struct td> vTD_add;    // for add
    
    int64 sum =0ll;
    for(uint i=0; i<K; ++i){
        sum += vTD[i].d;
        ++htUN[ vTD[i].t ];
        if(htUN[ vTD[i].t ]>=2){ vTD_rm.push_back( vTD[i] ); }
    }
    sort(vTD_rm.begin(), vTD_rm.end(), cmp_d);
    
    for(uint i=K; i<N; ++i){
        if( htUN[ vTD[i].t ] != 0 ){ continue; }
        vTD_add.push_back( vTD[i] );
    }
    sort(vTD_add.begin(), vTD_add.end(), cmp_gr_d);
    
    int64 numT = K - vTD_rm.size(); // num of type
    int64 point = sum + numT*numT;
    uint ri=0, ai=0;
    while( ri<vTD_rm.size() && ai<vTD_add.size() ){
        if( htUN[ vTD_rm [ri].t ] == 1 ){ ++ri; continue; }
        if( htUN[ vTD_add[ai].t ] >= 1 ){ ++ai; continue; }
        
        sum -= vTD_rm [ri].d; --htUN[ vTD_rm [ri].t ]; ++ri;
        sum += vTD_add[ai].d; ++htUN[ vTD_add[ai].t ]; ++ai;
        
        ++numT;
        
        int64 tmp = sum + numT * numT;
        point = max(point, tmp);
    }
    cout << point << endl;
    
    return 0;
}


Measured memory_bytes: 5540
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	string s;
	ll k;

	cin >> s >> k;

	ll ans = 0;

	if (k == 1 || s[0] != s[s.size() - 1]) {
		FOR(i, 1, s.size()) {
			if (s[i] == s[i - 1]) {
				s[i] = ';';
				ans++;
			}
		}
		ans = ans * k;
	}
	else {
		string ss = s + s;
		char c = s[s.size() - 1];
		FOR(i, 1, ss.size()) {
			if (ss[i] == ss[i - 1]) {
				ss[i] = ';';
				ans++;
			}
		}
		if (c == ss[ss.size() - 1]) {
			ll cnt = 0;
			FOR(i, s.size(), ss.size()) {
				if (ss[i] == ';') {
					cnt++;
				}
			}
			ans = ans + cnt * (k - 2);
			//cout << ss << endl;
		}
		else {
			ll cnt = 0;
			FOR(i, 0, s.size()) {
				if (ss[i] == ';') {
					cnt++;
				}
			}
			ans = ans * (k / 2) + cnt * (k % 2);
			//cout << ss << endl;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
# coding:utf-8

def calc_max_point(e_seq, scores):
    to_win = {'r': 'p', 's': 'r', 'p': 's'}

    if e_seq in ['r' * len(e_seq), 's' * len(e_seq), 'p' * len(e_seq)]:
        if len(e_seq) % 2 == 1:
            return scores[to_win[e_seq[0]]] * (len(e_seq) // 2 + 1)
        else:
            return scores[to_win[e_seq[0]]] * len(e_seq) // 2

    m_seq = ''
    should_wait = False
    ret_val = 0

    for i, e_choice in enumerate(e_seq):
        m_choice = to_win[e_choice]

        if m_seq == '':
            ret_val += scores[m_choice]
            m_seq += m_choice

        else:
            if m_seq[-1] != m_choice:
                ret_val += scores[m_choice]
                m_seq += m_choice
            else:
                try:
                    next_choice = to_win[e_seq[i+1]]
                    if next_choice == m_choice:
                        m_choice = to_win[m_choice]
                        m_seq += m_choice
                except IndexError:
                    m_choice = to_win[m_choice]
                    m_seq += m_choice

    return ret_val


N, K = map(int, input().split(' '))
R, S, P = map(int, input().split(' '))
T = input()

ans = 0

for i in range(K):
    val = calc_max_point(T[i::K], {'r': R, 's': S, 'p': P})
    ans += val

print(ans)

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

#define ll long long

ll N, K;
vector <ll> a; vector <bool> visited;

vector <ll> path; 
ll starting;

void dfs(ll v){
	visited[v] = 1;
	path.push_back(v);
	if (visited[a[v]] == 0){
		dfs(a[v]);
	}else{
		starting = a[v];
		return;
	}
	return;
}

int main(){
	cin >> N >> K; a.resize(N + 1); 
	for (int i = 1; i <= N; i ++) cin >> a[i];
	visited.resize(N + 1, 0);
	dfs(1);
	// for (auto p : path) cout << p << " "; cout << "\n";
	ll ix = find(path.begin(), path.end(), starting) - path.begin(), sz = path.size() - ix;
	if (K < ix){
		cout << path[K] << "\n";
	} else{
		K -= ix;
		cout << path[ix + (K % sz)] << "\n";
	}
}

Measured memory_bytes: 12436
a=[0]*100001
b=[0]*100001

n = int(input())
v = list(map(int,input().split()))

for i in range(0,n,2):
  a[v[i]]+=1
for i in range(1,n,2):
  b[v[i]]+=1

if a.index(max(a))==b.index(max(b)):
  a= sorted(a, reverse=True)
  b= sorted(b, reverse=True)
  print(min(n-a[1]-b[0],n-a[0]-b[1]))
else:
  print(n-max(a)-max(b))
  

Measured memory_bytes: 15940
# -*- coding: utf-8 -*-
x = int(input())

if x < 600:
    print('8')
elif x < 800:
    print('7')
elif x < 1000:
    print('6')
elif x < 1200:
    print('5')
elif x < 1400:
    print('4')
elif x < 1600:
    print('3')
elif x < 1800:
    print('2')
elif x < 2000:
    print('1')


Measured memory_bytes: 9168
#include <stdio.h>

int main(void) {
	unsigned long long factoricals[21];
	int i;
	factoricals[0]=1;
	for(i=1;i<=20;i++) {
		factoricals[i]=factoricals[i-1]*i;
	}
	scanf("%d",&i);
	printf("%llu\n",factoricals[i]);
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
long double pi=3.14159265358979323846L;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int h,w;cin>>h>>w;
    string s[h];
    rep(i,0,h){
        cin>>s[i];
    }
    int ans=0;
    rep(i,0,h*w-1){
        rep(j,i+1,h*w){
            int sh=i/w,sw=i%w,jh=j/w,jw=j%w;
            if(s[sh][sw]=='#'||s[jh][jw]=='#')continue;
            queue<pii> q;
            q.push({sh,sw});
            int d[h][w];
            rep(k,0,h)rep(l,0,w)d[k][l]=1000000000;
            d[sh][sw]=0;
            while(q.size()>0){
                pii p=q.front();q.pop();
                int nh=p.first,nw=p.second;
                rep(k,0,4){
                    int nnh=nh+dh[k],nnw=nw+dw[k];
                    if(nnh<0||nnh>=h||nnw<0||nnw>=w)continue;
                    if(s[nnh][nnw]=='#')continue;
                    if(d[nnh][nnw]<1000000000)continue;
                    d[nnh][nnw]=d[nh][nw]+1;
                    q.push({nnh,nnw});
                }
            }
            ans=max(ans,d[jh][jw]);
        }
    }
    cout<<ans<<endl;
}



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

#define ll long long
#define nums vector<int>
#define words vector<string>
#define letrs vector<char>
#define MOD 1000000007
#define pb push_back
#define llnums vector<ll>

using namespace std;

void solve() {

}
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int s, w;
    cin >> s >> w;
    cout << ((w >= s) ? "unsafe\n" : "safe\n");
    return 0;
}



Measured memory_bytes: 3648
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
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;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    REP(i, 30) {
        if(n - i * 4 >= 0 and (n - i * 4) % 7 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define N 100
void BSort(int sort[],int min,int max);
int main(){
	int a,b;
	int an[3];
	scanf("%d %d",&a,&b);
	an[0]=(a+b);
	an[1]=(a-b);
	an[2]=(a*b);
	BSort(an,0,2);
	printf("%d\n",an[0]);
	return 0;
}
void BSort(int sort[],int min,int max){
	int j,k,l;
	int tmp;
	int flag;
	k=0;
	l=0;
	/* ソートプログラム*/
	do {
		flag = 0;
		for( j=min; j<max-k; j++ ) {
			l++;
			if(sort[j] < sort[j+1] ) {
				flag = 1;
				tmp = sort[j];
				sort[j] = sort[j+1];
				sort[j+1] = tmp;

			}
		}/*ステップの表示*/
		/*for(int t=0;t<N;t++){
			printf("%d ",sort[t]);
		}*/
		k++;
	} while( flag == 1 );
	
}

Measured memory_bytes: 128
import java.io.*;
// import java.math.*;
import java.util.*;
// import java.util.Map.*;
// import java.util.stream.*;

@SuppressWarnings ("unchecked")
public class Main {
    public static <T> List<List<T>> zip (List<T>... lists) {
        List<List<T>> zipped = new ArrayList<List<T>>();
        for (List<T> list : lists) {
            for (int i = 0, listSize = list.size(); i < listSize; i++) {
                List<T> list2;
                if (i >= zipped.size())
                    zipped.add (list2 = new ArrayList<T>());
                else
                    list2 = zipped.get (i);
                list2.add (list.get (i));
            }
        }
        return zipped;
    }
    static List<Character> toCharacterList (String s) {
        if (s == null) {
            return null;
        }
        int len = s.length();
        List<Character> lst = new ArrayList<Character>();
        for (int i = 0; i < len; i++) {
            lst.add (Character.valueOf (s.charAt (i)));
        }
        return lst;
    }
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        List<Character> S = toCharacterList (reader.readLine());
        List<Character> T = toCharacterList (reader.readLine());
        List<List<Character>> z = zip (S, T);
        int ans = 0;
        for (List<Character> v : z) {
            if (!v.get (0).equals (v.get (1)))
                ans++;
        }
        System.out.println (ans);
        return;
    }
}

Measured memory_bytes: 62752
#![allow(non_snake_case)]

use std::io;
use std::str::FromStr;
use std::cmp::max;

macro_rules! parse_tuple {
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
                a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

macro_rules! _I {
    ($stride: expr, $i: expr, $j: expr) => { ($i as usize) * ($stride as usize) + ($j as usize) }
}

fn parse_matrix<T: FromStr>(n_rows: usize, n_cols: usize) -> Vec<T> {
    let mut tmp = String::new();
    let mut v = Vec::with_capacity(n_rows * n_cols);
    for _ in 0..n_rows {
        io::stdin().read_line(&mut tmp).unwrap();
        v.extend(tmp.split_whitespace().filter_map(|s| s.trim().parse().ok()));
        tmp.clear();
    }
    return v;
}

fn main() {
    let (N, M) = parse_tuple!(usize, usize);
    let mat = parse_matrix::<i64>(N, 3);
    let mut max_score = 0;

    for bits in 0..8 {
        let mut tmp = Vec::with_capacity(N);
        for i in 0..N {
            tmp.push(mat[_I!(3, i, 0)] * (-1i64).pow(bits & 1) +
                     mat[_I!(3, i, 1)] * (-1i64).pow((bits >> 1) & 1) +
                     mat[_I!(3, i, 2)] * (-1i64).pow((bits >> 2) & 1));
        }
        tmp.sort_by(|a, b| b.cmp(a));
        max_score = max(max_score, tmp[0..M].iter().sum());
    }
    println!("{}", max_score);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int m, n;
vector<P> M;
vector<P> N;
set<P> N_set;

bool chk(int idx){
  for(int i = 0; i < m; i++){
    P moved = P(N[idx].first + M[i].first - M[0].first, N[idx].second + M[i].second - M[0].second);
    if(N_set.find(moved) == N_set.end()){
      return false;
    }
  }
  return true;
}

int main(void){
  while(cin >> m, m){
    N_set.clear();
    M.clear();
    N.clear();
    M.resize(m);
    for(int i = 0; i < m; i++){
      cin >> M[i].first >> M[i].second;
    }
    cin >> n;
    N.resize(n);
    for(int i = 0; i < n; i++){
      cin >> N[i].first >> N[i].second;
      N_set.insert(N[i]);
    }
    for(int i = 0; i < n; i++){
      if(chk(i)){
        cout << N[i].first - M[0].first << " " << N[i].second - M[0].second << endl;
        break;
      }
    }
  }
  return 0;
}

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

int main() {
    string s;
    cin>>s;
    stack<char>q;
    for(int i=0;i<s.length();i++){
        if(s[i]=='B'){
            if(!q.empty())q.pop();
        }else q.push(s[i]);
    }
    vector<char>v;
    while(!q.empty()){
        char x=q.top();
        v.push_back(x);
        q.pop();
    }
    for(int i=v.size()-1;i>=0;i--)cout<<v[i];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string str;
    cin>>str;
    int n = str.length();
    string last = "";
    int i = 0;
    int ans = 0;
    while(i < n){
        string x = str.substr(i,1);
        //cout<<x<<"\n";
        i++;
        if(i == n){
            if(x == last)break;
            else{
                ans++;
                break;
            }
        }
        while(i < n && x == last){
            x += str[i];
            i++;
        }
        if(i == n){
            if(x == last)break;
            else{
                ans++;
                break;
            }
        }
        ans++;
        //cout<<x<<" "<<last<<"\n";
        last = x;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 640
l=[list(map(int,input().split())) for i in range(int(input()))]
l.sort(key=lambda x:x[2])
for i in range(0,101):
    for j in range(0,101):
        h=l[-1][2]+abs(i-l[-1][0])+abs(j-l[-1][1])
        for a,b,c in l[:-1]:
            if c!=max(0,h-abs(i-a)-abs(j-b)):break
        else:
            print(i,j,h)
            exit()

Measured memory_bytes: 3064