akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){
  int A = 0, B = 0, C = 0, D = 0;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

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

int main()
{
	ll N, V;
	cin >> N >> V;
	vector<ll> a(N), b(N), c(N), d(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> c[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	vector<ll> e(N * N), f(N * N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			e[i * N + j] = a[i] + b[j];
			f[i * N + j] = c[i] + d[j];
		}
	}
	ll res = 0;
	sort(f.begin(), f.end());
	for (int i = 0; i < N * N; i++) {
		auto p = equal_range(f.begin(), f.end(), V - e[i]);
		res += p.second - p.first;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 18396
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if (a>=k){
    cout<<k<<endl;}
 else if(k-a<=b){cout<<a<<endl;}
else {cout<<2*a+b-k<<endl;}
}

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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> tasks(n);
    rep(i,n){
        int a,b,c;
        cin >> a >> b >> c;
        tasks.at(i).push_back(a);
        tasks.at(i).push_back(b);
        tasks.at(i).push_back(c);
    }

    vector<ll> dp(3), p(3);
    p[0] = tasks[0][0];
    p[1] = tasks[0][1];
    p[2] = tasks[0][2];
    for(int i=1;i<n;i++){
        swap(dp,p);
        p[0] = max(dp[1], dp[2]) + tasks[i][0];
        p[1] = max(dp[0], dp[2]) + tasks[i][1];
        p[2] = max(dp[0], dp[1]) + tasks[i][2];
    }
    ll res = max(max(p[0],p[1]),p[2]);
    cout << res << endl;
    return 0;
}

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

int main(){

    while(1){

    int n,m;

    int tsum=0,hsum=0;

    cin>>n>>m;

    if(n==0 && m == 0) break;

    vector<int> taro(n);

    vector<int> hana(m);

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

        cin>>taro[i];

        tsum += taro[i];

    }

    for(int i=0; i<m; i++){
        
        cin>>hana[i];

        hsum += hana[i];
    }

    int ans1,ans2,jud=10000;

    //half = (tsum + hsum) / 2;

    bool flag = false;

    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){

            //if( tsum - half - taro[i] + hana[j] == hsum - half -hana[j] + taro[[i]])

            if( tsum + 2 * hana[j] == hsum + 2 * taro[i]){
                if(jud > hana[j] + taro[i] ){

                    jud = hana[j] + taro[i];

                    ans1 = taro[i];

                    ans2 = hana[j];

                    flag = true;
                }
            }
        }
    }

    if(flag) cout<<ans1<<" "<<ans2<<endl;

    else cout<<-1<<endl;
    }

    return 0;
}


Measured memory_bytes: 3064
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

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

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

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    ll N;
    cin >> N;
    //vector<vector<int>> data(3, vector<int>(4));
    //初期値0
    //vector<int> data(i, 0);
    vl monsters(N+1);
    vl heros(N);
    ll res = 0;
    rep(i, 0, N+1) {
        cin >> monsters[i];
    }
    rep(i, 0, N) {
        cin >> heros[i];
    }
    rep(i, 0, N) {
        if (monsters[i] >= 1) {
            if (heros[i] >= monsters[i]) {
                res += monsters[i];
            } else {
                res += heros[i];
            }
            ll temp = monsters[i];
            monsters[i] -= heros[i];
            heros[i] -= temp;
            if (heros[i] <= 0) {
                continue;
            }
        }

        if (monsters[i+1] >= 1) {
            if (heros[i] >= monsters[i+1]) {
                res += monsters[i+1];
            } else {
                res += heros[i];
            }
            ll temp = monsters[i+1];
            monsters[i+1] -= heros[i];
            heros[i] -= temp;
        }
    }
        
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h> 
 
 
 int main(){ 
     int m, f, r; 
     while(1){ 
         scanf("%d %d %d ", &m, &f, &r); 
         if(m==-1&&f==-1&&r==-1)break; 
         if(m==-1||f==-1){ 
             printf("F\n"); 
         }else if(m+f>=80){ 
             printf("A\n"); 
         }else if(m+f>=65){ 
             printf("B\n"); 
         }else if(m+f>=50){ 
             printf("C\n"); 
         }else if(m+f>=30){ 
             if(r>=50){ 
                 printf("C\n"); 
             }else{ 
                 printf("D\n"); 
             } 
         }else{ 
             printf("F\n"); 
         } 
     } 
     return 0; 
 } 



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

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

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

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> broken(n+1);
  for(int i = 0; i < m; i++){
    int a;
    std::cin >> a;
    broken[a] = 1;
  }

  std::vector<int> dp(n+2);
  const int mod = 1000000007;

  dp[n] = 1;

  for (int i = n-1; i >= 0; i--) {
    if (broken[i]) {
      dp[i] = 0;
      continue;
    }
    dp[i] = (dp[i+1] + dp[i+2]) % mod;
  }
    std::cout << dp[0] << std::endl;
  return 0;
}    


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f3f3f3f3f
#define pi 3.1415926535898
#define N 200050
using namespace std;
const ll mod=1e9+7;

int main()
{
    int x;
    cin>>x;
    if(x>=30)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> WA(N);
  vector<bool> AC(N);
  int WAnum = 0;
  int ACnum = 0;
  rep(i, N)
  {
    WA[i] = 0;
    AC[i] = false;
  }
  while (M--)
  {
    int p;
    string S;
    cin >> p >> S;
    if (AC[p])
    {
      continue;
    }
    if (S == "AC")
    {
      AC[p] = true;
      ACnum++;
      WAnum += WA[p];
    }
    else if (S == "WA")
    {
      WA[p]++;
    }
  }
  cout << ACnum << " " << WAnum << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define SORT(v) sort(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> intint;

int main(void)
{
    int n;
    cin >> n;
    for (int i = 1; i < 10; i++) {
        if(0 <= 111 * i - n && 111 * i - n <= 111){
            pr(111 * i);
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i<N; i++)
#define RVROOP(i, N) for(int i=N; i>=0; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
  int H,A; cin>>H>>A;
  if(H%A==0){
    cout<<H/A<<endl;
  }
  else{
    cout<<H/A+1<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#define int long long
using namespace std;

const int INF = 1e9;

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

    int n;
    cin >> n;
    vector <int> dpa(n), dpb(n), dpc(n);

    for(int i = 0; i < n; i++) {
        cin >> dpa[i] >> dpb[i] >> dpc[i];
    }

    for(int i = n - 2; i >= 0; i--) {
        dpa[i] += max(dpb[i + 1], dpc[i + 1]);
        dpb[i] += max(dpa[i + 1], dpc[i + 1]);
        dpc[i] += max(dpa[i + 1], dpb[i + 1]);
    }

    cout << max(dpa[0], max(dpb[0], dpc[0])) << "\n";  
}

Measured memory_bytes: 5516
import random
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]

#貪欲初期解
t = []
memo = [0 for _ in range(26)]
for i in range(d):
    scores = []
    for j in range(26):
        delta_score = 0
        delta_score += s[i][j]
        for k in range(26):
            if j == k:
                continue
            delta_score -= c[k] * (i+1 - memo[k])
        scores.append((delta_score, j))

    scores.sort(key=lambda x: -x[0])
    choice = scores[0][1]
    t.append(choice)
    memo[choice] = i+1

#局所探索
def delta_scoring(t, x, y):
    delta_score = 0
    before_ti, after_ti = 0, d+1
    before_y, after_y = 0, d+1

    for i in range(x):
        if t[i] == t[x]:
            before_ti = i+1
        if t[i] == y:
            before_y = i+1

    for i in range(x+1, d):
        if t[i] == t[x]:
            after_ti = i+1
            break
    for i in range(x+1, d):
        if t[i] == y:
            after_y = i+1
            break

    delta_score -= s[x][t[x]]
    delta_score += s[x][y]
    delta_score -= c[t[x]] * (x + 1 - before_ti) * (after_ti - x - 1)
    delta_score += c[y] * (x + 1 - before_y) * (after_y - x - 1)

    return delta_score

for _ in range(10 ** 5):
    x = random.randint(0, d-1)
    y = random.randint(0, 25)
    if delta_scoring(t, x, y) > 0:
        t[x] = y


for i in range(d):
    print(t[i] + 1)

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

#define int long long
#define rep(i, n) for (int i = 0; (int) (i) < n; i++)
#define reps(i, n) for (int i = 1; (int) (i) <= n; i++)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << x << endl
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) { return b < a && (a = b, true); }
struct SetUp { SetUp() { cout << fixed << setprecision(20); }; } setUp;

int N, K;
int h[110000];
signed main() {
    cin >> N >> K;
    int ans = 0;
    rep(i, N) {
        cin >> h[i];
        ans += h[i] >= K;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    ll s;
    cin >> s;
    ll mod = 1e9+7;
    vector<ll> dp(s+1, 0);
    dp[0] = 1;
    for(int i = 1; i < s+1; i++){
        for(int j = i-3; j >= 0; j--){
            dp[i] += dp[j];
            dp[i] %= mod;
        }
    }
    cout << dp[s] << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
using namespace std;
int n;
vector<long long> a,b;
long long B=0;
int main()
{
	cin>>n;
    a.resize(n,0);
	b.resize(n,0);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    while(true)
	{
        int change=0;
        for(int i=0;i<n;i++)
		{
            long long x=b[(n+i-1)%n],y=b[(n+i+1)%n];
            if(b[i]<x+y) continue;
            if(a[i]==b[i]) continue;
            change+=1;
            long long t=b[i]%(x+y);
            if(t<a[i])
			{
                long long p=b[i]-a[i];
                if(p%(x+y)!=0) B=-1;
                B+=p/(x+y);
                b[i]=a[i];
            }
            else
			{
                B+=b[i]/(x+y);
                b[i]=t;
            }
        }
        if(change==0||B==-1) break;
    }
    bool pos=true;
    for(int i=0;i<n;i++)
        if(a[i]!=b[i])
            pos=false;
    if(pos) cout<<B<<endl;
    else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int mod = 100007;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
ll cal(ll x){
	return x*x*x*x*x;
}
int main(){
	ll x;
	scanf("%lld",&x);
	for(ll i = 0;i <= 6208;++i){
		for(ll j = 0;j <= 6208;++j){
			if(cal(i) - cal(j) == x){
				printf("%lld %lld\n",i,j);
				return 0;
			}
			if(x - cal(j) == cal(i)){
				printf("%lld %lld\n",i,-j);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3760
n,k = map(int,input().split())
a = list(map(int,input().split()))
dic = {1:1}
his=[1]
p=1
s=0
g=0
step=1
for i in range(k):
    t=a[p-1]
    if (t in dic and dic[t]==1):
        s=t
        g=a[t-1]
        break
    else:
        dic[t]=1
    step+=1
    his.append(t)
    p=t
x=his.index(t)
o=step-x
lp=his[x:]
k-=x
#print(x,o,his,lp)
#print(dic)
print(lp[k%o])

Measured memory_bytes: 32300
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> prl;
typedef vector<ll> vcl;
typedef map<ll,ll> mapl;
typedef unordered_map<ll,ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 998244353;

int main() {
    // your code goes here
    ll a,b;
    cin >> a >> b;
    cout << a*b << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int inf = 0x3f3f3f3f;
int n,k;
int a[maxn],pos;
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>k;
    for(int i = 1;i<=n;i++) {
        cin>>a[i]; if(a[i]==1) pos = i;
    }
    int ans = inf;
    for(int i = max(1,pos-k+1);i<=pos;i++) {
        int j = i + k - 1;
        int sum = 0;
        sum += (i-1+k-2)/(k-1);
        sum += (n-j+k-2)/(k-1);
        ans = min(ans,sum + 1);
    }
    cout<<ans<<'\n';
}
/*
kx - (x-1) >= y
x(k-1) >= y - 1
*/

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }

    if (n % 2 == 0) {
        for (int i = n - 1; i >= 1; i -= 2) {
            printf("%d ",a.at(i));
        }
        for (int i = 0; i < n; i += 2) {
            printf("%d ",a.at(i));
        }
    }
    else {
        for (int i = n - 1; i >= 0; i -= 2) {
            printf("%d ",a.at(i));
        }
        for (int i = 1; i < n; i += 2) {
            printf("%d ",a.at(i));
        }
    }
    cout << "\n";
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long int ll;
ll n, ans;
ll l[111111], r[111111], d[111111];
priority_queue<ll> L, R;
ll L_add, R_add;

int main(void)
{
	fio; int i, j; cin>>n;
	for(i=1 ; i<=n ; i++) cin>>l[i]>>r[i];
	for(i=1 ; i<=n ; i++) d[i]=r[i]-l[i];
	ans=0; L.push(l[n]); R.push(-l[n]);
	for(i=n-1 ; i>=1 ; i--)
	{
		L_add+=d[i]; R_add+=d[i+1];
		ll U=L.top(); // in reality, U-L_add
		ll V=-R.top(); // in reality, V+R_add
		if(U>=l[i]+L_add)
		{
			L.pop(); R.push(-(U-L_add-R_add));
			L.push(l[i]+L_add); L.push(l[i]+L_add);
			ll VV=L.top();
			ans+=abs(U-VV); ans+=abs(VV-L_add-l[i]);
		}
		else if(V+R_add<=l[i])
		{
			R.pop(); L.push(V+R_add+L_add);
			R.push(-(l[i]-R_add)); R.push(-(l[i]-R_add)); 
			ll VV=-R.top();
			ans+=abs(V-VV); ans+=abs(VV+R_add-l[i]);
		}
		else if(U-L_add<=l[i] && l[i]<=V+R_add)
			L.push(L_add+l[i]), R.push(-(l[i]-R_add));
	}
	cout<<ans; return 0;
}

Measured memory_bytes: 4460
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x)//unsigned
{
	x = 0;
	char c;
	while (!isdigit(c = getchar()));
	while (isdigit(c))
	{
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
}
int main()
{
	string s;
	cin >> s;
	cout << string(s.size(), 'x') << endl;
	return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []

for i in range(1, n + 1):
    if a[i - 1] <= b[i - 1]:
        ans.append(a[i - 1])
        b[i - 1] = b[i - 1] - a[i - 1]
        a[i - 1] = 0
        if a[i] >= b[i - 1]:
            ans.append(b[i - 1])
            a[i] = a[i] - b[i - 1]
            b[i - 1] = 0
        else:
            ans.append(a[i])
            b[i - 1] = b[i - 1] - a[i]
            a[i] = 0
    else:
        ans.append(b[i - 1])
        a[i - 1] = a[i - 1] - b[i - 1]
        b[i - 1] = 0

print(sum(ans))

Measured memory_bytes: 19004
/* Bismillahirrahmanirrahim
   Semoga Dapet AC ya Allah
   Amin.................. :)
   Ps. SelfRemainder #1: Variabel gak otomatis nilainya 0
					 #2: Output harus sama persis formatnya sama di contoh
					 #3: Jangan lama2 mikirin 1 soal. Kalo dah gabisa, stop
					 #4: Kalau for bersarang, variabelnya jangan sama
*/
#include<bits/stdc++.h>
#define forA for(int i=0; i<a; i++)
#define Fora for(int i=1; i<=a; i++)
#define ll long long
#define F first
#define S second
using namespace std;

int main(){
	int a;
	cin >> a;
	a = a*a*a;
	cout << a << endl;
}


Measured memory_bytes: 256
// Problem : B - Trained?
// Contest : AtCoder - AtCoder Beginner Contest 065
// URL : https://atcoder.jp/contests/abc065/tasks/abc065_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int n;cin>>n;
int arr[n+1];
for(int i=1;i<=n;i++)
cin>>arr[i];
int pos=1;
vi ans(n+1,INT_MAX);
int t=0;
while(ans[pos]==INT_MAX)
{
	ans[pos]=t++;
	pos=arr[pos];
}
if(ans[2]==INT_MAX)
cout<<-1;
else
cout<<ans[2];
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 4760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>

using namespace std;

set<int> S;

int main(void) {

	int a[4];
	for (int i = 1; i <= 3; i++) {
		cin >> a[i]; S.insert(a[i]);
}

	if (S.size() == 2) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
l1=[]
l2=[]
for i in range(n):
  w=list(input())
  l1.append(w)
for i in range(m):
  w=list(input())
  l2.append(w)
d=n-m
b1=False
for i in range(d+1):#始点を横に動かす
  for j in range(d+1):#縦に動かす
    b=True
    for k in range(m):
      for h in range(m):
        if l2[k][h]!=l1[i+k][j+h]:
          b=False
    if b:
      b1=True
if b1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <unistd.h>
#include <stdlib.h>

char    *create_array(char *s, char *new_arr, char *t, int size)
{
	int i;
	int j;

	i = -1;
	while (s[++i])
		new_arr[i] = s[i];
	free(s);
	j = 0;
	while (j < size)
		new_arr[i++] = t[j++];   
	new_arr[i] = 0;
	return (new_arr);
}

char    *get_data(char *s)
{
	int     size;
	int     sum_size;
	char    t[1000];
	char    *new_arr;

	sum_size = 0;
	while ((size = read(0, t, 1000)))
	{
		if (size == -1)
			return (0);
		sum_size += size;
		if (!(new_arr = (char*)malloc(sum_size + 1)))
			return (0);
		s = create_array(s, new_arr, t, size);
	}
	return (s);
}

void    get_nums(int *array, char *s, int count)
{
	int num;
	int i;

	i = 0;
	while (s[i] && s[i] != 10)
	{
	    if (s[i] != 32)
	    {
	        num = 0;
	        while ('0' <= s[i] && s[i] <= '9')
	            num = num * 10 + s[i++] - '0';
	        array[count++] = num;
	        continue;
	    }
	    i++;
	}
}

char    *get_string(char *tmp, int pass_flag)
{
	int     i;
	int     j;
	int     k;
	int     count;
	char    *new_arr;

    count = 0;
	i = 0;
	while (count++ < pass_flag)
		while (tmp[i++] != 10)
			;
	j = 0;
	while (31 < tmp[i + j] && tmp[i + j] < 127)
		j++;
	if (!(new_arr = (char*)malloc(j + 1)))
	    return (0);
	k = -1;
	while (++k < j)
		new_arr[k] = tmp[i + k];
	new_arr[k] = 0;
	return (new_arr);
}

char    **get_strings(char *tmp, int pass_flag, int size)
{
	int     i;
	int     j;
	int     count;
	char    **new_arr;

	if (!(new_arr = (char**)malloc(sizeof(char*) * (size + 1))))
	    return (0);
	count = 0;
	i = 0;
	while (count++ < pass_flag)
		while (tmp[i++] != 10)
			;
	j = -1;
	while (++j < size)
		if(!(new_arr[j] = get_string(&tmp[i], j)))
		    return (0);
	new_arr[j] = 0;
	return (new_arr);
}

void get_ans(int *nums, char **arr, int i, int *y)
{
    int x[nums[0]];
    int j;

    while (++i < nums[0] && !(x[i] = 0))
    {
        j = -1;
        while (++j < nums[1])
            if (arr[i][j] == '.')
                arr[i][j] == '.' ? x[i]++, y[j]++ : 0;
    }
    i = -1;
    while (++i < nums[0])
    {
        if (x[i] == nums[1])
            continue;
        j = -1;
        while (++j < nums[1])
        {
            if (y[j] == nums[0])
                continue;
            write(1, &arr[i][j], 1);
        }
        write(1, "\n", 1);
    }
}

int     main(void)
{
	char    *s;
	int     nums[2];
	char    **arr;
	int     i;
	int     *y;
	
	s = malloc(1);
	if (!(s = get_data(s)))
	    return (-1);
	get_nums(nums, s, 0);
	arr = get_strings(s, 1, nums[0]);
	if (!(y = (int*) malloc(sizeof(int) * nums[1])))
	    return (-1);
	i = -1;
	while (++i < nums[1])
        y[i] = 0;
	get_ans(nums, arr, -1 , y);
	free(s);
	i = -1;
	while (++i < nums[0])
	    free(arr[i]);
	free(arr);
	free(y);
	return (0);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <deque>
#include <string>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <map>
#include <unordered_map>
#include <bitset>

#define _crt_secure_no_warnings
#define FREEELO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F3F3F3F3F
#define MAX 300001
#define ALPHABET 128
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;


int main(){
    ll a, b, c, d; cin >> a >> b >> c >> d;
    cout << max(b * d, max(a * c, max(a * d, b * c))) << endl;
}

Measured memory_bytes: 3180
#include<iostream>
using namespace std;
int main()
{      
    int n;
    cin >> n;
    for (int i=1;i<10;i++){
        for (int j=1;j<10;j++){
            if(i*j==n){
                cout << "Yes";
                exit(0);
            }
        }
    }
    cout << "No";

}
 

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

using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  ll A[N];
  ll B[N];
  ll num=0;
  ll sum=0;
  for(int i=0;i<N;i++){
    cin >> A[i];
    B[i] = abs(A[i]);
    sum += B[i];
    if(A[i]<0) num++;
  }
  sort(B,B+N);
  if(num%2!=0) sum -= 2*B[0];
  cout << sum << endl;
}


Measured memory_bytes: 4744
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#include <iomanip>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef long double ld;
ll big = 1000000007ll;
ll n,m,q,k;
ll T;

vector<ll> A;


ll yes[10] = {0};


bool g(ll i){
ll j = i;
while(j > 0){
    if(yes[j%10] == 1){
        return 0;
    }
    j /=10;
}
return 1;
}

ll f(ll i){
ll i2 = i;
while(g(i2) == 0){
    i2++;
}
return i2;
}

int main()
{
    ll c1,c2,c3,c4,c5;
    ll x,y,z;
    ll a,b,c,d,e;
    //freopen("test_input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> n >> k;

    for(c1 = 0; c1 < k; c1++){
        cin >> a;
        yes[a] = 1;
    }

    cout << f(n) << "\n";


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int N;
  cin >> N;
  vector<string> A(N);
  REP(i, N) cin >> A[i];

  int cnt = 0;
  REP(i,N){
    REP(j,A[i].size()-1){
      if(A[i].at(j)=='A'&&A[i].at(j+1)=='B'){
        cnt++;
      }
    }
  }

  int cntBA=0;
  int cntA=0;
  int cntB=0;
  REP(i,N){
    if(A[i].at(0)=='B'&&A[i].at(A[i].size()-1)=='A'){
      cntBA++;
    }else if(A[i].at(0)=='B'){
      cntB++;
    }else if(A[i].at(A[i].size()-1)=='A'){
      cntA++;
    }
  }
  if(cntBA>=1){
    cnt+=cntBA-1;
    if(cntA>=1){
      cnt++;
      cntA--;
    }
    if(cntB>=1){
      cnt++;
      cntB--;
    }
    cnt+=min(cntA,cntB);
  }else if(cntBA==0){
    cnt+=min(cntA,cntB);
  }

  cout << cnt << endl;
}

Measured memory_bytes: 768
#![allow(unused_imports, non_snake_case, dead_code)]
use proconio::{
    input, fastout,
    marker::{Chars, Bytes, Usize1}
};

const MODULO: u64 = 1_000_000_007;

struct Combination {
    MOD: u64,
    size: usize,
    fact: Vec<u64>,
    inv_fact: Vec<u64>,
}
impl Combination {
    fn new(size: usize, MOD: u64) -> Self {
        let mut fact = vec![1; size + 1];
        let mut inv_fact = vec![1; size + 1];
        for i in 1..size + 1 {
            fact[i] = fact[i - 1] * i as u64 % MOD;
        }
        inv_fact[size] = Self::modpow(fact[size], MOD - 2, MOD);
        for i in (1..size + 1).rev() {
            inv_fact[i - 1] = inv_fact[i] * i as u64 % MOD;
        }
        Combination {
            MOD,
            size,
            fact,
            inv_fact,
        }
    }
    fn modpow(mut x: u64, mut y: u64, m: u64) -> u64 {
        let mut res: u64 = 1;
        while y > 0 {
            if y & 1 > 0 {
                res = res * x % m;
            }
            x = x * x % m;
            y >>= 1;
        }
        res
    }
    fn modinv(x: u64, m: u64) -> u64 {
        Self::modpow(x, m - 2, m)
    }
    fn nPr(&self, n: usize, r: usize) -> u64 {
        if n < r {
            return 0;
        };
        self.fact[n] * self.inv_fact[n - r] % self.MOD
    }
    fn nCr(&self, n: usize, r: usize) -> u64 {
        if n < r {
            return 0;
        };
        self.fact[n] * self.inv_fact[r] % self.MOD * self.inv_fact[n - r] % self.MOD
    }
}

#[fastout]
fn main() {
    input!{
        N: usize
    }
    let ncr = Combination::new(N * 2, MODULO);
    let mut ans = 0;
    for i in 1..N/3+1 {
        ans = (ans + ncr.nCr(N-i*3+i-1, i-1)) % MODULO;
    }
    println!("{}", ans);

}


Measured memory_bytes: 2216
let listing n =
    let rec loop acc i =
        if i <= n then loop (i::acc) (i + 1) else List.rev acc in
    loop [] 1

let _ =
    let n = Scanf.scanf "%d\n" (fun n -> n) in
    Printf.printf "%d\n"
    @@ List.fold_left (fun x y -> x + y) 0 (listing n)



Measured memory_bytes: 384
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define mp make_pair

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef pair<int, int> ii;

class TaskA {
 public:
  map<int64, int64> cache;
  int64 a, b, c, d;

  int64 get(int64 x) {
    if (x == 0) return 0;
    auto it = cache.find(x);
    if (it != cache.end()) return it->second;
    int64 res = numeric_limits<int64>::max();
    {
      int64 y = x / 2;
      int64 cost = d * (x % 2) + a;
      if (y < x) {
        res = min(res, cost + get(y));
      }
    }
    {
      int64 y = x / 2 + 1;
      int64 cost = d * (2 - x % 2) + a;
      if (y < x) {
        res = min(res, cost + get(y));
      }
    }
    {
      int64 y = x / 3;
      int64 cost = d * (x % 3) + b;
      if (y < x) {
        res = min(res, cost + get(y));
      }
    }
    {
      int64 y = x / 3 + 1;
      int64 cost = d * (3 - x % 3) + b;
      if (y < x) {
        res = min(res, cost + get(y));
      }
    }
    {
      int64 y = x / 5;
      int64 cost = d * (x % 5) + c;
      if (y < x) {
        res = min(res, cost + get(y));
      }
    }
    {
      int64 y = x / 5 + 1;
      int64 cost = d * (5 - x % 5) + c;
      if (y < x) {
        res = min(res, cost + get(y));
      }
    }
    if (x <= res / d) {
      res = d * x;
    }
    cache[x] = res;
    return res;
  }

  void solveOne(istream &in, ostream &out) {
    int64 n;
    cache.clear();
    in >> n >> a >> b >> c >> d;
    out << get(n) << "\n";
  }

  void solve(std::istream &in, std::ostream &out) {
    int nt;
    in >> nt;
    for (int it = 0; it < nt; ++it) {
      solveOne(in, out);
    }
  }
};


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  TaskA solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 4908
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int count;
    cin>>count;
    
    int* list = new int[count];
    for(int i=0;i<count;i++){
        int temp;
        cin>>temp;
        list[i] = temp;
    }
    
    for(int j =0;j<count;j++){
        cout<<list[count-j-1];
        if(j!=(count-1)){
            cout<<' ';
        }
    }
    cout<<endl;
    delete list;
	return 0;
}

Measured memory_bytes: 3100
use std::io::Read;

fn main() {
    let mut buff = String::new();
    std::io::stdin().read_to_string(&mut buff).unwrap();
    let mut iter = buff.split_whitespace();

    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();
    let d: i32 = iter.next().unwrap().parse().unwrap();

    if ((b - a).abs() <= d && (c - b).abs() <= d) || (a - c).abs() <= d {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<stdio.h>

int main()
{
 int a,b,x,s1,s2,t1,t2;

 scanf("%d%d%d",&x,&a,&b);

 if(x>a){s1=x;s2=a;}
  else {s1=a;s2=x;}
 if(x>b){t1=x;t2=b;}
  else {t1=b;t2=x;}

 if((s1-s2)>(t1-t2))printf("B");
 else printf("A");

 return 0;
}


Measured memory_bytes: 1604
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

char S[10];
int main(){
  scanf("%s", S);
  for (int i = 0; i < 4; i++){
    if (S[i] == S[i + 1]){
      printf("Bad\n"); return 0;
    }
  }
  printf("Good\n");

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A_dic = { x: 0 for x in set(A)}
for a in A:
    A_dic[a] += 1
res_norm = 0
for a in set(A):
    x = A_dic[a]
    res_norm += x*(x-1)//2
for a in A:
    x = A_dic[a]
    print(res_norm - x*(x-1)//2 + (x-1)*(x-2)//2)

Measured memory_bytes: 95180
#include <iostream>

using namespace std;

int main()
{
    string S,C;
    int N,i,coun;
    cin>>N>>S;
    coun=0;
    for (i=0;i<N;i++){
        if (S[i]=='A'){
            if(S[i+1]=='B'){
                if(S[i+2]=='C'){
                    coun+=1;
            }
        }
    }
    }
    cout<<coun<<endl;
}


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

ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll solve(ll a){
  if(a==1){
    return 1;
  }
  if(a>=2){
    return solve(a/2)*2+1;
  }
}

int main() {
  ll a;
  cin>>a;
  cout<<solve(a)<<endl;
}

Measured memory_bytes: 256
mod = 10**9 + 7

N = int(input())

# NG = {AGC,GAC,ACG,ATGC,AGGC,AGTC}
# (A,C,G,T) = (0,1,2,3)
# dp[i][j]: 長さiの条件を満たす文字列のうち、末尾がjとなるものの場合の数
# 初期条件 dp[1] = [1,1,1,1]
# ans = dp[0] + dp[1] + dp[2] + dp[3]

dp = [[0]*4 for _ in range(N+1)]

# A,C,G,T それぞれ1通りずつ
dp[1] = [1]*4


for i in range(2,N+1):
    for j in range(4):
        # ひとまず長さi-1の文字列にjを足して良いとする
        dp[i][j] += sum(dp[i-1])
        dp[i][j] %= mod
    # ダメなパターンを引いて補正する
    if i >= 2:
        # 後ろ二文字が"AG","GA"の場合はCを付け足せない
        # ~AG, ~GA となる場合の数はそれぞれ dp[i-2][0]*1とdp[i-2][2]*1
        dp[i][1] -= dp[i-2][0] + dp[i-2][2]
        # 後ろ二文字が"AC"の場合はGを付け足せない
        # ~AC となる場合の数は dp[i-2][0] (- dp[i-3][2])
        dp[i][2] -= dp[i-2][0]
    if i >= 3:
        # 後ろ三文字が"ATG","AGG","AGT"となる場合はCを付け足せない
        # ~ATG, ~AGG, ~AGT となる場合の数は 合わせて dp[i-3][0]*3
        dp[i][1] -= dp[i-3][0]*3
        # ----------------------注意--------------------------
        # dp[i-2][0]は後ろから~ACとなる場合の数だから
        # これには~GACとなる場合の数も含まれている
        # しかし~GACというのは既に除外しているので
        # ~ACとなる場合の数は dp[i-2][0]-dp[i-3][2]
        # 余分に引いている分を+dp[i-3][2]することで補正
        dp[i][2] += dp[i-3][2]

ans = sum(dp[N]) % mod
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int cnt = 0;
    while (1)
    {
        if(cnt%2==0){
            c -= b;
            if(c<=0){
                cout << "Yes" << endl;
                return 0;
            }
        }
        else{
            a -= d;
            if(a<=0){
                cout << "No" << endl;
                return 0;
            }
        }
        cnt++;
    }

    return 0;
}

Measured memory_bytes: 3644
import java.util.*;

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String[] S = new String[H];
		for (int i = 0; i < H; i++) {
			S[i] = sc.next(); // 行ごとに入力
		}

		Deque<Point> dq = new ArrayDeque<Point>();
		int[][] d = new int[H][W];
		boolean[][] v = new boolean[H][W];
		int max = 0;

		// bfs
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (S[i].charAt(j) == '.') {
					dq.add(new Point(j, i));
					d[i][j] = 0;
					v[i][j] = true;
					while (!dq.isEmpty()) {
						Point now = dq.pollFirst();
						int hy = now.y;
						int hx = now.x;

						for (int k = 0; k < 4; k++) {
							int nx = hx + dx[k];
							int ny = hy + dy[k];
							// 迷路上の動ける点で、訪問済みでない点をキューに追加する
							if (0 <= nx && nx < W && 0 <= ny && ny < H && S[ny].charAt(nx) == '.' && !v[ny][nx]) {
								v[ny][nx] = true;
								d[ny][nx] = d[hy][hx] + 1;
								max = Math.max(d[ny][nx], max); // MAXの更新
								dq.add(new Point(nx, ny));
							}
						}
					}
					for (int k = 0; k < H; k++) {
						Arrays.fill(v[k], false); // 訪問済み情報のクリア
					}
				}
			}
		}
		System.out.println(max);
		sc.close();
	}

	static class Point {
		int y;
		int x;

		Point(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}
}


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

int main() {
  int N,count=0; cin >> N;
  string S;
  for(int i=0; i<N; i++) {
    cin >> S;
    if(S[i]=='R') count++;
    if(S[i]=='B') count--;
  }
  
  if(count <= 0) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 3584
using System;

namespace ABC120A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            string[] ss = Console.ReadLine().Split(' ');
            a = int.Parse(ss[0]);
            b = int.Parse(ss[1]);
            c = int.Parse(ss[2]);

            if (b / a >= c)
                Console.WriteLine(c);
            else
                Console.WriteLine(b / a);

                Console.ReadKey();


        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const int INF = 1e9;
const ll MOD = 998244353;


bool used[1000][1000][1000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int X,Y,Z,K;cin>>X>>Y>>Z>>K;
  vll A(X),B(Y),C(Z);
  repeat(i,X)cin>>A[i];
  repeat(i,Y)cin>>B[i];
  repeat(i,Z)cin>>C[i];
  sort(A.begin(),A.end(),greater<ll>());
  sort(B.begin(),B.end(),greater<ll>());
  sort(C.begin(),C.end(),greater<ll>());
  priority_queue<pair<ll,pair<int,Pii> > > Q;
  Q.push({A[0]+B[0]+C[0],{0,{0,0}}});
  int k=0;
  while(!Q.empty()){
    auto ret=Q.top();
    Q.pop();
    int a,b,c;
    a=ret.second.first;
    tie(b,c)=ret.second.second;
    if(used[a][b][c])continue;
    used[a][b][c]=true;
    k++;
    cout<<ret.first<<endl;
    if(a+1<X)Q.push({A[a+1]+B[b]+C[c],{a+1,{b,c}}});
    if(b+1<Y)Q.push({A[a]+B[b+1]+C[c],{a,{b+1,c}}});
    if(c+1<Z)Q.push({A[a]+B[b]+C[c+1],{a,{b,c+1}}});
    if(k==K)break;
  }
  return 0;
}


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

int main(void){
    while(1){
        int n,x;
        cin >> n >> x;

        if(n==0 && x==0)
            break;
        int num_of_combination = 0;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                for(int k=j+1;k<=n;k++){
                    if(i+j+k == x){
                        num_of_combination++;
                    }
                }
            }
        }
        cout << num_of_combination << endl;
    }
}


Measured memory_bytes: 3100
a, b = map(int, input().split())
if a > 0:
    print("Positive")
elif a == 0:
    print("Zero")
else:
    if b >= 0:
        print("Zero")
    else:
        if (b - a) % 2 == 0:
            print("Negative")
        else:
            print("Positive")

Measured memory_bytes: 38384
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
//http://hadrori.hateblo.jp/entry/aoj2424
//10の累乗で割った余りと商を掛けて次の数にするだけ。

int main(){
	int q;
	for(cin>>q;q;q--){
		int n;
		cin>>n;
		int t=n;
		int cnt=0;
		while(t/10>0){
			int d=10;
			int mx=0;
			while(t/d>0){
				mx=max(mx,(t/d)*(t%d));
				d*=10;
			}
			t=mx;
			if(t==n){
				cnt=n;
				break;
			}
			cnt++;
		}
		cout<<cnt<<endl;
		
	}
	
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    ll sum = 0;
    rep(i,n) sum += a.at(i);
    ll t = 0;
    for(int i = 1;i < n; i+=2){
        t += a.at(i);
    }
    ll x1 = sum / 2 - t;
    vector<ll> ans(n,0);
    ans.at(0) = x1;
    for(int i = 0; i < n -1;i++){
        ans.at(i+1) = a.at(i) - ans.at(i);
    }
    rep(i,n) cout << 2*ans.at(i) << " ";
    cout << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1'000'000'007;

ll mpow(ll x, ll y){
    if(y == 0) return 1LL;
    if(y == 1) return x%MOD;
    if(y%2 == 0) return mpow(x*x%MOD, y/2);
    else return mpow(x*x%MOD, y/2)*x%MOD;
}

int main(){
    string S;
    cin >> S;
    ll dp[100001][3];
    for(int i=0;i<3;i++) dp[0][i]=0;

    int count = 0;
    for(int i=0;i<S.size();i++){
        switch(S[i]){
            case 'A':
                dp[i+1][0] = (dp[i][0] + mpow(3,count)) % MOD;
                dp[i+1][1] = (dp[i][1]) % MOD;
                dp[i+1][2] = (dp[i][2]) % MOD;
                break;
            case 'B':
                dp[i+1][0] = (dp[i][0]           ) % MOD;
                dp[i+1][1] = (dp[i][1] + dp[i][0]) % MOD;
                dp[i+1][2] = (dp[i][2]           ) % MOD;
                break;
            case 'C':
                dp[i+1][0] = (dp[i][0]           ) % MOD;
                dp[i+1][1] = (dp[i][1]           ) % MOD;
                dp[i+1][2] = (dp[i][2] + dp[i][1]) % MOD;
                break;
            default:
                dp[i+1][0] = (dp[i][0]*3 + mpow(3, count)) % MOD;
                dp[i+1][1] = (dp[i][1]*3 + dp[i][0]) % MOD;
                dp[i+1][2] = (dp[i][2]*3 + dp[i][1]) % MOD;
                count++;
                break;
        }
    }
    cout << dp[S.size()][2] << endl;
    return 0;
}

Measured memory_bytes: 2816
<?php

fscanf(STDIN, "%d", $n);
$H = array_map('intval', explode(' ', trim(fgets(STDIN))));

$max_cnt = 0;
$cnt = 0;
for ($i = 0; $i < $n - 1; ++$i) {
    if ($H[$i] >= $H[$i + 1]) {
        ++$cnt;
    } else {
        $cnt = 0;
    }

    $max_cnt = max($max_cnt, $cnt);
}

echo $max_cnt;


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



 int  main() {
      int n,m;
      cin>>n>>m;
      int a[m];
      int s=0;
      for(int i=0;i<m;i++){
          cin>>a[i];
          s=s+a[i];
      }
      
      if(s>n){
          cout<<"-1"<<endl;
      }else{
          cout<<n-s<<endl;
      }
        
    
    
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef long long ll;

int main()
{
  int N;
  cin >> N;
  vi a(N);
  rep(i, N) cin >> a[i];
  rep(i, N)
  {
    if (!(a[i] & 1) && (a[i] % 3 != 0 && a[i] % 5 != 0))
    {
      puts("DENIED");
      return 0;
    }
  }
  puts("APPROVED");

  return 0;
}

Measured memory_bytes: 256
n=int(input())
da=[int(input()) for i in range(n)]
x,y=0,0
for i in range(n):
    if da[i]>x:
        y=x
        x=da[i]
    else:
        if y<da[i]:
            y=da[i]

for i in range(n):
    if da[i]==x:
        print(y)
    else:
        print(x)

Measured memory_bytes: 12520
# import sys
# input = sys.stdin.readline

N = int(input())

Slist = []
for i in range(N):
    Slist.append(input())
    # if S in Slist.keys():
    #     Slist[S] += 1
    #     if Slist[S] > maxNum:
    #         maxNum = Slist[S]
    # else:
    #     Slist[S] = 1
Slist.sort()

max_cnt = 1
cnt = 1
s_old = Slist[0]
max_Slist = []

for i in range(1,N):
    if Slist[i] == s_old:
        cnt += 1
    else:
        if cnt > max_cnt:
            max_cnt = cnt
            max_Slist = [s_old]
        elif cnt == max_cnt:
            max_Slist.append(s_old)
        s_old = Slist[i]
        cnt = 1

if Slist[N-1] == s_old:
    if cnt > max_cnt:
        max_Slist = [s_old]
    elif cnt == max_cnt:
        max_Slist.append(s_old)

for str in max_Slist:
    print(str)

Measured memory_bytes: 82136