akhauriyash/Code-Regression huggingface dataset:
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
def ok(a,b,c):
    return c < a+b
for i in range(n):
    for j in range(i+1,n):
        bot = j
        top = n
        while top-bot > 1:
            mid = (top+bot)//2
            if ok(l[i],l[j],l[mid]):bot = mid
            else:top = mid
        ans += bot - j
print(ans)

Measured memory_bytes: 43116
using System;

namespace helloworld {
    class Program {
        static void Main(string[] args) {
            var input = Console.ReadLine();
            var a = int.Parse(input.Split(' ')[0]);
            var b = int.Parse(input.Split(' ')[1]);

            var area = a * b;
            var length = 2 * (a + b);

            Console.WriteLine(area + " " + length);
        }
    }
}

Measured memory_bytes: 8948
#include<bits/stdc++.h>
#define mod 1000000007
#define maxi 1e18
#define ll long long
#define pb push_back
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define flr(i,a,b) for(ll i=a;i>b;i--)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define keep_unique(v) sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
#define print(v) for(auto i=v.begin();i!=v.end();i++){cout<<*i<<" ";}cout<<"\n";
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define pi 3.141592653589
using namespace std;
int main()
{
	fast;
	ll n,w;
	cin>>n>>w;
	ll c[n],v[n];
	fl(i,0,n)
		cin>>c[i]>>v[i];
	ll dp[n+1][w+1];
	fl(i,0,n+1)
	{
		fl(j,0,w+1)
		{
			if(i==0 || j==0)
				dp[i][j] = 0;
			else if(c[i-1]<=j)
				dp[i][j] = max((v[i-1]+dp[i-1][j-c[i-1]]),dp[i-1][j]);
			else
				dp[i][j] = dp[i-1][j];
		}
	}
	cout<<dp[n][w]<<"\n";
}


Measured memory_bytes: 79232
fn main(){
    let a: u32 = read();

    println!("{}", a + a * a + a * a * a);
}

#[allow(dead_code)]
fn read<T>() -> T
where T: std::str::FromStr,
      T::Err: std::fmt::Debug
{
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).expect("failed to read");
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 2084
#include <stdio.h>

int main(void)
{
	int S;
	scanf("%d", &S);

	int hour, minute, second;
	int a, b;

	a = S/60;
	hour = a/60;
	b = S-(hour*60*60);
	minute = b/60;
	second = b%60;

	printf("%d:%d:%d\n", hour, minute, second);
}

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

const long long MOD=1000003;
long long fac[MOD], finv[MOD], inv[MOD];

long long mypow(long long x,long long n,long long m){
	if(n==0) return 1;
	if(n%2==0) return mypow((x*x)%m,n/2,m);
	else return (x*mypow(x,n-1,m))%m;
} 

long long gcd(long long x,long long y){
	if(y==0) return x;
	return gcd(y,x%y);
}

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MOD; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

int main() {
	long long q,x,d,n,i,con,ans=0,g;
	COMinit();
	cin >> q;
	for(i=1;i<=q;i++){
		cin >> x >> d >> n;
		if(d==0){
			cout << mypow(x,n,MOD) << endl;
			continue;
		}
		g=gcd(x,d);
		x=x/g;
		d=d/g;
		con=((MOD-x)*inv[d])%MOD;
		if((n-1)>=con){
			cout << "0" << endl;
		} else {
			con=(x*inv[d])%MOD;
			ans=(fac[con+n-1]*inv[fac[con-1]])%MOD;
			ans=(ans*mypow(d,n,MOD))%MOD;
			ans=(ans*mypow(g,n,MOD))%MOD;
			cout << ans << endl;
		}
	}
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    string x = "x";
    int l = s.size();
    rep(i,l-1) x += "x";
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    TreeMap<Integer, Integer> map = new TreeMap<>();
    for (int i = 1; i <= n; i++) {
      int num = sc.nextInt();
      map.put(num, i);
    }
    for(int num: map.values()) {
      System.out.print(num + " ");
    }
    System.out.println();
  }
}


Measured memory_bytes: 69988
N = int(input())
A = list(map(int, input().split()))
B = [0]*60
mod = 10 ** 9 + 7

for x in A:
  temp = bin(x)[2:]
  for i in range(len(temp)):
    if temp[-1-i] == "1":
      B[i] += 1

ans = 0

for i in range(60):
  ans += (N-B[i])*B[i]*pow(2, i, mod)
  ans %= mod

print(ans)


Measured memory_bytes: 124488
// 2020-09-20 16:41:00
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
#include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
using namespace atcoder;

// clang-format on
const ll MX = 1e9;
void answer() {
  int n, k;
  cin >> n >> k;
  mcf_graph<int, ll> G(2 * n + 2);
  int s = 2 * n, t = s + 1;
  G.add_edge(s, t, n * k, MX);
  rep(i, n) {
    G.add_edge(s, i, k, 0);
    G.add_edge(n + i, t, k, 0);
  }
  rep(i, n) rep(j, n) {
    ll a;
    cin >> a;
    G.add_edge(i, n + j, 1, MX - a);
  }
  auto [cap, cost] = G.flow(s, t, n * k);
  vector<string> ans(n, string(n, '.'));
  for (auto& edge : G.edges()) {
    if (edge.flow == 0) continue;
    if (edge.from == s) continue;
    if (edge.to == t) continue;
    ans[edge.from][edge.to - n] = 'X';
  }
  cout << ll(n) * k * MX - cost << '\n';
  for (auto& a : ans) cout << a << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

int main() {
    int a, b, c, k, f, g;
    cin>>a>>b>>c;
    cin>>k;
    if(a<b&&b<c)
        cout<<"Yes";
    else 
    {
       f = 0;
       if(a>=b)
       {
           while(a >= b)
           {
               b*=2; f++;
           }
       }
       if(b>=c)
       {
           while(b >= c)
           {
               c*=2; f++;
           }
       }
       if (f <= k)
           cout<<"Yes";
       else
           cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define ppll pair<pll,ll>
#define vi vector <ll>
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define f(i,x,n) for(ll i=x;i<n;i++)
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;} 
const ll N = 1e6 + 5, M = 1e18 + 7; 

int main(){
    FAST;
    ll n, k, t, m = 0, x = 0, i, ans = 0, j, y = 0, z = 4, c = 0;
    string s;
    cin >> n >> s;

    set<ll> st[3];

    f(i, 0, n){
        if(s[i] == 'R') st[0].insert(i);
        if(s[i] == 'G') st[1].insert(i);
        if(s[i] == 'B') st[2].insert(i);
    }

    f(i, 0, n){
        f(j, 0, i){
            if(s[i] == 'R' && s[j] == 'G'){
                ans += st[2].size();
                if((i + j) % 2 == 0) if(st[2].find((i + j)/2) != st[2].end()) ans --;
                if(st[2].find(2*i - j) != st[2].end()) ans --;
                if(st[2].find(2*j - i) != st[2].end()) ans --;
            }
            else if(s[i] == 'R' && s[j] == 'B'){
                ans += st[1].size();
                if((i + j) % 2 == 0) if(st[1].find((i + j)/2) != st[1].end()) ans --;
                if(st[1].find(2*i - j) != st[1].end()) ans --;
                if(st[1].find(2*j - i) != st[1].end()) ans --;
            }
            else if(s[i] == 'G' && s[j] == 'R'){
                ans += st[2].size();
                if((i + j) % 2 == 0) if(st[2].find((i + j)/2) != st[2].end()) ans --;
                if(st[2].find(2*i - j) != st[2].end()) ans --;
                if(st[2].find(2*j - i) != st[2].end()) ans --;
            }
            else if(s[i] == 'G' && s[j] == 'B'){
                ans += st[0].size();
                if((i + j) % 2 == 0) if(st[0].find((i + j)/2) != st[0].end()) ans --;
                if(st[0].find(2*i - j) != st[0].end()) ans --;
                if(st[0].find(2*j - i) != st[0].end()) ans --;
            }
            else if(s[i] == 'B' && s[j] == 'R'){
                ans += st[1].size();
                if((i + j) % 2 == 0) if(st[1].find((i + j)/2) != st[1].end()) ans --;
                if(st[1].find(2*i - j) != st[1].end()) ans --;
                if(st[1].find(2*j - i) != st[1].end()) ans --;
            }
            else if(s[i] == 'B' && s[j] == 'G'){
                ans += st[0].size();
                if((i + j) % 2 == 0) if(st[0].find((i + j)/2) != st[0].end()) ans --;
                if(st[0].find(2*i - j) != st[0].end()) ans --;
                if(st[0].find(2*j - i) != st[0].end()) ans --;
            }
        }
    }
    cout << ans/3;
}   

Measured memory_bytes: 3836
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = in.nextInt();
            int[] res = new int[n];
            res[0] = 0;
            for (int i = 1; i < n; i++) {
                res[i] = Integer.MAX_VALUE;
                for (int j = 1; j <= k; j++) {
                    if (i - j >= 0) {
                        res[i] = Math.min(res[i - j] + Math.abs(arr[i] - arr[i - j]), res[i]);
                    }
                }
            }
            out.println(res[n - 1]);
        }

    }
}



Measured memory_bytes: 50784
# greedy is all you need
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right


def score(D, C, S, T):
    last = [-1] * 26
    # scores = [0]
    score = 0
    for d in range(D):
        # scores.append(scores[-1] + S[d][T[d]])
        score += S[d][T[d]]
        last[T[d]] = d
        for i in range(26):
            # scores[-1] -= C[i] * (d - last[i])
            score -= C[i] * (d - last[i])  # この場で一番罰則が大きいやつを使うとか？
    return score


D = a_int()
C = ints()
S = read_tuple(D)

T = []

last = [-1] * 26
for d in range(D):
    ma = -INF
    for i in range(26):
        tmp = S[d][i] + C[i] * (d - last[i])
        if tmp > ma:
            t = i
            ma = tmp
    last[t] = d  # Tを選んだあとで決める
    T.append(t)

# print(score(D, C, S, T))

print(*mina(*T, sub=-1), sep='\n')


Measured memory_bytes: 71464
import java.util.Scanner;

//AtCoder Beginner Contest 120
//C	Unification
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();

		sc.close();

		int N = S.length();

		int red = 0;
		int blue = 0;

		for (int i = 0; i < N; i++) {
			if (S.charAt(i) == '0') red++;
			if (S.charAt(i) == '1') blue++;
		}

		System.out.print(Math.min(red, blue) * 2);
	}
}


Measured memory_bytes: 25044
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main(){
  ll A,B=0,C;cin >> A;
  rep(i,A){
    cin >> C;
    B+=C;
  }
  cout << B-A << endl;
}

Measured memory_bytes: 256
#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)
using LL = long long;
using ULL = unsigned long long;

const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
const double pi = acos(-1.0);

int b[601123], d[601123];

int main()
{
    int n, k;
    cin >> n >> k;
    int *a = b + 200123, *c = d + 200123;
    Rep(i, n) scanf("%d", a+i);
    while(k--) {
        memset(c-n, 0, sizeof(int)*(2*n+1));
        Rep(i, n) ++c[i-a[i]], --c[i+a[i]+1];
        for(int i = -n; i <= n; ++i) c[i] += c[i-1];
        swap(a, c);
        int cnt = 0;
        Rep(i, n) cnt += a[i] == n;
        if(cnt == n) break;
    }
    // cout << k << endl;
    Rep(i, n) printf("%d%c", a[i], " \n"[i==n]);
    return 0;
}




Measured memory_bytes: 8408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
const ll INF = 1<<30;

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

int main(){
    string s,t; cin >> s >> t;
    int sizes = s.size(),sizet =  t.size();
    vector<vector<int> > dp(3030,vector<int>(3030,0));
    rep(i,sizes){
        rep(j,sizet){
            if(s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
            chmax(dp[i+1][j+1],dp[i+1][j]);
            chmax(dp[i+1][j+1],dp[i][j+1]);
        }
    }
    string res = "";
    int i = (int)s.size(), j = (int)t.size();
    while (i > 0 && j > 0)
    {
        // (i-1, j) -> (i, j) と更新されていた場合
        if (dp[i][j] == dp[i-1][j]) {
            --i; // DP の遷移を遡る
        }

        // (i, j-1) -> (i, j) と更新されていた場合
        else if (dp[i][j] == dp[i][j-1]) {
            --j; // DP の遷移を遡る
        }

        // (i-1, j-1) -> (i, j) と更新されていた場合
        else {
            res = s[i-1] + res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
            --i, --j; // DP の遷移を遡る
        }
    }
    cout << res << endl;
}


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

int main() {
  int N,Count;
  cin >> N;
  Count = 0;
  for(int i = 0; i<N; i++){
    int l,r;
    cin >> l >> r;
    Count += r-l+1;
  }
  cout << Count << endl;
}

Measured memory_bytes: 256
from functools import reduce
import math

n,x=map(int,input().split())
a=sorted(map(int,input().split()))
a=[i-x for i in a]

if len(a)==1:print(abs(a[0]));exit()
if len(a)==2:print(math.gcd(a[0],a[1]));exit()

l=[]
for y in range(n-1):
    l.append(a[y+1]-a[y])
    
print(reduce(lambda x,y:math.gcd(x,y),l))

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

using namespace std;

int a[105];
int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a,a+n,greater<int> ());
  int alice = 0;
  int bob = 0;
  for(int i = 0; i < n; i++) {
    if(i % 2 == 0) alice += a[i];
    else bob += a[i];
  }

  cout << alice - bob << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <vector>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,a,b,x[3];
int main(){
	cin>>n>>a>>b;
	rep(i,n){
		int p; cin>>p;
		if(p<=a) x[0]++;
		else if(p<=b) x[1]++;
		else x[2]++;
	}
	cout<<min(x[0],min(x[1],x[2]))<<endl;
}

Measured memory_bytes: 256
program main
implicit None
	integer(8),allocatable::a(:),b(:),w(:),g(:),g2(:)
	integer(8)::n,k,i,p,j,c
	
	read*,n,k
	allocate(a(n),b(n))
	
	read*,a
	b = a
	
	c = int(log(real(k))/log(real(2)))+1
	allocate(w(c),g(c))
	
	do j = 1,c
		p = 0
		do i = 1,n
			p = p + mod(a(i),2)
			a(i) = a(i)/2
		enddo
		w(j) = p
	enddo
	
	p = 0
	do j = c,1,-1
		if(w(j) >= n-w(j))then
			g(j) = 0
			else
			g(j) = 1
			p = p + 2**(j-1)
			
			if (p > k)then
				g(j) = 0
				p = p-2**(j-1)
			endif
		endif
	enddo
	
	k = 0
	do i = 1,n
		k = k + xor(p,b(i))
	enddo
	
	print "(i0)",k
	
end program main

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

string S, T;

string LCS(string s, string t) {
    int sl = s.length();
    int tl = t.length();
    int dp[sl+1][tl+1];

    for (int i = 0; i < sl+1; i++) {
        dp[i][0] = 0;
    }
    for (int j = 0; j < tl+1; j++) {
        dp[0][j] = 0;
    }

    for (int i = 1; i < sl+1; i++) {
        for (int j = 1; j < tl+1; j++) {
            if (s[i-1] == t[j-1]) {
                dp[i][j] = max(dp[i-1][j], max(dp[i][j-1], dp[i-1][j-1] + 1));
            }
            else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    string ret = "";
    int i = sl, j = tl;
    while (i > 0 && j > 0) {
        if (dp[i-1][j] == dp[i][j]) i--;
        else if (dp[i][j-1] == dp[i][j]) j--;
        else {
            ret = s[i-1] + ret;
            i--;
            j--;
        }
    }

    return ret;
}

int main() {
    cin >> S >> T;

    cout << LCS(S, T) << endl;

    return 0;
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    LL N,K;cin >> N >> K;
    LL ans = 0;

    for(LL i = K;i <= N+1;i++){
        LL st = (i-1)*i/2;
        LL en = (N)*(N+1)/2;
        en -= ((N-i)*(N-i+1)/2);
        
        ans += (en - st +1);
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N;
    cin >> N;

    char c[N + 1];
    cin >> c;
    
    ll countR = 0;
    ll cumulativeW[N];
    rep(i, N){
        if(c[i] == 'R'){
            countR++;
        }
        cumulativeW[i] = (i + 1) - countR;
    }

    cout << cumulativeW[countR - 1] << endl;

    return 0;
}

Measured memory_bytes: 5352
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    int five=0,seven=0;
    for(int i=0;i<3;i++)
    {
        if(a[i]==5)
        {
            five++;
        }
        else if(a[i]==7)
        {
            seven++;
        }
    }
    if(five==2 && seven==1)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}







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

using namespace std;

int main() {
  auto dsum = [](int x) {
    int ret = 0;
    while (x) {
      ret += x % 10;
      x /= 10;
    }
    return ret;
  };
  int n;
  scanf("%d", &n);
  int ans = 1e9;
  for (int i = 1; i < n; i++) {
    ans = min(ans, dsum(i) + dsum(n - i));
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
n,d=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]

cnt=0

for i in range(n-1):
  for j in range(i+1,n):
    X=0
    for k in range(d):
      X+=(A[i][k]-A[j][k])**2
    if (X**0.5)==((X**0.5)//1):    
      cnt+=1
print(cnt)

Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;
void enqueu(P);
P dequeu(void);
int min(int,int);


P Q[LEN+1];
int head,tail,n;

int main(){
  int elaps=0,c,i,q;
  P u;
  scanf("%d%d",&n,&q);

  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);

    }
      tail=n+1;
      head=1;
      while(head!=tail){
  u=dequeu();
  c=min(q,u.t);
  u.t=u.t-c;
  elaps=elaps +c;
  if(u.t>0)enqueu(u);
  else{
    printf("%s %d\n",u.name,elaps);

  }
      }
  return 0;
}

void enqueu(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeu(void){
  P x;
  x=Q[head];
  head=(head+1)%LEN;
  return x;
}

int min(int s,int t){
  if(s<t)return s;
  else return t;
}



Measured memory_bytes: 11872
n,m,k = map(int,input().split())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

a, b = [0], [0]
for i in range(n):
     a.append(a[i] + A[i])
for i in range(m):
     b.append(b[i] + B[i])

ans, j = 0, m
for i in range(n + 1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)


Measured memory_bytes: 47356
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    int ans = 1;
    repq(i,1,n) {
        ans = (ans * i) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vi vector<int>
#define pb push_back
using namespace std;
const int SIZE=1e5;
vector<int>v[SIZE];
queue<int>q;
int in[SIZE],n,N,M,a,b;
vi ans(SIZE,-1);
void kill(int now)
{
	for(int j=0;j<v[now].size();j++)
	{ 
		in[v[now][j]]--;
		if(in[v[now][j]]==0)
		{
			q.push(v[now][j]);
			ans[v[now][j]]=now;
		}
	}
}
void tuopu()
{
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		kill(x);
	}
}
int main()
{
	cin>>N>>M;
	n=N-1+M;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		a--,b--;
		in[b]++;
		v[a].pb(b); 
	}
	for(int i=0;i<N;i++)
	{
		if(in[i]==0)
		{
			q.push(i);
			break;
		}
	}
	tuopu();
	for(int i=0;i<N;i++)cout<<ans[i]+1<<' ';
}

Measured memory_bytes: 7040
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, long long K, std::vector<long long> A){
    cout << (int)ceil((N-1.0)/(K-1.0)) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
# frozen_string_literal: true

arr = gets.chomp!.split('')

a_index = nil
z_index = nil

arr.each.with_index do |e, i|
  a_index = i if e == 'A' && a_index.nil?

  z_index = i if e == 'Z'
end

puts z_index - a_index + 1


Measured memory_bytes: 12668
//By Vlgd
#include<bits/stdc++.h>
#define INF 2000000000
using namespace std;
int H[2000005],h=0;
void insert(int x){
	int i=++h;
	H[i]=x;
	while (i>1&&H[i/2]<H[i]){
		swap(H[i/2],H[i]);
		i/=2;
	}
}
void heapify(int i){
	int l=2*i,r=2*i+1,large;
	if (l<=h&&H[l]>H[i]) large=l;
	else large=i;
	if (r<=h&&H[r]>H[large]) large=r;
	if (large!=i){
		swap(H[i],H[large]);
		heapify(large);
	}
}
int extract(){
	if (h<1) return -INF;
	int max=H[1];
	H[1]=H[h--];
	heapify(1);	
	return max;
}
int main(){
	string ins;
	int xx;
	while (1){
		cin>>ins;
		if (ins=="end") break;
		else if (ins=="insert"){
			scanf("%d",&xx);
			insert(xx);
		}
		else if (ins=="extract") printf("%d\n",extract());
	}
	return 0;
}


Measured memory_bytes: 7196
object Main {
  def main(args: Array[String]): Unit = {
    val Array(r, c, _*) = io.StdIn.readLine().split(" ").map(_.toInt)

    val sheet = Array.ofDim[Int](r + 1, c + 1)
    var sum = 0
    for {
      y <- 0 until r
    } {
      io.StdIn.readLine().split(" ")
        .map(_.toInt)
        .zipWithIndex
        .foreach { case (v, x) =>
          sheet(y)(x) = v
          sheet(y)(c) += v
          sheet(r)(x) += v
          sum += v
        }
    }
    sheet(r)(c) = sum
    sheet.map(_.mkString(" ")).foreach(println)
  }
}

Measured memory_bytes: 48072
#pragma GCC optimize("Ofast")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <stdio.h>
#include <sstream>
#include <cstdlib>


using namespace std;

int n, m;
int s[10][10];
vector<int> p;
vector<int> k;
map<string, int> state;
int ans = 0;

void solve(string str, int l)
{
    if (l == 0){
        int ok = 1;
        // cout << str << endl;
        for(int i = 0; i < m; i++){
            int v = 0;
            for(int j = 0; j < k[i]; j++){
                
                string substr = str.substr(s[i][j]-1, 1);
                // cout << substr << endl;
                // int v = atoi(substr.c_str());

                // sscanf(c, "%d", &v);
                // cout << v << " " << p[i] << endl;
                if(substr == "1"){
                    v++;
                }
            }
            if(v % 2 != p[i]){
                ok = 0;
                break;
            }
        }
        if(ok){
            ans++;
        }
    }
    if (l > 0) {
        solve(str + "0", l - 1);
        solve(str + "1", l - 1);
    }
}

int main(void){
    string str = "";

    cin >> n >> m;

    for(int i = 0; i < m; i++){
        int q;
        cin >> q;
        k.push_back(q);
        for(int j = 0; j < q; j++){
            cin >> s[i][j];
        }
    }
    
    for(int i = 0; i < m; i++){
        int q;
        cin >> q;
        p.push_back(q);
    }

    /*

    for(int i = 0; i < m; i++){
        cout << k[i] << " ";
        for(int j = 0; j < k[i]; j++){
            cout << s[i][j] << " ";
        }
        cout << endl;
    }

    for(int i = 0; i < m; i++){
        cout << p[i] << " ";
    }
    */

    solve(str, n);

    // int ans = 0;
    /*
    for(int i = 0; i < m; i++){
        for(int j = 0; j < k[i]; j++){
            cout << s[i][j] << " ";
        }
    }
    */

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<algorithm>
    #include<vector>
    #include <numeric>
    using namespace std;
     
    int main(){
        int n;
        vector<int> edges;
        cin >> n;
     
        for(int i = 0; i < n; i++){
            int edge;
            cin >> edge;
            edges.push_back(edge);
        }
     
        sort(edges.begin(), edges.end());
     
        int m_edge = edges[n-1];
        int edge_sum = accumulate(edges.begin(), edges.end()-1, 0);
     
        //cout << m_edge << " " << edge_sum;
        if(m_edge < edge_sum){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
     
        return 0;
    }

Measured memory_bytes: 256
from functools import reduce


def gcd(a,b):
  x = max([a,b])
  y = min([a,b])
  while y:
    x, y = y, x % y
  return x

def lcm(x,y):
  return (x*y) // gcd(x,y)

def lcm_list(nums):
  return reduce(lcm, nums)
n = int(input())

a = list(map(int, input().split()))




m = lcm_list(a) - 1


ans = 0
for i in range(n):
  ans += m % a[i]
  
  
print(ans)

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;


Node treeMinimum(Node x){
  while(x->left!=NIL){
    x = x->left;
  }
  return x;

}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x = x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;

  if(k < u->key) return treeSearch(u->left, k);
  else return treeSearch(u->right, k);
}

Node treeSuccessor(Node x){
  Node y;

  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y!=NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left!=NIL) x = y->left;
  else x = y->right;

  if(x!=NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y!=z) z->key = y->key;


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
    z->parent = y;

    if(y==NIL) root = z;
    else if(z->key < y->key) y->left = z;
    else y->right = z;
  


}

void inorder(Node u){
  if(u!=NIL){
  inorder(u->left);
  printf(" %d",u->key);  
  inorder(u->right);
  }
  else return;
}
void preorder(Node u){
  if(u!=NIL){
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
  }
  else return;
}


int main(){
  int n,i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19360
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
using namespace std;
 
 
int main() {
	int a, b;
	cin >> a >> b ;
	if (a + b > a*b&&a + b > a - b) {
		cout << a + b << endl;
	}
	else if (a*b > a + b && a*b > a - b) {
		cout << a * b << endl;
	}
	else if(a-b>=a+b&&a-b>=a*b){
		cout << a - b << endl;
	}

	
	

	return 0;
}

Measured memory_bytes: 256
//Catchharsh
    #include<bits/stdc++.h>
    #define ll long long int 
    #define ld long double
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define F first
    #define S second
    #define pb push_back
    #define endl '\n'
    #define see(x) cout<<#x<<" = "<<x<<endl
    const ll MOD = 1e9+7;
    const ll INF = 1011111111;
    const ll LLINF = 1000111000111000111LL;
    const ld EPS = 1e-10;
    const ld PI = 3.14159265358979323;
    using namespace std;
    ll power (ll x,ll n)
    {
        if(n==0)
        return 1;
        else if(n%2==0)
        return power((x*x),n/2);
        else
        return x*power((x*x),(n-1)/2); 
    }
    int main()
    {   
         IOS;
         ll n,m,i,j,k;
         string s[7];
         s[0]="MON";
         s[1]="TUE";
         s[2]="WED";
         s[3]="THU";
         s[4]="FRI";
         s[5]="SAT";
         s[6]="SUN";
         int f=0;
         int id=-1,cnt=0;;
         string ss;
         cin>>ss;
         for(i=0;i<7;i++) if(s[i]==ss) id=i;
         for(i=id+1;i<7;i++)
         {
           if(s[i]=="SUN")
           {
            f=1;
            
           }
           else
           cnt++;
         }
         if(f==0)
         {
          for(i=0;i<=id;i++)
          {
            if(s[i]=="SUN")
              break;
            else
              cnt++;
          }

         }
         cout<<cnt+1;
         
         cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
    }

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

const ll MOD = 1e9 + 7;
ll power(ll x,ll y){
    ll res = 1;
    while(y){
        if(y&1) res = (res*x)%MOD;
        x = (x*x)%MOD;
        y >>= 1;
    }
    return res;
}

void solve(){
    ll n; cin>>n;
    string s; cin>>s;

    map<char,ll> m;
    for(char c:s){
        m[c]++;
    }

    ll ans = 1;
    for(auto x:m) ans = (ans*(x.second+1))%MOD;
    ans = (ans - 1 + MOD)%MOD;
    cout<<ans<<endl;
}

signed main(){

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    FastRead;    

    ll t;
    t = 1;
    while(t--) solve();
    
}


Measured memory_bytes: 512
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	zero := "0"[0]
	one := "1"[0]

	case1 := 0
	for i := 0; i < len(s); i++ {
		if i % 2 == 0 && s[i] != zero {
			case1++
		} else if i % 2 == 1 && s[i] != one {
			case1++
		}
	}

	case2 := 0
	for i := 0; i < len(s); i++ {
		if i % 2 == 0 && s[i] != one {
			case2++
		} else if i % 2 == 1 && s[i] != zero {
			case2++
		}
	}

	min := case1
	if case2 < case1 {
		min = case2
	}
	fmt.Printf("%d\n", min)
}


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

// a と b の最大公約数を返す関数
int64_t GCD(int64_t a, int64_t b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    int64_t N, X;
    cin >> N >> X;
    vector<int64_t> x(N+1);
    
    for ( int64_t i = 0; i < N; ++i){
        cin >> x[i];
    }
    x[N] = X;
    sort(x.begin(),x.end());
    
    vector<int64_t> dx(N);
    for ( int64_t i = 0; i < N; ++i){
        dx[i] = x[i+1] - x[i];
    }
    
    int64_t ans = 0;
    if ( N == 1 ){
        ans = x[1] - x[0];
    } else {
        ans = GCD(dx[1],dx[0]);
        for ( int64_t i = 2; i < N; ++i){
            ans = GCD(ans,dx[i]);
        }
    }
    
    cout << ans << endl;
    
    
    
    
    return 0;
}


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

int main(){
	int lenght;
	char word[255];
	int chr[5] = {0};
	scanf("%d", &lenght);
	
	for(int i=0; i < lenght; i++){
		scanf("%s", &word);
		
		if(strcmp(word, "AC") == 0){
			++chr[0];
		}else if (strcmp(word, "WA")==0){
			++chr[1];
		}else if (strcmp(word, "TLE")==0){
			++chr[2];
		}else if (strcmp(word, "RE")==0){
			++chr[3];
		}
	}
	
	printf("AC x %d\n", chr[0]);
	printf("WA x %d\n", chr[1]);
	printf("TLE x %d\n", chr[2]);
	printf("RE x %d\n", chr[3]);
	
	return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std ;

int main()
{
	int N ; 
	int AC = 0 , WA =0  ,TLE =0  ,RE =0 ; 
	cin >> N ; 
	while(N--){
		char ans[4] ; 
		cin >> ans ;
		if(!strcmp(ans,"AC"))
			AC++ ; 
		else if(!strcmp(ans,"WA"))
			WA++ ;
		else if(!strcmp(ans,"RE"))
			RE++ ;
		else if(!strcmp(ans,"TLE"))
			TLE++ ;
	}
	printf("AC x %d\n",AC) ; 
	printf("WA x %d\n",WA) ; 
	printf("TLE x %d\n",TLE) ; 
	printf("RE x %d\n",RE) ; 


	return 0 ; 
}

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

using namespace std;

typedef long long int lli;

int main() {
	lli N, K;
	cin >> N >> K;

	lli result = N - K * (N / K);

	if (result < K - result) {
		cout << result << endl;
	}
	else {
		cout << K - result << endl;
	}

	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 int long long

signed main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	int v1 = c - a, v2 = d - b;
	cout << c - v2 << ' ' << d + v1 << ' ' << a - v2 << ' ' << b + v1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long
#define lli long long  
#define mod 1000000007 
#define mod2 998244353
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}
long long ncr(long long x,long long y){
  long long z=1;
  long long k=x-y+1;
  while(k<=x){
      z*=k;
      z/=k-x+y;
      k++;
  }
  return z;

}

int main() {
   fast();
  // fact();
   long long int n,p;
   cin>>n>>p;
   long long a[n];
   long long int odd=0;
   long long int even=0;
   for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]%2==0){
      even++;
    }else{
      odd++;
    }
   }
   long long ans=0;
   
    long long int i=0;

    while(2*i+1<=odd){
       ans+=ncr(odd,2*i+1)*(1LL<<even);
       i++;
   }
   if(p%2==0){
    cout<<(1LL<<n)-ans<<"\n";
   }else{
    cout<<ans<<"\n";
   }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, ans = 0;
    bool R = false;
    string S;
    cin >> N;
    vector<pair<string, int>> st(N);
    for (int i = 0; i  < N; i++) {
        cin >> st.at(i).first >> st.at(i).second;
    }
    cin >> S;
    for (int i = 0; i < N; i++) {
        if (R) {
            ans += st.at(i).second;
        }
        if (st.at(i).first == S) {
            R = true;
        }
    }

    cout << ans << endl;
}



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

int main(void){
	int N;
	ll K;
	cin >> N >> K;
	int P[N+1];
	rep(i,N) cin >> P[i+1];
	ll C[N+1];
	rep(i,N) cin >> C[i+1];

	ll ans = -1e10;
	for (int i = 1; i <= N; i++) {
		ll tot = 0;
		ll max_n = -1e10;
		int period = 0;
		int j = i;
		vector<ll> v;
		while (1) {
			j = P[j];
			tot += C[j];
			max_n = max(max_n, tot);
			v.push_back(C[j]);
			period++;
			if (j == i) break;
		}

		ll cand;
		ll tmp = 0;
		rep(j, v.size()) {
			if (j+1>K) break;
			tmp+=v[j];
			cand = tmp;
			if (tot>0) {
				cand += tot*((K-j-1)/period);
			}
			ans = max(ans, cand);
		}
	}

	cout << ans << endl;

return 0;
}


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

using namespace std;

const int N = 1e5 + 10;

int x, n;
int cnt[N];

int main() {
    cin >> x >> n;
    for (int i = 1; i <= n; i++) {
        int xx; cin >> xx;
        cnt[xx]++;
    }
    for (int i = 0; i <= 1000; i++) {
        if (x >= i && !cnt[x - i]) {
            cout << x - i;
            return 0;
        } else if (x < i) {
            cout << x - i;
            return 0;
        }
        if (!cnt[x + i]) {
            cout << x + i;
            return 0;
        }
    }
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int n;cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    sort(All(a));
    int m=a[n-1];
    int p = lower_bound(a.begin(),a.end()-1,m/2.0)-a.begin();
    int res = a[p];
    if(p>0)if(abs(a[p-1]-m/2.0)<abs(a[p]-m/2.0)||res==m)res = a[p-1]; 
    cout << m << ' ' << res << endl;
    return 0;
}

Measured memory_bytes: 768
#!/usr/bin/env python3
import sys
import itertools
sys.setrecursionlimit(10**8)
INF = float("inf")


def bit(n, k):
    return (n >> k) & 1


def main():
    N, M, X = map(int, input().split())
    C = [0]*N
    A = [None]*N
    for i in range(N):
        C[i], *A[i] = map(int, input().split())

    min_money = INF
    # 全探索
    for pattern in itertools.product((0, 1), repeat=N):
        # for i in range(1 << N):
        tot = [0]*M
        money = 0
        for i, use in enumerate(pattern):
            if use == 0:
                continue
            money += C[i]
            for j in range(M):
                tot[j] += A[i][j]

        if all(tot[j] >= X for j in range(M)):
            min_money = min(money, min_money)
    if min_money == INF:
        print(-1)
    else:
        print(min_money)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9240
#define QSIZE 50000
#include<stdio.h>
#include<stdlib.h>

struct Queue {
	char name[1000];
	int time;
};

int head = 0, tail = 0, n;
struct Queue Q[QSIZE];

void enqueue(struct Queue);
struct Queue dequeue(void);


int main() {
	struct Queue a;
	int q, i, t = 0, j = 0;
	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++) scanf("%s %d", Q[i].name, &Q[i].time);
	while (j != n) {
		a = dequeue();
		if (a.time <= q) {
			t += a.time;
			printf("%s %d\n", a.name, t);
			++j;
		}
		else {
			t = q + t;
			a.time =  a.time - q;
			enqueue(a);
		}
	}
	
	return 0;
}


void enqueue(struct Queue a) {
  int next;

	Q[tail] = a;
	if (tail + 1 == n) tail = 0;
	else ++tail;
}
struct Queue dequeue(void) {
	struct Queue a;
	a = Q[head];
	if (head + 1 == n) head = 0;
	else ++head;
	return a;
}



Measured memory_bytes: 50752
X = int(input())
LEN = int(1e6)
p = [True] * LEN

p[0] = False
p[1] = False

for i in range(LEN):
  if p[i]:
    for j in range(i * 2, LEN, i):
      p[j] = False

for i in range(X, LEN):
  if p[i]:
    print(i)
    exit()


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

int N;
const int SIZE = 100005;
int mem [SIZE][4];
int arr [SIZE][3];


int dp (int i, int activ) {
  
  if (i == N) return 0;
  

 if (mem[i][activ] != -1) return mem[i][activ];  
  
  int ret = -1; 

  if (activ != 0) {
    ret = max (ret, arr[i][0] + dp(i+1, 0));
  }

  if (activ != 1) {
    ret = max (ret, arr[i][1] + dp(i+1, 1));
    
  }

  if (activ != 2) {
    ret = max (ret, arr[i][2] + dp(i+1, 2));
    
  }

  return  mem[i][activ] = ret;
}

int main (){ 

  cin  >> N ;
  for (int i =0; i< N; i++) {
    cin >> arr[i][0] >> arr [i][1] >> arr [i][2];
  }

  memset(mem, -1, sizeof mem);
  


  cout << dp(0,3);

}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int main(){
  int n;
  cin >> n;
  int d[n];
  REP(i, n) cin >> d[i];
  sort(d, d+n);
  cout << d[n/2] - d[n/2-1] << endl;
  return 0;
}

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

typedef long long ll;

int main() {
	// ios_base::sync_with_stdio(0);cin.tie(0);
	int n, x, arr[120];
	scanf("%d %d", &n, &x);
	for(int i = 0; i < n; i++) 
		scanf("%d", &arr[i]);
	sort(arr,arr+n);
	ll sum = 0, ans = 0;
	for(int i = 0; i < n-1; i++) {
		if(sum + arr[i] <= x) 
			sum += arr[i], ans++;
	} 
	if(x - sum == arr[n-1]) ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256