akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main(){
    int i, joi = 0, ioi = 0;
    char str[10000];
    
    while (scanf("%s", str) != EOF) {

        for (i = 0; i < strlen(str) - 3; i++) {
            if (str[i] == 'J' && str[i + 1] == 'O' && str[i + 2] == 'I')
                joi++;
            if (str[i] == 'I' && str[i + 1] == 'O' && str[i + 2] == 'I')
                ioi++;
        }
        printf("%d\n%d\n", joi, ioi);
        joi = 0, ioi = 0;
    }
    return 0;
}

Measured memory_bytes: 556
#include <bits/stdc++.h>
using namespace std;
#define ri rd<int>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; --i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++i)
const int maxN = 2e5 + 7;

template<class T> T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x;
}

int n;
int a[maxN];
int occ[maxN];
int len[maxN];

int main() {
	
	n = ri();
	rep (i, 1, n) a[i] = ri();
	rep (i, 1, n) {
		if (!occ[a[i]-1]) len[i] = 1;
		else len[i] = len[occ[a[i]-1]] + 1;
		occ[a[i]] = i;
	}
	int res = 0;
	rep (i, 1, n) res = max(res, len[i]);
	printf("%d\n", n - res);

	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int INF = 1e18;
int dist[10][10];
signed main(){
    int h,w;cin >> h >> w;
    rep(i,10)rep(j,10)cin >> dist[i][j];
    rep(i,10)rep(j,10)rep(k,10)dist[j][k] = min(dist[j][k],dist[j][i] + dist[i][k]);
    int ret =0 ;
    rep(i,h*w){
        int a;cin >> a;
        if(a ==-1)continue;
        ret += dist[a][1];
    }
    cout << ret << endl;

    

    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>

using namespace std;
int main (){
    int a,b,c;
    cin >> a >> b >> c;
    bool jud=false;
    for (int i = 1; i <= a; i++){
        if((c+b*i)%a == 0) jud=true;
    }
    if(jud) cout << "YES\n";
    else cout << "NO\n";
}

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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e6;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 1, (int)A.size()) out << A[i]+1 << " ";
    return out;
}

int B[(int)1e6+1];

int32_t main() {
    IOS 
    int n;  cin>>n;
    vector<int> A(n);
    memset(B,0,sizeof(B));
    fr(i,0,n){
        cin>>A[i];
        if(B[A[i]] == 0){
            for(int j=A[i]; j<=Maxn;j+=A[i])    B[j]++;    
        }else{
            B[A[i]]++;
        }
    }
    int ans = 0;
    for(auto ele : A){
        if(B[ele] == 1)   ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 12664
s = int(input())
a = [s]
while True:
    n = a[-1]
    if n % 2 == 0:
        next = n // 2
    else:
        next = 3 * n + 1
    if next in a:
        print(len(a) + 1)
        exit()
    a.append(next)


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
vector<ll> divisor(ll x){
	vector<ll> div;
	for(int i=1;i*i<=x;i++){
		if(i*i!=x && x%i==0){
			div.pb(i);
			div.pb(x/i);
		}
		else if(x%i==0) div.pb(i);
	}
	return div;
}
vector<ll> vectorprime(ll x){
	vector<bool> is_prime(x+1);
	vector<ll> prime;
	rep(i,x+1) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=x;i++){
		if(is_prime[i]){
			prime.pb(i);
		}
		for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
	}
	return prime;
}

//a,b x
int main(){
	ll N,L; cin>>N>>L;
	vector<ll>A(N);
	rep(i,N) cin>>A[i];
	//0 1 2 ... N-2 N-1
	// 0 1 ...... N-2(+1で答ヨ)
	bool ans=false;
	ll mem=0;	
	rep(i,N-1){
		if(A[i]+A[i+1]>=L){
			ans=true;
			mem=i+1;
		}
	}
	if(ans){
		cout<<"Possible"<<endl;
		rep1(i,mem-1) cout<<i<<endl;
		for(int i=N-1;i>mem;i--) cout<<i<<endl;
		cout<<mem;
	}
	else cout<<"Impossible";
}

Measured memory_bytes: 1664
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=list(Counter(a).items())
c.sort(reverse=True)
ans=0
for a,b in c:
    if(b>=4):
        if(ans==0):
            print(a*a)
            exit()
        else:
            print(ans*a)
            exit()
    elif(b>=2):
        if(ans!=0):
            print(ans*a)
            exit()
        else:
            ans=a
print(0)

Measured memory_bytes: 21412
#include<iostream>
#include<bitset>
#include<stack>
#include<queue>
using namespace std;
void reset(queue<int>& que, stack<int>& st) {
	while (que.size())que.pop();
	while (st.size())st.pop();
	return;
}
int main() {
	double n, point;
	int in;
	bool flag;
	queue<int>que;
	stack<int>st;
	while (1) {
		reset(que, st);
		cin >> n;
		if (n < 0)break;
		in = (int)n;
		point = (double)n - in;
		
		if (n >= 256 ) {
			cout << "NA" << endl;
			continue;
		}
		flag = true;
		if (point != 0) {
			for (int i = 0; i < 4; ++i) {
				point *= 2;
				if (point == 1.0) {
					flag = false;
					que.push(1);
				}
				else {
					if ((int)point == 1) {
						que.push(1);
						point -= 1;
					}
					else que.push(0);
				}
			}
			if (flag) {
				cout << "NA" << endl;
				continue;
			}
		}
		else for (int i = 0; i < 4; ++i)que.push(0);


		for (int i = 0; i < 8; ++i) {
			if (in % 2 == 0) {
				st.push(0);
			}
			else {
				st.push(1);
			}
			in /= 2;
		}
		while (st.size()) {
			cout << st.top();
			st.pop();
		}cout << ".";
		while (que.size()) {
			cout << que.front();
			que.pop();
		}
		cout << endl;

	}
	return 0;
}


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

typedef long long LL;
typedef unsigned long long LONG;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
using namespace std;
typedef pair<int, int> PII;
#define ft fisrt
#define sd second
#define eb emplace_back
#define END '\n'

template <class T>
inline bool Read(T &ret)
{
	char c;
	int sgn;
	if (static_cast<void>(c = getchar()), c == EOF)
		return 0;
	while (c != '-' && (c < '0' || c > '9'))
		c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
		ret = ret * 10 + (c - '0');
	ret *= sgn;
	return 1;
}

template <class T>
inline void Write(T x)
{
	if (x < 0)
		putchar('-'), Write(x);
	if (x > 9)
		Write(x / 10);
	putchar(x % 10 + '0');
}


vector<int>R,G,B;
int n;
string s;
int check(int i,int j){
	int l=0,num=0;
	int k=j+(j-i)+1;
	if((s[i]=='R'&&s[j]=='G')||(s[j]=='R'&&s[i]=='G')){
		i++;j++;
		num=B[n]-B[j];
		if(k<=n) num-=(B[k]-B[k-1]);
	}
	else if((s[i]=='R'&&s[j]=='B')||(s[j]=='R'&&s[i]=='B')){
		i++;j++;
		num=G[n]-G[j];
		if(k<=n) num-=(G[k]-G[k-1]);
	}
	else if((s[i]=='B'&&s[j]=='G')||(s[j]=='B'&&s[i]=='G')){
		i++;j++;
		num=R[n]-R[j];
		if(k<=n) num-=(R[k]-R[k-1]);
	}
	return num;
}
void solve(int question_num)
{
	while (question_num--)
	{
		cin>>n;
		cin>>s;
		R.resize(n+1);
		G.resize(n+1);
		B.resize(n+1);
		for(int i=0;i<n;++i){
			if(s[i]=='R') R[i+1]=R[i]+1;
			else R[i+1]=R[i];
			if(s[i]=='B') B[i+1]=B[i]+1;
			else B[i+1]=B[i];
			if(s[i]=='G') G[i+1]=G[i]+1;
			else G[i+1]=G[i];
		}
		// for(int i=1;i<=n;++i)
			// cout<<R[i]<<' '<<G[i]<<' '<<B[i]<<endl;
		LL ans=0;
		for(int i=0;i<n-2;++i){
			for(int j=i+1;j<n-1;++j){
				if(s[i]!=s[j]){
					ans+=check(i,j);
				}
			}
		}
		cout<<ans;
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t = 1;
	// cin >> t;
	solve(t);
	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<complex>
#include<bitset>
#include<numeric>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

const int MAX_H = 2000, MAX_W = 2000;
int H, W;
string S[MAX_H];
int bad[MAX_H - 1][MAX_W - 1];

signed main() {
    cin >> H >> W;
    rep(i, H) {
        cin >> S[i];
    }
    rep(h, H - 1) {
        rep(w, W - 1) {
            rep(i, 2) {
                rep(j, 2) {
                    bad[h][w] += (S[h + i][w + j] == '#');
                }
            }
            bad[h][w] %= 2;
        }
    }
    rep(w, W - 1)bad[0][w] = 2 - bad[0][w];
    rep(h, H - 2) {
        rep(w, W - 1) {
            if (bad[h + 1][w] == 1)bad[h + 1][w] = 1;
            else bad[h + 1][w] = bad[h][w] + 1;
        }
    }
    int ans = max(H, W);
    rep(h, H - 1) {
        stack<pii> st;
        rep(w, W - 1) {
            int tmp = w;
            while (!st.empty() && st.top().second > bad[h][w]) {
                pii p = st.top();
                st.pop();
                ans = max(ans, p.second * (w - p.first + 1));
                tmp = p.first;
            }
            st.push(pii(tmp, bad[h][w]));
        }
        while (!st.empty()) {
            pii p = st.top();
            st.pop();
            ans = max(ans, p.second * (W - p.first));
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    ll S; cin >>S;
    
    // (0, 0), (1e9, 1), (x, y) の3点を頂点とする三角形を考える
    const ll ma = 1e9;
    ll x, y;

    y = (S + ma - 1) / ma;
    x = ma * y - S;
    cout << "0 0 ";
    cout << "1000000000 1 ";
    cout << x << " " << y << endl;
}


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

int main()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[0] <<" "<< a[1] << " " << a[2] << endl;
    return 0;
}

Measured memory_bytes: 1184
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>b){
		printf("%d",2*a-1);
	}
	else if(b>a){
		printf("%d",2*b-1);
	}
	else{
		printf("%d",2*a);
	}
	return 0;
}

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

int main(){
    int n;
    bool ans = 0;
    cin >> n;
    for(int i = 0;i < 3;i++){
    if(n%10 == 7){
        ans = 1;
    }
    n -= n%10;
    n /= 10;
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
	int a, b;
	cin >> a >> b;
	if(a + b >= 10) cout << "error" << endl;
	else cout << a + b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Nmax=200010;
//ll a[Nmax];
//int* P = new int[N];
int main() {
	char c[10];
	for(int i=0;i < 10;i++) cin >> c[i];
	if(c[3] == '7') c[3] = '8';
	for(int i=0;i < 10;i++) cout << c[i];
	
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	
	if (n < 1000)
	{		
		cout << "ABC" << endl;
	}
	else
	{
		cout << "ABD" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val x = readLine()!!.toInt()

    var min = 0
    var max = 0

    while (min < x && max < x) {
        min += 100
        max += 105
    }

    if (x in min..max) {
        println(1)
    } else {
        println(0)
    }


}


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

int main(int argc, char *argv[]){
  int n;
  cin>>n;
  vector<int> vec(n+1,0);
  vector<int> oddHist(100001,0);
  vector<int> evenHist(100001,0);
  int flag=1;
  for(int i=1; i<n+1; i++){
    int v;
    cin>>v;
    vec[i]=v;
    if(i%2==0) evenHist[v]++;
    else       oddHist[v]++;
    if(i>1){
      if(vec[i]!=vec[i-1]) flag=-1;
    }
  }
  
  if(flag==1) {
    cout<<n/2<<endl;
    return 0;
  }
  int oddMax=-1;
  int evenMax=-1;
  int odd;
  int even;
  int cnt=1;
  int oddT2max=-1;
  int evenT2max=-1;
  int oddT2,evenT2;
  for(auto itr=vec.begin()+1; itr!=vec.end(); ++itr,cnt++){
    if(cnt%2==0){
      if(evenHist[*itr]>=evenMax){
	evenMax=evenHist[*itr];
	even=*itr;
      }
      else if(evenHist[*itr]>=evenT2max){
	evenT2max=evenHist[*itr];
	evenT2=*itr;
      }
    }  
    else{
      if(oddHist[*itr]>=oddMax){
	oddMax=oddHist[*itr];
	odd=*itr;
      }
      else if(oddHist[*itr]>=oddT2max){
	oddT2max=oddHist[*itr];
	oddT2=*itr;
      }
    }
  } 


    
    
  
  
  //cout<<odd<<" "<<even<<" "<<oddMax<<" "<<evenMax<<endl;
  int count=0;
  if(even==odd){
    //cout<<oddT2max<<" "<<evenT2max<<endl;
    if(oddT2max>evenT2max) odd=oddT2;
    else if(oddT2max<evenT2max) even=evenT2;
  }

    
  if(evenMax==1){
    for(int i=4; i<=n; i+=2){
      count++;
    }
  }
  if(oddMax==1){
    for(int i=3; i<=n-1; i+=2){
      count++;
    }
  }
  else if(evenMax!=1 && oddMax!=1){
    for(int i=1; i<n+1; i++){
      if(i%2==0){
	if(vec[i]!=even) count++;
      }
      else{
	if(vec[i]!=odd) count++;
      }
    }
  }
  
  


 
  cout<<count<<endl;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t l, r;
  std::cin >> l >> r;

  std::vector<int64_t> li(2019, 0);

  for (int64_t i = l; i <= r && i <= l + 2019 * 3; i++) {
    li[i % 2019]++;
  }

  int64_t ans = 2019;

  for (int64_t i = 0; i < 2019; i++) {
    if (2 <= li[i]) {
      ans = std::min(ans, (i * i) % 2019);
    }
    for (int64_t j = i + 1; j < 2019; j++) {
      if (1 <= li[i] && 1 <= li[j]) {
        ans = std::min(ans, (i * j) % 2019);
      }
    }
  }

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


Measured memory_bytes: 256
n,m = map(int,input().split())
ac_c = [False]*(n+1)
wa_c = [0]*(n+1)

for i in range(m):
    p,s=input().split()
    p = int(p)
    if(ac_c[p]):
        continue
    if(s=='WA'):
        wa_c[p] += 1
    if(s=='AC'):
        ac_c[p] = True

wa_ans = 0
for i in range(1,n+1):
    if(ac_c[i]):
        wa_ans += wa_c[i]
print(sum(ac_c),wa_ans)

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

int main()
{
    int n, l, s = 0, m = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &l);
        if (l > m) m = l;
        s += l;
    }
    cout << ((m*2 < s) ? "Yes" : "No");
}

Measured memory_bytes: 3724
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

def solve (i, m):
    if m == 0:
        return True
    elif i >= n:
        return False
    res = solve(i+1, m) or solve(i+1, m-A[i])
    return res

for m in M:
    if m < min(A) or m>sum(A):
        print('no')
    else:
        if solve(0, m):
            print('yes')
        else:
            print('no')


Measured memory_bytes: 5632
#include<stdio.h>

int main(void){
    int p[101];
    int a,b,x,n,m,flag,count;
    scanf("%d %d",&x,&n);
    for(a = 0;a < n;a++){
        scanf("%d",&p[a]);
    }
    for(a = 0;a <= 60;a++){
        flag = 0;
        count = 0;
        for(b = 0;b < n;b++){
            if(x - a == p[b]){
                flag++;
            }
            if(x + a == p[b]){
                count++;
            }
        }
        if(flag == 0 || count == 0){
            if(flag == 0){
                m = x-a;
            }else{
                m = x+a;
            }
            break;
        }
    }
    printf("%d\n",m);
    
    /*d = x - a;
    e = x + a;
    int flagd = 0,flage = 0;
    for(b = 0;b < n;b++){
        if(d == p[b]){
            flagd++;
        }
        if(e == p[b]){
            flage++;
        }
    }
    if(flagd == 0){
        printf("%d\n",d);
    }else if(flage == 0){
        printf("%d\n",e);
    }*/
    return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define ll long long

const ll MOD = 1000000007;

using namespace std;

int main(){
  
  ll N;
  cin >> N;
  
  ll ar[N], reversePrefix[N];
  
  for (int i = 0; i < N; i++){ cin >> ar[i]; }
  
  reversePrefix[N-1] = ar[N-1];
  
  for (int i = N-2; i >= 0; i--)reversePrefix[i] =( (reversePrefix[i+1] + ar[i])%MOD);
  ll total = 0;
  
 
  
  for (int i = 0; i < N-1; i++) {total += ((ar[i]*reversePrefix[i+1])%MOD); total %= MOD;}
  cout << total << endl;
  
	

	return 0;
}

Measured memory_bytes: 6744
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

A,B = inputIL()

if abs(A-B)>=2:
  m= max(A,B)
  print(m+m-1)
else:
  print(A+B)

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

int main() {
  int N, x, S=0, c=0;
  cin >> N >> x;
  
  vector<int> A(N);

  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());
  
  while (S < x && c < N){
    S = S + A.at(c);
    c = c + 1;
  }
  if (S == x){
    cout << c <<endl;
  }
  else{
    cout << c-1 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A, B;
    int cnt;
    string str;


    cin >> A >> B;

    for(int i=A; i<=B; i++)
    {
        str = to_string(i);
        if( str[0] == str[4]  &&  str[1] == str[3] )
            cnt++;    
    }

    cout << cnt << endl;

    return 0;
}

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

main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k=0,l,m,n,p,t;
   for(i=0;i<5;i++){
    cin>>j;
    if(j==0)k=i;
   }
   cout<<k+1<<endl;
    return 0;

}


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

using namespace std;

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

typedef long long ll;

int main(){
 ll n,m;
  cin >> n >> m;
  
   ll res=0;
  priority_queue<ll> que;
  rep(i,0,n){
    ll a;
    cin >> a;
    que.push(a);
  }
  
  rep(i,0,m){
   ll a=que.top();
    a/=2;
    que.pop();
    que.push(a);
  }
  
  while(!que.empty()){
   ll a=que.top();
    que.pop();
   res+=a;
  }
  
  
 cout << res << endl;
  
}

Measured memory_bytes: 1400
#include<iostream>
#include <bits/stdc++.h>
#include<algorithm>
#include <cstring>
#define endl "\n"
#define ll long long
using namespace std;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k,x,i;
    cin >> n >> k;
    vector <int> vect;
    for (i = 0; i < n; i++)
    {
        cin >> x;
        vect.push_back(x);
    }
    int l = 0;
    for (i = k; i < vect.size(); i++)
    {
        if (vect[i] > vect[l])
        {
            cout << "Yes\n";
        }
        else
        {
            cout << "No\n";
        }
        l++;
    }
}


Measured memory_bytes: 4284
n = int(input())
stair = list(map(int, input().split()))

for i in reversed(range(1, n)):
    d = stair[i] - stair[i - 1]
    if d < -1:
        print("No")
        exit()
    elif d == -1:
        stair[i - 1] -= 1
print("Yes")


Measured memory_bytes: 14252
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
antennas = [a, b, c, d, e]

flag = 0
for i in range(5):
  if flag == 1:
    break
    
  for j in range(5):
    if i == j or i > j:
      continue
    if antennas[j] - antennas[i] > k:
      print(':(')
      flag = 1
      break
 
if flag == 0:
  print('Yay!')

Measured memory_bytes: 3064
class UnionFind

  def initialize(n)
    @p = *0...n
    @r = [1] * n
  end

  def find(x)
    @p[x] == x ? x : @p[x] = find(@p[x])
  end

  def unite(x, y)
    x = find(x)
    y = find(y)
    return 0 if x == y
    s = @r[x] * @r[y]
    if @r[x] < @r[y]
      @p[x] = y
      @r[y] += @r[x]
    else
      @p[y] = x
      @r[x] += @r[y]
    end
    s
  end

  def same(x, y)
    find(x) == find(y)
  end

end

(n,m),*ab=$<.map{|s|s.split.map &:to_i}
uf=UnionFind.new(n+1)
s=0
p *ab.reverse.map{|a,b|
q=n*(n-1)/2-s
if not uf.same(a,b)
s+=uf.unite(a,b)
end
q
}.reverse

Measured memory_bytes: 16248
#create date: 2020-03-23 11:51

import sys
stdin = sys.stdin

import numpy as np

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = np.array(na())
    counter = np.bincount(a)
    total = np.sum(counter*(counter-1))//2
    answer = (total - (counter-1))[a]
    print(*answer, sep="\n")

if __name__ == "__main__":
    main()

Measured memory_bytes: 34736
#include <iostream>

using namespace std;

const int MAXN = 5e5 + 10;

int first[MAXN];
class Edges{
public:
	int next , to;
};

Edges edge[MAXN << 1];
int te = 0;
string s;
int N , deg[MAXN];

typedef long long ll;

ll ans = 0;

void add(int s , int t){
	++ te;
	edge[te].to = t;
	edge[te].next = first[s];
	deg[t] ++;
	first[s] = te;
}

int q[MAXN] , val[MAXN];
int main(){
	cin >> s;
	N = s.size();
	for(int i = 0 ; i < N ; ++ i){
		if(s[i] == '<')
			add(i + 1 , i + 2);
		else
			add(i + 2 , i + 1);
	}
	int head = 0 , tail = 0;
	for(int i = 1 ; i <= N + 1 ; ++ i)
		if(deg[i] == 0)
			q[++ tail] = i;
	while(head < tail){
		++ head;
		for(int e = first[q[head]] ; e ; e = edge[e].next){
			int to = edge[e].to;
			deg[to] --;
			if(deg[to] == 0){
				q[++ tail] = to;
				val[to] = val[q[head]] + 1;
			}
		}
	}
	
	for(int i = 1 ; i <= N + 1 ; ++ i)
		ans += val[i];
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 14468
n=int(input())
l=sorted(list(map(int,input().split())))
num=l[-1]
b1=[]

while num!=0:
  b1.append(num%2)
  num//=2
d={}
for i in range(len(b1)):
  d[i]=b1[i]

for i in range(2,n+1):
  num=l[-i]
  count=0
  while num!=0 or count<len(b1):
    d[count]+=num%2
    num//=2
    count+=1

ans=0
table=[1]
for i in range(60):
  table.append((2*table[-1])%(10**9+7))
for i in d: 
  ans=(ans+table[i]*(n-d[i])*d[i])%(10**9+7)
print(ans)

Measured memory_bytes: 123056
#include <bits/stdc++.h>
		using namespace std;
		#define pll pair<ll,ll>
		typedef long long ll;
		#define mod 1000000007
		#define fi first
		#define se second
		#define mp make_pair
		#define pb push_back
		#define INF 1e15
	
		
		int main()
		{
			ll n,m;
			cin>>n>>m;
			vector<ll> v(n);
			for(ll i=0;i<n;i++)
				{cin>>v[i];v[i]/=2;}
			ll g=v[0];
			ll lcm=v[0];
			for(ll i=1;i<n;i++)
			{
				g=__gcd(lcm,v[i]);
				lcm=(lcm*v[i]);
				lcm=lcm/g;
				if(lcm>m)
				{
					cout<<0;
					return 0;
				}
			}
			for(ll i=0;i<n;i++)
			{
				ll k1=lcm/v[i];
				if(k1%2==0)
				{
					cout<<0;
					return 0;
				}
			}
			ll k=m/lcm;
			if(k%2==1)
				cout<<k/2+1;
			else
				cout<<k/2;
			
		}


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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}

ll dp[12][10];

ll solve(ll i,ll num)
{
	if((num<0)||(num>9))
		return 0;
	if(i==11)
		return dp[i][num]=1;
	if(dp[i][num]!=-1)
		return dp[i][num];
	return dp[i][num] = solve(i+1,num)+solve(i+1,num-1)+solve(i+1,num+1);
}

int main()
{
	fastio;
	ll num=1;
	ll k,i,j;
	cin>>k;
	for(i=11;i>=0;i--)
	{
		memset(dp,-1,sizeof(dp));
		for(j=1;j<10;j++)
		{
			ll val = solve(i,j);
			if(k<=val)
				break;
			k-=val;
		}
		if(j!=10)
			break;
	}
	vector<ll> v;
	// for(i=0;i<12;i++)
	// {
	// 	for(j=0;j<10;j++)
	// 		cout<<dp[i][j]<<" ";
	// 	cout<<endl;

	// }
	ll pre=j;
	v.pb(j);
	i++;
	for(;i<12;i++)
	{
		for(j=0;j<10;j++)
		{
			if(abs(pre-j)>1)
				continue;
			if(dp[i][j]>=k)
				break;
			k-=dp[i][j];
		}
		// j = max(j-1,0LL);
		v.pb(j);
		pre=j;
		// cout<<j<<" ";
	}
	ll ans=0;
	for(i=0;i<sz(v);i++)
		ans=ans*10+v[i];
	cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 3640
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H1 = sc.nextInt();
		int M1 = sc.nextInt();
		int H2 = sc.nextInt();
		int M2= sc.nextInt();
		int K = sc.nextInt();
		
		System.out.println(H2*60 - H1*60 + M2 - M1 - K);

	}
}



Measured memory_bytes: 35800
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  REP(i, n - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = $stdin.gets.split.map {|i| i.to_i }
A = $stdin.gets.split.map {|i| i.to_i }
total = A.inject(:+)
limit = total / (4.0 * M)
result = A.select {|ai| ai >= limit }
puts result.length >= M ? 'Yes' : 'No'


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<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; }



int main(int argc, char const *argv[]) {
  int x;
  cin >> x;
  if(x==0) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}

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

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

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;

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

int main() {
    int N; cin >> N;
    cout << 0 << endl;
    string s; cin >> s;
    if(s == "Vacant") {
        return 0;
    }
    int type = s == "Male";
    int lb = 0, ub = N;
    while(ub - lb > 2) {
        int mid = (ub + lb) / 2;
        if((mid - lb) % 2 != 0) mid++;
        cout << mid << endl;
        cin >> s;
        if(s == "Vacant") return 0;
        int type2 = s == "Male";
        if(type == type2) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    cout << lb << endl;
    cin >> s;
    if(s == "Vacant") return 0;
    cout << lb + 1 << endl;
}


Measured memory_bytes: 876
//連鎖は、色を変えた場所付近から起こる＆0連鎖になるものをわざわざ消す必要はない。
//ということで、シミュレーションの前に、（色を変えるべき場所,色）の候補を絞る。
#include<iostream>
using namespace std;

int n;
int input[10000];

int erase( int pos, int num ){
	static int data[10000];
	int i,j;
	for( i = 0; i < n; i++ ){
		data[i] = input[i];
	}
	data[pos] = num;
	
	bool eflag = true;
	while( eflag ){
		eflag = false;
		for( i = 0; i < n-3; i++ ){
			if( data[i] == 0 )
				continue;
				
			int erased = 0;
			for( j = 1; i+j < n; j++ ){
				if( data[i+j] == 0 ){
					erased++;
					continue;
				}
				
				if( data[i] != data[i+j] )
					break;
			}
			if( j-erased >= 4 ){
				eflag = true;
				//消す
				int st = i, ed = i+j;
				for( j = st; j < ed; j++ ){
					data[j] = 0;
				}
				//ここでbreakをするとTLE確実。
			}
		}
	}
	int ret = n;
	for( i = 0; i < n; i++ ){
		if( data[i] == 0 )
			ret--;
	}
	return ret;
}

int main(){
	int i,j;
	
	while( cin >> n ){
		if(!n)break;
		for( i = 0; i < n; i++ ){
			cin >> input[i];
		}
	
		int ans = n;
		for( i = 0; i < n; i++ ){
			for( j = 1; j <= 3; j++ ){
				int l,r;
				for( l = i-1; l >= 0; l-- ){
					if( input[l] != j )
						break;
				}
				for( r = i+1; r < n; r++ ){
					if( input[r] != j )
						break;
					if( r - l - 1 >= 4 ){
						ans = min( ans, erase( i, j ) );
						break;
					}
				}
				//breakしなかった場合の処理も書こう(戒め
				if( r - l - 1 >= 4 ){
					ans = min( ans, erase( i, j ) );
					break;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define MODNUM (INT(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int h, a;
	scanf("%d %d", &h, &a);
	printf("%d\n", (h / a) + (h % a ? 1 : 0));
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static int digit(int x){
    int ans = 0, tmp = x;
    if(x == 0)return 1;
    while(tmp != 0){
      tmp /= 10;
      ++ans;
    }
    return ans;
  }
  
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt(), b = sc.nextInt();
    sc.close();
    String ans[] = {"Yes", "No"};
    int an = 1, tmpa = a, tmpb = b;
    int d = digit(tmpb);
    tmpa *= (int)Math.pow(10, d);
    tmpa += tmpb;
    tmpb = (int)Math.sqrt(tmpa);
    if(tmpa == tmpb * tmpb)an = 0;
    System.out.println(ans[an]);
  }
  
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    vec<vec<int>> dp(N + 1, vec<int>(N + 1, 0));

    for(int i=N-1;i>=0;--i) for(int j=N-1;j>=0;--j) {
        if (i == j) continue;
        if (S[i] == S[j]) dp[i][j] = dp[i + 1][j + 1] + 1;
    }

    int ans = 0;
    rep(i,N)rep(j,N){
        if(i<j&&i+dp[i][j]<=j) ans=max(ans,dp[i][j]);
    }
    cout << ans << endl;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b; cin >> a >> b;
  if(a>=10 || b>=10){
    cout << "-1" << endl;
    return 0;
  }
  cout << a*b << endl;
  
  return 0;
}


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



using namespace std;

int main(){
 string s;
 cin >> s;

 if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]){
   cout << "Bad" << endl;
 }
  else{
  cout << "Good" << endl;
  }
 
  
}

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


int main() {
    ULL N, X, M; cin >> N >> X >> M;

    int s = 0;
    ULL ans = 0;
    int I[100000]; rep(i, M) I[i] = -1;
    {
        int i = 1;
        while (N != 0) {
            ans += X; I[X] = i; N--;
            X = X * X % M; i++;
            if (I[X] != -1) { s = i - I[X]; break; }
        }
    }

    if (N != 0) {
        vector<ULL> V(s + 1);
        rep(i, s) { V[i + 1] = V[i] + X; X = X * X % M; }
        ans += (N / s) * V[s]; N %= s;

        ans += V[N];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3980
#include <iostream>
#include <queue>
#include <utility>
#include<algorithm>
using namespace std;
using pi = pair<int, int>;
int INF = 100000;
int dy[] = {1,0,-1,0};
int dx[]={0, 1,0,-1};
int h, w;
char mp[24][24];
int bfs(pi s) {
  queue<pi> que;
  vector<vector<int>>mc(24,vector<int>(24,INF));
  
  que.push(s);
  mc[s.first][s.second]=0;
  while(!que.empty()) {
    pi pos = que.front();que.pop();
    int y = pos.first;
    int x = pos.second;
    for (int i=0;i<4;i++){
      int ny=y+dy[i];
      int nx=x+dx[i];
      if (ny>=0&&ny<h&&nx>=0&&nx<w&&
        mp[ny][nx]!='#'&&
          mc[ny][nx]==INF){
        mc[ny][nx]=mc[y][x]+1;
        que.push({ny,nx});
        }
      }
    }
  
  int ret=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(mc[i][j]==INF)continue;
      ret=max(ret,mc[i][j]);
      }
    }
  return ret;
}

int main() {
  cin >>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>mp[i][j];
      }
    }
  
  int ans=0;
  for (int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(mp[i][j]=='#')continue;
      auto c=bfs(pi(i,j));
      ans=max(c,ans);
      }
    }
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    string S;
    cin >> S;
    map<int, int> Map;
    
    int Tmp = 0;
    int Fact = 1;
    Map[0] = 1;
    for (int l = S.length()-1; l >= 0; --l) {
        Tmp += Fact * (S[l] - '0');
        Tmp %= 2019;
        Fact *= 10;
        Fact %= 2019;
        Map[Tmp] += 1;
    }
    
    ll Res = 0;
    for (const auto& z : Map) {
        int n = z.second;
        Res += n*(n-1)/2;
    }
    cout << Res << endl;

    return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = pow(10, 9) + 7;
//const int mod = 998244353;
//const int mod = ;
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  
  vector<pair<int, int>> CB(M);
  for (int i = 0; i < M; i++)
  {
    cin >> CB.at(i).second >> CB.at(i).first;
  }

  sort(CB.begin(), CB.end(), greater<pair<int, int>>());
  for (int i = 0; i < M; i++)
  {
    int B = CB.at(i).second;
    int C = CB.at(i).first;
    for (int j = 0; j < B; j++)
    {
      A.push_back(C);
      if (A.size() >= 2 * N) break;
    }
  }
  
  sort(A.begin(), A.end(), greater<int>());

  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    ans += A.at(i);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 7184
a_str, b_str = input().split()

a = int(a_str)
b = int(b_str)


def change(i):
    if i == 1:
        return 14
    else:
        return i


a = change(a)
b = change(b)
if a > b:
    print('Alice')
elif b > a:
    print('Bob')
else:
    print('Draw')

Measured memory_bytes: 3064
use std::fmt::Write;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();
    let aa = read_vec::<usize>();

    let mut boxes = vec![0usize; n];

    let mut count = 0;

    for i in (0..n).rev() {
        let mut sum = 0;
        for j in 1.. {
            let index = (i+1) * j - 1;
            if index >= n {
                break;
            }
            if boxes[index] == 1{
                sum += 1;
            }
        }
        if sum % 2 == aa[i] {
            continue;
        }
        boxes[i] = 1;

        count += 1;
    }

    let mut ans = String::new();

    println!("{}", count);
    for (i, b) in boxes.iter().enumerate() {
        if *b == 1 {
            writeln!(ans, "{}", i+1).unwrap();
        }
    }

    print!("{}", ans);

}

Measured memory_bytes: 9208
#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>;

int m[51][51];
bool check[51][51];

void dfs(int y, int x, int w, int h){
    if(x < 0 || y < 0 || y >= h || x >= w) return;
    if(m[y][x] == 1 && !check[y][x]){
        check[y][x] = true;
        // cout << "[" << y << "," << x << "]" << endl;
        for(int dx = -1; dx <= 1; ++dx){
            for(int dy = -1; dy <= 1; ++ dy){
                dfs(y + dy, x + dx, w, h);
            }
        }
    }
}

int main() {
    int w, h;
    cin >> w >> h;
    
    while(w != 0 && h != 0){
        int res = 0;
        rep(i, 51) rep(j, 51){
            m[i][j] = 0;
            check[i][j] = false;
        }
        rep(i, h) rep(j, w) cin >> m[i][j];
        
        rep(i, h) rep(j, w){
            if(m[i][j] == 1 && !check[i][j]){
                ++res;
                // cout << "start[" << i << "," << j << "]" << endl; 
                dfs(i, j, w, h);
            }   
        }
        
        cout << res << endl;
        cin >> w >> h;
    }
    
    return 0;
}


Measured memory_bytes: 3288
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.lang.Math;

class Main{
    public static void main(String[] args){
        InputStreamReader inputStreamReader = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(inputStreamReader);
        boolean firstTime = true;

        String str;
        double[] num;
        double[] xy;
        try {
            while(reader.ready()){
                str = reader.readLine();
                num = getNum(str);
                xy = solveXY(num);
                //System.out.println(xy[0] + " " + xy[1]);
                System.out.println(String.format("%.3f %.3f", xy[0], xy[1]));
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static double[] getNum(String str){
        String[] data = str.split(" "); 
        double[] num = new double[data.length];

        for (int i = 0; i < data.length; i++){
            num[i] = Double.parseDouble(data[i]);
        }
        return num;
    }

    private static double[] solveXY(double num[]){
        // ax+by=c
        // dx+ey=f

        // x = (bf - ce) / (ae - bd)
        // y = (c - ax) / b = (f - dx) / e

        double[] xy = new double[2];
        double a, b, c, d, e, f;
        
        a = num[0];
        b = num[1];
        c = num[2]; 
        d = num[3];
        e = num[4];
        f = num[5];

        xy[0] = ((c * e) - (b * f)) / ((a * e) - (b * d));
        xy[1] = (c - a * xy[0]) / b;

        xy[0] = Math.round(xy[0] * 1000) * 0.001;
        xy[1] = Math.round(xy[1] * 1000) * 0.001;

        return xy;
    }
}


Measured memory_bytes: 24696