akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> row(h);
  for (int i; i < h; i++) {
    cin >> row.at(i);
  }
  for (int i; i < w + 2; i++) {
    if (i == w + 1) { cout << '#' << endl; }
    else { cout << '#'; }
  } 
  for (int i; i < h; i++) {
    cout << '#';
    cout << row.at(i);
    cout << '#' << endl;
  }
  for (int i; i < w + 2; i++) {
    if (i == w + 1) { cout << '#' << endl; }
    else { cout << '#'; }
  } 
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <limits>

long long solve2(long long n)
{
    long long max = std::ceil(std::sqrt(n));
    long long ans = std::numeric_limits<long long>::max();

    for (long long i = 1; i <= max; i++) {
        long long a = i;
        long long b = n / a;

        if (a * b != n) {continue;}
        if ((a - 1) + (b - 1) < ans) {
            ans = (a - 1) + (b - 1);
        }
    }

    return ans;
}

long long solve(long long n)
{
    std::vector<long long> factor; //多分長さは40以下程度

    long long max = std::ceil(std::sqrt(n)) + 1;

    // 素因数分解する
    for (long long i = 2; (i <= max) && (i <= n); i += std::min(2, static_cast<int>(std::ceil(static_cast<double>(i) / 2)))) {
        while (n % i == 0) {
            factor.push_back(i);
            n /= i;
        }
    }

    if (n != 1) {
        factor.push_back(n);
    }

    long long a = 1, b = 1;

#ifdef _DEBUG
    long long x = 1;
    std::cout << "factor: ";
    for (int i = 0; i < factor.size(); i++) {
        std::cout << factor[i] << " ";
        x *= factor[i];
    }
    std::cout << std::endl;
    std::cout << "check: " << x << std::endl;
#endif

    // 二つに分ける
    while(factor.size()) {
        long long last = factor[factor.size() - 1];
        factor.pop_back();

        if (a > b) {
            b *= last;
        } else {
            a *= last;
        }
    }


#ifdef _DEBUG
    std::cout << "(i, j) = (" << a << ", " << b << ")" << std::endl;
#endif

    return (a - 1) + (b - 1);
}

int main(int argc, char *argv[])
{
    long long n;
    long long ans;

    std::cin >> n;

    ans = solve2(n);

    std::cout << ans << std::endl;

    return 0;
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define RFOR(i, k, j) for (int i = k - 1; i >= j; i--)
#define RREP(i, j) RFOR(i, j, 0)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

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

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x; 
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    REP(i, n) a[i]--;

    vi idx(n);
    REP(i, n) {
        idx[a[i]] = i;
    }

    ll ans = 0;
    set<int> s;
    RREP(i, n) {
        int j = idx[i];
        s.insert(j);
        ll l0 = -1, l1 = -1, r0 = n, r1 = n;
        
        auto it = s.find(j);
        if (it != s.begin()) {
            --it;
            l0 = *it;
            if (it != s.begin()) {
                --it;
                l1 = *it;
            }
        }
        
        auto it2 = s.find(j);
        ++it2;
        if (it2 != s.end()) {
            r0 = *it2;
             ++it2;
            if (it2 != s.end()) {
                r1 = *it2;
            }
        }

        // cout << i + 1 << " " << l0 << " " << l1 << " " << r0 << " " << r1 << endl;
        
        ans += (i + 1) * ((l0 - l1) * (r0 - j) + (j - l0) * (r1 - r0));
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5760
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
double a=Double.parseDouble(sc.next());
double b=Double.parseDouble(sc.next());
double x=Math.ceil((a+b)/2);
int y=(int)x;
System.out.println(y);
}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007, mod998 = 998244353;

int X, A, B;

int main() {
	cin >> X >> A >> B;
	if (B - A <= 0) {
		cout << "delicious" << endl;
	}
	else if (B - X - A <= 0)
		cout << "safe" << endl;
	else
		cout << "dangerous" << endl;
	return 0;
}

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

const ll N = 1e5 + 5;
vector<ll>adj[N];

void doit(){
	ll nodes, edges, i;
	cin >> nodes >> edges;
	ll x, y;
	rep(i,0,edges){
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	queue<ll>q;
	q.push(1LL);
	vector<ll>dist(N);
	ll vis = 1;
	dist[1] = 1;
	while(!q.empty()){
		ll cur = q.front();
		q.pop();
		for(auto x : adj[cur]){
			if(dist[x] == 0){
				vis++;
				dist[x] = cur;
				q.push(x);
			}
		}
	}
	// mtv(vis)
	if(vis != nodes){
		cout << "No" << nl;
		return;
	}
	cout << "Yes" << nl;
	rep(i,2,nodes+1)cout << dist[i] << nl;

}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
   // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 12892
#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()
{
  ll N,K;
  cin >> N >> K;

  ll ans = 0;
  FOR(i,K+1,N+1){
    ll X = (N-K)/i;
    ans+=(i-K)*X;
    if(N-i*X>=i){
      ans+=i-K;
    }else{
      ans+=N-i*X-K+1;
    }
    if(K==0){
      ans--;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
int boss[100005];
int n;
struct st{
	int x,y,idx;
}dt[100005];
struct road{
	int u,v,d;
}rd[100005];
int find_boss(int x){
	return boss[x]==x ? x : boss[x] = find_boss(boss[x]);
}
int main(void){
	RI(n);
	REP(i,n){
		RII(dt[i].x, dt[i].y);
		dt[i].idx = i;
	}
	int cur=0;
	sort(dt,dt+n,[](st &a, st &b){
		return a.x < b.x;
	});
	for(int i=1;i<n;++i, ++cur){
		rd[cur].u = dt[i-1].idx;
		rd[cur].v = dt[i].idx;
		rd[cur].d = dt[i].x - dt[i-1].x;
	}
	sort(dt,dt+n,[](st &a, st &b){
		return a.y < b.y;
	});
	for(int i=1;i<n;++i, ++cur){
		rd[cur].u = dt[i-1].idx;
		rd[cur].v = dt[i].idx;
		rd[cur].d = dt[i].y - dt[i-1].y;
	}
	sort(rd,rd+cur,[](road &a, road &b){
		return a.d < b.d;
	});
	REP(i,n) boss[i] = i;
	int ans=0;
	REP(i,cur){
		if(find_boss(rd[i].u)!=find_boss(rd[i].v)){
			ans+=rd[i].d;
			boss[ find_boss(rd[i].u) ] = find_boss(rd[i].v);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int pm(int a,int n=mod-2){
	if(n==0)return 1;
	if(n==1)return a;
	int x=pm(a,n/2);
	x=(x*x)%mod;
	if(n%2)x=(x*a)%mod;
	return x;
}
int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,sum=0;
	cin >> n;
	int a[n],v[n]={0},f=1;
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int i=1;i<n;i++)
		v[i]=(v[i-1]+pm(i))%mod,
		f=(f*i)%mod;
	for(int i=1;i<n;i++)
		sum=(sum+(v[i]*(a[i]-a[i-1]))%mod)%mod;
	cout << (f*sum)%mod;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 100005;

int n;
int a[N];

int main() {

    FAST;

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int i = 1; ; i ++) {
        if (i % 2) {
            c -= b;
            if (c <= 0) {
                cout << "Yes\n";
                return 0;
            }
        }
        else {
            a -= d;
            if (a <= 0) {
                cout << "No\n";
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>

int main(void){
  int N;
  scanf("%d",&N);

  int ans = 0;
  int a;
  for (int i = 0; i < N; i++) {
    scanf("%d",&a);
    while(a%2 == 0){
      a /= 2;
      ans++;
    }
  }

  printf("%d\n",ans);

  return 0;
}

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

using namespace std;

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

    int ans=0;
    int pmax=0;
    for(int i=0;i<n;i++){
        int p;
        cin >> p;
        pmax = max(pmax,p);
        ans+=p;
    }
    cout << ans-pmax/2 << endl;
}


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

int main(){
	/*input*/
	char b;
	cin >> b;
	/*output*/
	switch(b){
		case 'A':
			cout << 'T' << endl;
		break;
		case 'C':
			cout << 'G' << endl;
		break;
		case 'G':
			cout << 'C' << endl;
		break;
		case 'T':
			cout << 'A' << endl;
	}
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
    
    static int[] a;
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		int max = 2*100000;
		long result = 0;
		int[] cnt = new int[max + 1];
		int[] minus = new int[max + 1];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		    if(a[i] > max) continue;
		    int chk = i - a[i];
		    if(chk >= 0){
		        result += cnt[chk];
		    }
		    if(a[i]+i > max) continue;
		    cnt[a[i]+i]++;
		}
		// 計算
		//int result = 0;
		
		
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 52104
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll cnt[1000005],ans[1000005],spf[1000005],hell=pow(10,6);
void solve(){
	ll n,g=0;
	cin>>n;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		g=__gcd(g,x);
		cnt[x]++;
	}
	ll f=0;
	for(ll i=2;i<=hell;i++)
		if(cnt[i]){
			if(cnt[i]>1)
				f=1;
			ll x=i;
			while(x>1){
				ll y=spf[x];
				while(x%y==0)
					x/=y;
				ans[y]++;
			}
		}
	for(ll i=2;i<=hell;i++)
		if(ans[i]>1)
			f=1;
	if(!f){
		cout<<"pairwise coprime";
		return;
	}
	if(g==1)
		cout<<"setwise coprime";
	else
		cout<<"not coprime";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    for(ll i=2;i*i<=hell;i++)
    	if(!spf[i])
    		for(ll j=i*i;j<=hell;j+=i)
    			if(!spf[j])
    				spf[j]=i;
    for(ll i=1;i<=hell;i++)
    	if(!spf[i])
    		spf[i]=i;
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
        solve();
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 15512
#include <bits/stdc++.h>
using namespace std;
long long f[3001][3001];
int a[3001];
int main()
{
	int i,j,n;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(n%2==0)
			f[i][i]=-a[i];
		else
			f[i][i]=a[i];	
	}
	for(j=1;j<n;j++)
	{
		for(i=1;i+j<=n;i++)
		{
			if(j%2==n%2)
				f[i][i+j]=min(f[i+1][i+j]-a[i],f[i][i+j-1]-a[i+j]);
			else if(j%2!=n%2)
				f[i][i+j]=max(a[i]+f[i+1][j+i],f[i][i+j-1]+a[i+j]);
		}
	}
	printf("%lld",f[1][n]);
	return 0;
}

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

using namespace std;

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

	int n;
	int w;
	cin >> n >> w;
	vector<pair<long long, long long>> items(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> items[i].first >> items[i].second;
	}
	vector<vector<long long>> dp(n + 5, vector<long long>(w + 5));
	for (int i = 0; i < n; ++i)
	{
		dp[i][0] = 0;
	}
	for (int i = 0; i < w; ++i)
	{
		dp[0][i] = 0;
	}

	long long ans = 0;

	for (int j = 1; j <= w; ++j)
	{
		for (int i = 1; i <= n; ++i)
		{
			if (j - items[i-1].first >= 0)
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - items[i-1].first] + items[i-1].second);
			else
				dp[i][j] = dp[i - 1][j];
		}
	}

	cout << dp[n][w];

	return 0;
}

Measured memory_bytes: 83328
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#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 all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll A, ll B, ll C, ll K) {
  int result = 0;

  if (A >= K) {
    result = K;
  } else {
    result += A;
    K -= A;
    K -= B;
    if (K >= 0) {
      result -= K;
    }
  }

  cout << result << endl;
}

int main() {
  ll A;
  scanf("%lld", &A);
  ll B;
  scanf("%lld", &B);
  ll C;
  scanf("%lld", &C);
  ll K;
  scanf("%lld", &K);
  solve(A, B, C, K);
  return 0;
}


Measured memory_bytes: 3764
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

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

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 50;
const long long mod_const = 1e9 + 7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;

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; }

using pll = pair<long long, long long>;

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

	ll N;
	cin >> N;

	if (N % 2 == 0) {
		cout << N / 2 - 1 << endl;
	}
	else {
		cout << (N - 1) / 2 << endl;
	}
	return 0;
}


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

int main() {
  int N, M, sum = 0;
  cin >> N >> M;
  vector<int> vec(M);

  for (int i = 0; i < M; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  int aso = N - sum;
  if (aso < 0) {
    cout << -1 << endl;
  } else {
    cout << aso << endl;
  }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<long, long>> eng(N);
    for(auto& i : eng)cin >> i.first >> i.second;
    auto d = static_cast<unsigned long>(partition(eng.begin(), eng.end(), [](auto i){return i.first == 0 ? i.second > 0 : i.first > 0;}) - eng.begin());
    for(unsigned long i = 0; i < N; ++i)eng.emplace_back(-eng[i].first, -eng[i].second);
    for(unsigned long i = 0; i < d; ++i)eng.emplace_back(eng[i].first, eng[i].second);
    auto cmp = [](auto i, auto j){return i.first * j.second > i.second * j.first;};
    sort(eng.begin(), eng.begin() + d, cmp);
    sort(eng.begin() + d, eng.begin() + d + N, cmp);
    sort(eng.begin() + d + N, eng.end(), cmp);
    long a{0}, b{0};
    unsigned long ans{0};
    for(unsigned long i = 0; i < 2 * N + d; ++i){
        a += eng[i].first;
        b += eng[i].second;
        ans = max<unsigned long>(ans, a * a + b * b);
    }
    boost::multiprecision::cpp_dec_float_50 t(ans), k(boost::multiprecision::sqrt(t));
    cout << k.str() << endl;
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
dp=[[0,0]for _ in[0]*N]
for _ in[0]*M:
    a,b=map(int,input().split())
    if a==1:
        dp[b][0]+=1
    elif b==N:
        dp[a][1]+=1
for i in range(N):
    if sum(dp[i])==2:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')

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

const int maxn=1e5+10;
int arr[maxn],n,m;
const int mod=1e9+7;
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin>>n>>m;
	while(m--){
		int tmp;
		cin>>tmp;
		arr[tmp]=-1;
	}
	arr[0]=1;
	for(int i=1;i<=n;++i){
		if(arr[i]==-1){
			arr[i]=0;
			continue;
		}
		else arr[i]=(i>=2?arr[i-2]:0)%mod+arr[i-1]%mod;
		arr[i]%=mod;
	}
	cout<<arr[n]<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  int n=s.size();
  int sum[n+1];
  sum[0]=0;
  int cur=1;
  rep(i,0,n){
    sum[i+1]=sum[i]+(s[n-1-i]-'0')*cur;
    sum[i+1]%=2019;
    cur*=10;
    cur%=2019;
  }
  int res[2019];
  rep(i,0,2019){
    res[i]=0;
  }
  rep(i,0,n+1){
    res[sum[i]]++;
  }
  ll ans=0;
  rep(i,0,2019){
    ans+=res[i]*(res[i]-1)/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4544
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
int main()
{
    ios::sync_with_stdio(false);
    int n; cin >> n;
    if (n >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3644
#![allow(dead_code, unused_imports, non_snake_case)]

use std::io::*;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::str::FromStr;

const MOD: i32 = 1_000_000_007;

fn main() {
    let (x1, y1, x2, y2): (i32, i32, i32, i32) = input();
    let (dx, dy) = (x2 - x1, y2 - y1);
    let (x3, y3) = (x2 - dy, y2 + dx);
    let (x4, y4) = (x3 - dx, y3 - dy);
    println!("{} {} {} {}", x3, y3, x4, y4);
}

trait Read {
    fn read(s: &str) -> Self;
}

fn input<T: Read>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

macro_rules! read_impl {
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl Read for String {
    fn read(s: &str) -> Self {
        s.to_string()
    }
}

impl Read for Vec<char> {
    fn read(s: &str) -> Self {
        s.chars().collect()
    }
}

impl<T: Read> Read for Vec<T> {
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}

impl<A: Read, B: Read, C: Read, D: Read> Read for (A, B, C, D) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]), D::read(tokens[3]))
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

bool solve() {
  int N;
  map<string, int> m;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    m[s] = 0;
  }
  int M;
  cin >> M;
  int cur = 0;
  for (int i = 0; i < M; i++) {
    string s;
    cin >> s;
    if (m.find(s) == m.end()) {
      cout << "Unknown " << s << endl;
      continue;
    }
    if (cur == 0)
      cout << "Opened by " << s << endl;
    else
      cout << "Closed by " << s << endl;
    cur = 1 - cur;
  }
  return true;
}

signed main() {
  fastio();
  solve();
  //   int t;
  //   cin >> t;
  //   while (t--) solve();
  // while (solve()) {}
  return 0;
}



Measured memory_bytes: 3240
import sys
sys.setrecursionlimit(10**6)

n = int(input())
edges = [[] for _ in range(n+1)]
colors = [None] * (n+1)

for i in range(n-1):
    u, v, w = [int(x) for x in input().split()]
    if w & 1 == 0:
        edges[u].append((v, 0))
        edges[v].append((u, 0))
    else:
        edges[u].append((v, 1))
        edges[v].append((u, 1))

colors[1] = 0


def color(node, c):
    colors[node] = c
    for i, j in edges[node]:
        if colors[i] is None:
            new_color = (c + j)%2
            color(i, new_color)

color(1,1)

for i in colors[1:]:
    print(i)

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

using namespace std;
using pii = pair<int, int>;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	sort(a.begin(), a.end());
	vector<pii> solution;
	int pos = lower_bound(a.begin(), a.end(), 0) - a.begin();
	pos = min(pos, n - 1);
	pos = max(pos, 1);
	int x = a.back();
	int y = a.front();
	for(int i = pos; i + 1 < n; ++i){
		solution.emplace_back(y, a[i]);
		y -= a[i];
	}
	solution.emplace_back(x, y);
	x -= y;
	for(int i = 1; i < pos; ++i){
		solution.emplace_back(x, a[i]);
		x -= a[i];
	}
	cout << x << endl;
	for(const auto& p : solution){
		cout << p.first << " " << p.second << endl;
	}
	return 0;
}



Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<string>


using namespace std;

int main(void)
{
	int a, b, c;
	int flagl, flagt;
	flagl = 0;
	flagt = 0;
	cin >> a;
	if (a == 5)
	{
		flagl++;
	}
	if (a == 7)
	{
		flagt++;
	}
	cin >> b;
	if ( b == 5)
	{
		flagl++;
	}
	if ( b == 7)
	{
		flagt++;
	}
	cin >> c;
	if ( c == 5)
	{
		flagl++;
	}
	if ( c == 7)
	{
		flagt++;
	}
	if (flagl == 2 && flagt == 1)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    ll N;
    cin >> N;
    vector<ll> v(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> v.at(i);
    }

    sort(v.begin(), v.end());
    double ans = v.at(0);
    for (ll i = 1; i < N; i++)
    {
        ans = (ans + v.at(i)) / 2.0f;
    }

    cout << ans << endl;
    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
 
static const int N = 1000;
 
int lcs(string X, string Y) {
    int c[N+1][N+1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int j = 0; j <= n; j++) c[0][j] = 0;
     
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if(X[i] == Y[j]) {
                c[i][j] = c[i-1][j-1] + 1;
            } else {
                c[i][j] = max(c[i-1][j], c[i][j-1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }
     
    return maxl;
}
 
int main() {
    string s1, s2;
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}


Measured memory_bytes: 7060
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    A, B, C, D, E, F = read_values()
    W = set()
    
    for a in range(F // (A * 100) + 1):
        for b in range(F // (B * 100) + 1):
            w = a * 100 * A + b * 100 * B
            if 0 < w <= F:
                W.add(w)

    S = set()
    for c in range(F // C + 1):
        for d in range(F // D + 1):
            s = c * C + d * D
            if 0 <= s <= F:
                S.add(s)
    S = sorted(list(S))
    
    s, t = 0, 100 * A
    for w in W:
        p = min(F - w, math.ceil(E * w / 100))
        f = S[bisect.bisect_right(S, p) - 1]
        if f * 100 > E * w:
            continue

        if s * (w + f) < t * f:
            s, t = f, w + f
    print(t, s)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9708
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
c1=[0]
c2=[k]
s=0
if k==1:
    print(0)
    sys.exit()
for i in range(n):
    s=(s+a[i])%k
    c1.append(s-i-1)
    c2.append(s+k-i-1)
d1={}
for i in range(1,n+1):
    if c1[i] in d1:
        d1[c1[i]]+=1
    else:
        d1[c1[i]]=1
ans=0
for i in range(n):
    if c1[i] in d1:
        ans+=d1[c1[i]]
    d1[c1[i+1]]-=1
d2={}
for i in range(1,min(k,n+1)):
    if c2[i] in d2:
        d2[c2[i]]+=1
    else:
        d2[c2[i]]=1
for i in range(n):
    if c1[i] in d2:
        ans+=d2[c1[i]]
    d2[c2[i+1]]-=1
    if i+k<=n:
        if c2[i+k] in d2:
            d2[c2[i+k]]+=1
        else:
            d2[c2[i+k]]=1
print(ans)










Measured memory_bytes: 118772
L=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', '\
P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', \
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',\
 'v', 'w', 'x', 'y', 'z']
while True:
    n=input()
    if n==0:break
    K=map(int,raw_input().split())
    s=raw_input()
    ans=""
    i=0
    for c in s:
        idx=L.index(c)
        ans+=L[idx-K[i]]
        i+=1
        if i>=n:
            i%=n
    print ans

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

int main() {
    int a, b, c, d;

    cin >> a >> b >> c >> d;

    while (a > 0 && c > 0) {
        c -= b;
        if (c <= 0) break;
        a -= d;
    }

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

Measured memory_bytes: 3592
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int n, m, l, r;
    scanf("%d%d", &n, &m);
    int al = 1, ar = n;
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &l, &r);
        al = max(al, l);
        ar = min(ar, r);
    }
    printf("%d\n", max(0, ar - al + 1));
    return 0;
}


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

int main(){
  ll N,K;cin>>N>>K;
  vector<ll> A(N);rep(i,N)cin>>A[i];
  vector<ll> cnt(N,0);
  rep(i,N) cnt[A[i]-1]++ ;
  sort(cnt.begin(),cnt.end(),greater<ll>());
  ll ans=0;
  for(int i=K;i<N;++i){
    ans+=cnt[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 unsigned long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

const int64 md = 1e9 + 7;
int64 n;
int64 val, res, cnt[66][2];

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> val;
        for (int j = 0; j < 60; j++){
            int tmp = (val >> j) & 1;
            res = (res + cnt[j][tmp ^ 1]) % md;
            cnt[j][tmp] = (cnt[j][tmp] + (1ll << j)) % md;
        }
    }
    cout << res % md;
    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(), count=0;
		int[] length = new int[n];
		for(int i=0;i<n;i++) length[i]=sc.nextInt();
		Arrays.sort(length);
		for(int i=0;i<n;i++) {
			for(int j=i+1;j<n-1;j++) {
				int left=0,right=n, tar=length[i]+length[j];
				while(left+1<right) {
					int mid = (left+right)/2;
					if(length[mid]<tar) left = mid;
					else right=mid;
				}
				count+=left-j;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 31464
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    vector<P> ps(n);
    rep(i,n){
        int a;
        cin >> a;
        ps[i] = P(a,i+1);
    }
    sort(ps.begin(),ps.end());
    rep(i,n){
        cout << ps[i].second;
        if(i==n-1)cout << endl;
        else cout << " ";
    }
    return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int[] a = new int[4];

    for (int i = 0; i < 6; i++) {
      a[sc.nextInt() - 1]++;
    }

    for (int i = 0; i < 4; i++) {
      if ((a[i] != 1) && (a[i] != 2)) {
        System.out.println("NO");
        return;
      }
    }

    System.out.println("YES");

  }
}

Measured memory_bytes: 35432
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

K = int(input())

res = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            tmp = gcd(i, j)
            tmp = gcd(tmp, k)
            res += tmp

print(res)

Measured memory_bytes: 68712
#include "iostream"
using namespace std;const int N=2e5+5;int64_t a[N],d[N],s[N],n,i;main(){cin>>n;for(;i<n;++i)cin>>a[i],s[i]=(i>1?s[i-2]:0)+a[i];for(i=1;i<n;++i)d[i]=max((i&1?s:d)[i-1],d[i-2]+a[i]);cout<<d[n-1];}

Measured memory_bytes: 8308
#include <iostream>
#include <cmath>

using namespace std;

char a[8];

void bsort(void){

  for( int i = 0 ; i < 8 ; i++ ){
    for( int j = 7 ; j > i ; j-- ){
      if( a[j-1] > a[j] ){
	char temp = a[j];
	a[j] = a[j-1];
	a[j-1] = temp;
      }
    }
  }
}
int main(void){

  int n;
  cin >> n;
  while(n--){
    cin >> a;
    bsort();
    int max,min;
    max = min = 0;
    for( int i = 0 ; i < 8 ; i++ ){
      min += pow( (double)10 , i )*(a[7-i] - '0');
      max += pow( (double)10 , i )*(a[i] - '0');
    }
    //cout << max << endl << min << endl;
    cout << max - min << endl;
  }
  return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <cstdlib>
#include <ctime>
#include <queue>
using namespace std;

#define X first
#define Y second
#define N 511
#define M 500010

typedef unsigned long long ull;
typedef long long ll;
const int INF=1<<30;

int main()
{
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
	
	int n, T, x, R = 0, res = 0; scanf("%d %d", &n, &T);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d", &x);
		if (x <= R) res += x + T - R, R = x + T;
		else res += T, R = x + T;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

char s[15];
LL cnt[400];

int main(){
	LL n,a,b,c,d,e,sum = 0;
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> s + 1;
		cnt[s[1]]++;
	}
	a = cnt['M'];
	b = cnt['A'];
	c = cnt['R'];
	d = cnt['C'];
	e = cnt['H'];
	sum += a * b * c;
	sum += a * b * d;
	sum += a * b * e;
	sum += a * c * d;
	sum += a * c * e;
	sum += a * d * e;
	sum += b * c * d;
	sum += b * c * e;
	sum += b * d * e;
	sum += c * d * e;
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

int H,W;
vector < string > M;
int dist[51][51];
bool used[51][51];

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

void bfs ()
{
    queue < vector < int > > que;
    que.push({0, 0, 0});
    while (!que.empty()) {
        int x = que.front()[0];
        int y = que.front()[1];
        int d = que.front()[2];
        que.pop();
        if (used[x][y]) continue;
        dist[x][y] = d;
        used[x][y] = true;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
            if (M[nx][ny] == '#') continue;
            if (used[nx][ny]) continue;
            que.push({nx, ny, d + 1});
        }
    }
}

int main ()
{
    cin >> H >> W;
    M.resize(H);
    REP(i,H) cin >> M[i];

    REP(i,51)REP(j,51) dist[i][j] = 1e9;

    bfs();

    int sum = 0;
    REP(x,H)REP(y,W) {
        if (M[x][y] == '.') {
            sum++;
        }
    }

    if (dist[H - 1][W - 1] == 1e9) {
        cout << -1 << endl;
        return 0;
    }

    cout << sum - dist[H - 1][W - 1] - 1 << endl;

    return 0;
}


Measured memory_bytes: 256
N=int(input())
a=[0]*N
b=[0]*N
c=[0]*N

for i in range(N):
	a[i],b[i],c[i]=map(int,input().split())

dp=[[0 for j in range(N)] for k in range(3)]

for l in range(N):
	if l==0:
		dp[0][l]=a[l]
		dp[1][l]=b[l]
		dp[2][l]=c[l]
	else:
		dp[0][l]=max(dp[1][l-1],dp[2][l-1])+a[l]
		dp[1][l]=max(dp[0][l-1],dp[2][l-1])+b[l]
		dp[2][l]=max(dp[0][l-1],dp[1][l-1])+c[l]

print(max(dp[0][N-1],dp[1][N-1],dp[2][N-1]))

Measured memory_bytes: 26888
#include <stdio.h>

long long int N, M;

int main()
{
    scanf("%d%d", &N, &M);
    int ans = 1;
    for (long long int i = 1; i * i <= M; i++)
    {
        if (M % i == 0)
        {
            if (i > ans && i * N <= M) ans = i;
            if (M > ans * i && N <= i) ans = M / i;
        }
    }
    printf("%d", ans);
}


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

int main() {
    using namespace std;
    unsigned long N;
    cin >> N;
    [&] {
        for (unsigned long i = 0; i <= N; ++i) {
            auto t = i * 27 / 25;
            if (t == N){
                cout << i << endl;
                return;
            }
        }
        puts(":(");
    }();
    return 0;
}

Measured memory_bytes: 256
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val S = sc.nextLine().map(_ - '0')
    // 入れる入れないを列挙する
    // |S| - 1 個の間で 入れる 入れない を選ぶ
    // 2^(|S| - 1) 通り
    def solve(S: IndexedSeq[Int]): Long = {
      val L = S.length - 1
      @scala.annotation.tailrec
      def dfs(stack: List[(Int, List[Int])], acm: Long): Long =
        if (stack.nonEmpty) {
          val (i, lst) = stack.head
          if (i < L) dfs((i + 1, lst) :: (i + 1, i :: lst) :: stack.tail, acm)
          else dfs(stack.tail, acm + calc(lst.reverse))
        } else acm
      def calc(lst: List[Int]): Long = {
        val N = S.length
        @scala.annotation.tailrec
        def loop(i: Int, lst: List[Int], num: Long, acm: Long): Long =
          if (i < N) {
            if (lst.nonEmpty) {
              if (i <= lst.head) loop(i + 1, lst, 10 * num + S(i), acm)
              else loop(i, lst.tail, 0, acm + num)
            } else loop(i + 1, lst, 10 * num + S(i), acm)
          } else acm + num
        loop(1, lst, S(0), 0)
      }
      dfs((0, Nil) :: Nil, 0)
    }

    println(solve(S))
  }

}


Measured memory_bytes: 25548
#include<bits/stdc++.h>
using namespace std;
int ans,s1,s2;
int solve(int tt,int pp);
string text,patn;

int main(){

    while(cin >> text){
        cin >> patn;
        s1=text.size();
        s2=0;
        ans=0;
        while(s1!=0 || s2<=(int)patn.size()){
            if(s1!=0)s1--;
            else s2++;
            ans=max(ans,solve(s1,s2));
            }
        cout << ans << endl;
        ans=0;
    }
    return 0;
}

int solve(int tl,int pl){
    int tt=0;
    int pp=0;
    int len=min(text.size()-tl,patn.size()-pl);
    for(int i=0;i<len;i++){
        if(text[tl+i]==patn[pl+i]){
            tt++;
        }else{
            pp=max(pp,tt);
            tt=0;
        }
    }
    return max(pp,tt);
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
     long long  int a,b,c,d,e,f,g,h,i,j;
     vector<pair<long long int,long long int> >v;
        vector<int>v1;
        cin>>a;
        h=a;
        int ar[a];
        cin>>b;
        while(a--)
        {
            long long int x,y;
            cin>>x>>y;
            v.push_back(make_pair(x,y));
        }
        sort(v.begin(),v.end());
        long long int ans=0;
        c=0,d=0;
        for(i=0;i<v.size();i++)
        {
            if(b==0)
            {
                break;
            }
            if(b>=v[i].second)
            {
                ans+=(v[i].first*v[i].second);
                b-=v[i].second;

            }
            else{
                ans+=(v[i].first*b);
                b-=b;
                break;
            }
        }
        cout<<ans<<endl;
        return 0;
 }


Measured memory_bytes: 2420
#include <iostream>

using namespace std;
#define Nmax 100000
int main() {
	int N;
	int a;
	int start;
	int Nnum[Nmax];
	scanf("%d", &N);
	for (int i = 1; i < N + 1; i++) {
		scanf("%d", &a);
		Nnum[i] = a;
	}
	int next = 1;
	int count = 0;
	while (count<N) {
		next = Nnum[next];
		count++;
		if (next == 2)
			break;
	}
	if (next == 2)
		printf("%d\n", count);
	else
		printf("%d\n", -1);
}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> edges(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    edges[u].push_back(v);
  }
  int S, T;
  cin >> S >> T;
  S--;
  T--;

  const int inf = 1e9;
  vector<vector<int>> D(N, vector<int>(3, inf));
  D[S][0] = 0;
  queue<int> que;
  que.push(S);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (auto e : edges[v]) {
      bool changed = false;
      if (D[v][0] != inf and D[e][1] == inf) {
        D[e][1] = D[v][0] + 1;
        changed = true;
      }
      if (D[v][1] != inf and D[e][2] == inf) {
        D[e][2] = D[v][1] + 1;
        changed = true;
      }
      if (D[v][2] != inf and D[e][0] == inf) {
        D[e][0] = D[v][2] + 1;
        changed = true;
      }
      if (changed) {
        que.push(e);
      }
    }
  }
  if (D[T][0] == inf) {
    cout << -1 << endl;
  } else {
    cout << D[T][0] / 3 << endl;
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 11136
#include<stdio.h>
#define NIL -1
typedef struct{
  int p;
  int l;
  int r;
}node;

void print(node *u,int i){
  int c;
  
  printf("node %d: ",i);
  printf("parent = %d, ",u[i]);
  printf("depth = %d, ",depth(u,i));
  if(u[i].p == NIL) printf("root, ");
  if(u[i].p != NIL && u[i].l == NIL) printf("leaf, ");
  if(u[i].p != NIL && u[i].l != NIL) printf("internal node, ");
  printf("[");
  if(u[i].l != NIL){
    printf("%d",u[i].l);
    c = u[i].l;
    while(u[c].r != NIL){
      printf(", %d",u[c].r);
      c = u[c].r;
    }
  }
  printf("]\n");
}

int depth(node *u,int x){
  int count=0,temp;

  while(u[x].p != NIL){
    count++;
    temp = u[x].p;
    x = temp;
  }
  return count;
}

int main(){
  node u[100001];
  int n,k,id,c,l,r;
  int i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    u[i].p = NIL;
    u[i].l = NIL;
    u[i].r = NIL;
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&c);
      if(j==0) u[id].l = c;
      else u[l].r = c;
      l = c;
      u[c].p = id;
    }
  }

  for(i=0;i<n;i++) print(u,i);
  
  return 0;
}



Measured memory_bytes: 2928
#include<iostream>
#include<algorithm>
using namespace std;
int ans[1001][1001][3];
char m[3]={'J','O','I'};
int main(){
	int h,w,k;
	cin>>h>>w>>k;
	char z;
	for(int i=0;i<h;i++)for(int r=0;r<3;r++)ans[i][0][r]=0;
	for(int j=0;j<w;j++)for(int r=0;r<3;r++)ans[0][j][r]=0;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>z;
			for(int r=0;r<3;r++){
				ans[i][j][r]=ans[i-1][j][r]+ans[i][j-1][r]-ans[i-1][j-1][r];
				if(m[r]==z)ans[i][j][r]++;
			}
		}
	}
	int x[2],y[2];
	for(int u=0;u<k;u++){
		for(int i=0;i<2;i++)cin>>y[i]>>x[i];
		for(int r=0;r<3;r++){
		if(r)cout<<" ";
		int cnt=ans[y[1]][x[1]][r]+ans[y[0]-1][x[0]-1][r];
		cnt-=ans[y[1]][x[0]-1][r]+ans[y[0]-1][x[1]][r];
		cout<<cnt;
		}
		cout<<endl;
	}
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

int main() {
    li w, h;
    cin >> w >> h;
    if (w % 3 == 0 || h % 3 == 0) {
        puts("0");
        return 0;
    }
    li res = min(w, h);

    // 1個目でｗだけ削る
    repp(i, w / 3, w / 3 + 2) {
        li tma = i * h;
        li tmi = i * h;
        tma = max(tma, (w - i) * ((h + 1) / 2));
        tmi = min(tmi, (w - i) * (h / 2));
        if (tmi == 0)continue;
        res = min(res, tma - tmi);
    }

    repp(i, h / 3, h / 3 + 2) {
        li tma = i * w;
        li tmi = i * w;
        tma = max(tma, (h - i) * ((w + 1) / 2));
        tmi = min(tmi, (h - i) * (w / 2));
        if (tmi == 0)continue;
        res = min(res, tma - tmi);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 998244353
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll ans[100];
ll fib(ll x){
    if (ans[x]!=-1)return ans[x];
    ans[x]=fib(x-1)+fib(x-2);
    return ans[x];
}

int main(){
    fill(ans,ans+50,-1);
    ans[0]=1;
    ans[0]=1;
    ll n;
    cin >> n;
    cout << fib(n) << endl;
    return 0;
}


Measured memory_bytes: 3132