akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

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

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

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(intmax_t, N, A, B);

    intmax_t res = (N / (A + B)) * A;
    res += min(N % (A + B), A);

    output(res);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <random>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

// 0:20
int main(){
    ll n,m;cin>>n>>m;
    vector<ll> vx(n);
    vector<ll> vy(n);
    vector<ll> vz(n);
    rep(i,n){
      cin>>vx[i]>>vy[i]>>vz[i];
    }
    vector<ll> vans(n);
    ll ans=0;

    rep(i,n){
      vans[i]=0;
      vans[i]=vx[i]+vy[i]+vz[i];
    }
    ll temp=0;
    sort(all(vans));
    rep(i,m){
      temp+=vans[n-i-1];
    }
    ans=max(abs(temp),ans);

    temp=0;
    rep(i,m){
      temp+=vans[i];
    }
    ans=max(abs(temp),ans);


    rep(i,n){
      vans[i]=0;
      vans[i]=vx[i]-vy[i]+vz[i];
    }
    temp=0;
    sort(all(vans));
    rep(i,m){
      temp+=vans[n-i-1];
    }
    ans=max(abs(temp),ans);

    temp=0;
    rep(i,m){
      temp+=vans[i];
    }
    ans=max(abs(temp),ans);


    rep(i,n){
      vans[i]=0;
      vans[i]=vx[i]+vy[i]-vz[i];
    }
    temp=0;
    sort(all(vans));
    rep(i,m){
      temp+=vans[n-i-1];
    }
    ans=max(abs(temp),ans);

    temp=0;
    rep(i,m){
      temp+=vans[i];
    }
    ans=max(abs(temp),ans);


    rep(i,n){
      vans[i]=0;
      vans[i]=-1*vx[i]+vy[i]+vz[i];
    }
    temp=0;
    sort(all(vans));
    rep(i,m){
      temp+=vans[n-i-1];
    }
    ans=max(abs(temp),ans);

    temp=0;
    rep(i,m){
      temp+=vans[i];
    }
    ans=max(abs(temp),ans);

    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <math.h>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

class Point{
public:
	double x,y;
};

void koch(int n,Point a,Point b){
	Point s,t;
	if(n==0) return;
	s.x = (2*a.x+b.x)/3;
	s.y = (2*a.y+b.y)/3;
	t.x = (a.x+2*b.x)/3;
	t.y = (a.y+2*b.y)/3;
	Point u;
	double rad = M_PI*(60.0/180.0);
	u.x = (t.x-s.x)*cos(rad) - (t.y-s.y)*sin(rad) + s.x;
	u.y = (t.x-s.x)*sin(rad) + (t.y-s.y)*cos(rad) + s.y;
	koch(n-1,a,s);
	cout << s.x << " " << s.y << endl;
	koch(n-1,s,u);
	cout << u.x << " " << u.y << endl;
	koch(n-1,u,t);
	cout << t.x << " " << t.y << endl;
	koch(n-1,t,b);
}

int main(){
	int n;
	cin >> n;
	Point a,b;
	a.x = 0;a.y = 0;
	b.x = 100;b.y = 0;
	cout << fixed << setprecision(8) << a.x << " " << a.y << endl;
	koch(n,a,b);
	cout << fixed << setprecision(8) << b.x << " " << b.y << endl;
	return 0;
}

Measured memory_bytes: 1248
n=int(input())
h=list(map(int,input().split()))
for i in range(n-2,-1,-1):
    if h[i]>h[i+1]:
        h[i]-=1
for i in range(n-1):
    if h[i]>h[i+1]:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 14396
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        int[] abc = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int ans = 0;

        while(!(abc[0] == abc[1] && abc[1] == abc[2]))
        {
            Array.Sort(abc);
            if(abc[0] < abc[1])
            {
                abc[0] += 2;
            }
            else if(abc[0] == abc[1])
            {
                abc[0] += 1;
                abc[1] += 1;
            }
            ans++;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    ll a, b, k; cin >> a >> b >> k;
    if(k<=a){
        a -= k;
    }else{
        k -= a;
        a = 0;
        b = max(b-k, (ll)0);
    }
    printf("%lld %lld\n", a, b);
    return 0;}

Measured memory_bytes: 3752
#include<stdio.h>

int main(){
  int n, i, j, u, k, v;
  int AM[100][100];

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      AM[i][j] = 0;
    }
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v);
      v--;
      AM[u][v] = 1;
    }
  }

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      if(j > 0) printf(" ");
      printf("%d",AM[i][j]);
    }
    printf("\n");
  }

  return 0;
}



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

using namespace std;

int main()
{

	string S, T;

	cin >> S >> T;

	int count = 0;

	for (int i = 0; i < S.length(); i++)
	{
		if (S[i] != T[i])
		{
			S[i] = T[i];
			count++;
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 3808
<?php

fscanf(STDIN, "%d%d", $animal, $animal_sum);


$x_2 = $animal * 2 ;
$y_4 = $animal * 4 ;


if ($animal_sum % 2 == 0 && $x_2 <= $animal_sum && $animal_sum <= $y_4){
        echo 'Yes';
}else{
    echo 'No';
}

Measured memory_bytes: 16072
#include <iostream>

using namespace std;

int main() {
	int A ,B;
	cin >> A >> B;
  if(A<6) {
	cout << 0 <<endl;
  }
  else if(6<=A && A<=12) {
    cout << B/2 <<endl;
  }
  else {
    cout << B <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, K;
string S;
cin >> N >> K >> S;
if(S.at(K - 1) == 'A')
S.at(K - 1) = 'a';
else if(S.at(K - 1) == 'B')
S.at(K - 1)= 'b';
else if(S.at(K - 1) == 'C')
S.at(K - 1)= 'c';
cout << S << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long n = sc.nextLong();
		long sum;
		if (n % 11 == 0) {
			sum = n / 11;
			sum = sum * 2;
		} else if (n % 11 <= 6) {
			sum = n / 11;
			sum = sum * 2 + 1;
		} else {
			sum = n / 11;
			sum = sum * 2 + 2;
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 22736
///not today

#include<bits/stdc++.h>
using namespace std;

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair< int, pair<int, int> >
#define plpll pair< ll, pair<ll, ll> >

using namespace std;

int32_t main(){
    int n, ans = 1;
    string s;
    cin >>n >>s;
    for(int i = 1; i < n; i ++){
        if(s[i] != s[i - 1])
            ans ++;
    }
    cout <<ans <<endl;
    return false;
}


Measured memory_bytes: 512
x=2*10**5

import math 
L=math.floor(math.sqrt(x))# 平方根を求める

Primelist=[i for i in range(x+1)]
Primelist[1]=0# 1は素数でないので0にする.
 
for i in Primelist:
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0

Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]

import bisect
X=int(input())

k=bisect.bisect_left(Primes,X)
print(Primes[k])


Measured memory_bytes: 11288
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010,Mo=1000000007;
int w[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,ans=1;
    cin>>n;
    for(int i=1;i<=n;i++) ++w[gi()];
    if(n&1) {
	ans=(w[0]==1);
	for(int i=2;i<n;i+=2)
	    ans=ans*2*(w[i]==2)%Mo;
    }
    else {
	for(int i=1;i<n;i+=2)
	    ans=ans*2*(w[i]==2)%Mo;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
using namespace std;

#define ll long long
using vt = int; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	int n;
	double ans;
	deque<double> v;
	cin >> n;
	rep(i, n) {
		double a;
		cin >> a;
		v.push_back(a);
	}
	sort(all(v));
	rep(i, n - 1) {
		double x, y, z;
		x = v.front();
		v.pop_front();
		y = v.front();
		v.pop_front();
		z = (x + y) / 2;
		if (!(v.empty())) v.push_front(z);
		else ans = z;
	}
	cout << fixed << setprecision(6) << ans;
	return 0;
}

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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;
const long long maxx = 1000000000000000000LL;
int main(){
  prep();
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > lr[n+1];
  for (int i=0; i<m; i++){
      int l, r, v;
      cin >> l >> r >> v;
      lr[l].push_back({r, v});
  }
  for (int i=1; i<=n-1; i++){
      lr[i+1].push_back({i, 0});
  }

  long long vals[n+1];
  bool got[n+1] = {false};
  got[1] = true;
  vals[1] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > q;
  q.push({0, 1});
  while (!q.empty()){
      pair<long long, int> p = q.top();
      int front = p.second;
      if (front == n){
          break;
      }
      q.pop();
      for (int i=0; i<lr[front].size(); i++){
          int node = lr[front][i].first;
          long long val = lr[front][i].second;
          if (!got[node]){
              got[node] = true;
              vals[node] = val+vals[front];
              q.emplace(vals[node], node);
          }else if (vals[node] > val+vals[front]){
              vals[node] = val+vals[front];
              q.emplace(vals[node], node);
          }
      }
  }
  if (!got[n]){
      cout << -1;
  }else{
      cout << vals[n];
  }
  return 0; 
}

Measured memory_bytes: 8060
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string s = Console.ReadLine();
		string t = Console.ReadLine();
		string aaa = "abcdefghijklmnopqrstuvwxyz";
		var list = new List<int>[26];
      	for(var i=0;i<26;i++){
          list[i] = new List<int>();
        }
		for(var i=0;i<s.Length;i++){
			int a1 = aaa.IndexOf(s.Substring(i,1));
			list[a1].Add(i);
		}
		long ans = 0;
		for(var i=0;i<t.Length;i++){
			int a1 = aaa.IndexOf(t.Substring(i,1));
			if(list[a1].Count==0){
				ans = -1;
				break;
			}
		}
		if(ans!=-1){
			int a1 = aaa.IndexOf(t.Substring(0,1));
			int b1 = list[a1][0];
			for(var i=1;i<t.Length;i++){
				int a2 = aaa.IndexOf(t.Substring(i,1));
				int min = 0;
				int max = list[a2].Count;
				while(min<max){
					int m = (min+max)/2;
					if(list[a2][m]>b1){
						max = m;
					} else {
						min = m+1;
					}
				}
				if(min==list[a2].Count){
					min = 0;
					ans++;
				}
				b1 = list[a2][min];
			}
          	ans = ans * s.Length + b1+1;
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 19424
// Author : Hardik Upadhyay
// college: SVNIT 
// slogan : Ab to phod dunga
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i = a ; i >= b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int MAXN = 100005;
ll mod=1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	double x;
	cin>>x;
	double amount = 100;
	for(int i = 0; i <= 1000000; i++){
		if(i!=0){
			amount=amount+ 0.01*amount;
			amount = (ll)amount;
		}
		if(amount >= x){
			cout<<i<<nl;
			break;
		}
	}
	return 0;
}



Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,y,z,K; cin>>x>>y>>z>>K;
    vector <long long> a(x); vector <long long> b(y); vector <long long> c(z);
    for(int i=0;i<x;i++){
        scanf("%lld" ,&a[i]);
    }
    for(int i=0;i<y;i++){
        scanf("%lld" ,&b[i]);
    }
    for(int i=0;i<z;i++){
        scanf("%lld" ,&c[i]);
    }
    vector <long long> ab;
    for(int i=0;i<x;i++){
        for(int j=0;j<y;j++){
            ab.push_back(a[i]+b[j]);
        }
    }
    sort(ab.begin(),ab.end(),greater<long long>());
    ab.resize(K);
    vector <long long> abc;
    for(int i=0;i<ab.size();i++){
        for(int j=0;j<z;j++){
            abc.push_back(ab[i]+c[j]);
        }
    }
    sort(abc.begin(),abc.end(),greater<long long>());
    for(int i=0;i<K;i++){
        cout<<abc[i]<<endl;
    }
}


Measured memory_bytes: 43368
#include<iostream> 
#include<algorithm> 
using namespace std;
static const int N = 100;
int main() {
    int n, p[N +1],m[N+1][N+1]; 
    cin >> n; 
    for ( int i = 1; i <= n; i++) { 
        cin >> p[i - 1] >> p[i];
    }
    for(int i = 1; i <= n; i++ ) m[i][i] = 0; 
    for(int l = 2; l<= n; l++ ) {
        for ( int i = 1; i <= n - l + 1; i++) {
            int j = i + l - 1;
            m[i][j] = (1 << 21); 
            for ( int k = i; k <= j - 1; k++ ){
                m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            }
            
        }
    }
    cout<<m[1][n]<<endl;
    return 0;
}



Measured memory_bytes: 3148
from collections import deque
 
n,x,y = map(int,input().split())
 
root = [[] for i in range(n)]
for i in range(1,n):
    root[i-1].append(i)
    root[i].append(i-1)

root[x-1].append(y-1)
root[y-1].append(x-1)

reselt = [0]*(n-1)

for i in range(n):
    stack=deque([i])
    check = [-1]*n
    check[i] = 0
 
    while len(stack)>0:
        v = stack.popleft()
        for i in root[v]:
            if check[i] == -1:
                check[i] = check[v]+1
                reselt[check[i]-1] += 1
                stack.append(i)

for i in reselt:
    print(i//2)

Measured memory_bytes: 76044
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int main(){
	LL N;
	cin >> N;
	//3*5*5
	//15*5
	//3*25
	//75
	int so[101]={};
	for(int i=2; i<=N; i++){
		int n = i;
		for(int j=2; j<=100; j++){
			while(n % j == 0){
				n /= j;
				so[j]++;
			}
			if(n == 1) break;
		}
	}

	//3*5*5
	int ans = 0;
	for(int i=2; i<=100; i++){
		if(so[i] < 3-1) continue;
		for(int j=2; j<=100; j++){
			if(so[j] < 5-1) continue;
			if(i == j) continue;
			for(int k=2; k<=100; k++){
				if(so[k] < 5-1) continue;
				if(i == k || j == k) continue;
				ans++;
				//cout << i << " " << j << " " << k << endl;
			}
		}
	}
	ans /= 2;
	//15*5
	for(int i=2; i<=100; i++){
		if(so[i] < 15-1) continue;
		for(int j=2; j<=100; j++){
			if(so[j] < 5-1) continue;
			if(i == j) continue;
			ans++;
			//cout << i << " " << j << endl;
		}
	}
	for(int i=2; i<=100; i++){
		if(so[i] < 25-1) continue;
		for(int j=2; j<=100; j++){
			if(so[j] < 3-1) continue;
			if(i == j) continue;
			ans++;
			//cout << i << " " << j << endl;
		}
	}
	//75
	for(int i=2; i<=100; i++){
		if(so[i] < 75-1) continue;
		ans++;
		//cout << i << endl;
	}
	cout << ans << endl;
}


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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int n;
    string s;
    cin >> n >> s;
    if(n % 2) {
        cout << "No" << endl;
    } else {
        for(int i = 0; i < n / 2; i++) {
            if(s[i] != s[i + n / 2]) {
                cout << "No" << endl;
                break;
            }
            if(i == n / 2 - 1) {
                cout << "Yes" << endl;
            }
        }
    }
    return 0;
}
//===========================================

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

Measured memory_bytes: 256
# print('input >>')
N = int(input())
As = list(map(int,(input().split())))

tashi = {}
hiki = {}

for i in range(len(As)):
    sum_ = i + As[i]
    sub_ = i - As[i]
    if not sum_ in tashi:
        tashi[sum_] = 0
    if not sub_ in hiki:
        hiki[sub_] = 0
    tashi[sum_] += 1
    hiki[sub_] += 1

ans = 0

for k, v in tashi.items():
    if k in hiki:
        ans += v * hiki[k]

# print('-----output-----')
print(ans)

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

int main(void){
    char s[5+1];
    char *p;
    int a=0,b=0,ab=0,o=0;
    
    while(scanf("%s\n",s)>0){
        p=s;
        while(*p++!=','){}
        if(strcmp(p,"A")==0)a++;
        else if(strcmp(p,"B")==0)b++;
        else if(strcmp(p,"AB")==0)ab++;
        else if(strcmp(p,"O")==0)o++;
        else return -1;
    }
    
    printf("%d\n%d\n%d\n%d\n",a,b,ab,o);

    return 0;
}



Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007,maxn=200100;
inline void Add(int &a,int b){a=a+b>=mod?a+b-mod:a+b;}
inline int ksm(int a,int b)
{
	int res=1;
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) res=1ll*res*a%mod;
	return res;
}
int fac[maxn],invfac[maxn];
inline int C(int n,int m){return 1ll*fac[n]*invfac[m]%mod*invfac[n-m]%mod;}
int head[maxn],nxt[maxn<<1],ver[maxn<<1],tot;
inline void addedge(int a,int b)
{
	nxt[++tot]=head[a];ver[tot]=b;head[a]=tot;
	nxt[++tot]=head[b];ver[tot]=a;head[b]=tot;
}
int ans[maxn],size[maxn],f[maxn],n;
inline void dfs(int x,int fat)
{
	f[x]=1;size[x]=1;
	for(int i=head[x];i;i=nxt[i])
	{
		int y=ver[i];if(y==fat) continue;
		dfs(y,x);f[x]=1ll*f[x]*invfac[size[y]]%mod;
		size[x]+=size[y];f[x]=1ll*f[x]*f[y]%mod;
	}
	f[x]=1ll*f[x]*fac[size[x]-1]%mod;
}
inline void bao(int x,int fat,int upv)
{
	int v=1ll*f[x]*upv%mod*C(n-1,size[x]-1)%mod;
	ans[x]=v;
	for(int i=head[x];i;i=nxt[i])
	{
		int y=ver[i];if(y==fat) continue;
		int nxtv=1ll*v*ksm(f[y],mod-2)%mod;
		nxtv=1ll*nxtv*invfac[n-1]%mod*fac[n-size[y]-1]%mod*fac[size[y]]%mod;
		bao(y,x,nxtv);
	}
}
int main()
{
	for(int i=fac[0]=1;i<maxn;i++) fac[i]=1ll*fac[i-1]*i%mod;
	invfac[maxn-1]=ksm(fac[maxn-1],mod-2);
	for(int i=maxn-2;i>=0;i--) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
	scanf("%d",&n);
	for(int i=1,a,b;i<n;i++) scanf("%d%d",&a,&b),addedge(a,b);
	dfs(1,0);bao(1,0,1);
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 9984
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
using namespace std;
#define N 100009
#define mod 1000000007

int main(){
    ll n,m;
    cin>>n>>m;
    bool data[n+1];
    for (ll i=1; i<=n; i++) data[i]=true;
    for (ll i=1; i<=m; i++){
        ll p;
        cin>>p;
        data[p]=false;
    }
    
    ll num[n+1];
    num[0]=1;
    if (data[1]) num[1]=1;
    else num[1]=0;
    
    for (ll i=2; i<=n; i++){
        if (data[i]){
            num[i]=num[i-1]+num[i-2];
            num[i]%=mod;
        }
        else num[i]=0;
    }
    
    cout<<num[n]<<endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int t, n, k, x[100000+10], a[100000+10];
    cin >> t;
    for(int i=0; i<t; i++){
        int sum=0;
        cin >> n >> k;
        for(int j=0; j<n; j++)  cin >> x[j];
        for(int j=0; j<n-1; j++) a[j] = x[j+1]-x[j];
        sort(a, a+(n-1));
        for(int j=0; j<n-1-(k-1); j++) sum+=a[j];
        cout << sum <<endl;
    }
    return 0;
}


Measured memory_bytes: 3848
<?php

fscanf(STDIN, "%d %d", $a, $b);
$c = $a + $b;

if ($c === 0)
{
	echo 'Impossible';
}
elseif ($a % 3 === 0)
{
	echo 'Possible';
}
elseif ($b % 3 === 0)
{
	echo 'Possible';
}
elseif ($c % 3 === 0)
{
	echo 'Possible';
}
else
{
	echo 'Impossible';
}

Measured memory_bytes: 3700
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n,k;
	cin>>n>>k;
	int i;
	for(i=0;i<k;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		if(a>=n/2){
			a=n-a-1;
		}
		if(b>=n/2){
			b=n-b-1;
		}
		chmin(a,b);
		a%=3;
		a++;
		cout<<a<<endl;
	}
	return 0;
}

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

int main() {
	int r;
	cin >> r;
	string k = "AGC";
	if(r < 1200)
	{
		k = "ABC";
	}
	else if(r < 2800)
	 {
	 	k = "ARC";
	 }
    cout << k << endl;
	return 0;
}


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

int h, w;
mt19937 ei(1333333);

bool check(vector<string> s) {
  int h = s.size();
  vector<string> t = s;
  for (auto &i : t) reverse(i.begin(), i.end());

  int cnt = 0;
  bool used[20] = {};
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < i; ++j) {
      if (used[j] || s[i] != t[j]) continue;
      used[i] = used[j] = true;
      cnt += 2;
      break;
    }
  }

  if (h & 1) for (int i = 0; i < h; ++i) {
    if (used[i] || s[i] != t[i]) continue;
    cnt++;
    break;
  }

  return cnt == h;
}

bool solve(auto &t, int q = 400000) {
  auto s = t;
  vector<int> v(w);
  for (int i = 0; i < w; ++i) v[i] = i;
  while (q--) {
    //怒りの乱択
    if (check(s)) return true;
    shuffle(v.begin(), v.end(), ei);
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        s[i][j] = t[i][v[j]];
      }
    }
  }

  return false;
}

int main() {
  cin >> h >> w;

  vector<string> s(h);
  for (auto &i : s) cin >> i;

  cout << (solve(s) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iomanip>
using namespace std;
#define brk system("pause");

const int N = 3001;
long long dp[N][N], a[N], n;

long long calc(int l, int r, int t = 0)
{
	if(l == r) return a[l] - 2 * a[l] * t;
	if(dp[l][r] != -1) return dp[l][r];
	
	if(t) dp[l][r] = min(calc(l + 1, r, t ^ 1) - a[l], calc(l, r - 1, t ^ 1) - a[r]);
	else dp[l][r] = max(calc(l + 1, r, t ^ 1) + a[l], calc(l, r - 1, t ^ 1) + a[r]);
	
	return dp[l][r];
}

main()
{
	scanf("%lld", &n);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
	
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j++)
			dp[i][j] = -1ll;
	
	printf("%lld\n", calc(1, n));
}


Measured memory_bytes: 70144
//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
template <class T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class K, class V> using Umap = gp_hash_table<K, V>;
using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;

inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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


signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    int h, w;
    cin >> h >> w;

    vector<string> a(h);
    vector<int> cnt(26);
    int four = 0, two = 0, one = 0;

    rep(i,h){
        cin >> a[i];
        rep(j,w){
            ++cnt[a[i][j] - 'a'];
        }
    }

    rep(i,26){
        four += cnt[i] / 4;
        cnt[i] %= 4;
        two += cnt[i] / 2;
        cnt[i] %= 2;
        one += cnt[i];
    }

    if(h % 2 == 0 && w % 2 == 0){
        if(two == 0 && one == 0){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }else if(h % 2 == 1 && w % 2 == 1){
        if(one == 1 && two <= h / 2 + w / 2){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }else{
        int x = (h % 2 == 0 ? h : w);
        if(one == 0 && two <= x / 2){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }

    return 0;
}

Measured memory_bytes: 3660
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      int N = sc.nextInt();
      int K = sc.nextInt();
      if(N >= 2 * (K - 1) + 1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
	}
}


Measured memory_bytes: 25044
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

ll d[1100][1100]; //d[u][v]は辺e=(u,v)のコスト(存在しない場合はINF，d[i][i]=0)
int V,perm[10]={0,1,2,3,4,5,6,7,8}; //頂点数

//(V^3)
void warshall_floyd(){
  for(int k=0;k<V;k++){
    for(int i=0;i<V;i++){
      for(int j=0;j<V;j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    }
  }
}

int main(){
  ll ans=INF;
  int M,R,r[10],a,b,t;
  cin>>V>>M>>R;
  for(int i=0;i<R;i++){
    cin>>r[i];
    r[i]--;
  } 
  
  for(int i=0;i<V;i++){
    for(int j=0;j<V;j++){
      d[i][j]=INF;
      if(i==j) d[i][j]=0;
    } 
  }
  
  for(int i=0;i<M;i++){
    cin>>a>>b>>t;
    a--; b--;
    d[a][b]=t; d[b][a]=t;
  }
  
  warshall_floyd();
  //cout<<d[0][2]<<endl;
  //int count=0;
  do{
    //count++;
    ll temp=0;
    for(int i=0;i<R-1;i++){
      temp+=d[r[perm[i]]][r[perm[i+1]]];
      //cout<<perm[i]<<" "<<perm[i+1]<<" "<<temp<<endl;
    }
    //cout<<endl;
    ans=min(ans,temp);
  }while(next_permutation(perm,perm+R));
  //上の場合だと2と3が入れ替わるだけで処理終了
  //cout<<count<<endl;
  cout<<ans<<endl;
}




Measured memory_bytes: 1408
def Next(x) :
	return (A * x + B) % C

while True :
	N, A, B, C, X = map(int, input().split())
	if(C == 0) :
		break
	else :
		Y = list(map(int,input().split()))
		for i in range(10002) :
			if(i == 10001) :
				print(-1)
			else :
				if(X == Y[0]) :
					del Y[0]
				if(len(Y) == 0) :
					print(i)
					break
				else :
					X = Next(X)


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x,y,z;cin >> x >>y >> z;
  cout << z <<  " " << x << " " <<  y << endl;

}

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

using namespace std;

int main(int argc,char* argv[]){
	int A,seven=0,five=0;
	for(int i=0;i<3;i++){
		cin >> A;
		if(A==5) five++;
		else if(A==7) seven++;
	} 
	if(five==2&&seven==1) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

bool x[11];

bool fm(string &s, int &idx) {
  if (s[idx] == '(') {
    idx++;
    bool f1 = fm(s,idx);
    char c = s[idx++];
    if (c == '-') idx++;
    bool f2 = fm(s,idx);
    assert(s[idx] == ')');
    idx++;
    if (c == '*') return f1 & f2;
    else if (c == '+') return f1 | f2;
    else if (c == '-') return !(f1 & (!f2));
  } else if (s[idx] == '-') {
    idx++;
    bool f1 = fm(s,idx);
    return !f1;
  } else if (s[idx] == 'T') {
    idx++;
    return 1;
  } else if (s[idx] == 'F') {
    idx++;
    return 0;
  } else {
    bool f = x[s[idx++]-'a'];
    return f;
  }
}

bool eq(string &s, int &idx) {
  bool f1 = fm(s,idx);
  assert(s[idx++] == '=');
  bool f2 = fm(s,idx);
  return f1 == f2;
}

int main() {
  string s;
  while(cin>>s,s!="#") {
    bool f = 0;
    REP(S,1<<11) {
      REP(i,11) x[i] = (S>>i&1);
      int idx = 0;
      if (!eq(s,idx)) {
        f = 1;
        break;
      }
    }
    if (f) cout << "NO" << endl;
    else cout << "YES" << endl;
  }
}

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

typedef long long ll;
using namespace std;

#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define _repi(i, s, n) for(ll i = (ll)(s); i < (ll)n; i++)
#define REP(...) _overload(__VA_ARGS__, _repi, _rep,)(__VA_ARGS__)
#define all(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() );
#define MOD 1000000007

ll dp[101][100001];

int main(){
	ll n, w;	cin >> n >> w;
	pair<ll, ll> item[n];
	REP(i, n){
		cin >> item[i].first >> item[i].second;
	}

	memset(dp, -1, sizeof(dp));

	REP(i, n+1) REP(j, w+1){
		dp[i][j] = 0;
	}

	REP(i, 1, n+1){
		REP(j, w+1){
			if( j - item[i-1].first < 0 )	dp[i][j] = dp[i-1][j];
			else	dp[i][j] = max(dp[i-1][j], dp[i-1][ j-item[i-1].first ] + item[i-1].second);
		}
	}

	cout << dp[n][w] << endl;

	return 0;
}


Measured memory_bytes: 82524
#[allow(dead_code)]

pub struct Scanner {
    idx: usize, 
    buf: Vec<String>,
}

impl Scanner {
    pub fn new<T: std::io::Read>(inf: &mut T) -> Scanner {
        Self {
            idx:0,
            buf: {
                let mut s = String::new();
                inf.read_to_string(&mut s).expect("I/O error");
                s.split_whitespace().map(|x| x.to_owned()).collect()
            },
        }
    }

    pub fn read<T: std::str::FromStr> (&mut self) -> T 
    where
        <T as std::str::FromStr>::Err: std::fmt::Debug,
    {
        if self.empty() {
            panic!("reached the end of input")
        }
        let ret = self.buf[self.idx].parse::<T>().expect("parse error");
        self.idx += 1;
        return ret;
    }

    pub fn empty(&self) -> bool {
        return self.idx >= self.buf.len();
    }
}

fn main() {
    let mut sc = Scanner::new(&mut std::io::stdin());
    let s: Vec<char> = sc.read::<String>().chars().collect();
    let mut ans: i64 = 0;
    let mut cnt: i64 = 0;

    for ch in s {
        if ch == 'W' {
            ans += cnt;
        }
        else {
            cnt += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 3264
/*
 © 2020-09-19 19:46:47 Franco1010 All Rights Reserved
*/

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;
const lli INF = 1e18;
struct segtree{
  #define mid (l + r) / 2
  #define left(u) (u + 1)
  #define right(u) (u + ((mid - l + 1) << 1))
  struct node{
    lli s, z;
    node(lli s = 0, lli z = 0): s(s), z(z) {}
    node operator + (const node &n){
      return node(max(s, n.s));
    }
  };
  vector<node> st;
  segtree(int n): st(2 * n) {}
  void push(int u, int l, int r){
    if(st[u].z){
      st[u].s = max(st[u].s, st[u].z);
      if(l < r){
        st[left(u)].s = max(st[left(u)].s, st[u].z);
        st[left(u)].z = max(st[left(u)].z, st[u].z);
        st[right(u)].s = max(st[right(u)].s, st[u].z);
        st[right(u)].z = max(st[right(u)].z, st[u].z);
      }
      st[u].z = 0;
    }
  }
  void update(int u, int l, int r, int ll, int rr, lli val){
    push(u, l, r);
    if(l > r or r < ll or l > rr) return;
    if(ll <= l and r <= rr){
      st[u].s = max(val, st[u].s);
      st[u].z = max(val, st[u].z);
      push(u, l, r);
      return;
    }
    push(u, l, r);
    update(left(u), l, mid, ll, rr, val);
    update(right(u), mid + 1, r, ll, rr, val);
    st[u] = st[left(u)] + st[right(u)];
  }
  lli query(int u, int l, int r, int ll, int rr){
    push(u, l, r);
    if(l > r or r < ll or l > rr) return 0;
    if(ll <= l and r <= rr) return st[u].s;
    push(u, l, r);
    return max(query(left(u), l, mid, ll, rr), query(right(u), mid + 1, r, ll, rr));
  }
};
int main(){ _
  lli n, k; cin >> n >> k;
  segtree sv(n), sh(n);
  sv.update(0, 0, n - 1, 0, n - 1, 1);
  sv.update(0, 0, n - 1, n - 1, n - 1, n);
  sh.update(0, 0, n - 1, 0, n - 1, 1);
  sh.update(0, 0, n - 1, 0, 0, n);
  lli res = (n - 2ll) * (n - 2ll);
  while(k--){
    lli q, x; cin >> q >> x;
    if(q == 1){
      lli foo = sv.query(0, 0, n - 1, x - 1, x - 1);
      res -= max(0ll, n - foo - 1);
      sv.update(0, 0, n - 1, x - 1, x - 1, n);
      sh.update(0, 0, n - 1, foo, n - 1, n - x + 1);
    }else{
      lli foo = sh.query(0, 0, n - 1, n - x, n - x);
      res -= max(0ll, n - foo - 1);
      sh.update(0, 0, n - 1, n - x, n - x, n);
      sv.update(0, 0, n - 1, 0, n - foo - 1, n - x + 1);
    }
  }
  cout << res << ENDL;
  return 0;
}


Measured memory_bytes: 15864
program abc166d
      implicit none
      integer(8)::x
      integer(8)::i,j

         read *, x

         do i=-150,150
            do j=-150,150
               if ((i**5-j**5)==x) then
                  print *, i,j
                  stop
               end if
            end do
         end do

   end program abc166d

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll n, m, k;
    cin >> n >> m >> k;
    
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    vector<ll> b(m);
    REP(i, m) cin >> b[i];

    vector<ll> A(n+1), B(m+1);
    A[0] = 0, B[0] = 0;
    for(ll i = 0; i < n; i++) {
        A[i+1] = a[i] + A[i];
    }
    for(ll i = 0; i < m; i++) {
        B[i+1] = b[i] + B[i];
    }

    ll ans = 0;
    for(ll i = 0; i <= n; i++) {
        if (A[i] > k) break;
        
        ll ng = 0;
        ll ok = (ll)B.size();
        ll key = k-A[i];

        while(abs(ok - ng) > 1) {
            ll mid = (ok + ng) / 2;
            
            if (B[mid] > key) ok = mid;
            else ng = mid;
        }

        ans = max(ans, i + ng);
    }
    
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 9552
import java.util.Scanner;
import java.util.StringJoiner;

class Main {

	static int n;

	static int[] inOrd;
	static int[] preOrd;
	static int[] postOrd;

	static int cIdx = 0;
	static int rIdx = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();

		inOrd = new int[n];
		for (int i = 0; i < n; i++) inOrd[i] = sc.nextInt();

		preOrd = new int[n];
		for (int i = 0; i < n; i++) preOrd[i] = sc.nextInt();

		sc.close();

		postOrd = new int[n];
		postOrder(0, n);

		StringJoiner sj = new StringJoiner(" ");
		for (int i = 0; i < n; i++) {
			sj.add(String.valueOf(postOrd[i]));
		}
		System.out.println(sj);

	}

	private static void postOrder(int l, int r) {

		if(l >= r) return;

		int next = inOrd[cIdx];
		cIdx++;

		int m = -1;
		for (int i = 0; i < r; i++) {
			if (preOrd[i] == next) {
				m = i;
				break;
			}
		}

		postOrder(l, m);
		postOrder(m+1, r);

		postOrd[rIdx] = next;
		rIdx++;
	}
}


Measured memory_bytes: 26388
import numpy as np
from numba import njit, i8


@njit(i8(i8, i8[:], i8[:]), cache=True)
def solve(H, A, B):
    A_max = A.max()
    dp = np.zeros(H + A_max + 1, dtype=np.int64)
    for i in range(A_max + 1, H + A_max + 1):
        dp[i] = np.min(dp[i - A] + B)
    return dp[-1]


H, N, *AB = map(int, open(0).read().split())
A = np.array(AB[::2], dtype=np.int64)
B = np.array(AB[1::2], dtype=np.int64)
print(solve(H, A, B))


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

int main() {
    int64_t n; cin >> n;
    vector<int64_t> a(n);
    vector<int64_t> an(100001, 0);
    int64_t s = 0;
    for (int64_t i = 0; i < n; i++) {
        cin >> a.at(i);
        an.at(a.at(i))++;
        s += a.at(i);
    }
    int64_t q; cin >> q;
    for (int64_t i = 0; i < q; i++) {
        int64_t b, c; cin >> b >> c;
        if (an.at(b) == 0) {
            cout << s << endl;
            continue;
        }
        s += (c - b) * an.at(b);
        an.at(c) += an.at(b);
        an.at(b) = 0;
        cout << s << endl;
    }
}

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

const int MAX=10000;
int n,A,B,C;
int l[MAX];

int dfs(int cur,int a,int b,int c){
  if(cur==n){
    if(a==0 || b==0 || c==0){
      return 1000000000;
    }else{
      return abs(a-A)+abs(b-B)+abs(c-C)-30;
    }
  }
  int r=dfs(cur+1,a,b,c);
  int r2=dfs(cur+1,a+l[cur],b,c)+10;
  int r3=dfs(cur+1,a,b+l[cur],c)+10;
  int r4=dfs(cur+1,a,b,c+l[cur])+10;
  return min(min(r,r2),min(r3,r4));
}

int main(){
  cin>>n;
  cin>>A>>B>>C;
  for(int i=0;i<n;i++){
    cin>>l[i];
  }
  cout<<dfs(0,0,0,0)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
    ll X;
    int count = 1;
    rep(i, 5) {
        cin >> X;
        if (X == 0) {
            cout << count << endl;
            break;
        }
        count++;
    }
    return 0;
}

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

int n;
map<ll, ll>One, Two;

int main(){
	scanf("%d", &n);
	for(ll i = 1; i <= n; i++){
		ll x;
		scanf("%lld", &x);
		One[x + i]++;
		Two[i - x]++;
	}
	ll ans = 0;
	for(auto &Now : One) ans += Two[Now.first] * Now.second;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 38040
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define LLIandI pair<long long int , int>
#define ll long long

//N,M<=1500

int main(){
    while(1){
        int N,M;
        scanf("%d %d",&N,&M);
        if(N==0)break;
        int h[1500];h[0]=0;
        int w[1500];w[0]=0;
        vector<int> hc;
        vector<int> wc;
        rep(i,N){
            scanf("%d",&h[i+1]);
            h[i+1]+=h[i];
            rep(j,i+1){
                hc.push_back(abs(h[i+1]-h[j]));
            }
        }
        rep(i,M){
            scanf("%d",&w[i+1]);
            w[i+1]+=w[i];
            rep(j,i+1){
                wc.push_back(abs(w[i+1]-w[j]));
            }
        }
        sort(hc.begin(),hc.end());
        sort(wc.begin(),wc.end());
        int ans=0;
        int counter=0;
        int hcounter=0;
        for(int i=0;i<hc.size();i++){
            hcounter=1;
            while(i<hc.size()-1){
                if(hc[i]==hc[i+1]){
                    hcounter++;
                    
                    i++;
                }else{
                    break;
                }
            }
            while(counter<wc.size()){
                if(hc[i]<wc[counter]){
                    break;
                }else if(hc[i]==wc[counter]){
                    ans+=hcounter;
                    counter++;
                }else{
                    counter++;
                }
            }
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 19276