akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

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

struct Node {
	Node* parent = NULL;
	vector<Node*> child;
	long long value = 0;
};
struct Edge {
	int parent = 0;
	int child = 0;
	bool operator <(const Edge& right) const { return parent < right.parent; }
};
struct Tree {
	vector<Node> node;
	Tree(int, vector<Edge>);
};
Tree::Tree(int nodeNum, vector<Edge> edge) {
	node.resize(nodeNum);
	for (Edge& it : edge) {
		node[it.child].parent = &node[it.parent];
		node[it.parent].child.push_back(&node[it.child]);
	}
}

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
		else {
			break;
		}
	}
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	long long m_module = 1000000007;
	vector<struct Memo> memo;
public:
	long long calculate(int, int);
	Combination1(int, long long);
};
long long Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, long long module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_Transfer(void) {

	int A, B, C; cin >> A >> B >> C;

	cout << max(-A + B + C, 0) << flush;
	return;
}

void B_Uneven_Numbers(void) {

	int N; cin >> N;

	int counter = 0;
	for (int length = 1; length <= 6; length+=2) {
		if (N < (int)pow(10, length)) {
			counter += max(N - (int)pow(10, length - 1) + 1, 0);
			break;
		}
		else {
			counter += (int)pow(10, length) - (int)pow(10, length - 1);
		}
	}

	cout << counter << flush;
	return;
}

int main(void) {

	//A_Transfer();
	B_Uneven_Numbers();
	return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <list>
#include <cstdlib>
#include <bitset>
#include <assert.h>
#include <time.h>
#include <iomanip>
// #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
// char buf[(1 << 21) + 1], * p1 = buf, * p2 = buf;
// #define int long long
#define lowbit(x) (x & (-x))
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
#define pb push_back
typedef unsigned long long ull;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> VI;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define SZ(x) ((int)((x).size()))
#define bug puts("BUG")
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-6;
template <class T>
inline void read(T &x)
{
    int sign = 1;char c = getchar();x = 0;
    while (c > '9' || c < '0'){if (c == '-')sign = -1;c = getchar();}
    while (c >= '0' && c <= '9'){x = x * 10 + c - '0';c = getchar();}
    x *= sign;
}
#ifdef LOCAL
    FILE* _INPUT=freopen("input.txt", "r", stdin);
    // FILE* _OUTPUT=freopen("output.txt", "w", stdout);
#endif
using namespace std;
int main()
{
    int k, a, b;
    read(k), read(a), read(b);
    puts((a % k == 0 || a / k * k + k <= b) ? "OK": "NG");
}

Measured memory_bytes: 3520
#include <stdio.h>
#include <string.h>

int main(){
  int i, a, b;
  char s[12], t[12];
  scanf("%s",s);
  scanf("%s",t);
  a = strlen(s);
  b = strlen(t);
  if(a != b-1) {
    puts("No");
    return 0;
  }
  for(i=0;i<a;i++){
    if(s[i]!=t[i]){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}
  

Measured memory_bytes: 1640
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            int res[] = new int[26];
            int max[] = new int[26];

            Arrays.fill(res,-1);

            for(int i=0; i<s.length(); i++){
                if(res[s.charAt(i)-'a']==-1){
                    res[s.charAt(i)-'a']=i;
                    max[s.charAt(i)-'a']=i-0;
                }
                else if(res[s.charAt(i)-'a']>-1){
                    if(i-res[s.charAt(i)-'a']-1>max[s.charAt(i)-'a']){
                        max[s.charAt(i)-'a']=i-res[s.charAt(i)-'a']-1;
                    }
                    res[s.charAt(i)-'a'] = i;
                }
                if(i==s.length()-1){
                    for(int j=0; j<26; j++){
                        if(i-res[j]>max[j]){
                            max[j]=i-res[j];
                        }
                    }
                }
            }
            int min = 100000;
            for(int i=0; i<26; i++){
                if(max[i]<min){
                    min = max[i];
                }
            }

            out.println(min);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 21332
#include <iostream>
using namespace std;
using ll = unsigned long long;
int main() {
  ll H, W;
  cin >> H >> W;
  if(H == 1ull || W == 1ull) {
    cout << 1 << endl;
    return 0;
  }

  if((H * W) % 2ull == 0ull) {
    ll ans = (H * W) / 2ull;
    cout << ans << endl;
  } else {
    ll ans = (H * W + 1ull) / 2ull;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

ll z_alg(string s){
    ll a[s.size()] = {};
    ll c = 0;
    ll ret = 0;

    for(ll i = 1; i < s.size(); ++i){
        if(i + a[i-c] < c + a[c]){
            a[i] = a[i-c];
        }
        else {
            ll j = max(0LL, c + a[c] - i);
            while(i + j < s.size() && s[j] == s[i + j])++j;
            a[i] = j;
            c = i;
        }

        ret = max(ret, min(i, a[i]));
    }

    return ret;
}

int main(){
    ll n;
    string s;
    cin >> n >> s;
    
    ll ans = 0;
    while(!s.empty()){
        ans = max(ans, z_alg(s));
        s.erase(s.begin());
    }

    cout << ans << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
#define pb=push_back
int INF=1e9+7;

int main() {
  string S,T;
  cin >> S >> T;
  int N=S.size(),ans=0;
  rep(i,N) {
    if(S[i]!=T[i]) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3848
package main

import "fmt"

func main() {
	var N, X int
	fmt.Scanf("%d %d", &N, &X)
	L := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &L[i])
	}
	D := 0
	count := 0
	for i := 0; i < N; i++ {
		if D <= X {
			count++
		}
		D += L[i]
	}
	if D <= X {
		count++
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int sumremn(int n) {
    int sum = n % 10;
    while (n >= 10) {
        n /= 10;
        int remn = n % 10;
        sum += remn;
    }
    return sum;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int n = i;
        int sum = sumremn(n);
        if (A <= sum&&B >= sum) {
            ans += n;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    
    if (W<x+r||H<y+r||x-r<0||y-r<0){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    
    return 0;
}



Measured memory_bytes: 2608
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
const double pi = acos(-1.0);
const double eps = 1e-6;
using namespace std;



int n, m;

void solve(){ 
    cin >> n >> m;

    vector <ll> a(n + 1);
    
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    ll mn = a[1];
    ll res = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++){
        if (a[i] <= mn) mn = a[i];
        else{
            if (res < a[i] - mn){
                res = a[i] - mn;
                ans = 1;
            }
            else if (res == a[i] - mn) ans++;
        }
    }
    cout << ans << endl;
    
}       
int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(5);
    //freopen("input.txt", "r", stdin);//freopen("output1.txt", "w", stdout);
    //freopen("icecream.in","r",stdin);// freopen("exam.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++){
         solve();
    }
}

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

int main(){
	int m, f, r;
	while (1){
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1){
			break;
		}
		else if (m == -1 || f == -1){
			cout << 'F' << endl;
		}
		else if (m + f >= 80){
			cout << 'A' << endl;
		}
		else if (m + f >= 65 && m + f < 80){
			cout << 'B' << endl;
		}
		else if (m + f >= 50 && m + f < 65||r>=50){
			cout << 'C' << endl;
		}
		else if (m + f >= 30 && m + f < 50){
			cout << 'D' << endl;
		}
		else if (m + f < 30){
			cout << 'F' << endl;
		}

	}

	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define mod 1000000007
#define int long long

void solve() {
	int n, k;
	cin >> n >> k;
	int i, j;
	int a[n];
	for (i = 0; i < n; i++)cin >> a[i];
	int dp[k + 1] = {0};
	dp[0] = 0;
	for (i = 1; i <= k; i++) {
		for (j = 0; j < n; j++) {
			if (i - a[j] >= 0) {
				if (dp[i - a[j]] == 0) {
					dp[i] = 1;
					break;
				}
			}
		}
	}

	// for (i = 0; i <= k; i++)cout << dp[i] << " ";
	// cout << endl;

	if (dp[k] == 1)cout << "First" << endl;
	else cout << "Second" << endl;

	return;
}

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	while (t--)solve();
	return 0;
}

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

#define FOR(i,s,e) for(ll (i)=(s);(i)<(e);(i)++)
typedef long long ll;

/* 2017/01/21 問題 ----- ABC045 D /Link http://abc045.contest.atcoder.jp/tasks/arc061_b */
/* -----解説等-----
問題: 縦 H 行、横 W 列のマス目からなる盤があります。最初、どのマス目も白く塗られています。
すぬけ君が、このうち N マスを黒く塗りつぶしました。i 回目 ( 1≦i≦N ) に塗りつぶしたのは、 上から ai 行目で左から bi 列目のマスでした。
すぬけ君がマス目を塗りつぶした後の盤の状態について、以下のものの個数を計算してください。
各整数 j ( 0≦j≦9 ) について、盤の中に完全に含まれるすべての 3 行 3 列の連続するマス目のうち、黒いマスがちょうど j 個あるもの。

制約
3≦H≦109
3≦W≦109
0≦N≦min(105,H×W)
1≦ai≦H (1≦i≦N)
1≦bi≦W (1≦i≦N)
(ai,bi)≠(aj,bj) (i≠j)


*/

ll H, W, N;
map<pair<int, int>, int>mp;
ll left0;
ll ans[10];

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

    cin >> H >> W >> N; //y,x

    int a, b;//1 -> H or W

    FOR(i, 0, N) {
        cin >> b >> a;
        FOR(x, -1, 2)FOR(y, -1, 2) {
            if (a + x >= 2 && a + x <= W - 1 && b + y >= 2 && b + y <= H - 1)
                mp[make_pair(a + x, b + y)]++;
        }
    }

    for (auto it = mp.begin(); it != mp.end(); it++) {
        ans[it->second]++;
    }

    left0 = (H - 2)*(W - 2)-mp.size();

    cout << left0 << endl;

    FOR(i, 1, 10)
        cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 56448
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 101, K = 1e5+10;

int n, k;
int a[N];
bool dp[K];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j < n; j++) {
      if (a[j] > i) continue;
      if (!dp[i-a[j]]) {
        dp[i] = 1;
        break;
      }
    }
  }
  puts(dp[k] ? "First" : "Second");
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a>b){
    cout<<a+a-1<<endl;
  }
  if(a==b){
    cout<<a+b<<endl;
  }
  if(a<b){
    cout<<b+b-1<<endl;
  }
}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int sum=0;
  for(int i=1;i<=n;i++){
      int n1,n2,n3,n4,n5,nn;
      n1=i%10;
      n2=i%100/10;
      n3=i%1000/100;
      n4=i%10000/1000;
      n5=i/10000;
      nn=n1+n2+n3+n4+n5;
  	if(nn>=a&&nn<=b){sum+=i;}
  }
  cout << sum <<endl;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long int 
signed main()
{
    int n,m;
    cin>>n>>m;
    int a[m];
    for(int i=0;i<m;i++)
        cin>>a[i];
    
    int dp[n+1]={0};
    for(int i=0;i<m;i++)
        dp[a[i]]=-1;
    
    dp[0]=1;
    if(dp[1]==-1)
    dp[1]=0;
    else
    dp[1]=1;
    for(int i=2;i<=n;i++)
    {
        if(dp[i]==-1)
        dp[i]=0;
        else
        {
            dp[i]=(dp[i-1]+dp[i-2])%mod;
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1792
// AGC003_A
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

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

    // input
    string str;
    cin >> str;
    
    // calculation
    // 縦，横
    ll north = 0, south = 0, west = 0, east = 0;
    REP(i, str.length()) {
        if (str[i] == 'N') north++;
        else if (str[i] == 'S') south++;
        else if (str[i] == 'W') west++;
        else east++;
    }
    
    if ((north == 0 && south != 0) || (north != 0 && south == 0) || (west == 0 && east != 0) || (west != 0 && east == 0)) {
        cout << "No" << "\n";
    } else {
        cout << "Yes" << "\n";
    }
    return 0;
}


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

int main(void)
{
	int r;
	
	/*printf("r = ");*/		scanf("%d", &r);
	
	if(r>=1 && r<=100){
		printf("%d",r*r);
	}
	/*else
		printf("out of range\a");*/
	
	return 0;
}


Measured memory_bytes: 128
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    a_b = []
    for _ in range(n):
        a_b.append(LI())
    a_b.sort(key=lambda x: x[1])
    t = 0
    for d in a_b:
        t += d[0]
        if t > d[1]:
            print("No")
            sys.exit()
    print("Yes")

if __name__ == '__main__':
    main()

Measured memory_bytes: 46932
#include<cstdio>

int main(){

    int n;

    while(scanf("%d",&n)!=EOF){
        int ans=0;
        for(int i=0;i<10;i++)for(int j=0;j<10;j++)for(int k=0;k<10;k++)for(int l=0;l<10;l++)if(i+j+k+l==n)ans++;
    printf("%d\n",ans);
    }

    return 0;
}

Measured memory_bytes: 1024
import heapq
N, M = map(int, input().split())
S = list()
A = [list() for _ in range(M+1)]
for _ in range(N):
    a, b = map(int, input().split())
    if M < a:
        continue
    heapq.heappush(A[a], -b)

ans = 0
for i in range(1, M+1):
    for num in A[i]:
        heapq.heappush(S, num)
    if S == []:
        continue
    ans -= heapq.heappop(S)
print(ans)


Measured memory_bytes: 89192
class Array
def insert k
x,l,r=self
x ?(k<x ?l:r).insert(k):self<<k<<[]<<[]
end
def find k
puts f(k) ?:yes: :no
end
def f k
x,l,r=self
x&&(k==x ?1:(k<x ?l:r).f(k))
end
def print
$x,$y=[p],[p]
w
puts $y*" ",$x*" "
end
def w
x,l,r=self
x&&($x<<x
l.w
$y<<x
r.w)
end
end
t=[]
gets
eval"t.#$_"while gets

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

int dp[101][100001];

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int nbItem, maxWeight;
    cin >> nbItem >> maxWeight;

    int maximum = 0;

    for (int i = 1; i <= nbItem; i++){
        int weight, value;
        cin >> weight >> value;
        //cout << "DEBUG " << i << endl;

        for (int a = 0; a <= maxWeight; a++){
            dp[i][a] = dp[i-1][a];
            if (a - weight >= 0){
                dp[i][a] = max(dp[i][a], value + dp[i-1][a - weight]);
            }
            
            //cout << "DEBUG " << a << ' ' << dp[i][a] << endl;
            maximum = max(maximum, dp[i][a]);
        }
    }
    cout << maximum;
}

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

int main(){
  int h,w;
  cin >>h >>w;
  string board[50];
  rep(i,h) cin >>board[i];
  const int dx[8] = {-1,0,1,-1,1,-1,0,1};
  const int dy[8] = {-1,-1,-1,0,0,1,1,1};
  rep(i,h){
    rep(j,w){
      if(board[i][j]=='#') continue;
      int num = 0;
      rep(d,8){
        const int ni = i+dy[d];
        const int nj = j+dx[d];
        if(ni<0 or h<=ni) continue;
        if(nj<0 or w<=nj) continue;
        if(board[ni][nj]=='#') num++;
      }
      board[i][j] = char(num+'0');
    }
  }
  rep(i,h) cout << board[i] << endl;
  return 0;
}

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

using namespace std;

int main(void){
  int N;
  long long int X[200001],XX[200001];
  long long int candidate1,candidate2;
  scanf("%d",&N );
  for(int i=0;i<N;++i){
    scanf("%lld",&X[i]);
    XX[i] = X[i];
  }
  sort(XX,XX+N);
  candidate1 = XX[(N-1)/2];
  candidate2 = XX[(N+1)/2];
  for(int i=0;i<N;++i){
    if(X[i] <= candidate1){
      printf("%lld\n",candidate2);
    }else{
      printf("%lld\n",candidate1 );
    }

  }
  return 0;

}


Measured memory_bytes: 5376
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int i, N, K, h[100000], dif;
  long long min = 1000000000;

  scanf("%d %d", &N, &K);
  for (i = 0; i < N; i++)
  {
    scanf("%d", &h[i]);
  }

  sort(h, h + N);

  for (i = 0; i < N - K + 1; i++)
  {
    dif = h[i + K - 1] - h[i];
    if (dif <= min && dif >= 0)
    {
      min = dif;
    }
  }

  printf("%lld\n", min);

  return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to,cap,rev; 
	edge (int from, int to, int cap, int rev){
		this->from=from; this->to=to; this->cap=cap; this->rev=rev;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;


int h, w;
string s;
int main(){
	cin >> h >> w;
	FORI(0, h) {
		cin >> s;
		cout << s << endl;
		cout << s << endl;
	}

	return 0;
}


Measured memory_bytes: 256
// #define DEBUG_MODE
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
#ifdef DEBUG_MODE
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp("[%s = %s]\n", #x, to_string(x).data())

int main () { 
#ifdef DEBUG_MODE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	
	int n, x;
	double ans = 0;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		ans += 1.0 / x;
	}
	printf("%f\n", 1.0 / ans);
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        
        char[] Schar = new char[S.length()];
        char[] Tchar = new char[T.length()];
        int count = 0;
        
        
        
        for(int i=0;i<S.length();i++){
            Schar[i] = S.charAt(i);
            Tchar[i] = T.charAt(i);
            if(Schar[i]!=Tchar[i]){
                count++;
            }
        }
        
        System.out.println(count);
    }
}


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

long a[100010];
int main()
{
    long n, k; cin>>n>>k;
    for(int i=0; i<n; ++i) cin>>a[i];
    long x=0;
    for(int i=62; i>=0; --i) {
        int c=0;
        for(int j=0; j<n; ++j) c+=(a[j]>>i)&1;
        if (2*c<n && (x|(1L<<i))<=k) x|=1L<<i;
    }
    long res=0;
    for(int i=0; i<n; ++i) res+=x^a[i];
    cout<<res<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int a,b,k;
  cin>>k;
  cin>>a;
  cin>>b;
	int ans=0;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			ans++;
		}
	}
	if(ans==0){
		cout<<"NG";
	}else{
		cout<<"OK";
	}
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}





int main(){
    int n; cin >> n;
    string a,b;
    int sa = 0,sb = 0;

    rep(i,n){
        cin >> a >> b;
        if(a > b) sa += 3;
        else if(a == b){sa++; sb++;}
        else sb += 3;
    }

    cout << sa << " " << sb << endl;

    
}



Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stdlib.h>  
using namespace std;
int main()
{
	int x,a,b;
	cin>>x>>a>>b;
	if(abs(a-x)<abs(b-x))
		cout<<"A";
	else
		cout<<"B";
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<< 29;
const double PI = 3.14159265358979323846;


int main(){
        int N,M,Q,p[509][509];
        cin >> N >> M >> Q;
        for(int i = 1; i <= M; i++){
                int L,R;
                cin >> L >> R; 
                p[L][R]++;
        }

        for(int i = 1;i <= N; i++){
                for(int j = 1; j <= N; j++){
                        p[i][j] += p[i][j-1];
                }
        }

        for(int i = 1; i <= N; i++){
                for(int j = 1; j <= N; j++){
                        p[i][j] += p[i-1][j];
                }
        }

        //2次元累積和のテクニック
        for(int i = 1; i <= Q; i++){
                int L,R;
                cin >> L >> R;
                cout << p[R][R] + p[L-1][L-1] - p[L-1][R] - p[R][L-1] << endl;
        }
        return 0;
}



Measured memory_bytes: 1920
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict

n = ni()
a = na()
dic = defaultdict(int)

def color(n):
    if n >= 1 and n <= 399:
        return "a"
    if n >= 400 and n <= 799:
        return "b"
    if n >= 800 and n <= 1199:
        return "c"
    if n >= 1200 and n <= 1599:
        return "d"
    if n >= 1600 and n <= 1999:
        return "e"
    if n >= 2000 and n <= 2399:
        return "f"
    if n >= 2400 and n <= 2799:
        return "g"
    if n >= 2800 and n <= 3199:
        return "h"
    return "z"

for i in range(n):
    c = color(a[i])
    if c != "z" and dic[c] >= 1:
        continue
    dic[color(a[i])] += 1

ansmin = max(1, sum(dic.values()) - dic["z"])
ansmax = sum(dic.values())
print(ansmin, ansmax)

Measured memory_bytes: 3316
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    long double l;
    cin >> l;
    long double ans = l * l * l;
    ans /= (long double)27;
    printf("%.10Lf", ans);
}

Measured memory_bytes: 3760
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;
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; }
char s[N];
int n, m, k = 2e9, ans, a[N], b[N], f[N];
signed main() {
	n = read(); m = read(); scanf("%s", s + 1);
	int tag = 1;
	for(int i = 1, len = 0; i <= m; ++ i) {
		if(s[i] != s[1]) {
			if(tag || len & 1) k = min(k, len / 2 + 1);
			tag = len = 0;
		}
		else ++ len;
	}
	if(tag) {
		f[0] = 0; f[1] = 1;
		for(int i = 2; i <= n; ++ i) f[i] = (f[i - 1] + f[i - 2]) % mod;
		printf("%lld\n", (2 * f[n - 1] + f[n]) % mod);
		return 0;
	}
	if(n & 1) return puts("0"), 0;
	n /= 2;// k = min(k, n);
	a[0] = b[0] = 1;
	for(int i = 1; i <= n; ++ i) {
		a[i] = b[i - 1];
		if(i > k) a[i] = ((a[i] - b[i - k - 1]) % mod + mod) % mod;
		b[i] = (b[i - 1] + a[i]) % mod; 
	}
	for(int i = 1; i <= k; ++ i) ans = (ans + 2 * i * a[n - i]) % mod;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3584
n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
m=min(a,b,c,d,e)
if n<=m:
    print(5)
else:
    n-=m
    ans=n//m
    if n%m:
        ans+=1
    print(5+ans)


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

#define MAX 310000
int N, A[MAX];

vector<int> convert() {
  map<int,int> mp;
  rep(i,N) ++mp[A[i]];
  vector<int> C;
  for(auto v : mp) C.push_back(v.second);
  sort(ALL(C));
  return C;
}

/*
  K,ans wo kotei
  Sigma( min(C[i],ans) ) / K >= ans de are ba tukure ruru- 
  Sigma( min(C[i],ans) ) >= ans * K 
  Sigma( min(C[i],ans) ) >= ans * K nara Sigma( min(C[i],(ans-1)) ) >= (ans-1) * K 
  binariy search
 */
vector<int> C;
ll sum[MAX];
bool check(ll ans, ll K) {
  int ptr = lower_bound(ALL(C), ans) - C.begin();
  --ptr;
  int rem = (int)C.size() - 1 - ptr;
  ll sigma = sum[ptr] + (ll)rem * ans;
  return sigma >= ans * K;
}

void compute() {
  C = convert();
  sum[0] = C[0];
  REP(i,1,(int)C.size()) sum[i] = sum[i-1] + C[i];
  REP(K,1,N+1) {
    ll L = 1, R = N+1;
    while( R - L ){
      ll ans = ( L + R ) / 2LL;
      if( check(ans,K) ) L = ans + 1LL;
      else               R = ans;
    }
    cout << L - 1LL << endl; 
  }
}

int main() {
  cin >> N;
  rep(i,N) cin >> A[i];
  compute();
  return 0;
}


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

using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);

    int n,m,l;
    int a[110][110];
    int b[110][110];
    long long  c[110][110];

    while(cin>>n>>m>>l)
    {
        memset(c,0,sizeof(c));
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
                cin>>a[i][j];
        }
        for(int i=0;i<m;i++)
            for(int j=0;j<l;j++)
                cin>>b[i][j];

        for(int i=0;i<n;i++)
        {
            for(int j=0;j<l;j++)
            {
                for(int k=0;k<m;k++)
                {
                    c[i][j]+=a[i][k]*b[k][j];
                }
            }
        }

        for(int i=0;i<n;i++)
        {
            for(int j=0;j<l;j++)
            {
                cout<<c[i][j]<<(j==l-1? "\n":" ");
            }
        }
    }
}



Measured memory_bytes: 3276
N, K = map(int, input().rstrip().split())
Ps = [int(x) for x in input().rstrip().split()]

Ps_sum_list = []
Ps_sum = 0
for x in Ps:
    Ps_sum += x
    Ps_sum_list.append(Ps_sum)

max_val = 0
if K == 1:
    max_val = max(Ps)
    print((max_val + 1) / 2)
elif N == K:
    max_val = Ps_sum_list[-1]
    print((max_val + K) / 2)
else:
    for i in range(N - K):
        val = Ps_sum_list[i + K] - Ps_sum_list[i]
        if val > max_val:
            max_val = val
    print((max_val + K) / 2)

Measured memory_bytes: 25188
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H,P,L;
string S,T;
ll ans;
ll x[101010];
ll y[101010];
ll a[201010];
ll b[101010];
ll c[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;
bool flag[100];
vector<ll> Prime{2,3,5,7,11,13,17,19,23,29,31};


int main() {
	cin>>S;
	ll zero=0,one=0;
	rep(i,0,S.size()){
		if(S[i]=='0'){
			zero++;
		}else{
			one++;
		}
	}
	cout<<min(zero,one)*2<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define PP pair<P,P>
using namespace std;

ll dp[2005][2005];
ll sum[2005][2005];

int main(){
int n,m; cin >> n >> m;
  int s[n];
  int t[m];
  rep(i,n) cin >> s[i];
  rep(i,m) cin >> t[i]; 
  rep(i,n+1) sum[i][0]=0;
  rep(i,m+1) sum[0][i]=0;

  for(int i=1; i<=n; i++){
    for(int j=1; j<=m; j++){
        sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i-1][j-1];
        sum[i][j]%=MOD;
        if(sum[i][j]<0) sum[i][j]+=MOD;
        if(s[i-1]==t[j-1]) dp[i][j]=sum[i][j]+1;
        else dp[i][j]=0;
        dp[i][j]%=MOD;
    }
  }

  ll ans=1;
  rep(i,n+1)rep(j,m+1){
      ans+=dp[i][j];
      ans%=MOD;
  }
  cout << ans << endl;
return 0;
}



Measured memory_bytes: 62976
import java.util.Arrays;
import java.util.Scanner;

public  class Main  {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String b = sc.next();
		char p[] = b.toCharArray();
		if(p[0]=='A')System.out.println("T");
		if(p[0]=='T')System.out.println("A");
		if(p[0]=='C')System.out.println("G");
		if(p[0]=='G')System.out.println("C");
			
		
		
		
	}
}



Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
typedef long long LL;
typedef pair<int,int> pii;

const double pi = acos(-1.0);

void run_case() {
    int r; cin >> r;
    cout << 2 * pi * r;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(10);
    run_case();
    cout.flush();
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;

const ll mod = 1e9+7;
const ll inf = 1e16;

#define loop(i,m,n) for(ll i=m;i<n;i++)
#define vloop(it,x) for(auto it=x.begin(); it!=x.begin(); it++)
#define all(x) x.begin(),x.end()
#define debug(x) cout << #x <<":"<< x <<endl	
#define showll(x) printf("%lld\n",x)
#define test(t) ll t;cin >> t;while(t--)
#define showc(x) printf("%c\n",x)
#define read(x) cin >> x
#define yes printf("YES\n")
#define no printf("NO\n")
#define pb push_back

void fast(){
ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}

//////////////////////////////// - _ - \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

int main()
{
	fast();
	// debug(n);
	// showll(a);
	ll n,i;
	read(n);
	ll arr[n];
	loop(i,0,n)
	{
		cin >> arr[i];
	}
	
	ll mini[n];
	mini[0] = 0;
	mini[1] = abs(arr[1]-arr[0]);
	for(i=2;i<n;i++)
	{
		mini[i] = min( (abs(arr[i]-arr[i-1])+mini[i-1]) , (abs(arr[i]-arr[i-2])+mini[i-2]) ); 
	}
	showll(mini[n-1]);
}	


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9;

int dp[1<<5][41][21][21];
int dir[] = {-1,0,1};

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

  int W, H, N;
  cin >> W >> H >> N;
  int BB = (1<<N) - 1;
  PII s;
  cin >> s;
  --s.FF;
  --s.SS;
  vector<vector<PII>> bm(N);
  int init = 0;
  REP(i,N){
	int L;
	cin >> L;
	REP(j,L){
	  PII p;
	  cin >> p;
	  --p.FF;
	  --p.SS;
	  bm[i].EB(p);
	}
	if(bm[i][0] == s) init |= 1<<i;
  }

  auto isin = [W,H](const PII& p){ return 0 <= p.FF && p.FF < W && 0 <= p.SS && p.SS < H; };
  using D = pair<PII,PII>;
  fill((int*)dp, (int*)dp+(1<<5)*41*21*21, INF);
  queue<D> q;
  q.push(MP(MP(init,0),s));
  dp[init][0][s.FF][s.SS] = 0;
  int ans = -1;
  while(!q.empty()){
	auto dd = q.front();
	q.pop();
	if(dd.FF.FF == BB){
	  ans = dd.FF.SS;
	  break;
	}

	int ntime = dd.FF.SS+1;
	REP(dx,3) REP(dy,3){
	  PII np(dd.SS.FF+dir[dx], dd.SS.SS+dir[dy]);
	  if(!isin(np)) continue;
	  bool ok = true;
	  REP(i,N) if(bm[i].back() == np){ ok = false; break;}
	  if(!ok) continue;

	  bool bomb = false;
	  PII ns(dd.FF.FF, ntime);
	  REP(i,N){
		if(ns.FF>>i&1) continue;
		if(ntime >= SZ(bm[i])-1){
		  bomb = true;
		  break;
		}
		else if(bm[i][ntime] == np)
		  ns.FF |= 1<<i;
	  }
	  if(bomb) continue;

	  if(dp[ns.FF][ns.SS][np.FF][np.SS] == INF){
		dp[ns.FF][ns.SS][np.FF][np.SS] = ntime;
		q.push(MP(ns,np));
	  }
	}
  }
  
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 5496
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
  
int main() {
    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    for (int i = 0; i < M; i++) {
        cin >> B.at(i);
    }
    for (int i = 0; i < N - M + 1; i++) {

        for (int j = 0; j < N - M + 1; j++){

            for (int k = 0; k < M; k++) {
                bool T = false;
                for (int l = 0; l < M; l++) {
                    if (B.at(k).at(l) != A.at(k + i).at(l + j)) {
                        T = true;
                        break;
                    }
                }
                if (T) {
                    break;
                }
                if (k == M - 1) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
def num_of_area( line )
	n1 = 2
	n2 = 2 
	2.upto( line ){|n|
		n2 = n1 + n	
		n1 = n2
	}
	return n2
end

answers = Array.new
while line = $stdin.gets
	n = line.chomp.to_i
	answers << num_of_area( n )
end
answers.each{ |a| puts a }


Measured memory_bytes: 6080
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        m: usize,
        collapses: [(Usize1, Usize1); m],
    }

    let mut v = vec![];
    let initial_value = (n * (n - 1) / 2) as isize;
    v.push(initial_value);

    let mut uf = UnionFind::new(n);

    for collapse in collapses.iter().rev() {
        if uf.same(collapse.0, collapse.1) {
            v.push(*v.last().unwrap());
        } else {
            let sub = uf.size(collapse.0) * uf.size(collapse.1);
            v.push(*v.last().unwrap() - sub);
            uf.unite(collapse.0, collapse.1);
        }
    }

    for nv in v.iter().rev().skip(1) {
        println!("{}", nv);
    }
}

struct UnionFind {
    par: Vec<isize>,
    rank: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind {
            par: vec![-1; n],
            rank: vec![0; n],
        }
    }

    fn root(&mut self, x: usize) -> usize {
        if self.par[x] < 0 {
            x
        } else {
            self.par[x] = self.root(self.par[x] as usize) as isize;
            self.par[x] as usize
        }
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }

    fn size(&mut self, x: usize) -> isize {
        let root = self.root(x);
        self.par[root] * -1
    }

    fn unite(&mut self, mut x: usize, mut y: usize) {
        x = self.root(x);
        y = self.root(y);
        if x == y {
            return;
        }

        if self.rank[x] < self.rank[y] {
            self.par[y] += self.par[x];
            self.par[x] = y as isize;
        } else {
            self.par[x] += self.par[y];
            self.par[y] = x as isize;
            if self.rank[x] == self.rank[y] {
                self.rank[x] += 1;
            }
        }
    }
}


Measured memory_bytes: 7204
class Dice():
    def __init__(self, number):
        self.number = number
        
    def S(self):
        temp = self.number
        self.number = [temp[4], temp[0], temp[2], temp[3], temp[5], temp[1]]
    
    def N(self):
        temp = self.number
        self.number = [temp[1], temp[5], temp[2], temp[3], temp[0], temp[4]]
        
    def E(self):
        temp = self.number
        self.number = [temp[3], temp[1], temp[0], temp[5], temp[4], temp[2]]
        
    def W(self):
        temp = self.number
        self.number = [temp[2], temp[1], temp[5], temp[0], temp[4], temp[3]]
        
    def order(self, str):
        for ch in str:
            if ch == "S":
                self.S()
            elif ch == "N":
                self.N()
            elif ch == "E":
                self.E()
            else:
                self.W()
                

number = list(map(int, input().split()))
order = input()

dice = Dice(number)
dice.order(order)
print(dice.number[0])


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

int main() {
  int n; cin >> n;
  vector<int> a(n + 1);
  for (int i = 2; i <= n; i ++) {
    int tmp = i;
    for (int j = 2; j <= i; j ++) {
      while (tmp % j == 0) {
        a[j] ++;
        tmp /= j;
      }
    }
  }

  int b[5] = {}; // 2, 4, 14, 24, 74
  for (int i = 2; i <= n; i ++) {
    if (a[i] >=  2) b[0] ++;
    if (a[i] >=  4) b[1] ++;
    if (a[i] >= 14) b[2] ++;
    if (a[i] >= 24) b[3] ++;
    if (a[i] >= 74) b[4] ++;
  }

  LL ans = b[1] * max(0, b[1] - 1) * max(0, b[0] - 2) / 2 + b[2] * max(0, b[1] - 1) + b[3] * max(0, b[0] - 1) + b[4];
  cout << ans << endl;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;
int N;

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

  std::cin >> S;

  N = S.size();

  bool ok = true;

  for(int i=0;i<N;++i){
      if(S[i] != S[N-1-i]){
          ok = false;
          break;
      }
  }

  for(int i=0;i<N/2;++i){
      if(S[i] != S[N/2-1-i]){
          ok = false;
          break;
      }
  }

  if(ok){
      std::cout << "Yes" << std::endl;
  }else{
      std::cout << "No" << std::endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#define A 100
int main(){
  int i,j,n,flag,hozon,count=0;
  int sort[A];
  int minj;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&sort[i]);
  }

  for(i=0;i<=n-1;i++){
    flag=0;
    minj = i;
    for(j=i;j<=n-1;j++){
      if(sort[j]<sort[minj]){
	minj = j;
	flag=1;
      }
    }
    if(flag==1){
      hozon = sort[i];
      sort[i] = sort[minj];
      sort[minj] = hozon;
      count++;
    }
  }
  
  for(i=0;i<=n-1;i++){
    if(i==n-1){
      printf("%d",sort[i]);
    }
    else printf("%d ",sort[i]);
  }
  printf("\n%d\n",count);

  return 0;
}
  
  



Measured memory_bytes: 2140