akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int size=100000;
long N,M;//N:vertex M:edge
int relate[size];int par[size];
int root(int v){
	if(relate[v]==v){
		return v;
	}else{
		return root(relate[v]);
	}
}
void unite(int x,int y){//union by size
	x=root(x);y=root(y);
	if(x==y){
		return;
	}else if(par[x]<par[y]){
		swap(x,y);
	}relate[y]=x;
	par[x]+=par[y];
	return;
}
int main(){
	cin>>N>>M;
	int A[M],B[M];long ans[M];
    long result=N*(N-1)/2;
	long a,b;
	for(int i=0;i<M;i++){
		cin>>A[i]>>B[i];
		A[i]--;B[i]--;
	}for(int i=0;i<N;i++){//initialize
		relate[i]=i;
        par[i]=1;
	}for(int i=M-1;i>=0;i--){
		ans[i]=result;
        a=root(A[i]);b=root(B[i]);
        if(a!=b){
            result-=par[a]*par[b];
            unite(a,b);
		}
	}for(int j=0;j<M;j++){
		cout<<ans[j]<<endl;
	}
}

Measured memory_bytes: 3712
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

typedef vector< vector<int> > Graph;

Graph G;
int N, M, Q;
int color[100010];
int rec[100010];
void dfs(int point, int col, int cur, int par = -1) {
    if(rec[point] >= cur) return;
    if(color[point] == 0) color[point] = col;
    rec[point] = cur;
    if(cur == 0) return;
    rep(i,0,G[point].size()) {
        int to = G[point][i];
        if(to == par) continue;
        dfs(to, col, cur-1, point);
    }
}

struct query {
    int v, d, c;
};

signed main() {
    cin >> N >> M;
    G.resize(N);
    rep(i,0,M) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    memset(color, 0, sizeof(color));
    memset(rec, -1, sizeof(rec));

    cin >> Q;
    vector<query> qs(Q);
    rep(i,0,Q) {
        cin >> qs[i].v >> qs[i].d >> qs[i].c;
        qs[i].v--;
    }
    reverse(qs.begin(), qs.end());

    rep(i,0,Q) {
        dfs(qs[i].v, qs[i].c, qs[i].d);
    }

    rep(i,0,N) {
        cout << color[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10740
import copy


def get_completed(s):
    ans = copy.deepcopy(s)

    not_close = 0
    not_open = 0

    for c in s:
        if c == '(':
            not_close += 1

        if c == ')':
            if not_close > 0:
                not_close -= 1
            else:
                not_open += 1

    for i in range(not_open):
        ans = '(' + ans

    for i in range(not_close):
        ans = ans + ')'

    return ans


if __name__ == '__main__':
    N = input()
    S = input()

    print(get_completed(S))


Measured memory_bytes: 3444
//package solution;

import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
import java.awt.Point;

public final class Main {
    BufferedReader br;
    StringTokenizer stk;

    public static void main(String[] args) throws Exception {
        //new Thread(null, new Runnable() {
            //@Override
            //public void run() {
                //try {
                    new Main().run();
                //} catch(Exception ex) {ex.printStackTrace();}
            //}
        //}, "solution", 1<<26).start();
    }
    
    {
        stk = null;
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    
    //long mod = 1000000007L;
    void run() throws Exception {
        int x = ni(), y = ni(), a = ni(), b = ni(), c = ni();
        long[] red = new long[a], green = new long[b], colorless = new long[c];
        for(int i=0; i<a; i++) red[i] = nl();
        for(int i=0; i<b; i++) green[i] = nl();
        for(int i=0; i<c; i++) colorless[i] = nl();
        
        Arrays.sort(red); Arrays.sort(green); Arrays.sort(colorless);
        
        List<Long> list = new ArrayList<>();
        for(int i=a-x; i<a; i++) {
            list.add(red[i]);
        }
        for(int i=b-y; i<b; i++) {
            list.add(green[i]);
        }
        for(int i=0; i<c; i++) list.add(colorless[i]);
        Collections.sort(list, Collections.reverseOrder());
        
        long total = 0;
        for(int i=0; i<x+y; i++) total += list.get(i);
        pl(total);
    }
    
    //Reader & Writer
    String nextToken() throws Exception {
        if (stk == null || !stk.hasMoreTokens()) {
            stk = new StringTokenizer(br.readLine(), " ");
        }
        return stk.nextToken();
    }

    String nt() throws Exception {
        return nextToken();
    }

    String ns() throws Exception {
        return br.readLine();
    }

    int ni() throws Exception {
        return Integer.parseInt(nextToken());
    }

    long nl() throws Exception {
        return Long.parseLong(nextToken());
    }

    double nd() throws Exception {
        return Double.parseDouble(nextToken());
    }

    void p(Object o) {
        System.out.print(o);
    }

    void pl(Object o) {
        System.out.println(o);
    }
}

Measured memory_bytes: 63252
#include <iostream>
#include <string>

void input_sentence(std::string& input);
std::string convert(char cstr1);
void output(std::string sentence);

int main()
{
	std::string sentence;
	input_sentence(sentence);
	
	int length = sentence.length();
	for (int i = 0; i < length; ++i)
	{
		sentence.replace(i, 1, convert(sentence[i]));
	}

	output(sentence);

	return 0;
}

void input_sentence(std::string& input)
{
	std::getline(std::cin, input);
}

std::string convert(char cstr1)
{
	std::string str;
	if (cstr1 >= 0x41 && cstr1 <= 0x5a)
	{
		cstr1 += 0x20;
	}
	else if (cstr1 >= 0x61 && cstr1 <= 0x7a)
	{
		cstr1 -= 0x20;
	}
	str = cstr1;
	return str;
}

void output(std::string sentence)
{
	std::cout << sentence << std::endl;
}




Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

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

    int ans = 0;
    for (int i = 1; i * i <= n; ++i) {
        chmax(ans, i * i);
    }

    cout << ans << endl;

    return 0;
}

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 998244353;

unordered_map <string,int> dp;

int solve(const string &s) {
    if (s.empty()) {
        return 1;
    }
    
    if (s.size() == 1) {
        return 1 + (s[0] - '0');
    }

    if (!dp.count(s)) {
        int n = s.size();
    
        string rest = s.substr(1, n-1);
        int ans = solve(rest);
        
        if (s[0] == '1') {
            ans = (ans * 2) % MOD;
        }
        
        FOR(len,1,n-1) {
            string part = s.substr(0, len);
        
            for (int full = 2 * len; full <= n; full += len) {
                FOR(i,full-len,full-1) {
                    if (s[i] == '0') {
                        part[i-full+len] = '0';
                    }
                }
                
                int right = solve(s.substr(full, n-full));
                ans = (ans + (ll) solve(part) * right) % MOD;
            }
        }
        
        dp[s] = ans;
    }
    
    return dp[s];
}

/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    string s;
    cin >> s;
    
    cout << solve(s);
    
    return 0;
}

/*************************************************************************/


Measured memory_bytes: 5388
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	char op;
	
	while (1)
	{
		scanf("%d %c %d", &a, &op, &b);
		
		if (op == '?')
		{
			break;
		}
		
		switch (op)
		{
			case '+':
				printf("%d\n", a + b);
				break;
			
			case '-':
				printf("%d\n", a - b);
				break;
			
			case '*':
				printf("%d\n", a * b);
				break;
			
			case '/':
				printf("%d\n", a / b);
				break;
				
			default:
				break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;
int main() {
	long long int n,total_h,max_h,total_d=0,ans=0;
	scanf("%lld %lld",&n,&total_h);
	max_h=total_h;
	deque<pair<long long int,long long int> > Q;
	for(int i=0;i<n-1;i++) {
		long long int d,h;
		scanf("%lld %lld",&d,&h);
		while(!Q.empty()&&Q.back().first<=h)
			Q.pop_back();
		Q.push_back(make_pair(h,total_d));
		total_d+=d;
		while(total_h<=total_d) {
			long long int tmp_h=total_h;
			while(!Q.empty()&&tmp_h+Q.front().first-Q.front().second>max_h) {
				total_h=Q.front().second+max_h;
				Q.pop_front();
			}
			if(!Q.empty()) {
				total_h=max(total_h,tmp_h+Q.front().first);
				long long int tmp=max(0LL,min((total_d-total_h)/Q.front().first,(Q.front().second+max_h-total_h)/Q.front().first));
				ans+=tmp;
				total_h+=tmp*Q.front().first;
			}
			ans++;
		}
	}
	printf("%lld\n",ans);
}

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

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() {return val;}
    bool operator!=(Iterator &itr) {return val < itr.val;}
    void operator++() {++val;}
  };
  Iterator i, n;
public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator &begin() {return i;}
  Iterator &end() {return n;}
};

template<class T> T at(vector<T> v, int i) {return v[(i % (int)v.size() + v.size()) % v.size()];}

template<class A, class B> B convert(A a) {
  stringstream ss;
  ss << a;
  B b;
  ss >> b;
  return b;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &i : a) cin >> i;
  sort(a.begin(), a.end());
  int r1 = 1e9, r2 = 1e9, r3 = 1e9;
  for (int i : range(min(n, 10))) for (int j : range(min(n, 10))) if (i != j) {
    int r = convert<string, int>(convert<int, string>(a[i]) + convert<int, string>(a[j]));
    if (r <= r1) {
      r3 = r2;
      r2 = r1;
      r1 = r;
    } else if (r <= r2) {
      r3 = r2;
      r2 = r;
    } else if (r <= r3) {
      r3 = r;
    }
  }
  cout << r3 << endl;
}

Measured memory_bytes: 1264
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a//b, b, a%b
        x0, x1 = x1, x0 -q*x1
        y0, y1 = y1, y0 -q*y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x %m

def main():
    X, Y = map(int, input().split())

    divider = 10**9 + 7

    m = 2 * X - Y
    n = 2 * Y - X

    if m%3 != 0 or n%3 != 0 or n < 0 or m < 0:
        print(0)
        return
    m //= 3
    n //= 3

    if m < n:
        m, n = n, m

    ans = 1
    for i in range(m+n, m, -1):
        ans *= i
        ans %= divider

    for i in range(n, 0, -1):
        ans *= modinv(i, divider)
        ans %= divider

    print(ans)

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc145","d",main)


Measured memory_bytes: 3064
#include<iostream>
#include<string>

using namespace std;

int main(void){
    string S;
    cin >> S;


    if(S[2]==S[3]&&S[4]==S[5]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


    return 0;
}

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

bool is_h[1000001];
ll cnt[1000001];
int main() {
	cnt[1] = is_h[1] = 1;
	for (ll i = 2; i <= 1000000; i++) {
		cnt[i] = cnt[i - 1];
		if ((!(i % 2) && is_h[i / 2]) || (!(i % 3) && is_h[i / 3]) || (!(i % 5) && is_h[i / 5])) {
			cnt[i]++;
			is_h[i] = 1;
		}
	}
	ll m, n;
	while (scanf("%lld", &m), m) {
		scanf("%lld", &n);
		printf("%lld\n", cnt[n] - cnt[m - 1]);
	}
}

Measured memory_bytes: 11688
main :: IO ()
main = do
  input <- (map read . words) <$> getLine
  putStrLn $ solve (input!!0) (input!!1) (input!!2)


solve x a b
  | (-a) + b > x = "dangerous"
  | otherwise = safeToEat x a b
  where safeToEat x a b
          | (-a) + b > 0 = "safe"
          | otherwise = "delicious"


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
const int INF = 1e9;
const llint llINF = 1e18;

int main () {
    int r, d, x2000;
    cin >> r >> d >> x2000;
    int out = x2000;
    for (int i = 1; i < 11; i++) {
        out = r * out - d;
        cout << out << endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main() {
    var (
        n, count int
        list []int
    )
    fmt.Scan(&n)
    list = make([]int, n)
    for i:=0; i<n; i++ {
        fmt.Scan(&list[i])
    }
    count = selection_sort(list, n)
    list_print(list)
    fmt.Println(count)
}

func selection_sort(a []int, n int) (count int){
    var minj int
    for i, _ := range a {
        minj = i
        for j:=i; j<n; j++ {
            if a[j] < a[minj] {
                minj = j
            }
        }
        a[i], a[minj] = a[minj], a[i]
        if(minj != i) {
            count++
        }
    }
    return
}

func list_print(list []int) {
    for i, val := range list {
        if i == 0 {
            fmt.Print(val)
        } else {
            fmt.Print(" ", val)
        }
    }
    fmt.Println()
}



Measured memory_bytes: 1132
#include <stdio.h>
#include <math.h>


int main(void){
    int N;
    int D;

    scanf("%d",&N);
    scanf("%d",&D);

    int zahyo[N][D];

    int i;
    int j;
    for(i=0;i<N;i++){
        for(j=0;j<D;j++){      
            scanf("%d",&zahyo[i][j]);
            //printf("%d,%d  %d \n",i,j, zahyo[i][j]);
        }
    }

    double keisankekka=0;
    double heihouwa=0;
    int jud=0;

    int counter=0;

    int iplus;
    
    for(i=0;i<N;i++){
        j=0;
        for(iplus=i+1;iplus<N;iplus++){
            if(iplus>N){
                break;
            }
            //printf("%d \n",iplus);
            keisankekka=0;
            for(j=0;j<D;j++){
                //printf("%d \n",zahyo[iplus][j]);
                keisankekka +=(zahyo[i][j]-zahyo[iplus][j])*(zahyo[i][j]-zahyo[iplus][j]);
            }
            //printf("%lf \n",keisankekka);
                heihouwa=sqrt(keisankekka);
                jud=(int)heihouwa *(int)heihouwa;
                if((double)jud==keisankekka){
                    counter++;
                }
        //printf("!\n");
        }
        //printf("?\n");
    }


    printf("%d \n",counter) ;
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int m, d;
    cin >> m >> d;
    int ans = 0;
    rep(month, 1, m + 1) {
        rep(day, 1, d + 1) {
            int d1 = day / 10;
            int d10 = day % 10;
            if (d1 >= 2 && d10 >= 2 && d1 * d10 == month) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}

int main(){
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    
    scanf("%d",&k);
    
    printf("%d\n",a[k-1]);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int min(int a, int b)
{
	if (a < b)
		return a;
	else
		return b;
}
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	double ans = 0, now = 0;
	if (n >= k)
		ans += (double)(n - k + 1) / (double)n;
	int i, point;
	for (i = 1; i < min(n + 1, k); i++)
	{
		now = (double)(1) / (double)(n);
		point = i;
		while (point < k)
		{
			point *= 2;
			now /= 2;
		}
		ans += now;
	}
	printf("%.20lf\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
struct Edge {
	int to;
	Edge *nxt;
	Edge(int to, Edge *nxt) : to(to), nxt(nxt) {}
} *head[N];
void add(int x, int y) {head[x] = new Edge(y, head[x]);}
int n, m, A, B, mx, cnt, flag, deg[N];
void dfs(int x, int f) {
	if(x == A && f) puts("Yes"), exit(0);
	if(x == B) return;
	for(Edge *i = head[x]; i; i = i->nxt) {
		if(i->to == f) continue;
		dfs(i->to, x);
	}
}
int main() {
	n = read(); m = read();
	for(int i = 1, x, y; i <= m; ++ i) deg[x = read()] ++, deg[y = read()] ++, add(x, y), add(y, x);
	for(int i = 1; i <= n; ++ i) {
		if(deg[i] & 1) return puts("No"), 0;
		mx = max(mx, deg[i]);
		if(deg[i] == 4) {cnt ++; if(A) B = i; else A = i;}
	}
	if(mx < 4 || (mx == 4 && cnt == 1))  return puts("No"), 0;
	if(mx > 4 || cnt > 2) return puts("Yes"), 0;
	dfs(A, 0); puts("No");
	return 0;
}
 

Measured memory_bytes: 8448
#include <cstdio>

int main()
{
  int n;
  char s[101];
  scanf("%d %s", &n, s);
  int x = 0;
  int max = 0;
  for (char *p = s; *p; ++p)
  {
    if (*p == 'I')
    {
      ++x;
      if (max < x) max = x;
    }
    else --x;
  }
  printf("%d\n", max);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
#include <string>
using namespace std;

typedef long long int ll;

int main(){
    ll A, flag = 0;
    cin >> A;
    for(int i=1; i*i<=A; i++){
        if(A%i==0){
            if(i < 10 && A/i < 10){
                cout << "Yes";
                flag = 1;
                break;
                }
            }
        }
    if(flag == 0)cout << "No";
}

Measured memory_bytes: 256
a = []
for i in range(5):
    b = input()
    c = b[-1] if b[-1] != "0" else "9"
    d = (int(b) + 10 - 1) // 10 * 10
    a.append([b, c, d])
a = sorted(a, key=lambda x: x[1])
e = 0
for i in range(5):
    if i == 0:
        e += int(a[i][0])
    else:
        e += a[i][2]
print(e)


Measured memory_bytes: 3060
// WARNING: Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Macro
#define rep(i, N) for(int i=0; i<(int)N; i++)
#define erep(i, N) for(int i=0; i<=(int)N; i++)
#define mp make_pair
#define pb push_back

// Type
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

// Constants
const int MOD = (int)1e9 + 7;
int dy[] = {0, 1, -1, 0};
int dx[] = {1, 0, 0, -1};

/**
  型に合わせたINFを返す
  int: 214,748,364 (2.14 * 1e8)
  ll : 922,337,203,685,477,580 (9.22 * 1e17)
*/
template <typename T>
T getINF() {
  // NOTE: INF同士を足してもオーバーフロー起こさないように、10で割っている
  return numeric_limits<T>::max() / 10;
}

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

int n, m;
vector<int> k;
vector< vector<int> > s;
vector<int> p;

bool isOK(int x) {
  vector<int> on;
  rep(i, n) {
    on.pb(x % 2);
    x /= 2;
  }

  rep(i, m) {
    int _sum = 0;
    rep(j, k[i]) {
      _sum += on[s[i][j]];
    }
    if(_sum % 2 != p[i]) return false;
  }
  return true;
}

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

  rep(i, m) s.pb(vector<int>());
  rep(i, m) {
    int ki;
    cin >> ki;
    k.pb(ki);
    rep(j, ki) {
      int sj;
      cin >> sj;
      s[i].pb(sj-1);
    }
  }
  rep(i, m) {
    int pi;
    cin >> pi;
    p.pb(pi);
  }

  int ans = 0;
  rep(x, pow(2, n)) {
    if(isOK(x)) ans++;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;
typedef long double ldouble;

void solve(){
	int N; scanf("%d", &N);
	ll s = 0;
	for(int i=1;;i++){
		s += i;
		if(s >= N){
			printf("%d\n", i);
			return;
		}
	}
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
public class Hello{
    public static void Main(){
        string[] str = System.Console.ReadLine().Split(' ');
        //var[] a = int.Parse(str.Split(' '));
        int[] a = new int[3];
        for(int i=0; i<3; i++){
            a[i] = int.Parse(str[i]);
            //System.Console.WriteLine(str[i]);
        }
        if(a[0]<a[1]){
            if(a[0]<a[2] && a[2]<a[1]){
                System.Console.WriteLine("Yes");
            }else{
                System.Console.WriteLine("No");
            }
        }else{
            if(a[1]<a[2] && a[2]<a[0]){
                System.Console.WriteLine("Yes");
            }else{
                System.Console.WriteLine("No");
            }
        }
        //System.Console.WriteLine(a[0]+a[1]+a[2]);
    }
}


Measured memory_bytes: 17708
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		for (int i=0; i<n; i++) {
			s[i] = sc.next();
		}
		sc.close();

		Map<String, Integer> map = new HashMap<>();
		for (int i=0; i<s.length; i++) {
			char[] c = s[i].toCharArray();
			Arrays.sort(c);
			String key = String.valueOf(c);
			if (map.containsKey(key)) {
				map.put(key, map.get(key) + 1);
			} else {
				map.put(key, 1);
			}
		}

		long cnt = 0;
		for (Integer v : map.values()) {
			if (v == 1) continue;
			long t = (long)v;
			cnt += (t*t - t) / 2;
		}

		System.out.println(cnt);
	}

}

Measured memory_bytes: 54200
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int n;
    cin>>n;
    long long int a[n];
    for(long long int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    long long int ans=a[n/2]-a[n/2-1];
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  bool judge = false;
  for(int i = 0;i < s.size();i++){
    for(int j = 0;j < s.size();j++){
      string S = s;
      if(i+j <= s.size()){
        S.erase(i,j);
        if(S == "keyence"){
          judge = true;
          break;
        }
      }
    }
  }
  if(judge == true)cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

int main() {
  string s;
  cin >> s;
  bool feasible = true;
  int n = s.size();
  if (s[n - 1] == '1') feasible = false;
  if (s[0] == '0') feasible = false;
  for (int ni = 0; ni < n / 2; ni++) {
    if (s[ni] != s[n - 2 - ni]) feasible = false;
  }
  vector<int> tree;
  int last = -1;
  for (int ni = 0; ni < n - 1; ni++) {
    if (s[ni] == '1') {
      tree.push_back(ni - last);
      last = ni;
    }
  }
  tree.push_back(1);
  if (feasible) {
    for (int i = 1; i < tree.size(); i++) {
      cout << i << " " << i + 1 << "\n";
    }
    int idx = tree.size() + 1;
    for (int i = 0; i < tree.size(); i++) {
      for (int j = 1; j < tree[i]; j++) {
        cout << i + 1 << " " << idx++ << "\n";
      }
    }
  } else {
    cout << -1 << "\n";
  }
  return 0;
}

Measured memory_bytes: 2040
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    const int dx=tx-sx, dy=ty-sy;

    cout << string(dy, 'U') << string(dx, 'R');

    cout << string(dy, 'D') << string(dx, 'L');

    cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
    cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (h, w) = (v[0], v[1]);
    for _ in 0..h {
        let s = read::<String>();
        println!("{}", s);
        println!("{}", s);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

const double INF = 1000 * 1000 * 1000;
int n, m;
vector<vector<int>> g;
vector<vector<int>> rg;
vector<int> u;
vector<int> c;
vector<int> ord;
int clr = 1;

void dfs(int v)
{
    if(u[v])
    {
        return;
    }
    u[v] = true;
    for(auto i : g[v])
    {
        dfs(i);
    }
    ord.push_back(v);
}
void dfs2(int v, int clr)
{
    if(u[v])
    {
        return;
    }
    u[v] = true;
    c[v] = clr;
    for(auto i : rg[v])
    {
        dfs2(i, clr);
    }
}

int main()
{
    int n, d, x;
    cin >> n >> d >> x;
    int ans = x;
    for(int i = 0; i < n; ++i)
    {
        int a;
        cin >> a;
        int cont = 1;
        while(a * cont + 1 <= d)
        {
            ++cont;
        }
        ans += cont;
    }
    cout << ans;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

#define H_MAX 100
#define W_MAX 100

int H, W;

char map[H_MAX][W_MAX];

void get_input() {
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            map[i][j] = getchar();
        }
        getchar();
    }
}

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

void dfs(int h, int w) {
    if (h < 0 || H <= h || w < 0 || W <= w) return;
    char k = map[h][w];
    map[h][w] = 'X';
    for (int i = 0; i < 4; i++) {
        int nx = w + dx[i], ny = h + dy[i];
        if (map[ny][nx] == k) dfs(ny, nx);
    }
}

//void debug(int count) {
//    cout << "count: " << count << endl;
//    for (int i = 0; i < H; i++) {
//        for (int j = 0; j < W; j++) {
//            cout << map[i][j];
//        }
//        cout << endl;
//    }
//}

int solve() {
    int count = 0;
//    debug(0);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (map[i][j] != 'X') {
                count++;
                dfs(i, j);
//                debug(count);
            }
        }
    }
    return count;
}

int main() {
    while (cin >> H >> W, (H || W)) {
        getchar(); // 最初の改行をつぶす
        get_input();
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(obj) (obj).begin(), (obj).end() //sort(ALL(obj))みたいな



using namespace std;

int main() {
  int h,a;
  cin >> h >> a;
  if (h%a != 0) cout << h/a + 1 << endl;
  else cout << h/a << endl;
}


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

int main() {
	int n;
	cin >> n;
	int a[4];
	for (int i = 0; i < 4; i++) {
		a[i] = n % 10;
		n /= 10;
	}
	if (a[3] - a[2] - a[1] - a[0] == 7)
		cout << a[3] << "-" << a[2] << "-" << a[1] << "-" << a[0] << "=" << 7 << endl;
	else if (a[3] - a[2] - a[1] + a[0] == 7)
		cout << a[3] << "-" << a[2] << "-" << a[1] << "+" << a[0] << "=" << 7 << endl;
	else if (a[3] - a[2] + a[1] - a[0] == 7)
		cout << a[3] << "-" << a[2] << "+" << a[1] << "-" << a[0] << "=" << 7 << endl;
	else if (a[3] - a[2] + a[1] + a[0] == 7) 
		cout << a[3] << "-" << a[2] << "+" << a[1] << "+" << a[0] << "=" << 7 << endl;
	else if (a[3] + a[2] - a[1] - a[0] == 7) 
		cout << a[3] << "+" << a[2] << "-" << a[1] << "-" << a[0] << "=" << 7 << endl;
	else if (a[3] + a[2] - a[1] + a[0] == 7)
		cout << a[3] << "+" << a[2] << "-" << a[1] << "+" << a[0] << "=" << 7 << endl;
	else if (a[3] + a[2] + a[1] - a[0] == 7)
		cout << a[3] << "+" << a[2] << "+" << a[1] << "-" << a[0] << "=" << 7 << endl;
	else if (a[3] + a[2] + a[1] + a[0] == 7)
		cout << a[3] << "+" << a[2] << "+" << a[1] << "+" << a[0] << "=" << 7 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds; 
using namespace std;



typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
 
 
//defines
typedef long long ll;
typedef long double ld;

    
ll a,b,c,n,m,k,t=1;

void solve()
{
    cin>>a>>b>>c>>n>>m;
    if(a==0){cout<<1;return;}
    if(b==0){cout<<2;return;}
    if(c==0){cout<<3;return;}
    if(n==0){cout<<4;return;}
    cout<<5;return;
   
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

ll solve(ll x, const ll N, const vector<ll> &a, const vector<ll> &b) {
    ll acc = 0;
    for (int i = 1; i <= N; i++) {
        ll border = b[i] - x;
        auto it = lower_bound(b.begin(), b.begin() + i, border);
        int start = it - b.begin();
        acc += i - start;
    }
    return acc;
}

int main(void) {
    ll N, Q;
    cin >> N >> Q;

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

    vector<ll> b(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        b[i] = b[i - 1] + a[i - 1];
    }

    for (int i = 0; i < Q; i++) {
        ll x;
        scanf("%lld", &x);
        printf("%lld\n", solve(x, N, a, b));
    }

    return 0;
}



Measured memory_bytes: 4424
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll w, h, n; cin >> w >> h >> n;
  vector<vector<ll>> m0(h, vector<ll>(w, -linf));
  vector<vector<ll>> m(h, vector<ll>(w, -linf));
  rep(t, n) {
    ll x, y, z; cin >> x >> y >> z; --x, --y;
    m0[y][x] = z;
    rep(i, h) rep(j, w) {
      chmax(m[i][j], z - (abs(x - j) + abs(y - i)));
    }
  }
  rep(y, h) rep(x, w) {
    if (m0[y][x] >= 0 && m[y][x] > m0[y][x]) {
      cout << "No" << endl;
      return;
    }
  }
  ll ans = 0;
  rep(y, h) rep(x, w) ans += m[y][x];
  cout << ans << endl;
}



Measured memory_bytes: 3252
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <cstring>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

typedef pair<int, int> P;

bool ps1(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first昇順
    return forall_a_in_P.first < forall_b_in_P.first;
}
bool ps2(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first降順
    return forall_a_in_P.first > forall_b_in_P.first;
}
bool ps3(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second昇順
    return forall_a_in_P.second < forall_b_in_P.second;
}
bool ps4(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second降順
    return forall_a_in_P.second > forall_b_in_P.second;
}

// 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策

// 入力

int n;
int k;
int dp[100100];
 
int main(){
    int x;
    cin>>x;
    vector<int>a(6,100);
    rep(i,6){
        a[i]+=i;
        //cout<<a[i]<<endl;
    }
    vector<int>m(6,1000);
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    rep(i,6){
        rep(j,x+1){
            if(dp[j]>=0){
                dp[j]=m[i];
            }else if(j<a[i]||dp[j-a[i]]<=0){
                dp[j]=-1;
            }else{
                dp[j]=dp[j-a[i]]-1;
            }
        }
    }
    if(dp[x]>=0){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
template<class T>
void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>
void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}
template<class T>T chmax(T&a,T b){return a=a>b?a:b;}
template<class T>T chmin(T&a,T b){return a=a<b?a:b;}
/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int d;
	cin>>d;
	rep(_,d){
		string s,t;
		cin>>s>>t;
		int n=s.size(),m=t.size();
		vvi dp(n+1,vi(m+1,0));
		rep(i,n){
			dp[i+1]=dp[i];
			rep(j,m){
				if(s[i]==t[j]){
					chmax(dp[i+1][j+1],dp[i][j]+1);
				}else{
					chmax(dp[i+1][j+1],dp[i+1][j]);
				}
			}
	//		cout<<dp[i]<<endl;
		}
	//	cout<<dp[n]<<endl;
		cout<<dp[n][m]<<endl;
	}
	return 0;
}


Measured memory_bytes: 6868
#include <iostream>
#include <cstdio>
using namespace std;
int a[100],k[100][100],n,m,p[100],d=0;
void readdata()
{
    cin>>n>>m;
    for (int i=1;i<=m;i++)
    {
        cin>>k[i][0];
        for (int j=1;j<=k[i][0];j++)
        {
            cin>>k[i][j];
        }
    }
    for (int i=1;i<=m;i++) cin>>p[i];
}

bool check()
{
    for (int i=1;i<=m;i++)
    {
        int s=0;
        for (int j=1;j<=k[i][0];j++)
        {
            if (a[k[i][j]]==2)s++;
        }
        if (s%2!=p[i]) return false;
    }
    return true;
}

void vet(int cou)
{
    if (cou>n)
    {
        if (check()) d++;
    }
    else
    {
        for (int i=1;i<=2;i++)
        {
            a[cou]=i;
            vet(cou+1);
        }
    }
}

void solve()
{
    vet(1);
    cout<<d;
}

int main()
{
   // freopen("a.inp","r",stdin);
   // freopen("a.out","w",stdout);
    readdata();
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define VECCIN(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int a, b;
    cin >> a >> b;
    cout << b * 2 - a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int n,m;
 	cin >> n>>m;
 	cout << max({n+m,m*2-1,n*2-1}) << endl;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,a[101],y;
bool nibun(int x){
	int s=0,q=0,t=0;
	r(i,n){
		if(s+a[i]<=x)s+=a[i];
		else s=0,q++,i--,t++;
		if(t>1000)return 0;
	}
	return m>=q+1;
}
main(){
	while(cin>>m>>n,m){
	  y=1e9;
	  r(i,n)cin>>a[i],y=min(y,a[i]);
	  int l=y,r=1500001;
	  while(l<r){
    	int mid=(l+r)/2;
		if(nibun(mid))r=mid;
		else l=mid+1;
	  }
	  cout<<l<<endl;
    }
}

Measured memory_bytes: 3052
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<deque>
#define MOD 1000000009
#define INF 9999999999999 
#define pb push_back
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;
ll ncr(ll n, ll r)
{
	ll i, ans = 1, k = 0;
	if (r == 0)
		return 1;
	else if (n < r)
		return 0;
	for (i = n; i >= n - r + 1; i--)
	{
		ans *= i;
		ans /= n - i + 1;
	}


	return ans;

}
bool visited[6] = { false };
int n = 6;
vector<int> adj[6];


void max_heapify(int a[100], int i)
{
	int l, r, largest = i;
	l = 2 * i + 1;
	r = 2 * i + 2;
	if (l<n && a[l]>a[i])
		largest = l;
	if (r<n && a[r]>a[l])
		largest = r;
	if (largest != i)
	{
		int k;
		k = a[i];
		a[i] = a[largest];
		a[largest] = k;
		max_heapify(a, largest);
	}

}
int power(ll x, ll y, ll p)
{
	int res = 1;
	x = x % p;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;


		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

bool square(ll n)
{
	double x;
	x = sqrt(n);
	if (x == floor(x))
		return true;
	else return false;
}


bool prime(ll n)
{
	ll i;
	for (i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}
void dfs(ll a, ll b, vector<pair<ll, ll>>adj[][1001], bool visited[][1001])
{
	visited[a][b] = true;
	for (auto u : adj[a][b])
	{
		if (!visited[get<0>(u)][get<1>(u)])
		{
			visited[get<0>(u)][get<1>(u)] = true;
			dfs(get<0>(u), get<1>(u), adj, visited);
		}
	}
}
ll modi(ll a, ll m)
{
	return power(a, m - 2, m);

}
void kmp(string s, ll pi[]) {
	int n = (int)s.length();
	pi[0] = 0;
	for (int i = 1; i < n; i++) {
		int j = pi[i - 1];
		while (j > 0 && s[i] != s[j])
			j = pi[j - 1];
		if (s[i] == s[j])
			j++;
		pi[i] = j;
	}

}
struct pair_hash {
	size_t operator()(const pair<int, int>& p) const noexcept {
		return hash<ll>() ((((ll)p.first) << 32) | ((ll)p.second));
	}
};


int main() {
	fast;
	ll k, arr[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	cin >> k;
	cout << arr[k - 1];
	return 0;
}

Measured memory_bytes: 256
N,C,K = map(int,input().split())

T = []

for i in range(N):

    t = int(input())
    T.append(t)

T.sort()

ans = 0
now = 0
nt = T[0]
for i in range(N):

    if T[i] - nt > K:
        ans += 1
        nt = T[i]
        now = 1

    elif now == C:
        ans += 1
        nt = T[i]
        now = 1

    else:
        now += 1

print (ans+1)


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());
	int ans=a.at(n-1)-a.at(0);
	cout << ans << endl;
}


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

int main() {
  int N, h, prev, ans;

  cin >> N;
  ans = 0;
  prev = 0;
  for (int i = 0; i < N; i++) {
    cin >> h;
    if (prev < h) {
      ans += h - prev;
    }
    prev = h;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256