akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(void){

  int n,num[1000],tanpaku[1000],shishitu[1000],tansui[1000],cal[1000],P,Q,R,C,result[1000],cnt=0;

  while(1){
    cnt = 0;
  cin >> n;
  if(n == 0) break;
  //テ・ツ?・テ・ツ環?
  for(int i = 0; i < n; i++){
    cin >> num[i] >> tanpaku[i] >> shishitu[i] >> tansui[i];
    cal[i] = tanpaku[i] * 4 + shishitu[i]*9 + tansui[i]*4;
  }

  //テ・ツ按カテゥツ卍静・ツ?、テ・ツ?・テ・ツ環?
  cin >> P >> Q >> R >> C;


  for(int i = 0; i < n; i++){
    if(tanpaku[i] <= P && shishitu[i] <= Q && tansui[i] <= R && cal[i] <= C){
      result[cnt] = num[i];
      cnt++;
    }
  }
  
    if(cnt != 0){
      for(int i = 0; i < cnt; i++){
	cout << result[i] << endl;
      }    
    }else{
      cout << "NA" << endl;
    }
  }

    return 0;
  }
  

Measured memory_bytes: 1184
import java.util.Scanner;
class Main{


	static char[][] map;

	static long[][] c;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		int[][] data = new int[n][d];
		for(int i = 0;i < n;i++){
			for(int j = 0;j < d;j++){
				data[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for(int i = 0;i < n;i++){
			for(int j = i + 1;j < n;j++){
				int calc = 0;
				for(int k = 0;k < d;k++){
					calc += Math.abs(data[i][k] - data[j][k])*Math.abs(data[i][k] - data[j][k]);
				}
				if(judge(calc)){
					ans++;
				}
			}
		}
		System.out.print(ans);
		
		

		
	}
	
	static boolean judge(int num){
		
		for(int i = 1;i*i <= num;i++){
			if(i*i == num){
				return true;
			}
		}
		
		return false;
		
		
	}


	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   end- otherpair.end;
	}







	static int find(int index,int current,int[] students,int ans,int[][] memo){
		if(current == index){
			return 1;
		}

		if(memo[current][index] != 0){
			return memo[current][index];
		}

		memo[current][index] = find(index, students[current]-1, students, ans+1, memo)+1;

		return memo[current][index];
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}






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

int main() {
  int n,k,i;
  cin >> n >> k;
  
  vector<int> a(k);
  for(int i=0; i<k; i++) cin >> a[i];
  
  for(i=n; ; i++){
    int flag=0;
    
    for(int x=i; x>0; x/=10){      
      for(int y : a){
        if(y==x%10) flag++;
      }
    }
    
    if(flag==0) break;
  }
  cout << i << endl;
}

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ANot {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int x;
        cin >> x;
        if (x == 0) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ANot solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3608
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int a,b;cin>>a>>b;
    int c=a+b;
    if(c>=24)
        c-=24;
    cout<<c<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






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

using ll = long long;

using namespace std;

int main() {
    string a;
    cin >> a;
    string cands[26];
    for (int i=0; i<26; i++)
        cands[i] = (char)'a' + i;
    
    int argmin = 0, _min;
    for (auto c:a) {
        cands[c-'a'] = cands[argmin] + c;
        _min = 2000000;
        for (int i=0; i<26; i++) {
            if (cands[i].size() < _min || (cands[i].size() == _min && cands[i] < cands[argmin])) {
                _min = cands[i].size();
                argmin = i;
            }
        }
    }
    cout << cands[argmin] << '\n';
    return 0;
}

Measured memory_bytes: 1008
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    string str;
    cin >> str;
    if(str.substr(2,1)==str.substr(3,1) && str.substr(4,1)==str.substr(5,1))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

struct Line {
	mutable ll k, m, p;
	bool operator<(const Line& o) const { return k < o.k; }
	bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line, less<>> {
	// (for doubles, use inf = 1/.0, div(a,b) = a/b)
	const ll inf = LLONG_MAX;
	ll div(ll a, ll b) { // floored division
		return a / b - ((a ^ b) < 0 && a % b); }
	bool isect(iterator x, iterator y) {
		if (y == end()) { x->p = inf; return false; }
		if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
		else x->p = div(y->m - x->m, x->k - y->k);
		return x->p >= y->p;
	}
	void add(ll k, ll m) {
		auto z = insert({k, m, 0}), y = z++, x = y;
		while (isect(y, z)) z = erase(z);
		if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
		while ((y = x) != begin() && (--x)->p >= y->p)
			isect(x, erase(y));
	}
	ll query(ll x) {
		assert(!empty());
		auto l = *lower_bound(x);
		return l.k * x + l.m;
	}
};

const int MAXN = 2e5 + 10;
int n,C; 
int h[MAXN],dp[MAXN];

void solve(){
    cin>>n>>C;

    FOR(i,1,n) cin>>h[i];

    LineContainer lc;

    FOR(i,1,n){
        if(i == 1) dp[i] = 0;
        else dp[i] = -lc.query(h[i]) + h[i]*h[i];
        int m = -2*h[i],c = dp[i] + C + h[i]*h[i];
        lc.add(-m,-c);
    }

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

signed main(){

   FastRead;    


    int t = 1; 
    // cin>>t; 
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}



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

int cnt[1000010];

int main() {
  int n,a,ans=0;
  scanf("%d",&n);
  for (int i=0; i<n; i++) {
    scanf("%d",&a);
    if (a>1000000)
      ans++;
    else
      cnt[a]++;
  }

  for (int i=1; i<=1000000; i++) {
    if (i<=cnt[i])
      ans += cnt[i]-i;
    else
      ans += cnt[i];
  }

  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
const ll mod = 1e9 + 7;
ll a[N], s[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 1; i <= n; ++i)
        s[i] = (s[i - 1] + a[i]) % mod;
    ll ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        ans = (ans + (a[i] * s[i - 1] % mod)) % mod;
    }
    cout << ans;
}

Measured memory_bytes: 6764
#include<stdio.h>
int main(void){
	int A,B,ans=0;
	scanf("%d %d",&A,&B);
	if((A+B)%2!=0){
		printf("IMPOSSIBLE\n");
	}else{
		ans=(A+B)/2;
		printf("%d\n",ans);
	}
	
	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "0" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
bool nodeki[101010];
ll nodenum[101010];
bool guheiro;
ll node0;
bool ans0;
struct edge{ll to, cost;};
struct graph{
    ll N;
    vector<vector<edge> > G;
    vector<bool> used;

    graph(ll n): N(n), G(N), used(N,false) {}

    void add_edge(ll s, ll t , ll cost){
        G[s].emplace_back((edge){t,cost});
        G[t].emplace_back((edge){s,cost}); //無向ならON
    }

    void dfs(ll v=0){
        used[v]=true;
        for(auto E : G[v]){
            if(used[E.to]){
                if(nodeki[v] xor nodeki[E.to]){
                    if(nodenum[v]+nodenum[E.to]!=E.cost) ans0=true;
                }
                else{
                    if(!guheiro){
                        guheiro=true;
                        ll x=E.cost-(nodenum[v]+nodenum[E.to]);
                        if(x%2!=0) ans0=true;
                        else{
                            if(nodeki[v]) node0=-x/2;
                            else node0=x/2;
                        }
                    }
                    else{
                        ll x=nodenum[v]+nodenum[E.to];
                        if(nodeki[v]) x-=node0*2;
                        else x+=node0*2;
                        if(x!=E.cost) ans0=true;
                    }
                }
            }
            if(!used[E.to]){
                nodenum[E.to]=E.cost-nodenum[v];
                nodeki[E.to]=!nodeki[v];
                dfs(E.to);
            }
        }
    }
};
//--MAIN-----------------------------------
void Main() {
    ll N,M; cin>>N>>M;
    vector<ll> u(M),v(M),s(M);
    rep(i,M) { cin>>u[i]>>v[i]>>s[i]; --u[i],--v[i];}
    graph g(N);
    rep(i,M) g.add_edge(u[i],v[i],s[i]);
    g.dfs();
    // 偶閉路がある->node0が決定 できないなら0
    // 奇閉路->満たすならok だめなら0
    // それ以外奇と偶の各min-1,0LLのmax
    // node0決定なら全部正か確認
    if(ans0) dame;
    if(guheiro){
        bool ok=true;
        rep(i,N) if(nodenum[i]+node0<=0) ok=false;
        if(ok) cout<< 1 <<"\n";
        else cout<< 0 <<"\n";
        return;
    }
    ll kimin=INF2,gumin=INF2;
    rep(i,N){
        if(nodeki[i]) mini(kimin,nodenum[i]);
        else mini(gumin,nodenum[i]);
    }
    cout<< max(0LL,kimin+gumin-1)<<"\n";

}
 
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------

Measured memory_bytes: 14208
N,M,C=map(int,input().split())
B=list(map(int,input().split()))

count=0
for i in range(N):
    A=list(map(int,input().split()))
    sum=0
    for j in range(M):
        sum= A[j]*B[j] +sum
    sum=C+sum
    
    if sum>0:
        count=count+1

print(count)






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

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

	int a, b, c;
	cin >> a >> b;
	c = a*b;
	if (c%2 == 1){
		cout << "Odd" << "\n";
	}else{
		cout << "Even" << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
import math


def main():
    s, t = input().split()
    A = int(s)
    b, c = map(int,t.split("."))
    ans = A*b + A*c//100
    print(ans)
 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10000)
    main()

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  bool ok=false;
  for(int i=0;i<s.size();i++){
    s=s.back()+s.substr(0,s.size()-1);
    if(s==t){
      ok=true;
      break;
    }
  }
  if(ok){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
    	Scanner sc = new Scanner(System.in);
		// 整数の入力
		String str = sc.nextLine();
        int count=0;
		for(int i=0;i<3;i++){
		    if(str.charAt(i)=='o'){
		        count++;
		    }
		}
		System.out.println(700+count*100);
		
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>

using namespace std;

typedef long long ll;
int main() {
    int N, W;
    cin >> N >> W;
    auto dp = vector<ll>(W+1, 0);
    for(int i = 0 ; i < N ;i++) {
        int w;
        ll v;
        cin >> w >> v;
        for (int j = W; j >= 0 ; j--) {
            if (j+w <= W) {
                dp[j+w] = max(dp[j+w] , dp[j] + v);
            }
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;

}

Measured memory_bytes: 1024
N = int(input())

if N < 4:
	print(1)
	exit()

vmax = 0
for i in range(2, N):
	v = i ** 2
	if N < v:
		break
	while True:
		v *= i
		if N < v:
			vmax = max(vmax, v // i)
			#print(i, v // i, vmax)
			break

print(vmax)


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans=0;
    for(int i=0;i<n;i++){
        int cnt=0;

        for(char c='a';c<='z';c++){
            bool left=false,right=false;

            for(int j=0;j<i;j++)
                if(s[j]==c)
                    left=true;

            for(int j=i;j<n;j++)
                if(s[j]==c)
                    right=true;
            
            if(left&&right)
                cnt++;
        }
        if(ans<cnt)
            ans=cnt;
    }
    cout << ans << endl;
}

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

using namespace std;
#define rep(i, l, r) for (int i = l; i<r;i++)
#define dec(i, l, r) for (int i = l; i>=r;i--)
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define pb(c) push_back(c)
#define vii vector<pair<int,int>>
#define ii pair<int,int>
#define max(a, b) (((a)<(b))?b:a)
#define min(a, b) ((a>b)?b:a)
#define mp(i, j) make_pair(i,j)
#define ull unsigned long long int
#define ll  long long int
#define pi 3.141592653589793238
#define inf ((ll)1e18)
#define eps 1e-14
#define mod ((int)1e9+7)
#define maxlg 18
#define left(i) ((i)<<1)
#define right(i) (((i)<<1)+1)
#define maxn 400006

map<int,int> f;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
 #endif
    int n;
    cin>>n;
    rep (i,0,n) {
        int g;cin>>g;
        f[g]++;
    }
    int ans=0;
    for (ii p:f) {
        int a = (p.second-p.first);
        if (a<0) {
            a = p.second;
        }
        ans+=a;
    }
    cout<<ans;
    return 0;
}








Measured memory_bytes: 4736
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;


int main(){
	while(1){
		int n,m,x[22],y[22],dist[33];
		char dir[33];
		bool f[22]={};
		bool ok=false;
		cin>>n;
		if(n==0)break;
		rep(i,0,n)cin>>x[i]>>y[i];
		cin>>m;
		rep(i,0,m)cin>>dir[i]>>dist[i];
		int nx=10,ny=10,px,py;
		rep(i,0,m){
			px=nx,py=ny;
			if(dir[i]=='N'){
				ny+=dist[i];
				rep(j,0,n)if(nx==x[j]&&py<=y[j]&&ny>=y[j])f[j]=true;
			}
			if(dir[i]=='S'){
				ny-=dist[i];
				rep(j,0,n)if(nx==x[j]&&ny<=y[j]&&py>=y[j])f[j]=true;
			}
			if(dir[i]=='E'){
				nx+=dist[i];
				rep(j,0,n)if(ny==y[j]&&px<=x[j]&&nx>=x[j])f[j]=true;
			}
			if(dir[i]=='W'){
				nx-=dist[i];
				rep(j,0,n)if(ny==y[j]&&nx<=x[j]&&px>=x[j])f[j]=true;
			}
		}
		rep(j,0,n){
			if(!f[j])break;
			if(j==n-1)ok=true;
		}
		if(ok?print("Yes"):print("No"));
	}
	return 0;
}


Measured memory_bytes: 2992
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << 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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int k; cin>>k;
    vector<ll> lun;
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    for (int i = 1; i < 10; ++i) pq.push(i);

    while (!pq.empty()) {
        if (lun.size() > k+100) break;
        ll cur = pq.top(); pq.pop();
        lun.push_back(cur);

        ll a = cur%10;
        ll nxt_p = (a+1)%10;
        ll nxt_m = (a-1)%10;
        ll nxt_z = a;
        if (a != 9) pq.push(cur*10+nxt_p);
        if (a != 0) pq.push(cur*10+nxt_m);
        pq.push(cur*10+nxt_z);
    }

    sort(lun.begin(), lun.end());
    cout << lun[k-1] << '\n';

    return 0;
}

Measured memory_bytes: 6180
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur -> key != key){
        cur = cur->next; 
    }
    return cur;
}

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur == nil){
            break;
        }
        if(isf++ > 0){
            printf(" ");
        }
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t){
    if(t == nil){
        return;
    }
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;

    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main(){
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d",&n);
    init();

    for(i = 0; i < n; i++){
        scanf("%s%d",com, &key);
        if(com[0] == 'i'){
            insert(key);
            np++;
            size++;
        }else if(com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F'){
                    deleteFirst();
                }else if(com[6] == 'L'){
                    deleteLast();
                }
            }else{
                deleteKey(key);
                nd++;
            }       
            size--;
        }
        
        
    }
    printList();
    return 0;
    
}




Measured memory_bytes: 33940
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (a - b >= 0)cout << "delicious" << endl;
	else if (b - a <= x)cout << "safe" << endl;
	else cout << "dangerous" << endl;
	return 0;
}

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

using namespace std;

//State
//dp[i][j]: The length of longest common subsequence of s[0...i]
//	and t[0...j]

//Initialization
//if s.at(0)=t.at(0) then dp[0][0] = 1 else dp[0][0] = 0

//Transitions (Only one of s[i] and t[i] can be in LCS[i,j] if they are not equal)
//if s[i]=t[i] then dp[i][j] = dp[i-1][j-1]+1
//else dp[i][j] = max(dp[i-1][j], dp[i][j-1])

//Order of evaluation
//Rowwise or columnwise

//Answer
//dp[len(s)-1][len(t)-1]

//Time Complexity = O(len(s)*len(t))

pair<int,pair<int,int>> dp[3005][3005] = {make_pair(0,make_pair(0,0))};

int main(){
	string s;
	string t;
	cin >> s >> t;
	int m = s.length();
	int n = t.length();
	/*if(s.at(0)==t.at(0)) dp[0][0] = 1;
	else dp[0][0] = 0;*/

	for(int i=0; i<m; i++){
		//start_pos, len_of_substring
		int found = s.substr(0,i+1).find(t.at(0));
		if(found != string::npos){
			dp[i][0] = make_pair(1,make_pair(-1,-1));
		}
		else{
			dp[i][0] = make_pair(0,make_pair(-1,-1));
		}
	}

	for(int i=1; i<n; i++){
		if(t.at(i) == s.at(0)){
			dp[0][i] = make_pair(1,make_pair(-1,-1));
		}
		else{
			dp[0][i] = dp[0][i-1];
		}
	}

	for(int i=1; i<m; i++){
		for(int j=1; j<n; j++){
			if(s.at(i)==t.at(j)){
				dp[i][j] = make_pair(1+dp[i-1][j-1].first, make_pair(i-1,j-1));
			}
			else{
			    pair<int,pair<int,int>> top = dp[i-1][j];
			    pair<int,pair<int,int>> left = dp[i][j-1];
			    if(top.first >= left.first){
			        dp[i][j] = make_pair(top.first, make_pair(i-1,j));
			    }
			    else{
			        dp[i][j] = make_pair(left.first, make_pair(i,j-1));
			    }
			}
		}
	}
	
	string result;
	int i,j;
    pair<int,int> curr = make_pair(m-1,n-1);
    while(true){
        i = curr.first;
        j = curr.second;
        pair<int,int> prev = dp[i][j].second; //cell from which we came to i,j
        if(prev.first<0){
            if(curr.first == 0){
                int index = t.substr(0, curr.second+1).find(s.at(0));
                if(index != string::npos) result = result + s.at(0);
                break;
            }
            else{
                int index = s.substr(0, curr.first+1).find(t.at(0));
                if(index != string::npos) result = result + t.at(0);
                break;       
            }
        }
        if(prev.first == i-1 && prev.second == j-1){
            result = result + s.at(i);
        }
        curr = prev;
    }
    reverse(result.begin(), result.end());
    cout << result << endl;
}



Measured memory_bytes: 109220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
//#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VL a(n); cin >> a;

    ll sum = accumulate(all(a), 0LL), m = *min_element(all(a));

    if (n % 2 == 0) {
        if (sum % 2 == 0) {
            if (m % 2 == 0) {
                cout << "Second\n";
            }
            else {
                cout << "First\n";
            }
        }
        else {
            if (m % 2 == 0) {
                cout << "First\n";
            }
            else {
                cout << "First\n";
            }
        }
    }
    else {
        if (sum % 2 == 0) {
            cout << "Second\n";
        }
        else {
            cout << "First\n";
        }
    }
}


Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int cnt[n] = {};
	for (int i = 0; i < n - 1; i++) {
		int t; cin >> t;
		++cnt[t - 1];
	}
	for (int i : cnt) cout << i << "\n";
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
typedef pair<ll, ll> point;
point Rotate(point p, point ar)
{
    return point(-(p.S - ar.S) + ar.F, (p.F - ar.F) + ar.S);
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll u1, v1, u2, v2;
    cin >> u1 >> v1 >> u2 >> v2;
    point a = {u1, v1};
    point b = {u2, v2};
    point d = Rotate(b, a);
    point c = Rotate(a, d);
    cout << c.F << ' ' << c.S << ' ' << d.F << ' ' << d.S;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    vector<string> a(2);
    cin >>a[0]>>a[1];
    sort(all(a));
    int n = stoi(a[1]);
    rep(i,n) cout<<a[0];
    cout <<endl;

}



Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

long n,k;
long minn;

void func( long i, long curr )
{
    if(i==n && minn>curr) {
        minn=curr;
    }

    if(i<n) {
        func( i+1, curr*2);
        func( i+1, curr+k);
    }   
    return;
}

int main(int argc, char* argv[])
{
    scanf("%ld%ld", &n, &k);
    minn = MOD;
    func( 0, 1);

    printf("%ld\n", minn);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

int main(){
    ll N;
    cin >> N;
    ll S = (N*(N+1))/2;
    ll ngroup = 0;
    deque<ll> v;
    rep(i,N){
        v.push_back(i+1);
    }
    if(N % 2){
        ngroup = (N+1)/2;
    }else{
        ngroup = N/2;
    }
    vector<vector<ll>> u(ngroup);
    ll ss = S/ngroup;
    rep(i,ngroup){
        ll a = v.back();
        v.pop_back();
        u[i].push_back(a);
        if(a == ss){
            continue;
        }else{
            a = v.front();
            v.pop_front();
            u[i].push_back(a);
        }
    }
    ll cnt = 0;
    rep(i,ngroup){
        rep(j,u[i].size()){
            rep(k,i){
                rep(l,u[k].size()){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    //cout << "ngroup:"<<ngroup<<endl; 
    rep(i,ngroup){
        rep(j,u[i].size()){
            rep(k,i){
                rep(l,u[k].size()){
                    cout << u[i][j] << " " << u[k][l] << endl;
                }
            }
        }
    }


    /*
    cout << (N-1)*(N-1) - N + 1 << endl;
    vector<Pll> v;
    for(int i=1;i<N;i++){
        for(int j=1;j<=N;j++){
            if(N-j != i && j != i){
                cout << i << " " << j << endl;
            }
        }
    }*/
    /*
    v.push_back(Pll(N, 1));
    v.push_back(Pll(N, N-1));
    rep(i, N-3){
        rep(j, i){
            v.push_back(Pll(i+2,j+2));
        }
        v.push_back(Pll(i+2,1));
        v.push_back(Pll(i+2,N-1));
        v.push_back(Pll(i+2,N));
    }
    cout << v.size() << endl;
    rep(i,v.size()){
        cout << v[i].first << " " << v[i].second << endl;
    }*/
}


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

int W, D, N;
bool iss[55][55];
int Min[55][55], Max[55][55];

void adjust(int x, int y)
{
    for(int i = 1; i <= W; i++)
        for(int j = 1; j <= D; j++)
    {
        int dis = abs(i-x)+abs(j-y);
        Min[i][j] = max( Min[i][j], Min[x][y]-dis );
        Max[i][j] = min( Max[i][j], Max[x][y]+dis );
    }
    //cout<<x<<' '<<y<<' '<<Min[x][y]<<' '<<Max[x][y]<<' '<<Min[1][1]<<' '<<Max[1][1]<<'\n';
}

int main()
{
    cin>>W>>D>>N;
    int x, y, z;
    for(int i = 1; i <= N; i++)
    {
        cin>>x>>y>>z;
        iss[x][y] = 1;
        Min[x][y] = Max[x][y] = z;
    }
    for(int i = 1; i <= W; i++)
        for(int j = 1; j <= D; j++)
            if(!iss[i][j])Min[i][j]=-200, Max[i][j]=200;

    for(int i = 1; i <= W; i++)
        for(int j = 1; j <= D; j++)
            adjust(i,j);

    for(int i = 1; i <= W; i++)
        for(int j = 1; j <= D; j++)
            if( Min[i][j] > Max[i][j] )
    {
        //cout<<i<<' '<<j<<' '<<Min[i][j]<<' '<<Max[i][j]<<'\n';
        cout<<"No\n";
        return 0;
    }

    int ans = 0;
    for(int i = 1; i <= W; i++)for(int j = 1; j <= D; j++)ans+=Min[i][j];

    cout<<ans<<'\n';

    return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#include <set>
#include <deque>
#pragma GCC optimize(3 , "Ofast" , "inline")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std ;
#define ios ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define x first
#define y second
#define pb push_back
#define ls rt << 1
#define rs rt << 1 | 1
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
int work()
{
    int n ;
    cin >> n ;
    vector<int> v(n + 1) ;
    for(int i = 1; i <= n ;i ++ ) cin >> v[i] ;
    int ans = 0 ;
    for(int i = 1; i <= n ;i ++ ) {
      for(int j = i + 1; j <= n ;j ++ ) {
        for(int k = j + 1; k <= n ;k ++ ) {
          if(v[i] == v[j] || v[i] == v[k] || v[j] == v[k]) continue ;
          if(v[i] + v[j] > v[k] && abs(v[j] - v[i]) < v[k]) ans ++ ;
        }
      }
    }
    cout << ans << endl ;
    return 0 ;
}
int main()
{
  //   freopen("C:UsersspnooyseedDesktopin.txt" , "r" , stdin) ;
  //   freopen("C:UsersspnooyseedDesktopout.txt" , "w" , stdout) ;

  work() ;
  return 0 ;
}
/*
*/


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
ll a[3005];
ll mo[3005][3005];
int n;
ll dp(int l,int r);
int main()
{


  cin >> n;

  for(int i=0; i<n; i++) cin >> a[i];

  memset(mo, -1, sizeof(mo));
  cout << dp(0,n-1) << endl;

  return 0;
}

ll dp(int l, int r){

  if(l == r) return a[l];
  if(mo[l][r] != -1) return mo[l][r];

  return mo[l][r] = max(a[l] - dp(l+1,r), a[r] - dp(l,r-1));

}


Measured memory_bytes: 71040
#include <iostream>

using namespace std;

int main()
{
	char c[2][4];

	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cin >> c[i][j];
		}
	}

	if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0])
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  long long W, H, x, y;
  cin >> W >> H >> x >> y;
  cout << W * H / 2.0 << " ";
  if (x*2==W && y*2==H) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<pair<ll,ll>,ll>P;
ll n,m,a,b;
vector<P>v;
ll ans[100000][2];
int main(void){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        v.push_back({{a,b},i});
    }
    sort(v.begin(),v.end());
    //cout<<setfill('0')<<setw(4)<<12<<endl;
    ll l=0,ch=0;
    for(int i=0;i<m;i++){
        if(v[i].F.F!=ch){
            ch=v[i].F.F;
            l=i;
        }
        ans[v[i].S][0]=v[i].F.F;
        ans[v[i].S][1]=i-l+1;
    }
    for(int i=0;i<m;i++){
        cout<<setfill('0')<<setw(6)<<ans[i][0];
        cout<<setfill('0')<<setw(6)<<ans[i][1]<<endl;
    }
}


Measured memory_bytes: 6256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  int a,b; cin >> a >> b;
  for(int i = b - a + 1; i <= b+a-1; ++i)
    cout << i << ' ' ;
  cout << endl;
}


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

int main(){
int N;
cin>>N;
map<int,int>mp;
vector<int>v(N);
for(int i=0;i<N;i++){
   cin>>v[i];
   
}
   vector<int> a(N);
for(int i=0;i<N;i++){
   a[v[i]-1]=i+1;
}
for(int i=0;i<N;i++){
   cout<<a[i]<<endl;
}

return 0;

}

Measured memory_bytes: 4036
s = gets.chomp
n = s.length
dp = Array.new(n+1){[0,0]}
dp[1][0] = 1
dp[2][1] = 1
1.upto(n-1) do |i|
  if s[i-1] == s[i]
    dp[i+1][0] = dp[i][1] + 1
  else
    dp[i+1][0] = dp[i].max + 1
  end
  if i >= 3 && s[i-3,2] == s[i-1,2]
    dp[i+1][1] = dp[i-1][0] + 1
  else
    dp[i+1][1] = dp[i-1].max + 1
  end
end
p dp[n].max

Measured memory_bytes: 16892
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int dp[5005][5005];

int main () {
  int n;
  string s;
  cin >> n >> s;
  
  for (int i = n-1; i >= 0; --i) {
    for (int j = n-1; j >= 0; --j) {
      if (s[i] != s[j]) dp[i][j] = 0;
      else dp[i][j] = dp[i+1][j+1]+1;
    }
  }

  int ans = 0;
  rep(i,n)rep(j,n) {
    //if (i >= j) continue; // i < j;
    int now = min(dp[i][j], j-i);
    ans = max(ans, now);
  }

  cout << ans << endl;
}

Measured memory_bytes: 98048
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int n;cin >> n;
    vector<string>s(n);
    rep(i,n)cin >> s[i];
    bool g_f=false,y_f=false,p_f=false,w_f=false;
    for(int i=0;i<n;i++){
        if(s[i]=="G")g_f=true;
        if(s[i]=="Y")y_f=true;
        if(s[i]=="P")p_f=true;
        if(s[i]=="W")w_f=true;
    }
    int cnt=0;
    if(g_f)cnt++;
    if(y_f)cnt++;
    if(p_f)cnt++;
    if(w_f)cnt++;
    if(cnt==3)cout << "Three" << endl;
    if(cnt==4)cout << "Four" << endl;
    return 0;
}



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

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> t(999);
  t[0] = 1;
  for (int i=1; i<999; i++) t[i] = t[i-1] + (i+1);

  cout << t[b-a-1] - b << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
ll count(ll x){
    if(x==0){
        return 0;
    }
    return count(x/2)+1;    
}
int main(){
    ll h, ans;
    cin >> h;
    ans = pow(2, count(h))-1;
    
    cout << ans << endl;
    return 0;
 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,W;
long long int v[105],wt[105];
long long int dp[105][100005];

int main(){

	scanf("%d %d",&N,&W);
	for(int i = 0; i < N; ++i)
		scanf("%lld %lld",&wt[i],&v[i]);
		
	for (int i = 0; i <=N; ++i){
		for (int w = 0; w <=W; ++w)	{
			/* code */
			if(i==0||w==0)
				dp[i][w] = 0;
			else if(wt[i-1] <= w){
				dp[i][w] = max(v[i-1] + dp[i-1][w-wt[i-1]],  dp[i-1][w]); 
			}
			else
				dp[i][w] = dp[i-1][w];

			// printf("%lld ",dp[i][w]);

		}
		// printf("\n");
	}



	printf("%lld\n",dp[N][W]);	

}

Measured memory_bytes: 80128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

ll N;
long double dp[301][301][301];

long double f (ll A, ll B, ll C) {
    // cout << A << " " << B << " " << C << "\n";
    long double a = A, b = B, c = C;
    if (dp[A][B][C] > -0.5) return dp[A][B][C];
    if (a == 0 and b == 0 and c == 0) return dp[0][0][0] = 0;


    long double ea = 0, eb = 0, ec = 0;
    if (A-1 >= 0) ea = f(A-1, B, C);
    if (B-1 >= 0) eb = f(A+1, B-1, C);
    if (C-1 >= 0) ec = f(A, B+1, C-1);
    dp[A][B][C] = (a*ea + b*eb + c*ec + N) / (a+b+c);
    // cout << dp[A][B][C] << "\n";
    return dp[A][B][C];
}

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

    cin >> N;
    vec a(N), cnt(4, 0);
    Rep (i, N) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    Rep (i, 301) Rep (j, 301) Rep (k, 301) dp[i][j][k] = -1;

    cout << fixed << setprecision(10) << f(cnt[1], cnt[2], cnt[3]) << "\n";
    





}

Measured memory_bytes: 429876
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) rep2(i,0,n)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
ll n,a[222222],e[222222];
ll ans=0;
int main()
{
	cin>>n>>a[0];
	e[0]=0;
	rep2(i,1,n)
	{
		cin>>a[i];
		e[i]=(a[i-1]+e[i-1])%1000000007;
	}
	rep(i,n)
	{
		ans+=(a[i]*e[i])%1000000007;
		ans%=1000000007; 
	}
	re(ans)
	return 0;}

Measured memory_bytes: 6740
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define pll pair <ll,ll>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<=(ll)n;i++)
#define rep(i,x,y) for(ll i=(ll)x;i<=(ll)y;i++)
#define reprev(i,n) for(ll i=(ll)n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

// FOR DEBUGGING
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", ";
	else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

const int mod = 1e9+7;
const long double pi = acos(-1);
const ll INF = 1e15;

ll power(ll x, ll y){
	x %= mod;
	ll ans = 1;
	while(y){
		if(y&1) ans = (ans*x)%mod;
		y /= 2;
		x = (x*x)%mod;
	}
	return ans;
}

void solve(){

	ll n;
	cin >> n;
	string ans = "";
	while(n){
		if(n%26==0) ans += 'z';
		else ans += n%26 - 1 + 'a';
		if(n%26==0) n--;
		n /= 26;
	}
	reverse(all(ans));
	cout << ans;

	return;
}

int main(){

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

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 3840