akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pre(i,a,b) for(int i=(a);i>(b);i--)
const int maxn=1e5+10;
const int mod=998244353;
const int inf=0x3f3f3f3f;
struct node
{
	ll data,lz;
	int l,r;
}tree[maxn*4];
void build(int l,int r,int k)
{
	tree[k].l=l;
	tree[k].r=r;
	tree[k].data=1e18;
	tree[k].lz=0;
	if(l==r) return ;
	int mid=(l+r)>>1;
	build(l,mid,2*k);
	build(mid+1,r,2*k+1);
}
void pushdown(int k)
{
	if(tree[k].lz==0) return ;
	if(tree[2*k].lz==0) tree[2*k].lz=tree[k].lz;
	else tree[2*k].lz=min(tree[2*k].lz,tree[k].lz);
	if(tree[2*k+1].lz==0) tree[2*k+1].lz=tree[k].lz;
	else tree[2*k+1].lz=min(tree[2*k+1].lz,tree[k].lz);
	tree[2*k].data=min(tree[2*k].data,tree[k].lz);
	tree[2*k+1].data=min(tree[2*k+1].data,tree[k].lz);
	tree[k].lz=0;
}
void change(int l,int r,int k,ll x)
{
	if(tree[k].l>=l&&tree[k].r<=r)
	{
		if(tree[k].lz==0) tree[k].lz=x;
		else tree[k].lz=min(tree[k].lz,x);
		tree[k].data=min(tree[k].data,x);
		return ;
	}
	pushdown(k);
	int mid=(tree[k].l+tree[k].r)>>1;
	if(mid>=l) change(l,r,2*k,x);
	if(mid<r) change(l,r,2*k+1,x);
	tree[k].data=min(tree[2*k].data,tree[2*k+1].data);
}
ll query(int l,int r,int k)
{
	ll ans=1e18;
	if(tree[k].l>=l&&tree[k].r<=r)return tree[k].data;
	pushdown(k);
	int mid=(tree[k].l+tree[k].r)>>1;
	if(mid>=l) ans=min(ans,query(l,r,2*k));
	if(mid<r) ans=min(ans,query(l,r,2*k+1));
	return ans;
}
struct abc
{
	int l,r,c;
	friend bool operator<(abc a,abc b)
	{
		return a.l<b.l;
	}
}book[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	build(1,n,1);
	for(int i=0;i<m;i++) cin>>book[i].l>>book[i].r>>book[i].c;
	sort(book,book+m);
	change(1,1,1,0);
	for(int i=0;i<m;i++)
	{
		ll now=query(book[i].l,book[i].l,1);
		change(book[i].l,book[i].r,1,now+book[i].c);
	}
	ll ans=query(n,n,1);
	if(ans>1e15) cout<<-1<<'\n';
	else cout<<ans<<'\n';
    return 0;
}



Measured memory_bytes: 8448
s = input()
t = input()
sl = len(s)
ss = ""
used = [False]*26
cnt = 0
for i in range(sl):
    if used[(ord(s[i])-97)%26]:
        ss += str(used[(ord(s[i])-97)%26])
    else:
        cnt += 1
        ss += str(cnt)
        used[(ord(s[i])-97)%26] = cnt

used = [False]*26
tt = ""
cnt = 0
for i in range(sl):
    if used[(ord(t[i])-97)%26]:
        tt += str(used[(ord(t[i])-97)%26])
    else:
        cnt += 1
        tt += str(cnt)
        used[(ord(t[i])-97)%26] = cnt

if ss==tt:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9956
#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const long long INF = 1LL << 61;

int main() {
	int N; cin >> N;
	vector<int> H(N);
	rep(i, N)cin >> H[i];

	int ans = 0;
	int count = 0;
	rep(i, N-1) {
		if (H[i] >= H[i + 1])count++;
		else {
			if (count > ans)ans = count;
			count = 0;
		}
	}
	if (count > ans)ans = count;
	cout << ans;
}

Measured memory_bytes: 640
import sys, math
from collections import defaultdict
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

S = rs()

L = len(S)

dp = [[0] * 13 for i in range(L+1)]

R = [0]*L
d = 1
for i in range(L):
	d %= 13
	R[i] = d
	d *= 10
R.reverse()

dp[0][0] = 1

for i in range(L):
	for j in range(13):
		if S[i] == '?':
			for k in range(10):
				r = (k * R[i] + j) % 13
				dp[i+1][r] = (dp[i+1][r] + dp[i][j]) % mod
		else:
			r = (int(S[i]) * R[i] + j) % 13
			dp[i+1][r] = (dp[i+1][r] + dp[i][j]) % mod
print(dp[L][5])


Measured memory_bytes: 98372
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(s.charAt(i));
            sb.append(t.charAt(i));
        }
        System.out.println(sb.toString());
    }

}


Measured memory_bytes: 21076
import numpy as np
n,d=map(int,input().split())

nums=[]

for i in range(n):
    nums.append(list(map(int,input().split())))

#print(nums)

ans=[]

for j in range(n-1):
    for k in range(j+1,n):
        x=abs(np.array(nums[j])-np.array(nums[k]))
        #print(x)
        y=x**2
        #print(y)
        z=np.sqrt(sum(y))
        #print(z)
        ans.append(z)
cnt=0
#print(ans)
for a in ans:
    if a.is_integer():
        cnt+=1
print(cnt)


Measured memory_bytes: 14432
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string s; cin >> s;
    cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << '\n';
}


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

int main() {
    int n;
    bool color[8];
    for (int i = 0; i < 8; i++) {
        color[i] = false;
    }
    int free = 0;

    cin >> n;
    for (int i = 0; i < n; i++) {
        int rate;
        cin >> rate;
        if (rate < 3200) {
            color[rate / 400] = true;
        } else {
            free++;
        }
    }

    int sum = 0;
    for (int i = 0; i < 8; i++) {
        if (color[i]) sum++;
    }

    cout << max(1, sum) << " " << (sum + free) << endl;

    return 0;
}


        


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(int)a;i<(int)b;i++)
#define revrep(i,a,b) for(i=(int)a;i>=(int)b;i--)
#define ii pair<int,int>
#define pb push_back
#define f first
#define s second
#define ll long long int
#define vi vector<int>
#define rs resize
bool is[10];
int main()
{  std::ios::sync_with_stdio(false);
   int m,n,i,h;
   cin>>m>>n;
   rep(i,0,n)
   {
      cin>>h;
      is[h] = true;
   }
   i = m;
   bool flag;
   while(1)
   {
      h = i;
      flag = true;
      while(h>0)
      {
        if(is[h%10])
        {
          flag = false;
          break;
        }
        h/=10;
      }
      if(flag)
       break;
      i++;
   }
   cout<<i;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=15;
int sum=1e9,n,m,p[N],c[N];
signed main()
{
	scanf("%d%d",&n,&m);
	for (int i=0;i<n;i++)scanf("%d%d",&p[i],&c[i]);
	for (int t=0;t<1<<n;t++)
	 {
	 	int num=0,ans=0;
	 	for (int i=0;i<n;i++)
	 	 if ((1<<i)&t)num+=c[i]+p[i]*100*(i+1),ans+=p[i];
	 	for (int i=n-1;i>=0;i--)
		 if (num<m&&!((1<<i)&t))
		  {
		  	int s=min(p[i]-1,(m-num-1)/(100*(i+1))+1);
		  	num+=s*100*(i+1);
		  	ans+=s;
		  } 
		if (m<=num)sum=min(sum,ans);  
	 }
	printf("%d\n",sum); 
	return 0; 
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(void){
 
  char sa[101];
  char sb[101];
  char sc[101];
  scanf("%s", sa);
  scanf("%s", sb);
  scanf("%s", sc);
  int a_length = strlen(sa);
  int b_length = strlen(sb);
  int c_length = strlen(sc);
  int a = a_length;
  int b = b_length;
  int c = c_length;
  int player = 0;
  while (1) {
    if (player == 0) {
      if (a == 0) {
        printf("A\n");
        break;
      }
      player = sa[a_length-a] - 'a';
      a--;
    } else if (player == 1) {
      if (b == 0) {
        printf("B\n");
        break;
      }
      player = sb[b_length-b] - 'a';
      b--;
    } else {
      if (c == 0) {
        printf("C\n");
        break;
      }
      player = sc[c_length-c] - 'a';
      c--;
    }
  }
 
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
	static Scanner sc = new Scanner(System.in);
	static long mod = 1_000_000_007;
	public static void main(String[] args) {
		int k = sc.nextInt();
		int n = sc.next().length();
		int m = n + k;
		initComb();
		long ans = 0;
		for(int i=n;i<=m;i++) {
			ans += comb(m, i) * pow(25, m-i) % mod;
			ans %= mod;
		}
		System.out.println(ans);
	}
	static long fact[] = new long[2002002];
	static long revFact[] = new long[2002002];
	
	static void initComb() {
		fact[0] = 1;
		for(int i=1;i<2002002;i++) {
			fact[i] = fact[i-1] * i % mod;
		}
		revFact[2002001] = div(1, fact[2002001]); 
		for(int i=2002001;i>=1;i--) {
			revFact[i-1] = revFact[i] * i % mod;
		}
	}
	
	static long div(long x, long y) {
		return x * pow(y, mod - 2) % mod;
	}
	
	static long pow(long a, long x) {
		if(x == 0)return 1;
		if(x % 2 == 1) return a * pow(a, x-1) % mod;
		long root = pow(a, x / 2);
		return root * root % mod;
	}
	
	static long comb(int x, int y) {
		if( x < y )return 0;
		long up = fact[x];
		long down = fact[x - y] * fact[y] % mod;
		return div(up, down);
	}
}

Measured memory_bytes: 77524
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s; cin >> s;

    for(int i=0;s[i];i++){
        cout << '9'-s[i]+1;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    int cnt = 0;
    int sum = 0;
    rep(i, n) {
        sum += a[i];
        if (sum <= x)
            cnt++;
        else
            break;
    }
    if (cnt == n && sum < x)
        cnt--;
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    ll h, w;
    cin >> h >> w;
    if(h==1 || w == 1){
        cout << 1 << endl;
        return 0;
    }
    ll ans = h*w/2;
    if(h*w%2 != 0) ans++;
    cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3632
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    C = []
    for i in range(H):
        c = input()
        C.append(c)
        C.append(c)

    for c in C:
        print(c)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 38384
#include<iostream>

using namespace std;

int H, W;
bool map[400][400], isused[400][400];
long long cttr, ctfl;//探索してる部分グラフでのノードでの　true falseの数のカウント
int vx[4] = { 1,0,-1,0 }, vy[4] = { 0,1,0,-1 };

void search(int i, int j) {
	isused[i][j] = true;
	if (map[i][j])cttr++;
	else ctfl++;
	for (int k = 0; k < 4; k++) {
		int nx = i + vx[k], ny = j + vy[k];
		if (nx < 0 || ny < 0 || nx >= H || ny >= W)continue;
		if (isused[nx][ny] || map[nx][ny] == map[i][j])continue;
		search(nx, ny);
	}
}

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char c;
			cin >> c;
			if (c == '#')map[i][j] = true;
			else map[i][j] = false;
		}
	}
	long long ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (isused[i][j] || !map[i][j])continue;
			cttr = 0, ctfl = 0;
			search(i, j);
			ans += (cttr * ctfl);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8064
N, M = map(int, input().split())
A = []
for _ in range(N):
    a = input()
    A.append(a)

B = []
for _ in range(M):
    b = input()
    B.append(b)

idx = [0, 0]
while True:
    if idx[0] == N - 1 and idx[1] == N - 1:
        break
    if A[idx[0]][idx[1]] == B[0][0]:
        check = False
        for i in range(M):
            for j in range(M):
                if 0 <= idx[0] + i < N and 0 <= idx[1] + j < N:
                    if A[idx[0] + i][idx[1] + j] != B[i][j]:
                        check = True
                        break
                else:
                    check = True
                    break
            if check:
                break

        if not check:
            print('Yes')
            exit()
    if idx[1] < N - 1:
        idx[1] += 1
        continue
    else:
        idx[0] += 1
        idx[1] = 1
        continue

if A[-1][-1] == B[0][0] and M == 1:
    print('Yes')
    exit()

print('No')


Measured memory_bytes: 9212
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>

#include <cstdlib>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> II;

int N;
int A[52];

void solve_neg(vector<II>& res) {
   for (int i = N-1; i >= 1; --i)
      res.push_back(II(i+1, i));
}

void solve_pos(vector<II>& res) {
   FOR(i, 2, N)
      res.push_back(II(i-1, i));
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(NULL);

   cin >> N;
   FOR(i, 1, N)
      cin >> A[i];

   int mn_idx = min_element(A+1, A+1+N) - A;
   int mx_idx = max_element(A+1, A+1+N) - A;

   int mn = A[mn_idx];
   int mx = A[mx_idx];

   vector<II> res;
   if (mx < 0) {
      // all negatives
      solve_neg(res);
   }
   else if (mn >= 0) {
      // all positives
      solve_pos(res);
   }
   else if (abs(mx) > abs(mn)) {
      FOR(i, 1, N)
         if (A[i] < 0)
            res.push_back( II(mx_idx, i) );
      solve_pos(res);
   }
   else {
      FOR(i, 1, N)
         if (A[i] >= 0)
            res.push_back( II(mn_idx, i) );
      solve_neg(res);
   }

   cout << res.size() << '\n';
   for (II p : res)
      cout << p.first << ' ' << p.second << '\n';

   return 0;
}


Measured memory_bytes: 256
from collections import deque
N=int(input())
E={i:{} for i in range(1,N+1)}

for _ in range(N-1):
    u,v,w=map(int,input().split())
    E[u][v]=w%2
    E[v][u]=w%2

inf=float("inf")
Dist=[inf]*(N+1)
Q=deque([1])
Dist[1]=0
while Q:
    u=Q.popleft()
    for v in E[u]:
        if Dist[v]==inf:
            Q.append(v)
            Dist[v]=Dist[u]^E[u][v]
print("\n".join(map(str,Dist[1:])))

Measured memory_bytes: 117608
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  string S;
  cin >> S;
  for (const auto& e : S) {
    if (e == '?') cout << 'D';
    else cout << e;
  }
  cout << '\n';
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int sum[1002][1002];
int main(){
    int n;
    cin>>n;
    int x1,y1,x2,y2;
    rep(i,n){
        cin>>x1>>y1>>x2>>y2;
        ++x1,++y1,++x2,++y2;
        ++sum[y1][x1],++sum[y2][x2];
        --sum[y2][x1],--sum[y1][x2];
    }
    int mx=0;
    FOR(i,1,1002)FOR(j,1,1002){
        sum[i][j]+=sum[i-1][j];
        sum[i][j]+=sum[i][j-1];
        sum[i][j]-=sum[i-1][j-1];
        mx=max(mx,sum[i][j]);
    }
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 7056
using System;
class P{
  static void Main(){
    var s=Console.ReadLine().ToCharArray();
    long a=0;
    for(int i=0;i<s.Length;i++)if(s[i]=='A'){a=i;break;}
    for(int i=s.Length-1;i>=0;i--)if(s[i]=='Z'){a=i-a+1;break;}
   Console.WriteLine(a);
  }
}

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

#define MOD 1000000007

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

ll func(ll n,ll m,ll p){
        if(p==0)return 1;
        if(p%2==0){
                ll t=func(n,m,p/2);
                return t*t%m;
        }else{
                return n*func(n,m,p-1)%m;
        }
}

ll fun1(ll n,ll x){
	ll ans=1;
	for(ll i=n;i>n-x;i--)ans=ans*i%MOD;
	for(ll i=1;i<x+1;i++)ans=ans*func(i,MOD,MOD-2)%MOD;
	return ans;
}

int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	ll num1,num2,num3;
	num1=func(2,MOD,n);
	num2=fun1(n,a);
	num3=fun1(n,b);
	ll ans=num1-1-num2-num3;
	if(ans>=0)cout<<ans%MOD<<endl;
	else{
		while(ans<0){ans+=MOD;}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int ar[20000005];
int main()
{
    int n,i,j,c=1;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>ar[i];
    }
    sort(ar,ar+n);
    for(i=1; i<n; i++)
    {

        if(ar[i]==ar[i-1])
        {
            c=0;
            break;
        }
    }
    if(c==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::{ min, max };

fn main() {
    let s = read::<String>().chars().collect::<Vec<char>>();
    let t = read::<String>().chars().collect::<Vec<char>>();

    let mut dp = vec![vec![0; t.len()+1]; s.len()+1];
    for i in 0..s.len() {
        for j in 0..t.len() {
            if s[i] == t[j] {
                dp[i+1][j+1] = dp[i][j]+1;
            } else {
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }

    let mut i = s.len();
    let mut j = t.len();
    let mut v: Vec<char> = Vec::new();
    while i > 0 && j > 0 {
        if dp[i][j-1] == dp[i][j] {
            j-=1;
        } else if dp[i-1][j] == dp[i][j] {
            i-=1;
        } else if dp[i-1][j-1] < dp[i][j] {
            v.insert(0, s[i-1]);
            i-=1;
            j-=1;
        }
    }
    
    for i in 0..v.len() {
        print!("{}", v[i])
    }

    println!("");
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  rep(i,n){
    vector<vector<int>> v(9,vector<int>(9,0));
    vector<vector<char>> v2(9,vector<char>(9,' '));
    if( i != 0) cout << endl;
    rep(i,9){
      rep(j,9){
        cin>>v[j][i];
      }
    }
    rep(i,9){
      int num[10] = {};
      rep(j,9){
        num[v[j][i]]++;
      }
      rep(j,9){
        if(num[v[j][i]] > 1){
          v2[j][i] = '*';
        }
      }
    }
    rep(j,9){
      int num[10] = {};
      rep(i,9){
        num[v[j][i]]++;
      }
      rep(i,9){
        if(num[v[j][i]] > 1){
          v2[j][i] = '*';
        }
      }
    }
    for(int i = 0; i < 9 ; i+= 3){
      for(int j = 0; j < 9; j += 3){
        int num[10]={};
        rep(k,3){
          rep(l,3){
            num[v[j+l][i+k]]++;
          }
        }
        rep(k,3){
          rep(l,3){
            if(num[v[j+l][i+k]] > 1){
              v2[j+l][i+k] = '*';
            }
          }
        }
      }
    }
    rep(i,9){
      rep(j,9){
        cout << v2[j][i]<<v[j][i];
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3092
N = int(input())
A = sorted([int(_) for _ in input().split()])
n = A[-1]

idx = 0
maxv = -1
for i in range(N - 1):
    if A[i] == 0:
        t = 0
    else:
        t = min(n - A[i], A[i])
    if t > maxv:
        maxv = t
        idx = i
print(n, A[idx])


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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	LL h[n];
	int ans = 0,k=0;
	for(int i=0;i<n;i++){
		cin >> h[i];
		if(i == 0){
			continue;
		}else{
			if(h[i] <= h[i-1]){
				k++;
			}else{
				ans = max(ans,k);
				k = 0;
			}
		}
	}
	ans = max(ans,k);
	// keisan
	cout << ans;
	// syutsuryoku
}

Measured memory_bytes: 4356
a=input().split()
#ans=[]
i=0
while(1):
    if (a[i]=='+') or (a[i]=='*') or (a[i]=='-'):
       x=int(a.pop(i-2))
       y=int(a.pop(i-2))
       i=i-2

       if a[i]=='+':
           a[i]=x+y
       elif a[i]=='*':
           a[i]=x*y
       elif a[i]=='-':
           a[i]=x-y

    else:
       i=i+1


    if len(a)==1:
       break

print(int(a[0]))


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

public class Main{

  public static void main(String[] args) {
    
    new Main().run();
  }

  private void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int heapSize = Integer.parseInt(br.readLine());
      String[] keys = br.readLine().split(" ");
      int[] mHeap = new int[heapSize+1];
      mHeap[0] = heapSize;
      for(int i=1; i<=heapSize; i++)
        mHeap[i] = Integer.parseInt( keys[i-1] );

      buildMaxHeap(mHeap);

      StringBuilder buf = new StringBuilder();
      for(int i=1; i<mHeap.length; i++) 
        buf.append(" ").append(mHeap[i]);

      System.out.println(buf);
    } catch(IOException e) {
      System.out.println("IOException!");
    }
  }
  private void buildMaxHeap(int[] heap) {
    for(int i= heap[0]/2; i>0; i--)
      maxHeapify(heap, i);
  }
  private void maxHeapify(int[] heap, int node) {
    int t,left,right,largest;
    t = largest = 0;
    left  = nodeLeft(node);
    right = nodeRight(node);

    if( (left <= heap[0]) && (heap[left] > heap[node]) )
      largest = left;
    else
      largest = node;
    if( (right <= heap[0]) && (heap[right] > heap[largest]) )
      largest = right;

    if( largest != node ) {
      t = heap[node]; heap[node] = heap[largest]; heap[largest] = t;

      maxHeapify(heap, largest);
    }
  }
  private int nodeLeft(int node) {
    return node*2;
  }
  private int nodeRight(int node) {
    return node*2+1;
  }
}


Measured memory_bytes: 74988
a, b, x = map(int, input().split())

from math import atan
from math import pi
if x > a*a*b/2:
    theta = atan(2 * (a*a*b - x) / (a**3))
else:
    theta = atan(a*b*b / (2*x))
print(theta * 180 / pi)

Measured memory_bytes: 38384
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N;
	cin >> N;
	vector<ll> A(N), B;
	map<int, int> m, k;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		m[A[i]]++;
	}
	{
		int i = 0;
		for (auto itr = m.begin(); itr != m.end(); itr++) {
			B.push_back((*itr).second);
			k[(*itr).first] = i;
			i++;
		}
	}
	vector<ll> C(B.size()), D(B.size(), 0), E(B.size(), 0);
	for (int i = 0; i < B.size(); i++) {
		if (B[i] < 2)C[i] = 0;
		else C[i] = B[i] * (B[i] - 1) / 2;
	}
	D[0] = C[0], E.back() = C.back();
	for (int i = 0; i < D.size()-1; i++) {
		D[i + 1] = D[i] + C[i + 1];
	}
	for (int i = E.size()-1; i >= 1; i--) {
		E[i - 1] = E[i] + C[i - 1];
	}
	for (int i = 0; i < N; i++) {
		ll ans = 0;
		if (B[k[A[i]]] >= 3)ans += (B[k[A[i]]] - 1) * (B[k[A[i]]] - 2) / 2;
		if (k[A[i]] != 0)ans += D[k[A[i]] - 1];
		if (k[A[i]] != B.size() - 1)ans += E[k[A[i]] + 1];
		cout << ans << endl;
	}
}

Measured memory_bytes: 18932
#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
const int MN=1e5+5;
int n,a[MN],pre[MN],suf[MN],num[MN],nmp[MN];
int main()
{
	n=read();
	reg int i,mx=0,mxp=0,ans=n;bool fl=1;a[1]=read();
	for(i=2;i<=n;++i) a[i]=read(),fl&=(a[i]==a[i-1]);
	for(i=1;i<=n;i+=2) ++num[a[i]];
	for(i=1;i<=100000;++i) pre[i]=max(pre[i-1],num[i]);
	for(i=100000;i;--i) suf[i]=max(suf[i+1],num[i]);
	for(i=2;i<=n;i+=2) ++nmp[a[i]];
	for(i=1;i<=100000;++i) ans=min(ans,n-nmp[i]-max(pre[i-1],suf[i+1]));
	if(fl) printf("%d\n",n/2);
	else printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2176
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int k;
  cin >> k;
  cout << k / 2 * (k - k / 2) << endl;
}



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

// clang-format off
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)
#define forn(i, x, y) for(int i = x; i < y; i++)

using ll = long long;
// clang-format on

int main()
{
  IOS;

  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  forn(i, 0, N) cin >> w[i] >> v[i];

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

  return 0;
}


Measured memory_bytes: 83080
l,r = map(int,input().split())
cnt = 0
mod_list = []
if r- l >=2019:
    print(0)
else:
    for i in range(l,r):
        for j in range(i+1,r+1):
            mod_list.append(i*j%2019)
    print(min(mod_list))

Measured memory_bytes: 75332
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a + b + c <= 21 ? "win" : "bust") << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

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

    int a[M], b[M], i, c[N];
    for(i=0; i<N; i++) {
        c[i] = 0;
    }

    for(i=0; i<M; i++) {
        cin >> a[i] >> b[i];
        c[a[i]-1] += 1;
        c[b[i]-1] += 1;
    }

    for(i=0; i<N; i++) {
        cout << c[i] << endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int k[15],a[15][15],p[15],d[15],n,m,ans;
void dfs(int x){
	if(x>n){
		int tot=0;
		for(int i=1;i<=m;i++){
			int num=0;
			for(int j=1;j<=k[i];j++)
				num+=d[a[i][j]];
			if(num%2==p[i]) tot++;
		}
		if(tot==m) ans++;
		return;
	}
	d[x]=1;
	dfs(x+1);
	d[x]=0;
	dfs(x+1);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d",&k[i]);
		for(int j=1;j<=k[i];j++)
			scanf("%d",&a[i][j]);
	}
	for(int i=1;i<=m;i++)
		scanf("%d",&p[i]);
	dfs(1);
	cout<<ans;
	return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
struct Matrix{
    int size;
    vector<vector<ll>>M;
    Matrix(int k):size(k){
        M=vector<vector<ll>>(k,vector<ll>(k));
    }
    void init(){
        for(int i=0;i<size;i++)
            M[i][i]=1;
    }


};
Matrix operator * (const Matrix &a, const Matrix &b) {
    Matrix ans(a.size);
    for (int i = 0; i < a.size; ++i) {
        for (int j = 0; j < a.size; ++j) {
            for (int k = 0; k < a.size; ++k) {
                ans.M[i][j] += (1LL * a.M[i][k] * b.M[k][j]) % mod;
                ans.M[i][j] %= mod;
            }
        }
    }
    return ans;
}
Matrix pow( Matrix M,ll n) {
    Matrix res(M.M.size());
    res.init();
    if (n == 1)
        return M;
    while (n >0) {
        if (n & 1)
            res = res * M;

        M=M*M;
        n>>=1;

    }
    return res;
}
int main(){
    ll n,k;
    cin>>n>>k;
    Matrix adj(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>adj.M[i][j];
        }
    }
    adj=pow(adj,k);
    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            ans=(ans+adj.M[i][j])%mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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; }
typedef pair<int,int> P;

vector<int> to[100005];
vector<int> d(100005,-1);
int dfs(int v) {
  if(d[v]!=-1)return d[v];
  d[v]=0;
  for (int u : to[v]) {
    chmax(d[v],dfs(u)+1);
  }
  return d[v];
}

int main() {
  int n, m;
  cin >> n >> m;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
  }
  int ans = 0;
  rep(i,n)chmax(ans,dfs(i));
  cout << ans << endl;
  return 0;
}


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

int main() {

	int a,b,c,d;
	cin >> a >> b >>c >>d ;
	
	while(1) {
		c = c-b;
		if(c<=0) 
        {
          cout << "Yes" ; 
          break ;
        }
		a = a-d ;
		if(a<=0) 
        {
          cout << "No" ; 
         break ;
        } 
	}
	
}

Measured memory_bytes: 3620
n,k = map(int,input().split())
V = list(map(int,input().split()))
rV = V[::-1]
Q = []
m = min(n,k)
res = []
for i in range(m+1):
    for j in range(m-i+1):
        Q.extend(V[:i])
        Q.extend(rV[:j])
        if not Q:
            continue
        s = sum(Q)
        Q.sort()
        for p in range(min(len(Q),k-len(Q))):
            if Q[p] < 0:
                s -= Q[p]   
        res.append(s)
        Q = []
print(max(res))

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
const int MAX_V = 1e+4, INF = 1e+9;
struct edge {int to, cost;};
typedef pair<int, int> P; // 距離, 頂点
int n, d[MAX_V]; vector<edge> G[MAX_V];

void dijkstra(int s) {
  fill(d, d+n, INF); d[s] = 0;
  priority_queue<P, vector<P>, greater<P>> q;
  q.push(P(0, s));
  while(!q.empty()) {
    P p = q.top(); q.pop();
    int now = p.second;
    // 最短距離以外を無視
    if(d[now] < p.first) continue;
    for(int i = 0; i < G[now].size(); ++i) {
      edge e = G[now][i];
      if(d[e.to] > d[now] + e.cost) {
        d[e.to] = d[now] + e.cost;
        // とりあえず追加して、あとで最短距離以外を無視
        q.push(P(d[e.to], e.to));
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  for(int i = 0, u, k; i < n; ++i) {
    scanf("%d %d", &u, &k);
    for(int j = 0, v, c; j < k; ++j) {
      scanf("%d %d", &v, &c);
      edge e = {v, c};
      G[u].push_back(e);
    }
  }
  dijkstra(0);
  for(int i = 0; i < n; ++i) {
    printf("%d %d\n", i, d[i]);
  }
}


Measured memory_bytes: 2996
# サンプル1はべつに3*2=6じゃなくても4*2=8（[1 3 4][2 2 4]）や5*1=10（[1 4 5]）も同じコストで実現できることがわかる
# つまり総和に近い偶数を目指す
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
tmp = arr[0]
ans = 10**10
e = -1
for i in range(1, n):
    # 超えないギリギリ
    if tmp + arr[i] <= s // 2:
        tmp += arr[i]
        e = i
    else:
        break
c = abs(s // 2 - tmp) + abs(s // 2 - sum(arr[i:]))
# print("超えない左側の合計と右側の合計 : {}, {}".format(tmp, sum(arr[i:])))
ans = min(ans, c)

e = -1
tmp = arr[0]
for i in range(1, n):
    # 超えたギリギリ
    if tmp > s // 2:
        break
    else:
        tmp += arr[i]
        e = i
c = abs(s // 2 - tmp) + abs(s // 2 - sum(arr[i:]))
# print("超えたギリギリの左側の合計と右側の合計 : {}, {}".format(tmp, sum(arr[i:])))
ans = min(ans, c)
print(ans)

Measured memory_bytes: 26060
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node{
	int p,l,r;
};

Node T[MAX];

int n,D[MAX];

void print(int u){
	int i,c;
	cout<<"node "<<u<<": ";
	cout<<"parent = "<<T[u].p<<", ";
	cout<<"depth = "<<D[u]<<", ";
	
	if(T[u].p==NIL) cout<<"root, ";
	else if(T[u].l==NIL) cout<<"leaf, ";
	else cout<<"internal node, ";
	cout<<"[";
	for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
		if(i) cout<<", ";
		cout<<c;
	}
	cout<<"]"<<endl;
}

int rec(int u,int p){
	D[u] = p;
	if(T[u].r!=NIL)
	rec(T[u].r,p);
	if(T[u].l!=NIL)
	rec(T[u].l,p+1);
}

int main(){
	int n,v,k,d,l,r;
	cin>>n;
	for(int i=0;i<n;i++) T[i].l=T[i].r=T[i].p=NIL;
	for(int i=0;i<n;i++){
		cin>>v>>k;
		for(int j=0;j<k;j++){ 
			cin>>d;
			if(j==0) T[v].l=d;
			else T[l].r=d;
			l=d;
			T[d].p=v;
		}
	}
	for(int i=0;i<n;i++){
		if(T[i].p==NIL) r=i;
	}
	
	rec(r,0);
	
	for(int i=0;i<n;i++){
		print(i);
	}
	return 0;
}

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

using ll= long long;
const ll INF=1LL<<60;
const ll MOD=1e9+7;

int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll res=INF;
    for(int i=0; i<=2*max(X, Y); i+=2){
        ll total;
        int a=X-i/2, b=Y-i/2, c=i;
        if(a < 0) a=0;
        if(b < 0) b=0; 
        total=a*A+b*B+c*C;
        res=min(res, total);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(lint i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define step(n) rep(_, n)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define Unique(a) a.erase(unique(Range(a)), a.end())
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define LINT_MAX (LONG_LONG_MAX)
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr Type Square(Type x) { return x * x; }
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }
void Print() { cout << endl; }
template <class Head, class... Tail> void Print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << ""; Print(forward<Tail>(tail)...); }
template <class T> void Print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class T> void Print(vector<vector<T>> &df) { for (auto& vec : df) { Print(vec); } }

int main()
{
    lint N; cin >> N;
    vector<lint> A(N); for(auto& it:A) { cin >> it; }

    map<lint, lint> L, R;
    rep (i, N)
    {
        L[i] = (i+1) + A[i];
    }

    rep (j, N)
    {
        R[(j+1) - A[j]]++;
    }

    lint ans = 0;
    rep (i, N)
    {
        ans += R[L[i]];
    }

    Print(ans);

    return 0;
}



Measured memory_bytes: 39720
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(int &x)
{
    register int c = gc();x = 0;int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

int main()
{
    fsscan();
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    ll c=0;
    for(int i=0;i<n;i++)
    {
        ll r=0;
        ll num=a[i];
        while(1)
        {
            //cout<<num<<endl;
            if(num%2==0)
            {
                num=num/2;
                r++;
            }
            else
            break;
        }
        c+=r;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 2000;

int main(){
    
    ll ans=0;
    int n;
    int l[maxn];
    
    cin >> n;
    
    rep(i,n){
        cin >> l[i];
    }
    
    sort(l,l+n);
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int a = l[i],b=l[j];
            int R = lower_bound(l+j+1,l+n,a+b)-l;
            int L= upper_bound(l+j+1,l+n,b-a)-l;
            ans+=R-L;
        }
    }
    
    cout << ans<<endl;
    
    return 0;
}


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

using namespace std;
const int maxn=200000+200;
int a[maxn];
int r[maxn];
int n,k;
set<int> s;
typedef set<int>::iterator it;
int c1,c2,c3;
it m1,m2,m3;
int sta[maxn];
int e=0;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=k;i++){
        s.insert(a[i]);
    }
    for(int i=1;i<=n;i++){
        while(e!=0&&a[sta[e-1]]>a[i])e--;
        sta[e++]=i;
        r[i]=e;
    }
    c3=1;
    if((r[k]-r[1])==k-1){
        c2+=1;
        c3=0;
    }
    for(int i=2;i<=(n-k+1);i++){
        m1=s.begin();
        m2=s.end();
        m2--;
        if(a[i-1]==(*m1)&&a[i+k-1]>(*m2))
            c1+=1;
        else if((r[i+k-1]-r[i])==k-1)
            c2+=1;
        else
            c3+=1;
        s.erase(s.lower_bound(a[i-1]));
        s.insert(a[i+k-1]);
    }
    if(c2>1)c2=1;
    c3+=c2;
    cout<<c3<<endl;
    return 0;
}
/*
8 2
1 3 5 7 2 4 6 8


*/


Measured memory_bytes: 11904
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
  
  int N,M;
  cin >> N >> M;
  vector<int > foodlist(M,0);

  for (int i = 0; i < N; i++)
  {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++)
    {
      int food;
      cin >> food;
      foodlist[food-1]++;
    }
  }
  
  int Ans =0;
  for (vector<int >::iterator itr = foodlist.begin(); itr < foodlist.end(); ++itr)
  {
    if (*itr == N) Ans++;
  }
  
  cout << Ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
#define MAXN 100100

int A[MAXN];
int gone[MAXN];
vi V[MAXN];
vi V2[MAXN];
int N,a,b;
vpi E;
vi res,res2;
deque<int> l;

void dfs(int x, int p){
	// cout<<"Safe "<<x<<'\n';
	l.pb(A[x]);
	for (auto v:V[x])if(v!=p && !gone[v]){
		dfs(v,x);
	}
}

int main(){
	cin>>N;
	if (N == 2){
		cout<<"1 2";
		return 0;
	}
	for (int i=1;i<N;++i){
		cin>>a>>b;
		E.pb(a,b);
		V[a].pb(b);V[b].pb(a);
	}
	for (int i=1;i<=N;++i)if(SZ(V[i]) == 1)gone[i] = 1;
	for (auto i : E){
		if (gone[i.f]){
			++A[i.s];
		}else if(gone[i.s]){
			++A[i.f];
		}
	}
	// for (int i=1;i<=N;++i)cout<<gone[i]<<' ';cout<<'\n';
	for (auto i : E){
		// cout<<i.f<<' '<<i.s<<' '<<gone[i.f]<<' '<<gone[i.s]<<'\n';
		if (gone[i.s] || gone[i.f])continue;
		V2[i.f].pb(i.s);
		V2[i.s].pb(i.f);
		// cout<<i.f<<' '<<i.s<<'\n';
	}
	for (int i=1;i<=N;++i)if(SZ(V2[i]) > 2){
		cout<<-1;
		return 0;
	}
	for (int i=1;i<=N;++i){
		if (SZ(V2[i]) == 1){
			dfs(i,-1);
			break;
		}
	}
	if (SZ(l) == 0){
		// Only one node
		for (int i=1;i<=N;++i){
			if (SZ(V[i]) > 1){
				dfs(i,-1);
				break;
			}
		}
	}
	
	l.back()--;l.push_back(0);
	l[0]--;l.push_front(0);

	int t = 1;
	for (auto i:l){
		// cout<<"Do "<<i<<'\n';
		if (i == 0){res.pb(t);++t;continue;}
		if (i == 1){res.pb(t+1);res.pb(t);t+=2;continue;}
		for (int k=t+1;k<=t+i;++k){
			res.pb(k);
		}
		res.pb(t);
		t = t+i+1;
	}

	reverse(ALL(l));

	t = 1;
	for (auto i:l){
		if (i == 0){res2.pb(t);++t;continue;}
		if (i == 1){res2.pb(t+1);res2.pb(t);t+=2;continue;}
		for (int k=t+1;k<=t+i;++k){
			res2.pb(k);
		}
		res2.pb(t);
		t = t+i+1;
	}
	// for (auto i :res2)cout<<i<<' ';cout<<'\n';
	bool btr = 0;
	for (int i=0;i<N;++i){
		if (btr)cout<<res[i]<<' ';
		else if (res[i] == res2[i]){
			cout<<res[i]<<' ';
		}else if (res[i] > res2[i]){
			--i;
			swap(res,res2);
			btr = 1;
		}else{
			--i;
			btr = 1;
		}
	}
}

Measured memory_bytes: 20976
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

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

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

void solve() {
    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No");
}

//#define LOCAL 1

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

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    solve();

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,x=0,maxv=0;
  cin>>n;
  string s;
  cin>>s;
  for(int i=0;i<n;i++){
    x+=(s[i]=='I'?1:-1);
    maxv=max(maxv,x);
  }
  cout<<maxv<<endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()
inline cpp_int between(cpp_int n, cpp_int x) {
  if(n >= 0)
    return (n/x)+1;
  else
    return 0;
}

int main () {
  int n, t, a, h;
  vector<int> hs;
  cin >> n >> t >> a;
  REP(i, n) {
    cin >> h;
    hs.push_back(abs((a*1000) - ((t*1000) - (h*6))));
  }
  auto min = min_element(ALL(hs));
  auto dist = distance(hs.begin(), min);
  cout << dist+1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

char s[100005];
int n;

int main()
{
    #ifdef NOT_DMOJ
    freopen("data.txt","r",stdin);
    #endif // NOT_DMOJ
    scanf("%s%n",s+1,&n);
    // do a basic check
    if (s[1]=='0' || s[n]=='1') {
        printf("-1\n");
        return 0;
    }
    for (int i=1; i<n; i++) {
        if (s[i]!=s[n-i]) {
            printf("-1\n");
            return 0;
        }
    }
    int parent=1;
    for (int i=2; i<=n; i++) {
        printf("%d %d\n",parent,i);
        if (s[n-i+1]=='1') {
            parent=i;
        }
    }
}


Measured memory_bytes: 1408