akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    int n;
    cin>>n;
    set<int> s;
    for(int i=-118;i<=119;i++)
        for(int j=-118;j<=119;j++)
            if((int)(pow(i,5)-pow(j,5))==n)
            {
                cout<<i<<" "<<j;
                return;
            }
}
int32_t main()
{
    //_READ  
    int t;
    t=1;
    //cin>>t;
    while(t--)
        solve();
    
    return 0;
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
typedef long long ll;

int n,a,b,c;
string s,t;

int main() {
  int c[3][3];
  rep(i,3)rep(j,3) cin >> c[i][j];
  bool ok=true;
  rep(i,2){
  if(!(c[i][0]-c[i][1]==c[i+1][0]-c[i+1][1]  &&
     c[i][1]-c[i][2]==c[i+1][1]-c[i+1][2])) ok=false;
       
  if(!(c[0][i]-c[1][i]==c[0][i+1]-c[1][i+1]  &&
     c[1][i]-c[2][i]==c[1][i+1]-c[2][i+1])) ok=false;
  }
  cout << (ok ? "Yes" : "No") << endl;
 }

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

const int MAX = 10;
const int MAX2 = 1024;
int main() {
	int D, G, p[MAX], c[MAX];
	cin >> D >> G;
	for (int i = 0;i < D;i ++) cin >> p[i] >> c[i];
	
	int ans = MAX2;
	for (int i = 0;i < (1 << D);i ++) {
		int score = 0, ac = 0, tmp;
		for (int j = 0;j < D;j ++) {
			if ((i & (1 << j)) == 0) continue;
			score += p[j] * (j + 1) * 100 + c[j];
			ac += p[j];
		}
		for (int j = D - 1;j >= 0;j --) {
			if (((i >> j) & 1) == 1) continue;
			if (score >= G) continue;
			tmp = min((G - score + 100 * j) / (j + 1) / 100, p[j]);
			ac += tmp;
			score += tmp * (j + 1) * 100;
		}
		ans = min(ans, ac);
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まずは、点数の高い順にソートする
この時、低い方から選択肢は次のようになる
1. 1問も解かない
2. 全部解く
後は足りなかった分を上から補えばいい
ここで、どの問題に対してコンプリートボーナスをもらうか決め打てば、後は上から解けば良いことが分かる
つまりそうすれば良い
*/

Measured memory_bytes: 256
n,m=gets.split.map(&:to_i)
s=Array.new(m)
k=Array.new(m)
m.times do |i|
    k[i],*s[i]=gets.split.map(&:to_i)
    end
p=gets.split.map(&:to_i)
ans=0
(0..2**n-1 ).each do |i|
f=true
m.times do |j|
    cnt=0
    k[j].times do |l|
        cnt^=1 if i[s[j][l]-1]==1
        end
    f=false if cnt!=p[j]
    end
ans+=1 if f
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;

int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int a , b;
    cin >> a >> b;
    
    a *= 3;
    
    cout << (a + b) / 2 << endl;
}


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

// 入力
long long N;

// cur: 現在の値、use: 7, 5, 3 のうちどれを使ったか, cnt: 答え
void func(long long cur, int use, long long &cnt){
  //cout<<cur<<" "<<use<<" "<<cnt<<endl;
  // ベースケース
  if (cur > N) return;
  // 答えを増やす
  if (use == 0b111) ++cnt;

  // 7 を付け加える
  func(cur * 10 + 7, use | 0b001, cnt);

  // 5 を付け加える
  func(cur * 10 + 5, use | 0b010, cnt);

  // 3 を付け加える
  func(cur * 10 + 3, use | 0b100, cnt);
}

int main() {
  cin >> N;
  long long res = 0;
  func(0, 0, res);
  cout << res << endl;
}

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

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = 1e10;
  for(int i = 0; i <= 100000; ++i){
	  ans = min(ans, 2*c*i + max(0, x-i)*a + max(0, y-i)*b);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] argv){
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int K = in.nextInt();
		int[] tree = new int[N];
		for(int i=0;i<N;i++)
			tree[i] = in.nextInt();
		int ans = Integer.MAX_VALUE;
		Arrays.sort(tree);
		for(int i=0;i<N-K+1;i++){
			ans = Math.min(ans, tree[i+K-1]-tree[i]);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 49888
#include <cstdio>

int main(){
    char c[2][3];
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 3; j++){
            scanf("\n%c",&c[i][j]);
        }
    }

    for(int i = 0; i < 3; i++){
        int j = 2 - i;
        if(c[0][i] != c[1][j]){
        printf("NO\n");

        return 0;
        }
    }
    printf("YES\n");

    return 0;
}

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

int main()
{
    ll a, b, c, d, res = LONG_MIN;
    cin >> a >> b >> c >> d;

    res = max(max(a * c, b * d), max(b * c, a * d));

    cout << res << "\n";
    return 0;
}

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

int main(){
  long N; cin >> N;

  long ans;
  long tmp1 = 2, tmp2 = 1;


  for(int i = 2; i <= N; i++){
    ans = tmp1 + tmp2;
    tmp1 = tmp2;
    tmp2 = ans;

    //cerr << "i: " << i << ", ans: " << ans << endl;
  }

  if(N==1){
    cout << 1 << endl;
  } else {
    cout << ans << endl;
  }

}

Measured memory_bytes: 256
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)

#define cio ios::sync_with_stdio(false); // Do not use it with "scanf" and other c input!
#define pb push_back
#define REP(i,a,b) for (int i = a;i <= b;i ++)
#define pre(i,a,b) for (int i = a;i >= b;i --)
#define rep(i,a,b) for (int i = a;i < b;i ++)

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    int n;
    scanf("%d",&n);
    while (n >= 10) {
        n %= 10;
    }
//    printf("%d\n",n);
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) printf("hon\n");
    else if (n == 0 || n == 1 || n == 6 || n == 8) printf("pon\n");
    else if (n == 3) printf("bon\n");
    return 0;
}


Measured memory_bytes: 3688
#include <iostream>
using namespace std;
char d[100000000],h[1000],h2[1000];
int main(){
	int hN,dN;
	while(1){
	cin>>hN;
	if(hN==0) break;
	for(int i=0;i<hN;i++){
		cin>>h[i]>>h2[i];
	}
	cin>>dN;
	for(int i=0;i<dN;i++){
		cin>>d[i];
	}
	for(int i=0;i<dN;i++){
		for(int j=0;j<hN;j++){
			if(d[i]==h[j]){
				d[i]=h2[j];
				break;
			}
		}
		cout<<d[i];
	}
	cout<<endl;
	}
	return 0;
}

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

vector<int> G[1010];
bool H[1010][1010];
bool visited[1010];

vector<int> path;
vector<int> cycle;

void dfs(int v) {
  visited[v] = true;
  path.push_back(v);
  for (int u : G[v]) {
    if (!cycle.empty()) continue;
    if (find(path.begin(), path.end(), u) != path.end()) {
      cycle = path;
      return;
    } else {
      dfs(u);
    }
  }
  path.pop_back();
}

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    H[a][b] = true;
  }

  for (int i = 0; i < N; i++) {
    if (visited[i]) continue;
    path.clear();
    dfs(i);
    if (cycle.size() > 0) {
      while (!H[cycle[cycle.size() - 1]][cycle[0]]) cycle.erase(cycle.begin());
      bool f = true;
      while (f) {
        f = false;
        bool used[1010] = {};
        for (int u : cycle) used[u] = true;

        int from, to;
        for (int i = 0; i < cycle.size(); i++) {
          int v = cycle[i];
          for (int u = 0; u < N; u++) {
            if (!used[u]) continue;
            if (u == v) continue;
            if (u == cycle[(i + 1) % cycle.size()]) continue;
            if (H[v][u]) {
              f = true;
              from = v, to = u;
              break;
            }
          }
        }

        if (f) {
          vector<int> tmp;
          tmp.push_back(from);
          while (to != tmp[0]) {
            tmp.push_back(to);
            for (int u : G[to]) {
              if (used[u] && H[to][u]) {
                to = u;
                break;
              }
            }
          }
          cycle = tmp;
        }
      }
      cout << cycle.size() << endl;
      for (int v : cycle) {
        cout << v + 1 << endl;
      }
      return 0;
    }
  }

  cout << -1 << endl;
  return 0;
}

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

using namespace std;

signed main()
{
    int x,y,z;
    std::vector<int> Size(3);
    cin>>x>>y>>z;
     cout<<(z/x)*y<<endl;
    return 0;
}



Measured memory_bytes: 768
#include <iostream>

using namespace std;

int get_digit(long long x) {
  int cnt = 0;
  while (x > 0) {
    cnt++;
    x /= 10;
  }
  return cnt;
}

long long sqrt_floor(long long x) {
  long long l = 0, r = x + 1, m;
  while (l + 1 < r) {
    m = (l + r) / 2;
    (m <= x / m ? l : r) = m;
  }
  return l;
}

int main() {
  long long N;
  cin >> N;

  long long d = sqrt_floor(N);

  while (d > 0) {
    if (N % d == 0) {
      cout << get_digit(N / d) << endl;
      break;
    }
    --d;
  }
}


Measured memory_bytes: 3508
/*  Don’t Quit
    
    When things go wrong as they sometimes will;
        When the road you’re trudging seems all uphill;
            When the funds are low, and the debts are high;
                And you want to smile, but you have to sigh;
                    When care is pressing you down a bit
                        Rest if you must, but don’t you quit.
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=2e5+10;

int gcd(int n,int m)
{
    if(n==0)
        return m;
    else
        return gcd(m%n,n);
}
int level[N];
vector<int>vp[N];
void dfs(int n ,int par)
{
    for(int i=0;i<vp[n].size();i++)
    {
        if(vp[n][i]!=par)
        {
            level[vp[n][i]]+=level[n];
            dfs(vp[n][i],n);
        }
    }
}
int32_t main()
{
    IOS;
    int n,q;
    cin>>n>>q;
    int x,y,val;
    for(int i=1;i<=n-1;i++)
    {
        cin>>x>>y;
        vp[x].pb(y);
        vp[y].pb(x);
    }
    for(int i=1;i<=q;i++)
    {
        cin>>x>>val;
        level[x]+=val;
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)
    {
        cout<<level[i]<<" ";
    }
    cout<<endl;


}

Measured memory_bytes: 24320
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
typedef long long ll; 
struct data
{
	ll val, w, lim; 
} arr[55];
ll sz[55], sum[55], dp[200005]; 
std::vector<int> son[55]; 
void dfs(int u)
{
	sz[u] = 1; 
	for (int v : son[u])
	{
		dfs(v); 
		sz[u] += sz[v]; 
		sum[u] += sum[v]; 
	}
}
int main()
{
	// freopen("ARC096-F.in", "r", stdin); 
	int n, w_lim, d; 
	scanf("%d%d%d", &n, &w_lim, &d); 
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", sum + i); 
		if (i)
		{
			int x; 
			scanf("%d", &x); 
			son[--x].push_back(i); 
		}
	}
	dfs(0); 
	for (int i = 0; i < n; i++)
		arr[i] = {sz[i], sum[i], i ? d - std::min(n, d) : w_lim}; 
	std::sort(arr, arr + n, [&] (const data &a, const data &b) { return a.val * b.w > a.w * b.val; });
	memset(dp, 0x3f, sizeof(dp)); 
	dp[0] = 0; 
	for (int i = 0; i < n; i++)
	{
		for (int j = n * n * n; j >= 0; j--)
		{
			for (int k = 0; k <= n && (!i || k <= d) && sum[i] * k <= w_lim && sz[i] * k <= j; k++)
				dp[j] = std::min(dp[j], dp[j - sz[i] * k] + sum[i] * k); 
		}
	}
	ll ans = 0; 
	for (int i = n * n * n; i >= 0; i--)
	{
		if (dp[i] > w_lim)
			continue; 
		ll res = i, rem = w_lim - dp[i]; 
		for (int j = 0; j < n; j++)
		{
			ll x = std::min(arr[j].lim, rem / arr[j].w); 
			res += arr[j].val * x; 
			rem -= arr[j].w * x; 
		}
		ans = std::max(ans, res); 
	}
	printf("%lld\n", ans);
	return 0; 
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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 INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n; cin>>n;
    if (n == 3) {
        cout<<2<<" "<<5<<" "<<63<<endl;
        return 0;
    }
    if (n == 4) {
        cout<<2<<" "<<5<<" "<<20<<" "<<63<<endl;
        return 0;
    }
    if (n == 5) {
        cout<<2<<" "<<5<<" "<<20<<" "<<30<<" "<<63<<endl;
        return 0;
    }

    ll cnt = 0;
    ll k = 0;
    ll s = 0;
    vl ans;
    ll c0 = 0, c4 = 0;
    rep(i, n) {
        ans.push_back(i * 6 + 2);
        s += i * 6 + 2;
        cnt++;
        if (cnt == n) break;
        ans.push_back(i * 6 + 3);
        s += i * 6 + 3;
        cnt++;
        if (cnt == n) break;
        ans.push_back(i * 6 + 4);
        s += i * 6 + 4;
        c4 = i * 6 + 4;
        cnt++;
        if (cnt == n) break;
        ans.push_back(i * 6 + 6);
        s += i * 6 + 6;
        c0 = i * 6 + 6;
        cnt++;
        if (cnt == n) break;
    }
    if (s % 6 == 2) {
        rep(i, n) if (ans[i] != 8) cout<<ans[i]<<endl;
        cout<<c0 + 6<<endl;
        return 0;
    }
    if (s % 6 == 3) {
        rep(i, n) if (ans[i] != 9) cout<<ans[i]<<endl;
        cout<<c0 + 6<<endl;
        return 0;
    }
    if (s % 6 == 5) {
        rep(i, n) if (ans[i] != 9) cout<<ans[i]<<endl;
        cout<<c4 + 6<<endl;
        return 0;
    }
    rep(i, n) cout<<ans[i]<<endl;
}

Measured memory_bytes: 640
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(int i=0; i<(n); i++)
#define LLREP(i,n) for(LL i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define SORT(x) sort(ALL(x))
#define REVE(x) reverse(ALL(x))
#define MP make_pair
#define PB push_back
#define INF INT_MAX

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef long long LL;

LL sum(string t) {
	//125 12+5 1+25 1+2+5
	LL re = 0, n = 0;
	LLREP(i, SZ(t)) {
		if (t[i] != '+')n = n * 10 + (t[i] - '0');
		if (t[i] == '+' || i == SZ(t) - 1) { re += n; n = 0; }
	}
	return re;
}

int main() {
	string s;
	cin >> s;
	int size = SZ(s);
	LL ans = 0;

	for (int bit = 0; bit < (1 << size - 1); bit++) {
		string t; int x = 1;
		t += s[0];
		for (int i = size - 2; i >= 0; i--) {
			if (bit&(1 << i))t += '+';
			t += s[x]; x++;
		}

		ans += sum(t);

		//cout << t << "=" << sum(t) << endl;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
ans=[]
for i in range(1,99):
    if 26**i>=n:
        n-=1
        for j in range(i):
            key=chr(ord("a")+(n%26))
            ans.append(key)
            n=n//26
        break
    else:
        n-=26**i
        
ans.reverse()
for i in range(len(ans)):
    if i!=len(ans)-1:
        print(ans[i],end="")
    else:
        print(ans[i])

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

template<typename T>
T gcd(T x,T y){return y?gcd(y,x%y):x;}

int main()
{
	int T; scanf("%d",&T);
	unsigned long int A,B,C,D;
	for(;0<T;T--)
	{
		scanf("%ld%ld%ld%ld",&A,&B,&C,&D);
		if(A<B||D<B||C<A%B||C<B-gcd(B,D)) puts("No");
		else puts("Yes");
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int cnt=0;
	char s[4];
	scanf("%s",s+1);
	if(s[1]=='R'&&s[2]=='R'&&s[3]=='R')
	{
		cnt=3;
	}
    else if(s[1]=='R'&&s[2]=='R')
	{
		cnt=2;
	}
	else if(s[3]=='R'&&s[2]=='R')
	{
		cnt=2;
	} 
	else if(s[1]=='R'||s[2]=='R'||s[3]=='R')
	{
		cnt=1;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 3808
def unite(par, i, j):
    j = get_par(par, j)
    par[j] = get_par(par, i)

def get_par(par, p):
    while par[p] != p:
        p = par[p]
    return par[p]

n,m = map(int,input().split())
edge = [list(map(int,input().split())) for _ in range(m)]
res = n * (n-1) // 2

ans = []
cnt = [1 for _ in range(n+1)]
par = [i for i in range(n+1)]

for a,b in edge[::-1]:
    a -= 1
    b -= 1
    ans.append(res)
    aa = get_par(par, a)
    bb = get_par(par, b)
    if aa == bb:
        continue

    # unite
    ca = cnt[aa]
    cb = cnt[bb]
    if ca > cb:
        par[bb] = aa
        cnt[aa] += cb
    else:
        par[aa] = bb
        cnt[bb] += ca
    res -= ca * cb

[print(i) for i in ans[::-1]]


Measured memory_bytes: 82264
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<limits>
#include<deque>
#include<string>
#include<map>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>

using namespace std;


int main() {
	int n; cin >> n;
	int a[n];
	int i;
	int sum = 0;
	
	map<int, int> mp;

	for (i = 0; i < n; i++) {
		cin >> a[i];
		mp[a[i]] += 1;
	}

	for (pair<int, int> x : mp) {
		if (x.first > x.second) { sum += x.second; }
		else { sum += x.second - x.first; }
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <set>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)

using namespace std;

multiset<int> s;
int n;

int main()
{
	cin >> n;

	REP(_i, n)
	{
		int a; cin >> a;

		auto it = s.lower_bound(a);
		if (it != s.begin())
			s.erase(--it);
		
		s.insert(a);
	}

	cout << s.size() << endl;
}

//// done E in 10min on 28, Sep, 2019
////

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll N,M,a,MOD=1e9+7;
	cin >> N >> M;
	vector<ll> X(N+5,0);
	for(int i=0;i<M;i++){
		cin >> a;
		X[a]=-1;
	}
	X[0] = 1;
	if(X[1]!=-1)X[1] = 1;
	for(int i=2;i<N+1;i++){
		if(X[i]==-1)continue;
		X[i] = ( (X[i-1]!=-1)*X[i-1] + (X[i-2]!=-1)*X[i-2] ) % MOD;
	}
	cout << X[N] << endl;
}

Measured memory_bytes: 1024
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){
//srandom((unsigned long)time(NULL));

string s;
cin>>s;
int x=1;
for(int i=0;i<s.length();i++){
    for(int j=0;j<s.length();j++){
        if(i!=j){
                if(s[i]==s[j]){
                    x=0;
                }
        }
    }
}

if(x==0)cout<<"no"<<endl;
else cout<<"yes"<<endl;
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int a, b, c;
	int i;
	int big, mi ,mu;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d %d %d", &a, &b, &c);
	if (a > b && a> c){
		big = a;
		mi = b;
		mu = c;
	}
	else if (b > a && b > c){
		big = b;
		mi = a;
		mu = c;
	}
	else {
		big = c;
		mi = b;
		mu = a;
	}
	if (big * big == mi * mi + mu * mu){
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
	}
	
	return (0);
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

int main(){
    int N, T;
    cin >> N >> T;
    vector<int> as(N, 0);
    int a_min = 1e9;
    int d = 0;
    int cnt = 0;
    rep(i, N){
        int a;
        cin >> a;
        a_min = min(a_min, a);
        if(d == a - a_min){
            cnt ++;
        }
        if(d < a - a_min){
            cnt = 1;
            d = a - a_min;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    int sum = 0;
    int tmp;
    for(int i = 0; i < m; i++){
        cin >> tmp;
        sum += tmp;
    }  
    if(sum > n){
        cout << -1 << endl;
    }else{
        cout << n - sum << endl;
    }

}

Measured memory_bytes: 3604
from sys import stdin
from operator import itemgetter
readline = stdin.readline


#readline = open('???.txt').readline

VERTICAL_LOW, HORIZONTAL, VERTICAL_HIGH = 0, 1, 2

import math
class segment_tree:
    
    # self.table is 1-indexed
    # math.log2 not implemented 3.2.3
    def __init__(self, size):
        self.offset = 2 ** math.ceil(math.log(size, 2))
        self.table = [0] * self.offset * 2
        for i in reversed(range(1, self.offset)):
            self.table[i] = self.table[2 * i] + self.table[2 * i + 1]

    # [l, r] closed-interval
    def sum(self, l, r):
        return sum(self.__range(l,r))

    def __range(self, l, r):
        l += self.offset
        r += self.offset
        while l <= r:
            if l & 1:
                yield self.table[l]
                l += 1
            l >>= 1
            if r & 1 == 0:
                yield self.table[r]
                r -= 1
            r >>= 1
        
    def add(self, i, x):
        i += self.offset
        self.table[i] += x
        while 1 < i:
            i >>= 1
            self.table[i] = self.table[2 * i] + self.table[2 * i + 1]

def main():
    n = int(readline())
    p = [list(map(int, readline().split())) for _ in range(n)]
    x = set(x1 for x1, y1, x2, y2 in p) | set(x2 for x1, y1, x2, y2 in p)
    c = {xi:i for i, xi in enumerate(sorted(x))}
    que = []
    for x1, y1, x2, y2 in p:
        if y1 == y2:
            if x1 > x2:
                x1, x2 = x2, x1
            que.append((y1, HORIZONTAL, c[x1], c[x2]))
        else:
            if y1 > y2:
                y1, y2 = y2, y1
            x1 = c[x1]
            que.append((y1, VERTICAL_LOW, x1, None))
            que.append((y2, VERTICAL_HIGH, x1, None))
    que.sort(key=itemgetter(0, 1))

    vertical_info = segment_tree(len(x))

    intersection = 0
    for y1, action, x1, x2 in que:
        if action == VERTICAL_LOW:
            vertical_info.add(x1, 1)
        elif action == HORIZONTAL:
            intersection += vertical_info.sum(x1, x2)
        else:
            vertical_info.add(x1, -1)
    print(intersection)
main()

Measured memory_bytes: 78440
#include <stdio.h>
#include <math.h>

int main() {
    unsigned long long a;
    scanf("%llu", &a);
    unsigned long long b = (unsigned long long) sqrt((double) a);
    for (; b > 1; b--) {
        unsigned long long rem = a % b;
        if (rem == 0) {
            printf("%llu", a/b + b - 2);
            return 0;
        }
    }
    printf("%llu", a - 1);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
long long frac(long long n){
  long long ret =1;
  while(n-1){
    ret=(ret*n)%mod;
    n--;
  }
  return ret;
}
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n,m,ans;cin>>n>>m;
  if(abs(n-m)>1){cout<<0;return 0;}
  ans=(frac(n)*frac(m))%mod;
  if(n==m){ans=(ans*2)%mod;}
  cout<<ans;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

for i in range(n-1, 0, -1):
    if h[i-1] == h[i] + 1:
        h[i-1] -= 1
    elif h[i-1] <= h[i]:
        pass
    else:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 14396
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main(){
int k,a,b;
scanf("%d %d %d",&k,&a,&b);
int i,j=0;
for(i=a;i<=b;i++)
if(i%k==0){
  puts("OK");
  j=1;
  break;}
if(j==0)puts("NG");
return 0;} 

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int MOD=1000000007;
const int nmax=3123;
int n,dp[2][nmax],res,nw,nx=1;
char s[nmax];
int main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    dp[0][1]=1;
    for(int i=2; i<=n; ++i){
        if(s[i-1]=='<'){
            dp[nx][1]=0;
            for(int j=2;j<=i; ++j){
                dp[nx][j]=dp[nx][j-1]+dp[nw][j-1];
                if(MOD<=dp[nx][j])dp[nx][j]-=MOD;
            }
        }
        else
            for(int j=i-1; j>0; --j){
                dp[nx][j]=dp[nx][j+1]+dp[nw][j];
                if(MOD<=dp[nx][j])dp[nx][j]-=MOD;
            }
        nw=1-nw;
        nx=1-nx;
    }
    for(int i=1; i<=n; ++i){
        res+=dp[nw][i];
        if(MOD<=res)res-=MOD;
    }
    printf("%d",res);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

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

	vector<int> P(N), Q(N);
	vector<int> v(N);
	for (auto &x : P) {
		cin >> x;
	}
	for (auto &x : Q) {
		cin >> x;
	}
	iota(v.begin(), v.end(), 1);
	int a = 0;
	int b = 0;
	int k = 0;
	do {
		if (v == P) {
			a = k;
		}
		if (v == Q) {
			b = k;
		}
		++k;
	} while (next_permutation(v.begin(), v.end()));

	int ans = abs(a - b);
	cout << ans << endl;
}


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

using namespace std;
int a[22];

signed main() {

    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int n;
    cin >> n;
    int ans = 0;
    for (int i= 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i < n - 1; i++) {
        if(a[i-1] < a[i] && a[i + 1] >= a[i]) ans++;
        else if(a[i - 1] >= a[i] && a[i + 1] < a[i]) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        t: usize
    }
    for _ in 0..t {
        input!(n: usize, abcd: (usize, usize, usize, usize));

        let mut memo = HashMap::new();
        println!("{}", rec(n, abcd, &mut memo));
    }
}

fn rec(n: usize, abcd: (usize, usize, usize, usize), memo: &mut HashMap<usize, usize>) -> usize {
    let (a, b, c, d) = abcd;
    if n == 0 {
        return 0;
    } else if n == 1 {
        return d;
    }
    if let Some(&res) = memo.get(&n) {
        return res;
    }

    let mut res = Vec::new();
    res.push(rec(n/2, abcd, memo) + d*(n - n/2*2) + a);
    res.push(rec((n+1)/2, abcd, memo) + d*((n+1)/2*2 - n) + a);
    res.push(rec(n/3, abcd, memo) + d*(n - n/3*3) + b);
    res.push(rec((n+2)/3, abcd, memo) + d*((n+2)/3*3 - n) + b);
    res.push(rec(n/5, abcd, memo) + d*(n - n/5*5) + c);
    res.push(rec((n+4)/5, abcd, memo) + d*((n+4)/5*5 - n) + c);
    res.push(rec(n/2, abcd, memo).saturating_add(d.saturating_mul(n - n/2)));
    let res = res.into_iter().min().unwrap();
    memo.insert(n, res);
    res
}

Measured memory_bytes: 2692
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    int x; cin >> x;

    for(ll i = -119; i < 120; i++)
    {
        ll j = i;
        while((j*j*j*j*j) - (i*i*i*i*i) < x) j++;
        if((j*j*j*j*j) - (i*i*i*i*i) == x)
        {
            cout << j << " " << i << endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
 
int main() {
	string S;
	int cnt=0;
	cin >> S;
	REP(i,S.length()){
		if(S[i]=='+') cnt++;
		else cnt--;
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

#define INF 		2000000007
#define MOD			1000003

#define MAX 		105

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)

typedef unsigned int 			uint;
typedef unsigned long long int	ull;


int main(){
	int N;cin>>N;
	int B;cin>>B;

	cout << (N <= B ? N : N-1) << endl;



	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()

    n, k = map(int, input().split())
    s = input()
    n = len(s)
    ans = 0
    for i in range(n-1):
        if s[i+1] == s[i]:
            ans += 1
    while ans < n-1 and k > 0:
        if n-1-ans > 1:
            ans += 2
        elif n-1-ans == 1:
            ans+=1
        k -=1
    print(ans)
    
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 9240
#include<iostream>
#include<algorithm>
using namespace std;
 
int N, M;
 
int main(){
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		int a, b;
		cin >> a >> b;
		int num = min(min(a, N - a + 1), min(b, N - b + 1));
		cout << (num % 3 == 0 ? 3 : num % 3) << endl;
	}
	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int flag=0;
	for(int i=1;i<=n;i++)
	{
		int m;
		scanf("%d",&m);
		if(m%2==0)
		{
			if(m%3!=0 && m%5!=0)
			{
				flag=1;
			}
		}
	}
	if(flag)
	{
		printf("DENIED\n");
	}
	else
	{
		printf("APPROVED\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll A;
    cin >> A;
    cout << A+(A*A)+(A*A*A) << endl;
    
    
    return 0;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define INF 10000000
int main()
{
    ll n,i,j,p;
    cin>>n;
    ll dp[n+2][2]={0};
    vector<ll> v(n,0);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    dp[0][0]=0;
    dp[0][1]=0;
    dp[1][0]=abs(v[0]-v[1]);
    dp[1][1]=INF;
    for(i=2;i<n;i++)
    {
        dp[i][0]=min(dp[i-1][0],dp[i-1][1])+abs(v[i]-v[i-1]);
        dp[i][1]=min(dp[i-2][0],dp[i-2][1])+abs(v[i]-v[i-2]);
    }
    cout<<min(dp[n-1][0],dp[n-1][1]);
    return 0;
}

Measured memory_bytes: 2560
#include<cctype>
#include<cstdio>
#include<cstring>
#include<algorithm>
using i64=long long;
const int N=507,V=327,E=140007;const i64 inf=1e18;
int n,m,s,t,tot,head[V],vis[V];i64 cost,dis[V];
struct edge{int v,f;i64 c;int next;}e[E];
struct node{int x,y;i64 v;}p[N];
struct opt{int o,a,b;}op[N];
int read(){int x=0;int c=getchar();while(isspace(c))c=getchar();while(isdigit(c))(x*=10)+=c&15,c=getchar();return x;}
i64 raed(){i64 x=0;int c=getchar();while(isspace(c))c=getchar();while(isdigit(c))(x*=10)+=c&15,c=getchar();return x;}
void add(int u,int v,int f,i64 c){e[++tot]={v,f,c,head[u]},head[u]=tot,e[++tot]={u,0,-c,head[v]},head[v]=tot;}
int update()
{
    i64 mn=inf;
    for(int u=1;u<=t;++u) if(vis[u]) for(int i=head[u];i;i=e[i].next) if(!vis[e[i].v]&&e[i].f) mn=std::min(mn,dis[e[i].v]+e[i].c-dis[u]);
    if(mn==inf) return 0;
    for(int u=1;u<=t;++u) if(vis[u]) dis[u]+=mn;
    return 1;
}
int dfs(int u,int res)
{
    if(u==t) return cost-=dis[s]*res,res;
    int use=0;vis[u]=1;
    for(int i=head[u],t;i;i=e[i].next)
	if(!vis[e[i].v]&&e[i].f&&dis[u]==dis[e[i].v]+e[i].c)
	{
	    t=dfs(e[i].v,std::min(res-use,e[i].f)),use+=t,e[i].f-=t,e[i^1].f+=t;
	    if(use==res) return use;
	}
    return use;
}
void solve(int k)
{
    static int lx[N],rx[N],ly[N],ry[N];
    tot=1,cost=0,s=2*k+2*n+1,t=s+1,memset(head+1,0,t<<2),memset(dis+1,0,t<<3);
    memset(lx+1,0,k<<2),memset(ly+1,0,k<<2),memset(rx+1,0x7f,k<<2),memset(ry+1,0x7f,k<<2);
    for(int i=1;i<=k;++i) add(s,i,1,0),add(i+n+n+k,t,1,0);
    for(int i=1;i<=n;++i) add(i+k,i+n+k,1,-p[i].v);
    for(int i=1;i<=m;++i)
	switch(op[i].o)
	{
	case'U':for(int j=1;j<=k-op[i].b;++j)ry[j]=std::min(ry[j],op[i].a-1);break;
	case'D':for(int j=op[i].b+1;j<=k;++j)ly[j]=std::max(ly[j],op[i].a+1);break;
	case'L':for(int j=op[i].b+1;j<=k;++j)lx[j]=std::max(lx[j],op[i].a+1);break;
	case'R':for(int j=1;j<=k-op[i].b;++j)rx[j]=std::min(rx[j],op[i].a-1);break;
	}
    for(int i=1;i<=k;++i) for(int j=1;j<=n;++j) if(lx[i]<=p[j].x&&p[j].x<=rx[i]) add(i,j+k,1,0);
    for(int i=1;i<=k;++i) for(int j=1;j<=n;++j) if(ly[i]<=p[j].y&&p[j].y<=ry[i]) add(j+n+k,i+n+n+k,1,0);
    do do memset(vis+1,0,t<<2);while(dfs(s,1e9));while(update());
}
int main()
{
    i64 ans=0;
    n=read();for(int i=1;i<=n;++i) p[i]={read(),read(),raed()};
    m=read();for(int i=1;i<=m;++i) op[i]={getchar(),read(),read()};
    for(int k=1;k<=n;++k) solve(k),ans=std::max(ans,cost);
    printf("%lld",ans);
}


Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

ll calc(const VL &a, ll x) {
  int n = a.size();
  ll tot = 0;
  REP(i, 0, n) {
    tot += abs(a[i] - x - i);
  }
  return tot;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VL a(n);
  REP(i, 0, n) cin >> a[i];
  ll lo = -1e10, hi = 1e10;
  while (hi - lo > 3) {
    ll mid1 = (2 * lo + hi + (ll)3e11) / 3 - 1e11;
    ll mid2 = (lo + 2 * hi + (ll)3e11) / 3 - (ll)1e11;
    ll v1 = calc(a, mid1);
    ll v2 = calc(a, mid2);
    if (v1 >= v2) {
      lo = mid1;
    } else {
      hi = mid2;
    }
  }
  ll mi = 1e18;
  REP(i, -5, 5) {
    mi = min(mi, calc(a, lo + i));
  }
  cout << mi << endl;
}


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

int main()
{
  int N;cin>>N;
  vector<int> A(N+1);
  for (int i=1;i<=N;i++)
    cin>>A[i];
  
  vector<int> B(N+1);
  for (int i=1;i<=N;i++)
  {
    B[A[i]]=i; 
  }
  
  for (int i=1;i<=N;i++)
    cout<<B[i]<<" ";
  cout<<endl;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int hi[101];

int main() {
	int a, b;
	cin >> a >> b;
	while (a != 0 || b != 0) {
	    int no = 0, yes = 0;
	    for (int i = 1; i <= 101; i++) hi[i] = 0;
	    for (int i = 0; i < a; i++) {
	        int x; cin >> x;
	        for (int o = 0; o < x; o++) {
	            int yay; cin >> yay;
	            hi[yay]++;
	        }
	    }
	    for (int i = 101; i > 0; i--) {
	        if (yes <= hi[i] && hi[i] >= b) {
	            no = i;
	            yes = hi[i];
	        }
	    }
	    cout << no << endl;
	    cin >> a >> b;
	}
}



Measured memory_bytes: 3016
import java.io.*;
import java.util.*;

public class Main {
    public static PrintWriter out;
    public static FastScanner in;

    private void solve(){
        long n = in.nextLong();
        long m = in.nextLong();

        long req = n*2;

        if(req < m){
            out.print(n+(m-req)/4);
        }else {
            out.print(m/2);
        }

    }

    private int gcd(int a ,int b){
        if(b==0) return a;
        return gcd(b,a%b);
    }

    private void runIO() {
        in = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        solve();
        out.close();
    }
    private static class FastScanner {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        private FastScanner() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

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

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

        private String nextLine() {
            String ret = "";
            try {
                ret = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}


Measured memory_bytes: 21204
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n;
    static long[][] dp = new long[31][31];
    public static void main(String[] args) {
        makeDpTable();
        while(read()){
            solve();
        }
    }

    static void makeDpTable(){
        dp[0][0] = 1;
        for(int i = 1; i < dp.length; i++){
            for(int j = 1; j < dp[0].length; j++){
                for(int k = 1; k <=3; k++){
                    if(j-k <0)continue;
                    dp[i][j] += dp[i-1][j-k];
                }
            }
        }
    }
    static boolean read(){
        n = sc.nextInt();
        if( n == 0 ) return false;
        return true;
    }

    static void solve(){
        int res = 0;
        for(int i = 1; i <= n; i++){
            res += dp[i][n];
        }

        System.out.println((res/10-1)/365+1);
    }
}

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

int main () {
    int  x, a, b ; 
    cin >> x >> a >> b ;
    if(a>=b){
    cout <<"delicious"<<endl;
    }
    else if(abs(a-b)<=x){
        cout <<"safe"<<endl;
    }
    else
    cout <<"dangerous"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
#define f first
#define s second
using namespace std;
const int INF=(int)0x3f3f3f3f;
const int MOD=(int)998244353;
const double eps=1e-9;
int cnt1[200005],cnt2[200005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    set<int> rows,cols;
    long long n,q,t,pos;
    cin>>n>>q;
    long long ans=(n-2)*(n-2),lft=n,top=n;
    while(q--&&cin>>t>>pos){
        if(t==1){
            if(pos<lft){
                cnt1[pos]=top-2;
                ans-=cnt1[pos];
                lft=pos;
            }
            else{
                auto it=cols.upper_bound(pos);
                it--;
                cnt1[pos]=cnt1[*it];
                ans-=cnt1[pos];
            }
            cols.insert(pos);
        }
        else{
            if(pos<top){
                cnt2[pos]=lft-2;
                ans-=cnt2[pos];
                top=pos;
            }
            else{
                auto it=rows.upper_bound(pos);
                it--;
                cnt2[pos]=cnt2[*it];
                ans-=cnt2[pos];
            }
            rows.insert(pos);
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 14516
s = input()

l = [
    "a",
    "b",
    "c",
    "d",
    "e",
    "f",
    "g",
    "h",
    "i",
    "j",
    "k",
    "l",
    "m",
    "n",
    "o",
    "p",
    "q",
    "r",
    "s",
    "t",
    "u",
    "v",
    "w",
    "x",
    "y",
    "z"
]

print(l[l.index(s)+1])

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


using namespace std;
using ll = long long;

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    set<string> s;
    rep(i,n) 
    {
        string a;
        cin >> a;
        s.insert(a);
    }
    cout << s.size() << endl;


   

    return 0;
}


Measured memory_bytes: 19196
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

vector<int> A;

int main(){
	
    int a, b;
    
    while(cin >> a >> b) {
    
    A.clear();
    
    for(int i=0;i<a;i++) {
    	
    int s;	
	cin >> s;
	A.push_back(s);
		
}
    for(int i=1;i<=b;i++) 
    for(int j=0;j<a-1;j++)
    if(A[j] % i > A[j+1] % i)
	swap( A[j], A[j+1]);

    for(int i=0;i<a;i++)
    cout << A[i] << "\n";
}
    return 0;
}


Measured memory_bytes: 3128
#include<stdio.h>
#include<string.h>

void keinazo(int,int);
void keikazu(int,int,int);


int N;
long dp[13][100001];

int main(void){
    char S[100001];

    int i,j;
    for(i=0;i<13;i++){
        for(j=1;j<100001;j++){
            dp[i][j]=0;
        }
    }

    scanf("%s",S);

    N=strlen(S);

    if(S[N-1]=='?'){
        for(i=0;i<10;i++){
            dp[i][1]=1;
        }
    }else{
        int base=S[N-1]-'0';
        dp[base][1]=1;
    }

    int p=10;

    for(i=N-2;i>=0;i--){
        if(S[i]=='?'){
            keinazo(N-i,p);
        }else{
            int ba=S[i]-'0';
            keikazu(N-i,p,ba);
        }
       // printf("%d\n",p);
        p*=10;
        p%=13;
    }

    /*for(i=1;i<N+1;i++){
        for(j=0;j<13;j++){
            printf("%d ",dp[j][i]);
        }
        printf("\n");
    }*/

    printf("%ld",dp[5][N]);

    return 0;
}

void keinazo(int n,int p){
    int i,j;

    for(i=0;i<10;i++){
        for(j=0;j<13;j++){
            dp[(j+p*i)%13][n]+=dp[j][n-1];
        }
    }
    for(i=0;i<13;i++){
        dp[i][n]%=1000000007;
    }

    return;
}

void keikazu(int n,int p,int base){
    int i;
    for(i=0;i<13;i++){
        dp[(i+p*base)%13][n]+=dp[i][n-1];
    }
    return;
}

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

int main() {
	long long n, k;
	cin >> n >> k;
	long long cnt = 0;
	if (k == 0) {
		cnt = n*n;
		cout << cnt << endl;
		return 0;
	}
	for (int b = k + 1; b <= n; b++) {
		int q, r;
		long long s;
		q = n / b;
		r = n % b;
		if (r < k) {
			s = q*(b - k);
		}
		else {
			s = (q + 1)*(r - k + 1) + q*(b - 1 - r);
		}
		//cout << s << endl;
		cnt += s;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int b=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		for(int j=0;j<s.size();j++){
		if(s[i]==s[j] && i!=j){
			b++;
		}
	}
}
	
	if(b>0){
		cout<<"no"<<endl;
	}
	
	else{
		cout<<"yes"<<endl;
	}
	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
// #include <math.h>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

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

  if(a==b) print("H");
  else print("D");

}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
A.sort()
A_acc = list(accumulate(A))[::-1]
A = A[::-1]
ans = 1
for i in range(1, N):
	if A_acc[i]*2 >= A[i-1]:
		ans += 1
	else:
		break
print(ans)


Measured memory_bytes: 16960
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
    string s; cin >> s;
    int n = s.size();
    vector<int> val(2019, 0);
    ll fac = 1, cur = 0;

    ++val[cur];
    for(int i = 0; i < n; ++i) {
        ll add = s[n-1-i] - '0';
        cur = (cur + fac * add) % 2019;
        fac = (fac * 10) % 2019;
        ++val[cur];
    }
    ll ans = 0;
    for(int i = 0; i < val.size(); ++i) {
        ans += val[i] * (val[i] - 1) / 2;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3720