akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int X,N;
    cin>>X>>N;
    vi p(N);
    for(int i=0;i<N;i++){
        cin>>p[i];
    }
    sort(ALL(p));
    if(upper_bound(ALL(p),X)-lower_bound(ALL(p),X)==0){
        cout<<X<<endl;return 0;
    }
    for(int i=1;i<=101;i++){
        if(upper_bound(ALL(p),X-i)-lower_bound(ALL(p),X-i)==0){
            cout<<X-i<<endl;return 0;
        }
        if(upper_bound(ALL(p),X+i)-lower_bound(ALL(p),X+i)==0){
            cout<<X+i<<endl;return 0;
        }
    }
}


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

using namespace std;
using ll = long long;

ll f(ll x, ll m) {
  return x % m;
}

int main() {
  ll n, x, m;
  cin >> n >> x >> m;

  bool flag = false;
  vector<pair<ll,ll>> selected(1e5, make_pair(-1, 0));
  ll vsum = x;
  ll a1 = x;
  for (ll i = 2; i <= n;) {
    ll a2 = f(a1*a1, m);
    if (selected[a2].first != -1 && flag == false) {
      ll f = selected[a2].first;
      ll s = selected[a2].second;
      ll dsum = vsum - s + a2;
      vsum = s + dsum * ((n - f) / (i - f));
      a1 = a2;
      i = f + (n - f) / (i - f) * (i - f) + 1;
      flag = true;
    }
    else {
      vsum += a2;
      a1 = a2;
      selected[a2] = make_pair(i, vsum);
      ++i;
    }
  }

  cout << vsum << endl;
}


Measured memory_bytes: 4836
#18:04
n,a,b,c = map(int,input().split())
mod = 10 ** 9 + 7
def inv(x):
  ans = 1
  now = x
  while now != 1:
    ans *= mod // now + 1
    ans %= mod
    now = now - mod % now
  return ans
p = (a * inv(a+b)) % mod
q = (b * inv(a+b)) % mod
taka = 0
aoki = 0
tcom = 1
acom = 1
for i in range(n):
  taka += tcom * (n+i)
  tcom *= n+i
  tcom *= inv(i+1)
  tcom *= q
  tcom %= mod
  aoki += acom * (n+i)
  acom *= n+i
  acom *= inv(i+1)
  acom *= p
  acom %= mod
for _ in range(n):
  taka *= p
  taka %= mod
  aoki *= q
  aoki %= mod
ans = taka + aoki
ans *= 100
ans *= inv(a+b)
ans %= mod
print(ans)

Measured memory_bytes: 3064
// abc132_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;

    map<char, int> mp;
    for (auto s: S){
        mp[s]++;
    }

    vector<P> vec(ALL(mp));
    if (vec.size() == 2 && vec[0].second == 2){
        print("Yes");
    } else {
        print("No");
    }



    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int n,m,x;
  scanf("%d%d%d",&n,&m,&x);
  int a[m];
  int i;
  i = 0;
  int right;
  int left;
  right = 0;
  left = 0;
  while (i < m)
  {
    scanf("%d",&a[i]);
    if (a[i] < x)
    {
      right++;
    }
    else
    {
      left++;
    }
    i++;
  }
  if (x + right < n - x + left)
  {
    printf("%d",right);
  }
  else
  {
    printf("%d",left);
  }
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi      vector <int>
#define vii     vector <pair<int,int>>
#define ii      pair<int,int>
#define loop(n)	for(int i=0;i<n;i++)
ll mod=1e9+7;
bool is_prime(int n)
{
    if(n==2)
        return true;
    if(n%2==0||n<2)
        return false;
    for(int i=3; i<=sqrt(n); i+=2)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=(power(n,k/2))%mod;
    sq=(sq*sq)%mod;
    if(k%2==1)
        sq=(sq*n)%mod;
    return sq%mod;
}
void low(char &c){
c=tolower(c);
}
void primeFactors(int n)
{
    while (n % 2 == 0)
    {
        cout << 2 << " ";
        n = n/2;
    }

    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            cout << i << " ";
            n = n/i;
        }
    }

    if (n > 2)
        cout << n << " ";
}

#include <iostream>
using namespace std;
void fast();
int arr[200005];
map <int,int> M;
int main() {
//fast();
int n,m,ch;
string s;
cin >> n;
loop(n){
    cin >> arr[i];
}
int sm=0,mn = arr[0];
loop(n){
    if(arr[i]<=mn){
        sm++;
        mn =arr[i];
    }
}
cout <<sm;
}





void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <queue>

using namespace std;

int wall[300][300];

struct P {
  int w, h, cost;
  P(int h, int w, int cost): h(h), w(w), cost(cost) {}
};

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

int main()
{
  int W, H;
  while (scanf("%d %d ", &W, &H) == 2) {
    if (W == 0 && H == 0) {
      break;
    }
    for (int i = 0; i < 300; i++) {
      fill(wall[i], &wall[i][300], 1);
    }
    
    for (int i = 1; i < W; i++) {
      scanf("%d ", &wall[1][i]);
    }
    for (int i = 1; i < H; i++) {
      for (int j = 1; j <= W; j++) {
	scanf("%d ", &wall[2 * i][j]);
      }
      for (int j = 1; j < W; j++) {
	scanf("%d ", &wall[2 * i + 1][j]);
      }
    }
    
    queue<P> Q;
    Q.push(P(0, 0, 1));
    bool visited[200][200];

    for (int i = 0; i < 200; i++) {
      fill(visited[i], &visited[i][200], false);
    }
    visited[0][0] = true;
    
    while (!Q.empty()) {
      P cur = Q.front();
      Q.pop();
      
      if (cur.h == H - 1 && cur.w == W - 1) {
	printf("%d\n", cur.cost);
	goto next;
      }
      for (int i = 0; i < 4; i++) {
	if (!wall[2 * cur.h + 1 + dy[i]][cur.w + dx[i]] &&
	    !visited[cur.h + _dy[i]][cur.w + _dx[i]]) {
	  Q.push(P(cur.h + _dy[i], cur.w + _dx[i], cur.cost + 1));
	  visited[cur.h + _dy[i]][cur.w + _dx[i]] = true;
	}
      }
    }
    printf("0\n");
  next:;
  }
  return 0;  
}

Measured memory_bytes: 1324
#include <bits/stdc++.h>
using namespace std;
using Int = long long unsigned;
int const MOD = 1000000007;
typedef pair<int,int> P;
typedef priority_queue<int> Pr;

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

    int n,q; cin>>n>>q; P inp[n-1]; int ans[n]={},qu[n]={};
    for (int i = 0; i < n-1; i++){
        int a,b; cin>>a>>b; a--; b--;
        inp[i].first=a; inp[i].second=b;
    }
    sort(inp,inp+n-1);
    for (int i = 0; i < q; i++){
        int p,x; cin>>p>>x; p--; qu[p]+=x;
    }
    ans[0]=qu[0];
    for (int i = 0; i < n-1; i++){
        ans[inp[i].second]+=ans[inp[i].first]+qu[inp[i].second];
    }
    for (int i = 0; i < n-1; i++){
        cout<<ans[i]<<' ';
    }
    cout<<ans[n-1]<<'\n';
}

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

int N;
vector<int> A;
long long ans = 0;

void dfs(int index, long long mul) {
    if (index == N - 1) {
        if (mul * (A[index] - 1) % 2 == 0) {
            ans++;
        }
        if (mul * (A[index]) % 2 == 0) {
            ans++;
        }
        if (mul * (A[index] + 1) % 2 == 0) {
            ans++;
        }
        return;
    }

    dfs(index + 1, mul * (A[index] - 1));
    dfs(index + 1, mul * A[index]);
    dfs(index + 1, mul * (A[index] + 1));
}

int main()
{
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }


    dfs(0, 1LL);
    cout << ans << endl;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  for ( int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;
  for ( int i = 0; i < H; i++){
    cout << "#";
    string r;
    cin >> r;
    cout << r;  
    cout << "#" << endl;
  }
  for ( int i = 0; i < W + 2; i++){
    cout << "#";
  }
}



Measured memory_bytes: 256
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

score = {'p': P, 'r': R, 's': S}
hand = {'r': 'p', 's': 'r', 'p': 's'}
H = [' '] * N

ans = 0
for sub in range(K):
    i = sub
    while i < N:
        c = T[i]
        if i - K >= 0 and hand[c] == H[i - K]:
            s = 0
            if i + K < N and hand[T[i + K]] == c:
                H[i] = hand[hand[c]]
            else:
                H[i] = c
        else:
            H[i] = hand[c]
            s = score[hand[c]]
        i += K
        ans += s

print(ans)


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

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

vector<int> to[100005];
const int INF =1001001001;

int main() {
  int n,m;
  cin>>n>>m;
  rep(i,m){
    int a,b;
    cin >>a>>b;
    --a;--b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  queue<int> q;
  vector<int> dist(n,INF);
  vector<int> pre(n,-1);
  dist[0];
  q.push(0);
  while (!q.empty())
  {
    int v =q.front();q.pop();
    for(int u: to[v]){
      if(dist[u] != INF) continue;
      dist[u]=dist[v]+1;
      pre[u]=v;
      q.push(u);
    }
  }
  cout<<"Yes"<<endl;
  rep(i,n){
    if(i==0) continue;
    int ans = pre[i];
    ++ans;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 10568
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int p=s.size()-1;
	for(int i=0;i<=p;i++)s[p-i+10]=s[p-i];
	for(p=p+10;;)
	{
		if(p==9)
		{
			cout<<"YES"<<endl;
			return 0;
		}
		else if(p<9)
		{
			cout<<"NO"<<endl;
			return 0;
		}
		if(s[p]=='r'&&s[p-1]=='e')
		{
			if(s[p-2]=='s'&&s[p-3]=='a'&&s[p-4]=='r'&&s[p-5]=='e')
			{
				p=p-6;
			}
			else if(s[p-2]=='m'&&s[p-3]=='a'&&s[p-4]=='e'&&s[p-5]=='r'&&s[p-6]=='d')
			{
				p=p-7;
			}
			else
			{
				cout<<"NO"<<endl;
				return 0;
			}
		}
		else if(s[p]=='m'&&s[p-1]=='a'&&s[p-2]=='e'&&s[p-3]=='r'&&s[p-4]=='d')
		{
			p=p-5;
		}
		else if(s[p]=='e'&&s[p-1]=='s'&&s[p-2]=='a'&&s[p-3]=='r'&&s[p-4]=='e')
		{
			p=p-5;
		}
		else
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
}

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

int main(){
long long N,A,B;
cin >> N>> A>>B;
if(N%(A+B) > A){
	cout << N/(A+B)*A+A<<endl;
}
else{
	cout << N/(A+B)*A+N%(A+B)<<endl;
}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
#include<string.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	long double a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	long double dis = abs(a - b);
	if (v <= w) cout << "NO" << endl;
	else {
		if ((dis / (v - w) > t)) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
}

Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

void dfs(const vector<vector<pair<ll, ll>>>& p, int v, vector<ll>& f, int oya, int t) {
    if (t % 2 == 1)f.at(v) = 1;
    for (int i = 0; i < p.at(v).size(); i++) {
        if (p.at(v).at(i).first == oya)continue;
        dfs(p, p.at(v).at(i).first, f, v, t + p.at(v).at(i).second);
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<pair<ll, ll>>> p(n);
    vector<ll> f(n);
    for (int i = 0; i < n - 1; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        c %= 2;
        p.at(a - 1).push_back(make_pair(b - 1, c));
        p.at(b - 1).push_back(make_pair(a - 1, c));
    }
    dfs(p, 0, f, 0, 0);
    int root = 0;
    for (int i = 0; i < n; i++) {
        cout << f.at(i) << endl;
    }
}

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

int t[16][16];

int main()
{
	int n;
	while(cin >> n, n)
	{
		for(int y=0; y<=n; y++)
		for(int x=0; x<=n; x++)
		{
			t[y][x] = 0;
		}

		for(int y=0; y<n; y++)
		for(int x=0; x<n; x++)
		{
			cin >> t[y][x];
			t[n][x] += t[y][x];
			t[y][n] += t[y][x];
			t[n][n] += t[y][x];
		}

		for(int y=0; y<=n; y++)
		{
			for(int x=0; x<=n; x++)
			{
				cout.width(5);
				cout << t[y][x];
			}
			cout << endl;
		}
	}

	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

ll x(ll n){
    if(n%4==0)return n;
    else if(n%4==1)return 1;
    else if(n%4==2)return n+1;
    else return 0;
}

int main(){
    ll a,b;
    cin>>a>>b;
    cout<<(x(a-1)^x(b))<<endl;
return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int a[3];
  map<int,int> mp;
  for(int i=0;i<3;i++) cin >> a[i];
  for(int i=0;i<3;i++) mp[a[i]]++;

  cout << mp.size() << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;


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

	string ans = "";

	/*
	ll sta = 26;

	ll a = n;
	int cnt = 0;
	while (a > 0) {
		a -= sta;
		cnt++;
		if (a <= 0) break;
		sta *= 26;
	}

	*/

	vector<char> cr(1, 'z');
	for (char c = 'a'; c <= 'z'; c++) cr.pb(c);

	while (n > 0) {
		ans.pb(cr[n%26]);
		if (n % 26 == 0) {n--;}
		n /= 26;
	}

	reverse(rng(ans));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(){
	int N;
	cin >> N;
	int x[365];
	int y[365];
	int b[365];
	int p[365];
	int cost[365];
	int costB[365];
	for(int i=0;i<N;i++){
		cin >> x[i] >> y[i] >> b[i] >> p[i];
		cost[i] = x[i]*b[i]+y[i]*p[i];
		if(b[i]>=5 && p[i]>=2) cost[i] *= 0.8;

		if(b[i]<5)
		b[i]=5;
		if(p[i]<2) 
		p[i]=2;
		costB[i]=(x[i]*b[i]+y[i]*p[i])*0.8;
	}
	for(int i=0;i<N;i++){
		if(cost[i]<costB[i])
			cout << cost[i] << endl;
		else   cout << costB[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> v(100000,0);
	for(int i=0;i<n;i++) {
		int t;
		cin>>t;
		if(t<99999) v[t+1]++;
		if(t>0) v[t-1]++;
		v[t]++;
	}
	int ma = 0;
	for(int i=0;i<100000;i++) {
		ma = max(ma,v[i]);
	}
	cout<<ma;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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 T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



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

int n, m;
int F[100][100];

int res = 0;
bool seen[100][100];
void rec(int x, int y, int num) {
    chmax(res, num);
    
    for (int i = 0; i < 4; ++i) {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
        if (!seen[nx][ny] && F[nx][ny]) {
            seen[nx][ny] = true;
            rec(nx, ny, num+1);
            seen[nx][ny] = false;
        }
    }
}

int main() {
    while (cin >> m >> n) {
        if (m == 0 && n == 0) break;
        memset(F, 0, sizeof(F));
        for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> F[i][j];
        
        memset(seen, 0, sizeof(seen));
        res = 0;
        for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
            if (F[i][j]) {
                seen[i][j] = true;
                rec(i, j, 1);
                seen[i][j] = false;
            }
        }
             
        cout << res << endl;
    }
    return 0;
}


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

int main(){
    ll k; cin >> k;
    queue<ll> q;
    for(int i=1;i<=9;i++){
        q.push(i);
    }
    rep(i,k){
        ll x = q.front();
        q.pop();
        ll y = x%10;
        if(y!=0) q.push(x*10+y-1);
        q.push(x*10+y);
        if(y!=9) q.push(x*10+y+1);
        if(i==k-1) cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    rep(i,4){
        vector<char> ans(n);
        if(i==0) ans[0]='S',ans[1]='S';
        if(i==1) ans[0]='S',ans[1]='W';
        if(i==2) ans[0]='W',ans[1]='S';
        if(i==3) ans[0]='W',ans[1]='W';
        rep(j,n){
            if(j==0||j==1) continue;
            if(s[j-1]=='o'&&ans[j-1]=='S') ans[j]=ans[j-2];
            if(s[j-1]=='x'&&ans[j-1]=='W') ans[j]=ans[j-2];
            if(s[j-1]=='o'&&ans[j-1]=='W'){
                if(ans[j-2]=='S') ans[j]='W';
                else ans[j]='S';
            }
            if(s[j-1]=='x'&&ans[j-1]=='S'){
                if(ans[j-2]=='S') ans[j]='W';
                else ans[j]='S';
            }
        }
        int x=1;
        if(s[n-1]=='o'&&ans[n-1]=='S'){
            if(ans[n-2]!=ans[0]) x=0;
        }
        if(s[n-1]=='x'&&ans[n-1]=='W'){
            if(ans[n-2]!=ans[0]) x=0;
        }
        if(s[n-1]=='o'&&ans[n-1]=='W'){
            if(ans[n-2]==ans[0]) x=0;
        }
        if(s[n-1]=='x'&&ans[n-1]=='S'){
            if(ans[n-2]==ans[0]) x=0;
        }
        if(s[0]=='o'&&ans[0]=='S'){
            if(ans[n-1]!=ans[1]) x=0;
        }
        if(s[0]=='x'&&ans[0]=='W'){
            if(ans[n-1]!=ans[1]) x=0;
        }
        if(s[0]=='o'&&ans[0]=='W'){
            if(ans[n-1]==ans[1]) x=0;
        }
        if(s[0]=='x'&&ans[0]=='S'){
            if(ans[n-1]==ans[1]) x=0;
        }
        if(x){rep(j,n) cout<<ans[j];return 0;}
    }
    cout<<-1;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		byte[] array = new byte[n];
		for (int i = 0; i < array.length; i++) {
			array[i] = sc.nextByte();
		}
		int count = 0;
		boolean flag = true;
		while(flag) {
			flag = false;
			for (int i = 1; i < array.length; i++) {
				if(array[i] < array[i - 1]){
					swap(array, i, i - 1);
					count++;
					flag = true;
				}
			}
		}
		for (int i = 0; i < array.length - 1; i++) {
			System.out.print(array[i] + " ");
		}
		System.out.println(array[array.length - 1]);
		System.out.println(count);
	}
	
	static void swap(byte[] array, int x, int y){
		byte tmp = array[x];
		array[x] = array[y];
		array[y] = tmp;
	}
}


Measured memory_bytes: 26372
#include <bits/stdc++.h>
using namespace std;
const string YES = "Yes";
const string NO = "No";
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;


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

    ll n, sm; cin >> n;
    vll x(n);
    REP(i,n) cin >> x[i];
    sort(ALL(x));
    ll ans = 1000000000;
    for(int i=x[0]; i<=x[n-1]; i++){
        sm=0;
        REP(j,n){
            sm += pow((x[j] - i),2) ;
        }
        ans = min(ans, sm);
    }

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


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

int c;

int decrease(int x, int y){
    if (y>0){
        c=c+1;;
        return decrease(x+1,y-x);
    } else {
        return c;
    }
}

int main(){
    int x;
    cin>>x;
    cout<<decrease(1,x);
    return 0;
}

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

typedef long long ll;
using namespace std;

int main()
{
    int n;
    vector<int> x;
    cin >> n ;
    x.assign(n, -1);
    for (int i = 0; i < n; ++i){
        cin >> x[i];
    }
    ll cnt_min = 100100100100100;
    for (int i = 0; i < 100; ++i)
    {
        int mtg = i;
        ll cnt = 0;
        for (int j = 0; j < x.size(); ++j)
        {
            cnt += (x[j] - i) * (x[j] - i);
        }
        if ( cnt < cnt_min)
            cnt_min = cnt;
    }
    cout << cnt_min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);

ll dp[110][100010]={};

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

    dp[0][0]=1;

    vector<ll> sum(k+2,0);

    for(int i=1;i <= n;i++)
    {
        for(int j=1;j <= k+1;j++)
        {
            sum[j]=sum[j-1]+dp[i-1][j-1];
            sum[j]%=mod;
        }
        

        for(int j=0;j <=k ;j++)//何枚使ったか
        {
            dp[i][j]+=sum[j+1]-sum[max(0,j-a[i-1])]+mod;
            dp[i][j]%=mod;
        }
    }

    cout<<dp[n][k]<<endl;
}

Measured memory_bytes: 80128
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    bool flg=false;
    for(int i=0;i<b;i++){
        if((a*i)%b==c){
            flg=true;
            break;
        }
    }
    if(flg == false)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 200005, INF = 0x3f3f3f3f3f3f3f3f;

ll N, arr[MAXN], dp[MAXN][7];

ll f() {
	for (int pos = 1; pos <= N; pos++) {
		for (int st = 0; st <= 4; st++) {
			if (st > 0) dp[pos-1][st] = min(dp[pos-1][st], dp[pos-1][st-1]);
			ll &ret = dp[pos][st];
			if (st == 0) {
				ll costNow = arr[pos];
				ret = costNow + dp[pos-1][st];
			}
			if (st == 1) {
				ll costNow = arr[pos] == 0 ? 2 : arr[pos]%2 == 1;
				ret = costNow + dp[pos-1][st];
			}
			if (st == 2) {
				ll costNow = arr[pos] % 2 == 0;
				ret = costNow + dp[pos-1][st];
			}
			if (st == 3) {
				ll costNow = arr[pos] == 0 ? 2 : arr[pos] % 2 == 1;
				ret = costNow + dp[pos-1][st];
			}
			if (st == 4) {
				ll costNow = arr[pos];
				ret = costNow + dp[pos-1][st];
			}
		}
	}
	ll ret = INF;
	for (int i = 0; i < 5; i++) {
		ret = min(ret, dp[N][i]);
	}
	return ret;
}

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

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> arr[i];
	}

	ll ans = f();
	cout << ans << "\n";
}

Measured memory_bytes: 12800
#include<iostream>
using namespace std;
int main(){
  string s;
  string t;
  cin>>s;
  cin>>t;
  int count = 0;
  for(int i = 0; i<s.size(); i++){
      for(int j = 0; j<t.size(); j++){
          if(s[i]<t[j]){
              cout<<"Yes"<<endl;
              return 0;
          }
          else if(s[i]==t[j]){
              count++;
          }
              
          
      }
  }
  
  if(count==s.size()*t.size()){
      if(s.size()<t.size()){
          cout<<"Yes"<<endl;
          return 0;      
          
      }
  }
  
  
  cout<<"No"<<endl;
  return 0;
}



Measured memory_bytes: 256
fun main(args : Array<String>) {
    val (n, a, b) = readLine()!!.split(" ").map { it.toLong() }

    val times = n / (a + b)
    val rest = n % (a + b)

    var cnt = times * a

    if (rest <= a) {
        cnt += rest
    } else {
        cnt += a
    }

    println(cnt)
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const int MOD = 1000000007;

inline void add(int &a, int b) {
    a += b;
    if (a >= MOD) {
       a -= MOD;
   }
}

inline void sub(int &a, int b) {
    a -= b;
    if (a < 0) {
       a += MOD;
   }
}

inline int mul(int a, int b) {
    return (long long) a * b % MOD;
}

inline int power(int a, int b) {
    int res = 1;

    while (b > 0) {
        if (b & 1) res = mul(res, a);
        b >>= 1;
        a = mul(a, a);
    }

    return res;
}

inline int inverse(int x) {
    return power(x, MOD - 2);
}

const int MX = 3010;
ll inv[MX], fact[MX], ifact[MX];

void init() {
    inv[1] = 1;
    for (int i = 2; i < MX; ++i) {
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
    }
    fact[0] = ifact[0] = 1;
    for (int i = 1; i < MX; ++i) {
        fact[i] = fact[i-1] * i % MOD;
        ifact[i] = ifact[i-1] * inv[i] % MOD;
    }
}

ll comb(int n, int r) {
    if (n < 0 || r < 0 || r > n) return 0;
    return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD;
}

int main() {
    int N; cin >> N;
    init();
    string s; cin >> s;
    vi vec;
    vec.pb(0);

    rep(i, N-1) {
        if (s[i] == '<') {
            vec.pb(i + 1);
        }
    }
    vec.pb(N);

    vector<ll> dp(vec.size());

    dp[0] = 1;

    rep(i, vec.size()) {
        rep(j, i) {
            ll way = dp[j] * ifact[vec[i] - vec[j]] % MOD;
            if ((i - j) % 2 == 0) {
                dp[i] -= way;
            } else {
                dp[i] += way;
            }
            dp[i] %= MOD;
            if (dp[i] < 0) dp[i] += MOD;
        }
    }

    cout << dp.back() * fact[N] % MOD << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll a, b, n, ans=LLINF;
    cin >> a >> b >> n;
    for(int i=1;i<=n;i++){
        if(b%i==0){
            ll c = b/i, d;
            d = min(n, (a-1)/c+1);
            ans = min(ans, abs(d*c-a));
            if(d<n) ans = min(ans, abs((d+1)*c-a));
            if(d>1) ans = min(ans, abs((d-1)*c-a));
        }
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

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

    int n,m;
    cin>>n>>m;

    int sum=0;

    for(int i=0;i<m;i++)
    {
        int tmp;cin>>tmp;
        sum+=tmp;
    }

    if(n-sum<0)
    {
        cout<<-1<<'\n';
        return 0;
    }

    cout<< n-sum<<'\n';
}

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

using namespace std;

#define endl "\n"
typedef long long int ll;

inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}

//DEBUG
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;

ll INF = 1e10;
int MOD = 1e9+7;

const int mxn = 1e5 + 5;
int n;
vector<int> adj[mxn];
ll white[mxn], black[mxn];
bool vis[mxn];

void DFS(int u){
	vis[u] = true;
	white[u] = black[u] = 1;
	if(u != 1 && adj[u].size() == 1) return;
	for(auto v: adj[u]){
		if(!vis[v]){
			DFS(v);
			white[u] *= (white[v]+black[v]);
			black[u] *= white[v];
			white[u]%=MOD;
			black[u]%=MOD;
		}
	}
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("debug.txt", "w", stderr);
    #endif
    fastio();
    cin>>n;
    for(int i=0;i<n-1;++i){
    	int x,y;
    	cin>>x>>y;
    	adj[x].push_back(y);
    	adj[y].push_back(x);
    }
    if(n == 1){
    	cout<<2;
    	return 0;
    }
    DFS(1);
    cout<<(white[1]+black[1])%MOD;
    return 0;
}


Measured memory_bytes: 16172
#include<bits/stdc++.h>   
typedef long long ll;
using namespace std;
     
    ll gcd(ll a, ll b){
    if(a<b){return gcd(b,a);}
    else if(a%b){return gcd(b,a%b);}
    else{return b;}
    }
    int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll ans = 0;
        if(a==b&&b==c&&a%2==0){
        cout<<-1<<endl; return 0;
        }
        while(gcd((a,b),c)%2!=1){
      ans++;
      ll x=(b+c)/2,y=(c+a)/2,z=(a+b)/2;
      a=x,b=y,c=z;
        }
    cout<<ans<<endl;
     
    }

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n[4];
	cin>>n[0]>>n[1]>>n[2]>>n[3];
	sort(n, n+4);
	if(n[0]==1 && n[1]==4 && n[2]==7 && n[3]==9) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    ll n;
    cin >> n;
    int input[n];
    rep0(i,n)
    {
        cin >> input[i];
    }
    int now=input[0];
    bool res = true;
    rep0(i,n)
    {
        if(now>input[i]){
            res = false;
            break;
        }
        now=max(input[i]-1,now);
    }
    if(res){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
        

}


Measured memory_bytes: 4004
import java.util.Arrays;

public class Main {
  private static void solve() {
    int[] a = na(3);
    Arrays.sort(a);
    
    int count = 0;
    
    int x = (a[2] - a[0]) / 2;
    count += x;
    a[0] += x * 2;
    
    int y = (a[2] - a[1]) / 2;
    count += y;
    a[1] += y * 2;
    
    Arrays.sort(a);
    
    if (a[0] == a[2]) {
      System.out.println(count);
    } else if (a[0] < a[1]) {
      System.out.println(count + 2);
    } else if (a[0] == a[1]) {
      System.out.println(count + 1);
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




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

int main(void)
{
  int N;
  cin >> N;
  int n = N % 10;

  if (n == 3)
  {
    cout << "bon" << endl;
  }
  else if (n == 0 || n == 1 || n == 6 || n == 8)
  {
    cout << "pon" << endl;
  }
  else
  {
    cout << "hon" << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
  ll N, T, A, ans=-1;
  double ld = 1e9;
  cin >> N >> T >> A;
  vector<ll> H(N);
  for (int j=0; j < N; ++j) {
    cin >> H[j];
  }
  for (int j=0; j < N; ++j) {
    double t = (double)T - H[j] * 0.006;
    double d = abs((double)A-t);
    if (ans == -1 || d < ld) {
      ld = d;
      ans = j;
    }
  }
  cout << ans+1 << endl;
}


Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : l : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    d | l <= (- n) = l + n - 1
      | 0 < l = l
      | otherwise = 0
  print $ n * l + ((pred n * n) `div` 2) - d

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b) a=b;};
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b) a=b;};

const Int MAX = 5050;
const Int INF = 1e9;
Int dp[MAX][MAX];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  Int n;
  cin>>n;
  vector<Int> v(n);
  for(Int i=0;i<n;i++) cin>>v[i];

  sort(v.begin(),v.end());

  unordered_map<Int, Int> rev;
  for(Int i=0;i<n;i++) rev[v[i]]=i;
  
  for(Int i=0;i<MAX;i++)
    for(Int j=0;j<MAX;j++)
      dp[i][j]=i>j?2:-INF;

  Int ans=2;
  for(Int i=0;i<n;i++){
    for(Int j=0;j<i;j++){
      Int x=v[i]+(v[i]-v[j]);
      if(!rev.count(x)) continue;
      Int k=rev[x];
      chmax(dp[k][i],dp[i][j]+1);
      chmax(ans,dp[k][i]);
    }    
  }
  
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 202688
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] ar = new int[100];
    for(int i=0;i < n;i++){
      ar[n-i-1] = sc.nextInt();
    }
    for(int i = 0;i < n;i++){
      System.out.print(ar[i]);
      if(i != n-1){
        System.out.print(" ");
      }
    }
    System.out.println("");
    sc.close();
  }
}



Measured memory_bytes: 26284
# ダイクストラ法で部屋1から各部屋への最短経路を出す
import queue

n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]

# 隣接行列の作成
edges_dict = {}
for edge in edges:
    a, b = edge

    if a not in edges_dict:
        edges_dict[a] = [b]
    else:
        edges_dict[a].append(b)

    if b not in edges_dict:
        edges_dict[b] = [a]
    else:
        edges_dict[b].append(a)

# 定数 
COST = 1
INF = 1e10

# i=0は未使用, i>0は部屋iへの最短距離
dist_list = [INF] * (n + 1)
# i=0は未使用, i>0は部屋iの最短経路がたどる次の部屋 = 道しるべ
prev_list = [None] * (n + 1)
q = queue.PriorityQueue()

# 初期化
q.put((0, 1)) # (最短経路, 部屋番号)
dist_list[1] = 0
prev_list[1] = 1

while not q.empty():
    min_dist, v = q.get()
    #print("min_dist={}, v={}".format(min_dist, v))

    if dist_list[v] < min_dist:
        #print("waste")
        continue

    #print("check edges: ", edges_dict[v])
    for w in edges_dict[v]:
        cost = dist_list[v] + COST
        if dist_list[w] > cost:
            #print("push path {} -> {}; cost {}; path {}".format(v, w, cost, prev_list[v]))
            dist_list[w] = cost
            prev_list[w] = v#prev_list[v]
            q.put((cost, w))

print("Yes")
#print(edges_dict)
#print(dist_list)
#print(prev_list)
for v in prev_list[2:]:
    print(v)


Measured memory_bytes: 68516
from fractions import gcd
n, x = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= x
    a[i] = abs(a[i])
ans = a[0]
for i in range(1, n):
    ans = gcd(ans, a[i])
print(ans)

Measured memory_bytes: 88172
#include <iostream>
#include <vector>
#include<set>
using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	set<int>Setter;
	
	for(int i = 0;i<N;i++){
		cin >> A[i];
		Setter.insert(A[i]);
	}
	
	if(N == Setter.size()){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
	
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define f first
#define s second

int main(){
	ll l, r;
	cin>> l >> r ;
	if(r-l>2019){
		cout<<0<<endl;
	}
	else{
		ll mn = 1e9;
		for(ll i = l ; i< r ; i++){
			for(ll j= i+1 ; j<= r ; j++){
				ll ps = (i%2019*j%2019)%2019;
				mn= min(mn, ps);
			}
		}
		cout<<mn<<endl;
	}
}

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

using namespace std;

int main(){
    string o, e, a;
    int olen, elen;

    cin >> o >> e;
    olen = o.size();
    elen = e.size();

    for(int i = 0; i < olen; i++){
        a.push_back(o[i]);
        if(i < elen) a.push_back(e[i]);
    }

    cout << a << endl;
}

Measured memory_bytes: 3600
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

template<typename T, class Predicate>
T partition_point_num(T left, T right, Predicate pred)
{
    while(left <= right) {
        T mid = (left + right) / (T)2;

        if (pred(mid)) {
            left = mid + 1;
        }
        else {
            right = mid - 1;
        }
    }
    return left;
}


/**
   ceil(0, 2) == 0
   ceil(1, 2) == 1
   ceil(2, 2) == 1
   ceil(3, 2) == 2
   ceil(4, 2) == 2
*/
template<class T>
T ceil(T dividend, T divisor)
{
    return (dividend + (divisor - 1)) / divisor;
}

int main()
{
    int64_t N, A, B;
    std::cin >> N >> A >> B;

    std::vector<int64_t> H;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        H.push_back(t);
    }

    std::sort(std::begin(H), std::end(H));

    const auto maxcount = 1 << 30;

    A -= B;

    auto i = partition_point_num<int64_t>(1, maxcount,
                                          [A, B, &H](auto c) {
                                              auto itr = std::partition_point(H.begin(),
                                                                              H.end(),
                                                                              [B, c](int64_t hp) {
                                                                                  return hp <= B*c;
                                                                              });
                                              if (itr == H.end()) {
                                                  return false;
                                              }
                                              int64_t append = 0;
                                              for (; itr != H.end(); ++itr) {
                                                  append += ceil(*itr - B*c, A);
                                              }
                                              if (append <= c) {
                                                  return false;
                                              }
                                              return true;
                                          });

    std::cout << i << std::endl;
    return 0;
}


Measured memory_bytes: 1400
n, m = map(int, input().split())
a = [input().strip() for _ in range(n)]
b = [input().strip() for _ in range(m)]

ans = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        inc = True
        for ii in range(m):
            for jj in range(m):
                if a[i+ii][j+jj] != b[ii][jj]:
                    inc = False

        if inc:
            ans = True

print('Yes' if ans else 'No')

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


int H,W;
bool michi[22][22];
int d[22][22][22][22];


void warshall_floyd() {
  for (int mh=1; mh<=H; mh++) for (int mw=1; mw<=W; mw++) {
    if(!michi[mh][mw]) continue;
    for (int sh=1; sh<=H; sh++) for (int sw=1; sw<=W; sw++) {
      if(!michi[sh][sw]) continue;
      for (int eh=1; eh<=H; eh++) for (int ew=1; ew<=W; ew++) {
        if(!michi[eh][ew]) continue;
        d[sh][sw][eh][ew] = min(d[sh][sw][eh][ew], d[sh][sw][mh][mw] + d[mh][mw][eh][ew]);
      }
    }
  }
}

signed main() {
  cin >> H >> W;
  for (int h=1; h<=H; h++) for (int w=1; w<=W; w++) {
    char c; cin >> c;
    if( c == '.' ) michi[h][w] = true;
  }

  for (int sh=1; sh<=H; sh++) for (int sw=1; sw<=W; sw++) {
    for (int eh=1; eh<=H; eh++) for (int ew=1; ew<=W; ew++) {
      if(sh==eh && sw==ew) {
        d[sh][sw][eh][ew] = 0;
      }
      else if(!michi[sh][sw] || !michi[eh][ew]) {
        d[sh][sw][eh][ew] = 1000000;
      }
      else if(((int)abs(sh-eh) == 1 && (int)abs(sw-ew) == 0) || ((int)abs(sh-eh) == 0 && (int)abs(sw-ew) == 1)) {
        d[sh][sw][eh][ew] = 1;
      }
      else {
        d[sh][sw][eh][ew] = 1000000;
      }
    }
  }

  warshall_floyd();

  int ans = 0;

  for (int sh=1; sh<=H; sh++) for (int sw=1; sw<=W; sw++) {
    for (int eh=1; eh<=H; eh++) for (int ew=1; ew<=W; ew++) {
      if(sh==eh && sw==ew) continue;
      if(!michi[sh][sw] || !michi[eh][ew]) continue;
      ans = max(ans, d[sh][sw][eh][ew]);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <array>
#include <map>
#include <set>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> vs(2, vector<int>(n));

    for (auto &row : vs)
    {
        for (auto &item : row)
        {
            cin >> item;
        }
    }

    int max_count = -1;
    for (int i = 0; i < n; i++)
    {
        int count = 0;
        for (int j = 0; j <= i; j++)
        {
            count += vs[0][j];
        }
        for (int j = i; j < n; j++)
        {
            count += vs[1][j];
        }
        max_count = max(max_count, count);
    }
    cout << max_count << endl;
}


Measured memory_bytes: 384