akhauriyash/Code-Regression huggingface dataset:
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

ll x[MAXn],y[MAXn];

int main()
{
    IOS();
    ll n,m,X,Y;
    cin>>n>>m>>X>>Y;
    REP(i,n)cin>>x[i],X = max(X,x[i]);
    REP(i,m)cin>>y[i],Y = min(Y,y[i]);
    if(Y > X)cout<<"No War"<<endl;
    else cout<<"War"<<endl;

}


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

using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;

ll fpow(ll x, ll p) {
    if (p == 0)
        return 1;
    return ((p & 1) ? x : 1) * fpow(x * x % MOD, p >> 1) % MOD;
}

ll subs(ll x, ll d) {
    return ((x - d) % MOD + MOD) % MOD;
}

class Fnwick {
    int *ar;
    int size;
  public:
    Fnwick(int n) {
        size = n + 1;
        ar = new int[size];
        memset(ar, 0, sizeof(int) * size);
    }
    ~Fnwick() {
        delete ar;
    }
    int add(int x, int v) {
        for (int ctr1 = x + 1; ctr1 < size; ctr1 += (ctr1 & -ctr1))
            ar[ctr1] += v;
    }
    int get(int x) {
        int rez = 0;
        for (int ctr1 = x + 1; ctr1 > 0; ctr1 -= (ctr1 & -ctr1))
            rez += ar[ctr1];
        return rez;
    }
};

ll count(vector<ii> &p, unordered_map<int, int> &rc, int n) {
    ll rez = 0;
    Fnwick bit(n);
    for (int ctr1 = 0; ctr1 < n; ++ctr1) {
        rez = subs(rez, fpow(2, ctr1));
        rez = subs(rez, fpow(2, n - 1 - ctr1));
        int y = rc.find(p[ctr1].second)->second;
        int lower = bit.get(y);
        int higher = ctr1 - lower;
        rez = (rez + fpow(2, lower)) % MOD;
        rez = (rez + fpow(2, higher)) % MOD;
        bit.add(y, 1);
    }
    return rez;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;

    int x, y;
    vector<ii> points;
    vector<int> compressed;
    unordered_map<int, int> rev;
    for (int ctr1 = 0; ctr1 < n; ++ctr1)
        cin >> x >> y, points.push_back(make_pair(x, y)), compressed.push_back(y);
    
    sort(points.begin(), points.end());
    sort(compressed.begin(), compressed.end());
    for (int ctr1 = 0; ctr1 < n; ++ctr1)
        rev.emplace(compressed[ctr1], ctr1);
    
    ll rez = subs(fpow(2, n), 1) * n % MOD;
    rez = (rez + count(points, rev, n)) % MOD;
    reverse(points.begin(), points.end());
    rez = (rez + count(points, rev, n)) % MOD;
    
    cout << rez << "\n";

    return 0;
}

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

int p[1010];

int main(){
	while(1){
		int n,m,t=0;
		cin>>n>>m;
		if(n==0&&m==0) break;
		for(int i=0;i<n;i++) cin>>p[i];
		int f=1;
		while(f==1){
			f=0;
			for(int j=0;j<n-1;j++){
				if(p[j]<p[j+1]){
					swap(p[j],p[j+1]);
					f=1;
				}
			}
		}
		for(int i=1;i<=n/m;i++){
			p[i*m-1]=0;
		}
		for(int i=0;i<n;i++){
			t+=p[i];
		}
		cout<<t<<endl;
	}
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<P> v(n);
    for(int i=0; i<n; i++){
        cin >> v[i].second >> v[i].first;
    }

    sort(v.begin(), v.end());

    ll t = 0;
    bool flag = true;
    for(int i=0; i<n; i++){
        t += v[i].second;
        if(t > v[i].first) flag = false;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("io\\in.txt", "r", stdin);
    freopen("io\\out.txt", "w", stdout);
#endif

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

    ll cur = 1000, mn = a[0];
    rep(i, n - 1) {
        if (a[i] > a[i + 1]) {
            cur += (cur / mn) * (a[i] - mn);
            mn = a[i + 1];
        }
    }
    cur += (cur / mn) * (a.back() - mn);
    cout << cur;

    return 0;
}


Measured memory_bytes: 3652
#include <queue>
#include <vector>
#include <iostream>
#pragma warning(disable : 4996)
using namespace std;
void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (1) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
inline void writeln(int x) {
	int s = 0; char f[8];
	while (x) {
		f[s++] = x % 10;
		x /= 10;
	}
	if (!s) f[s++] = 0;
	while (s--) putchar_unlocked(f[s] + '0');
	putchar_unlocked('\n');
}
int N, M, Q, a[200009], b[200009], r[200009], f[200009], dist[200009], ret[200009]; vector<int> g[200009], gt[200009]; bool vis[100009];
int main() {
	reader(&N), reader(&M), reader(&Q);
	for (int i = 0; i < M; i++) {
		reader(&a[i]), reader(&b[i]), a[i]--, b[i]--;
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}
	fill(f, f + M, -1);
	for (int i = 0; i < Q; i++) reader(&r[i]), r[i]--, f[r[i]] = i;
	queue<int> que1; que1.push(0);
	fill(dist, dist + N, -1); dist[0] = 0;
	while (!que1.empty()) {
		int u = que1.front(); que1.pop();
		for (int i : g[u]) {
			if (dist[i] == -1) {
				dist[i] = dist[u] + 1;
				que1.push(i);
			}
		}
	}
	for (int i = 0; i < M; i++) {
		if (dist[a[i]] == dist[b[i]]) continue;
		if (dist[a[i]] > dist[b[i]]) swap(a[i], b[i]);
		if (f[i] == -1) gt[a[i]].push_back(b[i]);
	}
	int cnt = N - 1;
	vector<bool> vis(N); vis[0] = true;
	queue<int> que2; que2.push(0);
	while (!que2.empty()) {
		int u = que2.front(); que2.pop();
		for (int i : gt[u]) {
			if (!vis[i]) {
				vis[i] = true; cnt--;
				que2.push(i);
			}
		}
	}
	for (int i = Q - 1; i >= 0; i--) {
		ret[i] = cnt;
		if (dist[a[r[i]]] == dist[b[r[i]]]) continue;
		gt[a[r[i]]].push_back(b[r[i]]);
		if (vis[a[r[i]]] && !vis[b[r[i]]]) {
			vis[b[r[i]]] = true; cnt--;
			queue<int> que; que.push(b[r[i]]);
			while (!que.empty()) {
				int u = que.front(); que.pop();
				for (int j : gt[u]) {
					if (!vis[j]) {
						vis[j] = true, cnt--;
						que.push(j);
					}
				}
			}
		}
	}
	for (int i = 0; i < Q; i++) writeln(ret[i]);
	return 0;
}

Measured memory_bytes: 23216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  int f = 0;
  cin >> s;
  
  if (s[1] == s[2]){
    if (s[1] == s[0] || s[1] == s[3]){
      cout << "Yes" << endl;
      f++;
    }
  }
  if (f == 0)
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


vector<ll> Eratosthenes(ll n) {
  vector<bool> prime(n, false);
  vector<ll> val;
  for (int i = 0; i < n; i++) {
    prime[i] = 1;
  }
  prime[0] = prime[1] = 0;

  for (int i = 0; i < n; i++) {
    if (prime[i]) {
      for (int j = i + i; j < n; j += i) {
        prime[j] = 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (prime[i])val.push_back(i);
  }
  return val;
}

void eratosthenesbool(vector<bool> &prime,ll n){
    for (int i = 0; i < n; i++) prime[i] = 1;
    prime[0] = prime[1] = 0;
    for (int i = 0; i < n; i++){
        if(prime[i]){
            for(int j = i + i; j < n; j+=i){
                prime[j] = 0;
            }
        }
    }
}



int main() {
  ll q;
  cin >> q ;


  ll num =100001;

  vector<ll> l(q);
  vector<ll> r(q);

  for (int i = 0; i < q; ++i)
  {
    cin >> l[i] >> r[i];
  }
  // vector<ll> prim = Eratosthenes(num);

  vector<bool> primbool(num, false);
  eratosthenesbool(primbool,num-1);
  // for(auto v:prim){
  //   primbool[v] = true;
  // }

  vector<ll> lis(num,0);

  for(ll i = 2;i<num;i++){
    lis[i] = lis[i-1];
    if ( primbool[i] == true && primbool[ (i+1)/2 ] ==true  && i%2==1 ){
      lis[i]++;
    }
  }

  for(int i=0;i<15;i++){
    cerr << primbool[i]  << ",";
  }cerr <<endl;


  for(int i=0;i<15;i++){
    cerr << lis[i]  << ",";
  }cerr <<endl;

  for(int i=0;i<q;i++){
    cout << lis[r[i]] - lis[l[i]-1] <<endl;
  }
  // cout << ans;

}




















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


int main()
{
	int n, k, r, s, p,ans=0;
	string t;
	int a[3],na[3];
	cin >> n >> k >> r >> s >> p; 
	cin>>t;

	for (int i = 0; i < k; i++) {
		a[0] = (t[i] == 's') * r;
		a[1] = (t[i] == 'p') * s;
		a[2] = (t[i] == 'r') * p;
		for (int j = 1; i + j * k < n; j++) {
			na[0] = max(a[1], a[2]) + (t[i+j*k] == 's') * r;
			na[1] = max(a[0], a[2]) + (t[i+j*k] == 'p') * s;
			na[2] = max(a[0], a[1]) + (t[i+j*k] == 'r') * p;
			a[0] = na[0];
			a[1] = na[1];
			a[2] = na[2];
		}
		ans += max(max(a[0], a[1]), a[2]);
	}
	cout << ans<<endl;
	return 0;
}

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

int main() {
   int K;
   cin >> K;
   long long ans = 0;
   for (int i=1; i<=K; i++) {
      for (int j=1; j<=K; j++) {
         for (int k=1; k<=K; k++) {
            ans += gcd(i,gcd(j,k));
         }
      }
   }
   cout << ans << endl;
   return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll x, y;
  cin >> x >> y;
  cout << max(x+y, max(x-y, x*y)) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;

class Class01
{
    public static void Main(string[] args)
    {
        int[] arr = new int[1000000];
        arr[0] = 0;
        arr[1] = 0;
        arr[2] = 1;
        int prime = 1;

        for (int i = 3; i < 1000000; i++)
        {
            var judge = true;
            for (int j = 2; j <= (int)Math.Sqrt(i); j++)
            {
                if (i % j == 0)
                {
                    judge = false;
                    break;
                }
            }
            if (judge == true) prime++;
            arr[i] = prime;
        }

        string s;
        while ((s = Console.ReadLine()) != null)
        {
            int i = int.Parse(s);
            Console.WriteLine(arr[i]);
        }
    }
}

Measured memory_bytes: 13036
import bisect
import copy
import heapq
import sys
import itertools
import math
from functools import lru_cache
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    A = read_list()
    res = 1000
    l = -1
    r = -1
    for a in A:
        if l < 0:
            l = a
            continue

        if r < 0:
            if l >= a:
                l = a
            else:
                r = a
        else:
            if r <= a:
                r = a
            else:
                res += (res // l) * (r - l)
                l = a
                r = -1

    if r >= 0:
        res += (res // l) * (r - l)
    print(res)


if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

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

signed main() {
  int N,K; cin >> N >> K;
  vector<int> A(N);
  rep(i,N){
    cin >> A[i];
  }

   rep(i, N-K) {
    if(A[K+i] > A[i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

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

int main(){
  int n,m,x;
  cin >> n >> m >> x;

  int ans0 = 0;
  int ansn = 0;
  for (int i = 0; i < m; i++)
  {
    int a;
    cin >> a;
    if (a<x) ans0++;
    else ansn ++;  
  }

  cout << min(ans0,ansn) << endl;
  
}

Measured memory_bytes: 256
h = [float(input()) for _ in range(int(input()))]
d = {"1": ":","2": ":","3": ":","4": ":","5": ":","6": ":"}
for v in h:
    if v < 165.0:
        d["1"] += "*"
    elif v >= 165.0 and v < 170.0:
        d["2"] += "*"
    elif v >= 170.0 and v < 175.0:
        d["3"] += "*"
    elif v >= 175.0 and v < 180.0:
        d["4"] += "*"
    elif v >= 180.0 and v < 185.0:
        d["5"] += "*"
    else:
        d["6"] += "*"

for k, v in sorted(d.items(), key=lambda x: int(x[0])):
    print(k+v)

Measured memory_bytes: 7760
#include <iostream>
#include <vector>

#define INF 1000000

#define MAXN 2009

int n, k;

using namespace std;

vector <int> g[MAXN];
bool viz[MAXN];
int d[MAXN][MAXN], s[MAXN], h[MAXN];
int aux[MAXN];

void dfs(int x){
    viz[x]=1;
    for(int i=1; i<=k; i++)
        d[x][i]=INF;
    h[x]=0;
    s[x]=1;
    for(auto y:g[x]) if(viz[y]==0){
        dfs(y);
        s[x]+=s[y];
        int l=min(h[x], k);
        for(int i=0; i<=k; i++)
            aux[i]=d[x][i]+s[y];
        l=min(h[y], k-1);
        for(int i=0; i<=l; i++){
            int lim=min(k-i-1, h[x]);
            for(int j=0; j<=lim; j++)
                aux[max(i+1, j)]=min(aux[max(i+1, j)], d[y][i]+d[x][j]);
        }
        for(int i=0; i<=k; i++)
            d[x][i]=aux[i];
        h[x]=max(h[x], h[y]+1);
    }
}

int main(){
    cin >> n >> k;

    for(int i=1; i<n; i++){
        int x, y;
        cin >> x >> y;

        g[x].push_back(y);
        g[y].push_back(x);
    }

    int r=1;
    dfs(r);
    int ans=d[r][0];
    for(int x=1; x<=n; x++)
        for(int i=0; i<=k; i++)
            ans=min(ans, d[x][i]+n-s[x]);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 16256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for(long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
using namespace std;

typedef long long ll;

long long myGcd(long long a, long long b)
{
	if (a % b == 0)return b;
	return myGcd(b, a % b);
}

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

long long myLcm(long long a, long long b)
{
	return a * b / myGcd(a, b);
}

int myLcm(int a, int b)
{
	return a * b / myGcd(a, b);
}

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

	ll account = 100, X, count = 0;

	cin >> X;

	while (1)
	{
		account += account * 0.01;
		count++;
		if (account >= X)
		{
			cout << count << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 3652
N, K = map(int, input().split())
a = [int(c) for c in input().split()]


dp = [False] * (K+1)
for k in range(K+1):
    for ai in a:
        if k >= ai:
            dp[k] = dp[k] or (not dp[k-ai])

print('First' if dp[k] else 'Second')

Measured memory_bytes: 41836
//Q-flower
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i=a;i<=b;i++)
#define mod 1000000007
#define inf (1LL<<60)
#define all(x) (x).begin(),(x).end()
#define prDouble(x) cout<<fixed <<setprecision(10)<<x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

struct flower
{
int hi;
int bty;
};

ll solve(vector<flower>& v,int n)
{

vector<ll>dp(n+1);
map<ll,ll>meaningful;
//base case
dp[1]=v[1].bty;
meaningful[v[1].hi]=dp[1];
ll ans=dp[1];
for(int i=2;i<=n;i++)
{   
    dp[i]=v[i].bty;
  auto it= meaningful.lower_bound((v[i].hi)+1); 
//if there is any guy which has a height greater then this

  if(it!=meaningful.begin())
  {
      it--;
       dp[i]+=it->second;
  }

meaningful[v[i].hi]=dp[i];

auto it2=meaningful.upper_bound(v[i].hi);

while(it2!=meaningful.end() && it2->second < dp[i])
{   
    auto temp=it2;
    temp++;
    meaningful.erase(it2);
    it2=temp;

}
ans=max(ans,dp[i]);
}
return ans;





}





int main()
{
    int n;
    cin>>n;
    vector<flower>v(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>v[i].hi;
    }
    for(int i=1;i<=n;i++)
    {
        cin>>v[i].bty;
    }
    cout<<solve(v,n);
    return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)


int main() {
	long long n,cnt1=1,n2;//n and n-1 is always ans
	cin>>n;
	for(long long i=2;i<=sqrt(n-1);i++){
	    if((n-1)%i==0)cnt1+=2;
	    if(i*i==n-1)cnt1--;
	}
	//cout<<cnt1;//
	cnt1++;
	for(long long i=2;i<=sqrt(n);i++){
	    n2=n;//cout<<n<<endl;
	    while(n2%i==0){
	        n2/=i;
	    }
	    if(n2!=n&&n2%i==1){
	        cnt1++;//cout<<i<<endl;
	    }
	}
	if(n==2)cnt1--;
	cout<<cnt1;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,-1,0,1,0};
const int dy[]={0,1,0,-1,0,1,0,-1};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> Pii;
typedef pair<int,vi > P;
typedef long long ll;
bool memo[52][52][52][52];
char stageL[52][52];
char stageR[52][52];
struct data{
    Pii l;
    Pii r;
    data(){}
    data(Pii _l ,Pii _r){
        l = _l;
        r = _r;
    }
};
int W,H;

bool canMove(int y,int x,char type){
    bool f = false;
    if(type == 'L'){
        f = stageL[y][x] != '#';
    }
    else if(type == 'R'){
        f = stageR[y][x] != '#';
    }
    return f & (y >= 0 && y < H && x >= 0 && x < W);
}

int main(){
    
    while(scanf("%d%d",&W,&H),W){
        memset(memo,0,sizeof(memo));
        memset(stageL,0,sizeof(stageL));
        memset(stageR,0,sizeof(stageR));
        Pii Lstart,Rstart;
        Pii Lgoal,Rgoal;
        rep(i,H){
            scanf("%s",stageL[i]);
            scanf("%s",stageR[i]);
            rep(j,W){
                if(stageL[i][j] == 'L'){
                    Lstart = Pii(i,j);
                }
                if(stageL[i][j] == '%'){
                    Lgoal = Pii(i,j);
                }
                if(stageR[i][j] == 'R'){
                    Rstart = Pii(i,j);
                }
                if(stageR[i][j] == '%'){
                    Rgoal = Pii(i,j);
                }
            }
        }

        queue < data > Q;
        Q.push(data(Lstart,Rstart));

        int ans = 0;

        while( !Q.empty() ){
            data e = Q.front();Q.pop();
            if(memo[e.l.fr][e.l.sc][e.r.fr][e.r.sc])continue;
            memo[e.l.fr][e.l.sc][e.r.fr][e.r.sc] = true;

            if(Lgoal == e.l && Rgoal != e.r){
                continue;
            }

            if(Lgoal != e.l && Rgoal == e.r){
                continue;
            }

            if(Lgoal == e.l && Rgoal == e.r){
                ans = 1;
                break;
            }

            rep(i,4){
                int nLy = e.l.fr + dy[i];
                int nLx = e.l.sc + dx[i];
                int nRy = e.r.fr + dy[i+4];
                int nRx = e.r.sc + dx[i+4];

                if(canMove(nLy,nLx,'L') && canMove(nRy,nRx,'R')){
                    Q.push(data(Pii(nLy,nLx),Pii(nRy,nRx)));
                }
                else if(!canMove(nLy,nLx,'L') && canMove(nRy,nRx,'R')){
                    Q.push(data(e.l,Pii(nRy,nRx)));
                }
                else if(canMove(nLy,nLx,'L') && !canMove(nRy,nRx,'R')){
                    Q.push(data(Pii(nLy,nLx),e.r));
                }

            }

        }

        ans ? puts("Yes") : puts("No");

    }
    return 0;
}

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

//create arrays outside of main()

int a[100];

int main(){

    int secs;
    int bisRate;
    int time;

    cin >> secs >> bisRate >> time;

    int biscuitsProd = (time/secs) * bisRate;

    cout << biscuitsProd; 

    return 0;
}

Measured memory_bytes: 256
/**
	������������ Author : Avi J Patel ������������
	������������ University : DA-IICT ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define N 100000
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define large 10000000000000001

#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
/*void calc()
{
	for(int i=0;i<2005;i++)
	{
		a[i][0]=1;
		a[i][i]=1;
		for(int j=1;j<i;j++)
		{
			a[i][j]=(a[i-1][j-1]+a[i-1][j])%MOD;	
		}
	}
}*/
int main()
{
	int n,k;
	cin>>n>>k;
	k=(2*k+1);
	//cout<<k<<endl;
	int r=n/k;
	if(n%k)
	r++;
	cout<<r;
	return 0;
}









Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (t, x) = get!(f64, f64);
    println!("{}", t / x);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=3009;
const ll mod=1e9+7;
int main()
{
    FASTINOUT;
    ll x;
    cin>>x;
    ll p=0,m=26,cnt=0;
    while (p<x)
    {
        p+=m;
        m=m*(ll)26;
        cnt++;
    }
    vector<char>v(cnt);
    for (int i=cnt-1; i>=0; i--)
    {
        x--;
        v[i]=('a'+x%26);
        x/=26;
    }
    for (auto j:v)
        cout<<j;
    return 0;
}


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

int main(){
  double ans;
  cin >> ans;
  cout << ans*6.283185307179586232 << endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
#define MAX 100005
typedef long long ll;

vector<pair<int,int> > g[MAX];
map<pair<int,int>, int> order;
int ans[MAX] = {0};
int n;
int numColors = 0;

void solve(int current,int parent){
    int prev = 0;
    for(int i=0;i<g[current].size();i++){
        int next = g[current][i].first;

        int thisColor;
        if(i==0){
            thisColor = (parent==1) ? 2 : 1;
        }
        else{
            thisColor = prev+1;
            if(thisColor==parent)
                thisColor++;
        }
        prev = thisColor;
        ans[order[{current,next}]] = thisColor;
        numColors = max(numColors,thisColor);
        g[current][i].second = thisColor;
        solve(next,thisColor);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;

    int a[n-1],b[n-1];
    for(int i=0;i<n-1;i++){
        cin >> a[i] >> b[i];
        order[{a[i],b[i]}] = i+1;
        g[a[i]].pb({b[i],0});
    }

    solve(1,0);
    cout << numColors << "\n";
    for(int i=1;i<=n-1;i++){
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 16128
/*
 * omg.cpp
 *
 *  Created on: 2019/06/03
 *      Author: J01003
 */
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
	int a,b,c,d,e,k,z;
	cin>>a>>b>>c>>d>>e>>k;
	z=a-b;
	if(z<0){z=0-z;}
	if(z>k){cout<<":("<<endl;return 0;}
	z=a-c;
		if(z<0){z=0-z;}
		if(z>k){cout<<":("<<endl;return 0;}
		z=a-d;
			if(z<0){z=0-z;}
			if(z>k){cout<<":("<<endl;return 0;}
			z=a-e;
				if(z<0){z=0-z;}
				if(z>k){cout<<":("<<endl;return 0;}
				z=b-c;
					if(z<0){z=0-z;}
					if(z>k){cout<<":("<<endl;return 0;}
					z=b-d;
						if(z<0){z=0-z;}
						if(z>k){cout<<":("<<endl;return 0;}
						z=b-e;
							if(z<0){z=0-z;}
							if(z>k){cout<<":("<<endl;return 0;}
							z=c-d;
								if(z<0){z=0-z;}
								if(z>k){cout<<":("<<endl;return 0;}
								z=c-e;
									if(z<0){z=0-z;}
									if(z>k){cout<<":("<<endl;return 0;}
									z=d-e;
										if(z<0){z=0-z;}
										if(z>k){cout<<":("<<endl;return 0;}
	cout<<"Yay!"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main() {
	int n;
	std::cin >> n;

	int c = 0;
	c += 105 <= n ? 1 : 0;
	c += 135 <= n ? 1 : 0;
	c += 165 <= n ? 1 : 0;
	c += 189 <= n ? 1 : 0;
	c += 195 <= n ? 1 : 0;
	std::cout << c << "\n";
	return 0;
}

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

int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  if (A1 + A2 + A3 < 22)
    cout << "win" << endl;
  else
    cout << "bust" << endl;

  return 0;
}


Measured memory_bytes: 256
w = gets.chomp.split("")
count = Array.new(26,0)
w.each do |c|
  count[c.ord-'a'.ord] += 1
end
ok = true
count.each do |c|
  if c%2 != 0 then
    ok = false
    break
  end
end

puts (ok ? "Yes" : "No")


Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int R = int.Parse(Console.ReadLine());
            double a = 2 * R * Math.PI;
            Console.WriteLine(a);
        }
    }
}

//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



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

int main() {
    int N;
    vector<int> t(110000), x(110000), y(110000);
    cin >> N;
    t.at(0) = x.at(0) = y.at(0) = 0;
    for (int i = 0; i<N; i++) cin >> t.at(i+1) >> x.at(i+1) >> y.at(i+1);

    bool can = true;
    for (int i = 0; i < N; i++)
    {
        int dt = t.at(i+1) - t.at(i);
        int dist = abs(x.at(i+1)-x.at(i)) + abs(y.at(i+1)-y.at(i));
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;  
}

Measured memory_bytes: 4412
#include <stdio.h>

int main(){
    int i, n;
    int a[100];
    
    scanf("%d", &n);
    
    for(i = 0; i < n; ++i){
        scanf("%d", &a[i]);
    }
    
    for(i = n - 1; i >= 0; --i){
        printf("%d", a[i]);
        
        if(i > 0){
            putchar(' ');
        }
    }
    
    putchar('\n');
    
    return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

ll n,m;

void dkstr(vector<vector<P>>& e,ll s,vector<ll>& result){
  result.resize(0);result.resize(n+1);
  priority_queue<P,vector<P>,greater<P>> pq;
  vector<bool> vis(n+1);
  pq.push(mp(0,s));
  while(!pq.empty()){
    ll i=pq.top().second,c=pq.top().first;pq.pop();
    if(vis[i]) continue;
    vis[i]=1;result[i]=c;
    fr(j,e[i].size()) if(!vis[e[i][j].first]) pq.push(mp(c+e[i][j].second,e[i][j].first));
  }
}

int main(){
  ll s,t,u,v,a,b,mn[100010];
  vector<ll> ra,rb;
  cin>>n>>m>>s>>t;
  vector<vector<P>> ea(n+1),eb(n+1);
  fr(i,m){
    cin>>u>>v>>a>>b;
    ea[u].pb(mp(v,a));
    ea[v].pb(mp(u,a));
    eb[u].pb(mp(v,b));
    eb[v].pb(mp(u,b));
  }
  dkstr(ea,s,ra);dkstr(eb,t,rb);
  mn[n+1]=1e15;
  iFr(i,n) mn[i]=min(ra[i]+rb[i],mn[i+1]);
  Fr(i,n) cout<<1000000000000000-mn[i]<<endl;
}


Measured memory_bytes: 19396
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	s = readline() |> chomp
	t = readline() |> chomp
	k = 0
	for i in 1:length(s)
		if s[i]!=t[i]
			k += 1
		end
	end
	println(k)
end

main()

Measured memory_bytes: 158164
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int n, a[100005];

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	LL ans1 = 0, sign = 0;
	LL run = 0;
	for (int i = 0; i < n; i++) {
		run += a[i];
		if (sign == 0) {
			if (run > 0);
			else {
				ans1 += ABS(1 - run); run = 1;
			}
		}
		else {
			if (run < 0);
			else {
				ans1 += ABS(-1 - run); run = -1;
			}
		}
		sign ^= 1;
	}
	LL ans2 = 0; sign = 1;
	run = 0;
	for (int i = 0; i < n; i++) {
		run += a[i];
		if (sign == 0) {
			if (run > 0);
			else {
				ans2 += ABS(1 - run); run = 1;
			}
		}
		else {
			if (run < 0);
			else {
				ans2 += ABS(-1 - run); run = -1;
			}
		}
		sign ^= 1;
	}

	LL ans = MIN(ans1, ans2);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {


	int N, i;
	scanf("%d%d", &N, &i);

	printf("%d", N - i + 1);

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;

  re(i, n + 1) {
    if ((int)(i * 1.08) == n) {
      cout << i << endl;
      return 0;
    }
  }

  cout << ":(" << endl;

  return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pdd;


int main() {
    ll n;
    ll mod =1000000007;
    cin>>n;
    vector<ll> cap(n);
    rep(i,n) cin>>cap[i];
    ll ans=1;
    ll a=0,b=0,c=0;
    rep(i,n){
        ll k=cap[i];
        if(a==k&& b==k&&c==k){ ans*=3; a++;}
        else if(b==k&&c==k){ans*=2; b++;}
        else if(a==k&&b==k){ans*=2; a++;}
        else if(a==k){a++;}
        else if(b==k){b++;}
        else if(c==k){c++;}
        else ans=0;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
#define pr(x) cout<<x
#define prs cout<<" "
#define prn cout<<"\n"
#define sc(x) cin>>x
#define ll long long int

ll w[102];
ll v[102];
ll dp[102][1000005];

ll solve(ll n, ll wt)
{
    if(n==0 || wt==0)
      return 0;
    if(dp[n][wt]!=-1)  return dp[n][wt];
    if(w[n-1] <= wt)
      return dp[n][wt] = max(v[n-1]+solve(n-1, wt-w[n-1]), solve(n-1,wt));
    else
     return  dp[n][wt] = solve(n-1,wt);
}
int main()
{
    ios :: sync_with_stdio(false); cin.tie(0);
    int t=1;
    //cin >> t;
    for(int i9 = 1; i9 <= t; i9++)
    {
        ll n, wt;
        cin>>n>>wt;
        memset(dp, -1, sizeof(dp));
        for(int i=0; i<n; i++)
          cin>>w[i]>>v[i];
        //cout<<"Cae #"<<i9<<": "<<res<<endl;
        cout<<solve(n,wt)<<endl;
    }
}

Measured memory_bytes: 797184
let () = Scanf.scanf "%d %d" @@ fun n k ->
  if (n - 1) * (n - 2) / 2 < k then
    print_endline "-1"
  else begin
    Printf.printf "%d\n" (n * (n - 1) / 2 - k);
    for v = 1 to n - 1 do
      Printf.printf "%d %d\n" v n
    done;
    let es =
      Array.of_list @@
      List.concat @@ Array.to_list @@ Array.init (n - 1) @@ fun u ->
        List.concat @@ Array.to_list @@ Array.init (n - 1) @@ fun v ->
          if v <= u then []
          else [(u + 1, v + 1)] in
    for i = 0 to (n - 1) * (n - 2) / 2 - k - 1 do
      let u, v = es.(i) in
      Printf.printf "%d %d\n" u v
    done
  end

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int vis[25][25];
char s[25][25];
int x[4] = {0, 1, 0, -1};
int y[4] = {1, 0, -1, 0};
struct node { int x, y; } q[25 * 25];
int h, w;

int Solve(int a, int b, int c, int d) {
  if (s[a][b] == '#' || s[c][d] == '#') return 0;
  memset(vis, 0, sizeof(vis));
  vis[a][b] = 1;
  int head = 1, tail = 0;
  q[++tail] = (node){a, b};
  while (head <= tail) {
    node t = q[head++];
    for (RI i = 0; i < 4; ++i) {
      if (t.x + x[i] >= 1 && t.x + x[i] <= h && t.y + y[i] >= 1 && t.y + y[i] <= w)
        if (!vis[t.x + x[i]][t.y + y[i]] && s[t.x + x[i]][t.y + y[i]] != '#')
          vis[t.x + x[i]][t.y + y[i]] = vis[t.x][t.y] + 1, q[++tail] = (node){t.x + x[i], t.y + y[i]};
    }
  }
    return vis[c][d] - 1;
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  cin >> h >> w;
  for (RI i = 1; i <= h; ++i)
    cin >> (s[i] + 1);
  int ans = 0;
  for (RI i = 1; i <= h; ++i)
    for (RI j = 1; j <= w; ++j)
      for (RI k = 1; k <= h; ++k)
        for (RI l = 1; l <= w; ++l)
          ans = max(ans, Solve(i, j, k, l));
  printf("%d\n", ans);

  return 0;
}


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

int main()
{
	std::ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    vector<long long> A;
    for (int i = 0; i < N; i++)
    {
        long long a;
        cin >> a;
        A.push_back(a);
    }
    
    vector<pair<int, int>> CB;
    for (int i = 0; i < M; i++)
    {
        int B, C;
        cin >> B >> C;
        // **************warning!!!!!!!!**********
        CB.push_back(make_pair(C, B));
    }
    sort(CB.begin(), CB.end());
    reverse(CB.begin(), CB.end());

    int numPushBack = N;
    for(auto cb: CB)
    {
        for (int i = 0; i < cb.second; i++)
            A.push_back(cb.first);
        numPushBack -= cb.second;
        if (numPushBack < 0)
            break;
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    long long ans = 0;
    for (int i = 0; i < N; i++)
        ans += A[i];
    cout << ans << endl;
   	return 0;
}

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

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

  vector<int> a(n);
  for (auto &i : a) {
    cin >> i;
    --i;
  }
  a.push_back(-1);

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == i) {
      ans++;
      swap(a[i], a[i + 1]);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
    int a[13];
    for(int i=0;i<13;i++){
        a[i]=0;
    }
    a[4] = a[6]= a[9] = a[11] = 1;
    a[2] = 2;
    int x,y;
    cin>>x>>y;
    if(a[x] == a[y]){
        cout<<"Yes"<<endl;
        return 0;

    }else{
        cout<<"No"<<endl;

    }
}

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

int main() {
 int n,d,a;
  cin >> n >> d;
  a=n/(2*d+1);
  if(n%(2*d+1)==0){
   cout << a << endl; 
  }
  else{
  cout << a+1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  vector<int> vec(x);
  for (int i = 0; i < x; i++) {
    cin >> vec[i];
  }
  int ans = 10000000;
  for (int i = -100; i < 101; i++) {
    int cnt = 0;
    for (int j = 0; j < x; j++) {
      cnt += abs(vec[j] - i) * abs(vec[j] - i);
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long h, n;
long a[1005], b[1005];
long dp[1003][10004];//[n][h]

int main(){
    scanf("%ld%ld", &h, &n);
    for(int i = 1; i <= n; i++){
        scanf("%ld%ld", a+i, b+i);
    }
    for(int i = 0; i <= h; i++){
        dp[0][i] = LINF;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= h; j++){
            if(j <= a[i]){
                dp[i][j] = std::min(dp[i-1][j], b[i]);
            }else{
                dp[i][j] = std::min(dp[i-1][j], dp[i][j-a[i]] + b[i]);
            }
            //printf("%2ld ", dp[i][j]);
        }
        //printf("\n");
    }
    printf("%ld\n", dp[n][h]);
}


Measured memory_bytes: 78464
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
char A[1100];
char B[110];
char w[20][10]={
"yocto","zepto","ato","femto","pico","nano","micro","milli","centi","deci",
"deca","hecto","kilo","mega","giga","tera","peta","exa","zetta","yotta"
};
int s[]={
-24,-21,-18,-15,-12,-9,-6,-3,-2,-1,1,2,3,6,9,12,15,18,21,24
};
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%s%s",A,B);
		int at=0;
		for(int i=0;i<20;i++){
			bool ok=true;
			for(int j=0;B[j]||w[i][j];j++){
				if(B[j]!=w[i][j])ok=false;
			}
			if(ok)at=s[i];
		}
		if(at){
			scanf("%s",B);
		}
		
		for(int i=0;A[i];i++){
			if(A[i]=='.')continue;
			if(A[i]!='0'){
				int d=-1;
				for(int j=0;A[j];j++)if(A[j]=='.')d=j;
				if(d==-1)d=strlen(A);
				if(d<i)d=d-i;
				else d=d-i-1;
				d+=at;
				printf("%c",A[i]);
				if(A[i+1])printf(".");
				for(int j=i+1;A[j];j++){
					if(A[j]=='.')continue;
					printf("%c",A[j]);
				}
				printf(" * 10^%d %s\n",d,B);
				break;
			}
		}
	}
}

Measured memory_bytes: 1028
#include <stdio.h>
#define MAXLENGTH 100000
int binarySearch(int arr[],int key,int size)
{
    int left=0;
    int right=size;
    while(left<right)
    {
        int middle = (left+right)/2;
        if(key==arr[middle])
            return middle;
        else if(arr[middle]>key)
            right = middle;
        else if(key>arr[middle])
            left=middle+1;
    }
    return -1;
}
int main() {
    int s[MAXLENGTH]={0};
    int t[MAXLENGTH]={0};
    int n, m,counter=0;
    scanf("%d", &n);
    for(int i=0;i<n;i++){scanf("%d", &s[i]);}
    scanf("%d", &m);
    for(int i=0;i<m;i++){scanf("%d", &t[i]);}
    for(int i=0;i<m;i++)
    {
        int mid = binarySearch(s, t[i], n);
        if(mid!=-1)
        {
            counter++;
        }
    }
    printf("%d\n", counter);
    return 0;
}



Measured memory_bytes: 2572
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;


int main() {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	string ans = "";

	if (k == 1) {
		string t = s;
		reverse(t.begin(), t.end());
		s = s + t;
		string x = s.substr(0, n);
		for (int i = 1; i < n; i++) {
			string y = s.substr(i, n);
			if (x > y) {
				x = y;
			}
		}
		ans = x;
	}
	else {
		string t = s;
		reverse(t.begin(), t.end());
		s = s + t;
		string x = s.substr(0, n);
		reverse(x.begin(), x.end());
		for (int i = 1; i <= n; i++) {
			string y = s.substr(i, n);
			reverse(y.begin(), y.end());
			if (x > y) {
				x = y;
			}
		}
		int tmp = 1;
		for (int i = 1; i < x.size(); i++) {
			if (x[i] == x[i - 1]) {
				tmp++;
			}
			else {
				break;
			}
		}

		string check = x.substr(tmp, x.size());//末尾にくっつけるやつ
		string answer = x.substr(0, tmp);//文字列最小のもの、これが2倍,4倍となる

		int kk = k;

		while (--kk&&answer.size()<n) {
			answer = answer + answer;
		}
		answer = answer + check;
		ans = answer.substr(0, n);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
using namespace std;

int N;
int W;
int ans;
int v[100];
int w[100];
int dp[101][10001];

//dp[n][m] = max(dp[n-1][m - k * w[n]] + k*v[n]

int main() {
    scanf("%d%d", &N, &W);
    for (int i=0; i<N; i++) {
        scanf("%d%d", &v[i], &w[i]);
    }

    for (int i=0; i<N; i++) {
        for (int j=0; j<=W; j++) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
            
        for (int j=0; j<=W; j++) {
            if (j + w[i] <= W) {
                dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i+1][j]+v[i]);
            }
        }
    }

    for (int i=0; i<=W; i++) {
        ans = max(ans, dp[N][i]);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 4936
#include<stdio.h>
#include<string.h>
int main(){
	int n,m;
	char a[105];
	while(~scanf("%d",&n))
	{
		scanf("%s",a);
			m=0;
		if(n%2!=0)
		printf("No\n");
		else
		{
			for(int i=n/2,j=0;i<n;i++,j++)
			{
				if(a[i]==a[j])
				m++;
			}
		if(m==n/2)
		printf("Yes\n");
		else
		printf("No\n");
		}
	}
	return 0;
}

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

int main(){
    int m, f, r;

    while(1){
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1)break;

        if (m == -1 || f == -1 || m + f <30)
        {
            cout << 'F' << endl;
        }else{
            if (m + f >=80)
            {
                cout << 'A' << endl;
            }else if (m + f < 80 && m + f >=65)
            {
                cout << 'B' << endl;
            }else if (m + f <65 && m + f >= 50)
            {
                cout << 'C' << endl;
            }else if (m + f < 50 && m + f >=30)
            {
                if (r >=50)
                {
                    cout << 'C' << endl;
                }else
                {
                    cout << 'D' << endl;
                }

            }
        
        }
}

    return 0;
    

}


Measured memory_bytes: 3096