akhauriyash/Code-Regression huggingface dataset:
n,a,b = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]

ans = 0
for i in range(n-1):
    if (x[i+1]-x[i])*a <= b: ans += (x[i+1]-x[i])*a
    else: ans += b
print(ans)


Measured memory_bytes: 62832
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;
typedef unsigned long long ull;

inline int scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
using namespace std;
int a[200005];
int b[200005];
int w1[200005];
int w2[200005];
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    cin >> a[i];
    for(int i = 1; i <= n; i++)
    cin >> b[i];
    int ans = 0;
    for(int i = 0; i <= 28; i++)
    {
        for(int j = 1; j <= n; j++)w1[j] = a[j]&(1<<(i+1))-1;
        for(int j = 1; j <= n; j++)w2[j] = b[j]&(1<<(i+1))-1;
        sort(w2+1, w2+1+n);
        int now = 0;
        int t1 = 1<<i, t2 = t1*2, t3 = t1*3, t4 = t1*4;
        for(int j = 1; j <= n; j++)
        {
            now ^= (lower_bound(w2+1, w2+1+n, t2-w1[j])-lower_bound(w2+1, w2+1+n, t1-w1[j]))&1;
            now ^= (lower_bound(w2+1, w2+1+n, t4-w1[j])-lower_bound(w2+1, w2+1+n, t3-w1[j]))&1;
        }
        ans |= (now<<i);
    }

    cout << ans << endl;
    return 0;
}
/*
                 ___====-_  _-====___
           _--^^^#####//      \\#####^^^--_
        _-^##########// (    ) \\##########^-_
       -############//  |\^^/|  \\############-
     _/############//   (@::@)   \\############\_
    /#############((     \\//     ))#############\
   -###############\\    (oo)    //###############-
  -#################\\  / VV \  //#################-
 -###################\\/      \//###################-
_#/|##########/\######(   /\   )######/\##########|\#_
|/ |#/\#/\#/\/  \#/\##\  |  |  /##/\#/  \/\#/\#/\#| \|
`  |/  V  V  `   V  \#\| |  | |/#/  V   '  V  V  \|  '
   `   `  `      `   / | |  | | \   '      '  '   '
                    (  | |  | |  )
                   __\ | |  | | /__
                  (vvv(VVV)(VVV)vvv)
                  ÁúÉñ±£ÓÓ ÓÀÎÞbug
*/


Measured memory_bytes: 3328
from collections import deque

n, m = map(int, input().split())
nodes = range(1,n+1)
edges = {v: set() for v in nodes}
for _ in range(m):
  a, b = map(int, input().split())
  edges[a].add(b)
  edges[b].add(a)

visited = {v: False for v in nodes}
cnt = -1
for v in nodes:
  if not visited[v]:
    visited[v] = True
    que = deque([v])
    while que:
      p = que.popleft()
      for q in edges[p]:
        if not visited[q]:
          visited[q] = True
          que.append(q)
    cnt += 1
print(cnt)

Measured memory_bytes: 111288
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009];
int main()
{
    ll a,b,c,i,j,k;
    string s;
    cin>>a>>s;
    for(i=1;i<=a;i++)
    {
        ar[i]=ar[i-1] ;
        if( s[i-1]=='W' )
        {
            ar[i]++;
        }
    }
    for(i=a;i>=1;i--)
    {
        br[i]=br[i+1] ;
        if(s[i-1]=='E' )
        {
            br[i]++;
        }
    }
    ll ans=999999999999;

    for(i=1;i<=a;i++)
    {
        ans=min(ans,ar[i-1] +br[i+1] ) ;
    }
    cout<<ans;
}



Measured memory_bytes: 6916
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto honest = new ulong[](N);
    auto unkind = new ulong[](N);
    foreach (i; 0 .. N)
    {
        long A = lread();
        foreach (_; 0 .. A)
        {
            long x, y;
            scan(x, y);
            if (y)
            {
                honest[i] |= 1 << (x - 1);
            }
            else
            {
                unkind[i] |= 1 << (x - 1);
            }
        }
    }
    bool isValid(ulong mh)
    {
        foreach (i; 0 .. N)
            if ((mh & (1 << i)) != 0)
            {
                if ((unkind[i] & mh) != 0)
                    return false;
                if ((honest[i] & (~mh)) != 0)
                    return false;
            }
        return true;
    }

    long ans;
    foreach (mh; 0 .. (1 << N))
        if (isValid(mh))
        {
            ans = ans.max(popcnt(mh));
        }
    writeln(ans);
}


Measured memory_bytes: 256
n = int(input())
lst = list(map(int, input().split()))

ans = 0

dp = [[0] * (n+1) for _ in range(n+1)] #dp[i]は石の数が残りi個のときに手番プレイヤーが勝利できるか

for i in range(n+1):
    for j in range(n - i+1):
        l = j
        r = j+i
        if l-r== 0:
            dp[l][r] == 0
        elif (n - (l - r-1)) % 2  ==1:
            dp[l][r] =  max(dp[l+1][r] + lst[l], dp[l][r-1] + lst[r-1])
        else:
            dp[l][r] =  min(dp[l+1][r] -  lst[l], dp[l][r-1] -  lst[r-1])
           
ans = dp[0][n]            
print(ans)

Measured memory_bytes: 144936
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, K = get_ints
S = gets.chomp

ones = []
zeros = []

current = '1'
current_number = 0

S.split('').each do |s|
  if s == '0'
    if current == '1'
      ones << current_number
      current_number = 0
      current = '0'
    end
    current_number += 1
  else
    if current == '0'
      zeros << current_number
      current_number = 0
      current = '1'
    end
    current_number += 1
  end
end

if current == '0'
  zeros << current_number
else
  ones << current_number
end

stock = ones[0]
right = 0
ans = stock
[*0...zeros.length].each do |left|
  while right < left + K
    stock += (right < zeros.length ? zeros[right] : 0) + (right+1 < ones.length ? ones[right+1] : 0)
    right += 1
  end
  ans = stock if ans < stock
  stock -= ones[left] + zeros[left]
end

puts ans


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

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

using namespace std;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long N, A, B, C ,D, E;
	long long S[5];

	cin >> N;
	cin >> A; S[0] = A;
	cin >> B; S[1] = B;
	cin >> C; S[2] = C;
	cin >> D; S[3] = D;
	cin >> E; S[4] = E;

	long long m = 1L<<60;
	long long t = 0;

	for(int i=0; i<5; i++){
		long long u;
		if(m > S[i]){
			m = S[i];
		}
		if(i == 0){
			t = N / m + 1;
			if((N % m) == 0){
				t--;
			}
		}
		else {
			u = N - (t - i) * m;
			t += u / m + 1;
			if((u % m) == 0){
				t--;
			}
		}
	}
	cout << t << endl ;
	return 0;
}

Measured memory_bytes: 256
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
	int n, m, c, a[20], b[20];
	cin >> n >> m >> c;
	REP(i, m) cin >> b[i];
	REP(i, n){
		int sum = 0;
		REP(j, m) cin >> a[j];
		REP(j, m)
		{
			//cout << a[j] * b[j] << endl; 
			sum += a[j] * b[j];
		}
		sum += c;
		if(sum > 0 ){
			ans ++;
			//cout << i << endl;
		}
	}
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if (A <= C && C <= B) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3572
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
//const ll MOD = 998244353
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll n, a, b;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> a >> b;
    if (a > b) swap(a,b);
    if ((b-a)%2 == 0) {
        cout<<(b-a)/2 << endl;
        return 0;
    }
    ll x = (a+b-1)/2;
    ll y = (2*n-a-b+1)/2;
    cout << min(x,y) << endl;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll s = 0;
    REP(a, N) {
        REP(b, N) {
            ll p = gcd(a + 1, b + 1);
            REP(c, N) {
                s += gcd(p, c + 1);
            }
        }
    }
    cout << s << endl;
    return 0;
}

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

using namespace std;

int N;

int main() {
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) { cin >> a[i]; }
	//sort(a.begin(), a.end());
	int ans = 0;
	for (int i = N - 1; i >= 0; i--) {
		ans = ans^a[i];
	}
	if (ans == 0) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
}

Measured memory_bytes: 640
s = list(map(int, input().split()))
q = int(input())
# 上面をnとして時計回りにサイコロを回したときの正面のindexの一覧[a_1,a_2,a_3,a_4]
# 正面がa_nのとき右面はa_n+1
dm = {0: [1, 2, 4, 3, 1],
      1: [0, 3, 5, 2, 0],
      2: [0, 1, 5, 4, 0],
      3: [0, 4, 5, 1, 0],
      4: [0, 2, 5, 3, 0],
      5: [1, 3, 4, 2, 1]}

for i in range(q):
    t, f = map(lambda x: s.index(int(x)), input().split())
    print(s[dm[t][dm[t].index(f)+1]])



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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    string s;
    cin >> s;
    int n = s.size();

    irep2(i, 1, n-1) {
        string t = s.substr(0, n-i);
        int m = t.size();
        if(t.size() % 2) {
            continue; 
        }
        //cout << t << endl;
        if(t.substr(0, m/2) == t.substr(m/2)) {
            cout << t.size() << endl;
            return 0;
        }
    }
    return 0;
}   
/** atcoder **/


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

const std::string ans[2]  = {"NO\n", "YES\n"};
const std::string keyence = "keyence";

int main() {
    std::string S;
    std::cin >> S;

    std::size_t n = S.length();

    if (n == 7) {
        std::cout << ans[(S == keyence)];
        return 0;
    }

    for (int i = 0; i <= 7; ++i) {
        std::string c_keyence = S.substr(0, i) + S.substr(i + n - 7, 7 - i);
        if (c_keyence == keyence) {
            std::cout << ans[1];
            return 0;
        }
    }

    std::cout << ans[0];
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C;
  D=min((A+B),(B+C));
  cout << min((C+A),D) << endl;
}


Measured memory_bytes: 3580
(* Vicfred
 * https://atcoder.jp/contests/abc143/tasks/abc143_c
 * implementation
 * *)
let main =
    Scanf.scanf "%d\n%s" @@ fun n s ->
        Printf.printf "%d\n" @@
        Array.fold_left ( + ) 1 @@
        Array.init (n - 1) @@ fun i ->
            if s.[i] = s.[i + 1] then 0 else 1



Measured memory_bytes: 5056
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdio>
#include<iomanip>

using namespace std;
int func(double x);

int main() {

	long long  N = 0;
	long long result = 0;
	string S;

	cin >> S;
	/*
	vector<long long> A(N);
	vector<long long> sum(N);
	for (long long i = 0; i < N; i++) {
		cin >> A[i];
		sum[i] =sum[i-1]+ A[i];
	}
	*/

	if (S == "SUN") { result = 7; }
	if (S == "MON") { result = 6; }
	if (S == "TUE") { result = 5; }
	if (S == "WED") { result = 4; }
	if (S == "THU") { result = 3; }
	if (S == "FRI") { result = 2; }
	if (S == "SAT") { result = 1; }

	cout << result;
}

int func(double x)
{
	if (x > 1) {
		x *= func(x - 1);
	}
	return x;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABCD = Console.ReadLine();

            for(var i=0;i<8;i++)
            {
                int ans = int.Parse(ABCD[0].ToString());
                var ansStr = $"{ABCD[0]}";
                for(var k=1;k<4;k++)
                {
                    if((i&(1<<(k-1)))==0)
                    {
                        ans += int.Parse(ABCD[k].ToString());
                        ansStr += $"+{ABCD[k]}";
                    }
                    else
                    {
                        ans -= int.Parse(ABCD[k].ToString());
                        ansStr += $"-{ABCD[k]}";
                    }
                }
                if(ans==7)
                {
                    Console.WriteLine($"{ansStr}=7");
                    return;
                }
            }

        }
    }
}


Measured memory_bytes: 13140
def scanning(s):
    def resolve(s, ans):
        if s == '':
            return ans
        elif s[0] == 'B' and len(ans) >= 0 :
            ans = ans[0:-1]
        else:
            ans += s[0]
        return resolve(s[1::], ans)
    return resolve(s, '')

print(scanning(input()))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int a[N],n,m,now;
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	for (int i=1;i<n;i++)
		if (a[now]+a[now+1]<a[i]+a[i+1])now=i;
	if (a[now]+a[now+1]<m){
		puts("Impossible");
		return 0;
	}
	puts("Possible");
	for (int i=1;i<now;i++)printf("%d\n",i);
	for (int i=n-1;i>now;i--)printf("%d\n",i);
	printf("%d",now);	
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int ans=0;
  for(int i=1;i<=a;i++){
    for(int j=1;j<=b;j++){
      if(j>=10){
        int x=j/10; int y=j%10;
        if(x*y==i&&x>1&&y>1) ans++;
      }
    }
  }
  cout << ans << endl;
}

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

long long func(long long a,long long b,long long x){
  long long ans;
  ans = floor((a*x)/b) + a*floor(x/b);
  return ans;
}

int main(){
  long long a,b,n;
  cin >> a >> b >> n;
  n = min(n,b-1);
  cout << func(a,b,n) << endl;
  
  return 0;
}


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

int main(void){
  int N,i,j,sum=0,min=1000000;
  int x[105];
  scanf("%d\n",&N );
  scanf("%d",&x[0] );
  for(i=1;i<N;i++){
    scanf(" %d",&x[i] );
  }
  for(i=1;i<101;i++){
    for(j=0;j<N;j++){
      sum += pow(x[j]-i ,2);
    }
    if(sum < min){
      min = sum;
    }
    sum = 0;
  }
  printf("%d\n",min );
  return 0;
}

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

int S;
long long MOD = 1000000007;

int f(long long x)
{
    if (x >= 10000000) return 8;
    else if (x >= 1000000) return 7;
    else if (x >= 100000) return 6;
    else if (x >= 10000) return 5;
    else if (x >= 1000) return 4;
    else if (x >= 100) return 3;
    else if (x >= 10) return 2;
    else return 1;    
}

int main()
{
    cin >> S;
    long long ans = 0;

    int begin = 1;
    int end = 1;
    int sum = 0;
    while (begin < 10000000)
    {
        if (sum == S)
        {
            ans++;
            sum = sum + f(end) - f(begin);
            end++;
            begin++;
        }
        else if (sum < S)
        {
            sum += f(end);
            end++;
        }
        else
        {
            sum -= f(begin);
            begin++;
        }
    }

    for (int i = S/8; i > 0; i--)
    {
        long long decmem = 1, adecmem = 0;
        if (S % i == 0)
        {
            int power = S / i - 1 - adecmem;

            long long tmp;
            for (int j = 1; j <= 30; j++)
            {
                if (j==1) tmp = 10;
                else tmp = tmp * tmp % MOD;
                if (power >> (j-1) & 1) decmem = decmem * tmp % MOD;
            }
            adecmem = S / i - 1;
            ans += (9 * decmem - i + 1 + MOD) % MOD;
            ans %= MOD;
        }
        else
        {
            ans = (ans + 1) % MOD;
        }
    }

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(v) (v).begin(),(v).end()
const ll MOD = 1e9 + 7;

int main() {
	int H, W, N;
	cin >> H >> W >> N;
	int sr, sc;
	cin >> sr >> sc;
	sr--; sc--;
	string S, T;
	cin >> S >> T;
	int l = 0, r = W - 1;
	if (S[N - 1] == 'L') l++;
	else if (S[N - 1] == 'R') r--;
	bool ok = 1;
	for (int i = N - 2; i >= 0; i--) {
		if (T[i] == 'L') r = min(r + 1, W - 1);
		else if (T[i] == 'R') l = max(l - 1, 0);
		if (S[i] == 'L') l++;
		else if (S[i] == 'R') r--;
		if (l > r) {
			ok = 0;
			break;
		}
	}
	if (l > sc || r < sc) ok = 0;
	l = 0, r = H - 1;
	if (S[N - 1] == 'U') l++;
	else if (S[N - 1] == 'D') r--;
	for (int i = N - 2; i >= 0; i--) {
		if (T[i] == 'U') r = min(r + 1, H - 1);
		else if (T[i] == 'D') l = max(l - 1, 0);
		if (S[i] == 'U') l++;
		else if (S[i] == 'D') r--;
		if (l > r) {
			ok = 0;
			break;
		}
	}
	if (l > sr || r < sr) ok = 0;
	if (ok) cout << "YES" << endl;
	else cout << "NO" << endl;
}


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

int main(){
    int N,W;cin >> N >> W;
    int dp[N+1][W+1] = {0};
    int w[N],v[N];
    
    for(int i = 0;i < N;i++){
        cin >> v[i] >> w[i];
    }
 
    for(int j=0;j<=W;j++){
        dp[0][j] = 0;
    }

    for(int n = 0;n < N;n++){
        for(int j = 0;j <= W;j++){
            if(j < w[n]){
                dp[n+1][j] = dp[n][j];
            }else{
                dp[n+1][j] = max(dp[n][j],dp[n][j - w[n] ] + v[n]);
            }
        }
    }

    cout << dp[N][W] << endl;
    
}


Measured memory_bytes: 7060
import java.util.*;
import java.lang.*;

public class Main {
    
    public static void main (String args[]) {
        
        int ans = 0;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        Arrays.sort(h);
        
        int min = Integer.MAX_VALUE;
        
        //System.out.println("---");
        
        for (int i = k-1; i < n; i++) {
            if (min > h[i] - h[i - (k - 1)]) {
                min = h[i] - h[i - (k - 1)];
                //System.out.println(min);
            }
        }
        
        ans = min;
        
        System.out.println(ans);
    }
}


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

int main() {
  int A,B;
  cin >> A >> B;
  int K = min(A,B);
  int L = max(A,B);
  for (int i = 0; i < L; i++)
    cout << K;
  cout << endl;
  
     
}


Measured memory_bytes: 384
A, B, C, D, E, F = map(int, input().split())

sugerWater = 0
suger = 0
maxConcentration = 0.0
for a in range(31):
    for b in range(16):
        for c in range(3001):
            for d in range(1501):
                x = a * 100 * A + b * 100 * B
                y = c * C + d * D
                if 0 < x + y <= F and 100 * y <= E * x:
                    concentration = 100 * y / (x + y)
                    if maxConcentration <= concentration:
                        maxConcentration = concentration
                        sugerWater = x + y
                        suger = y
                else:
                    break

print('{} {}'.format(sugerWater, suger))

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

long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

int main(void){
  int n,m; cin >> n >> m;
  if(n < 2 && m < 2) cout << 0 << endl;
  else if(n < 2) cout << combi(m,2) << endl;
  else if(m < 2) cout << combi(n,2) << endl;
  else cout << combi(m,2) + combi(n,2) << endl;
  return 0;
}

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

int main(void) {
  int n, l[102], ans = 0, hikaku = -1;

  if(scanf("%d", &n) == 1);

  for(int i = 0; i < n; i++) {
    if(scanf("%d", &l[i]) == 1);
    if(hikaku < l[i]) {
      hikaku = l[i];
    }
    ans += l[i];
  }

  if(hikaku < (ans - hikaku)) {
    printf("Yes");
  } else {
    printf("No");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int maxn = 305;
int vis[maxn<<1][maxn<<1][2], color[maxn<<1][maxn<<1][2];
int N,D1,D2;
int tot,color_cnt;
typedef pair<int,int> p;
vector<p> v1,v2;

void dfs(int x,int y,int a,int b){
	if(x < 0 || x >= 2 * N || y < 0 || y >= 2 * N || vis[x][y][a]) return;
	vis[x][y][a] = 1; color[x][y][a] = b;
	for(int i = 0; i < ((a == 0) ? v1.size() : v2.size()); i++){
		int dx = ((a == 0) ? v1[i].first : v2[i].first);
		int dy = ((a == 0) ? v1[i].second : v2[i].second);
		dfs(x + dx,y + dy, a, 3 - b);
		dfs(x - dx,y + dy, a, 3 - b);
		dfs(x + dx,y - dy, a, 3 - b);
		dfs(x - dx,y - dy, a, 3 - b);
	} 
}

int main(){
	scanf("%d%d%d",&N,&D1,&D2);
	// Decompose
	for(int i = 0; i <= D1; i++){
		int y = (int) sqrt(D1 - i * i);
		if(y * y + i * i == D1) v1.push_back(p(i,y));
	}
	for(int i = 0; i <= D2; i++){
		int y = (int) sqrt(D2 - i * i);
		if(y * y + i * i == D2) v2.push_back(p(i,y));
	}
	for(int i = 0; i < N * 2; i++){
		for(int j = 0; j < N * 2; j++){
			if(!vis[i][j][0]) dfs(i,j,0,1);
			if(!vis[i][j][1]) dfs(i,j,1,1);
		}
	}
	int cnt = 0;
	for(int i = 0; i < N * 2; i++){
		for(int j = 0; j < N * 2; j++){
			if(cnt == N * N) return 0;
			if(color[i][j][0] == 1 && color[i][j][1] == 1){
				printf("%d %d\n",i,j);
				cnt++; 
			}
		}
	}
	return 0;
}


Measured memory_bytes: 34816
//Link : https://atcoder.jp/contests/agc011/tasks/agc011_e
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define N 500005

struct bigInt {
  vector<int> digit;
  bigInt(vector<int> r) {
    int n = r.size();
    digit = vector<int>(n);
    for(int i=0;i<n;++i) {
      digit[i] = r[i];
    }
  }
  void multiply(int x) {
    vector<int> ret(digit.size()+1,0);
    int carry = 0;
    for(int i=0;i<digit.size();++i) {
      int u = digit[i]*x + carry;
      ret[i] = u%10;
      carry = u/10;
    }
    if(carry>0) {
      ret[digit.size()] = carry;
    } else {
      ret.pop_back();
    }
    digit = ret;
  }
  void add(vector<int> digit2) {
    int maxi = max(digit2.size(),digit.size());
    int carry = 0;
    vector<int> ret(maxi+1,0);
    for(int i=0;i<maxi;++i) {
      int a = 0,b = 0;
      if(i<digit.size()) {
        a = digit[i];
      }
      if(i<digit2.size()) {
        b = digit2[i];
      }
      int u = a + b + carry;
      ret[i] = u%10;
      carry = u/10;
    }
    if(carry) {
      ret[maxi] =  carry;
    } else {
      ret.pop_back();
    }
    digit = ret;
  }
  int digitSum() {
    int ret = 0;
    for(int i=0;i<digit.size();++i) {
      ret += digit[i];
    }
    return ret;
  }
};

bigInt getFromInt(int k) {
  vector<int> ret;
  while(k>0) {
    ret.push_back(k%10);
    k/=10;
  }
  return bigInt(ret);
}
void solve() {
  char s[N];scanf("%s ",s);
  int n = strlen(s);

  int l = 1,r = n+1,mid;
  while(l<r) {
    mid = (l+r)/2;
    bigInt tmp = getFromInt(mid*9);
    vector<int> ret(n);
    for(int i=n-1;i>=0;--i) {
      ret[n-1-i] = s[i]-'0';
    }

    bigInt b = bigInt(ret);
    b.multiply(9);
    b.add(tmp.digit);
    if(b.digitSum()<=mid*9) {
      r = mid;
    } else {
      l = mid+1;
    }
  }
  printf("%d\n", l);
}
int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 10556
#include <stdio.h>

int main(void)
{
  int a[2][4];
  int sum[2];
  int i;

  for (i = 0; i < 2; i++){
    scanf("%d %d %d %d", &a[i][0], &a[i][1], &a[i][2], &a[i][3]);
    sum[i] = a[i][0] + a[i][1] + a[i][2] + a[i][3];
  }

  if (sum[0] > sum[1] || sum[0] == sum[1]){
    printf("%d\n", sum[0]);
  }
  else {
    printf("%d\n", sum[1]);
  }

  return (0);
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

/*
 *if x == 1 ans = 1
 * ops = 1, x -= 1 x / 11, x % 11
 */

int main() {
	ll x;
	cin >> x;
	ll ops = 0;
	ops += 2 * (x / 11);
	if (x % 11 != 0) {
		if (x % 11 > 6) {
			ops += 2;
		}
		else {
			ops += 1;
		}
	}
	cout << ops;
}


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

#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

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

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T> void print(T &x) {
    cout << x << '\n';
    return;
}

template <class T> ll sized_subset(T &comb) {
    T x = comb & -comb, y = x + comb;
    return ((comb & ~y) / x) >> 1 | y;
}

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

int n, a[2][103], ans;
int main() {
    n = in();
    REP(i, 2) {
        REP(j, n) {
            a[i][j] = in();
            ans += a[i][j];
        }
    }
    if(n==1){print(ans);return 0;}
    if(n==2){ans=ans-min(a[0][1],a[1][0]);print(ans);return 0;}

    REP(i,n-1){
        ans-=a[1][i];
    }
    int buf=ans;
    REP(i,n-1){
        ans=max(ans,buf-a[0][n-i-1]+a[1][n-i-2]);
        buf=buf-a[0][n-i-1]+a[1][n-i-2];
    }
    print(ans);return 0;
    return 0;
}


Measured memory_bytes: 256
//kruskal tree
#include <cstdio>
#include <algorithm>
using namespace std;
#define M 9999
int parent[M],a[M],b[M];
pair<int,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,s,n,m;
	for(;scanf("%d%d",&n,&m)>1;printf("%d\n",s/100-n+1)){
		for(i=0;i<m;i++)scanf("%d,%d,%d",a+i,b+i,&node[i].first),node[i].second=i;
		sort(node,node+m);
		for(i=0;i<n;i++)parent[i]=i;
		for(s=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))s+=node[i].first;
	}
}

Measured memory_bytes: 1152
/**
 * DA-IICT
 * Author : PARTH PATEL
 */
import java.io.*;
import java.math.*;
import java.util.*;

import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;


 class Main {

	public static int mod = 1000000007;
	static FasterScanner in = new FasterScanner();
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {

		int testcases=in.nextInt();
		int answer=0;
		while(testcases-->0)
		{
			int l=in.nextInt();
			int r=in.nextInt();
			answer+=(r-l+1);
		}
		out.println(answer);
		out.close();

	}

	public static long pow(long x, long n, long mod) {
		long res = 1;
		for (long p = x; n > 0; n >>= 1, p = (p * p) % mod) {
			if ((n & 1) != 0) {
				res = (res * p % mod);
			}
		}
		return res;
	}

	public static long gcd(long n1, long n2) {
		long r;
		while (n2 != 0) {
			r = n1 % n2;
			n1 = n2;
			n2 = r;
		}
		return n1;
	}

	static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int snumChars;

		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, a, in;// , maxx = 0;
	vi x;
	cin >> n >> a;
	rep(i, n) {
		cin >> in;
		x.push_back(in-a);
		//maxx = max(maxx, in);
	}
	vector<vector<ll>> vv(2500 * 2 + 1, vector<ll>(n ,0));
	rep(i, n) {
		if (i == 0) {
			vv[2500 + x[0]][0]++;
			vv[2500][0]++;
		}
		else {
			rep(j, vv.size()) {
				vv[j][i] = vv[j][i-1];
				if (j - x[i] >= 0 && j - x[i] <= 5000) {
					vv[j][i] += vv[j-x[i]][i-1];
				}
			}
		}
	}

	cout << vv[2500][n-1]-1 << endl;
}

Measured memory_bytes: 2432
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

//先行順巡回//
void preParse(int u) {
	if (u == NIL)return;
	printf(" %d", u);
	preParse(T[u].l);
	preParse(T[u].r);
}

//中間巡回//
void inParse(int u) {
	if (u == NIL)return;
	inParse(T[u].l);
	printf(" %d", u);
	inParse(T[u].r);
}


//後行巡回//
void postParse(int u) {
	if (u == NIL)return;
	postParse(T[u].l);
	postParse(T[u].r);
	printf(" %d", u);
	
}



int main() {
	int i, v, l, r, root;

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

	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &v, &l, &r);
		T[v].l = l;
		T[v].r = r;
		if (l != NIL)T[l].p = v;
		if (r != NIL)T[r].p = v;
	}

	for (i = 0; i < n; i++) {
		if (T[i].p == NIL)root = i;
	}

	printf("Preorder\n");
	preParse(root);
	printf("\n");
	printf("Inorder\n");
	inParse(root);
	printf("\n");
	printf("Postorder\n");
	postParse(root);
	printf("\n");

	
	return 0;
}


Measured memory_bytes: 2768
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
	int[] test;
	test = new int[3];
	int tmp;
	Scanner sc  = new Scanner(System.in);
	for(int i = 0; i<3; i++){
	    test[i] = sc.nextInt();
    }
    for(int s = 0; s<2;s++){
	    for(int j = s+1; j<3;j++){
	       if(test[s]>test[j]){
	           tmp = test[s];
	           test[s] = test[j];
	           test[j] = tmp;
           }
        }
    }
		System.out.println(test[0]+ " "+test[1]+" "+test[2]);

		}
    }
   


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

int main (){

    int N;
    cin >> N;
    char S[N];
    for(int i = 0; i < N; i++) {
        cin >> S[i];
    }

    for(int i = 0; i < N; i++) {
        if(S[i] == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }
    
    cout << "Three" << endl;
    return 0;
}




Measured memory_bytes: 256
x, k, d = map(int, input().split())

#x：現在地
#k：回数
#d:移動距離

idou = abs(x) // d

if idou > k:
  idou = k
  
minus = abs(x - d * idou)
plus = abs(x + d * idou)


if minus < plus:
  x -= d * idou
else:
  x += d * idou

nokori = (k - idou) % 2

minus = abs(x - d * nokori)
plus = abs(x + d * nokori)

if minus < plus:
  x -= d * nokori
else:
  x += d * nokori
  
print(abs(x))


Measured memory_bytes: 61796
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(abs(a-c)<=d)
	{
		printf("Yes");
		return 0;
	}
	if(abs(a-b)<=d&&abs(b-c)<=d)
	{
		printf("Yes");
		return 0;
	}
	printf("No");
	return 0;
	
	
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ld,ld> id;
typedef tuple<ll,ll,ll> tl;
typedef tuple<ll,ll,ll,ll> ql;

#define FOR(i, a, b) for(ll i=(a); i<=(b); i++)
#define ROF(i, a, b) for(ll i=(a); i>=(b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define FILL(x, n, v) fill(x, x+n, v);
#define ALL(x) x.begin(), x.end()
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define f first
#define s second
#define ins insert
#define e emplace
#define eb emplace_back
#define ef emplace_front
#define p push
#define pf push_front
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ft front
#define bk back
#define pp pop
#define ppb pop_back
#define ppf pop_front

#define db cout<<"YEET\n";
#define ct(x) cout<<x<<'\n';

const ll MOD = 1e9+7; //998244353
const ll MAXN = 10+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);

int main(){
    FAST
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll tcnt = (c%b ? 1 : 0);
    ll acnt = (a%d ? 1 : 0);
    acnt += a/d;
    tcnt += c/b;

    if (tcnt<=acnt) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

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

    size_t N, K; cin >> N >> K;

    unordered_map<intmax_t, intmax_t> cnt;
    vector<intmax_t> a(N);
    for (size_t i = 0; i < N; ++i) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    if (a.size() <= K) {
        return cout << 0 << "\n", 0;
    }

    vector<pair<intmax_t, intmax_t>> vec;
    for (auto &ai: a) {
        vec.emplace_back(cnt[ai], ai);
    }

    sort(vec.begin(), vec.end());

    intmax_t res = 0;
    for (size_t i = 0; i < vec.size() - K; ++i) {
        res += cnt[vec[i].second];
    }

    cout << res << "\n";

    return 0;
}


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

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

    int n, k;
    cin >> n >> k;

    vector<int> s(n, 0);
    rep(i, k){
        int d;
        cin >> d;
        rep(j, d){
            int a;
            cin >> a;
            --a;
            ++s[a];
        }
    }

    int res = 0;
    rep(i, n){
        if(s[i] == 0) ++res;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3684
A, B, M = gets.split.map(&:to_i)
F = gets.split.map(&:to_i)
R = gets.split.map(&:to_i)
Q = M.times.map { gets.split.map(&:to_i) }

min_cost = F.min + R.min

Q.each do |x, y, c|
  cost = F[x - 1] + R[y - 1] - c

  min_cost = cost if min_cost > cost
end

puts min_cost


Measured memory_bytes: 18972
a,b,c,d = gets.split.map(&:to_i)

ans = 0

c_sum = a%c == 0 ? b/c-a/c+1 : b/c-a/c
d_sum = a%d == 0 ? b/d-a/d+1 : b/d-a/d
l = c.lcm(d)
cd_sum = a%l == 0 ? b/l-a/l+1 : b/l-a/l

puts (b-a+1) - (c_sum + d_sum - cd_sum)

Measured memory_bytes: 1788
import java.util.*;
// import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    try {
      int a = scanner.nextInt();
      int b = scanner.nextInt();
      int ans = solve(a,b);
      System.out.println(ans);
    } finally {
      scanner.close();
    }
  }
  
  private static int solve(int a, int b) {
    // 隣の塔との高さの差b-aを考える
    // 1番目と2番目の差は2、998番目と999番目の差は999なので
    // n-1番目とn番目の差はn
    // これがb-aになる
    int n = b - a;

    // 塔bの高さは、1 + 2 + ... + n
    int h = n * (n + 1) / 2;

    // 積雪の深さは、塔bの本当の高さから、雪の上に出ている高さを引いたもの
    return h - b;
  }
}


Measured memory_bytes: 35748
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto st = readln.split.to!(char[][]);
    char[] u;
    foreach (i; 0..N) {
        u ~= st[0][i];
        u ~= st[1][i];
    }
    writeln(u);
}

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

int main() {
	string o;
	int a = 0;
	cin >> o;
	rep(i, 3) {
		if (o[i] == 'o') {
			a++;
		}
	}
	cout << a * 100 + 700 << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def parse_input():
    line = [int(e) for e in input().split(" ")]
    a = line[0]
    b = line[1]

    return (a, b)


def solve(a, b):

    result = 0
    if b % a == 0:
        result = a + b
    else:
        result = b - a

    return str(result)

def main():
    # 出力

    a, b = parse_input()
    print(solve(a, b))

if __name__ == '__main__':

    main()


Measured memory_bytes: 3060
object Main extends App {  
  val n = readLine.toInt
  val list = readLine.split("").filter(_.nonEmpty).toVector
  
  val init = list.drop(1).count(_ == "E")
  
  val min = (1 to n-1).toSeq.scan(init)((a,b) => {
    val left = if (list(b - 1) == "W") 1 else 0
    val right = if (list(b) == "E") -1 else 0
    a + left + right
  }).min
  
  println(min)
}

Measured memory_bytes: 80600
//                          VIVEK UPADHYAY
//                         MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
//                        $$ JAB-TAK TODEGA NHI,
//                         TAB -TAK CHODEGA NHI :D
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<endl ;
#define ok cout<<"ok\n" ;
typedef long long ll;
const int MAXN = 3*1e7 + 10 ;
const int MAX = 1e7 ;
double pi = 3.1415926535897932384626433832795;
const ll inf=1e18 ;
int main() {
    string s ;
    cin >> s ;
    if(s=="999") cout<<"999\n" ;
    else {
        string str="" ;
        for(int i=0;i<s.length();i++)
            str+=s[0];
        if(str >= s) cout<<str<<endl;
        else {
            str="" ;
            for(int i=0;i<s.length();i++)
                str+=s[0]+1;
            cout<<str<<endl;
        }
    }
    
    return 0 ;
    
}


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

void insertionSort(int A[], int N){
  int i, v, j, k;
  for(i = 1; i < N; i++){
    for(k = 0; k < N; k++){
      printf("%d",A[k]);
      if(k <= N-2) {printf(" ");}
      else{printf("\n");}
    }
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  }
}


int main(void){
  int i, n;
  scanf("%d", &n);
  int *a;
  a = malloc(n * sizeof(int));
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  insertionSort(a, n);
  for(i = 0; i < n; i++){
    printf("%d",a[i]);
    if(i <= n-2) {printf(" ");}
    else{printf("\n");}
  }
  return 0;
}

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

#define ff first
#define ss second
#define maxn 2000006
#define pb push_back
#define ll long long
#define lll __int128
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<=n;i++)

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

using namespace std;

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

	ll n; cin >> n;

	ll h[n];
	f(i, 0, n - 1) cin >> h[i];

	ll dp[n];
	dp[0] = 0;

	f(i, 1, n - 1) {
		if (h[i - 1] >= h[i]) {
			dp[i] = dp[i - 1] + 1;
		}
		else dp[i] = 0;
	}
	ll ans = INT_MIN;
	f(i, 0, n - 1) ans = max(ans, dp[i]);

	cout << ans;

	return 0;
}

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

using namespace std;

typedef long long int ll;

int main(void){

    string s;
    ll k;

    cin >> s >> k;

    int count = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] != '1'){
            cout << s[i] << endl;
            break;
        }else count++;

        if(count == k){
            cout << 1 << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>

using namespace std;
#define REP(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1'000'000'000+7)

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

bool sorted(vector<int> &v) {
    REP(i, 1, v.size()) {
        if (v[i] < v[i-1]) {
            return false;
        }
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    REP(i, 0, N) {
        cin >> p[i];
    }
    
    if (sorted(p)) {
        cout << "YES" << endl;
        return 0;
    }
    REP(i, 0, N) {
        REP(j, i+1, N) {
            auto pp = p;
            swap(pp[i], pp[j]);
            if (sorted(pp)) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256