akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

ll sum[500];
ll dp[501][501];
const ll inf = 1e15;

ll get(int l, int r) {
    ll ret = sum[r];
    if (l) ret -= sum[l-1];
    return ret;
}

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    rep(i, N) {
        sum[i] = A[i];
        if (i>0) sum[i] += sum[i-1];
    }

    rep(i, N+1) rep(j, N+1) dp[i][j] = inf;
    rep(i, N+1) dp[i][i] = 0;


    for (int len=1; len<N; ++len) {
        for (int l=0; l<N-len; ++l) {
            int r = l + len;
            for (int m=l; m<r; ++m) {
                dp[l][r] = min(dp[l][r], dp[l][m] + dp[m+1][r] + get(l, r));
            }
        }
    }

    cout << dp[0][N-1] << endl;
}


Measured memory_bytes: 1792
<?php
fscanf(STDIN,"%d %d %d",$c[1][1], $c[1][2], $c[1][3]);
fscanf(STDIN,"%d %d %d",$c[2][1], $c[2][2], $c[2][3]);
fscanf(STDIN,"%d %d %d",$c[3][1], $c[3][2], $c[3][3]);

if($c[1][1]-$c[2][1] == $c[1][2]-$c[2][2] && $c[1][1]-$c[2][1] == $c[1][3]-$c[2][3] && 

$c[2][1]-$c[3][1] == $c[2][2]-$c[3][2] && $c[2][1]-$c[3][1] == $c[2][3]-$c[3][3] && 

$c[3][1]-$c[1][1] == $c[3][2]-$c[1][2] && $c[3][1]-$c[1][1] == $c[3][3]-$c[1][3])
{
    echo("Yes");
}
else
{
    echo("No");
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define add(a,b) a=((a)+(b))%1000000007
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define mod 1000000007
#define ll long long
//#define file
using namespace std;

int a[200001][2],ls[200001],nx[200001],d[200001],g[200001],sum[200001],len,n,i,j,k,l;
ll p[200001],f[200001][3],F[3],ans;

void New(int x,int y) {++len;a[len][0]=y;a[len][1]=ls[x];ls[x]=len;}
void dfs(int t,int D)
{
	int i;
	++sum[D];
	
	for (i=ls[t]; i; i=a[i][1])
	{
		dfs(a[i][0],D+1);
		if (d[a[i][0]]+1>d[t])
		d[t]=d[a[i][0]]+1,nx[t]=a[i][0];
	}
}
void Dfs(int t)
{
	int i,j,k,l;
	
	f[t][0]=f[t][1]=1;
	if (nx[t]!=-1)
	{
		for (i=ls[t]; i; i=a[i][1]) Dfs(a[i][0]);
		for (i=ls[t]; i; i=a[i][1])
		if (a[i][0]!=nx[t])
		{
			j=nx[t],k=a[i][0];
			while (k!=-1)
			{
				add(f[k][0],f[k][2]),f[k][2]=0;
				if (g[j]!=t)
				g[j]=t,add(f[j][0],f[j][2]),f[j][2]=0;
				
				memset(F,0,sizeof(F));
				add(F[0],f[j][0]*f[k][0]);
				add(F[1],f[j][0]*f[k][1]+f[j][1]*f[k][0]);
				add(F[2],f[j][0]*f[k][2]+f[j][1]*(f[k][1]+f[k][2])+f[j][2]*(f[k][0]+f[k][1]+f[k][2]));
				memcpy(f[j],F,sizeof(F));
				j=nx[j],k=nx[k];
			}
		}
	}
}

int main()
{
	#ifdef file
	freopen("arc086e.in","r",stdin);
	#endif
	
	memset(g,255,sizeof(g));
	memset(nx,255,sizeof(nx));
	scanf("%d",&n);
	p[0]=1;
	fo(i,1,n) scanf("%d",&j),New(j,i),p[i]=p[i-1]*2%mod;
	
	dfs(0,0);
	Dfs(0);
	
	for (i=j=0; i!=-1; add(ans,f[i][1]*p[n+1-sum[j]]),i=nx[i],++j);
	printf("%lld\n",ans);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

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

int main(){
    int n, m, i, j, c = 0, r = 0;
    cin >> n;
    string sm = " ", s[n];
    for(i=0; i<n; i++){
        cin >> s[i];
    }
    cin >> m;
    string t[m+1];
    for(i=0; i<m; i++){
        cin >> t[i];
    }
    t[m] = "zzzzzzzzzzz";
    sort(s, s+n);
    sort(t, t+m);
    i = 0;
    j = 0;
    while(i<n){
        if(s[i] != sm){
            while(t[j] <= sm){
                if(sm == t[j]){
                    c--;
                }
                j++;
            }
            r = max(r, c);
            c = 1;
            sm = s[i];
        }else{
            c++;
        }
        i++;
    }
    while(t[j] <= sm){
        if(sm == t[j]){
            c--;
        }
        j++;
    }
    r = max(r, c);
    cout << r;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
typedef struct{
  int p,l,r,d;
}Node;
Node A[100001];
int rec(int,int);
int main(){
  int n,k;
  int id,c,l,r,a;
  int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].p=A[i].l=A[i].r=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&c);
      if(j==0) A[id].l = c;
      else A[l].r = c;
      l = c;
      A[c].p = id;
    }
  }
  for(i=0;i<n;i++) if(A[i].p==-1) r = i;
  rec(r,0);
  
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,A[i].p,A[i].d);
    if(A[i].p==-1)printf("root, ");
    else if(A[i].l!=-1) printf("internal node, ");
    else printf("leaf, ");
    printf("[");
    if(A[i].l!=-1){
      printf("%d",A[i].l);
      a = A[i].l;
      while(1){
	if(A[a].r==-1) break;
	else printf(", %d",A[a].r);
	a = A[a].r;
      }
    }
    printf("]\n");
  }
  return 0;
}
int rec(int r,int p){
  A[r].d = p;
  if(A[r].r!=-1) rec(A[r].r,p);
  if(A[r].l!=-1) rec(A[r].l,p+1);
}



Measured memory_bytes: 6372
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, V, B, W, T = map(int, read().split())

def solve(A, V, B, W, T):
    x = abs(A - B)
    if V <= W:
        return 'NO'
    y = (V - W) * T
    return 'YES' if y >= x else 'NO'

print(solve(A, V, B, W, T))

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int R;
    cin >> R;
    string ans;
    if(R < 1200) ans = "ABC";
    else if(R >= 1200 && R < 2800) ans = "ARC";
    else ans = "AGC";
    cout << ans << endl;
}

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

bool d[30];


int main(void)
{
	int n;

	for(int i = 0; i < 28; i++){
		cin >> n;
		d[n-1] = true;
	}
	for(int i = 0; i < 30; i++)
		if(!d[i])
			cout << i+1 << endl;

	return 0;
}

Measured memory_bytes: 1160
a, b = map(int, input().split())
aa = []
bb = []

count = 2

while True:
  if a == 1:
    aa.append(a)
    break
  if a%count == 0:
    aa.append(count)
    a = a//count
  else:
      count += 1
    
count = 2

while True:
  if b == 1:
    bb.append(b)
    break
  if b%count == 0:
    bb.append(count)
    b = b//count
  else:
      count += 1
answer = 1
c = set(aa) | set(bb)
for i in c:
  answer *= i ** max(aa.count(i), bb.count(i))
print(answer)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
)

type YX struct {
	y int
	x int
}

func main() {
	var h, w int // 縦と横の長さ格納用
	fmt.Scan(&h, &w)
	var a = make([][]byte, h)                        // マス目格納用
	var d = make([][]int, h)                         // 黒マスからの距離格納用
	var reader = bufio.NewReaderSize(os.Stdin, 1024) // 文字列読み込みリーダ
	var ql = make([]YX, 0)                            // 黒マスのキュー

	for y := 0; y < h; y++ {
		l, _, _ := reader.ReadLine()
		a[y] = make([]byte, w)
		d[y] = make([]int, w)
		copy(a[y], l)
		for x := 0; x < w; x++ {
			if a[y][x] == '.' {
				d[y][x] = -1
			} else {
				ql = append(ql, YX{y, x})
			}
		}
	}

	for len(ql) > 0 {
		var newql = make([]YX, 0)
		for _, q := range ql {
			el := []bool{false, false, false, false}
			if q.y > 0 {
				el[0] = true
			}
			if q.y < h-1 {
				el[2] = true
			}
			if q.x > 0 {
				el[3] = true
			}
			if q.x < w-1 {
				el[1] = true
			}
			for i, e := range el {
				if e {
					switch i {
					case 0:
						y, x := q.y-1, q.x
						if d[y][x] == -1 {
							d[y][x] = d[q.y][q.x] + 1
							newql = append(newql, YX{y, x})
						}
					case 1:
						y, x := q.y, q.x+1
						if d[y][x] == -1 {
							d[y][x] = d[q.y][q.x] + 1
							newql = append(newql, YX{y, x})
						}
					case 2:
						y, x := q.y+1, q.x
						if d[y][x] == -1 {
							d[y][x] = d[q.y][q.x] + 1
							newql = append(newql, YX{y, x})
						}
					case 3:
						y, x := q.y, q.x-1
						if d[y][x] == -1 {
							d[y][x] = d[q.y][q.x] + 1
							newql = append(newql, YX{y, x})
						}
					}
				}
			}
		}
		ql = newql
	}

	// 答えを捜索
	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			ans = max(d[i][j], ans)
		}
	}

	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 73600
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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


  cin >> n;

  if (n < MAX*10) {
    ll x = 0;
    FOR(i, 1, n + 1) {
      if (n / i == n % i) x += i;
    }
    cout << x << endl;
    return 0;
  }


  FOR(i, 1, sqrt(n) + 1) {
    if (i*i == n) continue;
    if (n%i == 0) {
      ans += (n / i) - 1;
    }
  }
  cout << ans << endl;



  return 0;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
a = list(map(int, input().split()))
import numpy as np
link = set()
next = a[0]
link.add(1)
while next not in link:
    link.add(next)
    next = a[next-1]

# print(next)
link2 = set()
next2 = a[0]
link2.add(1)
while next not in link2:
    link2.add(next2)
    next2 = a[next2-1]

link2.remove(next)
ans = 0

rep = len(link) - len(link2)
# print(rep)
if (len(link2) == 0):
    p = k%rep
    # print('e')
    for i in range(p+rep):
        next = a[next-1]
elif(k > len(link2)):
    # print('f')
    p = (k-len(link2))%rep
    # print(p)
    # print(next)
    for i in range(p+rep):
        next = a[next-1]
else:
    # print('d')
    next = a[0]
    for i in range(k-1):
        next = a[next-1]
# print(next)
ans = next
# print(link,link2)
print(ans)


Measured memory_bytes: 57772
def main():
    S = input()
    A = [int(n) for n in S]
    for i in range(1 << 3):
        now = A[0]
        for j in range(3):
            if i >> j & 1:
                now += A[j + 1]
            else:
                now -= A[j + 1]
        if now == 7:
            ans = []
            for j in range(3):
                ans.append(S[j])
                if i >> j & 1:
                    ans.append("+")
                else:
                    ans.append("-")
            ans.append(S[3])
            ans.append("=7")
            print("".join(ans))
            return

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
typedef long long ll;
using namespace std;
int main() {
    string s; cin >> s;
    ll ans = 0;
    int n = s.size();
    repeat (x, 1<<(n-1)) {
        ll acc = 0;
        repeat (i,n) {
            acc *= 10;
            acc += s[i] - '0';
            if ((x&(1<<i)) == 0) {
                ans += acc;
                acc = 0;
            }
        }
        ans += acc;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using ll = long long;

template <typename T>
struct SegmentTree {
	int n;
	vector<T> data;
	T INITIAL_VALUE;

	//使うときは、この2つを適宜変更する
	static T merge(T x, T y);
	void updateNode(int k, T x);

	SegmentTree(int size, T initial_value) {
		n = 1;
		INITIAL_VALUE = initial_value;
		while (n < size) n *= 2;
		data.resize(2 * n - 1, INITIAL_VALUE);
	}

	T getLeaf(int k) {
		return data[k + n - 1];
	}

	void update(int k, T x) {
		k += n - 1; //葉の節点
		updateNode(k, x);
		while (k > 0) {
			k = (k - 1) / 2;
			data[k] = merge(data[k * 2 + 1], data[k * 2 + 2]);
		}
	}

	//区間[a, b)に対するクエリに答える
	//k:節点番号, [l, r):節点に対応する区間
	T query(int a, int b, int k, int l, int r) {
		//[a, b)と[l, r)が交差しない場合
		if (r <= a || b <= l) return INITIAL_VALUE;
		//[a, b)が[l, r)を含む場合、節点の値
		if (a <= l && r <= b) return data[k];
		else {
			//二つの子をマージ
			T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return merge(vl, vr);
		}
	}

	//外から呼ぶ用
	T query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
};

//使うときは以下2つを変更
template <typename T>
T SegmentTree<T>::merge(T x, T y) {
	return max(x, y);
}

template <typename T>
void SegmentTree<T>::updateNode(int k, T x) {
	data[k] = x;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> h(n), idxs(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		idxs[i] = i;
	}
	sort(idxs.begin(), idxs.end(), [&](const int i1, const int i2){return h[i1] < h[i2];});
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	SegmentTree<ll> st(n, 0);
	for (int i : idxs) {
		ll tmp = st.query(0, i) + a[i];
		st.update(i, tmp);
	}
	cout << st.query(0, n) << endl;
	return 0;
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
int main(){
        int n, m; cin >> n >> m;
        vector<int> v(n+1, 0);
        map<int, bool> mp;
        int cnt = 0;
        for (int x = 0; x < m; ++x){
            int p; string s; cin >> p >> s;
            if (s == "AC"){
                mp[p] = true;
            }
            if (mp[p] == false && s == "WA"){
                v[p]++;
            }
        }
        int ans = 0;
        for (int x = 1; x <= n; ++x){
            if (mp[x] == true){
                ans += v[x];
                cnt++;
            }
        }
        cout << cnt << " " << ans << endl;
    return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll L,R,d;
    cin >> L >> R >> d;
    ll ans = 0;
    for (ll i = L; i <= R; i++)
    {
        if(i%d==0)
            ans++;
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	string t = "YAKI";
	int count = 0;
	for(int i=0;i<4;i++){
		if(s[i]==t[i]){
			count++;
		}
	}
	if(count==4){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=0x3f3f3f3f;
int a[20][20],c[20],cur[20];
int n,m,k,ans=INF;
void dfs(int x,int sum)
{
	for(int i=1;i<=m;i++)
		cur[i]+=a[x][i];
	int f=1;
	for(int i=1;i<=m;i++)
		if(cur[i]<k)
			f=0;
	if(f==1)
		ans=min(ans,sum+c[x]);
	for(int i=x+1;i<=n;i++)
	{
		dfs(i,sum+c[x]);
		for(int j=1;j<=m;j++)
			cur[j]-=a[i][j];
	}
}
int main()
{
	cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
	{
        cin>>c[i];
        for(int j=1;j<=m;j++)
            cin>>a[i][j];
    }
    for(int i=1;i<=n;i++)
	{
        mem(cur,0);
        dfs(i,0);
    }
    if(ans!=INF) 
		cout<<ans<<endl;
    else 
		cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 3592
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>



using namespace std;




int main() {
	

	int a,b,c;
	cin>>a>>b>>c;
	if(a==b+c||b==a+c||c==a+b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

	

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int comp(const void* a, const void* b){
  return *(int*)a - *(int*)b;
}

int n, a[100001], b[100001];
int main(void){
  scanf("%d", &n);
  for (int i = 0; i < n; ++i){
    scanf("%d", &a[i]);
    b[a[i]-1] = i;
  }
  for (int i = 0; i < n; ++i){
    printf("%d", b[i]+1);
    if (i == n-1) return 0*printf("\n");
    printf(" ");
  }
  
  return 0*printf("\n");
}


Measured memory_bytes: 1536
def main():
    N = int(input())
    s = []
    ten = []
    for _ in range(N):
        tmp = int(input())
        if tmp%10 == 0:
            ten.append(tmp)
        else:
            s.append(tmp)
    if len(s) == 0:
        print(0)
        return
    s.sort(reverse=True)
    if sum(s)%10 == 0:
        s.pop()
    ans = sum(s)+sum(ten)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
  
	int x[5];
    cin >> x[0] >> x[1] >> x[2]>> x[3] >> x[4];
  	for (int i = 0; i<5; i++){
      if (x[i] == 0){
        cout << i+1;
      }
    }
      
      
      
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template

//main
signed main(){
  int a,b,c;cin>>a>>b>>c;
  cout<<min({a+b,b+c,c+a})<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
        int x,a,b;
        int as,bs;

        scanf("%d%d%d",&x,&a,&b);

        if(x>a)
                as = x-a;
        else
                as = a-x;

        if(x>b)
                bs = x-b;
        else
                bs = b-x;

        if(as > bs)
                printf("B\n");
        else
                printf("A\n");

        return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
struct Bipartite_Matching
{
  vector< vector< int > > graph;
  vector< int > match, alive, used;
  int timestamp;
 
  Bipartite_Matching(int n)
  {
    timestamp = 0;
    graph.resize(n);
    alive.assign(n, 1);
    used.assign(n, 0);
    match.assign(n, -1);
  }
 
  void add_edge(int u, int v)
  {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
 
  bool dfs(int v)
  {
    used[v] = timestamp;
    for(int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i], w = match[u];
      if(alive[u] == 0) continue;
      if(w == -1 || (used[w] != timestamp && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return (true);
      }
    }
    return (false);
  }
 
  int bipartite_matching()
  {
    int ret = 0;
    for(int i = 0; i < graph.size(); i++) {
      if(alive[i] == 0) continue;
      if(match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
      }
    }
    return (ret);
  } 
};
int main(){
    int n;
    cin>>n;
    Bipartite_Matching t(n*2);
    vp a(n);
    REP(i,n){
        cin>>a[i].fi>>a[i].se;
    }
    vp b(n);
    REP(i,n){
        cin>>b[i].fi>>b[i].se;
    }
    REP(i,n){
        REP(j,n){
            if(b[j].fi>a[i].fi&&b[j].se>a[i].se){
                t.add_edge(j+n,i);
            }
        }
    }
    cout<<t.bipartite_matching()<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
typedef long long ll;

//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく

//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

using namespace std;

int main(void){
 
  ll n;
  string c;
  cin >> n;
  cin >> c;
  ll r=0 ,w=0; //個数
  REP(i,n){
    if( c[i] == 'R' ){
      r++;
    } else {
      w++;
    }
  }
  ll ans = 0;
  REP(i,r){
    if( c[i] == 'W' ) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3752
fun main(args:Array<String>):Unit {
    while (true) {
        val n = readLine()!!.trim().toInt()
        if (n == 0) return
        var crues = List(n){
            Pair(it + 1, readLine()!!.trim().split(' ').drop(1).map(String::toInt))
        }
        readLine()!!.trim().split(' ').drop(1).map(String::toInt).forEach{c ->
            crues = crues.filter{
                it.second.contains(c)
            }
        }
        println(
                if (crues.size == 1) crues.first().first
                else -1
        )
    }
}


Measured memory_bytes: 59824
#include<iostream>
#include<algorithm>
using namespace std;
int n,k,h[1<<17],dp[1<<17];
main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
		dp[i]=!!i*2e9;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<=k;j++)dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
a, b ,c = map(int, raw_input().split())
k=2 ** int(raw_input())
if(a<b):
	if (b<c):
		x=a+b+c*k
	else:
		x=a+c+b*k
else:
	if(a<c):
		x=a+b+c*k
	else:
		x=b+c+a*k
print(x)


Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 1e6;
ll a[max_n];
int n;
ll reft[max_n], right[max_n];
ll gcd(ll s1, ll s2){
  if(s2 == 0) return s1;
  return gcd(s2, s1%s2);
}
void solve(){
  vector<ll> left(n+1, 0), right(n+1, 0);
  for(int i=0 ; i<n ; i++)  left[i+1] = gcd(left[i], a[i]);
  for(int i=n-1 ; i>=0 ; i--) right[i] = gcd(right[i+1], a[i]);
  ll ma = 1;
  for(int i=0 ; i<n ; i++){
    ma = max(ma, gcd(left[i], right[i+1]));
  }
  cout << ma << endl;
}
int main(){
  cin >> n;
  for(int i=0 ; i<n ; i++){
    cin >> a[i];
  }
  sort(a, a+n);
  solve();
  return 0;
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll a[n+1],b[n+1],c[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];
    ll dp[n+1][3];
    dp[0][0]=dp[0][1]=dp[0][2]=0;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);

    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
    return 0;
}


Measured memory_bytes: 4972
#include <iostream>
#include<string>
#include<cmath>
#include<vector>
using std::cin;
using std::cout;
using std::vector;
using std::string;
void solve(string &a,string &b){
	int no=a.length()+b.length();
	for(int i=1;i<=no;i++){
		if(i%2==0)
			cout<<b[i/2-1];
		else
		cout<<a[i/2];
	}
		
}
int main(){
	string a,b;
	cin>>a>>b;
	solve(a,b);
}

Measured memory_bytes: 256
# [2,2,4,5] = [3,3,3]
# 重複を排除したときの要素の数がその段数となる

def getElementNum(N,a):    
    """ 
    >>> getElementNum(4,[2,4,6,8])
    4
    """
    b = list(set(a))
    return len(b)

def main():
    N = int(input())
    a = []
    for i in range(N):
        a.append( int( input() ) )
    result = getElementNum(N,a)
    print(result)

if __name__ == '__main__':
    main()

# if __name__ == '__main__':
#    import doctest
#     doctest.testmod()


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int m = 200000, N, P, t, c;
  vector<bool> Prime(m, true);
  Prime[0] = false;
  Prime[1] = false;
  vector<int> V, M;
  for (int i = 2; i*i < m; ++i) for (int j = i; i*j < m; ++j) Prime[i*j] = false;
  while (cin >> N >> P, N != -1) {
    t = N+1;
    c = P;
    while (c > 0) {
      if (Prime[t]) {
	V.push_back(t);
	--c;
      }
      ++t;
    }
    for (int i = 0; i < P; ++i) {
      for (int j = i; j < P; ++j) {
	M.push_back(V[i]+V[j]);
      }
    }
    sort(M.begin(), M.end());
    cout << M[P-1] << endl;
    V.erase(V.begin(), V.end());
    M.erase(M.begin(), M.end());
  }
  return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

ll N, M;
vector<vector<edge>> g;

vector<bool> see;

vector<ll> pos;

void dfs(ll v) {
	see[v] = 1;

	for (edge e : g[v]) {
		if (see[e.to] == 1) { continue; }
		pos[e.to] = pos[v] + e.d;
		dfs(e.to);
	}

	return;
}




int main() {

	ll X, A, B;
	cin >> X >> A >> B;
	cout << (X - A) % B;

	system("PAUSE");

	

}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
int main(){
  int data[222222];
  int N;
  int x;
  cin >> N >> x;
  if(x == 2 * N - 1 || x == 1){cout << "No" << endl;return 0;}
  cout << "Yes" << endl;
  int g = 1;
  if(x == 2)g = -1;
  data[N - 1] = x;
  data[N - 2] = x - g;
  data[N] = x + g;
  data[N + 1] = x - g * 2;
  int cnt = 1;
  for(int i = 0;i < 2 * N - 1;i++){
    while(cnt >= x - 2 * g && cnt <= x + g || cnt >= x * g && cnt <= x - 2 * g)cnt++;
    if(i < N - 2 || i > N + 1){
      data[i] = cnt;
      cnt++;
    }
  }
  for(int i = 0;i < 2 * N - 1;i++){
    cout << data[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repM(i, n) for (int i = n; i > 0; i--)

int main() {
    int N;
    cin >> N;
    repX(i,9+1,1){
        if(N%i!=0)continue;
        if(1<=N/i&&N/i<=9){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

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

#define MAX(X,Y) ((X)>(Y)?(X):(Y))

int main(void){
  int n,hst,ans,h;
  
  hst = ans = 0;
  cin >> n;
  for (int i=0; i<n; i++){
    cin >> h;
    if (h>=hst) ans++;
    hst = MAX(hst,h);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

const int mod = 1000000007;

int N,A[16][16]; long long S[1<<16],D[1<<16];

int main()
{
	scanf ("%d",&N);
	for (int i=0;i<N;i++) for (int j=0;j<N;j++) scanf ("%d",&A[i][j]);

	for (int i=1;i<(1<<N);i++){
		int x = i & (-i);
		for (int j=0;j<N;j++) if (x == (1 << j)){
			S[i] = S[i-x];
			for (int k=j+1;k<N;k++) if (i & (1 << k)){
				S[i] += A[j][k];
			}
		}
	}

	for (int i=1;i<(1<<N);i++){
		D[i] = -1e18;
		for (int j=i;j;j=(j-1)&i){
			if (D[i] < D[i-j] + S[j])
				D[i] = D[i-j] + S[j];
		}
	}

	printf ("%lld\n",D[(1<<N)-1]);

	return 0;
}

Measured memory_bytes: 1280
N, K = gets.split.map &:to_i
WD = $<.map{|s|s.split.map &:to_i}
w, d = WD[0]
last = w + d * (K-1)

p (1..last).bsearch{|n|
  sum = 0
  WD.any?{|w, d|
    sum += n < w ? 0 : 1 + (n - w) / d
    sum >= K
  }
}


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

using namespace std;

int main() {
	int n; cin >> n;
  	double sum = 0;
  	for(int i = 0; i < n; i += 1) {
      double a; cin >> a;
      sum += (1/a);
    }
  cout << 1/sum << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize("trapv")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#include <x86intrin.h>
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 2e5 + 55, mod = 1e9 + 7 , i2 = (mod+1)/2;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, a[maxn], b[maxn], ax[2*maxn], bx[maxn], bk[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
	for(int i = 0; i < 2*(n-1); i++)
		ax[i] = a[i%n]^a[(i+1)%n];
	for(int i = 0; i < n-1; i++)
		bx[i] = b[i] ^ b[i+1];
	vi ans;
	int i = 0, j = -1;
	bk[0] = -1;
	while(i < n-1) {
		while(j != -1 && bx[i] != bx[j]) j = bk[j];
		i++, j++;
		bk[i] = j;
	}
	i = j = 0;
	while(i < 2*(n-1)) {
		while(j != -1 && ax[i] != bx[j]) j = bk[j];
		i++, j++;
		if(j==n-1) {
			ans.pb(i-(n-1));
			j = bk[j];
		}
	}
	for(auto i : ans) cout << i << ' ' << (b[0]^a[i]) << '\n';
}



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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int x, n;
bool vis[103];
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> x >> n;
	while(n--) {
		int num; cin >> num;
		vis[num] = 1;
	}
	int ans = 0, mn = x;
	for(int i=1; i<=101; i++) {
		if (vis[i]) continue;
		if (abs(x-i) < mn) {
			mn = abs(x-i);
			ans = i;
		}
	}
	cout << ans << endl;
	
	return 0;
}


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

int main() {
    string c1, c2;
    cin >> c1 >> c2;
    if (c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

int main(){
  	int n,cnt;
  	cnt = 0;
  	cin >> n;
  
  	for(int i = 0;i < 4;i++){
      if(n >= 3*5*(2*i+7)){
        cnt++;
      }
    }
  
  	if(n >= 3*7*9){
      cnt++;
    }
  
  	cout << cnt << endl;
 	return 0; 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		String s = scan.next();
		char[] c1=s.toCharArray();
		s=scan.next();
		char[] c2=s.toCharArray();
		scan.close();
		System.out.println((c1[0]==c2[2]&& c1[1]==c2[1]&&c2[0]==c1[2])? "YES":"NO");

	}

}

Measured memory_bytes: 23252
#include <stdio.h>
 
int main() {
	int i;
 	int n, a[1000];
 	scanf("%d", &n);
  	for(i = 1; i <= n; ++i) {
    	scanf("%d", &a[i]);
  	}
  	for(int i = n; i > 0; --i) {
    	printf("%d", a[i]);
    	if(i != 1) {
      		printf(" ");
    	} else {
      		printf("\n");
    	}
  	}
 
  	return 0;
}


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

using namespace std;

using ll = long long;

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

    ll n, c;

    cin >> n >> c;
    vector<ll> x(n + 2), v(n + 2);
    for (int i = 1; i <= n; ++i) cin >> x[i] >> v[i];

    ll max_c = 0;

    // 時計回り
    vector<ll> plus(n + 2, -c);
    for (ll i = 1, sum = 0; i <= n; ++i) {
        sum += v[i];
        plus[i] = max(plus[i - 1], sum - x[i]);
        max_c = max(max_c, plus[i]);
    }

    // 半時計回り
    vector<ll> neg(n + 2, -c);
    for (ll i = n, sum = 0; 1 <= i; --i) {
        sum += v[i];
        neg[i] = max(neg[i + 1], sum - (c - x[i]));
        max_c = max(max_c, neg[i]);
    }

    // 時計回り -> 半時計回り
    for (ll i = 1, sum = 0; i < n; ++i) {
        sum += v[i];
        max_c = max(max_c, (sum - 2 * x[i]) + neg[i + 1]);
    }

    // 半時計回り -> 時計回り
    for (ll i = n, sum = 0; 1 < i; --i) {
        sum += v[i];
        max_c = max(max_c, (sum - 2 * (c - x[i])) + plus[i - 1]);
    }

    cout << max_c << endl;

    return 0;
}


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

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

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

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int ans = 0;

    int N, T; cin >> N >> T;
    //T-1分後に食べるものについて全探索できるといいな
    int tm[N+1] = {}, val[N+1] = {};
    rep(i, N) cin >> tm[i+1] >> val[i+1];
    int dp1[N+1][T], dp2[N+1][T];
    rep(i, N+1){
        rep(j, T){
            dp1[i][j] = dp2[i][j] = 0;
        }
    }
    for(int i = 1; i <= N; i++){
        //iを食べるかどうか
        for(int j = 0; j < T; j++){
            if(j-tm[i] >= 0) dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-tm[i]] + val[i]);
            else dp1[i][j] = dp1[i-1][j];
        }
    }
    for(int j = 0; j < T; j++){
        if(j < tm[N]) dp2[N][j] = 0;
        else dp2[N][j] = val[N];
    }
    for(int i = N-1; i >= 1; i--){
        for(int j = 0; j < T; j++){
            if(j-tm[i] >= 0) dp2[i][j] = max(dp2[i+1][j], dp2[i+1][j-tm[i]] + val[i]);
            else dp2[i][j] = dp2[i+1][j];
        }
    }


    for(int i = 1; i <= N; i++){
        //iをT-1分後に注文する
        int res = 0;
        if(i == N){
            ans = max(ans, dp1[N-1][T-1] + val[i]);
        }
        else{
            for(int j = 0; j < T; j++){
                res = max(res, dp1[i-1][j] + dp2[i+1][(T-1)-j]);
            }
            ans = max(ans, res+val[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
const int MOD = 1e9+7;
const int MOOD = 998244353;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int use[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[10001];

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	for (int i = 0; i < m; i++) cin >> a[i];

	sort(a.begin(), a.end(), greater<int>());

	for (int i = 0; i <= 10000; i++) dp[i] = -1;
	dp[0] = 0;

	for (int i = 2; i <= n; i++){
		for (int j = 0; j < m; j++){
			if (i - use[a[j]] >= 0 && dp[i-use[a[j]]] != -1){
				dp[i] = max(dp[i], dp[i-use[a[j]]] + 1);
			}
		}
	}
	int temp = n;
	string ans;
	while (temp != 0){
		for (int i = 0; i < m; i++){
			if (dp[temp-use[a[i]]] + 1 == dp[temp] && temp-use[a[i]] >= 0){
				temp -= use[a[i]];
				ans += to_string(a[i]);
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3704
n, m = map(int, input(). split())
lists = [[int(i) for i in input().split()] for j in range(m)]
lists.sort()
a = b = count = 0
for x in lists:
  if a < x[0]:
    if b <= x[0]:
      count += 1
      a = x[0]
      b = x[1]
    else:
      b = min(b, x[1])
print(count)

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

using int64 = long long;
using uint64 = unsigned long long;

using namespace std;

template <int64 M>
struct ModInt {
    int64 n;
    constexpr ModInt(const int64 n = 0) noexcept : n(n % M) {}
    constexpr ModInt operator+(const ModInt rhs) const noexcept {
        return ModInt(*this) += rhs;
    }
    constexpr ModInt operator-(const ModInt rhs) const noexcept {
        return ModInt(*this) -= rhs;
    }
    constexpr ModInt operator*(const ModInt rhs) const noexcept {
        return ModInt(*this) *= rhs;
    }
    constexpr ModInt operator/(const ModInt rhs) const noexcept {
        return ModInt(*this) /= rhs;
    }
    constexpr ModInt& operator+=(const ModInt rhs) noexcept {
        n += rhs.n;
        while (n >= M) {
            n -= M;
        }
        return *this;
    }
    constexpr ModInt& operator-=(const ModInt rhs) noexcept {
        n -= rhs.n;
        while (n < 0) {
            n += M;
        }
        return *this;
    }
    constexpr ModInt& operator*=(const ModInt rhs) noexcept {
        (n *= rhs.n) %= M;
        return *this;
    }
    constexpr ModInt& operator/=(ModInt rhs) noexcept {
        *this *= pow(rhs, M - 2);
        return *this;
    }
    constexpr ModInt inv() const noexcept {
        return pow(*this, M - 2);
    }

    friend ostream& operator<<(ostream& os, const ModInt<M>& m) {
        os << m.n;
        return os;
    }

    static ModInt pow(ModInt a, int64 n) {
        ModInt res = 1;
        while (n) {
            if (n % 2) {
                res *= a;
            }
            a *= a;
            n /= 2;
        }
        return res;
    }
};

constexpr int MAX_N = 3000;
constexpr int MAX_S = 3000;
constexpr int64 MOD = 998244353;

ModInt<MOD> dp[MAX_N + 1][MAX_S + 1];

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

    int n, s;
    cin >> n >> s;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= s; j++) {
            dp[i + 1][j] += dp[i][j] * 2;
            if (j + a[i] <= s) {
                dp[i + 1][j + a[i]] += dp[i][j];
            }
        }
    }
    cout << dp[n][s] << endl;

    return 0;
}



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

int main()
{
	int n,y,a,b,c;
	cin>>n>>y;
	for(a=0;a<=y/10000;a++)
	for(b=0;b<=y/5000;b++)
	{
		c=n-a-b;
		if(a*10000+b*5000+c*1000==y&&c>=0)
		{
			cout<<a<<" "<<b<<" "<<c;
			return 0;
		}
	}
	cout<<"-1 -1 -1";
		return 0;
 } 

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
use std::collections::BinaryHeap;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<u64>();

    let (_, m) = (line[0], line[1]);

    let a: Vec<u64> = read_as_vec();

    let mut heap = BinaryHeap::new();

    for elem in a{
        heap.push(elem);
    }

    for _ in 0..m{
        let expensive = heap.pop().unwrap();

        heap.push(expensive/2);
    }

    println!("{}", heap.into_iter().sum::<u64>());
}


Measured memory_bytes: 8444
import java.util.Scanner;
 
public class Main{
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int[][] bi=new int[n][m];
        int[] b=new int[m];
        int[] sum=new int[n];
        
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                bi[i][j]=sc.nextInt();
            }
        }
        for(int i=0;i<m;i++){
            b[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                sum[i]+=(bi[i][j]*b[j]);
            }
        }
        for(int i=0;i<n;i++){
        	System.out.println(sum[i]);
        }
        
        sc.close();
 
    }
 
}


Measured memory_bytes: 40376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
const ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n){
    cin>>a[i];
  }
  int cur=a[0];
  ll ans=0;
  rep(i,1,n){
    if(a[i]<cur){
      ans+=cur-a[i];
    }
    else{
      cur=a[i];
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;
#define ll long long int
char ara[1005][1005];
ll n,m,dp[1005][1005],mod=1e9+7;

int main()
{
    ll i,j;
    cin>>n>>m;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=m; j++)
        {
            cin>>ara[i][j];
        }
    }

    for(i=1; i<=m; i++)
    {
        if(i==1) dp[1][i]=1;
        else if(ara[1][i]=='#') dp[1][i]=0;
        else dp[1][i]=dp[1][i-1];

    }
    for(i=1; i<=n; i++)
    {
        if(i==1) dp[i][1]=1;
        else if(ara[i][1]=='#') dp[i][1]=0;
        else dp[i][1]=dp[i-1][1];
    }
    for(i=2; i<=n; i++)
    {
        for(j=2; j<=m; j++)
        {
            if(ara[i][j]=='#')
            {
                dp[i][j]=0;
                continue;
            }
            dp[i][j]=dp[i][j-1]+dp[i-1][j];
            dp[i][j]%=mod;
        }
    }
    cout<<dp[n][m]<<endl;
    //for(i=1; i<=n)
    return 0;


}


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

using namespace std;

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

    int n, ans = 1;
    cin >> n;
    int arr[n], pre[n], suff[n];

    for (int i = 0; i < n; i++)
        cin >> arr[i];
    pre[0] = arr[0];
    suff[n - 1] = arr[n - 1];

    for (int i = 1; i < n; i++)
        pre[i] = __gcd(arr[i], pre[i - 1]);

    for (int i = n - 2; i >= 0; i--)
        suff[i] = __gcd(arr[i], suff[i + 1]);

    ans = max(suff[1], pre[n - 2]);

    for (int i = 1; i < n - 1; i++)
        ans = max(ans, __gcd(pre[i - 1], suff[i + 1]));

    cout << ans << '\n';

    return 0;
}

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

#define ll long long
#define endl "\n"
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define f first
#define s second
#define vecll vector<ll>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<ll,ll>>
#define mapllll map<ll,ll>
#define mapstrll map<string,ll>
#define mapllvecll map<ll,vecll>
#define setll set<ll>
#define fio ios_base::sync_with_stdio (false); cin.tie (NULL); cout.tie(NULL);

using namespace std;

ll const N=1e5+5;
ll const inf=1e18+5;
ll const MOD=1e9+7;

ll t,n,m,x,y,z,w,k;

int main()
{
    fio

    cin>>x>>y;

    z = x*y;
    w = __gcd(x,y);
    z /= w;
    cout<<z;
    return 0;
}



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

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

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

void solve_132A(){
    char s[4];
    cin >> s;

    sort(s, s+4);

    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main(void){
    solve_132A();
    
    return 0;
}

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

int main()
{
	long long k, a, b, m;

	cin >> k >> a >> b;

	if (k > a && b - a > 2) {
		long long t = (k - a + 1) / 2;
		m = a + (b - a) * t + (k - a + 1 - t * 2);
	}
	else
		m = k + 1;

	cout << m << endl;

	return 0;
}

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

constexpr int64_t MOD = 1000000007;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 210000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long ncr(int n, int k){
    int64_t numerator = 1;
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    
    for(int64_t i=n;i>=(n-k+1);i--) {
        numerator = (numerator * i) % MOD;
    }
    return numerator * finv[k] % MOD;
}

int main(void) {
    int64_t n,a,b;
    int64_t ans;
    cin >> n >> a >> b;

    COMinit();
//cout << modpow(2,n,MOD) << endl;
//cout << ncr(n,a) << endl;
//cout << ncr(n,b) << endl;
    ans = (modpow(2,n,MOD)-1- ncr(n,a) - ncr(n,b));
    ans %= MOD;

    if(ans < 0) ans = MOD + ans;
    ans %= MOD;

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int INF = int(1e9);
const int MX = 222222;

struct edge
{
	int to,cap,rev;
	edge(int to=0,int cap=0,int rev=0):to(to),cap(cap),rev(rev){}
};
vector <edge> vec[MX];
int level[MX];
int iter[MX];

void addedge(int s,int t,int c) //adds an edge of cap c to the flow graph
{
	int S=vec[s].size(),T=vec[t].size();
	vec[s].push_back(edge(t,c,T));
	vec[t].push_back(edge(s,0,S));
}
void bfs(int s)
{
	memset(level,-1,sizeof(level));
	queue <int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty())
	{
		int v = que.front();que.pop();
		for(int i=0;i<vec[v].size();i++)
		{
			edge&e=vec[v][i];
			if (e.cap>0&&level[e.to]<0)
			{
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}
ll flow_dfs(int v,int t,ll f)
{
	if (v==t) return f;
	for(int &i=iter[v];i<vec[v].size();i++)
	{
		edge &e=vec[v][i];
		if (e.cap>0&&level[v]<level[e.to])
		{
			ll d=flow_dfs(e.to,t,min(f,ll(e.cap)));
			if (d>0)
			{
				e.cap-=d;
				vec[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
ll maxflow(int s,int t) //finds max flow using dinic from s to t
{
	ll flow = 0;
	while(1)
	{
		bfs(s);
		if (level[t]<0) return flow;
		memset(iter,0,sizeof(iter));
		while (1)
		{
			ll f=flow_dfs(s,t,INF);
			if(f==0) break;
			flow += f;
		}
	}
}

vi A[222222];
vi contained[222222];
bool visited[222222];
ii chosen[222222];
int match[222222];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	int s = MX-1; int e = MX-2;
	for(int i=0;i<n-1;i++)
	{
		chosen[i]=mp(-1,-1);
		int k; cin>>k;
		addedge(s,i,1);
		for(int j=0;j<k;j++)
		{
			int u; cin>>u; u--;
			addedge(i,u+n,1);
			A[i].pb(u); contained[u].pb(i);
		}
	}
	for(int i=0;i<n;i++) addedge(i+n,e,1);
	int maxmatch = maxflow(s,e);
	if(maxmatch!=n-1)
	{
		cout<<-1<<'\n'; return 0;
	}
	set<int> S;
	for(int i=0;i<n;i++) S.insert(i);
	for(int i=0;i<n-1;i++)
	{
		for(auto X:vec[i])
		{
			if(X.to-n>=0&&X.to-n<n&&X.cap==0)
			{
				match[i]=X.to-n; S.erase(match[i]); break;
			}
		}
	}
	queue<int> q;
	q.push((*S.begin()));
	while(!q.empty())
	{
		int u = q.front(); q.pop();
		for(int v:contained[u])
		{
			if(visited[v]) continue;
			//cerr<<"CHOOSE "<<v<<" : "<<u<<' '<<match[v]<<'\n';
			chosen[v] = mp(u, match[v]);
			visited[v]=1;
			q.push(match[v]);
		}
	}
	for(int i=0;i<n-1;i++)
	{
		if(chosen[i].fi<0){cout<<-1<<'\n'; return 0;}
	}
	for(int i=0;i<n-1;i++)
	{
		cout<<chosen[i].fi+1<<' '<<chosen[i].se+1<<'\n';
	}
}


Measured memory_bytes: 49588