akhauriyash/Code-Regression huggingface dataset:
h, w = [int(i) for i in input().split(' ')]
tg = [input() for i in range(h)]
og = [['.']*w]*h

fail = False
for i in range(h):
    for j in range(w):
        # Blank
        if tg[i][j] == ".":
            continue

        # up direction
        if i > 0 and tg[i-1][j] == '#':
            og[i][j] = '#'
            og[i-1][j] = '#'
            continue

        # down direction
        if i < h-1 and tg[i+1][j] == '#':
            og[i][j] = '#'
            og[i+1][j] = '#'
            continue

        # left direction
        if j > 0 and tg[i][j-1] == '#':
            og[i][j] = '#'
            og[i][j-1] = '#'
            continue

        # right direction
        if j < w-1 and tg[i][j+1] == '#':
            og[i][j] = '#'
            og[i][j+1] = '#'
            continue

        fail = True
        break

    if fail:
        print("No")
        break

if not fail:
    print("Yes")

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 998244353ll;
const ll MAXN = (ll) 2e5 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-8;

bool CMP(pll a, pll b){
	return a.F + a.S > b.F + b.S;
}
pll a[MAXN];

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	ll f = 0, s = 0;
	for(int i = 0;i<n;i++) cin >> a[i].F >> a[i].S;
	sort(a, a + n, CMP);
	for(int i = 0; i < n; i+=2) f += a[i].F;
	for(int i = 1; i < n; i+=2) s += a[i].S;
	cout << f - s; 
	return 0;
}


/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/


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

int main() {
  int N;
  cin >> N;
  long long A = 0;
  
  for (int i = 1; i <= N; i++) {
    if (i%3 != 0 && i%5 != 0){
      A += i;
    }
  }
  cout << A << endl;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
    string S;
    cin >> S;
    for (int i = 1; i < S.size(); ++i) {
        if(S[i] == S[i-1]){
            cout << "Bad";
            return 0;
        }
    }
    cout << "Good";
    return 0;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

K = int(input())
A, B = map(int, input().split())

print("OK" if B // K - (A - 1) // K > 0 else "NG")

Measured memory_bytes: 9696
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

struct union_find{
    VI par;

    void init(int n){
        par.resize(n);
        REP(i,n) par[i] = i;
    }

    int find(int x){
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    void merge(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y) return;
        par[x] = y;
    }
};

int main() {
    int n, r;
    cin >> n >> r;
    VI p(n);
    REP(i,n) p[i] = in() - 1;
    union_find uf;
    uf.init(n);
    REP(i,n) uf.merge(i, p[i]);
    VI sz(n);
    REP(i,n) sz[uf.find(i)]++;
    VI a;
    REP(i,n) if (sz[i]) a.push_back(sz[i]);
    chmin(r, n - r);

    bitset<150001> bs;
    bs.set(0);
    for (int x : a) bs |= (bs << x);
    cout << (bs[r] ? "Yes" : "No") << endl;

    return 0;
}



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

int main() {
    int n, q;
    string s, t, d;

    cin >> n >> q >> s;
    t = string(q, 'A');
    d = string(q, 'R');
    for(int i=0;i<q;i++) cin >> t[i] >> d[i];

    int lft = 0, rit = n-1;
    for(int i=q-1;i>=0;i--){
        if(lft >= 0 && lft < n && t[i] == s[lft] && d[i] == 'L') lft++;
        if(lft-1 >= 0 && lft-1 < n && t[i] == s[lft-1] && d[i] == 'R') lft--;
        if(rit >= 0 && rit < n && t[i] == s[rit] && d[i] == 'R') rit--;
        if(rit+1 >= 0 && rit+1 < n && t[i] == s[rit+1] && d[i] == 'L') rit++;
    }

    cout << rit - lft + 1 << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x, y) for ((x) = (y).begin(); (x) != (y).end(); (x)++)
#define all(x) (x).begin(),(x).end()
#define _end '\n'
template<typename T> inline bool __max__(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool __min__(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using vvec = vector<vector<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

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

    int a, b;
    string s;

    cin >> a >> b;
    cin >> s;

    int i, len = s.size();

    for (i = 0; i < a; i++) {
        if ('0' <= s[i] && s[i] <= '9') {
            continue;
        } else {
            cout << "No" << _end;

            return 0;
        }
    }

    if (s[i++] != '-') {
        cout << "No" << _end;

        return 0;
    }

    for (; i < len; i++) {
        if ('0' <= s[i] && s[i] <= '9') {
            continue;
        } else {
            cout << "No" << _end;

            return 0;
        }
    }

    cout << "Yes" << _end;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include <map>
#include <set>

using namespace std;

#define REP(i,x) for(int i=0; i<(int)(x); i++)       // 0 <= i < x
#define REPS(i,x) for(int i=1; i<=(int)(x); i++)     // 0 < i <= x
#define RREP(i,x) for(int i=((int)(x)-1); i>=0; i--) // x > i >= 0
#define RREPS(i,x) for(int i=((int)(x)); i>0; i--)   // x >= i > 0
#define INF 100000000

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

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

int main(void){
	string s;
    int x, y;
    cin >> s >> x >> y;

    int num[8001] = {0};
    int j = 0;
    REP(i, s.size()){
        if(s[i] == 'F'){
            num[j]++;
        }else if(s[i] == 'T'){
            j++;
        }else{
            break;
        }
    }
    
    // x
    int dp[16001] = {0}, dp_next[16001] = {0};
    dp[8000 + num[0]] = 1;
    int a, b;
    
    for(int i = 1; i <= 4000; i++){
        REP(j, 16001){
            a = j - num[2 * i];
            b = j + num[2 * i];
            if(a < 0){
                dp_next[j] = dp[b];
            }else if(b >= 16001){
                dp_next[j] = dp[a];
            }else{
                dp_next[j] = dp[a] | dp[b];
            } 
        }
        REP(j, 16001){
            dp[j] = dp_next[j];
        }
    }

    if(dp[x + 8000] == 0){
        cout << "No\n";
        return 0;
    }

    // y
    REP(i, 16001){
        dp[i] = 0;
    }
    dp[8000] = 1;
    
    for(int i = 1; i <= 4000; i++){
        REP(j, 16001){
            a = j - num[2 * i - 1];
            b = j + num[2 * i - 1];
            if(a < 0){
                dp_next[j] = dp[b];
            }else if(b >= 16001){
                dp_next[j] = dp[a];
            }else{
                dp_next[j] = dp[a] | dp[b];
            } 
        }
        REP(j, 16001){
            dp[j] = dp_next[j];
        }
    }

    if(dp[y + 8000] == 0){
        cout << "No\n";
        return 0;
    }
    
    cout << "Yes\n";
    return 0;
}


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

typedef long long ll;

int main(void) {

    ll N, A, B; cin >> N >> A >> B;
    ll ans = (B*(N-1) + A) - (A*(N-1) + B) + 1;

    cout << (ans > 0 ? ans : 0) << endl;

    return 0;
}

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




int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string n;
	cin >> n;
	bool odp = false;
	for (int i = 0; i < 3; ++i)
		if (n[i] == '7')
			odp = true;
	cout << (odp ? "Yes\n" : "No\n");
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,s,c,a[100];
	cin>>n>>m;
	memset(a,-1,sizeof(a));
	for(int i=1;i<=m;i++)
	{
		cin>>s>>c;
		if(a[s]!=-1&&a[s]!=c)
		{
			cout<<-1<<endl;
			return 0;
		}
		else a[s]=c; 
	}
	if(n>1&&a[1]==0)
	cout<<-1<<endl;
	else if(n==1)
	{
		if(a[1]==-1)
		cout<<0<<endl;
		else
		cout<<a[1]<<endl;
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
		if(i==1&&a[i]==-1)
		cout<<1;
		else if(a[i]==-1)
		cout<<0;
		else
		cout<<a[i];	
		}
	}
	return 0;
}

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

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

Measured memory_bytes: 256
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: alireza_kaviani
 * Time: 2020-08-26 09:22:22
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

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

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 61;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll l , r , ind , ans;

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

	cin >> l >> r;
	for(int i = LOG ; i >= 0 ; i--){
		if((l & (1ll << i)) & (r & (1ll << i))){
			l ^= (1ll << i);
			r ^= (1ll << i);
		}
		else if(r & (1ll << i)){
			ind = i;
			break;
		}
	}
	
	int flag = 0;
	for(int i = ind - 1 ; i >= 0 ; i--){
		if(r & (1ll << i)){
			flag = 1;
			continue;
		}
		if(flag){
			ans += (1ll << i);
			continue;
		}
		ans += min((1ll << i) , max(0ll , (1ll << i) * 2 - l));
	}
	//cout << ind << sep << ans << endl;
	cout << ans + r - l + 1 << endl;
		
    return 0;
}
/*

*/


Measured memory_bytes: 3652
#include<stdio.h>
#include<algorithm>
#include <bits/stdc++.h>
using namespace std;
int main()
{


   long long int i,j,k,n,m,t;
   string s;
   cin>>s;
   n=s.size();
   j=0;
   //cout<<int(s[0]);
   for(i=0;i<n;i++)
   {
       j=j+int(s[i])-48;
   }
   if(j%9==0)
   {
       cout<<"Yes"<<endl;
   }
   else cout<<"No"<<endl;





return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> T(N);
  for(int i=0;i<N;i++) cin >> T.at(i);
  
  int Ans=0;
  
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      Ans += T.at(i)*T.at(j);
    }
  }
  
  for(int i=0;i<N;i++){
    Ans -= T.at(i) * T.at(i);
  }
  
  Ans /= 2;
  
  cout << Ans << endl;
}


Measured memory_bytes: 3636
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)

int C[499],S[499],F[499];
int N;

int calc(int id,int t){
	if(id==N-1) return t;
	t=max(t,S[id]);
	if((t%F[id])) t+= F[id]-t%F[id];
	return calc(id+1,t+C[id]);
}

int main()
{
	cin>>N;
	rep(i,N-1) cin>>C[i]>>S[i]>>F[i];
	rep(i,N) cout<<calc(i,0)<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long

const int MAX = 1500001;

int hcount[MAX], wcount[MAX];

signed main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (!n && !m) return 0;
    fill(hcount, hcount + MAX, 0);
    fill(wcount, wcount + MAX, 0);
    int h[n], w[m];
    for (int i = 0; i < n; i++) {
      cin >> h[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> w[i];
    }
    int hsum[n], wsum[m];
    hsum[0] = h[0];
    for (int i = 1; i < n; i++) {
      hsum[i] = hsum[i - 1] + h[i];
    }
    wsum[0] = w[0];
    for (int i = 1; i < m; i++) {
      wsum[i] = wsum[i - 1] + w[i];
    }
    for (int i = 0; i < n; i++) {
      hcount[hsum[i]]++;
      for (int j = i - 1; j >= 0; j--) {
        hcount[hsum[i] - hsum[j]]++;
      }
    }
    for (int i = 0; i < m; i++) {
      wcount[wsum[i]]++;
      for (int j = i - 1; j >= 0; j--) {
        wcount[wsum[i] - wsum[j]]++;
      }
    }
    int count = 0;
    for (int i = 1; i < MAX; i++) {
      count += hcount[i] * wcount[i];
    }
    cout << count << endl;
  }
}



Measured memory_bytes: 26580
<?php
$array = explode(' ', trim(fgets(STDIN)));
//echo var_dump($array[4]);

if ($array[1] < $array[3] + $array[4] || 0 > $array[3] - $array[4] || 0 > $array[2] - $array[4] || $array[0] < $array[2] + $array[4] ) {
    echo "No";
}else{
    echo "Yes";
}
?>

Measured memory_bytes: 15368
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


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

  sort(A,A+N);

  ll M = 0;
  for(int i=0; i<N; i++){
    M+=A[i];
  }


  int num=1;
  //符号が変わるもの　1~N-1個
  M -= 2*A[0];
  
  
  while(1){
    if(num<N-1 && A[num]<0){
      M-=2*A[num];
      num++;
    }else{
      break;
    }
  }
  cout<<M<<endl;


  ll temp1 = A[N-1];
  ll temp2 = A[0];

  for(int i=1; i<num; i++){
    cout << temp1 << " " << A[i]<<endl;
    temp1 -= A[i];
  }
  for(int i=num; i<N-1; i++){
    cout<< temp2 << " " << A[i] << endl;
    temp2 -= A[i];
  }

  cout << temp1 << " " << temp2 << endl;
  return 0;
}






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

long long MAXXX = 1000000000000000;

int main() {
  long long N;
  cin >> N;
  
  vector<long long> A(N+1),Bmin(N),Bmax(N),ans(N+1);
  
  for (int i=0; i<N+1; i++) {
    cin >> A[i];
  }
  
  if (N == 0) {
    if (A[0] == 1) {
      cout << 1 << endl;
    }
    else {
      cout << -1 << endl;
    }
    return 0;
  }
  
  ans[0] = 1;
  ans[N] = 0;
  Bmin[0] = 1;
  Bmax[0] = 1;
  
  if (A[0] != 0) {
    cout << -1 << endl;
    return 0;
  }
  
  for (int i=1; i<N; i++) {
    Bmax[i] = Bmax[i-1] * 2ll - A[i];
    Bmax[i] = min(Bmax[i],MAXXX);
    if (Bmax[i] < 0) {
      cout << -1 << endl;
      return 0;
    }
    Bmin[i] = max(0ll,Bmin[i-1] - A[i]);
  }
  
  Bmax[N-1] = min(Bmax[N-1],A[N]);
  Bmin[N-1] = max(Bmin[N-1],(A[N]+1ll) / 2ll);
  
  if (Bmin[N-1] > Bmax[N-1]) {
    cout << -1 << endl;
    return 0;
  }
  
  ans[N-1] = Bmax[N-1];
  
  for (int i=N-2; i>0; i--) {
    ans[i] = min(Bmax[i],ans[i+1] + A[i+1]);
  }
  
  long long kotae = 0;
  
  for (int i=0; i<N+1; i++) {
    kotae += ans[i];
    kotae += A[i];
  }
  
  cout << kotae << endl;
  
  
  return 0;
  
}

Measured memory_bytes: 6368
use std::io::Read;

const MOD: usize = 1_000_000_007;

fn mod_pow(r: usize, mut n: usize) -> usize {
    let mut t = 1;
    let mut s = r % MOD;
    while n > 0 {
        if n & 1 == 1 {
            t = t * s % MOD;
        }
        s = s * s % MOD;
        n >>= 1;
    }
    t
}

fn comb(n: usize, k: usize) -> usize {
    let k = std::cmp::min(k, n - k);
    let mut nu = 1;
    let mut de = 1;
    for i in 0..k {
        nu = nu * (n - i) % MOD;
        de = de * (i + 1) % MOD;
    }
    nu * mod_pow(de, MOD - 2) % MOD
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let x: usize = it.next().unwrap().parse().unwrap();
    let y: usize = it.next().unwrap().parse().unwrap();
    let mut ans = 0;
    for i in 0..(x + 1) {
        if 2 * i > y {
            continue;
        }
        let dx = x - i;
        let dy = y - 2 * i;
        if dx != 2 * dy {
            continue;
        }
        let j = dy;
        ans += comb(i + j, i);
    }
    ans %= MOD;
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
using namespace std;
 
int main(int argc, char *argv[])
{
    vector<long long> a, b;
    int n;
    cin >> n;
 
    for(int i = 0; i < n; ++i) 
    {
        long long a_i, b_i;
        cin >> a_i >> b_i;
        a.push_back(a_i);
        b.push_back(b_i);
    }
 
    long long num = 0;
    for(int i = (int)a.size() - 1; i >= 0; --i)
    {
        a[i] += num;
 
        int diff = 0;
        if(a[i] % b[i] != 0 && (b[i] != 1 || a[i] == 0))
        {
            if(a[i] < b[i])
            {
                diff = b[i] - a[i];
            }
            else if(a[i] > b[i])
            {
                diff = b[i] - (a[i] % b[i]);
            }
        }
 
        num += diff;
    }
 
    cout << num << endl;
}

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

bool check( char c )
{
    char C[5+4+2+1] = "yuiophjklnm";
    for ( int i = 0; i < 5+4+2+1; i++ ) {
        if ( c == C[i] ) return true;
    }
    return false;
}

int main( void )
{
    string input;
    while ( cin >> input && input != "#" ) {
        int answer = 0;
        bool flag = check( input[0] );
        for ( string ::iterator it = input.begin(); it != input.end(); it++ ) {
            if ( flag != check( *it ) ) {
                answer++;
            }
            flag = check( *it );
        }
        cout << answer << endl;
    }
    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int oo = 1<<29;
int N;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	int res = oo;
	forn(i,1,N){
		int a = i;
		int b = N-i;
		string _a = to_string(a);
		string _b = to_string(b);
		int act = 0;
		forn(j,0,_a.size()) act += _a[j]-'0';
		forn(j,0,_b.size()) act += _b[j]-'0';
		res = min(res,act);
 	}
	cout << res << '\n';
	return 0;
}


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

using namespace std;
typedef long long ll;

int sign(int A){ return (A>0) - (A<0); }

int func(){
    cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	int p[30] = {0};
    cin >> n;
    for(int i = 0; i < n; i++) cin >> p[i];

    int count = 0;
    for(int i = 0; i < n - 2; i++){
        if( (sign(p[i] - p[i+1]) * sign(p[i+1] - p[i+2]) == 1 )){
            count++;
        }
    }

    return count;
}

int main(){
    cout << func() << "\n";
}

Measured memory_bytes: 256
N, K = list(map(int, input().split()))
p_list = list(map(int, input().split()))

number_list = []

sum_max = 0
tmp_max = 0
past_max = 0
tmp_max_list = []
for index, p in enumerate(p_list):
    if index >= K:
        tmp_max += (p * (p + 1)) / 2 / p
        tmp_max -= tmp_max_list[index - K]
        if sum_max < tmp_max:
            sum_max = tmp_max
        tmp_max_list.append((p * (p + 1)) / 2 / p)
    else:
        tmp_max += (p * (p + 1)) / 2 / p
        tmp_max_list.append((p * (p + 1)) / 2 / p)

if N == 1:
    print('{:.12f}'.format(float(p_list[0] * (p_list[0] + 1) / 2 / p_list[0])))
elif N == K:
    print('{:.12f}'.format(float(sum(tmp_max_list))))
else:
    print('{:.12f}'.format(float(sum_max)))


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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    rep(i, n) {cin >> h[i];}
    vector<int> a(m);
    vector<int> b(m);

    rep(i, m) {cin >> a[i]; cin >> b[i];}
    
    vector<int> t(n, 1);
    rep(i, m) {
        if (h[a[i]-1] == h[b[i]-1]) {
            t[b[i]-1] = 0;
            t[a[i]-1] = 0;
        }
        else if (h[a[i]-1] > h[b[i]-1]) {
            t[b[i]-1] = 0;
        }
        else {
            t[a[i]-1] = 0;
        }
    }

    int ans = 0;
    rep(i, n) {
        if (t[i]) {
            ans++;
        }
    }

    cout << ans << endl;


    return 0;
} 


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

using namespace std;

int main(){
 int w,h,x,y;
  cin >> w >> h >> x >>y;
 
 float res;
  res=float(w)*float(h)/2.0;
    
  int uni=0;
  if(x+x==w&&y+y==h) uni=1;
  
  cout << res << " " << uni << endl;
}


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

int main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int l = 0;
    int r = 0;
    cin >> l >> r;
    sum += (r - l + 1);
  }
  cout << sum << endl;
}
    
 


Measured memory_bytes: 256
from sys import stdin
import math

def issqrt(x):
    y=int(math.sqrt(x))
    y=y*y
    if(x==y):
        return True
    else:
        return False

a=input()
a=a.replace(' ','')
a=int(a)
if(issqrt(a)):
    print("Yes")
else:
    print("No")

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

int dp[10005];
int damg[10005];
int cost[10005];
int h, n;

int solve (int health)
{
    if (health <= 0) {
        return 0;
    }
    int &res = dp[health];
    if (res != -1) {
        return res;
    }

    res = 1e9+8;
    for (int i = 0; i < n; i++) {
        res = min(res, solve(health-damg[i])+cost[i]);
    }
    return res;
}


int main ()
{
    memset(dp, -1, sizeof dp);
    cin >> h >> n;
    for (int i = 0; i < n; i++) {
        cin >> damg[i];
        cin >> cost[i];
    }
    cout << solve(h) << endl;
    return 0;
}


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

int main(){
    int n, m; cin >> n >> m;
    vector<int> ans(n, -1);
    for (auto i = 0; i < m; i++) {
        int s, c; cin >> s >> c; s--;
        if(ans[s] == -1 or ans[s] == c) ans[s] = c;
        else {
            cout << -1 << endl; return 0;
        }
    }

    if(ans[0] == 0 and n > 1) {
        cout << -1 << endl; return 0;
    }
    if(ans[0] == -1 and n > 1) ans[0] = 1;
    for (auto i = 0; i < n; i++) cout << ((ans[i] == -1) ? 0 : ans[i]);
    cout << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,b,n) for(int i=b;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define all(obj) (obj).begin(),(obj).end()

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,maxi=0;cin>>n;
    vector<int> a(n),b(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n){
        int k=0;
        rep(j,n){
            if(j<=i)k+=a[j];
            if(j>=i)k+=b[j];
        }
        maxi=max(maxi,k);
    }
    cout<<maxi<<endl;
    return 0;
}


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

long long gcd(long long a,long long b){
	if(a==0)return a;
	if(a<b){
    int tmp = a;
    a = b;
    b = tmp;
  	}
 
  	int r = a % b;
 	while(r!=0){
  	  a = b;
 	  b = r;
      r = a % b;
 	}
 	return b;
}

int main(){

	
	long long N;
	cin >> N;
	vector<long long>A(N,0);
	for(long long i=0;i<N;i++)cin >> A[i];
	
	// 0 is or not
	bool is0=false;
	for(long long i=0;i<N;i++)
		if(A[i]==0)is0=true;
	
	long long sum=0;
	long long mnum=0;
	long long minabs=1000000000;
	for(long long i=0;i<N;i++){
		//even or not
		if(A[i]<0)mnum++;
		sum += abs(A[i]);
		minabs=min(minabs,abs(A[i]));
	}
	
	if(is0==true || mnum%2==0)cout << sum<< endl;
	else cout << sum - 2*minabs << endl;
	
}


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

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

	int res1;
	res1 = ((a / k) + 1 ) * k;
	if (res1 <= b || a % k ==  0)
		cout << "OK";
	else
		cout << "NG"; 
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
#include <cctype>
using namespace std;
int main(){
int a,b;
cin >> a>> b;
if(a>=1&&a<=9&&b>=1&&b<=9){
    cout << a*b << endl;
}
else{
    cout << "-1" << endl;
}
    return 0;

}


Measured memory_bytes: 256
using System;
using System.Linq;
 
namespace ABC132
{
    class D
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = input[0];
            long K = input[1];
 
            init(4005);
 
            long red = 0;
            long blue = 0;
            for (long i = 1; i <= K; i++)
            {
                if (N - K + 1 < i) red = 0;
                else red = CalcCombination(N - K + 1, i);
 
                blue = CalcCombination(K - 1, i - 1);
 
                Console.WriteLine((blue * red) % 1000000007);
 
            }
 
        }
 
        // Combination
        static long[,] c;
        public static long[,] init(long x)
        {
            c = new long[x + 5, x + 5];
            c[0, 0] = 1;
            for (long i = 1; i <= x; i++)
            {
                for (long j = 0; j <= i; j++)
                {
                    if (j == 0) c[i, j] = c[i - 1, j];
                    else c[i, j] = (c[i - 1, j] + c[i - 1, j - 1]) % 1000000007;
                }
            }
            return c;
        }
 
        public static long CalcCombination(long n, long k)
        {
            return c[n, k];
        }
 
    }
 
 
 
}

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

using i64 = int64_t;

int main(){
    int n, k, m;
    while(cin >> n >> k >> m, n != 0){
        int ans = 0;
        for(int i=2;i<=n-1;++i)ans = (ans+k)%i;
        ans += m;
        ans %= n;
        cout << ans + 1 << endl;
    }

    return 0;
}



Measured memory_bytes: 3104
import java.util.Scanner;
import java.util.function.Function;

/**
 * Created by btk on 2017/10/13.
 */
public class Main {
   public static void main(String[] args){
       Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
       int k=sc.nextInt();
       long[] x = new long[n];
       long[] y = new long[n];
       for (int i = 0; i < n; i++) {
           x[i]=sc.nextLong();
           y[i]=sc.nextLong();
       }
       long ret=4123456789123456789l;
       for (int i = 0; i < n; i++) {
           for (int j = 0; j < n; j++) {
               for (int l = 0; l < n; l++) {
                   long lb=y[l];
                   long ub=1123456789;
                   final long xl=x[i];
                   final long xu=x[j];
                   final long yl=y[l];
                   Function<Long,Integer> calc=(m)->{
                       int sum=0;
                       for (int o = 0; o < n; o++) {
                           if(xl<=x[o]&&x[o]<=xu&&yl<=y[o]&&y[o]<=m){
                               sum++;
                           }
                       }
                       return sum;
                   };
                   if(calc.apply(ub)<k)continue;
                   while(ub-lb>1){
                       long m=(lb+ub)/2;
                       if(calc.apply(m)>=k)ub=m;
                       else lb=m;
                   }
                   ret=Math.min(ret,(xu-xl)*(ub-yl));

               }
           }
       }
       System.out.println(ret);
       sc.close();
   }
}


Measured memory_bytes: 39836
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	ll N;
	scll(N);
	vll dat(N);
	ll curr = 0;
	for (int i = 0; i < N; ++i) {
		scll(dat[i]);
		curr ^= dat[i];
	}
	for (int i = 0; i < N; ++i) {
		printf("%lld ", curr ^ dat[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 4796
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){
  int N;
  cin >> N;
  double x;
  vector<double> A(N);
  double sum = 0;
  cout << fixed << setprecision(14);
  rep(i, N){
    cin >> A.at(i);
    sum += 1 / A.at(i);
  }
  cout << 1 / sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<climits>
#include<queue>
#include<set>
#include<cmath>
#include<map>

typedef long long LL;
using namespace std;
#define pb push_back
#define mp make_pair
#define x first
#define y second

int read()
{
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)) { if(c == '-') f = 0; c = getchar(); }
	while(isdigit(c)) { x = (x * 10) + (c ^ 48); c = getchar(); }
	return f ? x : -x;
}

const int maxn = 410, mod = 998244353;
int vis[maxn], sumA, sumB;
int c[maxn][maxn], A[maxn], B[maxn], dp[maxn][maxn], inv[maxn], Inv[maxn][maxn], pw[maxn][maxn];

int Pow(int x, int p)
{
	int r = 1;
	while(p)
	{
		if(p & 1) r = (LL)x * r % mod;
		x = (LL)x * x % mod; p >>= 1;
 	}
	return r;
}

void ins(int x, int AA)
{
	for(int i = sumA; i >= AA; --i)
		for(int j = sumB; j >= 0; --j)
			for(int k = 0; k <= min(x, j); ++k)
				(dp[i][j] += (LL)(mod - 1) * c[j][k] % mod * dp[i - AA][j - k] % mod * pw[AA][k] % mod) %= mod;
}

void del(int x, int AA)
{
	for(int i = AA; i <= sumA; ++i)
		for(int j = 0; j <= sumB; ++j)
			for(int k = 0; k <= min(j, x); ++k)
				(dp[i][j] += mod - (LL)(mod - 1) * dp[i - AA][j - k] % mod * c[j][k] % mod * pw[AA][k] % mod) %= mod;
}

int main()
{

	int n = read();
	for(int i = 1; i <= n; ++i) A[i] = read(), B[i] = read(), (sumA += A[i]) %= mod, (sumB += B[i]) %= mod;

	c[0][0] = 1;
	for(int i = 1; i <= max(sumA, sumB); ++i)
	{
		for(int j = 1; j <= i; ++j)
			c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
		c[i][0] = 1;
	}

	for(int i = 0; i <= max(sumA, sumB); ++i) inv[i] = Pow(i, mod - 2);
	for(int i = 0; i <= max(sumA, sumB); ++i) 
		for(int j = 0; j <= max(sumA, sumB); ++j)
			Inv[i][j] = Pow(inv[i], j);
	for(int i = 0; i <= max(sumA, sumB); ++i)
		for(int j = 0; j <= max(sumA, sumB); ++j)
			pw[i][j] = Pow(i, j);

	dp[0][0] = 1;
	for(int i = 1; i <= n; ++i)
		ins(B[i] - 1, A[i]);

	int ans = 0;
	for(int i = 1; i <= n; ++i)
	{
		del(B[i] - 1, A[i]);
		for(int j = 0; j <= sumA; ++j)
			for(int k = 0; k <= sumB; ++k) if(dp[j][k])
			{
				int tmp = (LL)inv[j + A[i]] * sumA % mod;
				tmp = (LL)tmp * (k + B[i]) % mod * c[k + B[i] - 1][k] % mod * dp[j][k] % mod * Inv[j + A[i]][k + B[i]] % mod * pw[A[i]][B[i]] % mod;
				(ans += tmp) %= mod;
			}
		ins(B[i] - 1, A[i]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2816
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

vector<int>ans;
vector<int>E[100005];
int visited[100005];

void dfs(int v) {

	visited[v] = 1;

	int i;

	for (i = 0; i < E[v].size(); i++) {
		int u = E[v][i];
		if (visited[u] == 0) {
			ans.push_back(u);
			dfs(u);
			break;
		}
	}

}

int main() {

	int N, M;

	scanf("%d %d",&N,&M);

	int i;

	for (i = 0; i < M; i++) {
		int A, B;
		scanf("%d %d",&A,&B);
		E[A].push_back(B);
		E[B].push_back(A);
	}
	ans.push_back(1);
	dfs(1);
	reverse(ans.begin(),ans.end());
	dfs(1);
	cout << ans.size() << endl;
	for (i = 0; i<ans.size(); i++) {
		cout << ans[i];
		if (i != ans.size() - 1) {
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 10104
#include <stdio.h>
#include<string.h>
int main(void)
{
int a,b,c;
int q[3];
int temp;
int i;
scanf("%d%d%d",&q[0],&q[1],&q[2]);
for(i=0;i<3;i++){
	for(a=2;a>i;a--){
		if(q[a-1]>q[a]){
			temp=q[a];
			q[a]=q[a-1];
			q[a-1]=temp;
			
			
			
			
			
			
			
		}
		
		
		
		
		
	}
	
	
	
	
}

printf("%d %d %d\n",q[0],q[1],q[2]);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int n;
    cin >> n;
    vector <int> h(n);
    int ma = 0;;
    int a = 0;
    int ans = 0;
    rep(i,0,n) {
        cin >> h[i];
        ans += max(h[i] - a,0);
        a = h[i];
    }

    cout << ans << endl;
}

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

bool chk(string s) {
    bool ret = false;

    for (int i = 0; i < s.size() / 2; i++){
        if (s.at(i) != s.at(s.size() - i - 1)){
            ret = true;
        }
    }
    return ret;
}

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

    int len = s.size() / 2;
    if ((chk(s) == false) && chk(s.substr(0, len)) == false && chk(s.substr(len + 1, len)) == false){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
def main():
    from bisect import bisect_left as bl

    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()

    inf = 10**18+1

    ok = -inf
    ng = inf
    start_0 = bl(a, 0)
    start_1 = bl(a, 1)

    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        cnt = 0
        if mid >= 0:
            now = 0
            if start_0 > 0:
                for i in a[start_0-1::-1]:
                    while now < n:
                        if i*a[now] >= mid:
                            now += 1
                        else:
                            break
                    cnt += n - now
            now = n
            for i in a[start_1:]:
                while now > 0:
                    if i*a[now-1] >= mid:
                        now -= 1
                    else:
                        break
                cnt += now
        else:
            now = 0
            for i in a[:start_0]:
                while now < n:
                    if i*a[now] >= mid:
                        now += 1
                    else:
                        break
                cnt += n - now
            now = n
            for i in a[n-1:start_1-1:-1]:
                while now > 0:
                    if i*a[now-1] >= mid:
                        now -= 1
                    else:
                        break
                cnt += now
        if mid > 0:
            cnt += n * (start_1 - start_0)
        cnt -= len([None for i in a if i*i < mid])
        if cnt//2 < k:
            ok = mid
        else:
            ng = mid
    print(ok)


main()

Measured memory_bytes: 136472
def solve():
    card = []
    num_pos = {}
    for i in range(3):
        row = [int(num) for num in input().split()]
        card.append(row)
        for j,num in enumerate(row):
            num_pos[num] = (i,j)

    N = int(input())
    for i in range(N):
        target = int(input())
        # print(int(input()))
        if target in num_pos:
            pos_i, pos_j = num_pos[target]
            card[pos_i][pos_j] = 0

    ans = False
    for row in card:
        if not any(row):
            ans = True
    for column in range(3):
        column_flag = True
        for i in range(3):
            if card[i][column]:
                column_flag = False
        if column_flag:
            ans = True
    diagonal_flag = True
    for i in range(3):
        if card[i][i]:
            diagonal_flag = False
    if diagonal_flag:
        ans = True
    diagonal_flag = True
    for i in range(3):
        if card[2-i][i]:
            diagonal_flag = False
    if diagonal_flag:
        ans = True
    if ans:
        print("Yes")
    else:
        print("No")
    # for row in card:
    #     print(row)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(reader.readLine());
		}
		reader.close();
		System.out.println(LIS(n,a));
	}
	private int LIS(int n, int[] a) {
		int[] dp = new int[n];
		dp[0] = a[0];
		int lis = 0;
		for (int i = 1; i < n; i++) {
			if (a[i] < dp[0]) {
				dp[0] = a[i];
			} else if (a[i] > dp[lis]) {
				lis++;
				dp[lis] = a[i];
			} else {
				dp[findPos(dp, lis, a[i])] = a[i];
			}
 		}
		return lis + 1;
	}
	private int findPos(int[] dp, int lis, int target) {
		int i = 0;
		int j = lis;
		while (i <= j) {
			int guessIdx = i + (j - i) / 2;
			int guessValue = dp[guessIdx];
			if (guessValue == target) {
				return guessIdx;
			}
			if (guessValue < target) {
				i = guessIdx + 1;
			} else {
				j = guessIdx - 1;
			}
		}
		if (dp[i] < target) return i + 1;
		return i;
	}
}


Measured memory_bytes: 36844
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int get_exp(string x) {
  return stoi(x.substr(3));
}

bool dfs(string& s, int num, map<string, vector<pair<int, string>>>& G, map<string, int>& vis) {
  for(auto& e: G[s]) {
    int r; string next; tie(r, next) = e;
    auto iter = vis.find(next);

    if(iter != vis.end()) {
      if(num + r != iter->second) return false;
    } else {
      vis[next] = num + r;
      if(!dfs(next, num + r, G, vis)) return false;
    }

  }
  return true;
}

int main() {

  int N;
  while(cin >> N && N) {

    map<string, vector<pair<int, string>>> G;
    set<string> st;

    rep(__, N) {
      char _; string s1, s2, t;
      cin >> _ >> s1 >> _ >> t >> s2;
      G[s1].emplace_back(get_exp(t), s2);
      G[s2].emplace_back(get_exp(t) * -1, s1);
      st.insert(s1), st.insert(s2);
    }

    map<string, int> vis;
    bool ok = 1;
    for(auto s: st) {
      if(vis.find(s) != vis.end()) continue;
      vis[s] = 1;
      if(!dfs(s, 1, G, vis)) {
        ok = 0;
        break;
      }
    }

    cout << (ok ? "Yes" : "No") << endl;
  }
    
  return 0;
}

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

int64_t mod = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<int> list(N);
    for (int i = 0; i < N; i++)
        cin >> list[i];
    vector<int> tmp = list;
    sort(tmp.begin(), tmp.end());
    for (int i = 0; i < N; i++)
    {
        if (list[i] != tmp[N - 1])
            cout << tmp[N - 1] << endl;
        else
            cout << tmp[N - 2] << endl;
    }
}

Measured memory_bytes: 3200
#include <cstdio>  
#include <cstring>  
#include <cmath>  
using namespace std;  
//dp   dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j]  
const int maxn=1e2+10;   
int n;  
int a[maxn][maxn];  
int dp[maxn][maxn];  
  
int max(int a,int b)  
{  
    return a>b?a:b;  
 }   
  
void solve()  
{  
    dp[1][1]=a[1][1];  
    for(int i=1;i<=2;i++)  
    {  
        for(int j=1;j<=n;j++)  
        {  
            if(i==1)  
                dp[i][j]=dp[i][j-1]+a[i][j];  
            else  
                dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];   
        }  
    }  
}   
int main()  
{  
    while(~scanf("%d",&n))  
    {  
      
    memset(a,0,sizeof(a));  
    memset(dp,0,sizeof(dp));  
    for(int i=1;i<=2;i++)  
    {  
        for(int j=1;j<=n;j++)  
        {  
            scanf("%d",&a[i][j]);  
        }  
    }  
    solve();  
    printf("%d\n",dp[2][n]);  
}  
    return 0;  
} 

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define pi 3.141592653589
#define MOD 1000000007
#define to() int t; cin>>t; while(t--)
#define pb push_back
#define in insert
#define mp make_pair
#define ff first
#define ss second
#define si(s) s.size()
#define fori(it,v) for(it=v.begin();it!=v.end(); it++) 
#define for1(low,high,k) for(int i=low;i<high;i+=k)
#define for11(low,high,k) for(int j=low;j<high;j+=k)
#define for2(low,high,k) for(int i=low;i<=high;i+=k)
#define rev(high,low,k)  for(int i=high;i>=low ;i-=k)
#define all(x) x.begin(), x.end()
#define fil(x,i) memset(x,i,sizeof(x));
#define setbits(x) __builtin_popcount(x)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout) 
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;


int main()
{
	boost;
	ll a,b,c,d; cin>>a>>b>>c>>d;
	ll ans=b*d;
	ans=max(ans,a*d);
	ans=max(ans,a*c);
	ans=max(ans,b*c);
	cout<<ans<<endl;
	
	
	

return 0;
}


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

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

    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        a[i]--;
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (i == a[a[i]]) cnt++;
    }

    cout << cnt/2 << endl;

    return 0;
}

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

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define read FILE *fp;\
fp=freopen("testcase.txt","r",stdin);
#define ll long long
#define ull unsigned long long
#define sf(n) scanf("%I64d",&n)
#define pf(n) printf("%I64d\n",n)
#define loop for(long long i=0;i<n;i++)
#define lp(b,n) for(long long i=b;i<=n;i++)
#define pb(n) push_back(n)
#define srt(v) sort(v.begin(),v.end())
#define rvs(v) sort(v.begin(), v.end(), greater<long long>());
#define F first
#define S second
#define mp(a,b) make_pair(a,b);
#define fio ios::sync_with_stdio(false); cin.tie(),cout.tie();
ll llmax = numeric_limits<long long>::max();
ll llmin= numeric_limits<long long>::min();
ll mark[5010];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(),cout.tie();
    ll n,k;
    cin>>n>>k;
    vector<pair<ll,ll> >v;
    ll a=0,b=0,c=0,d=0,e=0;
    for(ll i=1;i<=n-2;i++)
    {
        a+=i;
    }
    if(k>a)
    {
        cout<<-1<<endl;
        return 0;
    }
    for(ll i=2;i<=n;i++)
    {
        v.push_back(make_pair(1,i));
    }
    d=a-k;
    for(ll i=2;i<n;i++)
    {
        for(ll j=i+1;j<=n;j++)
        {
            if(d==0)
            {
                c=1;
                break;
            }
            d--;
            v.push_back(make_pair(i,j));
        }
        if(c)
            break;
    }
    cout<<v.size()<<endl;
    for(ll i=0;i<v.size();i++)
    {
        cout<<v[i].first<<" "<<v[i].second<<endl;
    }
}



Measured memory_bytes: 3748