akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 3
#define N2 9
class puzzle{
public:
	int f[N2];
	int space;
	string path;
	
	bool operator < (const puzzle &p) const {
		for(int i=0;i<N2;i++){
			if(f[i]!=p.f[i]) return f[i]>p.f[i];
		}
		return false;
	}
	
};

static const int dx[4]={-1,+1,0,0};
static const int dy[4]={0,0,-1,+1};
static const char dir[4]={'u','d','l','r'};

bool isTarget(puzzle u){
	for(int i=0;i<N2;i++){
		if(u.f[i]!=i+1) return false;
	}
	return true;
}

string bfs(puzzle s){
	queue<puzzle> Q;
	map<puzzle,bool> V;
	puzzle u,v;
	s.path="";
	Q.push(s);
	V[s]=true;
	while(!Q.empty()){
		u=Q.front();Q.pop();
		if(isTarget(u)) return u.path;
		int sx=u.space/N,sy=u.space%N;
		for(int r=0;r<4;r++){
			int tx=sx+dx[r],ty=sy+dy[r];
			if(tx<0 || tx>=N || ty<0 || ty>=N) continue;
			v=u;
			swap(v.f[v.space],v.f[tx*N+ty]);
			v.space=tx*N+ty;
			if(!V[v]){
				V[v]=true;
				v.path+=dir[r];
				Q.push(v);
			}
		}
	}
	return "unsolvable";
}

int main() {
	puzzle in;
	for(int i=0;i<N2;i++){
			cin>>in.f[i];
			if(in.f[i]==0){
				in.f[i]=N2;
				in.space=i;
			}
	}
	string ans=bfs(in);
	cout<<ans.size()<<endl;
	
	return 0;
}


Measured memory_bytes: 30532
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;



// (a/b)%P の場合は，(a%P)*modinv(b)%P とする
ll modinv(ll a) {
    ll b = MOD, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

ll nCk(ll n, ll k){
    k = min(k,n-k);
    ll res=1;
    for(ll i=0;i<k;i++){
        res*=n;
        n--;
        res%=MOD;
    }
    ll bo = 1;
    for(ll i=1;i<=k;i++){
        bo*=i;
        bo%=MOD;
    }
    return (res%MOD)*modinv(bo)%MOD;
}

int main(void) {

    ll x,y;
    cin>>x>>y;
    ll bx=x,by=y;
    if(x<y)swap(x,y);
    pair<ll ,ll> edge = mp(-1,-1);
    ll eh;
    ll ew;
    for(ll i=0;i<10000000;i++){
        if(y*2==x){
            edge=mp(x,y);
            break;
        }
        x++;
        y--;
        if(y<0||x>4000000)break;
        if(y*2==x){
            edge=mp(x,y);
            break;
        }
    }
    if(edge.first==-1&&edge.second==-1){
        cout<<0<<endl;
        return 0;
    }
    // cout<<edge.first<<" "<<edge.second<<endl;
    eh=edge.second;
    ew=edge.first-bx;
    // cout<<eh<<" "<<ew<<endl;
    fin(nCk(eh,ew)%MOD);

}

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

using namespace std;

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

	int n;
	cin >> n;
	int dig=n%10;
	if(dig==3)
        cout << "bon" << endl;
    else if(dig==0 || dig==1 || dig==6 || dig==8)
        cout << "pon" << endl;
    else
        cout << "hon" << endl;

	return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
//#include <boost/multiprecision/cpp_int.hpp>

//namespace mp = boost::multiprecision;
using namespace std;

int main() {
	string s;
	cin >> s;
	while (1) {
		if(s.substr( 0, 7)=="keyence") {
			cout << "YES" << endl;
			break;
		}
		else if (
			s.substr(0,6)=="keyenc"&&s.substr(s.size()-1,1)=="e") {
			cout << "YES" << endl;
			break;
		}
		else if (s.substr(0,5)=="keyen"&&s.substr(s.size()-2,2)=="ce"){ 
			cout << "YES" << endl;
			break;
		}
		else if (s.substr(0, 4) == "keye"&&s.substr(s.size() - 3, 3) == "nce") {
			
				cout << "YES" << endl;
				break;
			}
		else if (s.substr(0, 3) == "key"&&s.substr(s.size() - 4, 4) == "ence") {
			
				cout << "YES" << endl;
				break;
			}
		else if (s.substr(0, 2) == "ke"&&s.substr(s.size() - 5, 5) == "yence") {
			
				cout << "YES" << endl;
				break;
			}
		else if (s.substr(0, 1) == "k"&&s.substr(s.size() - 6, 6) == "eyence") {
			
				cout << "YES" << endl;
				break;
			}

		else if (s.substr(s.size() - 7, 7) == "keyence") {
			
				cout << "YES" << endl;
				break;
			}
		else {
			cout << "NO" << endl;
			break;
		}
	}


}


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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int>A(M);
  for(int i=0;i<M;i++){
    cin>>A.at(i);
  }
  int s=0;
  for(int i=0;i<M;i++){
    s+=A.at(i);
  }
  if(N<s) cout<<"-1"<<endl;
  else {
    int ans=(N-s);
    cout<<ans<<endl;
  }
}

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

string S;
ll K;
P memo[4010][4010];

P dfs(int l, int r){
	if(memo[l][r].first != -1) return memo[l][r];
	
	P ret;
	if(l == r) ret = {1, 1};
	else if(l == r - 1){
		if(S[l] == S[r]) ret = {2, 1};
		else ret = {3, 2};
	}else{
		if(S[l] == S[r]){
			P p = dfs(l + 1, r - 1);
			p.first += 2;
			ret = p;
		}else{
			P p1 = dfs(l + 1, r);
			P p2 = dfs(l, r - 1);
			if(p1.first == p2.first){
				p1.second += p2.second;
				p1.first += 2;
				if(p1.second > K) p1.second = K + 1;
				ret = p1;
			}else if(p1.first < p2.first){
				p1.first += 2;
				ret = p1;
			}else{
				p2.first += 2;
				ret = p2;
			}
		}
	}
	return memo[l][r] = ret;
}
string dfs2(int l, int r, ll k){
	//cout << l << " " << r << " " << k << endl;
	if(l == r){
		assert(k == 1);
		return S.substr(l, 1);
	}else if(l == r - 1){
		if(S[l] == S[r]){
			assert(k == 1);
			return S.substr(l, 2);
		}else{
			assert(k <= 2);
			string ret;
			ret.resize(3);
			char cl = S[l];
			char cr = S[r];
			if(k == 1){
				ret[0] = min(cl, cr);
				ret[1] = max(cl, cr);
				ret[2] = min(cl, cr);
			}else{
				ret[0] = max(cl, cr);
				ret[1] = min(cl, cr);
				ret[2] = max(cl, cr);
			}
			return ret;
		}
	}else{
		if(S[l] == S[r]){
			return  S[l] + dfs2(l + 1, r - 1, k) + S[r];
		}else{
			P p1 = dfs(l + 1, r);
			P p2 = dfs(l, r - 1);
			if(p1.first == p2.first){
				if(S[l] < S[r]){
					if(p1.second >= k){
						return  S[l] + dfs2(l + 1, r, k) + S[l];
					}else{
						return  S[r] + dfs2(l, r - 1, k - p1.second) + S[r];
					}
				}else{
					if(p2.second >= k){
						return  S[r] + dfs2(l, r - 1, k) + S[r];
					}else{
						return  S[l] + dfs2(l + 1, r, k - p2.second) + S[l];
					}
				}
			}else if(p1.first < p2.first){
				return  S[l] + dfs2(l + 1, r, k) + S[l];
			}else{
				return  S[r] + dfs2(l, r - 1, k) + S[r];
			}
		}
	}
}


int main(){
	cin >> S;
	cin >> K;
	for(int i = 0; i < 4010; i++){
		for(int j = 0; j < 4010; j++){
			memo[i][j].first = -1;
		}
	}
	P ret = dfs(0, S.size() - 1);
	if(ret.second < K){
		cout << "NONE" << endl;
	}else{
		cout << dfs2(0, S.size() - 1, K) << endl;
	}
}

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

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

  int n;
  string s;
  cin >> n >> s;

  if(n % 2 != 0)
  {
    cout << "No" << endl;
    return 0;
  }
  
  for (int i = 0; i < n / 2; i++)
  {
    if(s[i] != s[i + (n/2)])
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	ll i,j,k,l,n;
	cin>>n;
	ll ar[n+1]; map<ll,ll> mp;
	for(i=1;i<=n;i++){
		cin>>ar[i];
		mp[ar[i]]++;
	}
	
	ll mx=-1; set<ll> st;
	for(auto it:mp){
		if(it.second>=4){
			mx=max(mx,it.first);
		}
		else if(it.second>=2){
			st.insert(it.first);
		}
	}

	
	ll mx2=-1,mx3=-1;
	if(st.size()>=1){
		mx3=max(mx3,mx*(*(--st.end())));
	}
		if(mx!=-1) mx=mx*mx;
	if(st.size()>=2){
		ll a,b;
		a=*(--st.end());
		st.erase(*(--st.end()));
		b=*(--st.end());
		mx2=max(mx2,a*b);
	}
	if(mx==-1&&mx2==-1){
		cout<<"0";
	}
	else{
		cout<<max(mx,max(mx2,mx3));
	}
	return 0;
}

Measured memory_bytes: 7296
class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        else:
            if self.size(x) < self.size(y):
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        x = self.find(x)
        return -self.parent[x]


h, w = map(int, input().split())
s = tuple(input() for _ in range(h))

uf_v = UnionFind(h * w)
uf_h = UnionFind(h * w)

for r in range(h):
    for c in range(w):
        if s[r][c] == '#': continue
        for dr in (-1, 1):
            nr = r + dr
            if 0 <= nr < h:
                if s[nr][c] == '.':
                    x = r * w + c
                    nx = nr * w + c
                    uf_v.unite(x, nx)
        for dc in (-1, 1):
            nc = c + dc
            if 0 <= nc < w:
                if s[r][nc] == '.':
                    x = r * w + c
                    nx = r * w + nc
                    uf_h.unite(x, nx)

ans = 0
for r in range(h):
    for c in range(w):
        x = r * w + c
        ans = max(ans, uf_v.size(x) + uf_h.size(x) - 1)
print(ans)


Measured memory_bytes: 207996
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define P pair<int,int>
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
//cout << setprecision(123);

int main(){
  int a,p;
  cin>>a>>p;
  
  cout <<(3*a+p)/2<<endl;
  
}

Measured memory_bytes: 384
import itertools

N, M, Q = map(int, input().split())
l = [i for i in range(1, M+1)]
qus = []
As = []
for _ in range(Q):
    b = list(map(int, input().split()))
    qus.append(b)
for v in itertools.combinations_with_replacement(l, N):
    a = list(v)
    A = 0
    for q in qus:
        pre = a[q[1]-1] - a[q[0]-1]
        if pre == q[2]:
            A += q[3]
    As.append(A)
print(max(As))

Measured memory_bytes: 12820
#include "bits/stdc++.h"
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if ((a * b) % 2 == 0)
		cout << "Even" << endl;
	else if ((a * b) % 2 == 1)
		cout << "Odd" << endl;
}

Measured memory_bytes: 256
x,y=map(int,input().split())

if x*y>=0 and y>x:
    ans = y-x
elif x*y>0 and x>y:
    ans=x-y+2
elif x*y<=0 and abs(x)-abs(y)>=0:
    ans=abs(x)-abs(y)+1
elif x*y <=0 and abs(y)-abs(x)>=0:
    ans=abs(y)-abs(x)+1

print(ans)



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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  int X, Y;
  X = tx - sx, Y = ty - sy;

  for (int i = 0; i < X; i ++) cout << 'R';
  for (int i = 0; i < Y; i ++) cout << 'U';
  for (int i = 0; i < X; i ++) cout << 'L';
  for (int i = 0; i < Y; i ++) cout << 'D';
  cout << 'D';
  for (int i = 0; i < X+1; i ++) cout << 'R';
  for (int i = 0; i < Y+1; i ++) cout << 'U';
  cout << 'L';
  cout << 'U';
  for (int i = 0; i < X+1; i ++) cout << 'L';
  for (int i = 0; i < Y+1; i ++) cout << 'D';
  cout << 'R';

  cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
       String s = sc.next();
       if (s.endsWith("s")) {
           System.out.println(s + "es");
       } else {
           System.out.println(s + "s");
       }



    }

}


Measured memory_bytes: 38440
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define INF 1200000000



int main(){
    int N,a;
    cin>>N;
    int num=1;
    int cnt=0;
    bool ok=0;
    rep(i,0,N){
        cin>>a;
        if(a!=num)cnt++;
        else num++;
        if(a==1)ok=1;
    }
    
    if(ok)cout<<cnt<<endl;
    else cout<<-1<<endl;
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace at
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var i = 0;
            int a = 0;
            int b = 0;
            foreach (var item in s)
            {
                i++;
                if(item.ToString() == "A") if(a <= 0) a = i;
                if(item.ToString() == "Z") b = i;
            }
            Console.WriteLine(b-a+1);
        }    
    }
}

Measured memory_bytes: 15712
using System;
using System.Linq;
using System.Collections.Generic;
 
namespace ConsoleApp1 {
    public class Class {
        static void Main(string[] args) {
            var N = long.Parse(Console.ReadLine());
            var C = new List<long>();
            while (N != 1) {
                while (N % 2 == 0) {
                    C.Add(2);
                    N /= 2;
                }
                for (var i = 3; i <=N/i; i += 2) {
                    while (N % i == 0) {
                        C.Add(i);
                        N /= i;
                    }
                }
                if(N != 1) {
                    C.Add(N);
                    N /= N;
                }
            }
            var tmp = C.GroupBy(_ => _).Where(x => x.Count() > 0).Select(x => x.Count()).ToList();
            var ans = 0;
            for (var t = 0; t < tmp.Count(); t++) {
                for (var i = 1; i <= tmp[t]; i++) {
                    if (tmp[t] - i >= 0) {
                        ans++;
                        tmp[t] -= i;
                    }
                }
            }
            Console.Write(ans);
        }
    }
}

Measured memory_bytes: 28532
#include<bits/stdc++.h>
using namespace std;
struct node
{
	int time;
	int id;
}s[100005];
bool cmp(node a,node b)
{
	return a.time<b.time;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i].time;
		s[i].id=i;
	}
	sort(s+1,s+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		cout<<s[i].id<<" ";
	}
	return 0;	
}

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 3e2 + 2;

pair < int , pp > T[N*N];

int A[N][N],H[N][N],n;

signed main(){
    
    cin >> n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            scanf("%d",&A[i][j]);
        
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++){
                if(A[i][k] + A[k][j] < A[i][j]){
                    cout << -1;
                    return 0;
                }            
                else if(k != i and k != j and A[i][k] + A[k][j] == A[i][j])
                    H[i][j] = 1;
            }
    
    long long ans = 0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            ans += (H[i][j] == 0) * A[i][j];
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  cout << ((n + 110) / 111) * 111 << endl;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int count1=0,count2=0; 
	if(a==5) 
		count1++;
	if(a==7)
		count2++;
	if(b==5) 
		count1++;
	if(b==7)
		count2++;
	if(c==5) 
		count1++;
	if(c==7)
		count2++;
	if(count1==2&&count2==1)
		cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    double x1, y1, x2, y2, x3, y3;
    std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    auto a = std::hypot(x2 - x1, y2 - y1),
        b = std::hypot(x3 - x2, y3 - y2),
        c = std::hypot(x1 - x3, y1 - y3),
        s = abs((x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1)) / 2.0,
        h = 2 * s / std::max({ a, b, c });
    std::cout << std::setprecision(10) << 2 * s / (a + b + c + 2 * h) << std::endl;

    return 0;
}


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

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

bool pairCompare(const Pa& firstElof, const Pa& secondElof)
{
    if(firstElof.first == secondElof.first) return firstElof.second > secondElof.second;
    else return firstElof.first < secondElof.first;
}

int main() {
    ll N;
    cin >> N;
    vector<pair<string,ll>> P(N),tmp(N);
    for(int i=0;i<N;i++){
        string s;
        ll a;
        cin >> s >> a;
        P[i]=make_pair(s,a);
        tmp[i]=make_pair(s,a);
    }
    sort(P.begin(),P.end(),pairCompare);
    vector<ll> ans(N);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(P[i].first==tmp[j].first && P[i].second == tmp[j].second){
               cout << j+1 << endl;
               break;
            }
            else continue;
        }
    }
}

Measured memory_bytes: 384
N,K=map(int,input().split())
class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res
ide_ele = 0
b=[int(input()) for _ in range(N)]
c=max(b)
def segfunc(x,y):
    return max(x,y)
seg=SegTree([0]*(c+6),segfunc,ide_ele)
for i in range(N):
    a=b[i]
    seg.update(a,seg.query(max(0,a-K),min(c+2,a+K+1))+1)
print(seg.query(0,c+3))


Measured memory_bytes: 114588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll q;
  cin >> q;
  rep(_, q) {
    string x, y;
    cin >> x >> y;
    ll m = x.size(), n = y.size();
    vector<vl> dp(m + 1, vl(n + 1, 0));
    rep(i, m) rep(j, n) {
      if(x[i] == y[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]);
    }
    cout << dp[m][n] << endl;
  }
}


Measured memory_bytes: 10748
/*
* AUTHOR : Haoyang(Max) Chen
* INSTITUTION : Australian National Unversity
*/

#include <iostream>
#include <cstdlib>
using namespace std;

#define ll long long

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

	ll ans;
	int X, Y;
	int temp = 2;

	cin >> X >> Y;

	if (X % Y == 0) {
		cout << -1 << endl;
	}
	else {
		bool isMultipleY = false;
		while(!isMultipleY){
			ans = temp * X;
			if (ans % Y != 0){
				isMultipleY = true;
			}else{
				temp += 1;
			}
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 632
use std::io::stdin;

#[derive(Default)]
struct Scanner {
	buffer: Vec<String>
}

impl Scanner {
	fn next<T: std::str::FromStr> (&mut self) -> T {
		loop {
			if let Some(token) = self.buffer.pop() {
				return token.parse().ok().expect("Failed parse");
			}
			let mut input = String::new();
			stdin().read_line(&mut input).expect("Failed read");
			self.buffer = input.split_whitespace().rev().map(String::from).collect();
		}
	}
}

fn main() {
	let mut scan = Scanner::default();
	let x: String = scan.next();
	match &x[..] {
		"RRR" => println!("3"),
		"RRS" | "SRR" => println!("2"),
		"RSS" | "SRS" | "SSR" | "RSR" => println!("1"),
		_ => println!("0"),
	}
}


Measured memory_bytes: 2144
#include <stdio.h>
#define MAX 10000
#define NIL -1

void setDepth(int, int);
int setHeight(int);
int getSibling(int);
void print(int);

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

struct Node T[MAX];
int D[MAX], H[MAX];

int main(){
    int n, i, id, l, r;
    scanf("%d",&n);

    for(i=0; i<n; i++) T[i].p = NIL;

    for(i=0; i<n; i++){
        scanf("%d%d%d",&id,&l,&r);

        T[id].l = l;
        T[id].r = r;
        if(l != NIL) T[l].p = id;
        if(r != NIL) T[r].p = id;
    }

    r=0;
    for(i=0; i<n; i++){
        if(T[i].p == NIL) r=i;
    }

    setDepth(r, 0);
    setHeight(r);

    for(i=0; i<n; i++)  print(i);

    return 0;
}

void setDepth(int u, int d){
    if(u == NIL)  return;

    D[u] = d;
    setDepth(T[u].r, d+1);
    setDepth(T[u].l, d+1);
}

int setHeight(int u){
    int h1 = 0, h2 = 0;

    if(T[u].l != NIL) h1 = setHeight(T[u].l) + 1;
    if(T[u].r != NIL) h2 = setHeight(T[u].r) + 1;
    if(h1 > h2) H[u] = h1;
    else H[u] = h2;

    return H[u];
}

int getSibling(int u){
    if(T[u].p == NIL) return NIL;
    if(T[T[u].p].l != u && T[T[u].p].l != NIL) return T[T[u].p].l;
    if(T[T[u].p].r != u && T[T[u].p].r != NIL) return T[T[u].p].r;
    return NIL;
}

void print(int u){
    printf("node %d: parent = %d, sibling = %d, ",u,T[u].p,getSibling(u));
    int d=0;
   
    if(T[u].l != NIL) d++;
    if(T[u].r != NIL) d++;

    printf("degree = %d, depth = %d, height = %d, ",d,D[u],H[u]);
   
    if(T[u].p == NIL) printf("root\n");
    else if(d == 0) printf("leaf\n");
    else printf("internal node\n");
}


Measured memory_bytes: 2104
a = gets.chomp.to_i
b = gets.chomp.to_i
#a = gets.chomp.split().map(&:to_i)

if a==1 && b ==2
  puts 3
elsif a==2 && b ==1
  puts 3
elsif a==1 && b ==3
  puts 2
elsif a==3 && b ==1
  puts 2
else
  puts 1
end


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cstdlib>
using namespace std;


int main(){
	int N,X,T;
	int times;
	cin >> N >> X >> T;
	
	times = ((N + X - 1)/X) * T;
	
	cout << times;
	return 0;
}


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

const int inf = 1e9;
const ll linf = 1e18;

int dsum(int n)
{
    int res = 0;
    while (n) {
        res += n % 10;
        n /= 10;
    }
    return res;
}

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

    int n; cin >> n;
    cout << (n % dsum(n) == 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;

const int maxn = 105, maxv = 1e5+5;
int n, s;
ll w[maxn], v[maxn], dp[maxn][maxv];

int main(){
	scanf("%d %d", &n, &s);
	int ts = 0;
	for(int i = 1; i<=n; i++){
		scanf("%lld %lld", &w[i], &v[i]);
		ts += v[i];
	}
	for(int i = 1; i<=ts; i++) dp[0][i] = 1e15;
	for(int i = 1; i<=n; i++){
		for(int j = 0; j<=ts; j++){
			dp[i][j] = dp[i-1][j];
			if (j-v[i]>=0) dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]]+w[i]);
		}
	}
	ll ans;
	for(int i = ts; i>=0; i--) if (dp[n][i]<=s) {ans = i; break;}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 80128
import java.util.*;

class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        //窓の長さ・カーテンの長さを取得する
        Integer windowLength = sc.nextInt();
        Integer curtainLength = sc.nextInt();
        
        //窓のうちカーテンで隠されていない横部分の長さを定義する
        Integer resultLength = windowLength - (curtainLength * 2);
        
        //カーテンが窓よりも長い場合は0とする
        if(resultLength < 0) {
            resultLength = 0;
        }
        
        //出力する
        System.out.println(resultLength);
    }
}

Measured memory_bytes: 23764
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

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

//https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a

ll mod_pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  vector<ll> A(N); rep(i,N) cin>>A[i];
  
  vector<int> flags(100000);
  for(auto a:A) flags[a]++;
  
  ll i;
  if(N%2==0) i=1;
  else {
    if(flags[0]==1) i=2;
    else {cout<<0<<'\n'; return 0;}
  }
  
  while(i<N){
    if(flags[i]!=2) {cout<<0<<'\n'; return 0;}
    i+=2;
  }
  
  cout<<mod_pow(2,N/2)<<'\n';
  
  return 0;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

#define N 100010

int main()
{
    lol result{0};
    int n, m, h[N], ma[N]; cin >> n >> m;
    //int k; cin >> k;
    /*
    vector<int> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    */
    FOR(i, 1, n)
    {
        cin >> h[i];
        ma[i] = 0;
    }
    FOR(i, 1, m)
    {
        int a, b;
        cin >> a >> b;
        ma[a] = max(ma[a], h[b]);
        ma[b] = max(ma[b], h[a]);
    }
    FOR(i, 1, n)
    {
        if(h[i] > ma[i])
            result++;
    }

    cout << result << endl;
    return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (b - a == c - b ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 256
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            佛祖保佑       永无BUG
*/
#include<stdio.h>
#include<algorithm>
#define re register
using namespace std;
const int maxn=1e5+5;
struct edge
{
	int to,nxt;
}e[maxn<<1];
int n,k,head[maxn],cnt;
int a[maxn],rem[maxn],ans;
void add(int u,int v)
{
	e[++cnt].to=v;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
void dfs(int u)
{
	for(re int i=head[u];i;i=e[i].nxt)
	{
		int v=e[i].to;
		dfs(v);
		if(rem[v]==k-1&&u!=1) 
		{
			ans++;
			rem[v]=-1;
		}
		rem[u]=max(rem[u],rem[v]+1);
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	for(re int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	if(a[1]!=1) ++ans;
	for(re int i=2;i<=n;++i)
		add(a[i],i);
	dfs(1);
	printf("%d",ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const ll INF=1e9;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s=="zyxwvutsrqponmlkjihgfedcba"){
        cout<<-1<<endl;
        return 0;
    }
    if(s.length()==26){
        string t = s;
        next_permutation(ALL(s));
        string ans;
        ll i = 0;
        while(true){
            if(s[i]==t[i]){
                ans += s[i];
            }else{
                ans += s[i];
                break;
            }
            i++;
        }
        cout<<ans<<endl;
    }else{
        set<ll> st;
        rep(i,26){
            st.insert(i);
        }
        rep(i,s.length()){
            st.erase(s[i]-'a');
        }
        char tmp;
        tmp = 'a' + *st.begin();
        cout<<s;
        cout<<tmp<<endl;
    }
    return  0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<algorithm>
#include <cstring>
#include<set>
#include<cmath>
using namespace std;

int main()
{
	long long r;
	cin>>r;
	cout<<2*M_PI*r<<endl;	
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pi  3.141592653589793238462643383279
#define int long long
#define ff first
#define ss second
#define endl '\n'
#define inf 21474836478965499999
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define high_functioning_sociopath  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const unsigned int M = 1000000007;
/*------------------------------------- THE GAME IS ON ---------------------------------------------*/
void solve()
{
      string s;
      cin>>s;
      int sum=0;
      for(int i=0;i<s.size();i++)sum+=(s[i]-'0');
      if(sum%9)cout<<"No\n";
      else cout<<"Yes\n";
}       
int32_t main()
{
   high_functioning_sociopath
   ll t=1;
   //cin>>t;
   while(t--)
   {
      solve();
   }
}

Measured memory_bytes: 3720
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
int n , a[N];
int main() {
    abdelrahman010
    cin >> n;
    for(int i = 1;i < n;i++) {
        int x;
        cin >> x;
        a[x]++;
    }
    for(int i = 1;i <= n;i++)
        cout << a[i] << '\n';
    return 0;
}

Measured memory_bytes: 4428
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1001

struct _Stack {
    int value;
};

_Stack S[MAX];
int top;

void push(int val) {
    top++;
    S[top].value = val;
}

int pop() {
    top--;
    return S[top+1].value;
}


int main() {
//    std::string tmp;
    char tmp[10];
    top = 0;
    while ( scanf("%s", tmp) != EOF ) {
        if ( tmp[0] == '+' ) {
            int a = pop();
            int b = pop();
            push(a + b);
        } else if ( tmp[0] == '-' ) {
            int b = pop();
            int a = pop();
            push(a - b);
        } else if ( tmp[0] == '*' ) {
            int a = pop();
            int b = pop();
            push(a * b);
        } else {
            push(atoi(tmp));
        }
    }
    printf("%d\n", pop());
    return 0;
}

Measured memory_bytes: 3156
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    string S; cin >> S;

    int num = 0;
    for (auto c : S) {
        if (c == '+') {
            num++;
        } else {
            num--;
        }
    }

    cout << num << endl;
    return 0;
}

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

long long func(long long x, long long y){
    long long ans = 1;
    for(long long i=x; i>1; i--){
        ans = ans*i%y;
    }
    return ans;
}

int main(){
    long long N, M;
    const long long y = 1000000000+7;
    cin >> N >> M;
    if((N+M)%2 == 0){
        if(N == M){
            cout << func(N, y)*func(M, y)*2%y;
        }else{
            cout << 0;
        }
    }else{
        if(N == M+1 || N+1 == M){
            cout << func(N, y)*func(M, y)%y;
        }else{
            cout << 0;
        }
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
s=input()
n=len(s)
m=int((n-1)/2)
l=int((n+3)/2)
a=0
#Sは回文の条件
for i in range(n):
    if s[i]!=s[n-i-1]:
        a+=1


for i in range(m):
    if s[i]!=s[m-i-1]:
        a+=1


for i in range(l,n):
    if s[i]!=s[n-i-1]:
        a+=1

if a==0:
    print('Yes')
else:
    print('No')
    



#a=n+m+(n-l+1)


Measured memory_bytes: 3064
def warshall_floyd(c):
    #d[i][j]: iからjへの最短距離
    for k in range(10):
        for i in range(10):
            for j in range(10):
                c[i][j] = min(c[i][j], c[i][k] + c[k][j])
    return c


h, w = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]

cost = warshall_floyd(c)

ans = 0
for _ in range(h):
    a = list(map(int, input().split()))
    for i in a:
        if i > -1:
            ans += cost[i][1]
print(ans)

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

int main() {
	int L, A, B, C, D;
	int jap, mat;

	scanf("%d", &L);
	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);
	scanf("%d", &D);

	jap = 0;
	while (A > 0) {
		A -= C;
		jap++;
	}
	mat = 0;
	while (B > 0) {
		B -= D;
		mat++;
	}
	L -= max(jap, mat);

	printf("%d\n", L);

	return 0;
}

Measured memory_bytes: 1024
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

using ld = long double;
ld henkaku(ld x, ld y) {
  return 180.0*atan2(y, x)/M_PI;
}

using ll = long long;
struct Pos {
  ll x, y;
  ld p;
};

ld dist(ld x, ld y) {
  return sqrt(x*x+y*y);
};

bool ng(ld p1, ld p2) {
  ld p = p2-p1;
  if (p < 0) p += 360;
  return p > 90.0000000000000000;
}

int main() {
  int n; cin >> n;
  vector<Pos> lp;
  for (int i = 0; i < n; ++i) {
    int x, y; 
    cin >> x >> y;
    if (x == 0 && y == 0) continue;
    lp.push_back((Pos){x, y, henkaku(x,y)});
  }
  sort(lp.begin(), lp.end(), [&](auto &l, auto &r){
    return l.p < r.p;
  });
  int n2 = lp.size();
  ld ans = 0;
  for (int i = 0; i < n2; ++i) {
    Pos &p = lp[i];
    Pos cp = p;
    ld best = dist(cp.x,cp.y);
    for (int j = 1; j < n2; ++j) {
      // cerr << i << " " << (i+j)%n2 << endl;
      Pos &p2 = lp[(i+j)%n2];
      // cerr << p.p << " " << p2.p << " " << ng(p.p, p2.p) << endl;
      cp.x += p2.x;
      cp.y += p2.y;
      if (dist(cp.x,cp.y) < best) break;
      best = dist(cp.x,cp.y);
    }
    // cerr << cp.x << " " << cp.y << endl;
    ans = max(ans, best);
    // cerr << lp[i].x << " " << lp[i].y << " " << lp[i].p << endl;
  }
  cout << fixed << setprecision(15) << ans << endl;
}


Measured memory_bytes: 256
import sys
import bisect


def input():
    return sys.stdin.readline()[:-1]


if __name__ == "__main__":
    N = int(input())
    L = sorted(list(map(int, input().split())))
    cnt = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            b = bisect.bisect_left(L, L[i]+L[j])
            cnt += b-j-1
    print(cnt)


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	int ans = 0;
	vector<vector<pair<int, int>>> list;
	
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		vector<pair<int, int>> v;

		for(int j = 0; j < a; j++){
			int x, y;
			cin >> x >> y;

			pair<int, int> p = make_pair(x, y);
			v.push_back(p);
		}

		list.push_back(v);
	}

	for (int i = 0; i < pow(2, n); i++)
	{
		vector<int> man(n);

		for(int j = 0; j < n; j++){
			int block = pow(2, n - j);

			// cout << "i + 1 = " << i + 1 << " j = " << j << " b = " << block << " i % block " << i % block <<endl;

			if (i % block < block / 2)
			{
				man[j] = 1;
			}
			else{
				man[j] = 0;
			}
		}

		bool flag = true;
		for(int j = 0; j < n; j++){
			if(!flag) break;

			if (man[j] == 0) continue;
			
			for(int k = 0; k < list[j].size(); k++){
				if(list[j][k].second != man[list[j][k].first - 1]){
					flag = false;
					break;
				}
			}
		}

		if(flag){
			int tmp = 0;
			for(auto a : man){
				if(a == 1) tmp++;
			}

			if(ans < tmp) ans = tmp;
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,b; cin >> a >> b;
  	int sa = b-a;
  	int x = 0;
  	FOR(i,1,sa) x += i;
  	OUT(x-a);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class UnionFind{
  int n;
  vector<int> data;
public:
  UnionFind(int _n):n(_n),data(_n,-1){}
  bool link(int a, int b){ //if new link, then true.
    int ra=find_root(a);
    int rb=find_root(b);
    if(ra!=rb){
      if(data[rb]<data[ra]) swap(ra,rb);
      data[ra]+=data[rb];
      data[rb]=ra;
    }
    return (ra!=rb);
  }
  bool check(int a, int b){ //if same set, then true.
    return (find_root(a)==find_root(b));
  }
  int find_root(int a){
    return ((data[a]<0)?a:(data[a]=find_root(data[a])));
  }
};

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> P;
  rep(i,N){
    int a;
    cin >> a;
    P.push_back(a);
  }
  vector<pair<int,int>> XY;
  UnionFind uf(N);
  rep(i,M){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    XY.emplace_back(a,b);
    uf.link(a,b);
  }

  map<int,vector<int>> memo;
  rep(i,N){
    memo[uf.find_root(i)].push_back(i);
  }

  int ret = 0;
  FOR(it,memo){
    vector<int> v = it->second;
    vector<int> w;
    //cout << it->first << " : ";
    rep(i,v.size()){
      //cout << v[i] << "," << P[v[i]]-1 << " ";
      w.push_back(P[v[i]]-1);
    }
    //cout << endl;
    sort(ALLOF(w));

    map<int,int> cnt;
    rep(i,v.size()){
      cnt[v[i]]++;
    }
    rep(i,w.size()){
      cnt[w[i]]++;
    }
    FOR(it2,cnt){
      if(it2->second == 2) ret++;
    }
  }
  
  cout << ret << endl;
  
  
  return 0;
}


Measured memory_bytes: 12788
import java.util.*;

public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
      	String s = sc.next();
      	char[] c = s.toCharArray();
      	for(char c1 : c) {
      	    char c2 = c1;
      	    c2 += n;
      	    if (c2 > (char)'Z') {
      	        c2 -= 'Z';
      	        c2 --;
      	        c2 += 'A';
      	    }
      	    System.out.print(c2);
      	}
      	System.out.println("");
    }
}

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

using namespace std;

#define ll long long
#define PI 3.14159265358979323846264338327950L

ll n,k;
int a[200001];
int v[200001];

void solve(){

    cin >> n >> k;

    int tmp;
    for (int i = 0; i < n; i++)
    {
        cin >> tmp;
        a[i] = tmp-1;
        v[i] = -1;
    }
    

    int cur = 0;
    int counter = 0;
    v[0]  = 0;

    while(k>0 ){
        cur = a[cur];
        counter++;
        k--;

        if(v[cur] == -1){
            v[cur] = counter;
            
        }
        else{
            ll cyc = counter - v[cur];
            
            k %= cyc;
            for (int i = 0; i < k; i++)
            {
                cur = a[cur];
            }
            
            cout << cur+1 << endl;
            return;
        }

    }

    cout << cur+1 << endl;

}





int main(){

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

    solve();

}

Measured memory_bytes: 5184
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;

using ci = const int;
using ld = long double;
using llint = long long;
using ullint = unsigned long long;
using pii = pair <int,int>;
using pcc = pair <char,char>;
using pll = pair <llint,llint>;
using pss = pair <string,string>;
using vi = vector <int>;
using vb = vector <bool>;
using vll = vector <llint>;
using vii = vi::iterator;

#define INF (1<<30)
#define MOD 1000000007
#define mt make_tuple
#define all(c) c.begin(), c.end()
#define ms(name,val) memset(name, val, sizeof name)
#define np nullptr
// inline functions



int main()
{
    ios_base::sync_with_stdio(0);
    //cin.tie(0);

    int a, b;
    cin >> a >> b;

    cout << (3*a + b)/2 << '\n';





































    return 0;
}

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

int main()
{
    int n;
    double t,a;
    cin >> n >> t >> a;
    double h[n];
    double p=(t-a)/0.006;
    double m=1000000;
    for(int i=0;i<n;i++)
        cin >> h[i];
    int k=10000;
    for(int i=0;i<n;i++){
        double r=m;
        m=min(m,fabs(h[i]-p));
        if(r!=m) k=i+1;
    }
    cout << k << endl;
    return 0;
}


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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

//#define int int64_t
int v[N+2];
int c[N+2];

int32_t  main(){
  IOS;
  int n;cin>>n;
  fori(i,n){
    cin>>v[i];
  }

  fori(i,n){
    cin>>c[i];
  }
  int ans=0;
  fori(i,n)ans+=max(0,v[i]-c[i]);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256