akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, n) for (int i = (n)-1; i >= 0; i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase(unique(ALL(v)), v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 2e18;
const double PI = acos(-1);

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	vector<char> Must({'K', 'I', 'H', 'B', 'R'});
	bool ok = true;
	int ind = 0;
	REP(i, SZ(S))
	{
		if (S[i] == 'A')
		{
			if (ok)
			{
				ok = false;
			}
			else
			{
				cout << "NO" << endl;
				return 0;
			}
		}
		else
		{
			if (S[i] != Must[ind])
			{
				cout << "NO" << endl;
				return 0;
			}
			ind++;
			if (ind >= 3)
			{
				ok = true;
			}
			else
			{
				ok = false;
			}
		}
		if (ind == 5)
		{
			bool ans = false;
			if (i == SZ(S) - 1)
				ans = true;
			if (i == SZ(S) - 2 & S[SZ(S) - 1] == 'A')
			{
				ans = true;
			}
			if (ans)
			{
				cout << "YES" << endl;
				return 0;
			}
			else
			{
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}


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

string s,t,r;
int n,a,b;
signed main(){
	cin>>s>>n;
	rep(i,n){
		cin>>t;
		if(t=="print"){
			cin>>a>>b;
			cout<<s.substr(a,b-a+1)<<endl;
		}
		else if(t=="reverse"){
			cin>>a>>b;
			reverse(s.begin()+a,s.begin()+b+1);
		}
		else{
			cin>>a>>b>>r;
			s=s.substr(0,a)+r+s.substr(b+1,s.size()-b);
		}
	}
	return 0;
}


Measured memory_bytes: 3232
package main

import (
	"fmt"
)

func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func LCM(a, b int, integers ...int) int {
	result := a * b / GCD(a, b)

	for i := 0; i < len(integers); i++ {
		result = LCM(result, integers[i])
	}

	return result
}
func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	countAC := int((a - 1) / (c))
	countBC := int((b / c))
	countAD := int((a - 1) / d)
	countBD := int((b / d))
	countACD := int((a - 1) / LCM(c, d))
	countBCD := int(b / LCM(c, d))

	countTotal := b - a + 1 - (countBD - countAD) - (countBC - countAC) + (countBCD - countACD)

	fmt.Println(countTotal)

}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> field(H);
    for (int i = 0; i < H; i++) {
        cin >> field.at(i);
    }

    vector<vector<long long>> dp(H + 1, vector<long long>(W + 1, 0));
    dp.at(1).at(1) = 1;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (i == 1 && j == 1) {
                continue;
            }
            if (field.at(i - 1).at(j - 1) == '#') {
                dp.at(i).at(j) = 0;
            }
            else {
                dp.at(i).at(j) = (dp.at(i - 1).at(j) + dp.at(i).at(j - 1)) % 1000000007;
            }
        }
    }

    cout << dp.at(H).at(W) << endl;
}

Measured memory_bytes: 9216
from sys import stdin

N,M = map(int,stdin.readline().rstrip().split())
lList = []
rList = []
for i in range(M):
    l,r = map(int,stdin.readline().rstrip().split())
    lList.append(l)
    rList.append(r)
lMax = max(lList)
rMin = min(rList)
ans = rMin - lMax +1
if ans < 0:
    ans = 0
print(ans)


Measured memory_bytes: 10996
<>;@a=glob<>;$\=1e9;while($\-$l>1){$b[$s=@a]=@b=$N=$c=0;$c+=$N+=2*$_>$l+$\?-$b[++$s]:$b[$s--],$b[$s]++for@a;($c>@a*(@a+1)/4?$\:$l)=$l+$\>>1}print

Measured memory_bytes: 29064
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N, M = map(int, input().split())

n = 0
m = 0
r = 2

if N>1:
    n = combinations_count(N, r)
if M>1:
    m = combinations_count(M, r)

sum = n+m
print(sum)

Measured memory_bytes: 3064
import java.util.Scanner;

class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long sq=(long)(Math.sqrt(n)+0.0001);
		while(true){
			if(n%sq==0){
				break;
			}
			sq--;
		}
		System.out.println((int)Math.log10(n/sq)+1);
	}

}

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

# スペース区切りの整数の入力
a, b = map(int, input().split())
coins = 0

for i in range(2):
    if a >= b :
        coins += a
        a -= 1
    else:
        coins += b
        b -= 1

# 出力
print(str(coins))


Measured memory_bytes: 2940
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#include "string.h"

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define COUT(x) out << (x) << endl;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;


class CStrangeBank {
public:
    int N;
    int dp[150000];

    void solve(std::istream& in, std::ostream& out) {
        in >> N;
        memset(dp, 0x3F, sizeof(dp));
        dp[0] = 0;
        for (int i = 0; i < N; ++i) {
            for (int a = 1; a <= N-i; a *= 6) dp[i+a] = min(dp[i] + 1, dp[i+a]);
            for (int b = 1; b <= N-i; b *= 9) dp[i+b] = min(dp[i] + 1, dp[i+b]);
        }
        COUT(dp[N]);
    }
};


int main() {
    CStrangeBank solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=1e7+1;
ll fac[N];
int main()
{
	
    int n,m,t;
    cin>>n>>m>>t;
    vector<ll> a(n),b(m);
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<m;i++)
    cin>>b[i];
    for(int i=1;i<n;i++)
    a[i]+=a[i-1];
    for(int i=1;i<m;i++)
    b[i]+=b[i-1];
    int ans=0;
    for(int i=0;i<n;i++)
    {
    	if(a[i]<=t)
    	{
    		if(t-a[i]>=b[m-1])
    		{
    			ans=max(ans,m+i+1);
    			continue;
			}
			if(t-a[i]<b[0])
			{
				ans=max(ans,i+1);
				continue;
			}
    		int idx=upper_bound(b.begin(),b.end(),t-a[i])-b.begin();
    		ans=max(ans,i+1+idx);
		}
	}
    for(int i=0;i<m;i++)
    if(b[i]<=t)
   ans=max(ans,i+1);
	cout<<ans<<endl;
}

Measured memory_bytes: 6420
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	char s;
	int count = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> s;
			if (s == '#') {
				count++;
			}
		}
	}
	if (count == h + w - 1) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	a, err := strconv.Atoi(input())
	if err != nil {
		log.Fatal(err)
	}

	result := a + a*a + a*a*a

	fmt.Println(result)
}


Measured memory_bytes: 1836
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int[] n = SpRead(' ').Select(a => int.Parse(a)).ToArray();
        int[] A = SpRead(' ').Select(a => int.Parse(a)).ToArray();
        int N = n[0];
        int M = n[1];
        int X = n[2];
        int C0 = 0;
        for (int i = X; i != 0; i--) if (A.Contains(i)) C0++;
        int CG = 0;
        for (int i = X; i <= N; i++) if (A.Contains(i)) CG++;
        Console.WriteLine(Math.Min(C0,CG));
    }

}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int Cin()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }

}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 1000006;
const ll MOD = 1000000007;

int n, m;
int a[MAXN];

ll cur, cnt;
typedef pair<int,int> pii;
vector<pii> qry[MAXN];
void init () {
    REP1 (i, n-1) {
        if (a[i-1] < a[i]) {
            cur += a[i] - a[i-1];
        } else {
            cur += a[i] + 1;
            cnt++;
        }
        qry[a[i-1]+1].emplace_back(1, i);
        qry[a[i]+1].emplace_back(-1, i);
    }
}

int dis (int f, int t) {
    if (f < t) {
        return t - f;
    } else {
        return t + m - f;
    }
}
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> n >> m;
    REP (i, n) {
        cin >> a[i];
    }

    init();
    ll ans = 0x3f3f3f3f3f3f3f3f;
    REP1 (i, m) {
        debug(cur, cnt);
        for (auto q : qry[i]) {
            int id = q.second;
            debug(q.first, id);
            if (q.first > 0) {
                cur++;
                cnt++;
            } else {
                cnt--;
                cur += dis(a[id-1], a[id]) -1;
                debug(dis(a[id-1], a[id]), id);
            }
        }
        cur -= cnt;
        debug(cur, cnt);
        ans = min(ans, cur);
    }

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


Measured memory_bytes: 27520
(defmacro while (condition &body body)
  `(do ()
       ((not ,condition))
     ,@body))

(defun counting (n)
  (let ((sum 0))
    (while (> n 0)
      (setf sum (+ sum (rem n 10)))
      (setf n (floor n 10)))
    sum))

(defun some-sums ()
    (let ((n (1+ (read)))
	  (a (read))
	  (b (read))
	  (ans 0))
      (dotimes (i n)
	(if (and
	     (>= (counting i) a)
	     (<= (counting i) b))
	    (setf ans (+ ans i))))
      ans))
      
(format t "~A~%" (some-sums))

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

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max(max(a*c, a*d), max(b*c, b*d)) << endl;

    return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 1'000'000'000'000
#define INF 2'000'000'000'000
i64 N;

void solve() {
  i64 min_n = INF;

  REPS(a, sqrt(N)) {
    if (N % a > 0) continue;

    i64 b = N / a;
    chmin(min_n, (a - 1) + (b - 1));
  }

  cout << min_n << endl;
}

int main() {
  cin >> N;

  solve();

  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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; }

#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int vec[12]={31,29,31,30,31,30,31,31,30,31,30,31};
  int m,d,c;
  while(cin>>m>>d){
    if(m==0) break;
    c=0;
    if(m!=1) rep(i,m-1) c+=vec[i];
    c+=d;
    if(c%7==1) cout<<"Thursday"<<endl;
    else if(c%7==2) cout<<"Friday"<<endl;
    else if(c%7==3) cout<<"Saturday"<<endl;
    else if(c%7==4) cout<<"Sunday"<<endl;
    else if(c%7==5) cout<<"Monday"<<endl;
    else if(c%7==6) cout<<"Tuesday"<<endl;
    else if(c%7==0) cout<<"Wednesday"<<endl;
  }
      
  return 0;
}


Measured memory_bytes: 3004
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int N, K;
	cin >> N >> K; 
	if (N % K == 0) cout << '0' << endl;
	else cout << '1' << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;
using P = pair<int, int>;
int main() {
    u32 h, w;
    cin >> h >> w;
    vector<vector<int>> v(h+1, vector<int>(w+1, 0));
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            int k;
            cin >> k;
            v[i][j] = k;
        }
    }
    stringstream ss;
    vector<string> ans;
    int flag = 0;
    for (int i = 1; i <= h; ++i) {
        if(i%2) {
            for (int j = 1; j <= w; ++j) {
                if(v[i][j]%2) flag = 1;
                else flag = 0;
                if(flag){
                    flag = 1;
                    if(j != w){
                        ss << i << " " <<  j << " " << i << " " << j+1;
                        v[i][j]--;
                        v[i][j+1]++;
                        ans.emplace_back(ss.str());
                        ss.str("");
                        ss.clear(stringstream::goodbit);
                    }else if(i != h){
                        ss << i << " " <<  j << " " << i+1 << " " << j;
                        v[i][j]--;
                        v[i+1][j]++;
                        ans.emplace_back(ss.str());
                        ss.str("");
                        ss.clear(stringstream::goodbit);
                    }
                }
            }
        }else {
            for (int j = w; j >= 1; --j) {
                if(v[i][j]%2) flag = 1;
                else flag = 0;
                if(flag){
                    flag = 1;
                    if(j != 1){
                        ss << i << " " <<  j << " " << i << " " << j-1;
                        v[i][j]--;
                        v[i][j-1]++;
                        ans.emplace_back(ss.str());
                        ss.str("");
                        ss.clear(stringstream::goodbit);
                    }else if(i != h){
                        ss << i << " " <<  j << " " << i+1 << " " << j;
                        v[i][j]--;
                        v[i+1][j]++;
                        ans.emplace_back(ss.str());
                        ss.str("");
                        ss.clear(stringstream::goodbit);
                    }
                }
            }
        }
    }
    cout << ans.size() << "\n";
    for (const auto &an : ans) {
        cout << an << "\n";
    }
    return 0;
}


Measured memory_bytes: 9972
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define forn(i,n) for(int i=0;i<(int) n;i++)
#define Forn(i,n) for(int i=1;i<=(int) n;i++)

int main()
{
string s1,s2;
cin>>s1;
cin>>s2;
int len1,len2;
len1=s1.size();
len2=s2.size();
   int i,c=0;
   for(i=0;i<len1;i++)
   {
       if(s1[i]!=s2[i]) c++;
   }
   cout<<c;



}






Measured memory_bytes: 3912
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    cout<<n/(a+b)*a+min(a,n%(a+b))<<endl;
    return 0;
}

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

using namespace std;


const long INF = 9'999'999'999;

void merge(vector<long>& A, int left, int mid, int right, int& cnt) {
	int lfLen, rtLen;
	lfLen = mid - left;
	rtLen = right - mid;
	vector<long> L(lfLen + 1);
	vector<long> R(rtLen + 1);
	int i, j, k;
	i = j = k = 0;
	for (i = 0;i < lfLen;i++) { L[i] = A[left + i]; }
	for (i = 0;i < rtLen;i++) { R[i] = A[mid + i]; }
	L[lfLen] = INF;
	R[rtLen] = INF;
	i = j = 0;
	for (k = left; k < right; k++)
	{
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		}
		else
		{
			A[k] = R[j];
			j++;
		}
		cnt++;
	}
	return;
}

void mergeSort(vector<long>& A, int left, int right, int& cnt) {
	int mid = 0;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		mergeSort(A, left, mid, cnt);
		mergeSort(A, mid, right, cnt);
		merge(A, left, mid, right, cnt);
	}

	return;
}

int main() {


	int n = 0, cnt = 0;
	cin >> n;
	vector<long> A(n);

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

	mergeSort(A, 0, n, cnt);

	for (int i = 0;i < n;i++) {
		cout << A[i];
		if (i < n - 1) cout << " ";
	}
	cout << endl;

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 10636
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

long long MOD = 1e9 + 7;

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

    long long ans;
    if (N == M) {
        ans = 1;
        for (int i = 1; i <= M; i++) {
            ans = (ans*i) % MOD;
            ans = (ans*i) % MOD;
        }
        ans = (ans * 2) % MOD;
    }
    else if (abs(N - M) == 1) {
        ans = 1;
        if (N < M)swap(N, M);
        for (int i = 1; i <= M; i++) {
            ans = (ans*i) % MOD;
            ans = (ans*i) % MOD;
        }
        ans = (ans*N) % MOD;
    }
    else ans = 0;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 768
import numpy as np
import heapq

(n,k),p = [list(map(int, s.split())) for s in open(0)]

p_np = np.array(p)
p_cumsum = (p_np[1:]>p_np[:-1]).cumsum()

_min = [(x,i) for i,x in enumerate(p[:k])]
_max = [(-x,i) for i,x in enumerate(p[:k])]
heapq.heapify(_min)
heapq.heapify(_max)

ans = n - k + 1
no_change = False
if p_cumsum[k-2]==k-1:
    no_change = True

for i in range(n-k):
    decrease = False
    
    heapq.heappush(_min, (p[i+k], i+k))
    heapq.heappush(_max, (-p[i+k], i+k))
    
    while _min[0][1] < i:
        heapq.heappop(_min)
    while _max[0][1] < i:
        heapq.heappop(_max)
    
    if (_min[0][0]==p[i] and -_max[0][0]==p[i+k]):
        ans -= 1
        decrease = True
    
    if p_cumsum[i]+k-1 == p_cumsum[i+k-1]:
        if no_change and not decrease:
            ans -= 1
        no_change = True

print(ans)

Measured memory_bytes: 73348
#include <iostream>
#include <utility>
#include <cstdio>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <assert.h>
#include <cmath>
using namespace std;

#define ALL(a) (a).begin(), (a).end()

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

struct State {
    int v, cost;

    State(int v, int cost): v(v), cost(cost) {}

    // 昇順
    bool operator<(const State& s) const {
        return cost < s.cost;
    }
    // 降順
    bool operator>(const State& s) const {
        return cost > s.cost;
    }
};

template<typename T>
void dump_vector(vector<T> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << (i < vec.size() - 1 ? " " : "\n");
    }
}

const int MAX_N = 100010;

ll a[MAX_N],
   b[MAX_N];

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

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

    ll ans = 0;
    ll accum = 0;
    for (int i = n - 1; i >= 0; i--) {
        ll x = a[i] + accum;  // 現在のa[i]の値
        if (x == 0) continue;

        ll temp = (b[i] - (x % b[i]) + b[i]) % b[i];
        ans += temp;
        accum += temp;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int A,B,X;
  char S;
 cin >> A >> S >>B;
 
  if(S == '+'){
  X=A+B;
  }else if(S =='-'){
  X=A-B;
  }
  cout<<  X <<endl;
}


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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int n, m;
	sf("%d %d", &n, &m);

	int h[n + 7];
	for (int i = 1; i <= n; ++i) {
		sf("%d", &h[i]);
	}

	vector<int> g[n + 7];
	for (int i = 0; i < m; ++i) {
		int x, y;
		sf("%d %d", &x, &y);
		g[x].pp(y);
		g[y].pp(x);
	}

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		bool ok = true;
		for (int j = 0; j < g[i].size(); ++j) {
			if (h[g[i][j]] >= h[i]) ok = false;
		}
		if (ok) ++ans;
	}

	printf("%d", ans);

	return 0;
}


Measured memory_bytes: 9272
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 20160116
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}
const int Maxn=2005;
char c[Maxn][Maxn];
int sum1[Maxn][Maxn],sum2[Maxn][Maxn],sum3[Maxn][Maxn];
int main(){
	int n,m;

	scanf("%d %d",&n,&m);
	int q;
	scanf("%d",&q);
	for (int i=1;i<=n;i++){
		scanf("%s",c[i]+1);
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			sum1[i][j]=sum1[i][j-1]+sum1[i-1][j]-sum1[i-1][j-1]+(int)(c[i][j]=='1');
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			sum2[i][j]=sum2[i][j-1]+sum2[i-1][j]-sum2[i-1][j-1]+(int)(c[i][j]=='1' && c[i-1][j]=='1');
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			sum3[i][j]=sum3[i][j-1]+sum3[i-1][j]-sum3[i-1][j-1]+(int)(c[i][j]=='1' && c[i][j-1]=='1');
			//cout<<sum3[i][j]<<' ';
		}//cout<<endl;
	}

	while (q--){
		int ux,uy,dx,dy;
		scanf("%d %d %d %d",&ux,&uy,&dx,&dy);
		int ans1=sum1[dx][dy]+sum1[ux-1][uy-1]-sum1[ux-1][dy]-sum1[dx][uy-1];
		int ans2=sum2[dx][dy]+sum2[ux][uy-1]-sum2[ux][dy]-sum2[dx][uy-1];
		int ans3=sum3[dx][dy]+sum3[ux-1][uy]-sum3[ux-1][dy]-sum3[dx][uy];
	//	cout<<ans1<<' '<<ans2<<' '<<ans3<<endl;
		printf("%d\n",ans1-ans2-ans3);
	}
	return 0;
} 

Measured memory_bytes: 52864
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

#define INF 1e+9
#define mp make_pair
#define pb push_back
#define fi first
#define fs first
#define se second
#define i64 long long
#define li long long
#define lint long long
#define pii pair<int, int>
#define vi vector<int>

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++)

int main() {
#ifdef LOCAL
    freopen("inp", "r", stdin);
    //freopen("outp", "w", stdout);
#else
    // freopen(TASKNAME ".in", "r", stdin);
    // freopen(TASKNAME ".out", "w", stdout);
#endif
    int n, k;
    scanf("%d%d", &n, &k);
    if (k == 0) {
        cout << (i64)n * n;
        exit(0);
    }
    i64 ans = 0;
    fore(b, k + 1, n) {
        //how many <= N and has rem. >= k when divided by b
        //k..b-1, b + k..b+b-1, 2b + k, ...
        //tb-1 <= n, n + 1 >= tb
        int t = (n + 1) / b;
        ans += (i64)(b - k) * t;
        int start = t * b + k;
        if (n >= start)
            ans += (n - start + 1);
        //cout << "b = " << b << " ans = " << ans <<  " start = " << start << " t = " << t << endl;
    }
    cout << ans;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  int ans = 1;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      ans = ans * k;
    } else {
      ans = ans * (k - 1);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+6;
const ll MOD=1e9+7;
const ll Seed=2333;
ll Hash[N];
ll vs[500];
ll vt[500];
ll vis[500];
int main(){
    memset(vis,0,sizeof vis);
    Hash[0]=1;
    for(int i=1;i<=2e5+5;i++)   Hash[i]=Hash[i-1]*Seed%MOD;
    string s,t;
    cin >> s>>t;
    int flag=1;
    for(int i=0;i<(int)s.size();i++)    vs[s[i]]+=(i+1)*Hash[i]%MOD;
    for(int i=0;i<(int)t.size();i++)    vt[t[i]]+=(i+1)*Hash[i]%MOD;
    for(int i=0;i<(int)s.size();i++){
        if(vs[s[i]]!=vt[t[i]]){
            cout << "No"<<endl;
            return 0;
        }
    }
    cout <<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 2436
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 310;
int n,m,k,cnt,ans[N][N];
char s[N][N];

int main(){
	n=read(),m=read(),k=read();
	For(i,1,n) scanf("%s",s[i]+1);
	For(i,1,m){
		For(j,1,n) 
			if (s[j][i]=='#') ans[j][i]=++cnt;
				else ans[j][i]=ans[j-1][i];
		Dow(j,n,1) if (!ans[j][i]) ans[j][i]=ans[j+1][i];
	}
	Dow(i,m,1){
		For(j,1,n) if (!ans[j][i]) ans[j][i]=ans[j][i+1];
	}
	For(i,1,m){
		For(j,1,n) if (!ans[j][i]) ans[j][i]=ans[j][i-1];
	}
	For(i,1,n){
		For(j,1,m) printf("%d ",ans[i][j]);
		puts("");
	}
}

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

int main() {
  int64_t N, D, count;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> X.at(i).at(j);
    }
  }
  count=0;
  for (int i=0; i<N ; i++){
    int64_t d1=X.at(i).at(0), d2=X.at(i).at(1);
    if(d1*d1+d2*d2<=D*D){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 14348
import java.util.*;
import static java.lang.System.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++)
			p[i] = sc.nextInt();
		int ans = 0;
		for (int i = 1; i < n - 1; i++) {
			int cnt = 0;
			if ( Math.max(p[i], p[i - 1]) == p[i])
				cnt++;
			if ( Math.max(p[i], p[i + 1]) == p[i])
				cnt++;
			if (cnt == 1)
				ans++;
		}
		out.println(ans);
		
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   /// https://ideone.com/Fd5s8n
ll a,b;
cin>>a>>b;
char c;
cin>>c;
int d;
cin>>d;
b*=100;
b+=d;
ll x=b*a;
cout << x/100 << endl;

    return 0;

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// rep(i, 1, 5) --> {1,2,3,4}
// rep(i, 5, 1) --> {4,3,2,1}
// rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n;
    cin >> n;
    int sum = 0;
    while(n--)
    {
        int l,r;
        cin >> l >> r;
        sum += (r-l+1);
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
a = []
a = gets.split.map(&:to_i)
b = []
for i in 0..a[0]-1
  b.push(gets.chomp.split(""))
end
c = []
for i in 0..a[1]-1
  c.push(gets.chomp.split(""))
end

def hantei (m, n, p, b, c)
  t = 0
  for i in 0..p-1
    for j in 0..p-1
      if b[i + m][j + n] != c[i][j]
        t =1
      end
    end
  end
  return t
end        
        
u = []
for m in 0..a[0] - a[1] #x軸の移動
  for n in 0..a[0] - a[1] #y軸の移動
    u.push(hantei(m,n,a[1], b, c))
  end
end
if u.min == 0
  puts "Yes"
else
  puts "No"
end

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

using namespace std;

int main()
{
    int N;
    cin>>N;
    string s;
    cin>>s;
    int n=s.size();
    vector<set<int>>v(26);
    for(int i=0;i<n;++i)
    {
        v[s[i]-'a'].insert(i);
    }
    int q;
    cin>>q;
    while(q--){

        int a;
        cin>>a;

        if(a==1){

            int pos; char ch;
            cin>>pos>>ch;
            --pos;
            v[s[pos]-'a'].erase(pos);
            s[pos]=ch;
            v[s[pos]-'a'].insert(pos);
        }
        else{

            int l,r;
            cin>>l>>r;
            --l,--r;
            int ans=0;
            for(int i=0;i<26;++i){

                auto it=v[i].lower_bound(l);
                if(it!=v[i].end()&& *it<=r) ++ans;
            }
           cout<<ans<<endl;
    }
 }
}

Measured memory_bytes: 24196
#include<bits/stdc++.h>
#define INF 0x7fffffff
typedef long long ll;
using namespace std;
int n,a,b,ans=INF;
int div(int x)
{
	int res=0;
	while(x)
	{
		res+=x%10;
		x/=10;
	}
	return res;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n>>1;i++)
		ans=min(ans,div(i)+div(n-i));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define init(arr, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = pow(10,9);
const int nil = -1;
int a, b, c, d;
int turn;

int main() {
    scanf(" %d %d %d %d", &a, &b, &c, &d);
    while (true) {
        turn = 0;
        c -= b;
        if (c <= 0) break;
        turn = 1;
        a -= d;
        if (a <= 0) break;
    }
    if (turn == 0) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 3760
#coding:utf-8
#1_5_C 2015.4.1
while True:
    length,width = map(int,input().split())
    if length == width == 0:
        break

    line = '#.' * (width//2 + 1)
    for i in range(length):
        if i % 2:
            print(line[1:width+1])
        else:
            print(line[0:width])
    print()

Measured memory_bytes: 6724
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100009;

 main()

{
    fast
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;

    return 0;

}





































Measured memory_bytes: 3652
#include<stdio.h>
#include<stdbool.h>

#define NUM 50//何回発言できるか

bool answer_check(const char*, const char, char*, char*);

int main(void)
{
    printf("?a\n");
    fflush(stdout);

    const char last_char = 'a';//こちら側が発言した最後の文字(いつも'a')
    int count = 0;//こちらの発言回数（今から）
    char used_word[NUM + 1] = {};//相手の2文字目を登録していく
    
    while (true) {
        char ai_answer[3];
        scanf("%s", ai_answer);
        char ai_last;//相手のラストの文字

        if (!answer_check(ai_answer, last_char, used_word, &ai_last)) {
            printf("!OUT\n");
            fflush(stdout);
            break;
        }

        printf("?%c%ca\n", ai_last, ('a' + count++));//"#?a"を出力する。#は相手のラスト文字、?はa,b,c...の順で
        fflush(stdout);
    }

	return 0;
}


bool answer_check(const char* ai_ans, const char last_c, char* used_word, char* ptr_ai_last)
{

    //相手のラスト文字をチェック
    if (ai_ans[1] == '\0') {
        return false;//"a"なら相手の負け
    } else {
        *ptr_ai_last = ai_ans[1];
    }

    if (last_c != ai_ans[0]) {//相手がこちらの最後の文字から始まらなかったら
        return false;
    }

    int i;
    for (i = 0; used_word[i] != '\0'; i++) {
        if (ai_ans[1] == used_word[i]) {//相手の2文字目が既に使われていたら
            return false;
        }
    }
    used_word[i] = ai_ans[1];//使った文字を記録する

    return true;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;

ll s[MAXn],t[MAXn];
ll get(ll x,ll *dt,ll sz,bool c){
  ll it = lower_bound(dt,dt+sz,x)-dt;
  debug(it);
  if (!c) return it;
  if (it != 0) {
    if (abs(x-dt[it-1]) < abs(x-dt[it])) return abs(x-dt[it-1]);
    return abs(x-dt[it]);
  }
  return abs(x-dt[it]);
}
ll gogo(ll x,ll it,ll *dt1,ll *dt2,ll sz){
  ll ret = INF;
  vector<ll> tmp;
  tmp.eb(it);
  if (it > 0) tmp.eb(it-1);
  REP (i,SZ(tmp)) {
    ret = min(ret,abs(x-dt1[tmp[i]]) + get(dt1[tmp[i]],dt2,sz,1));
  }
  return ret;
}
int main(){
  IOS();
  ll a,b,q;
  cin >> a >> b >> q;
  REP (i,a) cin >> s[i];
  REP (i,b) cin >> t[i];
  while (q--) {
    ll x;
    cin >> x;
    ll it = get(x,s,a,0);
    ll ans = gogo(x,it,s,t,b);
    it = get(x,t,b,0);
    ans = min(ans,gogo(x,it,t,s,a));
    cout << ans << endl;
  }
}


Measured memory_bytes: 2944
N, K = map(int, input().split())
d = []
A = []
for _ in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))

nusuke = [1 for _ in range(N)]

for kids in A:
    for kid in kids:
        nusuke[kid-1] = 0

itazura = nusuke.count(1)
print(itazura)

Measured memory_bytes: 9216
#include <iostream>

using namespace std;

int gcd(int x, int y){
  int r=0;
  if (x < y)
    swap(x, y);
  while( y > 0){
    r = x % y;
    x = y;
    y = r;
  }

  return x;
}

int main(){
  int x,y;

  cin >> x >> y;

  int _max;
  _max=gcd(x, y);

  cout << _max << "\n";


  return 0;
}



Measured memory_bytes: 3100
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int output=0;
        for(int i=0;i<n;i++){
            output+=1-sc.nextInt()+sc.nextInt();
        }
        System.out.println(output);
    }
 
    
}

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

ll n,k;
vector<ll> a;
map<ll,ll> mp;
ll l,r;
void dfs(int j, ll count){
	if(mp[a[j]] != -1){
		r = count;
		l = mp[a[j]];
		return;
	}
	mp[a[j]] = count;
	dfs(a[j], count+1);
}

int main(){
	cin >> n >> k;
	a.resize(n+1);
	REP(i,n) mp[i] = -1;
	REP(i,n) cin >> a[i];
	mp[1] = 0;
	dfs(1, 1);
	if(k <= l){
		REP(i,n){
			if(mp[i] == k){
				cout << i << endl;
				return 0;
			}
		}
	}else{
		k -= l;
		ll temp = k % (r - l);
		temp += l;
		REP(i,n){
			if(mp[i] == temp){
				cout << i << endl;
				return 0;
			}
		}
	}
    return 0;
}



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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

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

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,m; cin>>n>>m;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  rep(i,n) a[i]/=2;
  
  ll two=1;
  while(a[0]%2==0) two*=2, a[0]/=2;
  
  irep(i,1,n){
    ll tmp=1;
    while(a[i]%2==0) tmp*=2, a[i]/=2;
    if(two!=tmp){
      cout<<0<<endl;
      return 0;
    }
  }
  
  if(two) m/=two;
  ll l=1;
  rep(i,n){
    l=lcm(l,a[i]);
    if(l>m){
      cout<<0<<endl;
      return 0;
    }
  }
  
  // cout<<l<<' '<<m<<endl;
  ll ans=m/l-(m/l)/2;
  cout<<ans<<endl;
  
}

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

class Dice {
	private int _t, _s, _e, _w, _n, _b;
	private int[] _p;
	Dice(int[] pip) {
		_t = pip[0];
		_s = pip[1];
		_e = pip[2];
		_w = pip[3];
		_n = pip[4];
		_b = pip[5];
		_p = pip.clone();
		Arrays.sort(_p);
	}
	void rollX(boolean d) {
		if (d) {
			int temp = _t;
			_t = _n;
			_n = _b;
			_b = _s;
			_s = temp;
		} else {
			int temp = _t;
			_t = _s;
			_s = _b;
			_b = _n;
			_n = temp;
		}
	}
	void rollY(boolean d) {
		if (d) {
			int temp = _s;
			_s = _w;
			_w = _n;
			_n = _e;
			_e = temp;
		} else {
			int temp = _s;
			_s = _e;
			_e = _n;
			_n = _w;
			_w = temp;
		}
	}
	void rollZ(boolean d) {
		if (d) {
			int temp = _e;
			_e = _b;
			_b = _w;
			_w = _t;
			_t = temp;
		} else {
			int temp = _e;
			_e = _t;
			_t = _w;
			_w = _b;
			_b = temp;
		}
	}
	void anchorTop(int t) {
		if (t == _e) {
			rollZ(true);
		} else if (t == _w) {
			rollZ(false);
		} else {
			while (t != _t) {
				rollX(true);
			}
		}
	}
	boolean equals(Dice d) {
		anchorTop(_p[0]);
		d.anchorTop(d._p[0]);
		boolean res = false;
		res |= _t == d._t && _s == d._s && _e == d._e && _w == d._w && _n == d._n && _b == d._b;
		rollY(true);
		res |= _t == d._t && _s == d._s && _e == d._e && _w == d._w && _n == d._n && _b == d._b;
		rollY(true);
		res |= _t == d._t && _s == d._s && _e == d._e && _w == d._w && _n == d._n && _b == d._b;
		rollY(true);
		res |= _t == d._t && _s == d._s && _e == d._e && _w == d._w && _n == d._n && _b == d._b;
		return res;
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Dice[] d = new Dice[n];
		for (int i = 0; i < n; ++i) {
			int[] pip = new int[6];
			for (int j = 0; j < 6; ++j) {
				pip[j] = sc.nextInt();
			}
			sc.nextLine();
			d[i] = new Dice(pip);
		}
		for (int i = 0; i < n; ++i) {
			for (int j = i + 1; j < n; ++j) {
				if (d[i].equals(d[j])) {
					System.out.println("No");
					sc.close();
					return;
				}
			}
		}
		System.out.println("Yes");
		sc.close();
	}
}


Measured memory_bytes: 28580
<?php

fscanf(STDIN, '%d %d', $N, $K);
$h = array_map('intVal', explode(' ', trim(fgets(STDIN))));

$dp = [];
$dp[1] = 0;
$dp[2] = abs($h[1] - $h[0]);

for ($i = 3; $i <= $N; ++$i) {
    $list = [];
    for ($j = 1; $j <= $K; ++$j) {
        if ($i-$j-1 < 0) {
            break;
        } 
        $list[] = $dp[$i-$j] + abs($h[$i-1] - $h[$i-$j-1]);
    }
    $dp[$i] = min($list);
}

echo $dp[$N];


Measured memory_bytes: 18932
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back

int N,K;
int p[200005];
signed main(){
    scanf("%d %d",&N,&K);
    rep(i,N){
        scanf("%d",&p[i]);
        p[i]++;
    }
    int ans=0;
    int now=0;
    rep(i,N){
        if(i<K){
            now+=p[i];
        }
        if(i==K-1){
            ans=now;
        }
        if(i>=K){
            now+=p[i]-p[i-K];
            if(now>ans){ans=now;}
        }
        //printf("%lld-",now);
        
    }
    printf("%lf\n",(double)ans/2.0);
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fs first
#define sc second
#define mk make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int INF = 1e9+1;
const ll LINF = 1e17;
const int MAKS = 300100;
ll n;
int main(){
	cin >> n;
	cout << n*(n-1)/2;
}

Measured memory_bytes: 256