akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
using namespace std;


int main()
{
  vector<int> a(9,0);
  for (int i = 0; i < 9; i++)
    cin >> a[i];
  int n;
  cin >> n;
  int b;
  for (int i = 0; i < n; i++)
  {
    cin >> b;
    for (int i = 0; i < 9; i++)
      if (a[i] == b) a[i] = 1;
  }

  bool flag = false;
  for (int i = 0; i < 3; i++)
  {
    if (a[3 * i] == 1 && a[3 * i + 1] == 1 && a[3 * i + 2] == 1)
    {
      flag = true;
      break;
    }
    if (a[i] == 1 && a[i + 3] == 1 && a[i + 6] == 1)
    {
      flag = true;
      break;
    }
    if (a[0] == 1 && a[4] == 1 && a[8] == 1)
    {
      flag = true;
      break;
    }
    if (a[2] == 1 && a[4] == 1 && a[6] == 1)
    {
      flag = true;
      break;
    }
  }
  if (flag == true) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int len, L, R, cntL, cntR, ans = 0;
char s[500000];
bool judge = true;
int main( ) {
	scanf( "%s", s + 1 );
	len = strlen( s + 1 );
	L = 1; R = len;
	while( L <= R ) {//xabxa
		while( s[L] == 'x' ) L++;
		while( s[R] == 'x' ) R--;
		if( L >= R ) break;
		if( s[L] != s[R] ) { judge = false; break; }
		while( s[L] == s[R] ) { L++; R--; }
	}	 
	if( judge == false ) { printf( "-1\n" ); return 0; }
	L = 1; R = len;
	while( L <= R ) {
		cntL = 0; cntR = 0;
		while( s[L] == 'x' ) { L++; cntL++; }
		while( s[R] == 'x' ) { R--; cntR++; }
		ans += abs( cntL - cntR );
		while( s[L] == s[R] ) { L++; R--; }
	}
	printf( "%d\n", ans );
}

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

int a[100005], b[100005];
int n;

int main() {
  cin >> n;
  int v;
  rep(i, n) {
    scanf("%d", &v);
    (i & 1 ? b : a)[v]++;
  }
  int mx_pos, mx=0, sec=0;
  rep(i, 100005) {
    if(a[i] > mx) {
      sec = mx;
      mx = a[i];
      mx_pos = i;
    } else if(a[i] > sec) {
      sec = a[i];
    }
  }
  int ans=0;
  rep(i, 100005) {
    ans = max(ans, b[i] + (i == mx_pos ? sec : mx));
  }
  cout << n - ans << endl;
  return 0;
}



Measured memory_bytes: 1024
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int n, seg[N << 2], lazy[N << 2], L[N], R[N], m, num[N];
vi vl[N];

void modify(int id, int x){
	seg[id] += x;
	lazy[id] += x;
}
	
void shift(int id){
	modify(id << 1, lazy[id]);
	modify(id << 1 | 1, lazy[id]);
	lazy[id] = 0;
}
	
void add(int id, int lq, int rq, int x, int l, int r){
	if (rq <= l || r <= lq) return;
	if (lq <= l && r <= rq){
		modify(id, x);
		return;
	}
	int md = (l + r) >> 1;
	shift(id);
	add(id << 1, lq, rq, x, l, md);
	add(id << 1 | 1, lq, rq, x, md, r);
	seg[id] = max(seg[id << 1], seg[id << 1 | 1]);
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> m >> n;
	for (int i = 1; i <= m; i++){
		cin >> L[i] >> R[i];
		vl[L[i]].pb(R[i]);
	}
	int mx = 0, mx2 = 0;
	for (int i = 1; i <= n + 1; i++) add(1, i, i + 1, -(n - i + 1), 1, n + 2);
	for (int i = 0; i <= n; i++){
		for (auto u:vl[i]){
			add(1, 1, u + 1, 1, 1, n + 2);
		}
//		for (int j = 1; j <= n + 1; j++) mx2 = max(mx2, num[j] - i);
		mx = max(mx, seg[1] - i);
	}
	int mxL = 0, mxr = n + 1;
	mx = max(mx, m - n);
	cout << mx;










	return 0;
}


Measured memory_bytes: 17532
#include<stdio.h>
#define d 1000000007
int mp(long long m,int n){return n?(mp((m*m)%d,n/2)*((n%2)?m:1)%d):1;}
int main(){
    int m,n;
    scanf("%d%d",&m,&n);
    printf("%d\n",mp((long long)m,n));
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
using Graph = vector<vector<pair<ll, ll>>>;


int main()
{
    ll H, W, D; cin >> H >> W >> D;
    vector<pair<ll, ll>> v(H*W+1);
    rep(i, H) rep(j, W) {
        ll num; cin >> num; v[num] = {i, j};
    }

    vll sum(H*W+1);
    for (ll i = 1; i <= D; i++) {
        ll base = i;
        while (base < H * W + 1) {
            if (base <= D) sum[base] = 0;
            else sum[base] = sum[base - D] + abs(v[base].first - v[base - D].first) + abs(v[base].second - v[base - D].second);
            base += D;
        }
    }

    ll Q; cin >> Q;
    vll l(Q), r(Q); rep(i, Q) cin >> l[i] >> r[i];

    rep(i, Q) {
        cout << sum[r[i]] - sum[l[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 4736
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int k; string s; cin >> k >> s;
  cout << (s.length() <= k ? s : s.substr(0, k) + "...") << '\n';
  return 0;
}


Measured memory_bytes: 3656
N = int(input())
A = list(map(int,input().split()))
A.sort()
MAX = A[-1]+1
num_tmp = [0]*MAX

for a in A:
    num_tmp[a] += 1
    if num_tmp[a] == 1:
        for i in range(2*a,MAX,a):
            num_tmp[i] = 2

print(num_tmp.count(1))

Measured memory_bytes: 32140
#include <bits/stdc++.h>
using namespace std;
int N;
const int MAXN = 1e5+10;
int memo[MAXN];
vector<int> mvc;
int dfs(int u){
	if(u==(N-1))return 0;
	if(memo[u]!=-1)return memo[u];
	int ans;
	if(u<=N-3){
		ans=min(abs(mvc[u]-mvc[u+1])+dfs(u+1),abs(mvc[u]-mvc[u+2])+dfs(u+2) );
	}else if(u==N-2)ans=abs(mvc[u]-mvc[u+1] )+dfs(u+1);
	return memo[u]=ans;
}
int main(){
	int n;
	cin>>n;
	N=n;
	
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		mvc.push_back(t);
	}
	memset(memo,-1,sizeof(memo));
	int ans=dfs(0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3448
#include <cstdio>
#include <cstring>

using namespace std;

int N;
int adj[100005], gto[200005], gnxt[200005], e;
int inpath[100005], path;
int pre[100005], dis[100005];
int color[100005];

void add_edge(int u, int v) {
    gto[e] = v; gnxt[e] = adj[u]; adj[u] = e++;
}

void dfs(int s) {
    for (int e = adj[s]; ~e; e = gnxt[e])
        if (gto[e] != pre[s]) {
            pre[gto[e]] = s;
            dis[gto[e]] = dis[s] + 1;
            dfs(gto[e]);
        }
}

void dfs2(int s, int pre, int c) {
    for (int e = adj[s]; ~e; e = gnxt[e])
        if (color[gto[e]] != !c && gto[e] != pre) {
            color[gto[e]] = c;
            dfs2(gto[e], s, c);
        }
}

int main() {
    memset(color, -1, sizeof color);
    memset(adj, -1, sizeof adj);
    scanf("%d", &N);
    for (int i = 1; i != N; ++i) {
        int u, v; scanf("%d%d", &u, &v);
        add_edge(u, v); add_edge(v, u);
    }
    dfs(1);
    for (int i = N; i; i = pre[i]) inpath[path++] = i;
    for (int i = 0; i != path >> 1; ++i) color[inpath[i]] = 1;
    for (int i = path >> 1; i != path; ++i) color[inpath[i]] = 0;
    dfs2(1, 0, 0); dfs2(N, 0, 1);
    long long snuke = 0, fennec = 0;
    for (int i = 1; i <= N; ++i)
        if (color[i]) ++snuke; else ++fennec;
    puts(fennec > snuke ? "Fennec" : "Snuke");
    return 0;
}

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

int dp[100][100], a[100], b[100];
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d%d", &a[i], &b[i]);
	fill(dp[0], dp[n], INT_MAX);
	rep(i, n)dp[i][i] = 0;
	for (int i = 1; i < n; i++)rep(j, n - i + 1) {
		if (dp[j][j + i - 1] == INT_MAX)continue;
		for (int k = 0; k < j; k++) {
			if (dp[k][j - 1] == INT_MAX)continue;
			dp[k][j + i - 1] = min(dp[k][j + i - 1], dp[k][j - 1] + dp[j][j + i - 1] + a[k] * b[j - 1] * a[j] * b[j + i - 1]);
		}
		for (int k = j + i; k < n; k++) {
			if (dp[j + i][k] == INT_MAX)continue;
			dp[j][k] = min(dp[j][k], dp[j][j + i - 1] + dp[j + i][k] + a[j] * b[j + i - 1] * a[j + i] * b[k]);
		}
	}
	printf("%d\n", dp[0][n - 1]);
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int N;
  cin >> N;
  vector <int> vec(N);
  rep(i,N) cin >> vec[i];

  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int Alice = 0, Bob = 0;
  for(int i = 0; i < N; i+=2){
    Alice += vec[i];
  }
  for(int i = 1; i < N; i+=2){
    Bob += vec[i];
  }

  int sa = Alice - Bob;
  cout << sa << endl;
}


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

int main() {

    int n, m;
    cin >> n >> m;

    vector<pair<ll, ll>> V(n);

    rep(i,n) {
        ll a, b;
        cin >> a >> b;
        V[i] = make_pair(a,b);
    }

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

    ll ans = 0;
    ll cnt = 0;
    for(auto v : V) {
        ll a = v.first;
        ll b = v.second;
        if (cnt+b<m) {
            cnt += b;
            ans += a*b;
        } else {
            int d = m-cnt;
            ans += a*d;
            break;
        }
    }

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l;
    scanf("%d%d",&n,&l);
    string a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++)
        cout<<a[i];
    return 0;
}

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

ll lcm(int a,int b);
ll gcm(int a,int b);

int main(){
    ll a,b;
    int c,d;
    cin >> a >> b >> c >> d;
    ll cc = b/c - (a-1)/c;
    ll dd = b/d - (a-1)/d;
    ll ccdd = b/lcm(c,d) - (a-1)/lcm(c,d);
    //cout << cc << ' ' << dd << ' ' << lcm(c,d) << endl;
    cout << b-a+1-cc-dd+ccdd << endl;


}

ll lcm(int a,int b){
    	return a/gcm(a,b)*b;
}

ll gcm(int a,int b){
  while(max(a,b) % min(a,b) != 0)
    if(a>b) a %= b; else b %= a;
  return min(a,b);
}
  


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

int main() {
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 2e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    vi a(N); REP(i, N) cin >> a[i];
    sort(ALL(a));
    int ans = 0;
    REP(i, N-1) ans += a[i+1] - a[i];
    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

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



int main() 
{
  ll N;
  cin >> N;
  vector<ll> bot(N);
  rep (i,N)
  {
    cin >> bot.at(i);
  }
  ll num = 1;
  rep (i,N)
  {
    num = bot.at(num - 1);
    if (num == 2)
    {
      cout << i + 1 << endl;
      break;
    }
    if(i == N - 1)
    {
      cout << -1 << endl;
    }  
  }
  
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
import networkx as nx

def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    G = nx.Graph()

    for i in range(1, N+1):
        G.add_node(i)

    for i in range(M):
        G.add_edge(A[i], B[i])

    if nx.is_connected(G):
        print(0)
    else:
        print(nx.number_connected_components(G)-1)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 161000
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int t, a;

int temp(int x) {
	return t * 1000 - x * 6;
}

int main() {
	int n; cin >> n;
	cin >> t >> a;
	a *= 1000;
	int best = -1;
	int bestDiff = 1e9;

	for (int i = 0; i < n; ++i) {
		int h; cin >> h;
		int diff = abs(temp(h) - a);
		if (diff < bestDiff) {
			bestDiff = diff;
			best = i;
		}
	}
	cout << best + 1 << '\n';
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
    int x;
    int count = 1;
    while (true) {
        cin >> x;
        if (x==0) {
            break;
        }
        else {
            cout << "Case " << count << ": " << x << endl;
            count += 1;
        }
    }
    return 0;
}

Measured memory_bytes: 3080
using System;
using System.Linq;

namespace _0621
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            char[,] s = new char[x[0], x[1]];
            for (int i = 0; i < x[0]; i++)
            {
                string now = Console.ReadLine();
                for (int j = 0; j < x[1]; j++)
                {
                    s[i, j] = now[j];
                }
            }
            int b = x[0] * x[1];
            for (int i = 0; i < x[0] - 2; i++)
            {
                for (int j = i; j < x[0] - 1; j++)
                {
                    int a = 0;
                    for (int k = 0; k < x[0]; k++)
                    {
                        for (int l = 0; l < x[1]; l++)
                        {
                            if (k <= i)
                            {
                                if (s[k, l] != 'W')
                                {
                                    a++;
                                }
                            }
                            else if (k <= j)
                            {
                                if (s[k, l] != 'B')
                                {
                                    a++;
                                }
                            }
                            else
                            {
                                if (s[k, l] != 'R')
                                {
                                    a++;
                                }
                            }
                        }
                    }
                    if (b > a)
                    {
                        b = a;
                    }
                }
            }
            Console.WriteLine(b);
        }
    }
}

Measured memory_bytes: 9480
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
const int INF = 1e9;
const int MXN = 1e2 + 5;
const int MXK = 1e5 + 5;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i < (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i > (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);
vector<int> v(MXN);
int dp[MXN][MXK], sum[MXN][MXK];

int main()
{
    IOS;
    int n, k;
    cin >> n >> k;
    dp[0][k] = sum[0][k] = 1;
    FOR(i, 1, n + 1)
    {
        int x;
        cin >> x;
        FOR(j, 1, k + 1)
        {
            dp[i][j] =
                (sum[i - 1][min(k, j + x)] - sum[i - 1][j - 1] + MOD) % MOD;
        }
        dp[i][0] = sum[i][0] = sum[i - 1][x];
        FOR(j, 1, k + 1) { sum[i][j] = (sum[i][j - 1] + dp[i][j]) % MOD; }
    }
    cout << dp[n][0] << '\n';
}


Measured memory_bytes: 81732
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

a, b, c, k = map(int, input().split())

num = 0

if (a >= k):
    num = k
elif (a + b >= k):
    num = a
else:
    num = a - ((k - a - b) * 1)
print(num)    


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

const int N = 2e5 + 5;

int main() {

    string a; cin >> a;
    if(a == "SUN") {
        puts("7");
    }
    else if(a == "MON") {
        puts("6");
    }
    else if(a == "TUE") {
        puts("5");
    }
    else if(a == "WED") {
        puts("4");
    }
    else if(a == "THU") {
        puts("3");
    }
    else if(a == "FRI") {
        puts("2");
    }
    else if(a == "SAT") {
        puts("1");
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define pii pair<ll int, ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define repi(i, n) for(ll i=0; i<n; i++)
#define rep(i, a, b) for(ll i=a; i<=b; i++)
#define M 1000000007
 
using namespace std;
 
int main() {
    ios
    ll n; cin>>n;
    vector <ll> h(n);
    repi(i, n) cin>>h[i];
    vector <ll> dp(n);
    for(ll i=n-1; i>=0; i--){
        ll cur = 1e10;
        for(ll j=i+1; j<=min(n-1, i+2); j++) cur = min(cur, abs(h[i]-h[j]) + dp[j]);
        if(cur == 1e10) cur=0;
        dp[i] = cur;
    }
    cout<<dp[0];
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n, k;
const int N = 2010;
const int mod = 1e9 + 7;
ll fac[N], inv[N];

ll power(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
void init() {
    fac[0] = 1;
    for (int i = 1; i < N; ++i) {
        fac[i] = fac[i - 1] * i % mod;
    }
    inv[N - 1] = power(fac[N - 1], mod - 2);
    for (int i = N - 2; i >= 0; --i) {
        inv[i] = inv[i + 1] * (i + 1) % mod;
    }
}

ll C(ll a, ll b) {
    return fac[a] * inv[b] % mod * inv[a - b] % mod;
}

int main() {
    init();
    cin >> n >> k;
    int r = n - k;
    for (int i = 1; i <= k; ++i) {
        if (i > r + 1) { // put i into r + 1 slots
            cout << 0 << endl;
        } else {
            int res = C(r + 1, i) * C(k - 1, i - 1) % mod;
            cout << res << endl;
        }
    }
    return 0;
}


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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------
//重み付きunion-find

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int N = 1, Abel SUM_UNITY = 0) {
        init(N, SUM_UNITY);
    }

    void init(int N = 1, Abel SUM_UNITY = 0) {
        par.resize(N);
        rank.resize(N);
        diff_weight.resize(N);
        for (int i = 0; i < N; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool unite(int x, int y, Abel w) {
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

//------------------------------------------------------

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind<int> uf(n);

    rep(i, m) {
        int l, r, d;
        cin >> l >> r >> d;
        if (uf.issame(l, r) && uf.diff(l, r) != d) {
            cout << "No" << endl;
            return 0;
        } else {
            uf.unite(l, r, d);
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	long a[n+1], b[n];
	for(int i = 0; i < n+1; ++i) cin >> a[i];
	for(int i = 0; i < n; ++i) cin >> b[i];
	
	long long monster = 0;
	
	for(int i = 0; i < n; ++i)
	{
		long left = max(0l, a[i] - b[i]);
		b[i] -= a[i] - left;
		monster += a[i] - left;
		
		long right = max(0l, a[i+1] - b[i]);
		monster += a[i+1] - right;
		a[i+1] = right;
	}
	
	cout << monster << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node{
	int key;
	Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
	Node *cur = nil->next;///??????????¬????????´????????????°???
	while (cur != nil && cur->key != key){
		cur = cur->next;
	}
	return cur;
}

void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printList(){
	Node *cur = nil->next;
	int isf = 0;
	while (1){
		if (cur == nil) break;
		if (isf++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t){
	if (t == nil)return;//t??????????????´??????????????????
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	//????´¢????????????????????????
	deleteNode(listSearch(key));
}

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	//???????????´??????????´??????????
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main(){
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++){
		scanf("%s%d", com, &key);
		if (com[0] == 'i') { insert(key); np++; size++; }
		else if (com[0] == 'd'){
			if (strlen(com) > 6){
				if (com[6] == 'F') deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}
			else{
				deleteKey(key); nd++;
			}
			size--;
		}
	}
	printList();
	return 0;
}

Measured memory_bytes: 32216
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>

using namespace std;

#define N 1100
#define INF 111111111111111111ll

typedef long long ll;

struct Edge {
    ll from, to, cost;
};

int n, m;
ll d[N];
vector<Edge> G[N];
int cnt[N], inq[N];

bool bellman(int s) {
    queue<int> q;
    memset(cnt, 0, sizeof(cnt));
    memset(inq, 0, sizeof(inq));
    for (int i = 0; i <= n; ++i) d[i] = INF;
    d[s] = 0; inq[s] = 1; q.push(s);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        inq[u] = 0;
        for (int i = 0; i < G[u].size(); ++i) {
            Edge e = G[u][i];
            if (d[u] < INF && d[e.to] > d[u] + e.cost) {
                d[e.to] = d[u] +e.cost;
                if (!inq[e.to]) {
                    q.push(e.to); inq[e.to] = 1;
                    if (++cnt[e.to] > n) return false;
                }
            }
        }
    }
    return true;
}

int main() {
    while (scanf("%d%d", &n, &m) != EOF) {
        for (int i = 0; i <= n; ++i) G[i].clear();
        for (int i = 0; i < m; ++i) {
            int u, v; ll w;
            scanf("%d%d%lld", &u, &v, &w);
            G[v].push_back((Edge){v, u, -w});
        }
        if (!bellman(n)) puts("inf"); else printf("%lld\n", -d[1]);
    }
    return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 2e9;



int main() {
	int n; cin >> n;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	rep(i, 0, n - 1) a[i + 1] ^= a[i];
	vector<vector<int>> dp(2);
	rep(i, 0, 2) dp[i].resize(1 << 20,0);
	fill(dp[0].begin(), dp[0].end(), 1);
	vector<int> cnt(1 << 20, 0);
	int idx = 0;
	rep(i, 0, n) {
		if (a[i] == 0) idx++;
		else {
			dp[0][a[i]] = (dp[0][a[i]] + 1LL*dp[1][a[i]] * (idx - cnt[a[i]])) % mod;
			dp[1][a[i]] = (dp[1][a[i]] + dp[0][a[i]]) % mod;
			cnt[a[i]] = idx;
		}
	}
	if (a[n - 1] != 0) printf("%d", dp[0][a[n - 1]]);
	else {
		ll ans = 1;
		rep(i, 0, idx - 1) ans = (2LL * ans) % mod;
		rep(i, 0, 1 << 20) ans = (ans + dp[1][i]) % mod;
		printf("%lld", ans);
	}
	return 0;
}


Measured memory_bytes: 14464
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	swap(a,b);
	swap(a,c);
	printf("%d %d %d\n",a,b,c);
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>

using namespace std;

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

int main() {
    //clock_t start = clock();
    ios::sync_with_stdio(false); cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, m; cin >> n >> m;
    long a[55], b[55], c[55], d[55];
    for (int i=0; i<n; ++i) cin >> a[i] >> b[i];
    for (int i=0; i<m; ++i) cin >> c[i] >> d[i];
    for (int i=0; i<n; ++i) {
    	long res = 10000000000;
    	int cnt = 1;
    	for (int j=0; j<m; ++j) {
    		long dis = abs(a[i]-c[j]) + abs(b[i]-d[j]);
    		// cout << "dis = " << dis << endl;
    		if (dis < res) {
    			res = dis;
    			cnt = j + 1;
    		}
    	}
    	cout << cnt << endl;
    }
    //clock_t stop = clock();
    //cout << (double)(stop-start)/CLOCKS_PER_SEC << " (s)" << endl;
    return 0;
}


Measured memory_bytes: 256
line = input()
num_lst = list(map(int, line.split()))
r = num_lst[0] #4
c = num_lst[1] #5
#print(r, c)
array = []
last_row = []
for i in range(r):
    line = input()
    lst = list(map(int, line.split()))
    #print(line)
    num = sum(lst)
    lst.append(num)
    array.append(lst)
#print(array)

s = 0
for i in range(c+1):
    for j in range(r):
        s += array[j][i]
    last_row.append(s)
    s = 0
#print(last_row)
array.append(last_row)
#print(array)
for line in array:
    t = " ".join([str(n) for n in line])
    print(t)


Measured memory_bytes: 5700
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);

    set<pii> st;

    rep(i, 3) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        st.insert(MP(a, b));
        st.insert(MP(b, a));
    }

    vector<int> p = {0, 1, 2, 3};
    do {
        bool can = true;

        rep(i, 3) {
            if (!st.count(MP(p[i], p[i + 1]))) can = false;
        }

        if (can) {
            YES(true);
            return 0;
        }
    } while (NP(p));
    YES(false);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
//#include <list>
//#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)

void printVec(std::vector<int> &vec) {
//    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        std::cout << *it << " ";
    }
    cout << '\n';
}

void printVec1(std::vector<string> &vec) {
//    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        std::cout << *it << " ";
    }
    cout << '\n';
}

void printVec2(std::vector<Int> &vec) {
//    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        std::cout << *it << " ";
    }
    cout << '\n';
}

Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

bool ispositive(Int num,int i) {
    if (num > 0) return true;
    if (num < 0) return false;
    else if(i==0) return false;
    else return true;
}

int main() {
    IOS;
    //std::ifstream in("01-04.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    Int sum1 = 0, sum2 = 0;
    Int cnt1=0,cnt2=0;
    for (int i = 0; i < n; i++) {
        Int temp;cin>>temp;
        sum1+=temp;
        sum2+=temp;
        if(i%2==0&&!ispositive(sum1,0)){
            cnt1+=1-sum1;
            sum1=1;
        }
        if(i%2==1&&ispositive(sum1,1)){
            cnt1+=sum1+1;
            sum1=-1;
        }
        if(i%2==1&&!ispositive(sum2,0)){
            cnt2+=1-sum2;
            sum2=1;
        }
        if(i%2==0&&ispositive(sum2,1)){
            cnt2+=sum2+1;
            sum2=-1;
        }
        //cout<<sum2<<" ";
    }
    //if(sum1==0)cnt1++;
    //if(sum2==0)cnt2++;

    //cout<<cnt1<<" "<<cnt2;
    cout<<min(cnt2,cnt1);


    cout << endl;
    return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


Measured memory_bytes: 1016
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    int n,l;
    cin>>n>>l;

    ll sum = (n*(n+1))/2;
    ll total = (l-1)*n;
    ll left = l;
    ll right = l+n-1;
    ll ans = 0;

    if( left <= 0 && right >= 0 )
        ans = sum + total;
    else if( left <= 0 )
        ans = sum + total - right;
    else if( right >= 0 )
        ans = sum + total - left;

    cout<<ans,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <map>

using namespace std;

#define MAX 500002

int left(int i){
    return i*2;
}
int right(int i){
    return i*2+1;
}

/*
 *  添字indexから始まる部分木がmax-ヒープになるようにする。
 *
 * */
void maxHeapify(int *heap,int index,int H){
    int l;int r=-1;
    if(left(index)<=H){
        l=left(index);
    }
    if(right(index)<=H){
        r=right(index);
    }

    int largest;
    if(l<=H&&heap[l]>heap[index]){
        largest=l;
    }else{
        largest=index;
    }

    if(r>=1&&r<=H&&heap[r]>heap[largest]){
        largest=r;
    }

    if(largest!=index){
        swap(heap[index],heap[largest]);
        maxHeapify(heap,largest,H);
    }

}

/*
 *
 * ボトムアップに、部分木をmax-ヒープにすることで全体木をmax-ヒープにする。
 *
 * */
void buildMaxHeap(int *heap,int H){
    for(int i=H/2;i>=1;i--){
        maxHeapify(heap,i,H);
    }
}

void printHeap(int *heap,int H){
    for(int i=1;i<=H;i++){
        printf(" %d",heap[i]);
    }
}

int main() {


    int heap[MAX];
    int H;scanf("%d",&H);

    for(int i=1;i<=H;i++){
        scanf("%d",&heap[i]);
    }

    buildMaxHeap(heap,H);

    printHeap(heap,H);
    
    printf("\n");

    return 0;
}


Measured memory_bytes: 5152
/*
 * Author : Sadi
 * Mon 20/07/2020
 * 21:54:32.03
 */
#include <bits/stdc++.h>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;

long long gcd(long long a, long long b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    long long n, k;
    cin >> n >> k;
    cout << min(n % k, k - n % k) << "\n";

    return 0;
}


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

int main()
{
	string s, ans;
	cin >> s;

	ans = s.substr(1, s.size() - 1);

	cout << s.substr(0, 1) << ans.size() - 1 << s.substr(s.size() - 1, 1) << endl;
}



Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

string next(string S){
	int size = S.size();
	for(int i = 0; i < size; i++){
		if(S[i] == '3'){
			S[i] = '5';
			return S;
		}
		if(S[i] == '5'){
			S[i] = '7';
			return S;
		}
		S[i] = '3';
	}
	S.push_back('3');
	return S;
}
bool is753(string S){
	bool t = false, f = false, s = false;
	int size = S.size();
	for(int i = 0; i < size; i++){
		if(S[i] == '3')t = true;
		else if(S[i] == '5')f = true;
		else if(S[i] == '7')s = true;
	}
	return (t && f && s);
}
int main(){

	ll N;
	cin >> N;
	if(N < 357){
		cout << 0 << endl;
		return 0;
	}
	string S = "553", r;
	ll a, ans = 0;
	while(true){
		S = next(S);
		r = S;
		reverse(r.begin(), r.end());
		a = stoi(r);
		if(a > N)break;
		if(is753(S))ans++;
		//cout << S << endl;
		if(S == "777777777")break;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>
#define MAX 150
int am[MAX][MAX];

int main()
{
  int i,j,k,n,t;

  scanf("%d",&n);
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      am[i][j] = 0;

  for(i=1;i<=n;i++)
  {
    scanf("%d%d",&j,&k);
    for(j=1;j<=k;j++)
    {
       scanf("%d",&t);//iの次の人たち
       am[i][t] = 1;
    }
  }

  for(i=1;i<=n;i++) //１行目、２行目
  {
    for(j=1;j<=n;j++)
    {
     printf("%d", am[i][j]);
     if (j != n) printf(" ");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2132
DXYS = [[0, 1], [0, -1], [-1, 0], [1, 0], [1, 1], [-1, -1], [-1, 1], [1, -1]]

def initial_position(tiles)
  tiles.size.times do |j|
    tiles[0].size.times do |i|
      return [j, i] if tiles[j][i] == 1
    end
  end
  return []

end

def dfs(tiles, j, i)
  return if j<0 || tiles.size <= j
  return if i<0 || tiles[0].size <= i
  return if tiles[j][i] != 1 #???

  tiles[j][i] = 2 #?¨??????????

  DXYS.map do |dx,dy|
    dfs(tiles, j+dy, i+dx)
  end
end

loop do
  width, height = gets.split.map(&:to_i)
  break if width == 0 && height == 0

  #?????????
  tiles = []
  height.times {tiles << gets.split.map(&:to_i)}
  island_count = 0

  while (position=initial_position(tiles)) != []
    island_count += 1
    dfs(tiles, position[0], position[1])
  end

  p island_count
end

Measured memory_bytes: 14004
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  if(a>b){
    ans += a;
    a--;
  }else{
    ans += b;
    b--;
  }
  if(a>b){
    ans += a;
    a--;
  }else{
    ans += b;
    b--;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<cstring>
#include<stack>
#include<cstdlib>
#include<cmath>
using namespace std;

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

	int cnt = 0;
	while (n > 0) {
		if (n % 10 == 2)
			cnt++;
		n /= 10;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
import numpy as np
from sys import stdin
input = stdin.readline
N = int(input())
A = list(map(int, input().split()))
number = np.zeros(N, dtype = int)
total = 0

dic = {}
a = sorted(A)
now_key = a[0]
value = 1
dic[now_key] = 1
for i in range(1,N):
  if a[i] == now_key:
    value += 1
  else:
    dic[now_key] = value
    if value >= 2:
      total += value * (value-1) // 2
    now_key = a[i]
    value = 1
dic[now_key] = value
if value >= 2:
  total += value * (value-1)//2
for j in A:
  print(total - dic[j] + 1)

Measured memory_bytes: 35872
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func calc(x1, y1, x2, y2 int, a [][]int) int {
	ret := a[x2][y2] + a[x1][y1] - a[x1][y2] - a[x2][y1]
	// out(x1, y1, x2, y2, ret)
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	N, K := getInt(), getInt()
	black := make([][]int, 2*K+1)
	white := make([][]int, 2*K+1)
	for i := 0; i <= 2*K; i++ {
		black[i] = make([]int, 2*K+1)
		white[i] = make([]int, 2*K+1)
	}
	for i := 0; i < N; i++ {
		x, y, c := getInt(), getInt(), getString()
		x %= 2 * K
		y %= 2 * K
		if c == "B" {
			black[x+1][y+1]++
		} else {
			white[x+1][y+1]++
		}
	}

	// out("Black")
	// for i := 0; i <= 2*K; i++ {
	// 	for j := 0; j <= 2*K; j++ {
	// 		fmt.Print(black[j][i], " ")
	// 	}
	// 	out()
	// }
	// out("white")
	// for i := 0; i <= 2*K; i++ {
	// 	for j := 0; j <= 2*K; j++ {
	// 		fmt.Print(white[j][i], " ")
	// 	}
	// 	out()
	// }
	for i := 0; i <= 2*K; i++ {
		for j := 1; j <= 2*K; j++ {
			black[i][j] += black[i][j-1]
			white[i][j] += white[i][j-1]
		}
	}
	for i := 0; i <= 2*K; i++ {
		for j := 1; j <= 2*K; j++ {
			black[j][i] += black[j-1][i]
			white[j][i] += white[j-1][i]
		}
	}

	ans := 0
	for i := 0; i < K; i++ {
		for j := 0; j < K; j++ {
			// out(i, j, "-------")
			b0 := 0
			b1 := 0
			w0 := 0
			w1 := 0
			// out("black")
			b0 += calc(0, 0, i, j, black)
			b1 += calc(i, 0, i+K, j, black)
			b0 += calc(i+K, 0, 2*K, j, black)

			b1 += calc(0, j, i, j+K, black)
			b0 += calc(i, j, i+K, j+K, black)
			b1 += calc(i+K, j, 2*K, j+K, black)

			b0 += calc(0, j+K, i, 2*K, black)
			b1 += calc(i, j+K, i+K, 2*K, black)
			b0 += calc(i+K, j+K, K*2, K*2, black)
			// out("white")
			w0 += calc(0, 0, i, j, white)
			w1 += calc(i, 0, i+K, j, white)
			w0 += calc(i+K, 0, 2*K, j, white)

			w1 += calc(0, j, i, j+K, white)
			w0 += calc(i, j, i+K, j+K, white)
			w1 += calc(i+K, j, 2*K, j+K, white)

			w0 += calc(0, j+K, i, 2*K, white)
			w1 += calc(i, j+K, i+K, 2*K, white)
			w0 += calc(i+K, j+K, K*2, K*2, white)
			ret := max(w0+b1, w1+b0)
			// out(ret)
			ans = max(ans, ret)
		}
	}
	out(ans)
}


Measured memory_bytes: 70528