akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MOD = 1e9+7;
int add(int a, int b){return ((ll)a + (ll)b)%MOD;}
int sub(int a, int b){return add(a+MOD, -b);}
int mul(int a, int b){return ((ll)a * (ll)b)%MOD;}

void solve(){
    int n, k;
    cin >> n >> k;
    set<int> s;
    for(int i = 0; i < k; i++){
        int d; cin >> d;
        for(int j = 0; j < d; j++){
            int a; cin >> a;
            s.insert(a);
        }
    }
    cout << n-s.size() << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3616
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    if a[x-1]+b[y-1]-c < ans:
        ans = a[x-1]+b[y-1]-c
    else:
        pass
print(ans)


Measured memory_bytes: 18736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;

ll dat[1310720*2], add[1310720*2];
int segn = 1;
void init(int n){
	while(segn < n)segn *= 2;
	//for(int i = 0;i < segn*2;i++)dat[i] = inf;
}

void lazy_update(int k, int l, int r){
	dat[k] += add[k]*(r-l);
	add[k*2+1] += add[k];
	add[k*2+2] += add[k];
	add[k] = 0;
}

void update(int a, int b, int x, int k, int l, int r){
	lazy_update(k, l, r);
	if(b <= l || r <= a)return ;
	if(a <= l && r <= b){
		add[k] += x;
		lazy_update(k, l, r);
		return ;
	}
	update(a, b, x, k*2+1, l, (l+r)/2);
	update(a, b, x, k*2+2, (l+r)/2, r);
	dat[k] = dat[k*2+1]+add[k*2+1]+dat[k*2+2]+add[k*2+2];
}

ll get(int a, int b, int k, int l, int r){
	lazy_update(k, l, r);
	if(b <= l || r <= a)return 0;
	if(a <= l && r <= b)return dat[k];
	ll vl = get(a, b, k*2+1, l, (l+r)/2);
	ll vr = get(a, b, k*2+2, (l+r)/2, r);
	return vl+vr;
}

int main(){
	int n, q, c, s, t, x;
	scanf("%d%d", &n, &q);
	init(n);
	for(int i = 0;i < q;i++){
		scanf("%d", &c);
		if(!c){
			scanf("%d%d%d", &s, &t, &x);
			update(s-1, t, x, 0, 0, segn);
		}else{
			scanf("%d%d", &s, &t);
			ll res = get(s-1, t, 0, 0, segn);
			printf("%lld\n", res);
		}
	}
	return 0;
}


Measured memory_bytes: 7880
def main():
    num = int(input())
    value_array = []
    for i in range(0, num):
        value = input().split()
        value_array.append([int(x) for x in value])
    max_array = max(value_array)
    print(max_array[0] + max_array[1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 21156
#include <stdio.h>
#define MAX 25
#define NIL -1

typedef struct {
  int parent;
  int left;
  int right;
} Binary;

int depth;
Binary T[MAX];

int max(int, int);
int calcDepth(int);
int calcHeight(int);
int findSibling(int);
void print(int);


int main() {
  int n, i, p, l, r;
  
  scanf( "%d" , &n );
  for ( i=0; i<n; i++ ) T[i].parent = T[i].left = T[i].right = NIL;
  for ( i=0; i<n; i++ ) {
    scanf("%d%d%d", &p, &l, &r);
    T[l].parent = T[r].parent = p;
    T[p].left = l;
    T[p].right = r;
  }
  
  for ( i=0; i<n; i++ ) print(i);
  
  return 0;
}


int max(int a, int b) {
  if ( a > b ) return a;
  else return b;
}

int calcDepth(int u) {
  if ( T[u].parent == NIL ) return 0;
  else {
    depth++;
    calcDepth(T[u].parent);
  }
  return depth;
}

int calcHeight(int u) {
  int h1=0, h2=0;

  if ( T[u].left != NIL ) h1 = calcHeight(T[u].left) + 1;
  if ( T[u].right != NIL ) h2 = calcHeight(T[u].right) + 1;

  return max(h1, h2);
}

int findSibling(int u) {
  if ( T[u].parent == NIL ) return NIL;
  else if ( (T[T[u].parent].left != u)
	    && (T[T[u].parent].left != NIL) )
    return T[T[u].parent].left;
  else if ( (T[T[u].parent].right != u)
	    && (T[T[u].parent].right != NIL) )
    return T[T[u].parent].right;
  else return NIL;
}

void print(int u) {
  int degree=0;

  printf( "node %d: parent = %d, sibling = %d, "
	  , u , T[u].parent , findSibling(u) );
  
  if ( T[u].right != NIL ) degree++;
  if ( T[u].left != NIL ) degree++;
  printf( "degree = %d, " , degree );
  
  depth = 0;
  printf( "depth = %d, height = %d, " , calcDepth(u) , calcHeight(u) );
  
  if ( T[u].parent == NIL ) printf( "root\n" );
  else if ( (T[u].left == NIL)
	    && (T[u].right == NIL) ) printf( "leaf\n" );
  else printf( "internal node\n" );
}



Measured memory_bytes: 2052
// SeeAlso: https://atcoder.jp/contests/abc054/tasks/abc054_a

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int A, B;

int main() {
    
    cin >> A >> B;

    bool flag = false;

    if(A==1&&A!=B){
        flag = true;
    } else if(B==1&&A!=B) {
        flag = false;
    } else if(A!=B) {
        flag = A>B;
    } else {
        print("Draw");
        return 0;
    } 

    if(flag) {
        print("Alice");
    } else {
        print("Bob");
    }

    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	string s;
	cin >> s;
	int sum = 0;
	int p = 0;
	reverse(s.begin(), s.end());
	for (int i = 11; i >= 7; i--) {
		if (s[i] == '?')p = i;
		else {
			sum += (s[i] - '0')*(i - 5);
		}
	}
	for (int i = 6; i >= 1; i--) {
		if (s[i] == '?')p = i;
		else {
			sum += (s[i] - '0')*(i + 1);
		}
	}
	sum %= 11;
	vector<int>ret;
	if (p == 0) {
		int ans = 11 - sum;
		if (ans >= 10)ans = 0;
		cout << ans << endl;
		return 0;
	}
	else {
		for (int i = 0; i < 10; i++) {
			int box = sum;
			if (p <= 6) {
				box += i * (p + 1);
			}
			else {
				box += i * (p - 5);
			}
			box %= 11;
			int ans = 11 - box;
			if (ans >= 10)ans = 0;
			if (ans == s[0] - '0')ret.push_back(i);
		}
	}
	if (ret.size() == 1)cout << ret[0] << endl;
	else cout << "MULTIPLE" << endl;
}


Measured memory_bytes: 3228
//confilm 0LL and 1LL
//confilm cornercase such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll k, a, b;
	cin >> k >> a >> b;

	if(a >= b-1 || k <= a) co(k+1);
	else{
		ll ans = 1;
		ans += a-1;
		k -= a-1;
		ans += (b-a)*(k/2);
		if(k%2) ans++;
		co(ans);
	}

	return 0;
}


Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

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

using namespace std;

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

 main()

{
    fast
    int n,x,t;
    cin>>n>>x>>t;
    int ses=n/x;
    if(n%x!=0)ses++;
    ses=ses*t;
    cout<<ses<<"\n";
    return 0;

}





































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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  double a, b;
  cin >> a >> b;
  double x = (a + b) / 2;
  int y = (a + b) / 2;
  if (x >= y + 0.5) {
    cout << y + 1 << endl;
  } else {
    cout << y << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())
R = []
G = []
B = []
for i in range(len(S)):
    if S[i] == "R":
        R.append(i)
    elif S[i] == "G":
        G.append(i)
    else:
        B.append(i)

ans = len(R) * len(G) * len(B)
for i in range(N):
    for d in range(1, -(-(N-i)//2)):
        if S[i] != S[i + d] and S[i + d] != S[i + 2*d] and S[i + 2*d] != S[i]:
            ans -= 1
print(ans)


Measured memory_bytes: 71860
#include <iostream>
#include <vector>
#include <stdio.h>

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> p(n);
  for (int i = 0; i < n; ++i) std::cin >> p[i];
  int max_so_far = 0;
  int current_sum = 0;
  for (int i = 0; i < k; ++i) {
    current_sum += p[i];
  }
  max_so_far = current_sum;
  for (int i = k; i < n; ++i) {
    current_sum += p[i] - p[i - k];
    if (current_sum > max_so_far) max_so_far = current_sum;
  }
  printf("%f\n", (max_so_far + k) / 2.0);
  
  return 0;
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	int a[n+5];
	rep(i,1,n)
	{
		cin >> a[i];
	}
	int c=0;
	rep(i,2,n-1)
	{
		if((a[i]>a[i-1] && a[i+1]>a[i]) || (a[i]<a[i-1] && a[i+1]<a[i]))
		{
			c++;
		}
	}
	cout << c << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def ceil(a, b):
    if a%b == 0:
        return a//b
    else:
        return (a//b) + 1

def main():
    a, b, c, d = map(int, input().split())
    print("Yes" if ceil(c, b) <= ceil(a, d) else "No")


if __name__ == "__main__":
    main()

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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    while(n)
        ans++, n/=k;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>

#define REP(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

typedef complex<int> POINT;
template <class T>
class vevector : public vector<vector<T>>
{
public:
	using vector<vector<T>>::operator []; 
	T& operator [](const POINT &index) { return (*this)[index.real()][index.imag()]; }
};

template <class T> T read() { T t; cin >> t; return t; }
template <class T> vector<T> read(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i,n) v.push_back(read<T>(m)); return v; }
template <class T> void write(const T &t) { cout << t << endl; }
template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; }

template <class T> void write(const vector<T> &v)
{
	ostringstream ss; 
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	cout << s.substr(0, s.length() - 1) << endl;
}

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__

void solve();
int main() { solve(); return 0; }


/// template end ///



void solve()
{
	while (true)
	{
		READ(int, H, W);
		if (!(W|H)) { break; }
		auto field = read<char>(W, H);
		for (auto &f : field) { f.insert(f.begin(), '0'); f.push_back('0'); }
		field.insert(field.begin(), vector<char>(H+2, '0'));
		field.push_back(vector<char>(H+2, '0'));
		W += 2; H += 2;

		int count = 0;
		REP(sx,W) REP(sy,H) if (field[sx][sy] == '1')
		{
			typedef POINT P;
			queue<P> q;
			q.push(P(sx, sy));
			while (!q.empty())
			{
				P cur = q.front(); q.pop();
				if (field[cur] == '0') { continue; }
				field[cur] = '0';
				P d[] = { P(-1,-1), P(0,-1), P(1,-1), P(-1, 0), P(1, 0), P(-1,1), P(0,1), P(1,1) };
				REP(i, 8)
				{
					P next = cur + d[i];
					if (field[next] == '1') q.push(next);
				}
			}
			count++;
		}
		write(count);
	}
}

Measured memory_bytes: 1232
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

n = I()
S = LI()
q = I()
T = LI()
ans = 0
for t in T:
    a = 0
    for i in range(1, 10 * math.ceil(math.log(2, n)) + 10):
        if S[a] == t:
            ans += 1
            break
        elif S[a] < t:
            a += math.ceil(n / pow(2, i))
            if a >= n - 1:
                a = n - 1
        else:
            a -= math.ceil(n / pow(2, i))
            if a <= 0:
                a = 0
print(ans)



Measured memory_bytes: 18096
#include <bits/stdc++.h>
using namespace std;
#define longlong = ll;

int main()
{
    int r, g, b, k;

    cin >> r >> g >> b >> k;
    while (k != 0)
    {
        if (r < g && r < b && g < b)
        {
            b = b * 2;
        }
        else if (b <= r || b <= g)
        {
            b = b * 2;
        }
        else if (g <= r)
        {
            g = g * 2;
        }
        else
        {
            r = r * 2;
        }
        k--;
    }

    if (r < g && r < b && g < b)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define take freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);freopen("error.txt","w",stderr);
#define speed ios_base::sync_with_stdio(false);
#define int long long
#define endl "\n"
#define maxi 10000007
#define rof(i,a,b) for(int i=a;i<b;i++)
int32_t main()
{
    speed
    //take
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int m[n];
    m[0]=-1;
    int maxo=-1;
    for(int i=0;i<n-1;i++)
    {
        maxo=max(maxo,a[i]);
        m[i+1]=maxo;
    }
    int cost=0;
    for(int i=1;i<n;i++)
    {
        if(m[i]>a[i])
        {
            cost+=m[i]-a[i];
        }
    }
    cout<<cost;
}

Measured memory_bytes: 6744
#include<stdio.h>
#include<math.h>
#include<queue>
#include<stack>
#include<string.h>
#include<algorithm>
#include<cctype>
#include<vector>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int cou=0;
	while(n){
		cou++;n/=k;
	}printf("%d",cou);
}

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

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

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

    // start
    int a, b, t;
    cin >> a >> b >> t;
    cout << (t < a ? 0 : t / a * b) << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static string Solve(string S)
        {
            int a1 = int.Parse(S.Substring(0, 2));
            int a2 = int.Parse(S.Substring(2, 2));
            int flag = 0;
            if ((1 <= a1) && (a1 <= 12)) { flag |= 1; }
            if ((1 <= a2) && (a2 <= 12)) { flag |= 2; }
            switch (flag)
            {
            case 0: return "NA";
            case 1: return "MMYY";
            case 2: return "YYMM";
            default: return "AMBIGUOUS";
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine(Solve(Read()));
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


long mod = 1000000007;
/* C++の構造体 メンバがpublicなclass */
typedef struct mint
{
    ll x;
    mint(ll x = 0) : x(x % mod) {} //コンストラクタ
    /* 演算子オーバーロード */
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const
    {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const
    {
        mint res(*this);
        return res /= a;
    }
} mint_t;

ll intpow(mint_t m, int n)
{
    if (n == 0) return 1;
    mint_t ans(1);
    while (n >= 1)
    {
        if ((n % 2) == 0){
            m *= m.x;
            n /= 2;
        }else {
            ans *= m.x;
            n -= 1;
        }
    }
    return ans.x;
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main()
{
    int k;
    string s;
    cin >> k >> s;
    int l = s.length();

    combination  cb(k+l);

    mint ans(0);
    rep(i, k+1){
        mint m26(26); 
        mint m25(25);
        mint tans(0);
        tans = m25.pow(k-i) * m26.pow(i) * cb(l-1+k-i, l-1);
        ans += tans;
    }

    cout << ans.x << endl;
}


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

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] x = new long[n];
        long[] y = new long[n];
        long[] z = new long[n];

        for(int i=0; i<n; i++) {
            x[i] = sc.nextLong();
            y[i] = sc.nextLong();
            z[i] = sc.nextLong();
        }
        int[] xs = {1, 1, 1, 1, -1, -1, -1, -1};
        int[] ys = {1, 1, -1, -1, 1, 1, -1, -1};
        int[] zs = {1, -1, 1, -1, 1, -1, 1, -1};

        long res = 0;
        for(int j=0; j<8; j++) {
            long[] a = new long[n];
            for(int i=0; i<n; i++) {
                a[i] = x[i] * xs[j] + y[i] * ys[j] + z[i] * zs[j];
            }
            Arrays.sort(a);
            long sum = 0;
            for(int i=n-1; i>n-1-m; i--) {
                sum += a[i];
            }
            res = Math.max(res, sum);
        }

        System.out.println(res);
    }

}


Measured memory_bytes: 27568
#include <stdio.h>
int main() {
  char a,b;
  scanf("%c %c",&a,&b);
  if(a == 'H'){
    if(b == 'H') printf("H\n");
    else printf("D\n");
  }else{
    if(b == 'H') printf("D\n");
    else printf("H\n");
  }
  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = 1000000007;

const int MAX_N = 512345;
int border1[MAX_N];
int border2[MAX_N];
int kmpnxt[MAX_N];
void KMP(const string& S, int* border) {
  int N = (int)S.size();
  border[0] = kmpnxt[0] = -1;
  for (int i = 0, j = -1; i < N; i++) { 
    while (j >= 0 && S[i] != S[j]) j = kmpnxt[j];
    j++;
    border[i+1] = j;
    kmpnxt[i+1] = (S[i+1] == S[j]) ? kmpnxt[j] : j;
  }
  // cout << "S     :"; pv(ALL(S));
  // cout << "border:"; pv(border, border+N+1);
  // cout << "kmpnxt:"; pv(kmpnxt, kmpnxt+N+1);
}

int main2() {
  string w; cin >> w;
  int N = (int)w.size();
  if (N == 1) {
    cout << 1 << endl;
    cout << 1 << endl;
    return 0;
  }

  KMP(w, border1);
  int p = N - border1[N];
  if (!(N % p == 0 && N / p >= 2)) {
    cout << 1 << endl;
    cout << 1 << endl;
    return 0;
  }
  if (p == 1) {
    cout << N << endl;
    cout << 1 << endl;
    return 0;
  }
  reverse(ALL(w));
  KMP(w, border2);
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    bool yes = true;
    p = i - border1[i];
    if (i%p == 0 && i/p >= 2) yes = false;
    p = N-i - border2[N-i];
    if ((N-i) % p == 0 && (N-i)/p >= 2) yes = false;
    if (yes) ans++;
  }
  cout << 2 << endl;
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 6788
n, k = map(int, input().split())
a = list(map(int, input().split()))

a = [i-1 for i in a]

d = [1]*n
p = 0
b = []
while d[p]:
    b.append(p)
    d[p] = 0
    p = a[p]
avant = b.index(p)
loop_count = len(b) - avant
c = b[avant:]

if k <= avant:
    print(b[k]+1)
else:
    k -= avant
    k %= loop_count
    print(c[k]+1)


Measured memory_bytes: 115484
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

void chmin(ll &a, ll b) {
	a = min(a, b);
}
void chmax(int &a, int b) {
	a = max(a, b);
}
ll mod_pow(ll a, ll n, ll m = mod) {
	a %= m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

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

void solve() {
	ll n; cin >> n;
	rep1(h, 3500)rep1(w, 3500) {
		ll a = (ll)n*h*w;
		ll b = (ll)4 * h*w - (ll)n*h - (ll)n*w;
		if (b > 0) {
			if (a%b == 0) {
				ll r = a / b;
				cout << h << " " << w << " " << r << "\n";
				return;
			}
		}
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 7668
import math
from collections import deque
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return map(int, input().split())
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n = readInt()
x = int(n/1.08)
ans = [x-1,x,x+1]

for i in range(3):
	if int(ans[i]*1.08)==n:
		print(ans[i])
		exit()
print(":(")

Measured memory_bytes: 3444
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        long[] s = Console.ReadLine().Split().Select(long.Parse).ToArray();
        Console.WriteLine(solve(s[0], s[1]));
    }
    static long solve(long x, long y) {
        List<long> a = new List<long>();
        while(x <= y) {
            a.Add(x);
            x *= 2;
        }
        return a.Count();
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;

int n;
double d, x;

int main() {
	cin >> n >> d >> x;
	double ans = 0;
	while (n) {
		double del = d + (2 * n - 1) * x / 2;
		ans += del;
		double td = d, tx = x;
		d += (2 * td + 5 * x) / (2 * n);
		x += (2 * tx) / n;
		--n;
	}
	printf("%.10lf\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int data[200]={0},temp;
	for(temp=0;scanf("%d %d",&data[temp],&data[temp+1])!=EOF;temp++){
		int digit[200]={0},i=0;
		while(i<temp+1){
			if(data[i]+data[i+1]<10){digit[i]=1;}
			else if(data[i]+data[i+1]<100){digit[i]=2;}
			else if(data[i]+data[i+1]<1000){digit[i]=3;}
			else if(data[i]+data[i+1]<10000){digit[i]=4;}
			else if(data[i]+data[i+1]<100000){digit[i]=5;}
			else if(data[i]+data[i+1]<1000000){digit[i]=6;}
			else{digit[i]=7;}
			
			i++;
		}
		printf("%d\n",digit[i-1]);
		
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int K = sc.nextInt();
    
    int minAB = Math.min(A, B);
    List<Integer> list = new ArrayList<>();
    for (int i = 1; i <= minAB; i++) {
      if (A%i == 0 && B%i == 0) {
        list.add(i);
      }
    }
    
    System.out.println(list.get(list.size()-K));
  }
}

Measured memory_bytes: 21844
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getInt():
    return int(input())
def getInts():
    return [int(i) for i in input().split()]
def getIntLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInt())
    return res
def getIntsLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInts())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n, a, b = getInts()
print(min(a, b), max(0, a+b-n))

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    int n, m, l;
    cin >> n >> m >> l;
    int a[100][100] = {};
    int b[100][100] = {};
    long long c[100][100] = {};
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < m; i++){
        for (int j = 0; j < l; j++){
            cin >> b[i][j];
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < l; j++){
            c[i][j] = 0;
            for (int k = 0; k < m; k++){
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < l-1; j++){
            cout << c[i][j] << " ";
        }
        cout << c[i][l-1] << endl;
    }
}


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

using namespace std;
typedef long long ll;

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

    map<int , int > mp;
    for(auto &x : A){
        mp[x-1]++;
        mp[x]++;
        mp[x+1]++;
    } 
    int ans = 0;
    for(auto x : mp){
        ans = max(ans, x.second);
    }

    cout << ans << endl;
}

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

#define debug(x) cout <<"DEBUG"<<" "<<#x<<":"<<x<<'\n'

//↓0-indexか1-indexでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-index昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-index昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-index降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-index降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    string s; cin >> s;
    char s_last = (s[s.size()-1]=='<'? '>' : '<');
    s.push_back(s_last);  //番兵
    vll a;
    ll cnt = 0;
    for(ll i = 0; i < s.size()-1; i++) {
        cnt++;
        if(s[i]!=s[i+1]) {
            a.push_back(cnt);
            cnt = 0;
        }
    }
    //for(int i : a) cout << i << '\n'; ////debug -> ok
    if(s[0]=='<') {
        for(ll i = 0; i < a.size()-1; i+=2) {
            if(i==a.size()-1) {
                break;
            }
            if(a[i]<= a[i+1]) {
                a[i]--;
            } else {
                a[i+1]--;
            }
        }

    }else {
        for(ll i = 1; i < a.size()-1; i+=2) {
            if(i==a.size()-1) {
                break;
            }
            if(a[i]<=a[i+1]) {
                a[i]--;
            } else {
                a[i+1]--;
            }
        }
    }

    //計算
    ll answer = 0;
    for(ll aa : a) {
        if(aa==0) continue;
        answer += ((aa+1)*aa)/2;
    }

    cout << answer << '\n';
}

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

int main() {
  int x;
  cin >> x;
  int p=0;
  
  if(x!=0){
    p=(x/500)*1000;
    x=x%500;
  }
  
  if(x!=0){
    p=p+(x/5)*5;
    cout << p << endl;
  }
  else{
    cout << p << endl;
  }
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, BufWriter, Write};
use std::mem;

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>,
}

impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() {
    let mut scan = Scanner::default();
    let out = &mut BufWriter::new(stdout());

    loop {
        let mut x = scan.next::<i32>();
        let mut y = scan.next::<i32>();
        if x == 0 && y == 0 {
            break;
        }
        if x > y {
            mem::swap(&mut x, &mut y);
        }
        writeln!(out, "{} {}", x, y).ok();
    }
}



Measured memory_bytes: 5048
import java.util.*;

class Main{
	public static void main(String[] args){
		
		int top=0;
		boolean flag = false;
		
		Scanner sc = new Scanner(System.in);
		String s1 = sc.nextLine();
		String s = s1+s1;
		String p = sc.nextLine();		
		for(int i=0;i<s1.length();i++){
			if(p.equals(s.substring(top,top+p.length()))){
				flag = true;
				break;
			}
			top++;
		}
		if(flag){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26264
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    int c[100010];
    for(int i=0;i<a;++i){
        cin>>c[i];
    }
    sort(c, c + a);
    int d[100010];
    --b;
    for(int i=0;i<a-b;++i){
        d[i] = c[i+b] - c[i];
    }
    int Min=1000000010;
    for(int i=0;i<a-b;++i){
        if(d[i] < Min)Min = d[i];
    }
    cout<<Min;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n = 0; //????????????????????°
		int mat[][] = new int[11][11];  //??¶?´??????¶??????11*11?????????.
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			if(n ==0 || n > 50) break; //????????????????????°?????¶?´??????¶.
			for(int i = 0; i < n; ++i){
				for(int j = 0; j < n; ++j){
					mat[i][j] = sc.nextInt();
					mat[n][j] += mat[i][j];
					mat[i][n] += mat[i][j];
					mat[n][n] += mat[i][j];
					}
			}//??¨???
			for(int i = 0; i < n+1; ++i){
				for(int j = 0; j < n+1; ++j){
					System.out.printf("%5d",mat[i][j]);
				}
				System.out.println("");
			}
			//??????????????????
			for(int i = 0; i < 11; ++i){
				for(int j = 0; j < 11; ++j){
					mat[i][j] = 0;
				}
			}
		}
		sc.close();
	}

}

Measured memory_bytes: 32948
fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line);
    let S = line.trim();
    let mut dp = [0; 2019];
    let mut inv = [0; 2019];
    for i in 0..2019 {
        for j in 0..2019 {
            if i * j % 2019 == 1 {
                inv[i] = j;
            }
        }
    }
    let mut ans = 0;
    let mut a: usize = 1;
    let mut b: usize = 0; // ax + b
    for cur_b in S.bytes() {
        let num = (cur_b - b'0') as usize;
        a = a * 10 % 2019;
        b = (b * 10 + num) % 2019;
        // dp[a * i + b]
        // println!("{} {}", a, b);
        let idx = (num + 2019 - b) * inv[a] % 2019;
        dp[idx] += 1;
        // println!("cur {}",  dp[(2019 - b) %  2019]);
        // assert_eq!((a * idx + b) % 2019, num);
        ans += dp[(2019 - b) * inv[a] % 2019] as i64;
    }
    println!("{}", ans);
}


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

int main(){
  int N; cin >> N;
  int a[N];
  double ave = 0;
  REP(i,N){
    cin >> a[i];
    ave += (double)a[i];
  }
  ave /= N;

  int avei = (int) ave;
  if( (int)(ave*10)%10>=5 ){avei++;}
  
  int r = 0;
  int c;
  REP(i,N){
    c = a[i]-avei;
    r += c*c;
  }
  cout << r << '\n';
}
  

Measured memory_bytes: 256
#include <stdio.h>

int a, b, c, x;

int solve(){
  int ans = 0;
  for(int i = 0; i <= a; i++){
    for(int j = 0; j <= b; j++){
      for(int k = 0; k <= c; k++){
        int tmp = 500 * i + 100 * j + 50 * k;
        if(tmp == x) ans++;
      }
    }
  }
  return ans;
}

int main(){
  scanf("%d%d%d%d", &a, &b, &c, &x);
  printf("%d\n", solve());
  return 0;
}


Measured memory_bytes: 1700
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    vector<int> abc(3, 0);
    rep(i, 3) cin >> abc[i];
    sort(abc.begin(), abc.end());
    if ((abc[2] - abc[0]) % 2 == 0 && (abc[2] - abc[1]) % 2 == 0) {
        cout << (abc[2] - abc[0]) / 2 + (abc[2] - abc[1]) / 2 << endl;
    } 
    else if ((abc[2] - abc[0]) % 2 == 1 && (abc[2] - abc[1]) % 2 == 1){
        cout << (abc[2] - abc[0]) / 2 + (abc[2] - abc[1]) / 2 + 1 << endl;
    }
    else if ((abc[2] - abc[0]) % 2 == 1) {
        cout << (abc[2] - abc[0] + 1) / 2 + (abc[2] - abc[1]) / 2 + 1 << endl;
    }
    else {
        cout << (abc[2] - abc[0]) / 2 + (abc[2] - abc[1] + 1) / 2 + 1 << endl;
    }


    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    vector<int> A;
    bool isr = true;
    int num = 0;
    for (int i = 0; i < (int)S.size(); i++) {
        if (isr) {
            if (S[i] == 'R') {
                num++;
            } else {
                isr = false;
                A.push_back(num);
                num = 1;
            }
        } else {
            if (S[i] == 'L') {
                num++;
            } else {
                isr = true;
                A.push_back(num);
                num = 1;
            }
        }
    }
    A.push_back(num);

    vector<int> ans((int)S.size());
    int now = -1;
    isr = true;
    for (auto a : A) {
        if (isr) {
            now += a;
            ans[now] += (a + 1) / 2;
            ans[now + 1] += a / 2;
            isr = false;
        } else {
            ans[now + 1] += (a + 1) / 2;
            ans[now] += a / 2;
            now += a;
            isr = true;
        }
    }
    for (int i = 0; i < (int)S.size(); i++) {
        cout << ans[i];
        if (i != (int)S.size() - 1) cout << " ";
    }
    cout << endl;
}


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

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

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

ll dp[110][1010][10];

int main()
{

    int N, S;

    while (cin >> N >> S, N)
    {

        rep(i, 110) rep(j, 1010) rep(k, 10) dp[i][j][k] = 0;

        dp[0][0][0] = 1;

        rep(i, 101)
        {
            rep(j, 1010)
            {
                rep(k, 10)
                {
                    dp[i + 1][j][k] += dp[i][j][k];

                    if (j + i <= S && k + 1 <= N)
                        dp[i + 1][j + i][k + 1] += dp[i][j][k];
                }
            }
        }

        cout << dp[101][S][N] << endl;
    }

    return 0;
}


Measured memory_bytes: 11764
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>   
using namespace std;

int main(){
int a,i = 0;
cin >> a;
int b[a],c[a],ans[a];
while(a > i){
	cin >> b[i] >> c[i];
	ans[i] =  b[i] % c[i];
	if(ans[i] == 0) ans[i] = c[i];
	i++;
}
i = 0;
while(a > i){
cout << ans[i] << endl;
i++;
}
}

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

int main(){
    int a, b;
    cin >> a >> b;

    vector<int> num(3);
    num[0] = a + b;
    num[1] = a - b;
    num[2] = a * b;
    sort(num.begin(), num.end());

    cout << num[2] << endl;

    return 0;
}

Measured memory_bytes: 256
def comb(n,r,mod=10**9+7):
    cnt = 1
    for i in range(1, r+1): #nCr = n*(n-1)*...(n-r+1)/r!で分母 = cnt
        cnt *= (n-i+1)*pow(i,mod-2,mod) #逆元法 X*Y**(mod-2)%mod。繰り返し2乗法powを使う
        cnt %= mod #値が大きくなるので全てmodで計算
    return cnt

n, a, b = map(int, input().split())
mod = 10**9+7

ans = (pow(2,n,mod)-1-comb(n,a)-comb(n,b)) % mod #値が大きくなるので全てmodで計算
print(ans)

Measured memory_bytes: 40044
def selection_sort(A, N):
    count = 0
    for i in range(N):
        min_j = i
        for j in range(i, N):
            if A[j] < A[min_j]:
                min_j = j
        if i != min_j:
            A[i], A[min_j] = A[min_j], A[i]
            count += 1
    print " ".join(map(str, A))
    print count

N = input()        
A = map(int, raw_input().split())
selection_sort(A, N)

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			String n = sc.nextLine();
			if("0".equals(n)) break;
			int[][] array = new int[Integer.parseInt(n)][4];
			//int[] jud = new int[4];
			for(int i = 0 ; i < array.length ; i++){
				String data = sc.nextLine();
				String[] adata = data.split(" ");
				for(int j = 0 ; j < adata.length ; j++){
					array[i][j] = Integer.parseInt(adata[j]);
				}
			}
			String max = sc.nextLine();
			String[] amax = max.split(" ");
			int p = Integer.parseInt(amax[0]);
			int q = Integer.parseInt(amax[1]);
			int r = Integer.parseInt(amax[2]);
			int c = Integer.parseInt(amax[3]);
			for(int i = 0 ; i < array.length ; i++){
				if(array[i][1] > p || array[i][2] > q || array[i][3] > r || 4 * array[i][1] + 9 * array[i][2] + 4 * array[i][3] > c){
					array[i][0] = 0;
				}
			}
			int sum = 0;
			for(int i = 0 ; i < array.length ; i++){
				if(array[i][0] != 0){
					System.out.println(array[i][0]);
				}
				sum += array[i][0];
			}
			if(sum == 0 ) System.out.println("NA");
		}
		sc.close();
	}

}

Measured memory_bytes: 65556