akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

int dp[N];

signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n; cin>>n;
    int a[n][n];
    For(i, 0, n){
        For(j, 0, n){
            cin>>a[i][j];
        }
    }
    for(int mask=1; mask<(1<<n); mask++){
        For(i, 0, n){
            For(j, i+1, n){
                if((mask&(1<<i)) && (mask&(1<<j)))
                    dp[mask]+=a[i][j];
            }
        }
        int s_mask = (mask-1)&mask;
        for(; s_mask; s_mask=(s_mask-1)&mask){
            int m1 = s_mask;
            int m2 = s_mask ^ mask;
            dp[mask]=max(dp[mask], dp[m1]+dp[m2]);
        }
    }
    int mx = pow(2, n);
    cout<<dp[mx-1];
    return 0;
}





Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int x;
    cin >> x;
    cout << (x^1) << endl;
}

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

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

	vector<int> ab(t.length()+2);
	vector<vector<int> > dp(s.length()+2,ab);

	for(int i=0;i<=s.length();i++)
	{
		for(int j=0;j<=t.length();j++)
		{
			if(i==0||j==0)
				dp[i][j]=0;

			else if(s[i-1]==t[j-1])
				dp[i][j]=1+dp[i-1][j-1];
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}


	// for(int i=1;i<=s.length();i++)
	// {
	// 	for(int j=1;j<=t.length();j++)
	// 		cout<<dp[i][j]<<" ";
	// 	cout<<endl;
	// }
	int i=s.length();
	int j=t.length();
string ans="";
	while(i>=1&&j>=1)
	{
		if(s[i-1]==t[j-1])
			{
				ans+=s[i-1];
				i--;
				j--;
			}
		else if(dp[i-1][j]>dp[i][j-1])
		i--;
		else
		j--;	
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;
	// cout<<dp[s.length()][t.length()];
	return 0;

}

Measured memory_bytes: 35584
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define INF (10000001)

typedef pair<int, int> Edge;

int main()
{
    priority_queue<Edge,vector<Edge>,greater<Edge> > pq;
    vector<vector<Edge> > e;
    vector<int> d;
    Edge etemp;
    int n,u,k,v,c;
    cin >> n;
    e.resize(n);
    d.resize(n);
    for(int i=0; i<n; ++i) {
        cin >> u >> k;
        for(int j=0; j<k; ++j) {
            cin >> v >> c;
            e[u].push_back(Edge{c,v});
        }
        d[u]=INF;
    }

    d[0]=0;
    for(auto x : e[0]) {
        pq.push(x);
    }
    while(!pq.empty()) {
        etemp=pq.top(); pq.pop();
        v=etemp.second;
        c=etemp.first;
        if(d[v]<c) continue;
        d[v]=c;
        for(auto x : e[v]) {
            if(d[x.second]<=c+x.first) continue;
            pq.push(Edge{c+x.first,x.second});
        }
    }
    for(int i=0; i<n; ++i) {
        cout << i << " " << d[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3164
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
#include <array>
#include <numeric>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _NE noexcept
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _sc _il bool scan
_T T in(int c)_NE{T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_il int in()_NE{return in<int>(gcu());}
_T T scan(T &n)_NE{int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c)_NE{c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s)_NE{int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _ot _il void out
#define _ol _il void outl
_ot(bool b)_NE{pcu('0'+b);}
_ot(const char *s)_NE{while(*s)pcu(*s++);}
_ot(char c)_NE{pcu(c);}
#ifdef _GLIBCXX_STRING
_ot(string s)_NE{for(char c:s)pcu(c);}
#endif
_T _ot(T n)_NE{static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_ol(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _ot(vector<T> &v)_NE{for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _ot(H&& h, T&&... t)_NE{out(h);out(move(t)...);}
template <typename... T> _ol(T&&... t)_NE{out(move(t)...);outl();}

#define all(o) o.begin(), o.end()

void radix_sort(vector<int> &v) {
	vector<int> t(v.size());
	array<int, 256> c, s;
	for (int i = 0; i < 32; i += 8) {
		fill(all(c), 0);
		for_each(all(v), [&](int j) {c[(j >> i) & 255]++;});
		s.front() = 0;
		partial_sum(all(c) - 1, s.begin() + 1);
		for_each(all(v), [&](int j) {t[s[(j >> i) & 255]++] = j;});
		swap(v, t);
	}
}

int main() {
	for (int N, M; N = in(), M = in();) {
		vector<int> t(N), u;
		for (int &p: t)
			p = in();
		t.push_back(0);
		for (auto i = t.begin(); i != t.end(); i++)
			for (auto j = i; j != t.end(); j++)
				if (*i + *j <= M)
					u.push_back(*i + *j);
		radix_sort(u);
		int r = 0;
		for (auto i = u.begin(), e = u.end() - 1; i <= e; i++) {
			for (; *i + *e >= M; e--)
				;
			r = max(r, *i + *e);
		}
		outl(r);
	}
}


Measured memory_bytes: 6228
N, C = gets.split.map(&:to_i)
xs = []
vs = []
N.times do 
  x, v = gets.split.map(&:to_i)
  xs << x
  vs << v
end
X = xs
V = vs

def solve(xs, vs)
  xs = [0] + xs
  vs = [0] + vs

  right_col = [0]
  left_col = [0]
  for i in 1..N
    col = right_col[i-1] - (xs[i]-xs[i-1]) + vs[i]
    right_col << col

    d = xs[-i+1]
    if d==0
      d = C
    end

    col = left_col[i-1] - (d-xs[-i]) + vs[-i]
    left_col << col
  end

  left_col_max = []
  left_col_max[N+1] = 0
  for r in (1..N).to_a.reverse
    left_col_max[r] = [left_col_max[r+1], left_col[N-r]].max
  end

  max_sushi = 0
  max_sushi = [max_sushi, right_col.max].max

  for r in 1..N
    w = right_col[r] - xs[r] + left_col_max[r]
    max_sushi = [max_sushi, w].max
  end

  max_sushi
end

puts [solve(xs, vs), solve(xs.reverse.map {|x| C-x}, vs.reverse)].max


Measured memory_bytes: 16896
import           Control.Monad
import           Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [a] <- getIntList
  putStr $ if a == 25 then "Christmas" else ""
  putStr $ if a == 24 then "Christmas Eve" else ""
  putStr $ if a == 23 then "Christmas Eve Eve" else ""
  putStr $ if a == 22 then "Christmas Eve Eve Eve" else ""

Measured memory_bytes: 380
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<fstream>
using namespace std;
string s;
int ans=0;
int main(){
	cin>>s;
	int l=0,r=s.length()-1;
	for(int i=1;i<=s.length();i++){
		if(l>=r){
			break;
		}
		if(s[l]==s[r]){
			l++,r--;
			continue;
		}
		if(s[l]=='x'){
			l++,ans++;
			continue;
		}
		if(s[r]=='x'){
			r--,ans++;
			continue;
		}
		cout<<"-1"<<endl;
		return 0;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main(){
    int cnt[4]={};
    rep(i, 3) {
        int a, b;
        cin >> a >> b;
        cnt[a-1]++;
        cnt[b-1]++;
    }
    bool flag = true;
    rep(i, 4) if (cnt[i] >= 3) flag = false;

    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[]	data = null;

		while ((data = parseData()) != null) {
			int		p   = data[0] / data[1];
			int		q   = data[0] % data[1];
			int		e   = 0;
			int[]	lf  = new int[data[1]];
			String	out = "";
			String	lp  = "";

			Arrays.fill(lf, -1);
			while (true) {
				if (q == 0) {
					// 割り切れた
					lp = "";
					break;
				} else if (lf[q] != -1) {
					break;
				}
				lf[q] = e++;
				p = (q * 10) / data[1];
				q = (q * 10) % data[1];
				out += String.valueOf(p);
				lp  += " ";
			}

			out = (out.isEmpty()) ? "0" : out;
			
			System.out.println(out);
			if (!lp.isEmpty()) {
				char[]	tmp = lp.toCharArray();
				Arrays.fill(tmp, lf[q], e, '^');
				System.out.println(tmp);
			}
		}
	}

	private static int[] parseData() {
		int[]	data = null;
		String	str = null;

		if ((str = parseStdin()) != null) {
			String[]	lines = str.split(" ");
			data    = new int[2]; 
			data[0] = Integer.parseInt(lines[0]);
			data[1] = Integer.parseInt(lines[1]);
		}

		return data;
	}

	private static String parseStdin() {
        String  stdin = null;
        
        try {
        	String  tmp = br.readLine();
        	if (tmp != null) {
            	if (!tmp.isEmpty()) {
            		stdin = tmp;
            	}
        	}
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

Measured memory_bytes: 88756
N=int(input())
p=[]
for i in range(N):
    p.append(int(input()))
a=0
for i in range(N):
    if p[i]==max(p):
        a+=p[i]//2
        p.remove(p[i])
        break
for i in range(N-1):
    a+=p[i]
print(a)

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

int main() {
	string str;
	cin>>str;
	int cnt=0;
	int maxi=0;
	for (int i=0;i<str.size();i++){
		if (str[i]=='R'){
			cnt++;
		}
		else{
			maxi=max(maxi,cnt);
			cnt=0;
		}
	}
	maxi=max(maxi,cnt);
	cout<<maxi;
	return 0;
}

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

using namespace std;

typedef pair<int, int> P;

const int N = 101;
const int INF = (1 << 28);

vector<P> G[N];
vector<pair<string, int> > dat;
map<string, int> stoi;
int d[N];

int dijkstra(int s, int t){
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d+N, INF);
	d[s] = 0;
	que.push(make_pair(0, s));
	while(!que.empty()){
		P p = que.top(); que.pop();
		//cout << p.first << ' ' << p.second << endl;
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i=0;i<G[v].size();i++){
			P e = G[v][i];
			if(d[e.first] > d[v] + e.second){
				d[e.first] = d[v] + e.second;
				que.push(P(d[e.first], e.first));
			}
		}
	}
	return d[t];
}

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		string in;
		cin >> in;
		if(in == "goto"){
			cin >> in;
			in = in.substr(0, (int)in.size()-1);
			dat.push_back(make_pair(in, 1));
			G[i].push_back(make_pair(i+1, 1));
		}else{
			in = in.substr(0, (int)in.size()-1);
			dat.push_back(make_pair(in, 0));
			G[i].push_back(make_pair(i+1, 0));
			stoi[in] = i;
		}
	}
	for(int i=0;i<n;i++){
		if(dat[i].second){
			G[i].push_back(make_pair(stoi[dat[i].first], 0));
		}
	}
	/*for(int i=0;i<n;i++){
		cout << "i = " << i << ": ";
		for(int j=0;j<G[i].size();j++){
			cout << G[i][j].first << " ";
		}
		cout << endl;
		}*/
	cout << dijkstra(0, n) << endl;
	//for(int i=0;i<=n;i++) cout << d[i] << " "; cout << endl;
	return 0;
}

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

using namespace std;

int main() {
  int n,m,ans=0;
  cin>>m>>n;
  if(m<=n){
    for(int i=0;i<n;i++){
      ans+=m*pow(10,i);
    }
  }else{
    for(int i=0;i<m;i++){
      ans+=n*pow(10,i);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#define LL long long
using namespace std;
const int maxn=200005;
int n,a[maxn];
LL sum1[maxn],sum2[maxn],ans;
inline int read(){
	int ret=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-f;ch=getchar();}
	while (ch>='0'&&ch<='9') ret=(ret<<3)+(ret<<1)+ch-'0',ch=getchar();
	return ret*f;
}
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read(),sum1[i]=sum1[i-1]+a[i],sum2[i]=sum2[i-1]^a[i];
	int j=1;
	for (int i=1;i<=n;i++){
		ans+=(LL)j-i;
		while (j<=n&&sum1[j]-sum1[i-1]==(sum2[j]^sum2[i-1])) j++,ans++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head, const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int a,b;
    in(a,b);
    out(a/b,a%b,(double)a/b);
}


Measured memory_bytes: 3216
#include <stdio.h>

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

   scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);

 if(c < 0 || d < 0){

 printf("No\n");

 }

 else{

   if((a - e) >= c && (b - e) >= d){

   printf("Yes\n");
 
   }
  
   else{

   printf("No\n");

   }

   return 0;

 }

return 0;

}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);

	ll N,A,B; cin >> N>>A>>B;
	ll k = A + B;
	ll l = N / k;
	ll ans = l * A;
	N = N - k * l;
	if(N >= A) ans += A;
	else ans += N;
	cout << ans << endl;

}

Measured memory_bytes: 256
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = float("inf")
for i in range(n-k+1):
    l, r = x[i], x[i+k-1]
    if r <= 0:
        a = abs(l)
    elif l >= 0:
        a = r
    else:
        a = min(abs(l), abs(r)) * 2 + max(abs(l), abs(r))
    if ans > a: ans = a
print(ans)

Measured memory_bytes: 14252
#include "bits/stdc++.h"
#define ROP(a) for(int i=0; i<a; i++)
using namespace std;

int getSomeSum(int n)
{
	int dig;
	int ret = 0;

	while (n)
	{
		dig = n % 10;
		ret += dig;
		n /= 10;
	}

	return ret;
}

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

	int judge;
	int sum = 0;
	ROP(N)
	{
		judge = getSomeSum(i + 1);
		if (judge >= A && judge <= B)
		{
			sum += (i + 1);
		}
	}

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		String s = String.valueOf(a.charAt(0))+String.valueOf(b.charAt(0))+String.valueOf(c.charAt(0));
		
		System.out.println(s.toUpperCase());
		
	}

}


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

int main(void) {
  int n;
  string s, t;
  cin >> n >> s >> t;
  int isNotMatch = 1;
  for (int i = 0; i < n; i++) {
    if (s.substr(i, n-i) == t.substr(0, n-i)) {
      s += t.substr(n-i, i);
      isNotMatch = 0;
      break;
    }
  }
  if (isNotMatch == 1) s += t;
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int N,M;
    cin >> N >> M;
    ve<ve<int>> E(3*N);
    
    rep(i,M){
        int u,v;
        cin >> u >> v;
        u--,v--;
        E[3*u].pb(3*v+1);
        E[3*u+1].pb(3*v+2);
        E[3*u+2].pb(3*v);
    }
    int S,T;
    cin >> S >> T;
    
    S--,T--;
    S = 3*S;
    T = 3*T;
    
    ve<int> f(3*N,infi);
    f[S] = 0;
    
    queue<int> Q;
    Q.push(S);
    while (!Q.empty()) {
        int a = Q.front();
        Q.pop();
        for (int p : E[a]) {
            if(f[p] == infi){
                Q.push(p);
                f[p] = f[a]+1;
            }
        }
    }
    
    //outve(f);
    
    if(f[T] == infi) cout << -1 << endl;
    else if(f[T]) cout << f[T]/3 << endl;
    

    
    
    
    

    return 0;
}


Measured memory_bytes: 17792
n,q=map(int,input().split())
s=input()
list_ac=[]
number=0
state=0
for i in range(0,len(s)):
    if s[i]=='A':
        state=1
        list_ac.append(number)
    elif s[i]=='C':
        if state==1:
            number=number+1   
        list_ac.append(number)
        state=0
    else:
        state=0
        list_ac.append(number)
for i in range(0,q):
    l,r=map(int,input().split())
    print(list_ac[r-1]-list_ac[l-1])
        
    


Measured memory_bytes: 6128
#include<bits/stdc++.h>
using namespace std;
int a[3];
int main()
{
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]==a[1]) cout<<a[2]<<endl;
	else cout<<a[0]<<endl;
	return 0;
}

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

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll H,W;
	cin >> H >> W;

	if(H % 3 == 0 || W % 3 == 0){
		cout << 0 << endl;
		return 0;
	}

	ll mi = 1e12;

	// 横線のみ
	mi = min(mi,W);

	// 縦線のみ
	mi = min(mi,H);

	// 横線→縦線
	FOR(h,1,H){
		ll s1 = h * W;
		ll s2 = (H-h) * (W/2);

		mi = min(mi,max(max(s1,s2),H*W-s1-s2)-min(min(s1,s2),H*W-s1-s2));
	}

	// 縦線→横線
	FOR(w,1,W){
		ll s1 = w * H;
		ll s2 = (W-w) * (H/2);

		mi = min(mi,max(max(s1,s2),H*W-s1-s2)-min(min(s1,s2),H*W-s1-s2));
	}

	cout << mi << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b)) {
	  cout << "Yes" << endl;
	} else {
	  cout << "No" << endl;
	}
  return 0;
}


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

int calc_collatz(int x)
{
  if (x % 2 == 0) {
    return x / 2;
  } else {
    return 3 * x + 1;
  }
}

int main()
{
  std::unordered_set<int> dict;
  int ai;
  std::cin >> ai;
  int i = 1;
  while (true) {
    auto it = dict.find(ai);
    if (it != dict.end()) {
      break;
    }
    dict.insert(ai);
    ai = calc_collatz(ai);
    i++;
  }
  std::cout << i << '\n';
  return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   ll a, b;
   cin >> a >> b;

   ll ret = 1e18;
   if (a <= b) ret = min(ret, b - a);
   if (a <= -b) ret = min(ret, -b - a + 1);
   if (-a <= b) ret = min(ret, b + a + 1);
   if (-a <= -b) ret = min(ret, -b + a + 2);
   cout << ret << endl;

   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long a[1<<17],f;
main()
{
	int n;cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n,greater<long>());
	for(int i=0;i<n-1;i++)
	{
		if(a[i]==a[i+1])
		{
			if(f)
			{
				cout<<f*a[i]<<endl;
				return 0;
			}
			else f=a[i];
			i++;
		}
	}
	cout<<0<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n,i,k,b,c=0,x;
    cin >> n >> k;
    int a[n];
    for (i=0; i<n; i++){
        cin >> x;
        a[i] = x;
    }
    for(i =0; i < n; i++){
        b = k-a[i];
        if(b<0){
            c = c-b*2;
        }
        else{
            if(a[i]<b){
                c = c+a[i]*2;
            }
            else{
                c = c+b*2;
            }
        }
    }
    cout << c;
}

Measured memory_bytes: 256
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();

        while(true){
            String[] line = br.readLine().split(" ");
            int m = Integer.parseInt(line[0]);
            int f = Integer.parseInt(line[1]);
            int r = Integer.parseInt(line[2]);

            if(m == -1 && f == -1 && r == -1){
                break;
            }else if(m == -1 || f == -1){
                sb.append("F").append("\n");
            }else if(m + f >= 80){
                sb.append("A").append("\n");
            }else if(m + f >= 65){
                sb.append("B").append("\n");
            }else if(m + f >= 50){
                sb.append("C").append("\n");
            }else if(m + f >= 30){
                if(r >= 50){
                    sb.append("C").append("\n");
                }else{
                    sb.append("D").append("\n");
                }
            }else{
                sb.append("F").append("\n");
            }
        }
        System.out.print(sb.toString());
    }
}

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

bool check(int row, int column, int inc1, int inc2, int rowtotal, int columntotal, int grid[100][100]){
	for(int i = row, j = column; i < rowtotal && j < columntotal; i += inc1, j += inc2){
		if(grid[i][j] == '#')
			return 0;
	}
	return 1;
}

int main(){
	int h, w;
	cin >> h >> w;
	bool deleted[h+w] = {};
	int grid[100][100] = {};
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			scanf(" %c", &grid[i][j]);
		}
	}
	for(int i = 0; i < h; i++){
		if(check(i, 0, 0, 1, h, w, grid))
			deleted[i] = true;
	}
	for(int i = 0; i < w; i++){
		if(check(0, i, 1, 0, h, w, grid))
			deleted[h+i] = true;
	}
	for(int i = 0; i < h; i++){
		if(deleted[i])
			continue;
		for(int j = 0; j < w; j++){
			if(deleted[h+j])
				continue;
			cout << (char)grid[i][j];
		}
		cout << endl;
	}
}

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

#define ANS  //for answer
#define CMP  //for compe

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define nv(x) #x,(x)
#define ncv(x) #x,":",(x)
#define ncvc(x) #x,":",(x),","
using ll = long long;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>void pPRINT(std::ostream& ost,const T t,const U... u) {ost<<t<<" ";pPRINT(ost, u...);}
template <class... T>void PRINT(const T... t) {pPRINT(std::cout, t...);}
template <class... T>void PRINTl(const T... t){pPRINT(std::cout,t...);std::cout<<"\n";}
template <class T>void PRINTa(const T* const t,const ll size){REP(i,size)PRINT(t[i]);PRINTl();}
template <class T>void PRINTal(const T* const t,const ll size){REP(i,size)PRINTl(i,":",t[i]);}
#ifdef CMP
using namespace std;
#else
#endif
#ifdef ANS
#define DEBUG(...)
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}
#else
#define DEBUG(...) PRINT("##DEBUG##","file :",__FILE__,", line :",__LINE__,"[");PRINT(__VA_ARGS__);PRINTl("]");
void init(){}
#endif

void solve();

int main(int argc, char *argv[]) {

  init();
  DEBUG();
  solve();

  return 0;
}

void dns(vector<vector<ll>>& vv,int* g,set<ll>& s,ll pnt,ll node){
  auto& v = vv[node];
  s.insert(node);
  for_each(v.begin(),v.end(),[&](ll n){
    if(n!=pnt&&s.find(n)==s.end()){
      DEBUG(ncv(node),ncv(n));
      g[n]=g[node];
      dns(vv,g,s,node,n);
    }
  });
}

void solve(){

  DEBUG("SOLVE START");
  ll n,m;cin>>n>>m;
  vector<vector<ll>> v(n);
  int g[n]={};
  DEBUG("g");
  REP(i,m){
    ll x,y,z;cin>>x>>y>>z;x--;y--;
    // v[min(x,y)].push_back(max(x,y));
    v[x].push_back(y);
    v[y].push_back(x);
  }

  ll ans = 0;
  DEBUG();
  REP(i,n)if(g[i]==0){
    ans++;g[i]=ans;
    set<ll> s;
    dns(v,g,s,-1,i);
  }
  PRINT(ans);

}

Measured memory_bytes: 18560
END { load __FILE__ unless $stdin.eof? }

a, b, h, m = gets.split.map!(&:to_i)

ca = Complex.polar(a, (h * 60 + m) * 2 * Math::PI / 720)
cb = Complex.polar(b, m * 2 * Math::PI / 60)

puts (ca - cb).abs


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

long dp[10];
int main() {
    int H, W, N;
    cin >> H >> W >> N;
    dp[0]=(long) (H-2)*(W-2);
    map<int, map<int, int>> mp;
    for(int c=0; c<N; c++){
        int a, b; cin >> a >> b;
        for(int i=max(a-2, 1); i<=min(a, H-2); ++i){
            for(int j=max(b-2, 1); j<=min(b, W-2); ++j){
                int cnt=0;
                for(int k=0; k<9; ++k) cnt += mp[i+k/3][j+k%3];
                --dp[cnt];
                ++dp[cnt+1];
            }
        }
        mp[a][b]=1;
    }
    for(int i=0; i<10; ++i) cout << dp[i] << endl;
    return 0;
}


Measured memory_bytes: 164352
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int H,A;
    cin >> H >> A;
    int ans = (H + A - 1) / A;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int A, B;
    scanf("%d%d", &A, &B);
    int x = 0;
    for (int i = A; i <= B; i++)
    {
        int s = i % 10;
        int t = i / 10000 % 10;
        int u = i / 10 % 10;
        int v = i / 1000 % 10;
        if (s == t && u == v) x++;
    }
    printf("%d\n", x);
    return 0;
}

Measured memory_bytes: 128
N = gets.to_i
array = gets.chomp.split.map(&:to_i)

# 全部2で割る
# 一つでも割れないものがあれば、カウント終わり
ans = 100000000
for a in array do
  s = 0
  while a % 2 == 0 do
    a /= 2
    s += 1
  end
    ans = (ans < s ? ans : s)
end

puts ans


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll k,n;
    cin>>k>>n;
    ll a[n]={0};
    for(ll i=0;i<n;i++)
        cin>>a[i];
    ll b[n]={0};
    b[0] = k-a[n-1]+a[0];
    for(ll i=1;i<n;i++)
    {
        b[i] = a[i]-a[i-1];
    }
    ll maxIndex = 0;
    ll maxval = INT_MIN;
    for(ll i=0;i<n;i++)
    {
        //cout<<b[i]<<" ";
        if(b[i]>maxval)
        {
            maxval = b[i];
            maxIndex = i;
        }
    }
    ll sum=0;
    for(ll i = maxIndex+1; i<n;i++)
        sum = sum + b[i];
    for(ll i=0;i<maxIndex;i++)
        sum = sum+b[i];
    cout<<sum<<endl;
    return 0;
}



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

int main() {
  int N; cin >> N;
  int p[N];
  for (int i=0; i<N; i++) cin >> p[i];
  int count = 0;
  for (int i=0; i<N; i++) {
    if (p[i] != (i+1)) {
      count++;
    }
  }
  if (count == 0 || count == 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
struct dice{
    int side[10];
    int temp;
    char order[110];
};
int main(void){
    struct dice d;
    int i;
    int q;
    int f_side,u_side;
    for(i=1;i<=6;i++)
        scanf("%d",&d.side[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d %d",&u_side,&f_side);
        if(u_side==d.side[1]){
            if(f_side==d.side[2])
                printf("%d\n",d.side[3]);
            else if(f_side==d.side[3])
                printf("%d\n",d.side[5]);
            else if(f_side==d.side[5])
                printf("%d\n",d.side[4]);
            else if(f_side==d.side[4])
                printf("%d\n",d.side[2]);
        }
        if(u_side==d.side[2]){
            if(f_side==d.side[6])
                printf("%d\n",d.side[3]);
            else if(f_side==d.side[3])
                printf("%d\n",d.side[1]);
            else if(f_side==d.side[1])
                printf("%d\n",d.side[4]);
            else if(f_side==d.side[4])
                printf("%d\n",d.side[6]);
        }
        if(u_side==d.side[3]){
            if(f_side==d.side[2])
                printf("%d\n",d.side[6]);
            else if(f_side==d.side[6])
                printf("%d\n",d.side[5]);
            else if(f_side==d.side[5])
                printf("%d\n",d.side[1]);
            else if(f_side==d.side[1])
                printf("%d\n",d.side[2]);
        }
        if(u_side==d.side[4]){
            if(f_side==d.side[2])
                printf("%d\n",d.side[1]);
            else if(f_side==d.side[1])
                printf("%d\n",d.side[5]);
            else if(f_side==d.side[5])
                printf("%d\n",d.side[6]);
            else if(f_side==d.side[6])
                printf("%d\n",d.side[2]);
        }
        if(u_side==d.side[5]){
            if(f_side==d.side[3])
                printf("%d\n",d.side[6]);
            else if(f_side==d.side[6])
                printf("%d\n",d.side[4]);
            else if(f_side==d.side[4])
                printf("%d\n",d.side[1]);
            else if(f_side==d.side[1])
                printf("%d\n",d.side[3]);
        }
        if(u_side==d.side[6]){
            if(f_side==d.side[2])
                printf("%d\n",d.side[4]);
            else if(f_side==d.side[4])
                printf("%d\n",d.side[5]);
            else if(f_side==d.side[5])
                printf("%d\n",d.side[3]);
            else if(f_side==d.side[3])
                printf("%d\n",d.side[2]);
        }
    }
    return 0;
}


Measured memory_bytes: 2076
# 約数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

N = int(input())
divs = make_divisors(N)
# print(sorted(divs))
divs2 = make_divisors(N-1)
ans = len(sorted(divs2))-1
for div in divs[1:]:
    tmp = N
    while tmp%div == 0:
        tmp //= div
    if tmp%div == 1:
        ans += 1
print(ans)


Measured memory_bytes: 9464
import sys

n, m = map(int, input().split(" "))
ans = [-1]*n
for _ in range(m):
    s, c = map(int, input().split(" "))
    if ans[s-1] == -1:
        ans[s-1] = c
    elif ans[s-1] == c:
        pass
    else:
        print("-1")
        sys.exit()

if ans[0] == 0 and len(ans) > 1:
    print("-1")
    sys.exit()

if ans[0] == -1 and len(ans) > 1:
    ans[0] = 1

if ans[0] == -1 and len(ans) == 1:
    ans[0] = 0

print("".join(map(str, [ 0 if x == -1 else x for x in ans])))

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

using namespace std;

const int mod = 1e9 + 7;

int N, M;
vector< pair< int, int > > ev[303];
int dp[303][303][303];

bool iroha_check(int iroha, int r, int g, int b) {
  for(auto &p : ev[iroha]) {
    int add = 0;
    add += p.first <= r;
    add += p.first <= g;
    add += p.first <= b;
    if(add != p.second) return false;
  }
  return true;
}

int rec(int r, int g, int b) {
  if(r >= g) swap(r, g);
  if(r >= b) swap(r, b);
  if(g >= b) swap(g, b);
  int &ret = dp[r][g][b];
  if(~ret) return ret;
  if(!iroha_check(b, r, g, b)) return ret = 0;
  if(b == N) return ret = 1;
  ret = 0;
  (ret += rec(b + 1, g, b)) %= mod;
  (ret += rec(r, b + 1, b)) %= mod;
  (ret += rec(r, g, b + 1)) %= mod;
  return ret;
}

int main() {
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    ev[r].emplace_back(l, x);
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(0, 0, 0) << endl;
}

Measured memory_bytes: 108928
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using lint = long long;
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  rep1(i,n){
      if(i*111>=n){
          cout<<i*111<<"\n";
          return 0;
      }
  }
  return 0;
}

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

#define endl '\n'

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3648
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>b){
		printf("a > b\n");
	}
	if(a<b){
		printf("a < b\n");
	}
	if(a==b){
		printf("a == b\n");
	}
	
	return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int cap = a - b;
    int use = min(c, cap);
    int ans = c - use;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    int a, flag;

    cin >> a;

    while (1)
    {
        for (int i = a; i <= INT_MAX; i++)
        {
            if (i == 1 || i == 0)
                continue;

            flag = 1;

            for (int j = 2; j <= i / 2; ++j)
            {
                if (i % j == 0)
                {
                    flag = 0;
                    break;
                }
            }

            if (flag)
            {
                cout << i;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7
INF = 1 << 60

# ---------------------------------------------------
# ---------------------------------------------------
# ---------------------------------------------------
from bisect import bisect_left

def resolve():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    dp = [INF]*(N+1)
    for i in range(N):
        ind = bisect_left(dp, A[i])
        dp[ind] = A[i]

    ans = bisect_left(dp, INF)
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10480
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>

#define llong long long
#define rep(i,l,n) for(llong (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b))
#define _abs(a) ((a)>0?(a):(-(a)))

using namespace std;

#define P (1000000007)

int main(){
	int N;
	cin >> N;
	llong A[N];
	rep(i,0,N) cin >> A[i];
	
	llong ans = 0;
	rep(i,0,N) ans = (ans+A[i])%P;
	ans = (ans*ans)%P;
	rep(i,0,N){
		ans = (ans-A[i]*A[i])%P;
		while( ans < 0 ) ans+=P;
	}
	ans = (ans*500000004)%P;
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 5152
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	n, s := nextInt(), next()
	ans := 0
	for i := 0; i+2 < n; i++ {
		if s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C' {
			ans++
			i += 2
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end());
  if (a[n - 1] - a[0] > 1) {
    cout << "No\n";
    return 0;
  }
  if (a[0] == a[n - 1] && a[0] == n - 1) {
    cout << "Yes\n";
    return 0;
  }
  int cnt = 0;
  rep(i, n) if (a[i] != a[n - 1]) cnt++;
  cout << (cnt + 1 <= a[n - 1] && a[n - 1] <= cnt + (n - cnt) / 2 ? "Yes\n" : "No\n");
  

  





  
  return 0;
}

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

#define ub upper_bound
#define lb lower_bound
#define sum(a) accumulate(all(a),0ll)
#define all(v) begin(v),end(v)
#define allr(v) rbegin(v),rend(v)
#define sort_dec(v) sort(all(v),[](auto e1,auto e2){return e1>e2;})
#define For(n) for(ll i=0;i<n;i++)
#define Forj(n) for(ll j=0;j<n;j++)
typedef long long int ll;
typedef unsigned long long int ull;
#define fi first
#define se second
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define vpll vector< pair<ll,ll> >
#define bug(n) {cout<<n;return;}
#define cont(n) {cout<<n<<endl;continue;}
#define pb push_back
#define print(n) cout<<n<<" ";
ll mod=1e9+7;

const ll N=1001;
ll dist[N][N];
 
void solve()
{
	ll n,m;
	cin>>n>>m;
	string square[n];
	For(n)cin>>square[i];
	dist[0][0]=1;
	rep(i,1,m)
	if(square[0][i]=='.')dist[0][i]=dist[0][i-1];
	else dist[0][i]=0;
	rep(i,1,n)
	if(square[i][0]=='.')dist[i][0]=dist[i-1][0];
	else dist[i][0]=0;
	rep(i,1,n){
		rep(j,1,m){
			if(square[i][j]=='.')dist[i][j]=(dist[i-1][j]+dist[i][j-1])%mod;
			else dist[i][j]=0;
		}
	}
	// For(n)
	// {
	// 	Forj(m)cout<<dist[i][j]<<" ";cout<<endl;
	// }
	cout<<dist[n-1][m-1];
}
 
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	 
	// freopen("error.txt", "w", stderr);
	 
	int t=1;
	 
	while(t--)
	{
		solve();
	}

	cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	 
	return 0;
}

Measured memory_bytes: 12640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define INF 1e9

static const int seed=6;
static const int D=365;
static const int ntype=26;
static int ans[D+1];
static int max_score=-INF;
static int t=1e5;
class Contest{
public:
    Contest(){
        last=0;
    }
    int s[D+1];
    int c;
    int last;
};

static Contest contest[ntype+1];

void Input(){
    int d;
    cin>>d;
    for(int i=1;i<=ntype;++i){
        int t;
        cin>>t;
        contest[i].c=t;
    }
    for(int day=1;day<=D;++day){
        for(int type=1;type<=ntype;++type){
            int t;
            cin>>t;
            contest[type].s[day]=t;
        }
    }
}

int evaluate(){
    int sum=0;
    vector<int> l(ntype+1,0);
    for(int day=1;day<=D;++day){
        int type=ans[day];
        sum+=contest[type].s[day];
        l[type]=day;
        for(int t=1;t<=ntype;++t){
            sum-=contest[t].c*(day-l[t]);
        }
    }
    return sum;   
}

void Output(){
    for(int d=1;d<=D;++d) cout<<ans[d]<<endl;
}

void Init(){
    for(int d=1;d<=D;++d) ans[d]=rand()%ntype+1;
}

void Greedy(){
    vector<int> l(ntype+1,0);
    int score=0;
    for(int d=1;d<=D;++d){
        for(int i=1;i<=ntype;++i) score-=contest[i].c*(d-l[i]);
        int temp=score;
        int t=-1;
        for(int i=1;i<=ntype;++i){
            int k=contest[i].s[d]+contest[i].c*(d-l[i])+score;
            if(k>temp){
                temp=k;
                t=i;
            }
        }
        ans[d]=t;
        l[t]=d;
    }
}

void change(){
    int p=rand()%D+1;
    int temp=ans[p];
    ans[p]=rand()%ntype+1;
    int temp_score=evaluate();
    if(max_score<temp_score) max_score=temp_score;
    else ans[p]=temp;
}

void swap(){
    int p1=rand()%D+1;
    int p2=rand()%D+1;
    while(p1==p2) p2=rand()%D+1;
    int temp=ans[p1];
    ans[p1]=ans[p2];
    ans[p2]=temp;
    int temp_score=evaluate();
    if(max_score<temp_score) max_score=temp_score;
    else{
        ans[p2]=ans[p1];
        ans[p1]=temp;
    }
}

void solve(int times){
    max_score=evaluate();
    for(int i=0;i<times;++i){
        swap();
        change();
    }
}

int main(){
    srand(seed);
    Input();
    Greedy();
    solve(t);
    Output();
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
//    int a[5]={2,4,5,7,9};
//    int b[4]={0,1,6,8};
//    int c[1]={3};
    cin>>n;
    //cout<<n;
    vector<int>m;
    while(n>0){
        int k=n%10;
        m.push_back(k);
        n/=10;
        //cout<<n<<endl;
    }
    //cout<<n<<endl;
    //m.push_back(n);
    for(int i=0;i<m.size();i++){
        //cout<<m[i]<<" ";
        if(m[i]==3){
            cout<<"bon"<<endl;
            break;
        }
        else if(m[i]==0||m[i]==1||m[i]==6||m[i]==8){
            cout<<"pon"<<endl;
            break;
        } else {
            cout<<"hon"<<endl;
            break;
        }
    }
}


Measured memory_bytes: 3600
V,M = map(int, input().split())
abc = [list(map(int, input().split())) for i in range(M)]
G = [list() for i in range(V)]
for a,b,c in abc:
    G[b-1].append((a-1,-c))
INF = 10**18
dist = [INF] * V
dist[V-1] = 0
update = 1
for _ in range(V):
    update = 0
    for v, e in enumerate(G):
        for t, cost in e:
            if dist[v] != INF and dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                update = 1
    if not update:
        break
else:
    print('inf')
    exit()
print(-dist[0])

Measured memory_bytes: 48104