akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  rep(i,h) cin>>s[i];
  int ans=0;
  rep(si,h)rep(sj,w){
    if(s[si][sj]=='#') continue;
    vector<vector<int>> dist(h,vector<int>(w,INF));
    queue<P> q;
    auto update=[&](int i,int j,int x){
      dist[i][j]=x;
      q.push(P(i,j));// .emplace(i,j)
    };
    update(si,sj,0);
    while(!q.empty()){
      int i=q.front().first;
      int j=q.front().second; q.pop();
      rep(dir,4){
        int ni=i+di[dir], nj=j+dj[dir];
        if(ni<0||ni>=h||nj<0||nj>=w) continue;
        if(s[ni][nj]=='#') continue;
        if(dist[ni][nj]!=INF) continue;
        update(ni,nj,dist[i][j]+1);
      }
    }
    rep(i,h)rep(j,w){
      if(dist[i][j]==INF) continue;
      ans=max(ans,dist[i][j]);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#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 ll = long long;


int main(void) {
  int n;
  cin >> n;
  int a[n+1];
  rep2(i,1,n+1) cin >> a[i];
  
  int t = a[1];
  
  rep2(i,1,n){
    if(t==2){
      cout << i << endl;
      break;
    }
    t = a[t];
  }
  if(t!=2) cout << -1 << endl;
    
  
               
   
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
int main(){
    int n; cin >> n;
    string s,t; cin >> s >> t;
    string ans="";
    rep(i,n){
        ans+=s[i];
        ans+=t[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;		//H:高さ　W:横幅
  cin >> H >> W;	// H, Wの入力
  vector<string> a(H);	//a():文字の数
  
  for(int i=0 ; i<H ; i++)cin >> a.at(i);	//文字入力
  
  for(int i=0 ; i<(W+2) ; i++)cout << "#";	//最初の縁
  cout << endl;
  
  for(int i=0 ; i<H ; i++)cout << "#" << a.at(i) << "#" << endl;
  
  for(int i=0 ; i<(W+2) ; i++)cout << "#";
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<numeric>
#include<algorithm>
#include <sstream>
#include<cstring>
#include<cmath>
#include<iterator>
#include<utility>
#include<array>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<iomanip>
#include<forward_list>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define pa(a) cout<<a<<endl;
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;

int main()
{
#ifdef RAHUL
    freopen("input.txt","r",stdin);
#endif


int t;
int k;
cin>>t;
cin>>k;

if (k==t)
{
    /* code */
    cout<<"Yes"<<endl;
}
else
cout<<"No"<<endl;

return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
   int a,b;
   scanf("%d %d",&a,&b);
   if(a==b){
     printf("a == b\n");
   }else if(a<b){
     printf("a < b\n");
   }else{
     printf("a > b\n");
   }
   return 0;
}

Measured memory_bytes: 580
using System;
using System.Collections.Generic;
public class ABC132D {
    public static long BIGMUM = 1000000007;
    public static void Main() {
        long N, K, ans = 0;
        string[] str = Console.ReadLine().Split(' ');
        N = long.Parse(str[0]);
        K = long.Parse(str[1]);
        long[,] nCk = new long[4000, 4000];
        Fill(nCk);

        for (int i = 1; i <= K; i++) {
            ans = (nCk[N - K + 1, i] * nCk[K - 1, i - 1]) % BIGMUM;
            Console.WriteLine(ans);
        }
    }

    public static void Fill(long[,] nCk) {
        for (int i = 0; i < 4000; i++) {
            nCk[i, 0] = 1;
            nCk[i, i] = 1;
        }
        for (int i = 0; i < 4000; i++) {
            for (int j = 1; j < i; j++) {
                nCk[i, j] = (nCk[i - 1, j] + nCk[i - 1, j - 1]) % BIGMUM;
            }
        }
    }
}


Measured memory_bytes: 135776
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int tp[505050],la[505050];
struct Node
{
	Node *lch,*rch;
	int l,r;
	int ma;
}*rt;
int p[505050];
int t[505050];
int sn;
bool cmp(int x,int y)
{
	return p[x]<p[y];
}
void work(int l,int r)
{
	sn++;
	sort(t+l,t+r+1,cmp);
	for(int i=l;i<=r;i++)
	{
		la[t[i]]=tp[sn];
		tp[sn]=t[i];
	}
}
void update(Node *x)
{
	x->ma=max(x->lch->ma,x->rch->ma);
}
Node *Build(int l,int r)
{
	Node *ret=new Node;
	ret->l=l;
	ret->r=r;
	if(l==r)
	{
		ret->ma=p[l];
		ret->lch=ret->rch=NULL;
		return ret;
	}
	int mid=(l+r)>>1;
	ret->lch=Build(l,mid);
	ret->rch=Build(mid+1,r);
	update(ret);
	return ret;
}
void modify(Node *x,int p)
{
	if(x->l==x->r)
	{
		x->ma=0;
		return;
	}
	int mid=(x->l+x->r)>>1;
	if(p<=mid)
		modify(x->lch,p);
	else
		modify(x->rch,p);
	update(x);
}
int query(Node *x,int l,int r)
{
	if(l<=x->l&&r>=x->r)
		return x->ma;
	int ret=0,mid=(x->l+x->r)>>1;
	if(l<=mid)
		ret=max(ret,query(x->lch,l,r));
	if(mid<r)
		ret=max(ret,query(x->rch,l,r));
	return ret;
}
int n,k;
bool jud(int x)
{
	if(query(rt,max(x-k+1,1),min(x+k-1,n))==p[x])
		return true;
	return false;
}
bool inq[505050];
int ans[505050];
int vv;
priority_queue <int> q;
int main()
{
	int now,ss;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	for(int i=1;i<=n;i++)
		t[i]=i;
	sn=0;
	memset(tp,0,sizeof(tp));
	for(int i=1;i<=n;i+=k)
		work(i,min(i+k-1,n));
	memset(inq,0,sizeof(inq));
	for(int i=1;i<=sn;i++)
	{
		q.push(tp[i]);
		inq[tp[i]]=true;
	}
	rt=Build(1,n);
	inq[0]=true;
	vv=n;
	while(!q.empty())
	{
		now=q.top();
		inq[now]=false;
		q.pop();
		if(jud(now))
		{
			ans[now]=vv--;
			modify(rt,now);
			ss=(now+k-1)/k;
			tp[ss]=la[tp[ss]];
			for(int i=ss-1;i<=ss+1;i++)
				if(!inq[tp[i]])
				{
					q.push(tp[i]);
					inq[tp[i]]=true;
				}
		}
	}
	for(int i=1;i<=n;i++)
		printf("%d\n",ans[i]);
	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<bool> primes(1005, 1);
  primes[0] = primes[1] = false;
  for (int i = 2; i * i <= 1000; ++i) {
    if (not primes[i]) { continue; }
    for (int j = i * i; j <= 1000; j += i) {
      primes[j] = false;
    }
  }

  vector<int> freqs(N + 5, 0);
  for (int i = 2; i <= N; ++i) {
    int val = i;
    for (int p = 2; p <= i; ++p) {
      if (not primes[p]) { continue; }
      while (val > 1 and (val % p) == 0) {
        val /= p;
        ++freqs[p];
      }
    }
  }

  ll ans = 1;
  for (int i = 2; i <= N; ++i) {
    ans *= (freqs[i] + 1);
    ans %= MOD;
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main()
{
    int N;
    cin >> N;
    ll l0 = 2, l1 = 1, l2;
    for(int i=2;i<N+1;++i)
    {
        l2 = l0 + l1;
        l0 = l1;
        l1 = l2;
    }
    if(N == 0) cout << l0;
    else if(N == 1) cout << l1;
    else cout << l2;
    cout << endl;
}


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

int main()
{
	int n;
	string s;
	cin>>n>>s;
	if(n>=3200)
	{
		cout<<s;
		return 0;
	}
	else
	{
		cout<<"red";
		return 0;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string S;
        string T;
        cin >> S >> T;
        ll ns = len(S);
        ll nt = len(T);

        ll ans = inf;
        rep(i, 0, ns-nt+1) {
                ll cnt = 0;
                rep(j, 0, nt) {
                        if (S[i+j] != T[j]) ++cnt;
                }
                chmin(ans, cnt);
        }

        cout << ans << endl;
}


Measured memory_bytes: 3588
#include <stdio.h>
#pragma warning(disable : 4996)
#pragma warning(disable : 4996)



int main(void) {
	long long A, B, K;
	scanf("%lld %lld %lld", &A, &B, &K);
	if (A > K) {
		printf("%lld %lld\n", A - K, B);
	}
	else if(B - (K - A) > 0) {
		printf("0 %lld\n", B - (K - A));
	}
	else {
		printf("0 0\n");
	}

	return 0;
} 
 

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
        return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
        return a / gcd(a, b) * b;
}

llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main()
{
        int p[100001] = {};
        int n;
        ci >> n;

        rep(i, n) ci >> p[i];

        sort(p, p + n);

        int sum = 0;
        for(int i = 0; i < n - 1; i++) sum += p[i];
        sum += p[n - 1] / 2;

        co << sum << en;

        return 0;
}

Measured memory_bytes: 640
class SegmentTree():
    """区間更新、一点取得クエリをそれぞれO(logN)で答えるデータ構造を構築する
    update: 区間[begin, end)をvalに変更する
    get_val: i番目の値を求める
    """
    def __init__(self, n):
        self.update_cnt = 0
        self.n = n
        self.size = 1
        INF = 2**31 - 1
        while self.size < n:
            self.size *= 2
        self.node = [[self.update_cnt, INF] for i in range(2*self.size - 1)]

    def update(self, begin, end, val):
        self.update_cnt += 1
        begin += (self.size - 1)
        end += (self.size - 1)
        while begin < end:
            if (end - 1) & 1:
                end -= 1
                self.node[end] = [self.update_cnt, val]
            if (begin - 1) & 1:
                self.node[begin] = [self.update_cnt, val]
                begin += 1
            begin = (begin - 1) // 2
            end = (end - 1) // 2

    def get_val(self, i):
        i += (self.size - 1)
        val = self.node[i]
        while i > 0:
            i = (i - 1) // 2
            val = max(val, self.node[i])
        return val[1]


n, q = map(int, input().split())
info = [list(map(int, input().split())) for i in range(q)]

st = SegmentTree(n)
for i in range(q):
    if info[i][0] == 0:
        s, t, val = info[i][1], info[i][2], info[i][3]
        st.update(s, t + 1, val)
    else:
        s = info[i][1]
        print(st.get_val(info[i][1]))


Measured memory_bytes: 47936
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
int main(){
	while(true){
		int n,w,cnt[11]={};
		cin >> n >> w;
		if(n==0) break;
		int mx=0,cntmx=0;
		rep(i,n){
			int v;
			cin >> v;
			cnt[v/w]++;
			mx=max(mx,v/w);
			cntmx=max(cntmx,cnt[v/w]);
		}
		double ans=0.01;
		rep(i,mx+1) ans+=(double)cnt[i]/cntmx*(mx-i)/mx;
		printf("%.9f\n",ans);
	}
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long long n,a,i,sum=0;
    cin>>n>>a;
    long long b[a];
    for(i=0;i<a;i++)
    {
        cin>>b[i];
        sum=sum+b[i];
    }
    if(n<=sum)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define MAX 250

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

int parent(int i){
  return i/2;
}


int heap[MAX];


main(){
  int i, size;

  scanf("%d", &size);

  size = size + 1;

  for( i = 1; i < size; i++){
    scanf("%d", &heap[i]);
  }

  for( i = 1; i < size; i++){
    
    printf("node %d: key = %d, ", i, heap[i]);
  
    if( parent(i) > 0 ){
      printf("parent key = %d, ", heap[parent(i)]);
    }
    
    if( left(i) < size ){
      printf("left key = %d, ", heap[left(i)]);
    }
    
    if( right(i) < size ){
      printf("right key = %d, ", heap[right(i)]);
    }

    printf("\n");

  }

  return 0;

}

Measured memory_bytes: 600
#include <cstdio>
#include <unordered_map>
#include <vector>
using namespace std;
using Int = int64_t;
class FastIO {
  static const int rdata_sz = (1 << 25), wdata_sz = (1 << 25);
  char rdata[rdata_sz], wdata[wdata_sz], *rb, *wb;
  char tmp_s[20];
 
public:
  FastIO() {
    fread(rdata, 1, rdata_sz, stdin);
    rb = rdata; wb = wdata;
  }
  ~FastIO() {
    fwrite(wdata, 1, wb - wdata, stdout);
  }
 
  template<typename T>
  inline void read_i(T &x) {
    bool neg = false;
    x = 0;
    while((*rb < '0' || *rb > '9') && *rb != '-') ++rb;
    if(*rb == '-') {
      neg = true;
      ++rb;
    }
    while('0' <= *rb && *rb <= '9') {
      x = 10 * x + (*rb - '0');
      ++rb;
    }
    if(neg) x = -x;
  }
 
#define pc(x) *(wb++) = x
  template<typename T>
  inline void writeln_i(T x) {
    if (x == 0) { pc('0'); pc('\n'); return; }
    if(x < 0) { pc('-'); x = -x; }
    char *t = tmp_s;
    while(x) {
      T y = x / 10;
      *(t++) = (x - y*10) + '0';
      x = y;
    }
    while(t != tmp_s) pc(*(--t));
    pc('\n');
  }
#undef pc
};
FastIO io;
int main() {
    unordered_map<Int, Int> cnt, mul;
    Int N, sum = 0;
    io.read_i(N);
    vector<Int> A(N);
    for (auto& i : A) {
        io.read_i(i);
        cnt[i]++;
    }
    for (const auto& p : cnt) {
        sum += p.second * (p.second - 1) / 2;
        mul[p.first] = p.second * (p.second - 1) / 2;
    }
    for (int i : A) io.writeln_i(sum - cnt[i] * (cnt[i] - 1) / 2 + (cnt[i] - 1) * (cnt[i] - 2) / 2);
}

Measured memory_bytes: 17992
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  long long ans = INF;
  for(int i = 0; i <= 200000; i += 2){
    int p = x, q = y;
    long long cnt = i * c;
    p = max(0, p - i / 2);
    q = max(0, q - i / 2);
    ans = min(ans, cnt + p * a + q * b);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
import java.util.*;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    HashMap<String, Integer> map = new HashMap<>();
    while (N-- > 0) {
      String s = sc.next();
      map.put(s, map.getOrDefault(s, 0) + 1);
    }
    Stream<Map.Entry<String, Integer>> s =
        map.entrySet().stream()
            .sorted(
                (a, b) ->
                    b.getValue().equals(a.getValue())
                        ? a.getKey().compareTo(b.getKey())
                        : b.getValue() - a.getValue());
    Iterator<Map.Entry<String, Integer>> it = s.iterator();
    Map.Entry<String, Integer> e0 = it.next();
    int num = e0.getValue();
    System.out.println(e0.getKey());
    while (it.hasNext()) {
      Map.Entry<String, Integer> e1 = it.next();
      if (e1.getValue() != num) break;
      System.out.println(e1.getKey());
    }
  }
}


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

int main(){
  string s;
  char data[5][7]={
    "afkpuz",
    "bglqv.",
    "chmrw?",
    "dinsx!",
    "ejoty "
  };

  while(cin>> s){
    if(s.size()%2){
      cout<< "NA"<< endl;
      continue;
    }
    string ans="";
    for(int i=0;i<s.size();i+=2){
      int y=s[i+1]-'1';
      int x=s[i]-'1';
      if(y<0 || y>4 || x<0 || x>5){
	ans="NA";
	break;
      }
      else ans+=data[y][x];
    }
    cout<< ans;     
    cout<< endl;
  }
}

Measured memory_bytes: 1196
s = input()
if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
elif s == 'SAT':
    print(1)

Measured memory_bytes: 38256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s;
    cin >> s;
    int n = s.size() + 1;
    VI a(n);
    if (s[0] == '<') {
        for (int i = 0; i < n - 1 && s[i] == '<'; ++i) {
            a[i+1] = i + 1;
        }
    }
    if (s[n-2] == '>') {
        for (int i = n - 2; i >= 0 && s[i] == '>'; --i) {
            //dump(i);
            a[i] = max(a[i], n - 2 - i + 1);
        }        
    }
    //REP(i,0,n) cout << a[i] << endl;
    REP(i,1,n-1) {
        if (s[i-1] == '>' && s[i] == '<') {
            for (int j = i - 1; j >= 0 && s[j] == '>'; --j) {
                a[j] = max(a[j], i - j);
            }
            for (int j = i + 1; j < n && s[j-1] == '<'; ++j) {
                a[j] = max(a[j], j - i);
            }
        }
    }
    LL sum = 0;
    REP(i,0,n) sum += a[i];
    cout << sum << endl;
}

int main() {
    solve();
    
    return 0;
}

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

const int N = 2e3 + 100;

int n, w[N], b[N];
int dp[N][N];
int cw[N][N], cb[N][N];

int main() {
  char s[5];
  scanf("%d", &n);
  for (int i = 1; i <= 2 * n; i++) {
    int x;
    scanf("%s %d", s + 1, &x);
    if (s[1] == 'W') {
      w[x] = i;
    } else {
      b[x] = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if (w[i] < w[j]) {
        cw[i][0]++;
      }
    }
    for (int j = 1; j <= n; j++) {
      cw[i][j] = cw[i][j - 1];
      if (w[i] < b[j]) {
        cw[i][j]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if (b[i] < b[j]) {
        cb[0][i]++;
      }
    }
    for (int j = 1; j <= n; j++) {
      cb[j][i] = cb[j - 1][i];
      if (b[i] < w[j]) {
        cb[j][i]++;
      }
    }
  }
  int c1 = 0, c2 = 0;
  for (int i = 1; i <= n; i++) {
    c1 += cw[i][0];
    c2 += cb[0][i];
    dp[i][0] = c1;
    dp[0][i] = c2;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = min(dp[i - 1][j] + cw[i][j], dp[i][j - 1] + cb[i][j]);
    }
  }
  printf("%d\n", dp[n][n]);
  return 0;
}

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

using ll = long long;

int main() {
    int N, A, P = 2;
    cin >> N >> A;
    ll ans = A - 1;
    rep(i, N - 1) {
        cin >> A;
        if (A < P) continue;
        if (A == P) {
            P++;
            continue;
        }
        ans += (A - 1) / P;
    }
    cout << ans << endl;
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.1415926535
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main()
{
    int n;
    cin>>n;
    cout<<n*n;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define INF 1000000000000
#define MOD 1000000007
#define DEBUG(x) cerr<<'>'<<#x<<':'<<x<< endl
using namespace std;
ll  path[1005][1005];
ll H, W;

ll f(ll i, ll j)
{
    if(path[i][j] != -1)
        return path[i][j];
    path[i][j] = (f(i - 1, j) + f(i, j - 1)) % MOD;
    return path[i][j];
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> W >> H;
    for(ll i = 0; i <= W; i++)
    {
        for(ll j = 0; j <= H; j++)
        {
            if((i == 0)||(j == 0))
                path[j][i] = 0;
            else
                path[j][i] = -1;
        }
    }
    path[1][2] = 1; path[2][1] = 1;
    char ch;
    for(ll i = 1; i <= W; i++)
    {
        for(ll j = 1; j <= H; j++)
        {
            cin >> ch;
            if(ch == '#')
                path[j][i] = 0;
        }
    }    
    ll ans = f(H, W);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8192
N = int(input())
H = list(map(int, input().split()))

for i in reversed(range(N - 1)):
    if H[i + 1] - H[i] == -1:
        H[i] -= 1
    elif H[i + 1] - H[i] < -1:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 14252
N = input()
l = len(N)
if l == 1:
    print(N)
    exit()
nf = N[0]
ne = N[-1]
nm = 0
base = 1
if l > 2:
    nm = int(N[1:l-1:])
for i in range(1,l-2):
    base += 10**i
ans = 0

for i in range(int(N)+1):
    i = str(i)
    f = i[0]
    e = i[-1]
    if e != "0":
        if f == e:
            ans += 1
        if e < nf:
            ans += base
            if l > 2:
                ans += 10**(l-2)
        elif e == nf:
            if f <= ne:
                ans += base
                if l>2:
                    ans += nm + 1
            else:
                ans += base
                ans += nm
        else:
            if l >2:
                ans += base
print(ans)





Measured memory_bytes: 43244
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
		Addition solver = new Addition();
		solver.readInput();
		solver.solve();
		solver.writeOutput();
	}

	static class Addition {
		private int n;
		private int a[];

		private Scanner scanner;
		private String output;

		public Addition() {
			scanner = new Scanner(System.in);
		}

		public void readInput() {
			n = Integer.parseInt(scanner.next());
			a = new int[n];
			for(int i=0; i<n; i++) {
				a[i] = Integer.parseInt(scanner.next());
			}
			return;
		}

		public void solve() {
			int count=0;
			for(int i=0; i<n; i++) {
				if(a[i]%2 == 1) {
					count++;
				}
			}
			if(count%2==0) {
				output = "YES";
			} else {
				output ="NO";
			}
			return;

		}

		public void writeOutput() {
			System.out.println(output);
		}

	}
}

Measured memory_bytes: 49788
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int A[M];
    
    for(int i=0; i<M; i++){
        cin >> A[i];
    }
    
    int sum=0;
    for(int i=0; i<M; i++){
        sum+= A[i];
    }

    if(sum>N){
        cout << -1 << endl;
    }
    else{
        cout << N-sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
<?php
$inputs = [];
while ($line = fgets(STDIN)) {
   $inputs[] = explode(" ", trim($line));
}
$max_move_count = $inputs[0][1];
$stone_list = $inputs[1];

//メイン処理
$ary_count = count($stone_list);
$max_total = 0;

//配列の数の2倍は超えない
$max_move_count = min($max_move_count, $ary_count * 2);
for($move_count = 1; $move_count <= $max_move_count; $move_count++) {
	
	$trash = $max_move_count - $move_count;	//捨てれる数
	$truth_move_count = min($ary_count, $move_count);	//取り出せるのは最大配列数
	
	for ($left = 0; $left <= $truth_move_count; $left++) {
		$right = $truth_move_count - $left;
		
		//左右から指定数だけ取得する
		$get_list = array_merge(array_slice($stone_list, 0, $left), array_slice($stone_list, -1 * $right, $right));
		
		//捨てれるだけ捨てる
		rsort($get_list);
		for ($i = 0; $i < $trash; $i++) {
			$num = array_pop($get_list);
			if ($num > 0) {
				$get_list[] = $num;
				break;
			}
		}
		$max_total = max($max_total, array_sum($get_list));
	}
}

echo $max_total;

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&s){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#else
template<class...T>void dprint(T&&...t){_print(cerr,t...);}
#endif
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<<(ostream&o,const multiset<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>>n;
    vl h(n);
    cin>>h;

    ll last=LINF;
    REPR(i,n){
        if(h[i]>last){
            if(h[i]-last==1)h[i]--;
            else{
                Yes(0);
                return 0;
            }
        }
        last=h[i];
    }

    Yes(1);

    return 0;
}


Measured memory_bytes: 1024
n = gets.to_i
cards = gets.split(' ').map{|s| s.to_i}.sort{|a, b| b <=> a }

alice = 0
bob = 0


cards.each_with_index do |c, i |
  if i % 2 == 0
    alice += c
  else
    bob += c
  end
end

puts alice - bob

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

#define SIZE(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n); ++i)
#define print(x) cout<<x<<endl;

typedef long long ll;

//vector<vector<int>> a(n,vector<int>(3));

int gcd(int a, int b) { return min(a,b) ? gcd(min(a,b), max(a,b)%min(a,b)) : max(a,b); }
int dxy4[5] = { 0,1,0,-1,0 };
int dxy8[9] = { 0,1,1,0,-1,1,-1,-1,0 };
ll inf = 1LL <<61;
ll mod7 = 1000000007;
ll mod9 = 1000000009;

int main() {
    ll n,W;
    cin>>n>>W;
    vector<ll> w(n+1);
    vector<ll> v(n+1);
    ll sumv = 0;
    rep(i,n){
        cin>>w[i+1]>>v[i+1];
        sumv += v[i+1];
    }
    // print(sumv)
    vector<vector<ll>> dp(n+1,vector<ll>(sumv+1,inf));
    dp[0][0] = 0;
    for(int i=1;i<=n;++i){
        for(ll j=0;j<=sumv+1;++j){
            if(j<v[i]){
                dp[i][j] = dp[i-1][j];
                continue;
            }else{
                // if(dp[i-1][j-v[i]] == inf)continue;
                dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i]] + w[i]);
            }
        }
    }
    //     rep(i,n+1){
    //     rep(j,sumv+1){
    //         cout << dp[i][j]<<endl;;
    //     }
    //     cout<<endl;
    // }
    int ans;
    rep(i,sumv+1){
        if(dp[n][i]<=W)ans = i;
    }
    // cout<<dp[n][sumv]<<endl;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 80256
#include<iostream>
#include<vector>
#include<string>

int main(){
    int x, y, z;
    std::cin >> x >> y >> z;
    std::swap(x, y);
    std::swap(x, z);
    std::cout << x << " " << y << " " << z << std::endl;
    return 0;
}


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

using namespace std;

#define endl '\n'
#define ll long long

void solve(){
    int n;
    cin>>n;
    ll arr[n];
    for(int i = 0;i<n;i++)cin>>arr[i];
    ll x = arr[0];
    for(int i = 1;i<n;i++)x ^= arr[i];
    for(int i = 0;i<n;i++){
        ll z = x^arr[i];
        cout<<z<<" ";
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int t = 1;
    while(t--){
        solve();
    }
    return 0;
}

// 2
// 1 2
// 3
// 1 100
// 2 100
// 100 1000

Measured memory_bytes: 5160
h, w, m = map(int, input().split())
R = [0] * h
C = [0] * w
XY = [tuple(map(int, input().split())) for i in range(m)]
X = [x - 1 for x, y in XY]
Y = [y - 1 for x, y in XY]
for x, y in zip(X, Y):
    R[x] += 1
    C[y] += 1
maxR, maxC = max(R), max(C)
cnt0 = R.count(maxR) * C.count(maxC)
cnt1 = 0
for x, y in zip(X, Y):
    if R[x] == maxR and C[y] == maxC:
        cnt1 += 1
print(maxR + maxC - int(cnt0 == cnt1))


Measured memory_bytes: 169368
X , N = map(int,input().split())
if N == 0:
    print(X)
elif N == 1:
    P = int(input())
    if P == X:
        print(X - 1)
    elif X + 1 == P or X - P > 1:
        print(X - 1)
    else:
        print(X + 1)

else:
    P = list(map(int,input().split()))
    j = 1
    if X not in P:
        print(X)
    else:
        while True:
            
            if X - j not in P:
                print(X - j)
                break
            if X + j not in P:
                print(X + j)
                break
            j += 1

Measured memory_bytes: 9216
n=int(input())
l=len(str(n))
k=int(input())
dp=[[[0]*(k+1) for _ in range(2)] for _ in range(l+1)]
dp[0][1][0]=1
for pos in range(l):
  num=int(str(n)[pos])
  for i in range(10):
    if i==0:
      for count in range(k+1):
        if num==0:
          dp[pos+1][1][count]+=dp[pos][1][count]
          dp[pos+1][0][count]+=dp[pos][0][count]
        else:
          dp[pos+1][0][count]+=(dp[pos][0][count]+dp[pos][1][count])
    elif i<num:
      for count in range(k):
        dp[pos+1][0][count+1]+=(dp[pos][0][count]+dp[pos][1][count])
    elif i==num:
      for count in range(k):
        dp[pos+1][1][count+1]+=dp[pos][1][count]
        dp[pos+1][0][count+1]+=dp[pos][0][count]
    else:
      for count in range(k):
        dp[pos+1][0][count+1]+=dp[pos][0][count]
print(dp[l][0][k]+dp[l][1][k])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 2e5+7;
const int maxV = 90010;
//const int INF = 1e9+9;
//const ll INF = (1ll)<<60;
const int INF = 2e9+9;
const int MOD = 1e9+7;

int n,m;
int a[maxN];
int b[maxN];
vector<int> v[maxN];
int vis[maxN];
int c[maxN];
ll d[maxN];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		b[i] = 1;
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&a[i]);
		b[a[i]] = 0;
	}
	d[0] = 1;
	if(b[1]!=0)
		d[1] = 1;
	for(int i=2;i<=n;i++)
	{
		if(b[i] != 0)
		{
			d[i] = (d[i]+d[i-1]+d[i-2])%MOD;
		}
	}
	cout<<d[n]<<endl;
	return 0;
}

Measured memory_bytes: 7424
#include<iostream>
#include<stdio.h>
using namespace std;
double dat(double a,double b,double c,double d) {
	return a*d - b*c;
}
int main() {
	double a,b,c,d,e,f;
	while(cin >> a >> b >> c >> d >> e >> f) {
		// クラメルの公式を利用
		double A = dat(a,b,d,e);
		//if(A == 0)
		//	cout << "error" << endl;
		double A1 = dat(c,b,f,e);
		double A2 = dat(a,c,d,f);
		
		// x y
		double x = A1/A;
		double y = A2/A;
		
		// 小数点第4位で四捨五入
		int x_cp;
		int y_cp;
		if(x < 0)
			x_cp = (int)(x*1000 - 0.5);
		else
			x_cp = (int)(x*1000 + 0.5);
		if(y < 0)
			y_cp = (int)(y*1000 - 0.5);
		else
			y_cp = (int)(y*1000 + 0.5);
		
		x = (double)x_cp / 1000;
		y = (double)y_cp / 1000;
		
		printf("%.3lf %.3lf\n",x,y);
	}
	return 0;
}

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


int main(){
  int a,b;
  cin>>a>>b;
  string ans;
  if(a<=0&&b>=0) ans="Zero";
  else if(a<0&&(a+b)%2==0)ans="Negative";
  else ans="Positive";
  cout<<ans<<endl;
  
  return 0;
}


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

using namespace std;

const int N = 210;

int g[N][N];

int main() {
  int n, m, r;
  scanf("%d %d %d", &n, &m, &r);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      g[i][j] = (i == j ? 0 : (int) 1e9);
    }
  }
  vector<int> orders;
  for (int i = 0; i < r; i++) {
    int x;
    scanf("%d", &x);
    orders.push_back(x);
  }
  while (m--) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    g[x][y] = g[y][x] = min(z, g[x][y]);
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  int mn = (int) 1e9;
  sort(orders.begin(), orders.end());
  do {
    int crt = 0;
    for (int i = 1; i < r; i++) {
      crt += g[orders[i - 1]][orders[i]];
    }
    mn = min(mn, crt); 
  } while (next_permutation(orders.begin(), orders.end()));
  printf("%d\n", mn);
  return 0;
}

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



int main(){
	int N;
	cin >> N;
	vector<int> B(N+1);
	vector<int> a(N+1);
	rep(i,N){cin >> a[i+1];}

	for(int i=N; i>0; i--){
		if(i>N/2){ B[i] = a[i]; }
		else{
			int sum = 0;
			for(int j=i; j<=N; j+=i){
				if(B[j]==1)sum++;
			}
			B[i] = (sum+a[i])%2;
		}
	}

	cout << count(B.begin(),B.end(),1) << endl;
	vector<int> ans;
	for(int i=1; i<=N; i++){
		if(B[i]){ ans.push_back(i); }
	}
	for(int i=0; i<(int)ans.size(); i++){
		if(i)cout<<" ";
		cout << ans[i];
	}
	if(!ans.empty())cout << endl;
}


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int LIM = 32;

vector<int> zf(vector<int> a) {
	int n = (int)a.size();
	vector<int> z(n);
	int l = 0;
	int r = 0;
	for (int i = 1; i < n; i++) {
		z[i] = max(0, min(r - i, z[i - l]));
		while (i + z[i] < n && a[z[i]] == a[i + z[i]]) {
			z[i]++;
		}
		if (i + z[i] > r) {
			l = i;
			r = i + z[i];
		}
	}
	return z;
}

vector<int> solve(vector<int> a, vector<int> b) {
	int n = (int)a.size();
	vector<int> to = a;
	to.push_back(2);
	for (auto t : b) {
		to.push_back(t);
	}
	for (auto t : b) {
		to.push_back(t);
	}
	auto zz = zf(to);
	vector<int> ans;
	for (int shift = 0, pnt = n + 1; shift < n; shift++, pnt++) {
		if (zz[pnt] == n) {
			ans.push_back(shift);
		}
	}
	return ans;
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for (auto &t : a) {
    	cin >> t;
    }
    for (auto &t : b) {
    	cin >> t;
    }
    vector<int> cnt(n);
    for (int bit = 0; bit < LIM; bit++) {
    	vector<int> na(n);
    	vector<int> nb(n);
    	for (int i = 0; i < n; i++) {
    		na[i] = ((a[i] >> bit) & 1);
    		nb[i] = ((b[i] >> bit) & 1);
    	}
    	// for (auto t : na) {
    	// 	cerr << t << ' ';
    	// }
    	// cerr << endl;
    	// for (auto t : nb) {
    	// 	cerr << t << ' ';
    	// }
    	// cerr << endl;
    	vector<int> lol;
    	vector<int> hv(n);

    	lol = solve(na, nb);
    	for (auto t : lol) {
    		hv[t] = 1;
    	}

    	for (auto &t : na) {
    		t ^= 1;
    	}

    	lol = solve(na, nb);
    	for (auto t : lol) {
    		hv[t] = 1;
    	}

    	for (int i = 0; i < n; i++) {
    		cnt[i] += hv[i];
    	}
    }
    vector<pair<int, int>> out;
    for (int i = n - 1; i >= 0; i--) {
    	if (cnt[i] == LIM) {
    		out.emplace_back((n - i) % n, a[0] ^ b[i]);
    		// cout << (n - i) % n << ' ' << (a[0] ^ b[i]) << '\n';
    	}
    }
    sort(out.begin(), out.end());
    for (auto t : out) {
    	cout << t.first << ' ' << t.second << endl;
    }
}   


Measured memory_bytes: 18004
n, m = list(map(int,input().split()))
k = [list(map(int,input().split())) for i in range(n)]

dic = {}
for i in range(n):
    for j in range(1, k[i][0]+1):
        if k[i][j] in dic:
            dic[k[i][j]] += 1
        else:
            dic[k[i][j]] = 1

ans = 0
for i in dic.values():
    if n == i:
        ans += 1
print(ans)

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 200500;

int n;
ll p[N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;
	
	cin >> n;

	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		p[i] = p[i - 1] + x;
	}

	ll ans = inf;

	for (int i = 2, pl = 1, pr = 2; i < n; i++) {
		while (pl + 1 < i && abs(p[pl + 1] - (p[i] - p[pl + 1])) <= abs(p[pl] - (p[i] - p[pl])))
			pl++;
		while (pr + 1 < n && abs(p[pr + 1] - p[i] - (p[n] - p[pr + 1])) <= abs(p[pr] - p[i] - (p[n] - p[pr])))
			pr++;
		ans = min(ans, max({p[pl], p[i] - p[pl], p[pr] - p[i], p[n] - p[pr]}) - min({p[pl], p[i] - p[pl], p[pr] - p[i], p[n] - p[pr]}));
	}

	cout << ans;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 1792
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let a = get!();
    let b = get!();
    
    let k = (a + b) / 2;
    if (a - k).abs() != (b - k).abs() {
        println!("IMPOSSIBLE");
    } else {
        println!("{}", k);
    }
}

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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int h, n; cin >> h >> n;
	int sum = 0;
	rep(i, n){
		int a; cin >> a;
		sum += a;
	}
	if(sum >= h) cout << "Yes" << endl;
	else cout << "No" << endl;
} 

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0]*n
        self.size = [1]*n
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        else:
            if self.rank[x] < self.rank[y]:
                self.par[x] = y
                self.size[y] += self.size[x]
            else:
                self.par[y] = x
                self.size[x] += self.size[y]
            
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    def tree_size(self, x):
        return self.size[self.find(x)]
    


N, M = map(int, input().split())
bridge = [[int(_) for _ in input().split()] for _ in range(M)]
uf = UnionFind(N+1)
anslist = deque()
ans = N*(N-1)//2
anslist.append(ans)


for i in range(M-1):
    island1 = bridge[M-i-1][0]
    island2 = bridge[M-i-1][1]
    if uf.find(island1) != uf.find(island2):
        ans -= uf.tree_size(island1) * uf.tree_size(island2)
    
    anslist.append(ans)
    uf.unite(bridge[M-i-1][0], bridge[M-i-1][1])

for _ in range(M):
    print(anslist.pop())

Measured memory_bytes: 29232
from collections import deque

N, *AB = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)


def get_dist(src):
    Q = deque([src])
    dist = [0] * (N + 1)
    while Q:
        v =  Q.popleft()
        for u in E[v]:
            if dist[u] == 0:
                Q.append(u)
                dist[u] = dist[v] + 1
    return dist[1:]

F = get_dist(1)
S = get_dist(N)

fennec, snuke = 0, 0
for f, s in zip(F, S):
    if f <= s:
        fennec += 1
    else:
        snuke += 1

if fennec > snuke:
    print("Fennec")
else:
    print("Snuke")


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,W;
ll dp[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>W;
	while(N--) {
		cin>>x>>y;
		for(i=W-x;i>=0;i--) dp[i+x]=max(dp[i+x],dp[i]+y);
	}
	
	cout<<*max_element(dp,dp+W+1)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1024
import numpy as np
N, M = 3, 2

ARR = [
    list("#.#"),
    list(".#."),
    list("#.#"),
]

ARR2 = [
    "#.",
    ".#"
]


#
#
# N,M = 4, 1
# ARR = [
#     "....",
#     "....",
#     "....",
#     "....",
# ]
#
# ARR2 = [
#     "#"
# ]
# #
# N,M = 5,2
#
# ARR = [
#     "...##.",
#     "###..#",
#     "...##.",
#     "......",
#     "....##"
# ]
#
# ARR2 = [
#     "......",
#     "....##"
# ]
#
N,M = map(int,input().split())
ARR = []

for i in range(N):
    ARR.append(list(input()))

ARR2 = []

for j in range(M):
    ARR2.append(input())


def calculate(n, m, arr1, arr2):
    arr1 = np.array(arr1)
    isOK = False
    for j in range(0, n - m + 1):
        for i in range(0, len(arr1[0]) - len(arr2[0]) + 1):
            # print(j, i)
            c1 = arr1[j:j + m,i:i + len(arr2[0])]
            s1 = np.ravel(c1)
            s1 = "".join(s1)
            s2 = "".join(arr2)
            if s1 == s2:
                isOK = True
                break

        if isOK == True:
            break

    if isOK:
        print("Yes")
    else:
        print("No")


calculate(N, M, ARR, ARR2)


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

int main()
{
    int n;
    cin>>n;
    long count1=0;
    for(int i=0;i<n;i++)
    {
        long a;
        cin>>a;
        if(a%2==1)
            count1++;
    }
    if(count1%2==0)
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
using System;

class sort
{
    public static void Main()
    {
        String[] s = Console.ReadLine().Split();

        int[] a = new int[3];

        a[0] = int.Parse(s[0]);
        a[1] = int.Parse(s[1]);
        a[2] = int.Parse(s[2]);

        Array.Sort(a);

        Console.WriteLine(a[0] + " " + a[1] + " " + a[2]);


    }

}


Measured memory_bytes: 9324