akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const int ha=1e9+7;
const int N=310;
int a[N<<1],b[N<<1],c[N<<1];
int f[N<<1][N][N];
int n,fre=0,cnt=0;

inline void add(int &x,const int &y){x=(x+y>=ha)?(x+y-ha):(x+y);}

int fac(int n)
{
    int res=1;
    for(int i=1;i<=n;i++)
        res=1ll*res*i%ha;
    return res;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n*2;i++) scanf("%d",a+i);
    for(int i=1;i<=n;i++)
    {
        if(a[2*i-1]!=-1&&a[2*i]!=-1) b[a[2*i-1]]=b[a[2*i]]=2;
        else if(a[2*i-1]!=-1) b[a[2*i-1]]=1;
        else if(a[2*i]!=-1) b[a[2*i]]=1;
        else fre++;
    }
    for(int i=1;i<=n*2;i++)
        if(b[i]<2) c[++cnt]=b[i];
    f[cnt][0][0]=1;
    for(int i=cnt;i>=1;i--)
        for(int j=0;j<=min(n,cnt-i);j++)
            for(int k=0;k<=min(n,cnt-i);k++)
                if(c[i]==1)
                {
                    add(f[i-1][j+1][k],f[i][j][k]);
                    if(k) add(f[i-1][j][k-1],f[i][j][k]);
                }
                else
                {
                    add(f[i-1][j][k+1],f[i][j][k]);
                    if(j) add(f[i-1][j-1][k],1ll*j*f[i][j][k]%ha);
                    if(k) add(f[i-1][j][k-1],f[i][j][k]);
                }
    int ans=1ll*f[0][0][0]*fac(fre)%ha;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 225536
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, q := scanInt(), scanInt()
	c := scanInts(n)

	p := make([]pair, q)
	for i := 0; i < q; i++ {
		p[i] = pair{scanInt() - 1, scanInt() - 1}
	}
	arr := make([]pair, q)
	copy(arr, p)
	sort.Slice(p, func(i, j int) bool {
		return p[i].b < p[j].b
	})

	d := make([]int, n)
	bit := make(binaryIndexedTree, n+1)
	for i := 0; i < n; i++ {
		d[i] = -1
	}

	t := 0
	ans := map[pair]int{}
	for i := 0; i < q; i++ {
		for t <= p[i].b {
			if d[c[t]-1] != -1 {
				bit.add(d[c[t]-1], -1)
			}
			d[c[t]-1] = t
			bit.add(t, 1)
			t++
		}
		ans[p[i]] = bit.sum(p[i].b) - bit.sum(p[i].a-1)
	}
	for i := 0; i < q; i++ {
		fmt.Fprintln(wr, ans[arr[i]])
	}

}

type pair struct{ a, b int }

type binaryIndexedTree []int

func (t binaryIndexedTree) sum(i int) int {
	s := 0
	for i++; i > 0; i -= i & -i {
		s += t[i]
	}
	return s
}
func (t binaryIndexedTree) add(i, x int) {
	for i++; i < len(t); i += i & -i {
		t[i] += x
	}
}


Measured memory_bytes: 93896
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
int main(){
  int s,w;
  cin>>s>>w;
  if(w>=s){
    cout<<"unsafe"<<"\n";  
  }
  else{
    cout<<"safe"<<"\n";  
  }
  return 0;
}

Measured memory_bytes: 3652
n, y = map(int, input().split())
ans = [-1, -1, -1]
for i in range(y // 10000 + 1):
    for j in range(y // 5000 + 1):
        if n - i - j >= 0 and y - 10000 * i - 5000 * j - (n - i - j) * 1000 == 0:
            ans = [i, j, n - i - j]
print(*ans)


Measured memory_bytes: 3060
$memo={}
def f(n,sq)
  if sq==1
    1
  elsif $memo[[n,sq]]
    $memo[[n,sq]]
  else
    $memo[[n,sq]]=(0..(n/(sq*sq))).map{|i|f(n-(sq*sq*i),sq-1)}.inject(:+)
  end
end

while (n=gets.to_i)>0
  p f(n,17)
end

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

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

  int res = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] != t[i]) res++;
  }

  cout << res << endl;
}

Measured memory_bytes: 3856
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define YES(n) cout << (n?"YES":"NO")<<endl;
#define Yes(n) cout << (n?"Yes":"No")<<endl;

int main() {
    int X, A, B;
    cin >> X >> A >> B;
    int sum = X - A;
    sum %= B *(sum/B);
    cout << sum << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
link = [[0] * (N+1) for i in range(N+1)]
links = []
count = 0

def dfs(pos):
    if reached[pos]:
        return
    reached[pos] = 1
    for next in range(N+1):
        if link[pos][next]:
            dfs(next)

for i in range(M):
    a, b = map(int, input().split())
    links.append([a, b])
    link[a][b] = 1
    link[b][a] = 1

for a, b in links:
    link[a][b] = 0
    link[b][a] = 0
    reached = [0] * (N+1)
    dfs(1)
    if all(reached[1:]) == False:
        count += 1
    link[a][b] = 1
    link[b][a] = 1

print(count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int n, m;
  cin >> n >> m;
  vector<ll> dp(n + 1, 0);

  int a;
  for (int i = 0; i < m; i++){
    cin >> a;
    dp[a] = -1;
  }


  dp[0] = 1;
  if (dp[1] != -1)
    dp[1] = 1;

  for (int i = 2; i <= n; i++){
    if (dp[i] == -1)
      continue;
    if (dp[i - 1] == -1 && dp[i - 2] == -1)
      dp[i] = -1;
    else if (dp[i - 1] == -1)
      dp[i] = dp[i - 2];
    else if (dp[i - 2] == -1)
      dp[i] = dp[i - 1];
    else
      dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
  }



  cout << max((ll)0, dp[n]) << endl;

  return 0;
}


Measured memory_bytes: 1024
//jinhaonan
#include<set>
#include<map>
#include<list>
#include<ctime>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<sstream>
#include<numeric>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define For(i,x,y) for(int i=x,_y=y;i<=_y;++i)
#define Rep(i,x,y) for(int i=x,_y=y;i>=_y;--i)
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
inline int read()
{
	int x=0;char c=getchar();bool f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';x=(x<<1)+(x<<3)+c-'0',c=getchar());
	return f?-x:x;
}
inline void write(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+48);
}
const int N=1e5+10;
int n,k,pos,ans=2e9,x[N];
int main()
{
	n=read(),k=read();
	For(i,1,n)x[i]=read();
	pos=lower_bound(x+1,x+n+1,0)-x-1;
	For(l,0,pos)
	{
		int r=max(0,k-l),ll=0,rr=0;
		if(r>n-pos)continue;
		if(l>0)ll=-x[pos-l+1];
		if(r>0)rr=x[r+pos];
		ans=min(ans,ll+ll+rr);
		ans=min(ans,ll+rr+rr);
	}
	write(ans);puts("");
}

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

#define fs first
#define sc second

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


// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    bool a = 1;
    for (auto e : v ) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << " " << p.second << ")";
    return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::multiset Debug
template<typename T>
ostream& operator<<(ostream& os, const multiset<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
    os << "{";
    bool a = 1;
    for (auto e : mp) {
        os << (a ? "" : " ");
        os << e.first << ":" << e.second;
        a = 0;
    }
    os << "}";
    return os;
}

// std::tuple Debug
template<int N, class Tuple>
void out(ostream& os, const Tuple& t){}
template<int N, class Tuple, class H, class ...Ts>
void out(ostream& os, const Tuple& t) {
    if (N) os << " ";
    os << get<N>(t);
    out<N+1,Tuple,Ts...>(os, t);
}
template<class ...Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
    os << "(";
    out<0,tuple<Ts...>,Ts...>(os, t);
    os << ")";
    return os;
}

// Debug
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl


struct edge { int to, cost; };
ostream& operator<<(ostream& os, const edge& e) {
    os << "(" << e.to << ", " << e.cost << ")";
    return os;
}

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

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

    cout << max(c - (a - b), 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
char map[60][60];
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
int main(){
	int n,m;
	while(cin>>n>>m){
		getchar();
		for(int i=0;i<n;i++) scanf("%s",map[i]);
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(map[i][j]=='.'){
					int res=0;
					for(int k=0;k<8;k++){
						if(map[i+dx[k]][j+dy[k]]=='#'){
							res++;
						}
					}
					map[i][j]=res+'0';
				}
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				cout<<map[i][j];
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>

bool binarySearch(int first, int last, int val, int * S) {
    if (first + 1 == last) {
        return val == S[first];
    }
    int idx = (first + last) / 2;

    if (val < S[idx]) {
        return binarySearch(first, idx, val, S);
    } else if (val > S[idx]) {
        return binarySearch(idx, last, val, S);
    } else if (val == S[idx]) {
        return true;
    }
    return false;
}


int main(int argc, char ** argv) {
    int n, q;
    std::cin >> n;
    int S[n];
    for (int i = 0; i < n; i++) {
        std::cin >> S[i];
    }

    std::cin >> q;
    int count = 0;
    for (int i = 0; i < q; i++) {
        int val;
        std::cin >> val;
        if (binarySearch(0, n, val, S)) {
            count++;
        }
    }

    std::cout << count << std::endl;
}



Measured memory_bytes: 3384
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int n, K;
    scanf("%d%d", &n, &K);
    vector<int> p(n), c(n), flag(n);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d", &p[i]); p[i]--;
    }
    for (i = 0; i < n; i++) {
        scanf("%d", &c[i]);
    }
    vector<vector<int> > z;
    for (i = 0; i < n; i++) {
        if (flag[i]) continue;

        vector<int> z0;
        int curr = i;
        while (1) {
            z0.push_back(c[curr]);
            flag[curr] = 1;

            int next = p[curr];
            if (next == i) {
                break;
            }
            curr = next;
        }
        z.push_back(z0);
    }

    ll ans = -LINF;
    for (i = 0; i < (int)z.size(); i++) {
        vector<int>& z0 = z[i];

        int num = (int)z0.size();
        vector<int> a;
        vector<ll> sa(num * 2 + 1);
        int j, k;
        for (j = 0; j < num; j++) {
            a.push_back(z0[j]);
        }
        for (j = 0; j < num; j++) {
            a.push_back(z0[j]);
        }
        for (j = 0; j < num * 2; j++) {
            sa[j + 1] = sa[j] + a[j];
        }
        
        if (sa[num] <= 0 || K<=num) {
            ll K2 = MIN(K, num);
            for (j = 0; j < num * 2; j++) {
                for (k = 1; k <= K2; k++) {
                    int j2 = j + k;
                    if (j2 <= num * 2) {
                        ans = MAX(ans, sa[j2] - sa[j]);
                    }
                }
            }
        }
        else {
            for (k = 1; k <= num; k++) {
                ll A=(K - k) / num;
                ll add = A * sa[num];

                for (j = 0; j < num * 2; j++) {                    
                    int j2 = j + k;
                    if (j2 <= num * 2) {
                        ans = MAX(ans, add+sa[j2] - sa[j]);
                    }
                }
            }
        }
    }
    printf("%lld\n", ans);


    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}


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

int main(){
    long long ans = 0, n;
    cin >> n;
    for(long long i = 1; i <= n; i++)
        for(long long j = 1; j*i <= n; j++)
            ans += i*j;
    cout << ans << '\n';
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>

using namespace std;

string s, t;
bool flag = false;


void Work()
{
    int lens = s.size();
    int lent = t.size();
    string ans(lens, 'z');

    for(int i = 0; i < lens; i++)
    {
        if(s[i] == '?' || s[i] == t[0])
        {
            string tmp = s;
            for(int j = 0; j < i; j++)
                if(tmp[j] == '?')
                    tmp[j] ='a';
            bool can = false;
            for(int j = 0; j < lent; j++)
            {

                if(tmp[i+j]!= '?' && tmp[i+j] != t[j])
                    break;
                tmp[i+j] = t[j];
                if(j == lent - 1) can = true;
            }
            if(can)
            {
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';
                if(tmp<ans)
                {
                    ans = tmp;
                    flag = true;
                }
            }
        }
    }
    if(!flag) cout << "UNRESTORABLE" << endl;
    else cout << ans << endl;
}
int main()
{
    cin >> s >> t;
    Work();
}






















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

int find(int a,vector<int>&uf){
	if(a==uf.at(a))return a;
	return uf.at(a)=find(uf.at(a),uf);
}

bool same(int a,int b,vector<int>&uf){
	return find(a,uf)==find(b,uf);
}

void unite(int a,int b,vector<int>&uf){
	a=find(a,uf),b=find(b,uf);
	if(a==b)return;
	uf.at(a)=b;
}

void ufinit(vector<int>&uf){
	for(int i=0;i<uf.size();++i){
		uf.at(i)=i;
	}
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m; cin>>n>>m;
	vector<pair<int,int>>path(m);
	for(auto&&i:path)cin>>i.first>>i.second,--i.first,--i.second;
	int ans=0;
	for(int i=0;i<m;++i){
		vector<int>uf(n); ufinit(uf);
		for(int j=0;j<m;++j){
			if(i==j)continue;
			unite(path.at(j).first,path.at(j).second,uf);
		}
		if(!same(path.at(i).first,path.at(i).second,uf))++ans;
	}
	cout<<ans<<"\n"s;
}


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

int main() {
  
  int64_t A, B, C; cin >> A >> B >> C;
  
  int64_t dif1, dif2, dif3;
  
  dif1 = A * B; dif2 = B * C; dif3 = C * A;
  
  if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) cout << 0 << endl;
  
  else cout << min(dif1, min(dif2, dif3)) << endl;
  
}

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

using namespace std;
typedef long long ll;

ll expo(ll b, ll e) {
    if(!e) return 1;
    b %= MOD;
    if(e & 1) return b * expo(b * b, e >> 1) % MOD;
    return expo(b * b, e >> 1);
}

ll inv_mod(ll x) { return expo(x, MOD - 2); }

ll fat[MN], ifat[MN], n, k;

void prep() {
    fat[0] = 1;
    for(int i = 1; i < MN; i++)
        fat[i] = fat[i-1] * i % MOD;
    ifat[MN-1] = inv_mod(fat[MN-1]);

    for(int i = MN-1; i > 0; i--)
        ifat[i-1] = ifat[i] * i % MOD;
    assert(ifat[0] == 1);
}

ll nCr(ll n, ll k) {
    if(n < 0) return 1;
    if(k < 0 || k > n) { return 0;}
    return fat[n] * ifat[k] % MOD * ifat[n-k] % MOD;
}

ll tbl[2][MN][MN], acum[2][MN][MN];

void calc(int z) {
    for(int i = 0; i < MN; i++)
        acum[z][0][i] = tbl[z][0][i] + ((i) ? acum[z][0][i-1] : 0);

    for(int r = 1; r < MN; r++) {
        tbl[z][r][0] = acum[z][r][0] = tbl[z][r-1][0] % MOD;
        for(int c = 1; c < MN; c++) {
            tbl[z][r][c] = (tbl[z][r-1][c] + 2*acum[z][r-1][c-1]) % MOD;
            acum[z][r][c] = (acum[z][r][c-1] + tbl[z][r][c]) % MOD;
        }
    }
}

int main() {
    prep();
    tbl[0][0][0] = tbl[1][0][0] = tbl[1][0][1] = 1;
    calc(0); calc(1);

    scanf("%lld %lld", &k, &n);

    for(int i = 2; i <= 2*k; i++) {
        int rite = min(k, i - 1LL);
        int left = i - rite;
        int sz = (rite - left + 1);
        int row = (sz&1) ? (sz/2) : (sz+1)/2;

        ll ans = 0;
        for(int j = 0; j <= n; j++) {
            ans = (ans + nCr(j+k-sz-1, j) * tbl[sz&1][row][n-j]) % MOD;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 501376
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Tuple (swap)
import Data.List (sortBy)
import Data.Function (on)
import qualified Data.IntSet as IS

main :: IO ()
main = do
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    initialize :: [(Int, Int)] -> (IS.IntSet, Int, Int, [Int], [(Int, Int)])
    initialize = go k IS.empty 0 0 []
      where
        go :: Int -> IS.IntSet -> Int -> Int -> [Int] -> [(Int, Int)] -> (IS.IntSet, Int, Int, [Int], [(Int, Int)])
        go 0 us0 dp0 tp0 ds0 cs0 = (us0, dp0, tp0, ds0, cs0)
        go c us dp tp ds ((d, t) : dts)
            | IS.member t us = go c' us dp' tp ds' dts
            | otherwise      = go c' us' dp' tp' ds dts
          where
            c' = pred c :: Int
            us' = IS.insert t us :: IS.IntSet
            dp' = dp + d :: Int
            tp' = succ tp :: Int
            ds' = d : ds :: [Int]
    maxSP ::  (IS.IntSet, Int, Int, [Int], [(Int, Int)]) -> Int
    maxSP (us0, dp0, tp0, ds0, cs0) = go cs0 us0 ds0 dp0 tp0 sp0
      where
        sp0 = dp0 + tp0 ^ 2 :: Int
        go :: [(Int, Int)] -> IS.IntSet -> [Int] -> Int -> Int -> Int -> Int
        go ((d, t) : cs') us ds@(d' : ds') dp tp sp
            | IS.member t us = go cs' us ds dp tp sp
            | otherwise      = go cs' us' ds' dp' tp' sp'
          where
            us' = IS.insert t us :: IS.IntSet
            dp' = dp - d' + d :: Int
            tp' = succ tp :: Int
            sp' = max sp (dp' + tp' ^ 2) :: Int
        go _ _ _ _ _ sp = sp
  tds <- sequence . replicate n $ unsafeListToPair . map unsafeTextToInt . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    dts = sortBy (flip compare `on` fst) . map swap $ tds :: [(Int, Int)]
  print . maxSP . initialize $ dts

unsafeListToPair :: [a] -> (a, a)
unsafeListToPair [x, y] = (x, y)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 58748
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
pair<string, int>A[101];
signed main() {
  string S; cin>>S;
  int count=0;
  bool B=false;
  int coun=0;
  rep(i,S.size()){
    if(S.at(i)=='A'||S.at(i)=='C'||S.at(i)=='G'||S.at(i)=='T'){
      B=true;
      coun++;
    }
    else if(B==true){
      count=max(count,coun);
      coun=0;
    }
  }
  count=max(count,coun);
  cout<<count<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-10;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
int n, m;
int single[111111], all[111111];
struct magic { int mp, tar, dam; };

int main()
{
	while (cin >> n, n)
	{
		fill(ALL(single), INF); fill(ALL(all), INF);
		vi hp(n);
		vector<magic> v;
		REP(i, n) cin >> hp[i];
		cin >> m;
		REP(i, m)
		{
			string s, t; int a, b, c;
			cin >> s >> a >> t >> b;
			if (t == "Single") c = 0;
			else c = 1;
			v.push_back(magic{ a, c, b });
		}
		single[0] = all[0] = 0;
		REP(i, 100001)
		{
			REP(j, v.size())
			{
				chmin(single[min(100000, i + v[j].dam)], single[i] + v[j].mp);
				if(v[j].tar==1) chmin(all[min(100000, i + v[j].dam)], all[i] + v[j].mp);
			}
		}
		for (int i = 100000; i >= 0; i--)
		{
			chmin(single[i], single[i + 1]);
			chmin(all[i], all[i + 1]);
		}
		ll ans = INF;
		REP(i, 100001)
		{
			ll cnt = all[i];
			vi tmp = hp;
			REP(j, tmp.size()) tmp[j] = max(0, tmp[j] - i);
			REP(j, tmp.size()) cnt += single[tmp[j]];
			chmin(ans, cnt);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2100
using System;
class p
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    string S = Console.ReadLine();
    int num = 0, max = 0;
    for (int i = 0; i < N; i++) {
      num = (S[i] == 'I') ? (num + 1) : (num - 1);
      max = Math.Max(max, num);
    }
    Console.WriteLine(max);
  }
}

Measured memory_bytes: 13140
n, m = map(int, input().split())
one = [0 for i in range(n + 1)]
edges = []
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        one[b] = 1
    if b == 1:
        one[a] = 1
    else:
        edges.append((a, b))
for a, b in edges:
    if one[a] and b == n or one[b] and a == n:
        print('POSSIBLE')
        exit(0)
print('IMPOSSIBLE')


Measured memory_bytes: 31664
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main() {
	string S; cin >> S;
	vector<char> res(500000);
	bool dir = true;
	int left = 200001, right = left + S.size() - 1;
	for (int i = left; i <= right; ++i)
		res[i] = S[i - 200001];
	int Q; cin >> Q;
	while (Q--) {
		int t; cin >> t;
		if (t == 1) {
			dir = dir ? false : true;
		}
		else {
			int f; cin >> f;
			char c; cin >> c;
			if ((f == 1) ^ dir) { // right + 1に
				res[++right] = c;
			}
			else { // left - 1に
				res[--left] = c;
			}
		}
	}
	if (dir) {
		for (; left <= right; ++left)
			cout << res[left];
	}
	else {
		for (; left <= right; --right)
			cout << res[right];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1280
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// メイン
int main()
{
	// 入力
	int x, a, b;
	cin >> x >> a >> b;

	int now = b - a;
	if (now <= 0) {
		cout << "delicious" << endl;
	} else if (now <= x) {
		cout << "safe" << endl;
	} else {
		cout << "dangerous" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main(){
long long n , a[200005] , ans=0 ,kind[200005]={};
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        kind[a[i]]++;
    }
    
    for(int i=0;i<=n;i++){
        ans += kind[i] * (kind[i] -1) / 2;
    }
    
    for(int i=0;i<n;i++){
        cout << ans - kind[a[i]] * (kind[a[i]]-1) / 2 + (kind[a[i]]-1) * (kind[a[i]]-2) / 2 << endl;
    }
    return(0);
}

Measured memory_bytes: 5760
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int amount = sc.nextInt();
        int hour = amount/3600;
        int min = (amount-(hour*60*60))/60;
        int sec = amount-(hour*60*60)-(min*60);
        System.out.println(hour+":"+min+":"+sec);
    }
}


Measured memory_bytes: 26268
#include<iostream>
using namespace std;
typedef long long int llint;
llint arr[100005],sum[100005],sum2[100005];
int main()
{
	int n,k;
	cin >> n >> k;
	for(int i=0;i<n;i++) {
		cin >> arr[i];
		if(i==0) sum[i]=arr[i];
		else sum[i]=sum[i-1]+arr[i];
		if(i==0) {
			if(arr[i]>=0) sum2[i]=arr[i];
			else sum2[i]=0;
		}
		else {
			if(arr[i]>=0) sum2[i]=sum2[i-1]+arr[i];
			else sum2[i]=sum2[i-1];
		}
	}
	/*for(int i=0;i<n;i++) {
		cout <<sum2[i]<<" ";
	}
	cout <<endl;*/
	long long int maxi=0;
	for(int i=0;i<n-k+1;i++) {
		//cout <<i<<endl;
		long long int s=0;
		if(i>0) s+=sum2[i-1];
		//cout <<i<<" "<<s<<endl;
		s+=sum2[n-1]-sum2[i+k-1];
		//cout <<i<<" "<<s<<endl;
		if(i==0) {
			if(sum[i+k-1]>=0) maxi=max(maxi,s+sum[i+k-1]);
			else maxi=max(maxi,s);
		}
		else {
			if(sum[i+k-1]-sum[i-1]>=0) maxi=max(maxi,s+sum[i+k-1]-sum[i-1]);
			else maxi=max(maxi,s);
		}
	}
	cout <<maxi;
	return 0;
}


Measured memory_bytes: 2560
# include "iostream"
# include "cstdio"
# include "cmath" 

using namespace std;

int n; 

void Dfs(int n){
	if(n==0) return;
	int now=n%2;
	if(now) n--; 
	Dfs(n/(-2)); 
	printf("%d",abs(now)); 
	return; 
}

int main(){
	scanf("%d",&n); 
	if(n==0){
		printf("0"); 
	}else{
		Dfs(n); 
	}
	return 0; 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char str1[100];
char str2[100];
char str3[200];
int main()
{
	int n,i,j=0,k=0;
	scanf("%d",&n);
	scanf("%s",str1);
	scanf("%s",str2);
	for(i=0;i<n*2;i++)
	{
		if(i%2==0) 
		{
		str3[i]=str1[j];
		j++;}
		else{
		 str3[i]=str2[k];
		 k++;
	}
	}
	printf("%s",str3);
	return 0;
}

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

using namespace std;

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

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

    int next[N];
    fill(next, next+N, 0);
    bool battled[N];

    int cnt = 0;
    int ans = 0;
    while(cnt != N){
        cnt = 0;
        ans++;
        fill(battled, battled+N, false);

        //cout << "### Day " <<  ans << " ###" << endl;
        for(int i=0; i<N; i++){
            //cout << "--- " <<  i << " ---" << endl;
            
            //その日は戦い済み
            if(battled[i]) continue;

            //全日程を終了している
            if(next[i] == N-1){
                cnt++;
                continue;
            }

            int enemy = A[i][next[i]];

            //cout << i << " " << A[i][next[i]] << " " << enemy  << " " << A[enemy][next[enemy]] << endl;

            //相手の次の対戦者が自分かつまだ対戦可能なら
            if(A[enemy][next[enemy]] == i && !battled[enemy] && next[enemy] != N-1){
                next[i]++;
                next[enemy]++;
                battled[i] = true;
                battled[enemy] = true;
            }
            if(!battled[i]) cnt++;
        }
    }

    ans--;

    bool b = false;
    for(int i=0; i<N; i++){
        if(next[i] != N-1) b = true;
    }
    if(b) ans = -1;
    cout << ans;

    return 0;
}

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

int main() {
    int n;
    cin>>n;
    vector<int>p(n);
    for(int i=0;i<n;i++) cin>>p.at(i);
    int sum=0;
    for(int i=1;i<n-1;i++){
        if(p.at(i-1)<p.at(i) and p.at(i)<p.at(i+1)) sum++;
        else if(p.at(i-1)>p.at(i) and p.at(i)>p.at(i+1)) sum++;

    }
    cout<<sum<<endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "YES" << endl;}
void no(){ cout << "NO" << endl;}

//-----------------------------------------
//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, k;
  cin >> n >> k;

  vll a(n);
  vll seen(n,0);
  vll dis(n,INF);

  REP(i,n) {cin >> a[i]; a[i]--;}

  ll x, y;
  seen[0] = 1;
  dis[0] = 0;
  ll j = 0;

  while(1){
    ll tmp = a[j];
    if(seen[tmp] == 0){
      dis[tmp] = dis[j] + 1;
      seen[tmp] = 1;
    }
    else{
      x = dis[tmp];
      y = dis[j] - dis[tmp] + 1;
      break;
    }
    j = tmp;
  }

  //cout << x << " " << y  << endl;

  if(k < x){
    REP(i,n) if(dis[i] == k) cout << i+1 <<endl;
  }
  else{
    REP(i,n) if(dis[i] == (k - x) % y + x) cout << i + 1 <<endl;
  }



  return 0;
}



Measured memory_bytes: 7908
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P)
{
    int i = 0;
    for(int j = 0; j < k; j++)
    {
        llong s = 0;
        while(s + T[i] <= P)
        {
            s += T[i];
            i++;
            if(i == n)
                return n;
        }
    }
    return i;
}

llong search()
{
    llong left = 0, right = MAX * 10000;
    llong middle;
    while(right - left > 1)
    {
        middle = (left + right) / 2;
        int v = check(middle);
        if(v >= n)
            right = middle;
        else
            left = middle;
    }
    return right;
}

int main()
{
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> T[i];
    llong ans = search();
    cout << ans << endl;
}


Measured memory_bytes: 3900
#include <stdio.h>
#define N 123456*2+5

int main(void){
    int a[N],i,j,l=1,count;
    
    for(i=0;i<N;i++)
        a[i]=1;
    a[0]=a[1]=0;
    for (i=2; i*i<N; i++) {
        if(a[i])
            for (j=i+i; j<N; j=j+i) {
                a[j]=0;
            }
    }
   
    
    while(1){
        scanf("%d",&l);
        if(l==0)break;
        
        count=0;
        for(i=l+1;i<=2*l;i++)
            if(a[i])
                count++;
        printf("%d\n",count);
    }
    
    return 0;
}

Measured memory_bytes: 1564
class KMP:
    def __init__(self, P):
        self.P = P
        self.N = len(P)
        self.T = [0] * (self.N + 1)
        self._compile()

    def _compile(self):
        j = 0
        self.T[0] = -1
        for i in range(1, self.N):
            self.T[i] = j
            j += 1 if self.P[i] == self.P[j] else -j
        self.T[self.N] = j

    def search(self, S):
        NS = len(S)
        i = m = 0
        A = []
        while m + i < NS:
            if self.P[i] == S[m + i]:
                i += 1
                if i != self.N:
                    continue
                A.append(m)
            m += i - self.T[i]
            i = max(0, self.T[i])
        return A

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [A[i]^A[(i+1)%N] for i in range(N)]
D = [B[i]^B[(i+1)%N] for i in range(N)]
C = C + C[:-1]
K = KMP(D).search(C)
for k in K:
    print(k, A[k]^B[0])

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

int main(){
  int n, s;
  cin >> n >> s;
  int a[n];
  rep(i,n) cin >> a[i];
  int l = 0;
  int ans = INF;
  int sum = 0;
  rep(r,n) {
    sum += a[r];
    while(l < r && sum - a[l] >= s) {
      sum -= a[l];
      l++;
    }
    if(sum >= s) ans = min(ans,r-l+1);
  }
  cout << (ans == INF ? 0 : ans) << endl;
  return 0;
}


Measured memory_bytes: 3484
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		String s = sc.next();

		for(int i = 0; i < n; i++) {
			if(i == m-1) {
				System.out.print(s.toLowerCase().charAt(i));
			} else {
				System.out.print(s.charAt(i));
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 21844
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
HH = inpl()
HH[0] -= 1
for i in range(N-1):
    #print(HH)
    if HH[i+1]-HH[i] > 0:
        HH[i+1] -= 1
    elif HH[i+1]-HH[i] == 0:
        continue
    else:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 15992
#include<bits/stdc++.h>
#define ns "-1"
#define fs(i,x,y,z) for(ll i=x;i<=y;i+=z)
#define ft(i,x,y,z) for(ll i=x;i>=y;i+=z)
#define ll long long
#define ull unsigned long long
#define db double
#define ms(a,b) memset(a,b,sizeof(a))
#define sz(a) sizeof(a)
using namespace std;
const int rw[]={-1,0,1,0,-1,1,-1,1},cl[]={0,1,0,-1,-1,1,1,-1};
const int N=100001,inf=0x7f7f7f7f;
const db E=2.718281828459,pi=acos(-1.0),eps=0.0000000001;
inline bool xr(bool x,bool y){
	return x==y?0:1;
}
inline int read(){
	int date=0,w=1;char c=0;
	while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
	while(c>='0'&&c<='9'){date=date*10+c-'0';c=getchar();}
	return date*w;
}
ull ksm(ull a,ull b){
    ull ans=1,base=a;
    while(b){
        if(b&1){
            ans*=base;
	    }
	    base*=base;
	    b>>=1;
	}
    return ans;
}
ll gcd(ll a,ll b){
    if(b) return gcd(b,a%b);
    return a;
}
bool prm(ll k){
	if(k<2) return 0;
	if(k==2||k==3||k==5) return 1;
	if(k%2==0||k%3==0||k%5==0) return 0;
	fs(i,7,sqrt(k)+1,2) if(k%i==0) return 0;
	return 1;
}
int n,a[N];
//#include<somo.h>
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
    cout.tie(0);
    cin>>n;
    if(n<1200) cout<<"ABC\n";
    else cout<<"ARC\n";
	return 0;
}


Measured memory_bytes: 256
from itertools import accumulate

n, k = map(int, input().split())
p = map(int, input().split())

ac = [0] + list(accumulate(map(lambda x: (1 + x) / 2, p)))
ans = max(ac[i+k] - ac[i] for i in range(n - k + 1))
print(ans)


Measured memory_bytes: 23616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1') {
			cout << 9;
		}
		else {
			cout << 1;
		}
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
use proconio::{fastout, input};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        s: [String; n],
    }
    let mut h = HashMap::new();
    for i in 0..n {
        if h.get(&s[i]) != None {
            h.insert(&s[i], h.get(&s[i]).unwrap() + 1);
        } else {
            h.insert(&s[i], 1);
        }
    }

    println!("{}", h.len());
}


Measured memory_bytes: 21692
A=[]
B=[]
a=i=0
for c in input():
 if"\\"==c:A+=[i]
 elif"/"==c and A:
  j=A.pop()
  t=i-j
  a+=t
  while B and B[-1][0]>j:t+=B[-1][1];B.pop()
  B+=[(j,t)]
 i+=1
print(a)
if B:print(len(B),*list(zip(*B))[1])
else:print(0)


Measured memory_bytes: 6500
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  for(int a = 1; a < 10; a++){
    for(int b = 1; b < 10; b++){
      if(a*b == N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll a[n],i;
    for(i=0;i<n;i++)
    cin>>a[i];
    
    ll sum=0,temp=a[0];
    for(i=1;i<n;i++)
    {
        if(a[i]<temp)
        {
            sum+=(temp-a[i]);
            a[i]=temp;
        }
        
        temp=a[i];
    }
    cout<<sum;
}




Measured memory_bytes: 5132
/*author: hyperion_1724
  date: 
*/

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(int i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define endl '\n'
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(int a=b;a<c;a++)
#define FORD(a,b,c) for(int a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

	READV(N);
	READV(D);
	cout<<ceil(((ld)N)/((ld)(2*D+1)))<<endl;

	return 0;
}

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

int main()
{
  int N;
  std::cin >> N;
  std::vector<std::map<int, int>> candy(2);
  for(int i = 0; i < 2; i++) {
    for(int j = 0; j < N; j++) {
      int num;
      std::cin >> num;
      candy[i].insert(std::make_pair(j, num));
    }
  }
  int answer = 0;
  for(int i = 0; i < N; i++) {
    int ans = std::accumulate(candy[0].begin(), std::next(candy[0].begin(), i + 1), 0, [](const int sum, std::pair<int, int> num){return sum + num.second;});
    ans += std::accumulate(std::next(candy[1].begin(), i), candy[1].end(), 0, [](const int sum, std::pair<int, int> num){return sum + num.second;});
    answer = std::max(answer, ans);
  }
  std::cout << answer << std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int sum=0;
    for(int i=1;i<=n;i++){
      if(String.valueOf(i).length()%2==1){
        sum++;
      }
    }
    System.out.println( sum );
  }
}

Measured memory_bytes: 27860
/*
   Author : tarang
*/
#include<bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define PI = acos(-1)
using namespace std ;
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll f(ll x){
	if(x%4 == 0){
		return x ;
	}
	else if(x%4 == 1){
		return 1 ;
	}
	else if(x%4 == 2){
		return (x+1) ;
	}
	else return 0 ;
}
int main(){
	 ll a , b ;
	 cin >> a >> b ;
	 cout << (f(b)^f(a-1)) << endl;
}

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

int main()
{
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i< N; ++i) cin >> A[i];
    for(int i = 0; i < N-1; ++i) printf("%d ", A[i]);
    printf("%d\n", A[N-1]);
    for(int i = 1; i < N; ++i) {
        
        int v = A[i];
        int j = i-1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            --j;
        }
        A[j+1] = v;
        for(int j = 0; j < N-1; ++j) cout << A[j] << " ";
        cout << A[N-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3228
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)



int main() {
	unordered_map<ll, ll> mp;
	int N;
	cin >> N;
	ll res = 0;
	repi(i, 1, N + 1) {
		ll a;
		cin >> a;
		ll k = i - a;
		if (mp.count(k) != 0)res += mp[k];
		if (mp.count(a + i) != 0) mp[a + i] += 1;
		else mp.insert(pair<ll, ll>(a + i, 1));
	}
	cout << res << endl;
	return 0;
}


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

int main(void){
    int a, b, x;
    for(int i = 0; i < 4; i++){
        cin >> a >> b;
        if(a == 1){
            x = 6000*b;
        }
        else if(a == 2){
            x = 4000*b;
        } 
        else if(a == 3){
            x = 3000*b;
        }
        else{
            x = 2000*b;
        }
        cout << x << endl;
    }
}



Measured memory_bytes: 3100
def solve(n, a, s)
  res=0
  sum=a[0]
  if sum*s <= 0
    res += sum.abs + 1
    sum = s
  end
  1.upto(n-1) do |i|
    pre = sum
    sum += a[i]
    next if pre*sum < 0
    res += sum.abs + 1
    sum = pre<0 ? 1 : -1
  end
  res
end

n=gets.to_i
a=gets.split.map &:to_i
p [solve(n, a.dup, 1), solve(n, a.dup, -1)].min


Measured memory_bytes: 8580
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)

readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

main = do
  xy <- readInts
  if or $ map (\c -> and $ map (flip elem c) xy) cs
    then putStr "Yes\n" 
    else putStr "No\n"
    where
      cs = [[1, 3, 5, 7, 8, 10, 12],
            [4, 6, 9, 11],
            [2]]
  


Measured memory_bytes: 380
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

int main() {
  queue<char> q;
  char c;
  while (cin >> c) {
    q.push(c);
  }

  ll l, r, sum = 0;
  while (!q.empty()) {
    l = 0;
    r = 0;
    while (q.front() == '<') {
      l++;
      q.pop();
    }
    while (q.front() == '>') {
      r++;
      q.pop();
    }

    if (r > l) swap(l, r);
    sum += l * (l + 1) / 2 + r * (r - 1) / 2;
  }

  cout << sum << endl;

  
  return 0;
}

Measured memory_bytes: 768