akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a += b;
	a %= MOD;
}

int segtree[1212121][2],m;

bool segflag[1212121];

void eval(int i, int l, int r){
	if(segflag[i]){
		segtree[i][0] += segtree[i][1] * (r-l);
		if(r-l>1){
			segtree[i*2+1][1] += segtree[i][1];
			segflag[i*2+1] = true;
			segtree[i*2+2][1] += segtree[i][1];
			segflag[i*2+2] = true;
		}
		segtree[i][1] = 0;
		segflag[i] = false;
	}
}

void update(int a, int b, int i=0, int l=0, int r=m){
	eval(i,l,r);
	if(r<=a || b<=l){
		return;
	}
	if(a<=l && r<=b){
		++segtree[i][1];
		segflag[i] = true;
		eval(i,l,r);
	}else{
		update(a,b,i*2+1,l,(l+r)/2);
		update(a,b,i*2+2,(l+r)/2,r);
		segtree[i][0] += segtree[i*2+1][0] + segtree[i*2+2][0];
	}
}

int query(int a, int b, int i=0, int l=0, int r=m){
	int lv,rv;
	eval(i,l,r);
	if(r<=a || b<=l){
		return 0;
	}
	if(a<=l && r<=b){
		return segtree[i][0];
	}else{
		lv = query(a,b,i*2+1,l,(l+r)/2);
		rv = query(a,b,i*2+2,(l+r)/2,r);
		return (lv+rv);
	}
}

vector<P> v[300300];

int main(void){
	int n,i,d,l,r,ans;
	cin >> n >> m; ++m;
	for(i=0; i<n; ++i){
		cin >> l >> r; ++r;
		v[r-l].push_back(P(l,r));
	}
	for(d=1; d<m; ++d){
		ans = n;
		for(i=d; i<m; i+=d){
			ans += query(i,i+1);
			// cout << d << " " << i << " " << query(i,i+1) << endl;
		}
		for(i=(v[d].l_ength()-1); i>=0; --i){
			--n;
			update(v[d][i].first,v[d][i].second);
			// cout << v[d][i].first << " " << v[d][i].second << endl;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 17536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int n;
    cin >> n;
    int p[n];
    for(int i=0;i<n;++i) cin >> p[i];
    int ans=0;
    for(int i=1;i<n-1;++i) {
        if(p[i]<p[i-1] && p[i]>p[i+1]) ++ans;
        else if(p[i]>p[i-1] && p[i]<p[i+1]) ++ans;
    }
    cout << ans << endl;
}



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

using ll = long long;

const int M = 1e9 + 7;

ll mul(ll a, ll b) {
    return a * b % M;
}

int main(int argc, char *argv[])
{
    int N;
    cin >> N;
    vector<ll> arr(N);
    for (auto& v : arr) {
        cin >> v;
    }
    ll res = 0;
    for (int b = 0; b < 63; b++) {
        ll v = 1LL << b;
        ll n = 0;
        for (int i = 0; i < N; i++) {
            if (arr[i] & v) {
                n++;
            }
        }
        res += mul(mul(n, N - n), v % M);
        res %= M;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int a[27];
int main()
{
    long long int i,j,k,z,t,x,y,n;
    map<long long int,long long int>m;
    vector<long long int>v;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        m[x]++;
        if(m[x]>1)
        {
            v.push_back(x);
            m[x]=0;
        }

    }
    sort(v.begin(),v.end(),greater<int>());
    if(v.size()<2)
        cout<<0<<endl;
    else
    {
        x=v[0]*v[1];
        cout<<x<<endl;
    }
}

Measured memory_bytes: 9772
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<std::vector<int>> edg(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; std::cin >> a >> b;
        a--; b--;
        edg[a].push_back(b);
        edg[b].push_back(a);
    }
    std::vector<int> color(n);
    auto dfs = [&](
            const auto &self, int pos=0, int prev=-1, bool col=false) -> void {
        color[pos] = col;
        for (int c : edg[pos]) {
            if (c == prev) continue;
            self(self, c, pos, !col);
        }
    };
    dfs(dfs);
    int cnt0 = 0, cnt1 = 0;
    for (int i = 0; i < n; i++) (color[i] ? cnt1 : cnt0)++;
    std::vector<int> ans(n, -1);
    if (cnt0 <= n / 3) {
        int pos = 3;
        for (int i = 0; i < n; i++) {
            if (pos > n) break;
            if (!color[i]) {
                ans[i] = pos;
                pos += 3;
            }
        }
        int poso = 1;
        for (int i = 0; i < n; i++) {
            if (ans[i] != -1) continue;
            if (pos <= n) {
                ans[i] = pos;
                pos += 3;
            }
            else {
                ans[i] = poso;
                poso += poso % 3;
            }
        }
    }
    else if (cnt1 <= n / 3) {
        int pos = 3;
        for (int i = 0; i < n; i++) {
            if (pos > n) break;
            if (color[i]) {
                ans[i] = pos;
                pos += 3;
            }
        }
        int poso = 1;
        for (int i = 0; i < n; i++) {
            if (ans[i] != -1) continue;
            if (pos <= n) {
                ans[i] = pos;
                pos += 3;
            }
            else {
                ans[i] = poso;
                poso += poso % 3;
            }
        }
    }
    else {
        int pos1 = 1, pos2 = 2;
        for (int i = 0; i < n; i++) {
            int &pos = color[i] ? pos1 : pos2;
            if (pos > n) continue;
            ans[i] = pos;
            pos += 3;
        }
        int pos = 3;
        for (int i = 0; i < n; i++) {
            if (ans[i] != -1) continue;
            ans[i] = pos;
            pos += 3;
        }
    }
    for (int i = 0; i < n; i++) std::cout << ans[i] << " \n"[i == n - 1];
    return 0;
}


Measured memory_bytes: 14836
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define all(arr) (arr).begin(), (arr).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1ll << 59;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

/*<ここから>***********************************************************/



int main()
{
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	double sml = -1;
	int t, s;

	for (int i = 0; i <= 30; i++) {
		for (int j = 0; j <= 30; j++) {
			for (int k = 0; k <= 100; k++) {
				for (int l = 0; l <= 100; l++) {

					int wtot = 100 * A * i + 100 * B * j;
					int stot = k * C + l * D;
					int tot = wtot + stot;

					if (wtot > 0 && tot <= F) {

						if (wtot / 100 * E >= stot) {

							double dns = 100 * stot / (double)tot;
							if (dns > sml) {
								sml = dns;
								t = tot;
								s = k * C + l * D;
							}
						}
					}
				}
			}
		}
	}
	

	cout << t << " " << s << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>                          
using namespace std;    
string s,t;
int x,y,ans;                             
int main(){	
	cin>>s;
	cin>>t;
	if(s.size()!=t.size()) {cout<<"No";return 0;}
	for(int i=0;i<s.size();i++)
	{
		for(int j=0;j<t.size();j++)
		{
			ans=0;
			x=i;
			y=j;
			while(s[x]==t[y])
			{
				ans++;
				x=(x+1)%s.size();
				y=(y+1)%t.size();
				if(ans==s.size()) {cout<<"Yes";return 0;}
			}
		}  
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List

getLineRepeat :: Int -> IO [String]
getLineRepeat times = replicateM times getLine

main = do
    first <- getLine
    d <- getLineRepeat 3
    let k = read $ (words first) !! 3 :: Int
    let rev = flip compare
    let cakeA = map read $ words (d !! 0) :: [Integer]
    let cakeB = map read $ words (d !! 1) :: [Integer]
    let cakeC = map read $ words (d !! 2) :: [Integer]
    let sum1 = take k $ sortBy rev [a + b | a <- cakeA, b <- cakeB]
    let sum = take k $ sortBy rev [ab + c | ab <- sum1, c <- cakeC]
    forM_ sum $ putStrLn . show 


Measured memory_bytes: 444796
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {

	static int ans[];
	static int count = 0;

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {

			String str[] = br.readLine().split(" ");

			int n = Integer.parseInt(str[0]);
			int m = Integer.parseInt(str[1]);

			if (n == 0 && m == 0)
				break;

			ans = new int[n];
			Arrays.fill(ans, 0);
			count = 0;

			ArrayList<ArrayList<Edge>> edge = new ArrayList<>();

			for (int i = 0; i < n; i++) {
				edge.add(new ArrayList<>());
			}

			for (int i = 0; i < m; i++) {
				str = br.readLine().split(" ");

				int s = Integer.parseInt(str[0]) - 1;
				int t = Integer.parseInt(str[1]) - 1;
				int c = Integer.parseInt(str[2]);

				edge.get(s).add(new Edge(t, c));
				edge.get(t).add(new Edge(s, c));
			}

			prime(edge, n);
			Arrays.sort(ans);

			System.out.println(ans[n / 2]);
		}
	}

	static void prime(ArrayList<ArrayList<Edge>> edges, int n) {
		boolean[] done = new boolean[n];

		Queue<Edge> q = new PriorityQueue<Edge>();
		q.add(new Edge(0, 0)); // 0から(ダミー)

		double totalCost = 0;
		while (!q.isEmpty()) {
			Edge e = q.poll(); // 最小コストの辺を取り出す
			if (done[e.to]) {
				continue;
			}

			done[e.to] = true; // 訪問済にする
			ans[count++] = e.cost;
			q.addAll(edges.get(e.to)); // 隣接しているすべての辺を追加
		}
	}
}

class Edge implements Comparable<Edge> {
	int to;
	int cost;

	public Edge(int to, int cost) {
		this.to = to;
		this.cost = cost;

	}

	@Override
	public int compareTo(Edge e) {
		return this.cost - e.cost;
	}
}



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

int main() {
  int n;cin>>n;
  int an[n];rep(i,n)cin>>an[i];
  ll cost_min = 1001001001;
  for (int k=-100;k<=100;k++) {
    ll cost=0;
    rep(i,n) cost+= pow(an[i]-k, 2);
    cost_min=min(cost, cost_min);
  }
  cout << cost_min;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
 
using namespace std;
 
int main(){
  int N, ans;
  cin >> N;

  ans = ceil(N / 1.08);
  if(N == floor(ans * 1.08)){
    printf("%d\n",ans);
  }else{
    printf(":(\n");
  }
  
}


Measured memory_bytes: 3708
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

# A
"""
a, b = map(int, input().split())
sum = a-1
if b >= a:
    sum += 1
print(sum)
"""
# B
"""
a,b,c = map(int, input().split())
k = int(input())
sum = a+b+c+max(a,b,c)*(2**k-1)
print(sum)
"""
# C
"""
def check(y,x):
    if y-1 < 0:
        if x-1 < 0:
            move_x = [1,0]
            move_y = [0,1]
        if x+1 >= w:
            move_x = [-1,0]
            move_y = [0,1]
        else:
            move_x = [1,-1,0]
            move_y = [0,0,1]
    if y+1 >= h:
        if x-1 < 0:
            move_x = [1,0]
            move_y = [0,-1]
        if x+1 >= w:
            move_x = [-1,0]
            move_y = [0,-1]
        else:
            move_x = [1,-1,0]
            move_y = [0,0,-1]
    else:
        if x-1 < 0:
            move_x = [1,0,0]
            move_y = [0,1,-1]
        if x+1 >= w:
            move_x = [-1,0,0]
            move_y = [0,1,-1]
        else:
            move_x = [1,-1,0,0]
            move_y = [0,0,1,-1]
    for i in range(len(move_x)):
        if stage[y+move_y[i]][x+move_x[i]] == "#":
            return True
    return False
h,w = map(int, input().split())
stage = [input() for i in range(h)]
for i in range(h):
    for j in range(w):
        if stage[i][j] == "#":
            if not check(i,j):
                print("No")
                quit()
print("Yes")
"""
# D
n = I()
ans = [11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381]
print(*ans[:n])


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

int main() {
	int x,n;
	cin >> x >> n;
	if (!n)
	{
		cout << x << endl;
		return 0;
	}
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	sort(v.begin(), v.end());
	int start = 0, end = n - 1;
	if (x < v[start] || x>v[end])
	{
		cout << x << endl;
		return 0;
	}
	if (x == v[start])
	{
		cout << (v[start]-1)<< endl;
		return 0;
	}
	int i;
	for (i = 0; i < n; ++i)
		if (v[i] == x)
			break;
	if (i == n)
	{
		cout << x << endl;
		return 0;
	}
	int j = i, k = i;
	while (j >= 0 && k <= end)
	{
		if (j-1>=0 &&  abs(v[j] - v[j -1]) > 1)
		{
			cout << (v[j] - 1);
			return 0;
		}
		if (k+1<=end &&  abs(v[k] - v[k + 1]) > 1)
		{
			cout << (v[k] + 1);
			return 0;
		}
		--j;
		++k;
	}
	if (abs(x - (v[0] - 1)) > abs(x - (v[end] + 1)))
	{
		cout << (v[end] + 1);
		return 0;
	}
	cout << (v[0] - 1) << endl;
	return 0;
}

Measured memory_bytes: 3636
n = int(input())
a = [0]*n
xy = [0]*n
for i in range(n):
    a[i] = int(input())
    xy[i] = [list(map(int, input().split())) for _ in range(a[i])]

ans = 0
for i in range(2**n):
    flag = True
    for j in range(n):
        if i >> j & 1 == 1:  # 右からｊ番目の人は正直もの
            for k in range(a[j]):
                if xy[j][k][1] == 1 and i >> (xy[j][k][0]-1) & 1 != 1:
                    flag = False
                    break
                elif xy[j][k][1] == 0 and i >> (xy[j][k][0]-1) & 1 != 0:
                    flag = False
                    break
            else:
                continue
            break
    if flag and ans < str(bin(i)).count("1"):
        ans = str(bin(i)).count("1")


print(ans)

Measured memory_bytes: 45296
#!/usr/bin/env python3
#ABC74 C

a,b,c,d,e,f = map(int,input().split())

s = f//(100*a)
t = f//(100*b)
u = f//c
v = f//d

concentration = 0
solution = 0
suger = 0
for A in range(s+1)[::-1]:
    for B in range(t+1)[::-1]:
        for C in range(u+1)[::-1]:
            for D in range(v+1)[::-1]:
                if 100*a*A + 100*b*B + c*C + d*D <= f:
                    if (a*A+b*B)*e >= (c*C + d*D):
                        if 100*a*A + 100*b*B + c*C + d*D != 0:
                            if concentration < (c*C + d*D)/(100*a*A + 100*b*B + c*C + d*D):
                                concentration = (c*C + d*D)/(100*a*A + 100*b*B + c*C + d*D)
                                solution = 100*a*A + 100*b*B + c*C + d*D
                                suger = c*C + d*D
if solution == 0:
    solution = 100*a
print(solution,suger)


Measured memory_bytes: 42860
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define ld long double
#define mkp make_pair
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e9+7;
const ll INF = (ll)3e9+1;

bool ok=0;
ll n, m, a, b, c;
ll v[100001];
vector< pair<ll, ll> > adj[100001];

void dfs(ll cur)
{
    for(auto nxt : adj[cur])
    {
        if(ok) return;
        if(v[nxt.F]==INF)
        {
            v[nxt.F] = v[cur] + nxt.S;
            dfs(nxt.F);
        }
        else if(v[nxt.F]-v[cur]!=nxt.S)
        {
            cout << "No";
            ok = 1;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("D.txt", "r", stdin);
    #endif
    cin >> n >> m;
    for(int i=1; i<=n; i++) v[i] = INF;
    for(int i=0; i<m; i++)
    {
        cin >> a >> b >> c;
        adj[a].pb({b, c});
        adj[b].pb({a, -c});
    }
    for(int i=1; i<=n; i++)
    {
        if(v[i]==INF)
        {
            v[i] = 0;
            dfs(i);
        }
    }
    if(!ok) cout << "Yes";
}



Measured memory_bytes: 16512
import java.util.*;
 
 
class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        int abcd[] = new int[4];
        for(int i=0; i<4; i++){
            abcd[i] = Integer.valueOf(String.valueOf(s.charAt(i)));
        }
        int n = 3;
        String pm[] = new String[3];
        for(int i=0; i<3;i++){
            pm[i] = "";
        }

        for(int i = 0;i < Math.pow(2,n);i++) {
            int sum = abcd[0];
            for(int j=0; j<n;j++){
                if((1 & i>>j) == 1) {
                    sum += abcd[j+1];
                    pm[j] = "+";
                } else {
                    sum -= abcd[j+1];
                    pm[j] = "-";
                }
            }
            if(sum==7){
                System.out.print(abcd[0]);
                for(int k=0; k<3; k++){
                    System.out.print(pm[k]);
                    System.out.print(abcd[k+1]);
                }
                System.out.println("=7");
                return;
            }
        }

    }
}

Measured memory_bytes: 21844
def color(s):
    k = 0
    for i in range(len(s)-1):
        if s[i+1]==s[i]:
            if s[i]=='0':
                s[i+1]='1'
            if s[i]=='1':
                s[i+1]='0'
            k = k+1
    return k
    
s=list(input())
print(color(s))

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int solver(int N, int K, vector<int> Vec){
    deque<int> V;
    rep(i, N){
        V.push_back(Vec[i]);
    }

    int ans = 0;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j + i <= K; j++){
            //i番目まで左から、j番目まで右から取り出す　残りは詰めるパート
            deque<int> tmp = V;
            vector<int> t_ans;
            // cout << i << " " << j << endl;
            rep(l, i){
                if(tmp.size() == 0)break;
                t_ans.push_back(tmp[0]);
                tmp.pop_front();
            }
            rep(r, j){
                if(tmp.size() == 0)break;
                t_ans.push_back(tmp[tmp.size() - 1]);
                tmp.pop_back();
            }
            sort(all(t_ans));
            int loop = min(K - i - j, (int)t_ans.size());
            rep(k, loop){
                if(t_ans[k] < 0)t_ans[k] = 0;
            }
            int sum = 0;
            rep(k, t_ans.size())sum += t_ans[k];
            ans = max(ans, sum);
        }
    }
    return ans;
}


int main(){
    int N, K; cin >> N >> K;
    vector<int> V(N);
    rep(i, N) cin >> V[i];
    cout << solver(N, K, V) << endl;
}

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

using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define vi vector <int>
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define tiii tuple <int,int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(v) v.rbegin(),v.rend()
#define endl '\n'
#define matrix vector <vector <int> >
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 500006
#define mod 1000000007
#define mod2 998244353
#define inf 1e17

int dp[101][100001];
int w[101],v[101];
int n,W;

// int solve(int id,int val)
// {
//     if(val<=0)
//         return 0;
//     if(id<0)
//         return inf;
    
//     int &ans=dp[id][val];
//     if(ans!=-1)
//         return ans;
//     //ans=0;
//     ans=min(solve(id-1,val),w[id]+solve(id-1,val-v[id]));
//     return ans;


// }


int32_t main()  
{
    boost
    // #ifndef ONLINE_JUDGE 
    // NAYAN
    // #endif
    
    

    cin >> n >> W;

    
    //memset(dp,-1,sizeof dp);
    int i,j;
    
    for(i=1;i<=n;i++)
    {
        cin >> w[i] >> v[i];
    }


    for(i=0;i<101;i++)
    {
        for(j=0;j<100001;j++)
        {
            dp[i][j]=inf;
        }
    }


    dp[0][0]=0;

    for(i=1;i<=n;i++)
    {
        for(j=100000;j>=0;j--)
        {
            if(j>=v[i])
            {
                dp[i][j]=min(dp[i-1][j],w[i]+dp[i-1][j-v[i]]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }

    for(i=100000;i>=0;i--)
    {
        if(dp[n][i]<=W)
        {
            cout << i << endl;
            return 0;
        }
    }

   


}

Measured memory_bytes: 79232
// https://atcoder.jp/contests/abc133/tasks/abc133_b
#include <bits/stdc++.h>
using namespace std;

int main(void){
  int N, D;
  cin >> N >> D;
  int X[N][D];
  for (int i = 0; i < N; i++){
    for (int j = 0; j < D; j++){
      cin >> X[i][j];
    }
  }

  int count = 0;
  for (int i = 0; i < N-1; i++){
    for (int j = i+1; j < N; j++){
      double d = 0;
      for (int k = 0; k < D; k++){
        d += pow(X[i][k] - X[j][k], 2);
      }
      d = sqrt(d);
      if (ceil(d) == floor(d)){
        count++;
      }
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
/*
[ ( ^ _ ^ ) ]
*/

// problem: atc/abc161_a

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;


    void solve(InputReader in, PrintWriter out) throws IOException {
        int x = in.nextInt();
        int y = in.nextInt();
        int z = in.nextInt();
        out.println(z+" "+x+" "+y);
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 20564
/*
** author:mahmoud magdy
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"

inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m;
    cin>>m;
    return m;
}
void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
int a[100005];
int dp[100005];
int n;
int solve(int i){
 if(i>=n)return 1e9;
 if(i==n-1)
    return 0;
 if(dp[i]!=-1)
      return dp[i];
 int ch1=abs(a[i]-a[i+1])+solve(i+1);
 int ch2=abs(a[i]-a[i+2])+solve(i+2);
 return dp[i]=min(ch1,ch2);
}
int main()
{
    fast();
    n=D();
    for(int i=0;i<n;++i){
        a[i]=D();
    }
    memset(dp,-1,sizeof dp);
    cout<<solve(0)<<endl;
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    pair<int, int> d[n];

    if (s[0] == 'E')
        d[0].first = 1;
    else
        d[0].second = 1;

    rep(i, n - 1) {
        d[i + 1].first += d[i].first;
        d[i + 1].second += d[i].second;

        if (s[i + 1] == 'E')
            d[i + 1].first += 1;
        else
            d[i + 1].second += 1;
    }

    int w = count(s.cbegin(), s.cend(), 'W');
    int e = count(s.cbegin(), s.cend(), 'E');

    int ans = 1e6;
    for (int i = 0; i < n; i++) {
        int lw = (s[i] == 'W') ? d[i].second - 1 : d[i].second;
        int re = e - d[i].first;
        ans = min(ans, lw + re);
    }

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


Measured memory_bytes: 2948
//#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e4 + 100;
ll n,a,b,c,d;

int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
    for (ll i = 0; i < n; ++i)
    {
        if (i * c - (n - i - 1) * d <= b - a &&
            i * d - (n - i - 1) * c >= b - a)
        {
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,ww;
int w[101],v[101];
ll dp[100001];
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>ww;
	rep(i,n)
	cin>>w[i]>>v[i];
	rep(i,100001)
	dp[i]=1e11;
	dp[0]=0;
	rep(i,n)
	for(int j=100001;j>=v[i];j--)
	dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
	int ans=0;
	rep(i,100001)
	if(dp[i]<=ww)
	ans=i;
	cout<<ans;
	re 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <utility>
#include <set>
#include <vector>
#include <functional>
#include <map>
#include <queue>
using namespace std;
int main()
{
  long long M,N;
  cin>>M>>N;
  cout<<max((M-2)*(N-2),-(M-2)*(N-2))<<endl; 
  //system("pause");
  return 0;
}

Measured memory_bytes: 256
s=input()
ans=1
n=len(s)
for i in range(len(s)//2):
  if s[i]!=s[len(s)-1-i]:
    ans=0
s1=s[:(n-1)//2]
for i in range(len(s1)//2):
  if s1[i]!=s1[len(s1)-1-i]:
    ans=0
s2=s[(n+3)//2-1:]
for i in range(len(s2)//2):
  if s2[i]!=s2[len(s2)-1-i]:
    ans=0

print("YNeos"[1-ans::2])

Measured memory_bytes: 38256
N,M=map(int,input().split())
ans=1
mod=10**9+7
if N>M+1 or M>N+1:
  print(0)
  exit()
for i in range(1,N+1):
  ans*=i
  ans%=mod
for j in range(1,M+1):
  ans*=j
  ans%=mod
if N==M:
  ans=ans*2%mod
print(ans)

Measured memory_bytes: 9060
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <limits>
#include <bits/stdc++.h>
using namespace std;
int main(){
    string moji;
    cin >> moji;
    int i=0;
    int count=0;
    int MAX=0;
    while(i<=moji.size()){
        if(moji[i]=='A' ||moji[i]=='C'|| moji[i]=='G' || moji[i]=='T'){
            count++;
            i++;
        }else{
            MAX=max(MAX,count);
            count=0;
            i++;
        }
        
    }
    cout << MAX <<endl;
}


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

int main()
{
	string s;
	int cnt = 0;
	cin >> s;
	char c = s[0];
	for (int i = 1; i < s.size(); i++) {
		if (s[i] != c) {
			cnt++;
			c = s[i];
		}
	}

	cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <queue>

int main(void){

  bool maze[52][52] = {};

  int h, w;
  std::cin >> h >> w;

  for(int i=0; i<52; i++){
    maze[0][i] = true; // wall
    maze[w+1][i] = true;
    maze[i][0] = true;
    maze[i][h+1] = true;
  }

  int count=0;
  for(int i=1; i<=h; i++){
    for(int j=1; j<=w; j++){
      char temp;
      std::cin >> temp;
      if(temp=='#'){
        maze[j][i]=true;
        count++;
      }
    }
  }

  /**for(int i=0; i<=h+1; i++){
    for(int j=0; j<=w+1; j++){
      std::cout << (maze[j][i]?"#":" ");
    }
    std::cout << std::endl;
    }**/

  bool visited[52][52] = {};
  visited[1][1] = true;

  std::queue<std::vector<int> > q;
  q.push(std::vector<int>{1,1,1});
  while(!q.empty()){
    std::vector<int> now = q.front();
    q.pop();

    //std::cout << now[0] << " " << now[1] << " " << now[2] << std::endl;

    if(now[0] == w && now[1] == h){
      std::cout << (h*w-now[2]-count) << std::endl;
      return 0;
    }

    if(!maze[now[0]][now[1]+1] && !visited[now[0]][now[1]+1]){
      visited[now[0]][now[1]+1]=true;
      q.push(std::vector<int>{now[0], now[1]+1, now[2]+1});
    }
    if(!maze[now[0]][now[1]-1] && !visited[now[0]][now[1]-1]){
      visited[now[0]][now[1]-1]=true;
      q.push(std::vector<int>{now[0], now[1]-1, now[2]+1});
    }
    if(!maze[now[0]-1][now[1]] && !visited[now[0]-1][now[1]]){
      visited[now[0]-1][now[1]]=true;
      q.push(std::vector<int>{now[0]-1, now[1], now[2]+1});
    }
    if(!maze[now[0]+1][now[1]] && !visited[now[0]+1][now[1]]){
      visited[now[0]+1][now[1]]=true;
      q.push(std::vector<int>{now[0]+1, now[1], now[2]+1});
    }
  }

  std::cout << -1 << std::endl;
  return 0;
}

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

using namespace std;

const double EPS=1e-8;
const double INF=1e9;

typedef complex<double>Point;

#define EQ(a,b) (fabs((a)-(b))<EPS)
#define EQV(a,b) (abs((a)-(b))<EPS)
struct Segment{
    Point p1,p2;
    Segment(Point p1=Point(),Point p2=Point()):p1(p1),p2(p2){}
};

typedef Segment Line;

struct Circle{
    Point c;
    double r;
    Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

typedef vector<Point>Polygon;

double dot(Point a,Point b){
    return real(a)*real(b)+imag(a)*imag(b);
}

double cross(Point a,Point b){
    return real(a)*imag(b)-imag(a)*real(b);
}

bool isOrthogonal(Point a,Point b){
    return EQ(dot(a,b),0.0);
}

bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
    return isOrthogonal(a1-a2,b1-b2);
}

bool isOrthogonal(Line l1,Line l2){
    return isOrthogonal(l1.p2-l1.p1,l2.p2-l2.p1);
}

bool isParallel(Point a,Point b){
    return EQ(cross(a,b),0.0);
}

bool isParallel(Point a1,Point a2,Point b1,Point b2){
    return isParallel(a1-a2,b1-b2);
}

bool isParallel(Line l1,Line l2){
    return isParallel(l1.p2-l1.p1,l2.p2-l2.p1);
}

Point project(Line l,Point p){
    Point base=l.p2-l.p1;
    double r=dot(p-l.p1,base)/norm(base);
    return l.p1+base*r;
}

Point reflect(Line l,Point p){
    return p+(project(l,p)-p)*2.0;
}
int main(){
    Line L;
    scanf("%lf%lf",&L.p1.real(),&L.p1.imag());
    scanf("%lf%lf",&L.p2.real(),&L.p2.imag());

    int N;
    scanf("%d",&N);
    while(N--){
        Point P;
        scanf("%lf%lf",&P.real(),&P.imag());
        Point prj=project(L,P);
        printf("%.8f %.8f\n",prj.real(),prj.imag());
    }

    return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

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


template<class T>
bool chmax(T &a, const T &b) { if (a < b) { return b; } return a; }

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

int main() {
    ll n; 
    cin >> n;
    
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    ll ans = 0; 
    for (ll i = n-1; i >= 0; i--) {
        if ((a[i]+ans)%b[i] != 0)
        {
            ans += b[i] - (a[i]+ans)%b[i];
        }
        // cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, x;
    cin>>n;
    int cnt = 0;
    for(int i=1; i<=n; i++)
    {
        cin>>x;
        if(i!=x)
            cnt++;
    }
    if(cnt<=2)
        cout<<"YES\n";
    else
        cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
#define mod 1000000007
#define maxn 200005
 
typedef pair<ll, ll> P;
 
//bool cmp(P p1, P p2) { return p1.first == p2.first ? p1.second > p2.second : p1.first < p2.first; }
 
ll n, x, d;
map<int, vector<P>> mp;
 
int main()
{
    cin >> n >> x >> d;
    if (d == 0)
    {
        cout << ((x == 0) ? 1 : n + 1) << endl;
        return 0;
    }
    if (d < 0)
        x = -x, d = -d;
    for (ll i = 0; i <= n; i++)
    {
        ll gp = i * x % d;
        ll l = i * x + i * (i - 1) / 2 * d;
        ll r = i * x + (i * n - i * (i + 1) / 2) * d;
        mp[gp].push_back(P((l - gp) / d, (r - gp) / d));
    }
    ll ans = 0;
    for (auto iter = mp.begin(); iter != mp.end(); iter++)
    {
        vector<P> &v = iter->second;
        if (v.empty())
            continue;
        sort(v.begin(), v.end());
        ll l = v[0].first;
        ll r = v[0].second;
        for (int j = 1; j <= v.size(); j++)
        {
            if (j == v.size())
            {
                ans += (r - l + 1);
                break;
            }
            if (v[j].first > r)
            {
                ans += (r - l + 1);
                l = v[j].first;
                r = v[j].second;
            }
            else
                r = max(r, v[j].second);
        }
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 22144
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define MAX 10000
int sosu[MAX]={1,1,0};
int main(){
	ll out[1000]={0};
	out[999]=1;
	loop(i,2,1500)if(sosu[i]==0){
		for(int j=i;j<MAX;j+=i)sosu[j]=i;
		ll tmp=0;
		for(int j=999;j>=1;j--){
			out[j]=out[j]*i+tmp;
			tmp=out[j]/(int)1e9;
			out[j]%=(int)1e9;
		}
	}
	out[999]+=2;
	bool h=false;	
	rep(i,1000)if(out[i]||h){
		if(h)printf("%09d",out[i]);
		else printf("%d",out[i]);
		h=true;
	}
	cout<<endl;
	int n;cin>>n;
	rep(i,n)cout<<sosu[i+2]<<endl;
}

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

ll N, M, minv = 200000, ans=0;

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        int a;
        cin >> a;
        minv = min(minv, a);
        if(a<=minv) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
x,n=map(int,input().split())
if n==0:
  p=set()
else:
  p=set(map(int,input().split()))

for i in range(1000):
  if x-i not in p:
    print(x-i)
    break
  elif x+i not in p:
    print(x+i)
    break


Measured memory_bytes: 9020
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

struct node
{
	int key;
	node *left;
	node *right;
};

node nil;
node *root = &nil;

void init()
{
	nil.left = &nil;
	nil.right = &nil;
}

void insert(int key)
{
	node *newNode = (node *)malloc(sizeof(node));
	newNode->key = key;
	newNode->left = &nil;
	newNode->right = &nil;

	node *tmp = &nil;
	node *iter = root;
	while(iter != &nil)
	{
		tmp = iter;

		if (newNode->key < iter->key)
		{
			iter = iter->left;
		}
		else
		{
			iter = iter->right;
		}
	}
	//empty tree
	if (tmp == &nil)
		root = newNode;
	else if (newNode->key < tmp->key)
		tmp->left = newNode;
	else
		tmp->right = newNode;
}

void inorder(node *t)
{
	if (t == &nil)
		return;
	inorder(t->left);
	cout << " " << t->key;
	inorder(t->right);
}

void preorder(node *t)
{
	if (t == &nil)
		return;
	cout << " " << t->key;
	preorder(t->left);
	preorder(t->right);
}

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

	for (int i = 0; i < n; i++)
	{
		string cmd;
		cin >> cmd;
		if (cmd == "insert")
		{
			int key;
			cin >> key;
			insert(key);
		}
		else if(cmd == "print"){
			inorder(root);
			cout << endl;

			preorder(root);
			cout << endl;
		}
	}
}


Measured memory_bytes: 18700
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    string S;
    string Sb="";
    string Se="";
    int Q;
    bool rev=false;
    cin >>S>>Q;
    REP(i,Q){
        int a;
        cin >>a;
        if(a==1){
            rev = !rev;
        }
        else{
            int b;
            char c;
            cin >>b>>c;
            if((b==1 &&rev==false)||(b==2 &&rev==true)){
                Sb+=c;
            }
            if((b==1 &&rev==true)||(b==2 &&rev==false)){
                Se+=c;
            }
        }
    }
    reverse(Sb.begin(),Sb.end());
    string ans =Sb+S+Se;
    if(rev){
        reverse(ans.begin(),ans.end());
    }
    cout << ans <<endl;
}

Measured memory_bytes: 1348
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
int a[100005]={0};
int main()
{
 ll n,m;
 cin>>n;
 for(int i=0;i<n;i++)
 {
 	 cin>>a[i];
 }
 sort(a,a+n);
 ll sum=0;
  for(int i=0;i<n-1;i++)
   sum+=a[i];
   if(sum>a[n-1])
    printf("Yes\n");
    else
    printf("No\n");
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=3005,INF=1<<29;
vector<string> S(50);
int color[MAX][2];
int H,W;
vector<int> dx={-1,0,1,0},dy={0,1,0,-1};
void DFS(int u,int k){
    if(color[u][k]) return;
    color[u][k]=1;
    
    for(int i=0;i<4;i++){
        int a=u/W,b=u%W;
        
        if(0<=a+dx[i]&&a+dx[i]<H&&0<=b+dy[i]&&b+dy[i]<W){
            if(S[a+dx[i]][b+dy[i]]=='.') DFS((a+dx[i])*W+b+dy[i],k);
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        cin>>W>>H;
        if(H+W==0) break;
        memset(color,0,sizeof(color));
        
        for(int i=0;i<H;i++) cin>>S[i];
        
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(S[i][j]=='B') DFS(i*W+j,0);
                if(S[i][j]=='W') DFS(i*W+j,1);
            }
        }
        
        int ans1=0,ans2=0;
        
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(color[i*W+j][0]&&color[i*W+j][1]==0&&S[i][j]!='B') ans1++;
                if(color[i*W+j][1]&&color[i*W+j][0]==0&&S[i][j]!='W') ans2++;
            }
        }
        
        cout<<ans1<<" "<<ans2<<endl;
    }
    
}



Measured memory_bytes: 3248
"use strict";

function Main(input) {
	input = input.split(" ");
    const a = parseInt(input[0], 10);
    let b = parseInt(input[1], 10);
    const c = parseInt(input[2], 10);

    let answer = 0;
    for (let i = 0; i < c; i++) {
        if (a > b) {
            break;
        } else {
            answer++;
            b -= a;
        }
    }

    console.log(answer);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<VL> VVL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    ll x,y,n,m,h,k,w,max=-10000000,min=2020202021,ans=0,sum=0,left=0,right=0;
    string s,t;
    cin >> n;
    VI a(n);
    VI b(n+1);
    b[0]=0;
    rep(i,n){
        cin >> a[i];
	}

    left += a[0];
    for(int j=1;j<n;j++){
        right += a[j];
    }
    for(int i=1;i<n;i++){
        if(min > abs(left-right))
            min = abs(left-right);
        left += a[i];
        right -= a[i];
    }
    
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 3e3+10;
int a,b,n,m,dp[N][N];
void add(int &a, ll b) {a=(a+b)%P;}
int main() {
	scanf("%d%d%d%d",&a,&b,&n,&m);
	dp[a][b] = 1;
	REP(i,a,n) REP(j,b,m) {
		int &r = dp[i][j];
		if (!r) continue;
		add(dp[i+1][j],(ll)r*j);
		add(dp[i][j+1],(ll)r*i);
		add(dp[i+1][j+1],-(ll)r*i%P*j);
	}
	printf("%d\n",dp[n][m]);
}


Measured memory_bytes: 38876
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    int A,B;
    cin >> A >> B;
    cout << max(A,B)+max(max(A,B)-1,min(A,B));
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int INF = 1e9+10;
int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++)
    {
        cin >> p[i];
        p[i]--;
    }
    vector<int> a(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++)
    {
        a[p[i]] = 1 + (p[i]) * n + i;
        b[p[i]] = 1 + (n-p[i]+1) * n;
    }
    for(int ans : a) cout << ans << " ";
    cout << endl;
    for(int ans : b) cout << ans << " ";
    cout << endl;
}


Measured memory_bytes: 3832
import java.util.Scanner;

public class Main {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a < b){
            System.out.println("a < b");
        } else if(a > b){
            System.out.println("a > b");
        } else{
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26064
import java.math.BigInteger;
import java.util.*;

public class Main {
	double EPS = 10.e-08;
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int d = a - b;
			System.out.println(c - Math.min(d, c));
			
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 21844
N,M = map(int,input().split())
MOD = 10**9+7

if abs(N-M) <= 1:
  cnt = 2 - abs(N-M)
  for i in range(1,N+1):
    cnt *= i
    cnt %= MOD

  for i in range(1,M+1):
    cnt *= i
    cnt %= MOD
else:
  cnt = 0

print(cnt)

Measured memory_bytes: 3060