akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#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;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

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

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy



int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);    
    
    int N; cin >> N;
    vector<vector<char> > data;
    F0R(i, N) {
		vector<char> cur(10);
		F0R(i, 10) cin >> cur[i];
		sort(all(cur)); data.pb(cur);
	}
	sort(all(data));
	ll ans = 0;
	int start = 0;
	FOR(i, 1, N) {
		if (data[start] != data[i]) {
			ll dif = i-start;
			ans += dif * (dif-1) / 2;
			start = i;
		}
	}
	ll dif = N-start;
	ans += dif*(dif-1) / 2;
	
	cout << ans << endl;
    
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 6964
N = int(input())
A = [int(i) for i in input().split()]
Asum = [0]
for i in range(N):
    Asum.append(Asum[i] + A[i])

left, right = 0, 2
Ans = float("inf")
for i in range(1, N-2):
    B = Asum[left+1]-Asum[0]
    C = Asum[i+1] - Asum[left+1]
    while left < i-1:
        if abs(C-B) > abs(C-B-2*A[left+1]):
            left += 1
            B += A[left]
            C -= A[left]
        else:
            break
    if i == right:
        right = i+1
    D = Asum[right+1] - Asum[i+1]
    E = Asum[N] - Asum[right+1]
    while right < N-2:
        if abs(E-D) > abs(E-D-2*A[right+1]):
            right += 1
            D += A[right]
            E -= A[right]
        else:
            break
    Ans = min(Ans, max(B, C, D, E) - min(B, C, D, E))
print(Ans)

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

int main() {
  int N,M;
  cin >> N >> M;
  
  if(N == 1){
    long long A;
    cin >> A;
    for(int i=0;i<M;i++){
      A /= 2;;
    }
    cout << A << endl;
  }else{
    long long b;
  
    std::priority_queue<long long> A;
    for(int i=0;i<N;i++){
      cin >> b;
      A.push(b);
    }
    for(int i=0;i<M;i++){
      b = A.top();
      A.pop();
      b /= 2;
      A.push(b);
    }
    long long price = 0;
    for(int i=0;i<N;i++){
      b = A.top();
      price += b;
      A.pop();
    }
    cout << price << endl;
  
  }
}


Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 200000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

int solve(int num,int mod){
  int sum=0;
  while(num){
    int dig=num%mod;
    sum+=dig;
    num=floor(num/mod);
  }
  return sum;
}

signed main(){
  int n,s; cin>>n>>s;
  
  if(n<s){
    cout<<-1<<en;
    RE;
  }else if(n==s){
    cout<<n+1<<en;
    RE;
  }
  for(int i=2; i*i<=n; i++){
    int ret=solve(n, i);
    if(ret==s){
      cout<<i<<en;
      RE;
    }
  }
  int ans=INF;
  for(int i=1; i*i<n; i++){
    if((n-s)%i) continue;
    if(solve(n, (n-s)/i+1)==s){
      ans=min(ans,(n-s)/i+1);
    }
  }
  if(ans==INF) cout<<-1<<en;
  else cout<<ans<<en;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <cstdlib>
#define PI acos(-1.0)
#define ll long long int
#define db double
#define ull unsigned long long int
#define Fill(x,y) memset(x,y,sizeof(x))
#define bug printf("!!!!!!\n");
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define sz(a) (int)(a).size()
using namespace std;
const db eps = 1e-6;
const int inf = 0x3f3f3f3f; //用这个可以直接mem
const ll INF = 1e18;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int cas=1;
int a[maxn];
bool cmp(int a, int b) {
    return a > b;
}
void solve()
{
    int n, k;
    cin >> n >> k;
    for (int i = 1 ; i <= n ; i ++) {
        int x; cin >> x ;
        a[x]++;
    }
    sort(a+1, a+1+n, cmp);
    int ans = 0;
    for (int i = k + 1 ; a[i] ; i ++) ans+=a[i];
    cout << ans << endl;
}
int main()
{
   //  freopen("in.txt","r",stdin);
    //  freopen("out.txt","w",stdout);
    int t = 1 ;
    //scanf("%d",&t);
    while(t--){
       // printf("Case %d: ", cas++);
        solve();
        //printf("\n");
    }
}









Measured memory_bytes: 1024
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

struct UFTree(T)
{
    struct Node
    {
        T parent;
        T rank = 1;
    }

    ///
    this(T n)
    {
        nodes.length = n;
        sizes.length = n;
        foreach (i, ref node; nodes) {
            node = Node(i.to!T);
            sizes[i] = 1;
        }
    }

    ///
    bool unite(T a, T b)
    {
        a = root(a);
        b = root(b);

        if (a == b) return false;

        if (nodes[a].rank < nodes[b].rank) {
            sizes[nodes[a].parent] += sizes[nodes[b].parent];
            nodes[b].parent = nodes[a].parent;
        } else {
            sizes[nodes[b].parent] += sizes[nodes[a].parent];
            nodes[a].parent = nodes[b].parent;
            if (nodes[a].rank == nodes[b].rank) nodes[a].rank += 1;
        }

        return true;
    }

    ///
    bool is_same(T a, T b)
    {
        return root(a) == root(b);
    }

    ///
    T size(T i)
    {
        return sizes[root(i)];
    }

    T size()
    {
        bool[T] memo;
        foreach (node; this.nodes) {
            memo[root(node.parent)] = true;
        }
        T cnt;
        foreach (_; memo) ++cnt;
        return cnt;
    }

    Node[] nodes;
    T[] sizes;

    T root(T i)
    {
        if (nodes[i].parent == i) return i;

        return nodes[i].parent = root(nodes[i].parent);
    }
}

///
UFTree!T uftree(T)(T n)
{
    return UFTree!T(n);
}

alias Cost = Tuple!(int, "i", long, "a");
Cost[10^^5] CS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];

    foreach (i, a; readln.split.to!(long[])) {
        CS[i] = Cost(i.to!int, a);
    }
    sort!"a.a < b.a"(CS[0..N]);

    auto uftree = uftree(N);

    foreach (_; 0..M) {
        auto xy = readln.split.to!(int[]);
        uftree.unite(xy[0], xy[1]);
    }

    if (uftree.size() == 1) {
        writeln(0);
        return;
    }

    int[int] PS;
    foreach (node; uftree.nodes) {
        PS[uftree.root(node.parent)] = 0;
    }
    int max_n = -1;
    foreach (_; PS) ++max_n;

    int cnt;
    long r;
    foreach (ref c; CS[0..N]) {
        auto t = uftree.root(c.i);
        if (!PS[t]) {
            r += c.a;
            ++cnt;
            ++PS[t];
            c.a = -1;
        }
    }
    foreach (c; CS[0..N]) {
        if (cnt == max_n*2) break;
        auto t = uftree.root(c.i);
        if (c.a < 0) continue;
        ++cnt;
        r += c.a;
    }

    if (cnt == max_n*2) {
        writeln(r);
    } else {
        writeln("Impossible");
    }
}

Measured memory_bytes: 16508
#include <bits/stdc++.h>
using namespace std;
int main(){
	set<int> S; 
	int a, b, c; cin >> a >> b >> c; 
	S.insert(a); S.insert(b); S.insert(c); 
	if(S.size() == 2) cout << "Yes" << endl; 
	else cout << "No" << endl;  
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }

    
    public class Class1
    {
        static List<string> cons = new List<string>();
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int n = int.Parse(str);
            string[] n2 = Console.ReadLine().Split(' ');

            bool initialvalidation = true;
            int? a = null;
            int? b = null;
            int? c = null;
            int ac = 0;
            int bc = 0;
            int cc = 0;

            for(int i=0; i<n; i++)
            {
                var nn = Int32.Parse(n2[i]);
                if (nn > 0) initialvalidation = false;

                if (a == null)
                {
                    a = nn;
                    ac = 1;
                }
                else if (a == nn)
                {
                    ac++;
                }
                else if (b == null)
                {
                    b = nn;
                    bc = 1;
                }
                else if(b == nn)
                {
                    bc++;
                }
                else if (c == null)
                {
                    c = nn;
                    cc = 1;
                }
                else if (c == nn)
                {
                    cc++;
                } else
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            if (initialvalidation)
            {
                Console.WriteLine("Yes");
                return;
            }

            if ( c == null)
            {
                if ((a == 0 && bc == ac * 2) || (b == 0 && ac == bc * 2))
                {
                    Console.WriteLine("Yes");
                } else
                {
                    Console.WriteLine("No");
                }
                return;
            }

            if (b == null || c == null
                || ac != bc || bc != cc || ac != cc
                || !calc(a.Value, b.Value, c.Value) )
            {
                Console.WriteLine("No");
                return;
            }
            Console.WriteLine("Yes");
        }


        static bool calc( int a, int b, int c)
        {
            while(true)
            {
                if (a == 0 && b == 0 && c == 0) return true;
                var a2 = a % 2;
                a = a / 2;
                var b2 = b % 2;
                b = b / 2;
                var c2 = c % 2;
                c = c / 2;

                if ((a2 + b2 + c2) % 2 != 0) return false;
            }

        }
    }


}


Measured memory_bytes: 19552
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(double x){
  printf("%.15f",x);
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int X[100000];
int Y[100000];
char D[100000];
char buf[10];
double gt(double t){
  double x, x1, x2, y, y1, y2;
  int i;
  x1 = y1 = 1e300;
  x2 = y2 = -5076944270305263616LL;
  for(i=0;i<N;i++){
    x = X[i];
    y = Y[i];
    if(D[i]=='R'){
      x += t;
    }
    if(D[i]=='L'){
      x -= t;
    }
    if(D[i]=='U'){
      y += t;
    }
    if(D[i]=='D'){
      y -= t;
    }
    chmin(x1, x);
    chmax(x2, x);
    chmin(y1, y);
    chmax(y2, y);
  }
  return (x2-x1) * (y2-y1);
}
int main(){
  double res, s1, s2, t1, t2, x, y;
  int Lj4PdHRW, i, j, k;
  rd(N);
  for(i=0;i<N;i++){
    rd(X[i]);
    rd(Y[i]);
    rd(buf);
    D[i] = buf[0];
  }
  res = 1e300;
  x = 0;
  y = 10000000000LL;
  for(Lj4PdHRW=0;Lj4PdHRW<300;Lj4PdHRW++){
    s1 = (x+x+y) / 3;
    s2 = (x+y+y) / 3;
    t1 = gt(s1);
    t2 = gt(s2);
    chmin(res, t1);
    chmin(res, t2);
    if(t1 < t2){
      y = s2;
    }
    else{
      x = s1;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190609-2 [beta]

// --- original code ---
// int N, X[1d5], Y[1d5]; char D[1d5], buf[10];
// 
// double gt(double t){
//   int i;
//   double x1, x2, y1, y2, x, y;
//   x1 = y1 = 1e300;
//   x2 = y2 = -1d300;
// 
//   rep(i,N){
//     x = X[i];
//     y = Y[i];
//     if(D[i]=='R') x += t;
//     if(D[i]=='L') x -= t;
//     if(D[i]=='U') y += t;
//     if(D[i]=='D') y -= t;
//     x1 <?= x;
//     x2 >?= x;
//     y1 <?= y;
//     y2 >?= y;
//   }
// 
//   return (x2-x1) * (y2-y1);
// }
// 
// {
//   int i, j, k;
//   double x, y, s1, s2, t1, t2, res;
//   
//   
//   rd(N);
//   rep(i,N){
//     rd(X[i], Y[i], buf);
//     D[i] = buf[0];
//   }
// 
//   res = 1e300;
//   x = 0; y = 1d10;
//   rep(300){
//     s1 = (x+x+y) / 3;
//     s2 = (x+y+y) / 3;
//     t1 = gt(s1);
//     t2 = gt(s2);
//     res <?= t1;
//     res <?= t2;
//     if(t1 < t2) y = s2; else x = s1;
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main(){
  long long n;
  cin>>n;
  int ans=0;
  if(n<10){
    cout<<n<<endl;
    return 0;
  }else if(10<=n&&n<100){
    cout<<9<<endl;
    return 0;
  }else if(100<=n&&n<1000){
    cout<<9+n-99<<endl;
  }else if(1000<=n&&n<10000){
    cout<<909<<endl;
  }else if(10000<=n&&n<100000){
    cout<<909+n-9999<<endl;
  }else{
    cout<<90909<<endl;
  }
  return 0;
}

    


Measured memory_bytes: 256
N = int(input())
*A, = map(int, input().split())

Asum = [a for a in A]
for i in range(N-1, -1, -1):
    Asum[i] += Asum[i+1]

ans = 0
v = 1  # 子になれる頂点数
for i in range(N+1):
    if v < A[i]:
        ans = -1
        break

    ans += v
    p = v-A[i]
    if i < N:
        v = min(Asum[i+1], 2*p)

print(ans)


Measured memory_bytes: 86524
def R(S):
    return "".join(reversed([c for c in S]))

def solve(S):
    l = len(S)
    if not S == R(S):
        return False
    if not S[0: (l - 1) // 2] == R(S[0: (l - 1) // 2]):
        return False
    if not S[(l - 1) // 2 + 1:] == R(S[(l - 1) // 2 + 1:]):
        return False

    return True

def main():
    if solve(input()):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e16;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){

  int N, M; cin >> N >> M;

  vector < vector<int> > graph(3 * N);
  for (int i = 0; i < M; i++){
    int u, v; cin >> u >> v;
    u--; v--;
    graph[3 * u].push_back(3 * v + 1);
    graph[3 * u + 1].push_back(3 * v + 2);
    graph[3 * u + 2].push_back(3 * v);
  }

  int S, T; cin >> S >> T; S--; T--;
  S *= 3; T *= 3;

  priority_queue < pair<int, int>, vector<pair<int, int> > , greater<pair<int, int> > > que;
  vector <bool> visited(3 * N);
  vector <int> dist(3 * N);
  fill(dist.begin(), dist.end(), -1);
  dist[S] = 0;
  que.push(make_pair(0, S));

  int C = 0;
  while (!que.empty()){
    pair<int, int> P = que.top(); que.pop();
    int D = P.first, start = P.second;
    if (visited[start] == false){
      visited[start] = true;
      dist[start] = D;
      if (start == T) break;      
      for (int i = 0; i < graph[start].size(); i++){
        int next = graph[start][i];
        if (visited[next] == false){
          que.push(make_pair(D + 1, next));
        }
      }
    }
  }
  
  if (dist[T] == -1){
    cout << -1 << endl;
  }else{
    cout << dist[T] / 3 << endl;
  }
   

  return 0;
}


Measured memory_bytes: 17920
object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)

    var a = 0
    for(_ <- 1 to scanner.nextInt) {
      val x = scanner.nextDouble
      if((2 to math.sqrt(x).toInt).find(x % _ == 0).isEmpty) a = a + 1
    }
    println(a)
  }
}



Measured memory_bytes: 155836
#include<iostream> 
#include<vector> 
#include<algorithm> 
using namespace std; 
#define lld long long int
#define X 1000000007
#define fast();  ios_base::sync_with_stdio(false); cin.tie(0);
# define rec(i,n) for(int i=0;i<n;i++) 
#define w(t) int t; cin>>t; while(t--)
int main()
{
    fast(); 

    int n; 
    int flag=0; 
    cin>>n; 
    while(n) 
    { if(n%10==7) 
        flag=1; 
        n=n/10; 
    } 
    if(flag) 
    cout<<"Yes"<<endl; 
    else 
    cout<<"No"<<endl; 
    
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
int n;
int a[nax];

int main() {
    scanf("%d", &n);

    int64_t tot = 0;

    for (int i = 1 ; i <= n ; ++ i) {
        scanf("%d", &a[i]);
        if (i > 1 && a[i] < a[i - 1]) {
            tot += abs(a[i] - a[i - 1]);
        }

        a[i] = max(a[i], a[i - 1]);
    }

    printf("%lld\n", tot);
}



Measured memory_bytes: 4592
using System;
using System.Linq;
class A{
  static void Main(){
    var s = Console.ReadLine();
    var t = Console.ReadLine();
    var n = s.Length;
    for (var i=0;i<n;i++)
    {
      var ok = true;
      for (var j=0;j<n;j++)
        ok &= s[j]==t[(j+i)%n];
      if (ok){Console.WriteLine("Yes");return;}
    }
    Console.WriteLine("No");
  }
}


Measured memory_bytes: 13140
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {

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

	string s;
	int n, k;
	cin >> n >> k;
	cin >> s;

	s[k-1] += 32;

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <utility>
#include <string>
#include <queue>
#include <cmath>
#include <array>

typedef long long ll;

ll solve(const std::string s)
{
    const int n = s.length();
    ll ans = 0;

    std::vector<int> r, g, b;
    r.reserve(4000);
    g.reserve(4000);
    b.reserve(4000);

    for (int i = 0; i < n; i++) {
        switch(s[i]) {
            case 'R':
                r.push_back(i);
                break;
            case 'G':
                g.push_back(i);
                break;
            case 'B':
                b.push_back(i);
                break;
            default:
                return -1;
        }
    }

    const int r_n = r.size();
    const int g_n = g.size();
    const int b_n = b.size();

    for (int r_p = 0; r_p < r_n; r_p++) {
        const int i = r[r_p];

        for (int g_p = 0; g_p < g_n; g_p++) {
            const int j = g[g_p];

            const int ij_min = std::min(i, j);
            const int ij_max = std::max(i, j);
            //const int ij_min = (i>j)?j:i;
            //const int ij_max = i + j - ij_min;

            for (int b_p = 0; b_p < b_n; b_p++) {
                const int k = b[b_p];

                const int a = std::min(ij_min, k);
                const int c = std::max(ij_max, k);
                //const int a = (ij_min>k)?k:ij_min;
                //const int c = (ij_max>k)?ij_max:k;
                const int b = i + j + k - a - c;

                if (b - a != c - b) {
                    ans++;
                }
            }
        }
    }

    return ans;
}

int main(int argc, char *argv[])
{
    int n;
    std::string s;

    std::cin >> n;
    std::cin >> s;

    ll ans = solve(s);

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
int main()
{
    int res;
    char s[100] ;
    gets(s) ;
    res=strcmp(s,"ABC") ;
    if(res==0)
        //cout<<"ARC"<<endl ;
        printf("ARC\n");
    else if(res!=0)
        printf("ABC\n");

    return 0;

}


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

int main(){
	int n, p, d1, d2, ap, ad;

	while(cin>>n, n){
		ap=ad=-1;
		while(n--){
			cin>>p>>d1>>d2;
			if(ad<d1+d2)ap=p, ad=d1+d2;
		}
		printf("%d %d\n", ap, ad);
	}
	return 0;
}

Measured memory_bytes: 1136
#include <bits/stdc++.h>
using namespace std;
int main (){
  int n;
  cin>>n;
  int i=1,c=1,d=1;
  bool a=0;
  for(i=2;i*i<=n;i++){
    d=1;
    while(a==0){
      if(d*i>n)
        a++;
      else
      d*=i;
    }
    a=0;
    c=max(c,d);
    d=1;
  }
  cout<<c;
  return 0;
}



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

int main(){
    double x1, x2;
    double y1, y2;
    double ans;
    
    scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
    
    ans = sqrt( (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
    
    printf( "%lf\n", ans );
    return 0;
}


Measured memory_bytes: 2060
n = int(input())
p = list(map(int,input().split()))
count=0

for i in range(0,n-2):
    #print(i)
    p_list=[p[i],p[i+1],p[i+2]]
    #print(p_list)
    p_sorted=sorted(p_list)
    #print(p_sorted)
    if p_list[1]==p_sorted[1]:
        count+=1

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
    int n,C; cin>>n>>C;
    int D[30][30];
    VE v[3];
    FOR(i,0,C) FOR(j,0,C) cin>>D[i][j];
    FOR(i,0,n){
        FOR(j,0,n){
            int c; cin>>c;
            v[(i+j)%3].PB(c-1);
        }
    }
    
    int iwakan[3][30]={};
    FOR(k,0,3){
        FOR(i,0,C){
            FOR(j,0,v[k].size()){
                iwakan[k][i]+=D[v[k][j]][i];
            }
        }
    }
    int ans=INF;
    FOR(i,0,C){
        FOR(j,0,C){
            FOR(k,0,C){
                if(i!=j&&j!=k&&k!=i){
                    ans=min(ans,iwakan[0][i]+iwakan[1][j]+iwakan[2][k]);
                }
            }
        }
    }
    co(ans);
}


Measured memory_bytes: 1520
#include <bits/stdc++.h>
#define maxi 1000001
using namespace std;
struct trie
{
    int l;
    int r;
    int idx;
};
void updatr(vector<int> &bits,int val, int id, int n)
{
    
    while(id<=n)
    {
        bits[id]+=val;
        id += (id&-id);
    }
}
int getsum(vector<int> &bits, int id, int n)
{
    int sum=0;
    
    while(id>0)
    {
        sum += bits[id];
        id -= (id&(-id));
    }
    return sum;
}
void findr(vector<int> arr,vector<trie> q, int n,int qc)
{
    vector<int> bits(n+1,0);
    vector<int> first(maxi,-1);
    vector<int> ans(qc);
    int qi=0;
    for(int i=0;i<n;i++)
    {
        
        if(first[arr[i]]!=-1)
        updatr(bits,-1,first[arr[i]]+1,n);
        first[arr[i]]=i;
        updatr(bits,1,i+1,n);
        
        while(qi<qc && q[qi].r==i)
        {
            //cout<<1<<endl;
            ans[q[qi].idx] = getsum(bits,q[qi].r+1, n) - getsum(bits,q[qi].l, n);
            qi++;
        }
    }
    
    for(int i=0;i<qc; i++)
    {
        
        cout<<ans[i]<<endl;
    }
}
bool cmp(trie a , trie b)
{
    return a.r<b.r;
}
int main() {
    int n,q;
    cin>>n>>q;
    vector<int> arr(maxi);
    for(int i=0;i<n;i++)
    {
       
        cin>>arr[i];
    }
    vector<trie> v(q);
    for(int i=0;i<q;i++)
    {
        cin>>v[i].l>>v[i].r;
        v[i].idx=i;
        v[i].l--;
        v[i].r--;
    }
    sort(v.begin(),v.end(),cmp);
    findr(arr,v, n,q);
    //vector<int> freq(maxi);
    return 0;
}


Measured memory_bytes: 31112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int main(){
	int N,D,x,p_[10][10];
	cin>>N>>D>>x;
	rep(i,D) rep(j,N) cin>>p_[i][j];
	rep(i,D-1){
		int dp[100001]={};
		rep(j,N){
			int p=p_[i][j],q=p_[i+1][j];
			for(int k=x;k>=p;k--) chmax(dp[k-p],dp[k]+q);
		}
		int tmp=0;
		rep(j,x+1) chmax(tmp,j+dp[j]);
		x=tmp;
	}
	cout<<x<<endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll x2 = 0;
  rep(i,n) {
    if (i%2) x2 -= a[i];
    else x2 += a[i];
  }
  vector<int> ans(n);
  ans[0] = x2/2;
  rep(i,n-1) {
    ans[i+1] = a[i]-ans[i];
  }
  rep(i,n) ans[i] *= 2;
  rep(i,n) printf("%d%c", ans[i], i==n-1?'\n':' ');
  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(x...)
#endif
#define endl "\n"
#define int long long int
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define loop(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7;

void solving() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	bool ans[1000005] {};
	memset(ans, false, sizeof(ans));
	// }
	for (int i = 0; i < n; i++) {
		if (i > 0) {
			if (a[i] == a[i - 1]) {
				ans[a[i]] = true;
				continue;
			}
		}

		for (int j = 2 * a[i]; j < 1000005; j += a[i]) {
			ans[j] = true;
		}
	}
	int c = 0;
	for (int i = 0; i < n; i++) {
		if (ans[a[i]] == false) {
			c++;
		}
	}
	cout << c << endl;
}

int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// int t{}; cin >> t; while (t--)
	solving();
	return 0;
}

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

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

int main(){
    int limit = pow(10, 9) + 7;
    int N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    vector<ll> sum(N+1, 0);
    for(int i = 1; i < N+1; i++){
        sum[i] = sum[i-1] + a[i-1];
    }

    ll ans = 0;
    rep(i, N-1){
        ans = (ans + (((sum[N] - sum[i+1]) % limit) * a[i]) % limit) % limit;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6368
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var kn = Console.ReadLine().Split();
            var around = int.Parse(kn[0]);
            var time = int.Parse(kn[1]);
            var data = Console.ReadLine().Split(' ');
            var nums = new int[time];
            var max = 0;
            for(int i = 0; i < time; i++)
            {
                nums[i] = int.Parse(data[i]);
            }
            for(int i = 0; i < time - 1; i++)
            {
                max = Math.Max(max, nums[i + 1] - nums[i]);
            }
            max = Math.Max(max, around - nums[time - 1] + nums[0]);
            Console.WriteLine(around - max);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 36188
<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}

/*		START		*/
$N = getq();
$S = getq();
$ARRAY = array();
$ans=array();
for ($i=0; $i < strlen($S); $i++)
	if(array_search($S[$i],$ARRAY)===false)array_push($ARRAY,$S[$i]);
for ($i=1; $i < strlen($S); $i++) {
	$front = substr($S,0,$i);
	$end = substr($S,$i,strlen($S)-$i);
	//echo "$front $end \n";
	$count=0;
	foreach ($ARRAY as $stm) {
		if(strpos($front,$stm) !==false && strpos($end,$stm)!==false){
			$count++;
		}
	}
	array_push($ans,$count);
}
echo max($ans)."\n";
//print_r($ARRAY);
?>


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  char a,b; cin>>a>>b;
  string s=string(b-'0',a);
  string t=string(a-'0',b);
  if(s>t) cout<<t<<endl;
  else cout<<s<<endl;
}

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

int num[MAX];
int rtime[MAX];

void bubble_sort(int n){

  for( int i = 0 ; i < n - 1 ; i++ ){
    for( int j = n - 1 ; j > i ; j-- ){
      if( rtime[j - 1] > rtime[j] ){

	int temp = rtime[j - 1];
	rtime[j - 1] = rtime[j];
	rtime[j] = temp;

	temp = num[j - 1];
	num[j - 1] = num[j];
	num[j] = temp;

      }
    }
  }

}


int main(void){

  int n;
  while( cin >> n , n ){

    int m1,s1,m2,s2,m3,s3,m4,s4;
    for( int i = 0 ; i < n ; i++ ){
      cin >> num[i] >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      rtime[i] = m1*60 + s1 + m2*60 + s2 + m3*60 + s3 + m4*60 + s4;
    }
    bubble_sort(n);

    cout << num[0] << endl;
    cout << num[1] << endl;
    cout << num[n - 2] << endl;

  }
  return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, D;
ll i,j,ans;
int main(){
    scanf("%lld%lld", &N,&D);
    printf("%lld", (N - 1) / (D * 2 + 1) + 1);

    return 0;
}

Measured memory_bytes: 256
MAX = 120 * 60

def print_remaining_time(diff)
  min, ans_second = diff.divmod(60)
  ans_hour, ans_minite = min.divmod(60)

  printf "%02d:%02d:%02d\n", ans_hour, ans_minite, ans_second
end

readlines.each do |line|
  t, h, s = line.chomp.split.map(&:to_i)
  break if t == -1 && h == -1 && s == -1

  second = t * 60 * 60 + h * 60  + s

  print_remaining_time(MAX - second)
  print_remaining_time((MAX - second) * 3)
end

Measured memory_bytes: 8556
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll k=(min(b,d)-max(a,c));
        if(k<=0)
        cout<<"0";
        else
        cout<<k;
    } 
    return 0;
}


Measured memory_bytes: 3612
# -*- coding: utf-8 -*-

import numpy as np

def solve():
    N = int(input())
    A = np.array(list(map(int,input().split())))
    B = np.array(list(map(int,input().split())))
    if A.sum() < B.sum():
        res = -1
    else:
        C = B-A
        d = np.maximum(C,0).sum()
        M = np.minimum(np.maximum(C,0),1).sum()
        C.sort()
        for c in C:
            if d <= 0:
                break
            d += c
            M += 1
        res = M
    return str(res)

if __name__ == '__main__':
    print(solve())

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;

typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,k;
    cin >> n >> k;

    if (n+1 >= k*2) {
        cout << "YES" << "\n";
    } else {
        cout << "NO" << "\n";
    }
    return 0;
}

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

int main(){
 int A,B,C,d,e;
  cin>>A>>B>>C;
  d=A%B;
  e=d;
  for(int i=0;i<100;i++){
    if(e==C){
      cout<<"YES"<<endl;
      return 0;
    }
    e+=d;
    e%=B;
  }
     
  cout<<"NO"<<endl;
}


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


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        long[]a=new long[n];
        long x=0;
        int[]c=new int[31];
        for(int i=0;i<n;++i){
            a[i]=sc.nextLong();
            x^=a[i];
            c[Long.bitCount((a[i]&-a[i])-1)]++;
        }
        int ans=0;
        for(int i=30;i>=0;--i)
            if((x&1<<i)!=0)
                if(c[i]>0){
                    x^=(1<<(i+1))-1;
                    ans++;
                }else
                    break;
        out.println(x==0?ans:-1);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 38664
#include<iostream>
#include<algorithm>


using namespace std;

int main(void)
{
	int n;
	cin>>n;
	
	int a[n];
	
	int i;
	for(i=0; i<n; i++)
	{
		cin>>a[i];
	}
	
	
	sort(a,a+n);
	
	
	cout<<a[n-1]-a[0];
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int main() {
	int a, b, t;
	std::cin >> a >> b >> t;

	std::cout << t / a * b << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  LL n,m; cin>>n>>m;
  vector<LL> v(m);
  forn(i,m) cin>>v[i];
  LL an = 0;
  forn(i,m) an+=v[i];
  cout<<((n>=an?n-an:-1))<<endl;

  return 0;
}


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

int main(){
  int a = 0, b = 0, c = 0, d = 0, n; cin >> n;
  rep(i, n){
    string s; cin >> s;
    if(s == "AC") ++a;
    else if(s == "WA") ++b;
    else if(s == "TLE") ++c;
    else if(s == "RE") ++d;
  }
  cout << "AC x " << a << "\n";
  cout << "WA x " << b << "\n";
  cout << "TLE x " << c << "\n";
  cout << "RE x " << d << "\n";
  return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1000000000000007ll;

const double eps = 1e-10;

const i64 MAXN = 100005;

i64 n;

i64 a[MAXN];
i64 b[MAXN];

i64 sa[MAXN];
i64 sb[MAXN];

map<i64, i64> qa;
map<i64, i64> qb;

i64 u[MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n;

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

    for (i64 i = 0; i < n; i++) {
        cin >> b[i];
        sb[i] = b[i];
    }

    sort(sa, sa + n);
    sort(sb, sb + n);


    bool f = true;
    for (i64 i = 0; i < n; i++) {
        if (sa[i] > sb[i]) {
            f = false;
            break;
        }
    }

    if (!f) {
        cout << "No" << endl;
        return 0;
    }

    i64 g = false;
    for (i64 i = 1; i < n; i++) {
        if (sa[i] <= sb[i - 1] && sa[i - 1] <= sb[i]) {
            g = true;
            break;
        }
    }

    if (g) {
        cout << "Yes" << endl;
        return 0;
    }

    for (i64 i = 0; i < n; i++) {
        qa[sa[i]] = i;
        qb[sb[i]] = i;
    }

    for (i64 i = 0; i < n; i++) {
        a[i] = qa[a[i]];
        b[i] = qb[b[i]];
    }

    for (i64 i = 0; i < n; i++) {
        qa[a[i]] = i;
        qb[b[i]] = i;
    }


    i64 j = 0;
    for(;;){
        if (u[j]) {
            break;
        }
        u[j] = 1;
        j = a[qb[j]];
    } 

    i64 R = 0;
    for (i64 i = 0; i < n; i++) {
        R += u[i];
    }

    if (R < n) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 27904
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

const int N = 2e5+10;
int n, h[N], a[N], vh[N], id[N], last[N];
ll len[N], ans = 0;
set<int> s;

ll rec(int curh) {
	return (curh == 0 || len[curh] != 0) ? len[curh] : len[curh] = vh[curh]+rec(last[curh]);
}

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    cin >> n;
    FOR(i, 1, n) cin >> h[i];
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) vh[h[i]] = a[i];
    s.insert(0);
    FOR(i, 1, n) {
    	int curh = h[i];
    	auto itr = s.lower_bound(curh);
    	--itr;
    	last[curh] = *itr;
    	rec(curh);
    	ans = max(ans, len[curh]);
    	++itr;
    	while(itr != s.end() && len[*itr] <= len[curh]) {
    		auto temp = itr++;
    		s.erase(temp);
    	}
    	s.insert(curh);
    }

    cout << ans << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting min to 0 instead of -INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)


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

vector<vector<bool>> TFcombination(int n){
    vector<vector<bool>> ans(pow(2, n), vector<bool>(n));
    for(int i = 0; i < (1 << n); i++){
        for(int j = 0; j < n; j++){
            ans[i][j] = i >> j & 1;
        }
    }
    return ans;
}

int main(){
    string s;
    cin >> s;
    int len = s.size();
    vector<vector<bool>> isPlus = TFcombination(len - 1);
    ll ans = 0;
    for(auto x : isPlus){
        ll tmp = 0;
        for(int i = 0; i < len; i++){
            tmp += s[i] - '0';
            if(i == len - 1) break;
            if(x[i]){
                ans += tmp;
                tmp = 0;
            }
            else{
                tmp *= 10;
            }
        }
        ans += tmp;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int NMAX = (int)1e5+1;

int max(int a,int b){
  return a>b ? a : b;
}

int main(){
  int n,i,ans=1;
  char s[NMAX];
  
  scanf("%d",&n);
  scanf("%s",s);
  
  for(i=0;i<n-1;i++)
    if(s[i]!=s[i+1])ans++;
  
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int maxn = 100000;
int eratoes[100005];
int main(){
	for(int i=2; i<=maxn; i++) eratoes[i] = i;
	for(int i=2; i*i<=maxn; i++){
		if(eratoes[i]==i){
			for(int j=i*i; j<=maxn; j+=i) eratoes[j] = i;
		}
	}
	vector<int>ret;
	for(int i=2; i<=55555; i++){
		if(eratoes[i]==i && i%5==1) ret.push_back(i);
	}
	int n;
	cin>>n;
	for(int i=0; i<n; i++) cout<<ret[i]<<" ";
}

Measured memory_bytes: 4024
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
#define sz 100005
ll inf = 1e18;
ll power(ll x, ll n, ll mod)
{
  ll res = 1;
  x %= mod;
  while (n)
  {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res%mod;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll n;
  cin>>n;
  vector<pair<ll,ll>> v;
  for(ll i=0;i<n;i++)
  {
    ll x,y;
    cin>>x>>y;
    v.push_back({x,y});
  }
  vector<ll> sum,diff;
  for(ll i=0;i<n;i++)
  {
    sum.push_back(v[i].first+v[i].second);
    diff.push_back(v[i].first-v[i].second);
  }
  sort(sum.begin(),sum.end());
  sort(diff.begin(),diff.end());
  ll ans=max(sum[n-1]-sum[0],diff[n-1]-diff[0]);
  cout<<ans;
  return 0;
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


char a;

void solve()
{
    cin >> a;
    int k = a;
    if (a<96) nout('A');
    else nout('a');
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
using namespace std;
using ll = long long;
using V = pair<int, int>;
using E = pair<V, int>;
 
int main() {
  int N, M;
  cin >> N >> M;
  map<V, vector<E>> G;
  for (int i = 0; i < M; i++) {
    int p, q, c;
    cin >> p >> q >> c;
    V v1 = V(p, c);
    V v2 = V(q, c);
    G[v1].push_back(E(v2, 0));
    G[v2].push_back(E(v1, 0));
  }
  map<V, vector<E>> newG = G;
  for (auto &ps: G) {
    V v1 = ps.first;
    V v2 = V(v1.first, -1);
    newG[v1].push_back(E(v2, 0));
    newG[v2].push_back(E(v1, 1));
  }
  G = newG;
  map<V, int> dist;
  priority_queue<pair<int, V>> q;
  V start = V(1, -1), goal = V(N, -1);
  dist[start] = 0;
  q.emplace(0, start);
  while (!q.empty()) {
    auto ps = q.top(); q.pop();
    int cost = -ps.first;
    V v = ps.second;
    if (dist[v] < cost) {
      continue;
    }
    for (auto e: G[v]) {
      V u = e.first;
      int add = e.second;
      if (!dist.count(u) || cost + add < dist[u]) {
        dist[u] = cost + add; 
        q.emplace(-dist[u], u);
      }
    }
  }
  cout << (dist.count(goal) ? dist[goal] : -1) << endl;
  return 0;
}


Measured memory_bytes: 150012